1999-11-20 01:12:28 +00:00
|
|
|
/*
|
2007-07-27 03:12:12 +00:00
|
|
|
*******************************************************************************
|
2008-11-24 20:04:52 +00:00
|
|
|
* Copyright (C) 1999-2008, International Business Machines
|
2007-07-27 03:12:12 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: gennames.c
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 1999nov01
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*
|
|
|
|
* This program reads a binary file and creates a C source code file
|
|
|
|
* with a byte array that contains the data of the binary file.
|
|
|
|
*
|
|
|
|
* 12/09/1999 weiv Added multiple file handling
|
|
|
|
*/
|
1999-11-20 01:12:28 +00:00
|
|
|
|
2005-02-17 00:19:44 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#ifdef U_WINDOWS
|
2002-03-28 18:26:25 +00:00
|
|
|
# define VC_EXTRALEAN
|
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
# define NOUSER
|
|
|
|
# define NOSERVICE
|
|
|
|
# define NOIME
|
|
|
|
# define NOMCX
|
2000-05-03 23:08:20 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <time.h>
|
2006-09-28 16:03:43 +00:00
|
|
|
#endif
|
2002-03-29 02:31:17 +00:00
|
|
|
|
2006-09-28 16:03:43 +00:00
|
|
|
#ifdef U_LINUX
|
|
|
|
# define U_ELF
|
2002-03-29 02:31:17 +00:00
|
|
|
#endif
|
|
|
|
|
2006-09-28 16:03:43 +00:00
|
|
|
#ifdef U_ELF
|
|
|
|
# include <elf.h>
|
|
|
|
# if defined(ELFCLASS64)
|
|
|
|
# define U_ELF64
|
|
|
|
# endif
|
|
|
|
/* Old elf.h headers may not have EM_X86_64, or have EM_X8664 instead. */
|
|
|
|
# ifndef EM_X86_64
|
|
|
|
# define EM_X86_64 62
|
|
|
|
# endif
|
|
|
|
# define ICU_ENTRY_OFFSET 0
|
2000-05-03 23:08:20 +00:00
|
|
|
#endif
|
|
|
|
|
1999-11-20 01:12:28 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-01-03 00:18:57 +00:00
|
|
|
#include "unicode/putil.h"
|
1999-11-20 01:12:28 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
|
|
|
#include "filestrm.h"
|
1999-11-23 04:49:35 +00:00
|
|
|
#include "toolutil.h"
|
2003-08-14 21:34:54 +00:00
|
|
|
#include "unicode/uclean.h"
|
2000-04-18 20:51:36 +00:00
|
|
|
#include "uoptions.h"
|
2008-11-24 20:04:52 +00:00
|
|
|
#include "pkg_genc.h"
|
1999-11-20 01:12:28 +00:00
|
|
|
|
2006-09-28 16:03:43 +00:00
|
|
|
#if defined(U_WINDOWS) || defined(U_ELF)
|
2001-11-11 07:45:58 +00:00
|
|
|
#define CAN_GENERATE_OBJECTS
|
|
|
|
#endif
|
|
|
|
|
2008-11-24 20:04:52 +00:00
|
|
|
enum {
|
2003-07-18 00:46:04 +00:00
|
|
|
kOptHelpH = 0,
|
|
|
|
kOptHelpQuestionMark,
|
|
|
|
kOptDestDir,
|
|
|
|
kOptName,
|
|
|
|
kOptEntryPoint,
|
|
|
|
#ifdef CAN_GENERATE_OBJECTS
|
|
|
|
kOptObject,
|
2006-09-28 16:03:43 +00:00
|
|
|
kOptMatchArch,
|
2003-07-18 00:46:04 +00:00
|
|
|
#endif
|
2004-02-27 22:54:23 +00:00
|
|
|
kOptFilename,
|
|
|
|
kOptAssembly
|
|
|
|
};
|
|
|
|
|
2000-04-18 20:51:36 +00:00
|
|
|
static UOption options[]={
|
2000-12-06 03:02:21 +00:00
|
|
|
/*0*/UOPTION_HELP_H,
|
|
|
|
UOPTION_HELP_QUESTION_MARK,
|
|
|
|
UOPTION_DESTDIR,
|
|
|
|
UOPTION_DEF("name", 'n', UOPT_REQUIRES_ARG),
|
2004-02-27 22:54:23 +00:00
|
|
|
UOPTION_DEF("entrypoint", 'e', UOPT_REQUIRES_ARG),
|
2001-11-11 07:45:58 +00:00
|
|
|
#ifdef CAN_GENERATE_OBJECTS
|
2003-07-18 21:55:53 +00:00
|
|
|
/*5*/UOPTION_DEF("object", 'o', UOPT_NO_ARG),
|
2006-09-28 16:03:43 +00:00
|
|
|
UOPTION_DEF("match-arch", 'm', UOPT_REQUIRES_ARG),
|
2001-11-11 07:45:58 +00:00
|
|
|
#endif
|
2004-02-27 22:54:23 +00:00
|
|
|
UOPTION_DEF("filename", 'f', UOPT_REQUIRES_ARG),
|
|
|
|
UOPTION_DEF("assembly", 'a', UOPT_REQUIRES_ARG)
|
2000-04-18 20:51:36 +00:00
|
|
|
};
|
|
|
|
|
2008-11-24 20:04:52 +00:00
|
|
|
#define CALL_WRITECCODE 'c'
|
|
|
|
#define CALL_WRITEASSEMBLY 'a'
|
|
|
|
#define CALL_WRITEOBJECT 'o'
|
1999-11-20 01:12:28 +00:00
|
|
|
extern int
|
2000-09-21 21:49:32 +00:00
|
|
|
main(int argc, char* argv[]) {
|
2002-03-21 17:09:52 +00:00
|
|
|
UBool verbose = TRUE;
|
2008-11-24 20:04:52 +00:00
|
|
|
char writeCode;
|
2002-01-04 23:48:46 +00:00
|
|
|
|
2002-03-15 23:41:40 +00:00
|
|
|
U_MAIN_INIT_ARGS(argc, argv);
|
|
|
|
|
2003-07-18 00:46:04 +00:00
|
|
|
options[kOptDestDir].value = ".";
|
2001-11-13 07:51:45 +00:00
|
|
|
|
2000-04-18 20:51:36 +00:00
|
|
|
/* read command line options */
|
|
|
|
argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
|
2006-09-28 16:03:43 +00:00
|
|
|
|
2000-04-18 20:51:36 +00:00
|
|
|
/* error handling, printing usage message */
|
|
|
|
if(argc<0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"error in command line argument \"%s\"\n",
|
|
|
|
argv[-argc]);
|
|
|
|
}
|
2003-07-18 00:46:04 +00:00
|
|
|
if(argc<0 || options[kOptHelpH].doesOccur || options[kOptHelpQuestionMark].doesOccur) {
|
1999-11-20 01:12:28 +00:00
|
|
|
fprintf(stderr,
|
2000-04-18 20:51:36 +00:00
|
|
|
"usage: %s [-options] filename1 filename2 ...\n"
|
|
|
|
"\tread each binary input file and \n"
|
|
|
|
"\tcreate a .c file with a byte array that contains the input file's data\n"
|
2002-03-15 23:41:40 +00:00
|
|
|
"options:\n"
|
|
|
|
"\t-h or -? or --help this usage text\n"
|
|
|
|
"\t-d or --destdir destination directory, followed by the path\n"
|
|
|
|
"\t-n or --name symbol prefix, followed by the prefix\n"
|
2006-09-28 16:03:43 +00:00
|
|
|
"\t-e or --entrypoint entry point name, followed by the name (_dat will be appended)\n"
|
2002-04-02 03:41:50 +00:00
|
|
|
"\t-r or --revision Specify a version\n"
|
2006-09-28 16:03:43 +00:00
|
|
|
, argv[0]);
|
2001-11-11 07:45:58 +00:00
|
|
|
#ifdef CAN_GENERATE_OBJECTS
|
2006-09-28 16:03:43 +00:00
|
|
|
fprintf(stderr,
|
2002-03-15 23:41:40 +00:00
|
|
|
"\t-o or --object write a .obj file instead of .c\n"
|
2006-09-28 16:03:43 +00:00
|
|
|
"\t-m or --match-arch file.o match the architecture (CPU, 32/64 bits) of the specified .o\n"
|
|
|
|
"\t ELF format defaults to i386. Windows defaults to the native platform.\n");
|
2001-11-11 07:45:58 +00:00
|
|
|
#endif
|
2004-02-27 22:54:23 +00:00
|
|
|
fprintf(stderr,
|
2006-09-28 16:03:43 +00:00
|
|
|
"\t-f or --filename Specify an alternate base filename. (default: symbolname_typ)\n"
|
2004-02-27 22:54:23 +00:00
|
|
|
"\t-a or --assembly Create assembly file. (possible values are: ");
|
|
|
|
|
2008-11-24 20:04:52 +00:00
|
|
|
printAssemblyHeadersToStdErr();
|
1999-11-20 01:12:28 +00:00
|
|
|
} else {
|
2000-05-03 23:08:20 +00:00
|
|
|
const char *message, *filename;
|
2008-11-24 20:04:52 +00:00
|
|
|
/* TODO: remove void (*writeCode)(const char *, const char *); */
|
2004-02-27 22:54:23 +00:00
|
|
|
|
|
|
|
if(options[kOptAssembly].doesOccur) {
|
|
|
|
message="generating assembly code for %s\n";
|
2008-11-24 20:04:52 +00:00
|
|
|
writeCode = CALL_WRITEASSEMBLY;
|
|
|
|
/* TODO: remove writeCode=&writeAssemblyCode; */
|
|
|
|
|
|
|
|
if (!checkAssemblyHeaderName(options[kOptAssembly].value)) {
|
2004-02-27 22:54:23 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Assembly type \"%s\" is unknown.\n", options[kOptAssembly].value);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2001-11-11 07:45:58 +00:00
|
|
|
#ifdef CAN_GENERATE_OBJECTS
|
2004-02-27 22:54:23 +00:00
|
|
|
else if(options[kOptObject].doesOccur) {
|
2002-01-04 23:48:46 +00:00
|
|
|
message="generating object code for %s\n";
|
2008-11-24 20:04:52 +00:00
|
|
|
writeCode = CALL_WRITEOBJECT;
|
|
|
|
/* TODO: remove writeCode=&writeObjectCode; */
|
2004-02-27 22:54:23 +00:00
|
|
|
}
|
2001-11-11 07:45:58 +00:00
|
|
|
#endif
|
2004-02-27 22:54:23 +00:00
|
|
|
else
|
2001-11-11 07:45:58 +00:00
|
|
|
{
|
2002-01-04 23:48:46 +00:00
|
|
|
message="generating C code for %s\n";
|
2008-11-24 20:04:52 +00:00
|
|
|
writeCode = CALL_WRITECCODE;
|
|
|
|
/* TODO: remove writeCode=&writeCCode; */
|
2000-05-03 23:08:20 +00:00
|
|
|
}
|
|
|
|
while(--argc) {
|
|
|
|
filename=getLongPathname(argv[argc]);
|
2002-01-04 23:48:46 +00:00
|
|
|
if (verbose) {
|
|
|
|
fprintf(stdout, message, filename);
|
|
|
|
}
|
1999-11-20 01:12:28 +00:00
|
|
|
|
2008-11-24 20:04:52 +00:00
|
|
|
switch (writeCode) {
|
|
|
|
case CALL_WRITECCODE:
|
|
|
|
writeCCode(filename, options[kOptDestDir].value,
|
|
|
|
options[kOptName].doesOccur ? options[kOptName].value : NULL,
|
|
|
|
options[kOptFilename].doesOccur ? options[kOptFilename].value : NULL,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
case CALL_WRITEASSEMBLY:
|
|
|
|
writeAssemblyCode(filename, options[kOptDestDir].value,
|
|
|
|
options[kOptEntryPoint].doesOccur ? options[kOptEntryPoint].value : NULL,
|
|
|
|
options[kOptFilename].doesOccur ? options[kOptFilename].value : NULL,
|
|
|
|
NULL);
|
|
|
|
break;
|
2003-05-02 20:12:55 +00:00
|
|
|
#ifdef CAN_GENERATE_OBJECTS
|
2008-11-24 20:04:52 +00:00
|
|
|
case CALL_WRITEOBJECT:
|
|
|
|
writeObjectCode(filename, options[kOptDestDir].value,
|
|
|
|
options[kOptEntryPoint].doesOccur ? options[kOptEntryPoint].value : NULL,
|
|
|
|
options[kOptMatchArch].doesOccur ? options[kOptMatchArch].value : NULL,
|
|
|
|
options[kOptFilename].doesOccur ? options[kOptFilename].value : NULL,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
/* Should never occur. */
|
|
|
|
break;
|
2002-05-30 23:46:30 +00:00
|
|
|
}
|
2008-11-24 20:04:52 +00:00
|
|
|
/* TODO: remove writeCode(filename, options[kOptDestDir].value); */
|
2003-07-18 00:46:04 +00:00
|
|
|
}
|
1999-11-20 01:12:28 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 20:04:52 +00:00
|
|
|
return 0;
|
2003-04-25 00:17:44 +00:00
|
|
|
}
|