vfs: check userland buffers before reading them.
[haiku.git] / src / bin / rc / docs / librdef.html
blobbb54d3831f60068b56393b254674f4fa4a9a024d
1 <HTML>
2 <HEAD>
3 <TITLE>The librdef library</TITLE>
4 </HEAD>
5 <BODY BGCOLOR="#FFFFFF">
7 <H1>The librdef library</H1>
9 <P>Of course, it would be cool if other applications (such as GUI resource editors) could also import and export rdef files. That is why the bulk of rc's functionality is implemented in a separate shared library, librdef.so.</P>
11 <P>Using the library in your own applications is very simple. Here are some quick instructions to get you started:</P>
13 <OL>
14 <LI><CODE>#include "rdef.h"</CODE> in your sources</LI>
15 <LI>link your app to librdef.so</LI>
16 </OL>
18 <P>The API is rather bare-bones, but it gets the job done. The library uses files to transfer data to and from your application. This may seem odd, but it is actually a big advantage. After calling the API functions to compile an rdef file, you can use the standard BResources class to read the resources from the output file. Chances are high that your application already knows how to do this.</P>
20 <P>To compile a resource file, the steps are typically this:</P>
22 <OL>
24 <LI>Call <CODE>rdef_add_include_dir()</CODE> one or more times to add include file search paths.</LI>
26 <LI>Call <CODE>rdef_add_input_file()</CODE> one or more times to add the rdef files that you want to compile.</LI>
28 <LI>Call <CODE>rdef_set_flags()</CODE> to toggle compiler options.</LI>
30 <LI>Call <CODE>rdef_compile()</CODE> with the name of the output file. This performs the actual compilation.</LI>
32 <LI>Call <CODE>rdef_free_input_files()</CODE> to clear the list of input files that you added earlier.</LI>
34 <LI>Call <CODE>rdef_free_include_dirs()</CODE> to clear the list of include directories that you added earlier.</LI>
36 </OL>
38 <P>Decompiling is very similar, although include directories are not used here:</P>
40 <OL>
42 <LI>Call <CODE>rdef_add_input_file()</CODE> one or more times to add the resource files that you want to decompile.</LI>
44 <LI>Call <CODE>rdef_set_flags()</CODE> to toggle compiler options.</LI>
46 <LI>Call <CODE>rdef_decompile()</CODE> 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.</LI>
48 <LI>Call <CODE>rdef_free_input_files()</CODE> to clear the list of input files that you added earlier.</LI>
50 </OL>
52 <P>If one of these functions returns something other than B_OK, an error occurred. You can look at the following variables to find out more about the error, and construct meaningul error messages:</P>
54 <UL>
55 <LI><CODE>rdef_err</CODE> The error code that was returned.</LI>
56 <LI><CODE>rdef_err_line</CODE> The line number where compilation failed.</LI>
57 <LI><CODE>rdef_err_file</CODE> The file where the error occurred.</LI>
58 <LI><CODE>rdef_err_msg</CODE> The error message from the compiler.</LI>
59 </UL>
61 <P>For more information about using librdef, see "rdef.h", which explains the available functions and data structures in more depth. For a real-world example, take a look at "rc.cpp", which contains the complete implementation of the rc compiler. As you'll see, there really isn't much to it, because librdef already does all the work.</P>
63 </BODY>
64 </HTML>