static int32_t pkg_executeOptions(UPKGOptions *o) { UErrorCode status = U_ZERO_ERROR; int32_t result = 0; // char cmd[SMALL_BUFFER_MAX_SIZE] = ""; const char mode = o->mode[0]; char targetDir[SMALL_BUFFER_MAX_SIZE] = ""; char tmpDir[SMALL_BUFFER_MAX_SIZE] = ""; char datFileName[SMALL_BUFFER_MAX_SIZE] = ""; char datFileNamePath[LARGE_BUFFER_MAX_SIZE] = ""; char checkLibFile[LARGE_BUFFER_MAX_SIZE] = ""; /* Initialize pkgdataFlags */ pkgDataFlags = (char**)uprv_malloc(sizeof(char*) * PKGDATA_FLAGS_SIZE); if (pkgDataFlags != NULL) { for (int32_t i = 0; i < PKGDATA_FLAGS_SIZE; i++) { pkgDataFlags[i] = (char*)uprv_malloc(sizeof(char) * SMALL_BUFFER_MAX_SIZE); if (pkgDataFlags[i] != NULL) { pkgDataFlags[i][0] = 0; } else { fprintf(stderr,"Error allocating memory for pkgDataFlags.\n"); return -1; } } } else { fprintf(stderr,"Error allocating memory for pkgDataFlags.\n"); return -1; } #ifndef WINDOWS_WITH_MSVC /* Read in options file. */ parseFlagsFile(o->options, pkgDataFlags, SMALL_BUFFER_MAX_SIZE, (int32_t)PKGDATA_FLAGS_SIZE, &status); if (U_FAILURE(status)) { fprintf(stderr,"Unable to open or read \"%s\" option file.\n", o->options); return -1; } #endif if (mode == MODE_FILES) { /* Copy the raw data to the installation directory. */ if (o->install != NULL) { uprv_strcpy(targetDir, o->install); if (o->shortName != NULL) { uprv_strcat(targetDir, PKGDATA_FILE_SEP_STRING); uprv_strcat(targetDir, o->shortName); } result = pkg_installFileMode(targetDir, o->srcDir, o->fileListFiles->str); } return result; } else /* if (mode == MODE_COMMON || mode == MODE_STATIC || mode == MODE_DLL) */ { uprv_strcpy(targetDir, o->targetDir); uprv_strcat(targetDir, PKGDATA_FILE_SEP_STRING); uprv_strcpy(tmpDir, o->tmpDir); uprv_strcat(tmpDir, PKGDATA_FILE_SEP_STRING); uprv_strcpy(datFileNamePath, tmpDir); uprv_strcpy(datFileName, o->shortName); uprv_strcat(datFileName, UDATA_CMN_SUFFIX); uprv_strcat(datFileNamePath, datFileName); result = writePackageDatFile(datFileNamePath, o->comment, o->srcDir, o->fileListFiles->str, NULL, U_IS_BIG_ENDIAN ? 'b' : 'l'); if (result != 0) { fprintf(stderr,"Error writing package dat file.\n"); return result; } if (mode == MODE_COMMON) { char targetFileNamePath[LARGE_BUFFER_MAX_SIZE] = ""; uprv_strcpy(targetFileNamePath, targetDir); uprv_strcat(targetFileNamePath, datFileName); if (T_FileStream_file_exists(targetFileNamePath)) { if ((result = remove(targetFileNamePath)) != 0) { fprintf(stderr, "Unable to remove old dat file: %s\n", targetFileNamePath); return result; } } /* Move the dat file created to the target directory. */ result = rename(datFileNamePath, targetFileNamePath); if (result != 0) { fprintf(stderr, "Unable to move dat file (%s) to target location (%s).\n", datFileNamePath, targetFileNamePath); } return result; } else /* if (mode[0] == MODE_STATIC || mode[0] == MODE_DLL) */ { char gencFilePath[SMALL_BUFFER_MAX_SIZE] = ""; char version_major[10] = ""; UBool reverseExt = FALSE; #ifndef WINDOWS_WITH_MSVC /* Get the version major number. */ if (o->version != NULL) { for (uint32_t i = 0;i < sizeof(version_major);i++) { if (o->version[i] == '.') { version_major[i] = 0; break; } version_major[i] = o->version[i]; } } #ifndef OS400 /* Certain platforms have different library extension ordering. (e.g. libicudata.##.so vs libicudata.so.##) * reverseExt is FALSE if the suffix should be the version number. */ if (pkgDataFlags[LIB_EXT_ORDER][uprv_strlen(pkgDataFlags[LIB_EXT_ORDER])-1] == pkgDataFlags[SO_EXT][uprv_strlen(pkgDataFlags[SO_EXT])-1]) { reverseExt = TRUE; } #endif /* Using the base libName and version number, generate the library file names. */ createFileNames(version_major, o->version, o->libName, reverseExt); if (o->version != 0 && o->rebuild == FALSE) { /* Check to see if a previous built data library file exists and check if it is the latest. */ sprintf(checkLibFile, "%s%s", targetDir, libFileNames[LIB_FILE_VERSION_TMP]); if (T_FileStream_file_exists(checkLibFile)) { if (isFileModTimeLater(checkLibFile, o->srcDir, TRUE) && isFileModTimeLater(checkLibFile, o->options)) { if (o->install != NULL) { uprv_strcpy(libFileNames[LIB_FILE_VERSION], libFileNames[LIB_FILE_VERSION_TMP]); result = pkg_installLibrary(o->install, targetDir); } return result; } } } pkg_checkFlag(o); #endif if (pkgDataFlags[GENCCODE_ASSEMBLY_TYPE][0] != 0) { const char* genccodeAssembly = pkgDataFlags[GENCCODE_ASSEMBLY_TYPE]; /* Offset genccodeAssembly by 3 because "-a " */ if (checkAssemblyHeaderName(genccodeAssembly+3)) { writeAssemblyCode(datFileNamePath, o->tmpDir, o->entryName, NULL, gencFilePath); result = pkg_createWithAssemblyCode(targetDir, mode, gencFilePath); if (result != 0) { fprintf(stderr, "Error generating assembly code for data.\n"); return result; } else if (mode == MODE_STATIC) { return result; } } else { fprintf(stderr,"Assembly type \"%s\" is unknown.\n", genccodeAssembly); return -1; } } else { #ifdef CAN_WRITE_OBJ_CODE writeObjectCode(datFileNamePath, o->tmpDir, o->entryName, NULL, NULL, gencFilePath); #ifdef U_LINUX result = pkg_generateLibraryFile(targetDir, mode, gencFilePath); #elif defined(WINDOWS_WITH_MSVC) return pkg_createWindowsDLL(mode, gencFilePath, o); #endif #elif defined(BUILD_DATA_WITHOUT_ASSEMBLY) result = pkg_createWithoutAssemblyCode(o, targetDir, mode); #endif if (result != 0) { fprintf(stderr, "Error generating package data.\n"); return result; } } #ifndef U_WINDOWS /* Certain platforms uses archive library. (e.g. AIX) */ result = pkg_archiveLibrary(targetDir, o->version, reverseExt); if (result != 0) { fprintf(stderr, "Error creating data archive library file.\n"); return result; } #ifndef OS400 /* Create symbolic links for the final library file. */ result = pkg_createSymLinks(targetDir); if (result != 0) { fprintf(stderr, "Error creating symbolic links of the data library file.\n"); return result; } #endif /* Install the libraries if option was set. */ if (o->install != NULL) { result = pkg_installLibrary(o->install, targetDir); if (result != 0) { fprintf(stderr, "Error installing the data library.\n"); return result; } } #endif } } return result; }
extern int main(int argc, char* argv[]) { UBool verbose = TRUE; char writeCode; U_MAIN_INIT_ARGS(argc, argv); options[kOptDestDir].value = "."; /* read command line options */ argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options); /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "error in command line argument \"%s\"\n", argv[-argc]); } if(argc<0 || options[kOptHelpH].doesOccur || options[kOptHelpQuestionMark].doesOccur) { fprintf(stderr, "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" "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 (_dat will be appended)\n" "\t-r or --revision Specify a version\n" , argv[0]); #ifdef CAN_GENERATE_OBJECTS fprintf(stderr, "\t-o or --object write a .obj file instead of .c\n" "\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"); #endif fprintf(stderr, "\t-f or --filename Specify an alternate base filename. (default: symbolname_typ)\n" "\t-a or --assembly Create assembly file. (possible values are: "); printAssemblyHeadersToStdErr(); } else { const char *message, *filename; /* TODO: remove void (*writeCode)(const char *, const char *); */ if(options[kOptAssembly].doesOccur) { message="generating assembly code for %s\n"; writeCode = CALL_WRITEASSEMBLY; /* TODO: remove writeCode=&writeAssemblyCode; */ if (!checkAssemblyHeaderName(options[kOptAssembly].value)) { fprintf(stderr, "Assembly type \"%s\" is unknown.\n", options[kOptAssembly].value); return -1; } } #ifdef CAN_GENERATE_OBJECTS else if(options[kOptObject].doesOccur) { message="generating object code for %s\n"; writeCode = CALL_WRITEOBJECT; /* TODO: remove writeCode=&writeObjectCode; */ } #endif else { message="generating C code for %s\n"; writeCode = CALL_WRITECCODE; /* TODO: remove writeCode=&writeCCode; */ } while(--argc) { filename=getLongPathname(argv[argc]); if (verbose) { fprintf(stdout, message, filename); } 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; #ifdef CAN_GENERATE_OBJECTS 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; } /* TODO: remove writeCode(filename, options[kOptDestDir].value); */ } } return 0; }