2 *******************************************************************************
3 * Copyright (C) 1999-2013, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * file name: gennames.c
8 * tab size: 8 (not used)
11 * created on: 1999nov01
12 * created by: Markus W. Scherer
14 * This program reads a binary file and creates a C source code file
15 * with a byte array that contains the data of the binary file.
17 * 12/09/1999 weiv Added multiple file handling
20 #include "unicode/utypes.h"
22 #if U_PLATFORM_HAS_WIN32_API
24 # define WIN32_LEAN_AND_MEAN
33 #if U_PLATFORM_IS_LINUX_BASED && U_HAVE_ELF_H
39 # if defined(ELFCLASS64)
42 /* Old elf.h headers may not have EM_X86_64, or have EM_X8664 instead. */
46 # define ICU_ENTRY_OFFSET 0
51 #include "unicode/putil.h"
56 #include "unicode/uclean.h"
66 #ifdef CAN_GENERATE_OBJECTS
74 static UOption options[]={
76 UOPTION_HELP_QUESTION_MARK,
78 UOPTION_DEF("name", 'n', UOPT_REQUIRES_ARG),
79 UOPTION_DEF("entrypoint", 'e', UOPT_REQUIRES_ARG),
80 #ifdef CAN_GENERATE_OBJECTS
81 /*5*/UOPTION_DEF("object", 'o', UOPT_NO_ARG),
82 UOPTION_DEF("match-arch", 'm', UOPT_REQUIRES_ARG),
84 UOPTION_DEF("filename", 'f', UOPT_REQUIRES_ARG),
85 UOPTION_DEF("assembly", 'a', UOPT_REQUIRES_ARG)
88 #define CALL_WRITECCODE 'c'
89 #define CALL_WRITEASSEMBLY 'a'
90 #define CALL_WRITEOBJECT 'o'
92 main(int argc, char* argv[]) {
96 U_MAIN_INIT_ARGS(argc, argv);
98 options[kOptDestDir].value = ".";
100 /* read command line options */
101 argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
103 /* error handling, printing usage message */
106 "error in command line argument \"%s\"\n",
109 if(argc<0 || options[kOptHelpH].doesOccur || options[kOptHelpQuestionMark].doesOccur) {
111 "usage: %s [-options] filename1 filename2 ...\n"
112 "\tread each binary input file and \n"
113 "\tcreate a .c file with a byte array that contains the input file's data\n"
115 "\t-h or -? or --help this usage text\n"
116 "\t-d or --destdir destination directory, followed by the path\n"
117 "\t-n or --name symbol prefix, followed by the prefix\n"
118 "\t-e or --entrypoint entry point name, followed by the name (_dat will be appended)\n"
119 "\t-r or --revision Specify a version\n"
121 #ifdef CAN_GENERATE_OBJECTS
123 "\t-o or --object write a .obj file instead of .c\n"
124 "\t-m or --match-arch file.o match the architecture (CPU, 32/64 bits) of the specified .o\n"
125 "\t ELF format defaults to i386. Windows defaults to the native platform.\n");
128 "\t-f or --filename Specify an alternate base filename. (default: symbolname_typ)\n"
129 "\t-a or --assembly Create assembly file. (possible values are: ");
131 printAssemblyHeadersToStdErr();
133 const char *message, *filename;
134 /* TODO: remove void (*writeCode)(const char *, const char *); */
136 if(options[kOptAssembly].doesOccur) {
137 message="generating assembly code for %s\n";
138 writeCode = CALL_WRITEASSEMBLY;
139 /* TODO: remove writeCode=&writeAssemblyCode; */
141 if (!checkAssemblyHeaderName(options[kOptAssembly].value)) {
143 "Assembly type \"%s\" is unknown.\n", options[kOptAssembly].value);
147 #ifdef CAN_GENERATE_OBJECTS
148 else if(options[kOptObject].doesOccur) {
149 message="generating object code for %s\n";
150 writeCode = CALL_WRITEOBJECT;
151 /* TODO: remove writeCode=&writeObjectCode; */
156 message="generating C code for %s\n";
157 writeCode = CALL_WRITECCODE;
158 /* TODO: remove writeCode=&writeCCode; */
161 filename=getLongPathname(argv[argc]);
163 fprintf(stdout, message, filename);
167 case CALL_WRITECCODE:
168 writeCCode(filename, options[kOptDestDir].value,
169 options[kOptName].doesOccur ? options[kOptName].value : NULL,
170 options[kOptFilename].doesOccur ? options[kOptFilename].value : NULL,
173 case CALL_WRITEASSEMBLY:
174 writeAssemblyCode(filename, options[kOptDestDir].value,
175 options[kOptEntryPoint].doesOccur ? options[kOptEntryPoint].value : NULL,
176 options[kOptFilename].doesOccur ? options[kOptFilename].value : NULL,
179 #ifdef CAN_GENERATE_OBJECTS
180 case CALL_WRITEOBJECT:
181 writeObjectCode(filename, options[kOptDestDir].value,
182 options[kOptEntryPoint].doesOccur ? options[kOptEntryPoint].value : NULL,
183 options[kOptMatchArch].doesOccur ? options[kOptMatchArch].value : NULL,
184 options[kOptFilename].doesOccur ? options[kOptFilename].value : NULL,
189 /* Should never occur. */
192 /* TODO: remove writeCode(filename, options[kOptDestDir].value); */