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