vfs: check userland buffers before reading them.
[haiku.git] / src / bin / rc / rdef.h
blob7d6d8cc923ca6097731385ad2ccf7482e04857a0
1 /**
2 * @file rdef.h
4 * Public header file for the librdef shared library. Programs that want to
5 * use librdef should include this file, and link to librdef.so.
7 * @author Copyright (c) 2003 Matthijs Hollemans
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
28 #ifndef RDEF_H
29 #define RDEF_H
31 #include <OS.h>
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
37 // bonefish: What was this needed for?
38 //#if __INTEL__
39 //# ifdef _BUILDING_RDEF
40 //# define _IMPEXP_RDEF __declspec(dllexport)
41 //# else
42 //# define _IMPEXP_RDEF __declspec(dllimport)
43 //# endif
44 //#else
45 # define _IMPEXP_RDEF
46 //#endif
48 /**
49 * Whether to overwrite or merge with the output file. With this flag, the
50 * compiler will add the resources to the output file (if it exists). When
51 * something goes wrong, the output file is not deleted (although it may
52 * already contain some of the new resources). The default action is to clobber
53 * the contents of the output file if it already existed, and the file is
54 * deleted in case of an error. Not used for decompiling.
56 #define RDEF_MERGE_RESOURCES (1 << 0)
58 /**
59 * Whether to generate resource names from symbolic identifiers, or vice versa.
60 * With this flag, the compiler will use symbolic names in statements such as
61 * "resource(R_Symbol)" to generate the resource name, in this case "R_Symbol".
62 * Otherwise, you must explicitly specify a name, such as "resource(R_Symbol,
63 * "Name") ..." If this option is set when decompiling, the decompiler will put
64 * resource names that are valid C/C++ identifiers in an enum statement in a
65 * new header file.
67 #define RDEF_AUTO_NAMES (1 << 1)
69 /** Error codes returned by the librdef functions. */
70 enum {
71 /** Syntax error or other compiler error. */
72 RDEF_COMPILE_ERR = B_ERRORS_END + 1,
74 /** Could not find one of the input files. */
75 RDEF_FILE_NOT_FOUND,
77 /** One of the input files has nothing to decompile. */
78 RDEF_NO_RESOURCES,
80 /** Could not write the output file. */
81 RDEF_WRITE_ERR,
83 /* B_OK */
84 /* B_ERROR */
85 /* B_NO_MEMORY */
88 /**
89 * The result of the most recent (de)compilation. B_OK if the operation
90 * was successful, a negative error code otherwise. This is the same as
91 * the value returned by any of the rdef_xxx functions.
93 _IMPEXP_RDEF extern status_t rdef_err;
95 /**
96 * The line number where compilation failed. Valid line numbers start
97 * at 1. This is 0 if the error did not happen on a specific line.
99 _IMPEXP_RDEF extern int32 rdef_err_line;
101 /**
102 * The file where the error occurred. This is an empty string if the
103 * error did not happen in a specific file.
105 _IMPEXP_RDEF extern char rdef_err_file[];
107 /**
108 * The error message from the compiler. This is an empty string if there
109 * was no additional information to report.
111 _IMPEXP_RDEF extern char rdef_err_msg[];
113 /**
114 * Returns the version number of the librdef API. You can use this to
115 * check which functions and variables are available.
117 _IMPEXP_RDEF int32 rdef_get_version();
120 * Adds a directory where the compiler will look for include files.
121 * Typically, you want to add the current directory to this list.
122 * Not used for decompilation.
124 _IMPEXP_RDEF status_t rdef_add_include_dir(const char *dir, bool toEndOfList);
126 /** Removes an include directory */
127 _IMPEXP_RDEF status_t rdef_remove_include_dir(const char *dir);
129 /**
130 * Frees the list of include directories. If you call rdef_add_include_dir(),
131 * you should always call rdef_free_include_dirs() when the compiler is done.
133 _IMPEXP_RDEF void rdef_free_include_dirs();
136 * Adds an input file for the compiler or decompiler. Input files are not
137 * required to have a specific extension.
139 _IMPEXP_RDEF status_t rdef_add_input_file(const char* file);
142 * Frees the list of input files. If you call rdef_add_input_file(), you
143 * should always call rdef_free_input_files() when the compiler is done.
145 _IMPEXP_RDEF void rdef_free_input_files();
147 /** Changes the configuration of the compiler or decompiler. */
148 _IMPEXP_RDEF void rdef_set_flags(uint32 flags);
150 /** Resets all the configuration options to their default values. */
151 _IMPEXP_RDEF void rder_clear_flags();
153 /**
154 * Invokes the rdef-to-rsrc compiler. Before you call rdef_compile(), you must
155 * have specified at least one input file with rdef_add_input_file(), and one
156 * include search path with rdef_add_include_dir().
158 _IMPEXP_RDEF status_t rdef_compile(const char* output_file);
160 /**
161 * Invokes the rsrc-to-rdef decompiler. Just as with rdef_compile(), you must
162 * first add at least one input file with rdef_add_input_file(). Include dirs
163 * are not necessary, because the decompiler does not use them. The decompiler
164 * writes at least an rdef script file. In addition, if the "auto names" option
165 * is enabled it also writes a C/C++ header file. If these files already exist,
166 * they will be overwritten.
168 _IMPEXP_RDEF status_t rdef_decompile(const char* output_file);
170 #ifdef __cplusplus
172 #endif
174 #endif /* RDEF_H */