2 *******************************************************************************
3 * Copyright (C) 1999-2008, 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"
24 # define WIN32_LEAN_AND_MEAN
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"
60 #if defined(U_WINDOWS) || defined(U_ELF)
61 #define CAN_GENERATE_OBJECTS
70 #ifdef CAN_GENERATE_OBJECTS
78 static UOption options
[]={
80 UOPTION_HELP_QUESTION_MARK
,
82 UOPTION_DEF("name", 'n', UOPT_REQUIRES_ARG
),
83 UOPTION_DEF("entrypoint", 'e', UOPT_REQUIRES_ARG
),
84 #ifdef CAN_GENERATE_OBJECTS
85 /*5*/UOPTION_DEF("object", 'o', UOPT_NO_ARG
),
86 UOPTION_DEF("match-arch", 'm', UOPT_REQUIRES_ARG
),
88 UOPTION_DEF("filename", 'f', UOPT_REQUIRES_ARG
),
89 UOPTION_DEF("assembly", 'a', UOPT_REQUIRES_ARG
)
92 #define CALL_WRITECCODE 'c'
93 #define CALL_WRITEASSEMBLY 'a'
94 #define CALL_WRITEOBJECT 'o'
96 main(int argc
, char* argv
[]) {
100 U_MAIN_INIT_ARGS(argc
, argv
);
102 options
[kOptDestDir
].value
= ".";
104 /* read command line options */
105 argc
=u_parseArgs(argc
, argv
, sizeof(options
)/sizeof(options
[0]), options
);
107 /* error handling, printing usage message */
110 "error in command line argument \"%s\"\n",
113 if(argc
<0 || options
[kOptHelpH
].doesOccur
|| options
[kOptHelpQuestionMark
].doesOccur
) {
115 "usage: %s [-options] filename1 filename2 ...\n"
116 "\tread each binary input file and \n"
117 "\tcreate a .c file with a byte array that contains the input file's data\n"
119 "\t-h or -? or --help this usage text\n"
120 "\t-d or --destdir destination directory, followed by the path\n"
121 "\t-n or --name symbol prefix, followed by the prefix\n"
122 "\t-e or --entrypoint entry point name, followed by the name (_dat will be appended)\n"
123 "\t-r or --revision Specify a version\n"
125 #ifdef CAN_GENERATE_OBJECTS
127 "\t-o or --object write a .obj file instead of .c\n"
128 "\t-m or --match-arch file.o match the architecture (CPU, 32/64 bits) of the specified .o\n"
129 "\t ELF format defaults to i386. Windows defaults to the native platform.\n");
132 "\t-f or --filename Specify an alternate base filename. (default: symbolname_typ)\n"
133 "\t-a or --assembly Create assembly file. (possible values are: ");
135 printAssemblyHeadersToStdErr();
137 const char *message
, *filename
;
138 /* TODO: remove void (*writeCode)(const char *, const char *); */
140 if(options
[kOptAssembly
].doesOccur
) {
141 message
="generating assembly code for %s\n";
142 writeCode
= CALL_WRITEASSEMBLY
;
143 /* TODO: remove writeCode=&writeAssemblyCode; */
145 if (!checkAssemblyHeaderName(options
[kOptAssembly
].value
)) {
147 "Assembly type \"%s\" is unknown.\n", options
[kOptAssembly
].value
);
151 #ifdef CAN_GENERATE_OBJECTS
152 else if(options
[kOptObject
].doesOccur
) {
153 message
="generating object code for %s\n";
154 writeCode
= CALL_WRITEOBJECT
;
155 /* TODO: remove writeCode=&writeObjectCode; */
160 message
="generating C code for %s\n";
161 writeCode
= CALL_WRITECCODE
;
162 /* TODO: remove writeCode=&writeCCode; */
165 filename
=getLongPathname(argv
[argc
]);
167 fprintf(stdout
, message
, filename
);
171 case CALL_WRITECCODE
:
172 writeCCode(filename
, options
[kOptDestDir
].value
,
173 options
[kOptName
].doesOccur
? options
[kOptName
].value
: NULL
,
174 options
[kOptFilename
].doesOccur
? options
[kOptFilename
].value
: NULL
,
177 case CALL_WRITEASSEMBLY
:
178 writeAssemblyCode(filename
, options
[kOptDestDir
].value
,
179 options
[kOptEntryPoint
].doesOccur
? options
[kOptEntryPoint
].value
: NULL
,
180 options
[kOptFilename
].doesOccur
? options
[kOptFilename
].value
: NULL
,
183 #ifdef CAN_GENERATE_OBJECTS
184 case CALL_WRITEOBJECT
:
185 writeObjectCode(filename
, options
[kOptDestDir
].value
,
186 options
[kOptEntryPoint
].doesOccur
? options
[kOptEntryPoint
].value
: NULL
,
187 options
[kOptMatchArch
].doesOccur
? options
[kOptMatchArch
].value
: NULL
,
188 options
[kOptFilename
].doesOccur
? options
[kOptFilename
].value
: NULL
,
193 /* Should never occur. */
196 /* TODO: remove writeCode(filename, options[kOptDestDir].value); */