1/**
2 * @file rdef.h
3 *
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.
6 *
7 * @author Copyright (c) 2003 Matthijs Hollemans
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
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.
26 */
27
28#ifndef RDEF_H
29#define RDEF_H
30
31#include <OS.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37// bonefish: What was this needed for?
38//#if __i386__
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
47
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.
55 */
56#define RDEF_MERGE_RESOURCES  (1 << 0)
57
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.
66 */
67#define RDEF_AUTO_NAMES  (1 << 1)
68
69/** Error codes returned by the librdef functions. */
70enum {
71	/** Syntax error or other compiler error. */
72	RDEF_COMPILE_ERR = B_ERRORS_END + 1,
73
74	/** Could not find one of the input files. */
75	RDEF_FILE_NOT_FOUND,
76
77	/** One of the input files has nothing to decompile. */
78	RDEF_NO_RESOURCES,
79
80	/** Could not write the output file. */
81	RDEF_WRITE_ERR,
82
83	/* B_OK */
84	/* B_ERROR */
85	/* B_NO_MEMORY */
86};
87
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.
92 */
93_IMPEXP_RDEF extern status_t rdef_err;
94
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.
98 */
99_IMPEXP_RDEF extern int32 rdef_err_line;
100
101/**
102 * The file where the error occurred. This is an empty string if the
103 * error did not happen in a specific file.
104 */
105_IMPEXP_RDEF extern char rdef_err_file[];
106
107/**
108 * The error message from the compiler. This is an empty string if there
109 * was no additional information to report.
110 */
111_IMPEXP_RDEF extern char rdef_err_msg[];
112
113/**
114 * Returns the version number of the librdef API. You can use this to
115 * check which functions and variables are available.
116 */
117_IMPEXP_RDEF int32 rdef_get_version();
118
119/**
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.
123 */
124_IMPEXP_RDEF status_t rdef_add_include_dir(const char *dir, bool toEndOfList);
125
126/**	Removes an include directory */
127_IMPEXP_RDEF status_t rdef_remove_include_dir(const char *dir);
128
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.
132 */
133_IMPEXP_RDEF void rdef_free_include_dirs();
134
135/**
136 * Adds an input file for the compiler or decompiler. Input files are not
137 * required to have a specific extension.
138 */
139_IMPEXP_RDEF status_t rdef_add_input_file(const char* file);
140
141/**
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.
144 */
145_IMPEXP_RDEF void rdef_free_input_files();
146
147/** Changes the configuration of the compiler or decompiler. */
148_IMPEXP_RDEF void rdef_set_flags(uint32 flags);
149
150/** Resets all the configuration options to their default values. */
151_IMPEXP_RDEF void rder_clear_flags();
152
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().
157 */
158_IMPEXP_RDEF status_t rdef_compile(const char* output_file);
159
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.
167 */
168_IMPEXP_RDEF status_t rdef_decompile(const char* output_file);
169
170#ifdef __cplusplus
171}
172#endif
173
174#endif /* RDEF_H */
175