void UPerfTest::init(UOption addOptions[], int32_t addOptionsCount, UErrorCode& status) { //initialize the argument list U_MAIN_INIT_ARGS(_argc, _argv); resolvedFileName = NULL; // add specific options int32_t optionsCount = OPTIONS_COUNT; if (addOptionsCount > 0) { memcpy(options+optionsCount, addOptions, addOptionsCount*sizeof(UOption)); optionsCount += addOptionsCount; } //parse the arguments _remainingArgc = u_parseArgs(_argc, (char**)_argv, optionsCount, options); // copy back values for additional options if (addOptionsCount > 0) { memcpy(addOptions, options+OPTIONS_COUNT, addOptionsCount*sizeof(UOption)); } // Now setup the arguments if(_argc==1 || options[HELP1].doesOccur || options[HELP2].doesOccur) { status = U_ILLEGAL_ARGUMENT_ERROR; return; } if(options[VERBOSE].doesOccur) { verbose = TRUE; } if(options[SOURCEDIR].doesOccur) { sourceDir = options[SOURCEDIR].value; } if(options[ENCODING].doesOccur) { encoding = options[ENCODING].value; } if(options[USELEN].doesOccur) { uselen = TRUE; } if(options[FILE_NAME].doesOccur){ fileName = options[FILE_NAME].value; } if(options[PASSES].doesOccur) { passes = atoi(options[PASSES].value); } if(options[ITERATIONS].doesOccur) { iterations = atoi(options[ITERATIONS].value); if(options[TIME].doesOccur) { status = U_ILLEGAL_ARGUMENT_ERROR; return; } } else if(options[TIME].doesOccur) { time = atoi(options[TIME].value); } else { iterations = 1000; // some default } if(options[LINE_MODE].doesOccur) { line_mode = TRUE; bulk_mode = FALSE; } if(options[BULK_MODE].doesOccur) { bulk_mode = TRUE; line_mode = FALSE; } if(options[LOCALE].doesOccur) { locale = options[LOCALE].value; } int32_t len = 0; if(fileName!=NULL){ //pre-flight ucbuf_resolveFileName(sourceDir, fileName, NULL, &len, &status); resolvedFileName = (char*) uprv_malloc(len); if(resolvedFileName==NULL){ status= U_MEMORY_ALLOCATION_ERROR; return; } if(status == U_BUFFER_OVERFLOW_ERROR){ status = U_ZERO_ERROR; } ucbuf_resolveFileName(sourceDir, fileName, resolvedFileName, &len, &status); ucharBuf = ucbuf_open(resolvedFileName,&encoding,TRUE,FALSE,&status); if(U_FAILURE(status)){ printf("Could not open the input file %s. Error: %s\n", fileName, u_errorName(status)); return; } } }
UPerfTest::UPerfTest(int32_t argc, const char* argv[], UErrorCode& status){ _argc = argc; _argv = argv; ucharBuf = NULL; encoding = ""; uselen = FALSE; fileName = NULL; sourceDir = "."; lines = NULL; numLines = 0; line_mode = TRUE; buffer = NULL; bufferLen = 0; verbose = FALSE; bulk_mode = FALSE; passes = iterations = time = 0; locale = NULL; //initialize the argument list U_MAIN_INIT_ARGS(argc, argv); //parse the arguments _remainingArgc = u_parseArgs(argc, (char**)argv, (int32_t)(sizeof(options)/sizeof(options[0])), options); // Now setup the arguments if(argc==1 || options[HELP1].doesOccur || options[HELP2].doesOccur) { status = U_ILLEGAL_ARGUMENT_ERROR; return; } if(options[VERBOSE].doesOccur) { verbose = TRUE; } if(options[SOURCEDIR].doesOccur) { sourceDir = options[SOURCEDIR].value; } if(options[ENCODING].doesOccur) { encoding = options[ENCODING].value; } if(options[USELEN].doesOccur) { uselen = TRUE; } if(options[FILE_NAME].doesOccur){ fileName = options[FILE_NAME].value; } if(options[PASSES].doesOccur) { passes = atoi(options[PASSES].value); } if(options[ITERATIONS].doesOccur) { iterations = atoi(options[ITERATIONS].value); } if(options[TIME].doesOccur) { time = atoi(options[TIME].value); } if(options[LINE_MODE].doesOccur) { line_mode = TRUE; bulk_mode = FALSE; } if(options[BULK_MODE].doesOccur) { bulk_mode = TRUE; line_mode = FALSE; } if(options[LOCALE].doesOccur) { locale = options[LOCALE].value; } if(time > 0 && iterations >0){ status = U_ILLEGAL_ARGUMENT_ERROR; return; } int32_t len = 0; resolvedFileName = NULL; if(fileName!=NULL){ //pre-flight ucbuf_resolveFileName(sourceDir, fileName,resolvedFileName,&len, &status); resolvedFileName = (char*) uprv_malloc(len); if(fileName==NULL){ status= U_MEMORY_ALLOCATION_ERROR; return; } if(status == U_BUFFER_OVERFLOW_ERROR){ status = U_ZERO_ERROR; } ucbuf_resolveFileName(sourceDir, fileName, resolvedFileName, &len, &status); ucharBuf = ucbuf_open(resolvedFileName,&encoding,TRUE,FALSE,&status); if(U_FAILURE(status)){ printf("Could not open the input file %s. Error: %s\n", fileName, u_errorName(status)); return; } } }