Program: cEnum2Java Author: Adrian Lanning Date: Sept. 08, 2004 This Java program handles converting c-style typedef'd enums into Java interfaces. This is very useful when integrating Java code with native libraries using JNI. A seperate Java Interface source file will be generated for each typedef'd enum found. Dependencies between enums will be handled correctly for enums WITHIN the same file. Dependencies on enum constants in seperate files will NOT be handled. You will have to manually fix the generated Java files yourself if you have cases where this occurs. First line of regex.txt will be used as regex to match against. If regex.txt file can not be found, class will use a default that I made which handles the formats specified below. See usage function for usage instructions. Note: Program will recursively process directories if a directory name is supplied as the target. Here's a quick breakdown of the important parts: suffixes global constant - used when determining which files to process regex.txt - regular expression to use when matching enums waveConfig.txt - config file for Wave preprocessor convertEnums - tracking of last constant values and handling of variable dependencies generateJavaEnumCode - template for how enum values are formatted in generated code preprocessFile - handles preprocessing the data processTargetFile - main driver function for conversion. handles processing file or directory Assumed format of c-style typedef enum input is: typedef enum { enum1, enum2, enum3 } NAME; More complex formats such as the following will also be handled correctly: typedef enum { enum1 = 3, enum2 = 0x6, enum3 = enum2 + enum1 } NAME; typdef enum { enum4 = enum1 + enum2; } NAME2; ** CASES THAT WILL NOT WORK ** The following formats will NOT currently work correctly: FAIL CASE 1: typedef enum { enum1 = 1, enum2 = 2, enum3 = enum2 + enum1, enum4 } NAME; In the above case, rather than "enum4" having the expected value of 4 (enum2 + enum1 + 1) it will be 3 (continued sequence from last specified numeral value). This isn't usually necessary so i left this out. Fix is not complicated. Just track enum constant values along with constant names. If you would like help implementing this feature, let me know. FAIL CASE 2 (may fail, see description): FILE 1: typedef enum { enum1 = 3, enum2 = 0x6, enum3 = enum2 + enum1 } NAME; FILE 2: typdef enum { enum4 = enum1 + enum2; } NAME2; This case may fail because dependencies are NOT tracked between files. HOWEVER, if you use the Wave preprocessor, it should include the necessary header files for you so this program SHOULD correctly reference the required Interface in that case. ACKNOWLEDGEMENTS Special thanks to Bob Friesenhahn for his many great posts to the JMagick mailing list and for helping to point me in the right direction with this program. CHANGELOG - Sept. 08, 2004 Initial release.