1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 1999-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: gennames.c
10 * tab size: 8 (not used)
13 * created on: 1999nov01
14 * created by: Markus W. Scherer
16 * This program reads a binary file and creates a C source code file
17 * with a byte array that contains the data of the binary file.
19 * 12/09/1999 weiv Added multiple file handling
22 #include "unicode/utypes.h"
24 #if U_PLATFORM_HAS_WIN32_API
26 # define WIN32_LEAN_AND_MEAN
35 #if U_PLATFORM_IS_LINUX_BASED && U_HAVE_ELF_H
41 # if defined(ELFCLASS64)
44 /* Old elf.h headers may not have EM_X86_64, or have EM_X8664 instead. */
48 # define ICU_ENTRY_OFFSET 0
53 #include "unicode/putil.h"
58 #include "unicode/uclean.h"
69 #ifdef CAN_GENERATE_OBJECTS
77 static UOption options
[]={
79 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
, UPRV_LENGTHOF(options
), 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-q or --quiet do not display warnings and progress\n"
122 "\t-n or --name symbol prefix, followed by the prefix\n"
123 "\t-e or --entrypoint entry point name, followed by the name (_dat will be appended)\n"
124 "\t-r or --revision Specify a version\n"
126 #ifdef CAN_GENERATE_OBJECTS
128 "\t-o or --object write a .obj file instead of .c\n"
129 "\t-m or --match-arch file.o match the architecture (CPU, 32/64 bits) of the specified .o\n"
130 "\t ELF format defaults to i386. Windows defaults to the native platform.\n");
133 "\t-f or --filename Specify an alternate base filename. (default: symbolname_typ)\n"
134 "\t-a or --assembly Create assembly file. (possible values are: ");
136 printAssemblyHeadersToStdErr();
138 const char *message
, *filename
;
139 /* TODO: remove void (*writeCode)(const char *, const char *); */
141 if(options
[kOptAssembly
].doesOccur
) {
142 message
="generating assembly code for %s\n";
143 writeCode
= CALL_WRITEASSEMBLY
;
144 /* TODO: remove writeCode=&writeAssemblyCode; */
146 if (!checkAssemblyHeaderName(options
[kOptAssembly
].value
)) {
148 "Assembly type \"%s\" is unknown.\n", options
[kOptAssembly
].value
);
152 #ifdef CAN_GENERATE_OBJECTS
153 else if(options
[kOptObject
].doesOccur
) {
154 message
="generating object code for %s\n";
155 writeCode
= CALL_WRITEOBJECT
;
156 /* TODO: remove writeCode=&writeObjectCode; */
161 message
="generating C code for %s\n";
162 writeCode
= CALL_WRITECCODE
;
163 /* TODO: remove writeCode=&writeCCode; */
165 if (options
[kOptQuiet
].doesOccur
) {
169 filename
=getLongPathname(argv
[argc
]);
171 fprintf(stdout
, message
, filename
);
175 case CALL_WRITECCODE
:
176 writeCCode(filename
, options
[kOptDestDir
].value
,
177 options
[kOptName
].doesOccur
? options
[kOptName
].value
: NULL
,
178 options
[kOptFilename
].doesOccur
? options
[kOptFilename
].value
: NULL
,
182 case CALL_WRITEASSEMBLY
:
183 writeAssemblyCode(filename
, options
[kOptDestDir
].value
,
184 options
[kOptEntryPoint
].doesOccur
? options
[kOptEntryPoint
].value
: NULL
,
185 options
[kOptFilename
].doesOccur
? options
[kOptFilename
].value
: NULL
,
189 #ifdef CAN_GENERATE_OBJECTS
190 case CALL_WRITEOBJECT
:
191 writeObjectCode(filename
, options
[kOptDestDir
].value
,
192 options
[kOptEntryPoint
].doesOccur
? options
[kOptEntryPoint
].value
: NULL
,
193 options
[kOptMatchArch
].doesOccur
? options
[kOptMatchArch
].value
: NULL
,
194 options
[kOptFilename
].doesOccur
? options
[kOptFilename
].value
: NULL
,
200 /* Should never occur. */
203 /* TODO: remove writeCode(filename, options[kOptDestDir].value); */