1999-11-20 01:12:28 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
2001-03-21 23:22:16 +00:00
|
|
|
* Copyright (C) 1999-2001, International Business Machines
|
1999-12-13 22:28:37 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
1999-11-20 01:12:28 +00:00
|
|
|
*******************************************************************************
|
|
|
|
* 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.
|
1999-12-12 02:33:22 +00:00
|
|
|
*
|
|
|
|
* 12/09/1999 weiv Added multiple file handling
|
1999-11-20 01:12:28 +00:00
|
|
|
*/
|
|
|
|
|
2000-05-03 23:08:20 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
1999-11-20 01:12:28 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.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"
|
2000-04-18 20:51:36 +00:00
|
|
|
#include "uoptions.h"
|
1999-11-20 01:12:28 +00:00
|
|
|
|
|
|
|
static uint16_t column=0xffff;
|
|
|
|
|
2001-11-11 07:45:58 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#define CAN_GENERATE_OBJECTS
|
|
|
|
#endif
|
|
|
|
|
1999-11-20 01:12:28 +00:00
|
|
|
/* prototypes --------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2000-04-18 20:51:36 +00:00
|
|
|
writeCCode(const char *filename, const char *destdir);
|
1999-11-20 01:12:28 +00:00
|
|
|
|
|
|
|
static void
|
2000-05-03 23:08:20 +00:00
|
|
|
writeObjectCode(const char *filename, const char *destdir);
|
|
|
|
|
|
|
|
static void
|
|
|
|
getOutFilename(const char *inFilename, const char *destdir, char *outFilename, char *entryName, const char *newSuffix);
|
1999-11-20 01:12:28 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
write8(FileStream *out, uint8_t byte);
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
|
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),
|
2002-03-16 02:26:17 +00:00
|
|
|
UOPTION_DEF( "entrypoint", 'e', UOPT_REQUIRES_ARG),
|
|
|
|
/*5*/ UOPTION_DEF( "revision", 'r', UOPT_REQUIRES_ARG),
|
2001-11-11 07:45:58 +00:00
|
|
|
#ifdef CAN_GENERATE_OBJECTS
|
2002-03-16 02:26:17 +00:00
|
|
|
/*6*/, UOPTION_DEF("object", 'o', UOPT_NO_ARG)
|
2001-11-11 07:45:58 +00:00
|
|
|
#endif
|
2000-12-06 03:02:21 +00:00
|
|
|
|
2000-04-18 20:51:36 +00:00
|
|
|
};
|
|
|
|
|
2000-08-30 23:58:24 +00:00
|
|
|
char symPrefix[100];
|
|
|
|
|
1999-11-20 01:12:28 +00:00
|
|
|
extern int
|
2000-09-21 21:49:32 +00:00
|
|
|
main(int argc, char* argv[]) {
|
2002-01-04 23:48:46 +00:00
|
|
|
UBool verbose = FALSE;
|
|
|
|
|
2002-03-15 23:41:40 +00:00
|
|
|
U_MAIN_INIT_ARGS(argc, argv);
|
|
|
|
|
2001-11-13 07:51:45 +00:00
|
|
|
options[2].value = ".";
|
|
|
|
|
2000-04-18 20:51:36 +00:00
|
|
|
/* read command line options */
|
|
|
|
argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
|
2002-03-16 02:26:17 +00:00
|
|
|
|
|
|
|
if( options[3].doesOccur ) /* be consistent with gencmn! */
|
2000-08-30 23:58:24 +00:00
|
|
|
{
|
2001-11-11 07:45:58 +00:00
|
|
|
uprv_strcpy(symPrefix, options[3].value);
|
2000-08-30 23:58:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
symPrefix[0] = 0;
|
|
|
|
}
|
2002-03-16 02:26:17 +00:00
|
|
|
|
|
|
|
if( options[5].doesOccur )
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int i;
|
|
|
|
uprv_strcat(symPrefix, options[5].value);
|
|
|
|
/* Convert non alpha numeric symbols to underscores */
|
|
|
|
|
|
|
|
/* turn dots in the entry name into underscores */
|
|
|
|
len=uprv_strlen(symPrefix);
|
|
|
|
for(i=0; i<len; ++i) {
|
|
|
|
if(symPrefix[i]=='.') {
|
|
|
|
symPrefix[i]='_';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add an underscore to the prefix if non empty */
|
|
|
|
if(symPrefix[0] != 0)
|
|
|
|
{
|
|
|
|
uprv_strcat(symPrefix, "_");
|
|
|
|
}
|
2000-08-30 23:58:24 +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]);
|
|
|
|
}
|
|
|
|
if(argc<0 || options[0].doesOccur || options[1].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"
|
|
|
|
"\t-e or --entrypoint entry point name, followed by the name\n"
|
2002-03-16 02:26:17 +00:00
|
|
|
"\t-r or --revision Specify a version\n"
|
2001-11-11 07:45:58 +00:00
|
|
|
#ifdef CAN_GENERATE_OBJECTS
|
2002-03-15 23:41:40 +00:00
|
|
|
"\t-o or --object write a .obj file instead of .c\n"
|
2001-11-11 07:45:58 +00:00
|
|
|
#endif
|
|
|
|
, argv[0]);
|
1999-11-20 01:12:28 +00:00
|
|
|
} else {
|
2000-05-03 23:08:20 +00:00
|
|
|
const char *message, *filename;
|
2001-03-27 22:59:41 +00:00
|
|
|
void (*writeCode)(const char *, const char *);
|
2001-11-11 07:45:58 +00:00
|
|
|
#ifdef CAN_GENERATE_OBJECTS
|
2002-03-16 02:26:17 +00:00
|
|
|
if(options[6].doesOccur) {
|
2002-01-04 23:48:46 +00:00
|
|
|
message="generating object code for %s\n";
|
2000-05-03 23:08:20 +00:00
|
|
|
writeCode=&writeObjectCode;
|
2001-11-11 07:45:58 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2002-01-04 23:48:46 +00:00
|
|
|
message="generating C code for %s\n";
|
2000-05-03 23:08:20 +00:00
|
|
|
writeCode=&writeCCode;
|
|
|
|
}
|
|
|
|
while(--argc) {
|
|
|
|
filename=getLongPathname(argv[argc]);
|
2002-01-04 23:48:46 +00:00
|
|
|
if (verbose) {
|
|
|
|
fprintf(stdout, message, filename);
|
|
|
|
}
|
1999-12-12 02:33:22 +00:00
|
|
|
column=0xffff;
|
2000-05-03 23:08:20 +00:00
|
|
|
writeCode(filename, options[2].value);
|
1999-12-12 02:33:22 +00:00
|
|
|
}
|
1999-11-20 01:12:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-04-18 20:51:36 +00:00
|
|
|
writeCCode(const char *filename, const char *destdir) {
|
1999-11-20 01:12:28 +00:00
|
|
|
char buffer[4096], entry[40];
|
|
|
|
FileStream *in, *out;
|
|
|
|
size_t i, length;
|
|
|
|
|
|
|
|
in=T_FileStream_open(filename, "rb");
|
|
|
|
if(in==NULL) {
|
|
|
|
fprintf(stderr, "genccode: unable to open input file %s\n", filename);
|
|
|
|
exit(U_FILE_ACCESS_ERROR);
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:08:20 +00:00
|
|
|
getOutFilename(filename, destdir, buffer, entry, ".c");
|
1999-11-20 01:12:28 +00:00
|
|
|
out=T_FileStream_open(buffer, "w");
|
|
|
|
if(out==NULL) {
|
|
|
|
fprintf(stderr, "genccode: unable to open output file %s\n", buffer);
|
|
|
|
exit(U_FILE_ACCESS_ERROR);
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:08:20 +00:00
|
|
|
/* turn dashes in the entry name into underscores */
|
|
|
|
length=uprv_strlen(entry);
|
|
|
|
for(i=0; i<length; ++i) {
|
|
|
|
if(entry[i]=='-') {
|
|
|
|
entry[i]='_';
|
1999-11-30 23:58:15 +00:00
|
|
|
}
|
2000-05-03 23:08:20 +00:00
|
|
|
}
|
1999-11-30 23:58:15 +00:00
|
|
|
|
2002-03-01 03:41:41 +00:00
|
|
|
/* Function renaming shouldn't be done in data */
|
2000-05-03 23:08:20 +00:00
|
|
|
sprintf(buffer,
|
2002-03-01 03:41:41 +00:00
|
|
|
"#define U_DISABLE_RENAMING 1\n"
|
|
|
|
"#include \"unicode/umachine.h\"\n"
|
2000-08-30 23:58:24 +00:00
|
|
|
"U_CDECL_BEGIN\n"
|
|
|
|
"const struct {\n"
|
2000-05-03 23:08:20 +00:00
|
|
|
" double bogus;\n"
|
|
|
|
" uint8_t bytes[%ld]; \n"
|
2002-03-01 03:41:41 +00:00
|
|
|
"} %s%s={ 0.0, {\n",
|
2001-03-27 22:59:41 +00:00
|
|
|
(long)T_FileStream_size(in), symPrefix, entry);
|
2000-05-03 23:08:20 +00:00
|
|
|
T_FileStream_writeLine(out, buffer);
|
1999-11-20 01:12:28 +00:00
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
length=T_FileStream_read(in, buffer, sizeof(buffer));
|
|
|
|
if(length==0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for(i=0; i<length; ++i) {
|
|
|
|
write8(out, (uint8_t)buffer[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-30 23:58:24 +00:00
|
|
|
T_FileStream_writeLine(out, "\n}\n};\nU_CDECL_END\n");
|
1999-11-20 01:12:28 +00:00
|
|
|
|
|
|
|
if(T_FileStream_error(in)) {
|
|
|
|
fprintf(stderr, "genccode: file read error while generating from file %s\n", filename);
|
|
|
|
exit(U_FILE_ACCESS_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(T_FileStream_error(out)) {
|
|
|
|
fprintf(stderr, "genccode: file write error while generating from file %s\n", filename);
|
|
|
|
exit(U_FILE_ACCESS_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
T_FileStream_close(out);
|
|
|
|
T_FileStream_close(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-05-03 23:08:20 +00:00
|
|
|
writeObjectCode(const char *filename, const char *destdir) {
|
|
|
|
#ifdef WIN32
|
|
|
|
char buffer[4096], entry[40];
|
|
|
|
struct {
|
|
|
|
IMAGE_FILE_HEADER fileHeader;
|
|
|
|
IMAGE_SECTION_HEADER sections[2];
|
|
|
|
char linkerOptions[100];
|
|
|
|
} objHeader;
|
|
|
|
IMAGE_SYMBOL symbols[1];
|
|
|
|
struct {
|
|
|
|
DWORD sizeofLongNames;
|
|
|
|
char longNames[100];
|
|
|
|
} symbolNames;
|
|
|
|
FileStream *in, *out;
|
|
|
|
size_t i, entryLength, length, size;
|
|
|
|
|
|
|
|
in=T_FileStream_open(filename, "rb");
|
|
|
|
if(in==NULL) {
|
|
|
|
fprintf(stderr, "genccode: unable to open input file %s\n", filename);
|
|
|
|
exit(U_FILE_ACCESS_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* entry have a leading '_' */
|
|
|
|
entry[0]='_';
|
|
|
|
getOutFilename(filename, destdir, buffer, entry+1, ".obj");
|
|
|
|
|
2001-11-11 07:45:58 +00:00
|
|
|
if(options[4].doesOccur) {
|
|
|
|
uprv_strcpy(entry+1, options[4].value);
|
2000-12-06 03:02:21 +00:00
|
|
|
uprv_strcat(entry, "_dat");
|
|
|
|
}
|
2000-05-03 23:08:20 +00:00
|
|
|
/* turn dashes in the entry name into underscores */
|
|
|
|
entryLength=uprv_strlen(entry);
|
|
|
|
for(i=0; i<entryLength; ++i) {
|
|
|
|
if(entry[i]=='-') {
|
|
|
|
entry[i]='_';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open the output file */
|
|
|
|
out=T_FileStream_open(buffer, "wb");
|
|
|
|
if(out==NULL) {
|
|
|
|
fprintf(stderr, "genccode: unable to open output file %s\n", buffer);
|
|
|
|
exit(U_FILE_ACCESS_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* populate the .obj headers */
|
|
|
|
uprv_memset(&objHeader, 0, sizeof(objHeader));
|
|
|
|
uprv_memset(&symbols, 0, sizeof(symbols));
|
|
|
|
uprv_memset(&symbolNames, 0, sizeof(symbolNames));
|
|
|
|
size=T_FileStream_size(in);
|
|
|
|
|
|
|
|
/* write the linker export directive */
|
|
|
|
uprv_strcpy(objHeader.linkerOptions, "-export:");
|
|
|
|
length=8;
|
|
|
|
uprv_strcpy(objHeader.linkerOptions+length, entry);
|
|
|
|
length+=entryLength;
|
|
|
|
uprv_strcpy(objHeader.linkerOptions+length, ",data ");
|
|
|
|
length+=6;
|
|
|
|
|
|
|
|
/* set the file header */
|
|
|
|
objHeader.fileHeader.Machine=IMAGE_FILE_MACHINE_I386;
|
|
|
|
objHeader.fileHeader.NumberOfSections=2;
|
|
|
|
objHeader.fileHeader.TimeDateStamp=time(NULL);
|
|
|
|
objHeader.fileHeader.PointerToSymbolTable=IMAGE_SIZEOF_FILE_HEADER+2*IMAGE_SIZEOF_SECTION_HEADER+length+size; /* start of symbol table */
|
|
|
|
objHeader.fileHeader.NumberOfSymbols=1;
|
|
|
|
|
|
|
|
/* set the section for the linker options */
|
2000-08-23 02:29:56 +00:00
|
|
|
uprv_strncpy((char *)objHeader.sections[0].Name, ".drectve", 8);
|
2000-05-03 23:08:20 +00:00
|
|
|
objHeader.sections[0].SizeOfRawData=length;
|
|
|
|
objHeader.sections[0].PointerToRawData=IMAGE_SIZEOF_FILE_HEADER+2*IMAGE_SIZEOF_SECTION_HEADER;
|
|
|
|
objHeader.sections[0].Characteristics=IMAGE_SCN_LNK_INFO|IMAGE_SCN_LNK_REMOVE|IMAGE_SCN_ALIGN_1BYTES;
|
|
|
|
|
|
|
|
/* set the data section */
|
2000-08-23 02:29:56 +00:00
|
|
|
uprv_strncpy((char *)objHeader.sections[1].Name, ".rdata", 6);
|
2000-05-03 23:08:20 +00:00
|
|
|
objHeader.sections[1].SizeOfRawData=size;
|
|
|
|
objHeader.sections[1].PointerToRawData=IMAGE_SIZEOF_FILE_HEADER+2*IMAGE_SIZEOF_SECTION_HEADER+length;
|
|
|
|
objHeader.sections[1].Characteristics=IMAGE_SCN_CNT_INITIALIZED_DATA|IMAGE_SCN_ALIGN_16BYTES|IMAGE_SCN_MEM_READ;
|
|
|
|
|
|
|
|
/* set the symbol table */
|
|
|
|
if(entryLength<=8) {
|
2000-08-23 02:29:56 +00:00
|
|
|
uprv_strncpy((char *)symbols[0].N.ShortName, entry, entryLength);
|
2000-05-03 23:08:20 +00:00
|
|
|
symbolNames.sizeofLongNames=4;
|
|
|
|
} else {
|
|
|
|
symbols[0].N.Name.Short=0;
|
|
|
|
symbols[0].N.Name.Long=4;
|
|
|
|
symbolNames.sizeofLongNames=4+entryLength+1;
|
|
|
|
uprv_strcpy(symbolNames.longNames, entry);
|
|
|
|
}
|
|
|
|
symbols[0].SectionNumber=2;
|
|
|
|
symbols[0].StorageClass=IMAGE_SYM_CLASS_EXTERNAL;
|
|
|
|
|
|
|
|
/* write the file header and the linker options section */
|
|
|
|
T_FileStream_write(out, &objHeader, objHeader.sections[1].PointerToRawData);
|
|
|
|
|
|
|
|
/* copy the data file into section 2 */
|
|
|
|
for(;;) {
|
|
|
|
length=T_FileStream_read(in, buffer, sizeof(buffer));
|
|
|
|
if(length==0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
T_FileStream_write(out, buffer, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write the symbol table */
|
|
|
|
T_FileStream_write(out, symbols, IMAGE_SIZEOF_SYMBOL);
|
|
|
|
T_FileStream_write(out, &symbolNames, symbolNames.sizeofLongNames);
|
|
|
|
|
|
|
|
if(T_FileStream_error(in)) {
|
|
|
|
fprintf(stderr, "genccode: file read error while generating from file %s\n", filename);
|
|
|
|
exit(U_FILE_ACCESS_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(T_FileStream_error(out)) {
|
|
|
|
fprintf(stderr, "genccode: file write error while generating from file %s\n", filename);
|
|
|
|
exit(U_FILE_ACCESS_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
T_FileStream_close(out);
|
|
|
|
T_FileStream_close(in);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
getOutFilename(const char *inFilename, const char *destdir, char *outFilename, char *entryName, const char *newSuffix) {
|
1999-12-28 23:57:50 +00:00
|
|
|
const char *basename=findBasename(inFilename), *suffix=uprv_strrchr(basename, '.');
|
1999-11-20 01:12:28 +00:00
|
|
|
|
|
|
|
/* copy path */
|
2000-04-18 20:51:36 +00:00
|
|
|
if(destdir!=NULL && *destdir!=0) {
|
|
|
|
do {
|
|
|
|
*outFilename++=*destdir++;
|
|
|
|
} while(*destdir!=0);
|
|
|
|
if(*(outFilename-1)!=U_FILE_SEP_CHAR) {
|
|
|
|
*outFilename++=U_FILE_SEP_CHAR;
|
|
|
|
}
|
|
|
|
inFilename=basename;
|
|
|
|
} else {
|
|
|
|
while(inFilename<basename) {
|
|
|
|
*outFilename++=*inFilename++;
|
|
|
|
}
|
1999-11-20 01:12:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(suffix==NULL) {
|
|
|
|
/* the filename does not have a suffix */
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_strcpy(entryName, inFilename);
|
|
|
|
uprv_strcpy(outFilename, inFilename);
|
2000-05-03 23:08:20 +00:00
|
|
|
uprv_strcat(outFilename, newSuffix);
|
1999-11-20 01:12:28 +00:00
|
|
|
} else {
|
|
|
|
/* copy basename */
|
|
|
|
while(inFilename<suffix) {
|
|
|
|
*outFilename++=*entryName++=*inFilename++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* replace '.' by '_' */
|
|
|
|
*outFilename++=*entryName++='_';
|
|
|
|
++inFilename;
|
|
|
|
|
|
|
|
/* copy suffix */
|
|
|
|
while(*inFilename!=0) {
|
|
|
|
*outFilename++=*entryName++=*inFilename++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*entryName=0;
|
|
|
|
|
|
|
|
/* add ".c" */
|
2000-05-03 23:08:20 +00:00
|
|
|
uprv_strcpy(outFilename, newSuffix);
|
1999-11-20 01:12:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
write8(FileStream *out, uint8_t byte) {
|
|
|
|
char s[4];
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
/* convert the byte value to a string */
|
|
|
|
if(byte>=100) {
|
2000-08-23 02:29:56 +00:00
|
|
|
s[i++]=(char)('0'+byte/100);
|
1999-11-20 01:12:28 +00:00
|
|
|
byte%=100;
|
|
|
|
}
|
1999-11-22 19:35:39 +00:00
|
|
|
if(i>0 || byte>=10) {
|
2000-08-23 02:29:56 +00:00
|
|
|
s[i++]=(char)('0'+byte/10);
|
1999-11-20 01:12:28 +00:00
|
|
|
byte%=10;
|
|
|
|
}
|
2000-08-23 02:29:56 +00:00
|
|
|
s[i++]=(char)('0'+byte);
|
1999-11-20 01:12:28 +00:00
|
|
|
s[i]=0;
|
|
|
|
|
|
|
|
/* write the value, possibly with comma and newline */
|
|
|
|
if(column==0xffff) {
|
|
|
|
/* first byte */
|
|
|
|
column=1;
|
|
|
|
} else if(column<16) {
|
|
|
|
T_FileStream_writeLine(out, ",");
|
|
|
|
++column;
|
|
|
|
} else {
|
|
|
|
T_FileStream_writeLine(out, ",\n");
|
|
|
|
column=1;
|
|
|
|
}
|
|
|
|
T_FileStream_writeLine(out, s);
|
|
|
|
}
|