-static void
-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+ICU_ENTRY_OFFSET, ".obj");
-
- if(options[4].doesOccur) {
- uprv_strcpy(entry+ICU_ENTRY_OFFSET, options[4].value);
- uprv_strcat(entry, "_dat");
- }
- /* 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=ICU_OBJECT_MACHINE_TYPE;
- 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 */
- uprv_strncpy((char *)objHeader.sections[0].Name, ".drectve", 8);
- 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 */
- uprv_strncpy((char *)objHeader.sections[1].Name, ".rdata", 6);
- 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) {
- uprv_strncpy((char *)symbols[0].N.ShortName, entry, entryLength);
- 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);