1The librdef library
2===================
3
4Of course, it would be cool if other applications (such as GUI resource editors) could also import
5and export rdef files. That is why the bulk of rc's functionality is implemented in a separate
6shared library, librdef.so.
7
8Using the library in your own applications is very simple. Here are some quick instructions to get
9you started:
10
111. ``#include "rdef.h"`` in your sources
122. link your app to librdef.so
13
14The API is rather bare-bones, but it gets the job done. The library uses files to transfer data to
15and from your application. This may seem odd, but it is actually a big advantage. After calling the
16API functions to compile an rdef file, you can use the standard BResources class to read the
17resources from the output file. Chances are high that your application already knows how to do this.
18
19To compile a resource file, the steps are typically this:
20
21
221. Call ``rdef_add_include_dir()`` one or more times to add include file search paths.
232. Call ``rdef_add_input_file()`` one or more times to add the rdef files that you want to compile.
243. Call ``rdef_set_flags()`` to toggle compiler options.
254. Call ``rdef_compile()`` with the name of the output file. This performs the actual compilation.
265. Call ``rdef_free_input_files()`` to clear the list of input files that you added earlier.
276. Call ``rdef_free_include_dirs()`` to clear the list of include directories that you added earlier.
28
29Decompiling is very similar, although include directories are not used here:
30
311. Call ``rdef_add_input_file()`` one or more times to add the resource files that you want to decompile.
322. Call ``rdef_set_flags()`` to toggle compiler options.
333. Call ``rdef_decompile()`` with the name of the output file. The name of the header file (if any) will be automatically constructed by appending ".h" to the output file name.
344. Call ``rdef_free_input_files()`` to clear the list of input files that you added earlier.
35
36If one of these functions returns something other than B_OK, an error occurred. You can look at the
37following variables to find out more about the error, and construct meaningul error messages:
38
39rdef_err
40    The error code that was returned.
41
42rdef_err_line
43    The line number where compilation failed.
44
45rdef_err_file
46    The file where the error occurred.
47
48rdef_err_msg
49    The error message from the compiler.
50
51For more information about using librdef, see "rdef.h", which explains the available functions and
52data structures in more depth. For a real-world example, take a look at "rc.cpp", which contains
53the complete implementation of the rc compiler. As you'll see, there really isn't much to it,
54because librdef already does all the work.
55