// //{--MM-DD}[TimeZone] // 0123456 // void TimeVal::parseMonthDay() { initParser(); if (parser_context.fBuffer[0] != DATE_SEPARATOR || parser_context.fBuffer[1] != DATE_SEPARATOR || parser_context.fBuffer[4] != DATE_SEPARATOR ) { throw TimeValXMLParseErrorException("DateTime_gMthDay_invalid", parser_context.fBuffer); } //initialize parser_context.fValue[CentYear] = YEAR_DEFAULT; parser_context.fValue[Month] = parseInt(2, 4); parser_context.fValue[Day] = parseInt(5, 7); if ( MONTHDAY_SIZE < parser_context.fEnd ) { int sign = findUTCSign(MONTHDAY_SIZE); if ( sign<0 ) { throw TimeValXMLParseErrorException("DateTime_gMthDay_invalid",parser_context.fBuffer); } else { getTimeZone(sign); } } validateDateTime(); xmlnormalize(); }
int parseGame(const char *filename) { initParser(); if (!parseGameFile(filename)) { g_outputError("failed to parse game file %s\n", filename); return 0; } /* make sure a room named "start" exists */ if (NULL == g_hash_table_lookup(roomParsedTable, "start")) { g_outputError("room 'start' must be defined\n"); return 0; } initGlobalEvents(); initObjects(); initCreatures(); initRooms(); /* make sure we didn't have any issues parsing Lua scripts */ if (g_scriptError) { return 0; } destroyParser(); return 1; }
bool USOAPParser::parse(const UString& msg) { U_TRACE(0, "USOAPParser::parse(%.*S)", U_STRING_TO_TRACE(msg)) initParser(); if (UXMLParser::parse(msg)) { // If we succeeded, get the name of the method being called. This of course assumes only // one method in the body, and that there are no objects outside of the serialization root. // This method will need an override if this assumption is invalid U_INTERNAL_ASSERT_POINTER(body) method = body->childAt(0); envelope.methodName = method->elem()->getAccessorName(); // load the parameters for the method to execute UString param; for (uint32_t i = 0, num_arguments = method->numChild(); i < num_arguments; ++i) { param = method->childAt(i)->elem()->getValue(); // check if parameter optional if (param) envelope.arg->push_back(param); } U_RETURN(true); } U_RETURN(false); }
// // [-]{CCYY-MM-DD}[TimeZone] // void TimeVal::parseDate() { initParser(); getDate(); parseTimeZone(); validateDateTime(); xmlnormalize(); }
DOMDocument* XQillaBuilderImpl::parse(const DOMInputSource& source) { initParser(); Wrapper4DOMInputSource isWrapper((DOMInputSource*) &source, false, getMemoryManager()); AbstractDOMParser::parse(isWrapper); return getDocumentAndAddGrammar(); }
int main (void) { int fd = initMW(); ThinkGearStreamParser ctx; initParser(&ctx); #ifdef OUTPUT_UDP initUDP(); #endif int res, i, n; unsigned char bytes[BUFSIZE]; while (1) { n = read (fd, bytes, BUFSIZE); // read up to BUFSIZE bytes from the device if (n > 0) { #ifdef __DEBUG fprintf (stderr, "%i bytes read\n", n); #endif for (i = 0; i < n; i++) { res = THINKGEAR_parseByte(&ctx, bytes[i]); if (res < 0) { fprintf (stderr, "error parsing byte: %i\n", res); initParser(&ctx); continue; } control(); // output robot control char } } else if (n < 0) { fprintf (stderr, "error %d reading %s: %s\n", errno, MINDWAVEPORT, strerror (errno)); return (1); } usleep ((n * 100) + 1000); // sleep approx 100 uS per char transmit + 1kuS } return (0); }
void TimeVal::parseYearMonth() { initParser(); // get date getYearMonth(); parser_context.fValue[Day] = DAY_DEFAULT; parseTimeZone(); validateDateTime(); xmlnormalize(); }
// // [-]{CCYY-MM-DD}'T'{HH:MM:SS.MS}[TimeZone] // void TimeVal::parseDateTime() { initParser(); getDate(); //parser_context.fStart is supposed to point to 'T' if (parser_context.fBuffer[parser_context.fStart++] != DATETIME_SEPARATOR) throw TimeValXMLParseErrorException("DateTime_dt_missingT", parser_context.fBuffer); getTime(); validateDateTime(); xmlnormalize(); }
void TimeVal::parseTime() { initParser(); // time initialize to default values parser_context.fValue[CentYear]= YEAR_DEFAULT; parser_context.fValue[Month] = MONTH_DEFAULT; parser_context.fValue[Day] = DAY_DEFAULT; getTime(); validateDateTime(); xmlnormalize(); }
TimeVal::TimeVal (const std::string &s, const parseformat fmt) { struct tm conv; time_t res; memset(&parser_context,0,sizeof(parser_context)); reset(); setBuffer(s); initParser(); switch (fmt) { case XML_DATETIME: parseDateTime(); break; case XML_DURATION: parseDuration(); break; default: throw TimeValException("unknown XML TimeVal format"); break; } xmlnormalize(); memset(&conv,0,sizeof(conv)); conv.tm_sec = parser_context.fValue[Second]; conv.tm_min = parser_context.fValue[Minute]; conv.tm_hour= parser_context.fValue[Hour]; conv.tm_mday= parser_context.fValue[Day]; if (parser_context.fValue[Month] > 0) { conv.tm_mon = parser_context.fValue[Month]-1; } conv.tm_year = parser_context.fValue[CentYear]; if (conv.tm_year > 1900) conv.tm_year -= 1900; conv.tm_isdst = 0; if (fmt == XML_DURATION) { conv.tm_year += 70; // start of epoch added to the duration conv.tm_mday += 1; conv.tm_hour += 1; } tv_sec = mktime (&conv); tv_usec = parser_context.fValue[MiliSecond] * 1000; m_tz = gmt; // not give we get here, destructor does same thing to be sure }
static int load(Ejs *ep, EjsVar *thisObj, int argc, EjsVar **argv) { const char *fileName; XmlState *parser; Exml *xp; MprFile *file; if (argc != 1 || !ejsVarIsString(argv[0])) { ejsError(ep, EJS_ARG_ERROR, "Bad args. Usage: load(fileName);"); return -1; } fileName = argv[0]->string; /* FUTURE -- not romable Need rom code in MPR not MprServices */ file = mprOpen(ep, fileName, O_RDONLY, 0664); if (file == 0) { ejsError(ep, EJS_IO_ERROR, "Can't open: %s", fileName); return -1; } xp = initParser(ep, thisObj, fileName); parser = exmlGetParseArg(xp); exmlSetInputStream(xp, readFileData, (void*) file); if (exmlParse(xp) < 0) { if (! ejsGotException(ep)) { ejsError(ep, EJS_IO_ERROR, "Can't parse XML file: %s\nDetails %s", fileName, exmlGetErrorMsg(xp)); } termParser(xp); mprClose(file); return -1; } ejsSetReturnValue(ep, parser->nodeStack[0].obj); termParser(xp); mprClose(file); return 0; }
short parseJpVoc(const char* str,VocInfo vi) { pANTLR3_INPUT_STREAM input; pJpVocabularyLexer lxr; pANTLR3_COMMON_TOKEN_STREAM tstream; pJpVocabularyParser psr; ANTLR3_FPRINTF(stdout,"parseJpVoc:%s\n",str); input = antlr3StringStreamNew((pANTLR3_UINT8)str, ANTLR3_ENC_UTF8, strlen(str),(pANTLR3_UINT8)"jpVocabu"); initParser(&input,&lxr,&tstream,&psr); psr->vocabulary(psr,vi.pronun, vi.writing,vi.partOfSpeech,vi.expl); ANTLR3_FPRINTF(stdout,"parseJpVoc:pronun:%s\twriting:%s\tpartOfSpeech:%s\texpl:%s\n", vi.pronun,vi.writing,vi.partOfSpeech,vi.expl); cleanParser(&input,&lxr,&tstream,&psr); return 0; }
void traverseFullDepTree() { //postfl("->traverseFullDepTree\n"); fflush(stdout); gClassCompileOrderNum = 0; gClassCompileOrder = (ClassDependancy**)pyr_pool_compile->Alloc( gClassCompileOrderSize * sizeof(ClassDependancy)); MEMFAIL(gClassCompileOrder); // parse and compile all files initParser(); // sets compiler errors to 0 gParserResult = -1; traverseDepTree(s_object->classdep, 0); compileDepTree(); // compiles backwards using the order defined in gClassCompileOrder compileClassExtensions(); pyr_pool_compile->Free(gClassCompileOrder); finiParser(); //postfl("<-traverseFullDepTree\n"); fflush(stdout); }
// // {--MM--}[TimeZone] // {--MM}[TimeZone] // 012345 // void TimeVal::parseMonth() { initParser(); if (parser_context.fBuffer[0] != DATE_SEPARATOR || parser_context.fBuffer[1] != DATE_SEPARATOR ) { throw TimeValXMLParseErrorException("DateTime_gMth_invalid", parser_context.fBuffer); } //set constants parser_context.fValue[CentYear] = YEAR_DEFAULT; parser_context.fValue[Day] = DAY_DEFAULT; parser_context.fValue[Month] = parseInt(2, 4); // REVISIT: allow both --MM and --MM-- now. // need to remove the following lines to disallow --MM-- // when the errata is officially in the rec. parser_context.fStart = 4; if ( parser_context.fEnd >= parser_context.fStart+2 && parser_context.fBuffer[parser_context.fStart] == DATE_SEPARATOR && parser_context.fBuffer[parser_context.fStart+1] == DATE_SEPARATOR ) { parser_context.fStart += 2; } // // parse TimeZone if any // if ( parser_context.fStart < parser_context.fEnd ) { int sign = findUTCSign(parser_context.fStart); if ( sign < 0 ) { throw TimeValXMLParseErrorException("DateTime_gMth_invalid",parser_context.fBuffer); } else { getTimeZone(sign); } } validateDateTime(); xmlnormalize(); }
int main(int argc, char *argv[]) { char *fileName; printf("MILA interpreter\n"); if (argc == 1) { printf("Input from keyboard, write the source code terminated by a dot.\n"); fileName = NULL; } else { fileName = argv[1]; printf("Input file %s.\n", fileName); } if(!initParser(fileName)) { printf("Error creating the syntax analyzer.\n"); return 0; } Program(); closeInput(); Print(); Run(); freeSymbTab(); printf("End.\n"); return 0; }
// //[-]{CCYY}[TimeZone] // 0 1234 // void TimeVal::parseYear() { initParser(); // skip the first '-' and search for timezone // int sign = findUTCSign((parser_context.fBuffer[0] == '-') ? 1 : 0); if (sign == NOT_FOUND) { parser_context.fValue[CentYear] = parseIntYear(parser_context.fEnd); } else { parser_context.fValue[CentYear] = parseIntYear(sign); getTimeZone(sign); } //initialize values parser_context.fValue[Month] = MONTH_DEFAULT; parser_context.fValue[Day] = DAY_DEFAULT; //java is 1 validateDateTime(); xmlnormalize(); }
// Main entry point for this example // int ANTLR3_CDECL main(int argc, char *argv[]) { pANTLR3_UINT8 fName; pANTLR3_INPUT_STREAM input; pJpVocabularyLexer lxr; pANTLR3_COMMON_TOKEN_STREAM tstream; pJpVocabularyParser psr; if (argc < 2 || argv[1] == NULL) { //fName = (pANTLR3_UINT8) "./input"; // Note in VS2005 debug, working directory must be configured VocInfo vi; initVocInfo(&vi); short ret = parseJpVoc("あいかわらず(相変わらず)[副]照旧,依然", vi); printf("pronun:%s\twriting:%s\tpartOfSpeech:%s\texpl:%s\n", vi.pronun,vi.writing, vi.partOfSpeech,vi.expl); /*printf("pronun:%s\twriting:%s\tpartOfSpeech:%s\texpl:%s\n", emptyIfNull(vi.pronun),emptyIfNull(vi.writing), emptyIfNull(vi.partOfSpeech),emptyIfNull(vi.expl));*/ clearVocInfo(&vi); return 0; } else { fName = (pANTLR3_UINT8) argv[1]; } ANTLR3_FPRINTF(stdout,"\xE6\x85\x8C\xE3\x81\xA6\xE3\x81\xBE\xE3\x81\x99\n"); ANTLR3_FPRINTF(stdout,"input file name:%s\n",fName); //ANTLR3_ENC_8BIT, ANTLR3_ENC_UTF8, ANTLR3_ENC_UTF16 input = antlr3FileStreamNew(fName, ANTLR3_ENC_UTF8); initParser(&input,&lxr,&tstream,&psr); psr->voclist(psr); cleanParser(&input,&lxr,&tstream,&psr); return 0; }
// Converts the given EU3 save into a V2 mod. // Returns 0 on success or a non-zero failure code on error. int ConvertEU3ToV2(const std::string& EU3SaveFileName) { Object* obj; // generic object ifstream read; // ifstream for reading files char curDir[MAX_PATH]; GetCurrentDirectory(MAX_PATH, curDir); LOG(LogLevel::Debug) << "Current directory is " << curDir; Configuration::getInstance(); //Get V2 install location LOG(LogLevel::Info) << "Get V2 Install Path"; string V2Loc = Configuration::getV2Path(); struct _stat st; if (V2Loc.empty() || (_stat(V2Loc.c_str(), &st) != 0)) { LOG(LogLevel::Error) << "No Victoria 2 path was specified in configuration.txt, or the path was invalid"; return (-1); } else { LOG(LogLevel::Debug) << "Victoria 2 install path is " << V2Loc; } // Get V2 Documents Directory LOG(LogLevel::Debug) << "Get V2 Documents directory"; string V2DocLoc = Configuration::getV2DocumentsPath(); if (V2DocLoc.empty() || (_stat(V2DocLoc.c_str(), &st) != 0)) { LOG(LogLevel::Error) << "No Victoria 2 documents directory was specified in configuration.txt, or the path was invalid"; return (-1); } else { LOG(LogLevel::Debug) << "Victoria 2 documents directory is " << V2DocLoc; } //Get EU3 install location LOG(LogLevel::Debug) << "Get EU3 Install Path"; string EU3Loc = Configuration::getEU3Path(); if (EU3Loc.empty() || (_stat(EU3Loc.c_str(), &st) != 0)) { LOG(LogLevel::Error) << "No Europa Universalis 3 path was specified in configuration.txt, or the path was invalid"; return (-1); } else { LOG(LogLevel::Debug) << "EU3 install path is " << EU3Loc; } // Get EU3 Mod LOG(LogLevel::Debug) << "Get EU3 Mod"; string fullModPath; string modName = Configuration::getEU3Mod(); if (modName != "") { fullModPath = EU3Loc + "\\mod\\" + modName; if (fullModPath.empty() || (_stat(fullModPath.c_str(), &st) != 0)) { LOG(LogLevel::Error) << modName << " could not be found at the specified directory. A valid path and mod must be specified."; return (-1); } else { LOG(LogLevel::Debug) << "EU3 Mod directory is " << fullModPath; } } //get output name const int slash = EU3SaveFileName.find_last_of("\\"); // the last slash in the save's filename string outputName = EU3SaveFileName.substr(slash + 1, EU3SaveFileName.length()); const int length = outputName.find_first_of("."); // the first period after the slash outputName = outputName.substr(0, length); // the name to use to output the mod int dash = outputName.find_first_of('-'); while (dash != string::npos) { outputName.replace(dash, 1, "_"); dash = outputName.find_first_of('-'); } int space = outputName.find_first_of(' '); while (space != string::npos) { outputName.replace(space, 1, "_"); space = outputName.find_first_of(' '); } Configuration::setOutputName(outputName); LOG(LogLevel::Info) << "Using output name " << outputName; LOG(LogLevel::Info) << "* Importing EU3 save *"; // Parse EU3 Save LOG(LogLevel::Info) << "Parsing save"; obj = doParseFile(EU3SaveFileName.c_str()); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file " << EU3SaveFileName; exit(-1); } // Read all localisations. LOG(LogLevel::Info) << "Reading localisation"; EU3Localisation localisation; localisation.ReadFromAllFilesInFolder(Configuration::getEU3Path() + "\\localisation"); if (!fullModPath.empty()) { LOG(LogLevel::Debug) << "Reading mod localisation"; localisation.ReadFromAllFilesInFolder(fullModPath + "\\localisation"); } // Construct world from EU3 save. LOG(LogLevel::Info) << "Building world"; EU3World sourceWorld(obj); // Read EU3 common\countries LOG(LogLevel::Info) << "Reading EU3 common\\countries"; { ifstream commonCountries(Configuration::getEU3Path() + "\\common\\countries.txt"); sourceWorld.readCommonCountries(commonCountries, Configuration::getEU3Path()); if (!fullModPath.empty()) { ifstream convertedCommonCountries(fullModPath + "\\common\\countries.txt"); sourceWorld.readCommonCountries(convertedCommonCountries, fullModPath); } } // Figure out what EU3 gametype we're using WorldType game = sourceWorld.getWorldType(); switch (game) { case VeryOld: LOG(LogLevel::Error) << "EU3 game appears to be from an old version; only IN, HttT, and DW are supported."; exit(1); case InNomine: LOG(LogLevel::Info) << "Game type is: EU3 In Nomine. EXPERIMENTAL."; break; case HeirToTheThrone: LOG(LogLevel::Info) << "Game type is: EU3 Heir to the Throne."; break; case DivineWind: LOG(LogLevel::Info) << "Game type is: EU3 Divine Wind."; break; default: LOG(LogLevel::Error) << "Error: Could not determine savegame type."; exit(1); } sourceWorld.setLocalisations(localisation); // Resolve unit types LOG(LogLevel::Info) << "Resolving unit types."; RegimentTypeMap rtm; read.open("unit_strength.txt"); if (read.is_open()) { read.close(); read.clear(); LOG(LogLevel::Info) << "\tReading unit strengths from unit_strength.txt"; obj = doParseFile("unit_strength.txt"); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file unit_strength.txt"; exit(-1); } for (int i = 0; i < num_reg_categories; ++i) { AddCategoryToRegimentTypeMap(obj, (RegimentCategory)i, RegimentCategoryNames[i], rtm); } } else { LOG(LogLevel::Info) << "Reading unit strengths from EU3 installation folder"; struct _finddata_t unitFileData; intptr_t fileListing; if ( (fileListing = _findfirst( (EU3Loc + "\\common\\units\\*.txt").c_str(), &unitFileData)) == -1L) { LOG(LogLevel::Info) << "Could not open units directory."; return -1; } do { if (strcmp(unitFileData.name, ".") == 0 || strcmp(unitFileData.name, "..") == 0 ) { continue; } string unitFilename = unitFileData.name; string unitName = unitFilename.substr(0, unitFilename.find_first_of('.')); AddUnitFileToRegimentTypeMap((EU3Loc + "\\common\\units"), unitName, rtm); } while(_findnext(fileListing, &unitFileData) == 0); _findclose(fileListing); } read.close(); read.clear(); sourceWorld.resolveRegimentTypes(rtm); // Merge nations LOG(LogLevel::Info) << "Merging nations."; obj = doParseFile("merge_nations.txt"); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file merge_nations.txt"; exit(-1); } mergeNations(sourceWorld, obj); // Parse V2 input file LOG(LogLevel::Info) << "Parsing Vicky2 data"; vector<pair<string, string>> minorityPops; minorityPops.push_back(make_pair("ashkenazi","jewish")); minorityPops.push_back(make_pair("sephardic","jewish")); minorityPops.push_back(make_pair("","jewish")); V2World destWorld(minorityPops); // Construct factory factory LOG(LogLevel::Info) << "Determining factory allocation rules."; V2FactoryFactory factoryBuilder; // Parse province mappings LOG(LogLevel::Info) << "Parsing province mappings"; obj = doParseFile("province_mappings.txt"); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file province_mappings.txt"; exit(-1); } provinceMapping provinceMap; inverseProvinceMapping inverseProvinceMap; resettableMap resettableProvinces; initProvinceMap(obj, sourceWorld.getWorldType(), provinceMap, inverseProvinceMap, resettableProvinces); sourceWorld.checkAllProvincesMapped(inverseProvinceMap); sourceWorld.setEU3WorldProvinceMappings(inverseProvinceMap); // Get country mappings LOG(LogLevel::Info) << "Getting country mappings"; CountryMapping countryMap; countryMap.ReadRules("country_mappings.txt"); // Get adjacencies LOG(LogLevel::Info) << "Importing adjacencies"; adjacencyMapping adjacencyMap = initAdjacencyMap(); // Generate continent mapping LOG(LogLevel::Info) << "Finding Continents"; string EU3Mod = Configuration::getEU3Mod(); continentMapping continentMap; if (EU3Mod != "") { string continentFile = Configuration::getEU3Path() + "\\mod\\" + EU3Mod + "\\map\\continent.txt"; if ((_stat(continentFile.c_str(), &st) == 0)) { obj = doParseFile(continentFile.c_str()); if ((obj != NULL) && (obj->getLeaves().size() > 0)) { initContinentMap(obj, continentMap); } } } if (continentMap.size() == 0) { obj = doParseFile((EU3Loc + "\\map\\continent.txt").c_str()); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file " << EU3Loc << "\\map\\continent.txt"; exit(-1); } if (obj->getLeaves().size() < 1) { LOG(LogLevel::Error) << "Failed to parse continent.txt"; return 1; } initContinentMap(obj, continentMap); } if (continentMap.size() == 0) { LOG(LogLevel::Warning) << "No continent mappings found - may lead to problems later"; } // Generate region mapping LOG(LogLevel::Info) << "Parsing region structure"; if (_stat(".\\blankMod\\output\\map\\region.txt", &st) == 0) { obj = doParseFile(".\\blankMod\\output\\map\\region.txt"); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file .\\blankMod\\output\\map\\region.txt"; exit(-1); } } else { obj = doParseFile((V2Loc + "\\map\\region.txt").c_str()); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file " << V2Loc << "\\map\\region.txt"; exit(-1); } } if (obj->getLeaves().size() < 1) { LOG(LogLevel::Error) << "Could not parse region.txt"; return 1; } stateMapping stateMap; stateIndexMapping stateIndexMap; initStateMap(obj, stateMap, stateIndexMap); // Parse Culture Mappings LOG(LogLevel::Info) << "Parsing culture mappings"; obj = doParseFile("cultureMap.txt"); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file cultureMap.txt"; exit(-1); } if (obj->getLeaves().size() < 1) { LOG(LogLevel::Error) << "Failed to parse cultureMap.txt"; return 1; } cultureMapping cultureMap; cultureMap = initCultureMap(obj->getLeaves()[0]); obj = doParseFile("slaveCultureMap.txt"); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file slaveCultureMap.txt"; exit(-1); } if (obj->getLeaves().size() < 1) { LOG(LogLevel::Error) << "Failed to parse slaveCultureMap.txt"; return 1; } cultureMapping slaveCultureMap; slaveCultureMap = initCultureMap(obj->getLeaves()[0]); unionCulturesMap unionCultures; inverseUnionCulturesMap inverseUnionCultures; if (EU3Mod != "") { string modCultureFile = Configuration::getEU3Path() + "\\mod\\" + EU3Mod + "\\common\\cultures.txt"; if ((_stat(modCultureFile.c_str(), &st) == 0)) { obj = doParseFile(modCultureFile.c_str()); if ((obj != NULL) && (obj->getLeaves().size() > 0)) { initUnionCultures(obj, unionCultures, inverseUnionCultures); } } } if (unionCultures.size() == 0) { obj = doParseFile((EU3Loc + "\\common\\cultures.txt").c_str()); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file " << EU3Loc << "\\common\\cultures.txt"; exit(-1); } initUnionCultures(obj, unionCultures, inverseUnionCultures); } sourceWorld.checkAllEU3CulturesMapped(cultureMap, inverseUnionCultures); // Parse EU3 Religions LOG(LogLevel::Info) << "Parsing EU3 religions"; bool parsedReligions = false; if (EU3Mod != "") { string modReligionFile = Configuration::getEU3Path() + "\\mod\\" + EU3Mod + "\\common\\religion.txt"; if ((_stat(modReligionFile.c_str(), &st) == 0)) { obj = doParseFile(modReligionFile.c_str()); if ((obj != NULL) && (obj->getLeaves().size() > 0)) { EU3Religion::parseReligions(obj); parsedReligions = true; } } } if (!parsedReligions) { obj = doParseFile((EU3Loc + "\\common\\religion.txt").c_str()); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file " << EU3Loc << "\\common\\religion.txt"; exit(-1); } if (obj->getLeaves().size() < 1) { LOG(LogLevel::Error) << "Failed to parse religion.txt."; return 1; } EU3Religion::parseReligions(obj); } // Parse Religion Mappings LOG(LogLevel::Info) << "Parsing religion mappings"; obj = doParseFile("religionMap.txt"); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file religionMap.txt"; exit(-1); } if (obj->getLeaves().size() < 1) { LOG(LogLevel::Error) << "Failed to parse religionMap.txt"; return 1; } religionMapping religionMap; religionMap = initReligionMap(obj->getLeaves()[0]); sourceWorld.checkAllEU3ReligionsMapped(religionMap); //Parse unions mapping LOG(LogLevel::Info) << "Parsing union mappings"; obj = doParseFile("unions.txt"); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file unions.txt"; exit(-1); } if (obj->getLeaves().size() < 1) { LOG(LogLevel::Error) << "Failed to parse unions.txt"; return 1; } unionMapping unionMap; unionMap = initUnionMap(obj->getLeaves()[0]); //Parse government mapping LOG(LogLevel::Info) << "Parsing governments mappings"; initParser(); obj = doParseFile("governmentMapping.txt"); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file governmentMapping.txt"; exit(-1); } governmentMapping governmentMap; governmentMap = initGovernmentMap(obj->getLeaves()[0]); //Parse tech schools LOG(LogLevel::Info) << "Parsing tech schools."; initParser(); obj = doParseFile("blocked_tech_schools.txt"); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file blocked_tech_schools.txt"; exit(-1); } vector<string> blockedTechSchools; blockedTechSchools = initBlockedTechSchools(obj); initParser(); obj = doParseFile( (V2Loc + "\\common\\technology.txt").c_str() ); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file " << V2Loc << "\\common\\technology.txt"; exit(-1); } vector<techSchool> techSchools; techSchools = initTechSchools(obj, blockedTechSchools); // Get Leader traits LOG(LogLevel::Info) << "Getting leader traits"; V2LeaderTraits lt; map<int, int> leaderIDMap; // <EU3, V2> // Parse EU4 Regions LOG(LogLevel::Info) << "Parsing EU4 regions"; obj = doParseFile((EU3Loc + "\\map\\region.txt").c_str()); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file " << EU3Loc << "\\map\\region.txt"; exit(-1); } if (obj->getLeaves().size() < 1) { LOG(LogLevel::Error) << "Failed to parse region.txt"; return 1; } EU3RegionsMapping EU3RegionsMap; initEU3RegionMap(obj, EU3RegionsMap); if (EU3Mod != "") { string modRegionFile = Configuration::getEU3Path() + "\\mod\\" + EU3Mod + "\\map\\region.txt"; if ((_stat(modRegionFile.c_str(), &st) == 0)) { obj = doParseFile(modRegionFile.c_str()); if (obj == NULL) { LOG(LogLevel::Error) << "Could not parse file " << modRegionFile; exit(-1); } EU3Religion::parseReligions(obj); } } // Create Country Mapping removeEmptyNations(sourceWorld); if (Configuration::getRemovetype() == "dead") { removeDeadLandlessNations(sourceWorld); } else if (Configuration::getRemovetype() == "all") { removeLandlessNations(sourceWorld); } countryMap.CreateMapping(sourceWorld, destWorld); // Convert LOG(LogLevel::Info) << "Converting countries"; destWorld.convertCountries(sourceWorld, countryMap, cultureMap, unionCultures, religionMap, governmentMap, inverseProvinceMap, techSchools, leaderIDMap, lt, EU3RegionsMap); destWorld.scalePrestige(); LOG(LogLevel::Info) << "Converting provinces"; destWorld.convertProvinces(sourceWorld, provinceMap, resettableProvinces, countryMap, cultureMap, slaveCultureMap, religionMap, stateIndexMap, EU3RegionsMap); LOG(LogLevel::Info) << "Converting diplomacy"; destWorld.convertDiplomacy(sourceWorld, countryMap); LOG(LogLevel::Info) << "Setting colonies"; destWorld.setupColonies(adjacencyMap, continentMap); LOG(LogLevel::Info) << "Creating states"; destWorld.setupStates(stateMap); LOG(LogLevel::Info) << "Setting unciv reforms"; destWorld.convertUncivReforms(); LOG(LogLevel::Info) << "Converting techs"; destWorld.convertTechs(sourceWorld); LOG(LogLevel::Info) << "Allocating starting factories"; destWorld.allocateFactories(sourceWorld, factoryBuilder); LOG(LogLevel::Info) << "Creating pops"; destWorld.setupPops(sourceWorld); LOG(LogLevel::Info) << "Adding unions"; destWorld.addUnions(unionMap); LOG(LogLevel::Info) << "Converting armies and navies"; destWorld.convertArmies(sourceWorld, inverseProvinceMap, leaderIDMap, adjacencyMap); // Output results LOG(LogLevel::Info) << "Outputting mod"; system("%systemroot%\\System32\\xcopy blankMod output /E /Q /Y /I"); FILE* modFile; if (fopen_s(&modFile, ("Output\\" + Configuration::getOutputName() + ".mod").c_str(), "w") != 0) { LOG(LogLevel::Error) << "Could not create .mod file"; exit(-1); } fprintf(modFile, "name = \"Converted - %s\"\n", Configuration::getOutputName().c_str()); fprintf(modFile, "path = \"mod/%s\"\n", Configuration::getOutputName().c_str()); fprintf(modFile, "user_dir = \"%s\"\n", Configuration::getOutputName().c_str()); fprintf(modFile, "replace = \"history/provinces\"\n"); fprintf(modFile, "replace = \"history/countries\"\n"); fprintf(modFile, "replace = \"history/diplomacy\"\n"); fprintf(modFile, "replace = \"history/units\"\n"); fprintf(modFile, "replace = \"history/pops/1836.1.1\"\n"); fprintf(modFile, "replace = \"common/religion.txt\"\n"); fprintf(modFile, "replace = \"common/cultures.txt\"\n"); fprintf(modFile, "replace = \"gfx/interface/icon_religion.dds\"\n"); fprintf(modFile, "replace = \"localisation/text.csv\"\n"); fprintf(modFile, "replace = \"localisation/0_Names.csv\"\n"); fprintf(modFile, "replace = \"localisation/0_Cultures.csv\"\n"); fprintf(modFile, "replace = \"history/wars\"\n"); fclose(modFile); string renameCommand = "move /Y output\\output output\\" + Configuration::getOutputName(); system(renameCommand.c_str()); destWorld.output(); LOG(LogLevel::Info) << "* Conversion complete *"; return 0; }
int main(){ int i = 0; int mapCount = 0, clearMapCount = 0, dumpCount=0; int revFrameCount = 0; #ifdef USE_NORTH targetsGPS[maxTargets].lat = ADVANCED5LAT; targetsGPS[maxTargets].lon = ADVANCED5LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED6LAT; targetsGPS[maxTargets].lon = ADVANCED6LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED7LAT; targetsGPS[maxTargets].lon = ADVANCED7LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED8LAT; targetsGPS[maxTargets].lon = ADVANCED8LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED2LAT; targetsGPS[maxTargets].lon = ADVANCED2LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED1LAT; targetsGPS[maxTargets].lon = ADVANCED1LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED3LAT; targetsGPS[maxTargets].lon = ADVANCED3LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED12LAT; targetsGPS[maxTargets].lon = ADVANCED12LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED4LAT; targetsGPS[maxTargets].lon = ADVANCED4LON; maxTargets++; #else targetsGPS[maxTargets].lat = ADVANCED4LAT; targetsGPS[maxTargets].lon = ADVANCED4LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED1LAT; targetsGPS[maxTargets].lon = ADVANCED1LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED2LAT; targetsGPS[maxTargets].lon = ADVANCED2LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED3LAT; targetsGPS[maxTargets].lon = ADVANCED3LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED11LAT; targetsGPS[maxTargets].lon = ADVANCED11LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED8LAT; targetsGPS[maxTargets].lon = ADVANCED8LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED7LAT; targetsGPS[maxTargets].lon = ADVANCED7LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED6LAT; targetsGPS[maxTargets].lon = ADVANCED6LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED11LAT; targetsGPS[maxTargets].lon = ADVANCED11LON; maxTargets++; targetsGPS[maxTargets].lat = ADVANCED5LAT; targetsGPS[maxTargets].lon = ADVANCED5LON; maxTargets++; #endif maxTargetIndex=maxTargets-1; for(i=0;i<maxTargets;i++){// this is converting all GPS point data to XY data. targetListXY[i].x = GPSX(targetsGPS[i].lon, startLongitude); targetListXY[i].y = GPSY(targetsGPS[i].lat, startLatitude); } currentXY.x = GPSX(gpsvar.longitude,startLongitude);// converts current robot X location compared to start longitude currentXY.y = GPSY(gpsvar.latitude,startLatitude);// converts current robot Y location compared to start latitude targetXY = targetListXY[currentTargetIndex];//sets first target GPS point nextTargetIndex = (currentTargetIndex + 1)%maxTargets;//sets next target GPS point nextXY = targetListXY[nextTargetIndex];// ?? previousXY.x = GPSX(startLongitude, startLongitude);// why? previousXY.y = GPSY(startLatitude, startLatitude);//Why? initRoboteq(); /* Initialize roboteq */ initGuide();//what is guide? #ifdef USE_VISION // if USE_vision is defined, then initialize vision. initVision(); #endif //USE_VISION #ifdef USE_GPS// if USE_GPS is defined, then initialize GPS. initGPS(); initParser(); #endif //USE_GPS #ifdef USE_LIDAR// if USE_LIDAR is defined, then initialize LIDAR. initObjects(); initSICK(); #endif //USE_LIDAR #ifdef DEBUG_VISUALIZER// if defined, then use visualizer. initVisualizer(); #endif //DEBUG_VISUALIZER #ifdef USE_MAP//////>>>>>>>>>>>???? initMap(0,0,0); #endif //USE_MAP #ifdef DUMP_GPS// dump GPS data into file FILE *fp; fp = fopen("gpsdump.txt", "w"); #endif // DUMP_GPS while(1){ double dir = 1.0; double speed = 0.0, turn = 0.0; static double turnBoost = 0.750;//Multiplier for turn. Adjust to smooth jerky motions. Usually < 1.0 static int lSpeed = 0, rSpeed = 0;//Wheel Speed Variables if (joystick() != 0) {// is joystick is connected if (joy0.buttons & LB_BTN) {// deadman switch, but what does joy0.buttons do????????????????????????????????? speed = -joy0.axis[1]; //Up is negative on joystick negate so positive when going forward turn = joy0.axis[0]; lSpeed = (int)((speed + turnBoost*turn)*maxSpeed);//send left motor speed rSpeed = (int)((speed - turnBoost*turn)*maxSpeed);//send right motor speed }else{ //stop the robot rSpeed=lSpeed=0; } if(((joy0.buttons & B_BTN)||autoOn)&& (saveImage==0)){//what is the single & ??????????????????? saveImage =DEBOUNCE_FOR_SAVE_IMAGE;//save each image the camera takes, save image is an int declared in vision_nav.h }else{ if (saveImage) saveImage--; // turn off if button wasn't pressed? } if(joy0.buttons & RB_BTN){//turn on autonmous mode if start??? button is pressed autoOn = 1; mode=1; } if(joy0.buttons & Y_BTN){ // turn off autonomous mode autoOn = 0; mode =0; } lastButtons = joy0.buttons;//is this just updating buttons? } else{ // printf("No Joystick Found!\n"); rSpeed=lSpeed=0; } // // printf("3: %f %f\n",BASIC3LAT,BASIC3LON); // printf("4: %f %f\n",BASIC4LAT,BASIC4LON); // printf("5: %f %f\n",BASIC5LAT,BASIC5LON); // getchar(); #ifdef AUTO_SWAP//what is this if((currentTargetIndex>1&&targetIndexMem!=currentTargetIndex)||!autoOn||!mode==3){ startTime=currentTime=(float)(clock()/CLOCKS_PER_SEC); targetIndexMem = currentTargetIndex; }else{ currentTime=(float)(clock()/CLOCKS_PER_SEC); } totalTime = currentTime-startTime; if(totalTime>=SWAPTIME&&autoOn){ swap(); targetIndexMem = 0; } #endif //AUTO_SWAP #ifdef USE_GPS readGPS(); currentXY.x = GPSX(gpsvar.longitude,startLongitude); currentXY.y = GPSY(gpsvar.latitude,startLatitude); robotTheta = ADJUST_RADIANS(DEG2RAD(gpsvar.course)); #else currentXY.x = 0.0; currentXY.y = 0.0; robotTheta = 0.0; #endif //USE_GPS if(autoOn&&!flagPointSet){//this whole thing????? flagXY.x=currentXY.x+FLAG_X_ADJUST; flagXY.y=currentXY.y; flagPointSet=1; startAutoTime=currentAutoTime=(float)(clock()/CLOCKS_PER_SEC); } if(autoOn){ currentAutoTime=(float)(clock()/CLOCKS_PER_SEC); totalAutoTime = currentAutoTime-startAutoTime; if(totalAutoTime>=MODE2DELAY){ mode1TimeUp=1;//what is mode1 time up? } printf("TIMEING\n"); } // if(currentTargetIndex <= OPEN_FIELD_INDEX || currentTargetIndex >= maxTargetIndex){ if(currentTargetIndex <= OPEN_FIELD_INDEX){//if you are on your last target, then set approaching thresh, and dest thresh to larger values? //OPEN_FIELD_INDEX is set to 0 above...? approachingThresh=4.0; destinationThresh=3.0; }else{//otherwise set your thresholds to a bit closer. // destinationThresh=1.0; destinationThresh=0.75; approachingThresh=2.5; } //mode1 = lane tracking and obstacle avoidance. mode 2 = vision, lane tracking, but guide to gps. its not primary focus. //mode3= gps mode in open field, but vision is toned down to not get distracted by random grass. //mode 4= flag tracking if(guide(currentXY, targetXY, previousXY, nextXY, robotTheta, robotWidth, 1)&& !allTargetsReached){//If target reached and and not all targets reached printf("REACHED TARGET\n"); initGuide();// reset PID control stuff. problably resets all control variables. previousXY = targetXY;//update last target if(currentTargetIndex == maxTargetIndex){ //seeing if you are done with all targets. allTargetsReached = 1; }else{//otherwise update all the target information currentTargetIndex = (currentTargetIndex + 1); nextTargetIndex = (currentTargetIndex + 1)% maxTargets; targetXY = targetListXY[currentTargetIndex]; nextXY = targetListXY[nextTargetIndex]; } } if((autoOn&&(currentTargetIndex == 0&&!approachingTarget&&!mode1TimeUp))||allTargetsReached){ //if autonomous, and on first target, and not not approaching target, and not mode 1 time up, or reached last target. mode =1;//wtf is mode distanceMultiplier = 50;//wthis is how heavily to rely on vision } else if((autoOn&¤tTargetIndex == 0&&mode1TimeUp)||(autoOn&&approachingTarget&&(currentTargetIndex<=OPEN_FIELD_INDEX||currentTargetIndex>=maxTargetIndex-END_LANE_INDEX))){ mode =2; distanceMultiplier = 50; } else if((autoOn&¤tTargetIndex!=0)){ mode =3; distanceMultiplier = 12; } flagPointDistance = D((currentXY.x-flagXY.x),(currentXY.y-flagXY.y));// basically the distance formula, but to what? what flags GPS point? if(allTargetsReached&&flagPointDistance<FLAG_DIST_THRESH){ mode =4;// what is mode } #ifdef FLAG_TESTING /*FLAG TESTING*/ mode=4; #endif //FLAG_TESTING /*Current Target Heading PID Control Adjustment*/ cvar.lookAhead = 0.00;//? cvar.kP = 0.20; cvar.kI = 0.000; cvar.kD = 0.15; turn = cvar.turn; int bestVisGpsMask = 99; int h = 0; double minVisGpsTurn = 9999; for(h=0;h<11;h++){ if(fabs((cvar.turn-turn_angle[h]))<minVisGpsTurn){ minVisGpsTurn=fabs((cvar.turn-turn_angle[h])); bestVisGpsMask = h; } } bestGpsMask = bestVisGpsMask; // printf("bvg: %d \n", bestVisGpsMask); // printf("vgt: %f cv3: %f\n", minVisGpsTurn,cvar3.turn); #ifdef USE_VISION // double visTurnBoost = 0.50; double visTurnBoost = 1.0; if(imageProc(mode) == -1) break; if(mode==1||mode==2){ turn = turn_angle[bestmask]; turn *= visTurnBoost; }else if(mode==3 && fabs(turn_angle[bestmask])>0.70){ turn = turn_angle[bestmask]; turn *= visTurnBoost; } #endif //USE_VISION #ifdef USE_LIDAR updateSick(); // findObjects(); #endif //USE_LIDAR #ifdef USE_COMBINED_BUFFER//?????????? #define WORSTTHRESH 10 #define BESTTHRESH 3 if(mode==4){ #ifdef USE_NORTH turn = (0.5*turn_angle[bestBlueMask]+0.5*turn_angle[bestRedMask]); #else turn = (0.65*turn_angle[bestBlueMask]+0.35*turn_angle[bestRedMask]); #endif turn *= 0.75; } combinedTargDist = cvar.targdist; if(((approachingTarget||inLastTarget)&¤tTargetIndex>OPEN_FIELD_INDEX &¤tTargetIndex<maxTargetIndex-END_LANE_INDEX)||(MAG(howbad[worstmask]-howbad[bestmask]))<BESTTHRESH||mode==4){ getCombinedBufferAngles(0,0);//Don't Use Vision Radar Data }else{ getCombinedBufferAngles(0,1);//Use Vision Radar Data } if(combinedBufferAngles.left != 0 || combinedBufferAngles.right !=0){ if(mode == 1 || mode==2 || mode==3 || mode==4){ // if(mode == 1 || mode==2 || mode==3){ // if(mode==2 || mode==3){ // if(mode==3){ if(fabs(combinedBufferAngles.right)==fabs(combinedBufferAngles.left)){ double revTurn; double revDistLeft, revDistRight; int revIdx; if(fabs(turn)<0.10) dir = -1.0; if(fabs(combinedBufferAngles.left)>1.25) dir = -1.0; if(dir<0){ revIdx = 540-RAD2DEG(combinedBufferAngles.left)*4; revIdx = MIN(revIdx,1080); revIdx = MAX(revIdx,0); revDistLeft = LMSdata[revIdx]; revIdx = 540-RAD2DEG(combinedBufferAngles.right)*4; revIdx = MIN(revIdx,1080); revIdx = MAX(revIdx,0); revDistRight = LMSdata[revIdx]; if(revDistLeft>=revDistRight){ revTurn = combinedBufferAngles.left; }else { revTurn = combinedBufferAngles.right; } turn = revTurn; }else{ turn = turn_angle[bestmask]; } } else if(fabs(combinedBufferAngles.right-turn)<fabs(combinedBufferAngles.left-turn)){ // } else if(turn<=0){ turn = combinedBufferAngles.right; }else { turn = combinedBufferAngles.left; } } } #endif //USE_COMBINED_BUFFER if(dir<0||revFrameCount!=0){ dir = -1.0; revFrameCount = (revFrameCount+1)%REVFRAMES; } // turn *= dir; turn = SIGN(turn) * MIN(fabs(turn), 1.0); speed = 1.0/(1.0+1.0*fabs(turn))*dir; speed = SIGN(speed) * MIN(fabs(speed), 1.0); if(!autoOn){ maxSpeed = 60; targetIndexMem = 0; }else if(dir<0){ maxSpeed = 30; }else if(mode<=2||(mode==3 && fabs(turn_angle[bestmask])>0.25)){ maxSpeed = 60 - 25*fabs(turn); // maxSpeed = 70 - 35*fabs(turn); // maxSpeed = 90 - 50*fabs(turn); // maxSpeed = 100 - 65*fabs(turn); }else if(mode==4){ maxSpeed = 45-20*fabs(turn); }else{ maxSpeed = 85 - 50*fabs(turn); // maxSpeed = 100 - 65*fabs(turn); // maxSpeed = 110 - 70*fabs(turn); // maxSpeed = 120 - 85*fabs(turn); } if(autoOn){ lSpeed = (speed + turnBoost*turn) * maxSpeed; rSpeed = (speed - turnBoost*turn) * maxSpeed; } #ifdef DEBUG_MAIN printf("s:%.4f t: %.4f m: %d vt:%f dir:%f tmr: %f\n", speed, turn, mode, turn_angle[bestmask], flagPointDistance, totalAutoTime); #endif //DEBUG_MAIN #ifdef DUMP_GPS if(dumpCount==0){ if (fp != NULL) { fprintf(fp, "%f %f %f %f %f\n",gpsvar.latitude,gpsvar.longitude, gpsvar.course, gpsvar.speed, gpsvar.time); } } dumpCount = dumpCount+1%DUMPGPSDELAY; #endif //DUMP_GPS #ifdef DEBUG_TARGET debugTarget(); #endif //DEBUG_TARGET #ifdef DEBUG_GUIDE debugGuide(); #endif //DEBUG_GUIDE #ifdef DEBUG_GPS debugGPS(); #endif //DEBUG_GPS #ifdef DEBUG_LIDAR debugSICK(); #endif //DEBUG_LIDAR #ifdef DEBUG_BUFFER debugCombinedBufferAngles(); #endif //DEBUG_BUFFE #ifdef DEBUG_VISUALIZER robotX = currentXY.x; robotY = currentXY.y; robotTheta = robotTheta;//redundant I know.... targetX = targetXY.x; targetY = targetXY.y; // should probably pass the above to the function... paintPathPlanner(robotX,robotY,robotTheta); showPlot(); #endif //VISUALIZER #ifdef USE_MAP if(mapCount==0){ // mapRobot(currentXY.x,currentXY.y,robotTheta); if(clearMapCount==0) clearMapSection(currentXY.x,currentXY.y,robotTheta); else clearMapCount = (clearMapCount+1)%CLEARMAPDELAY; mapVSICK(currentXY.x,currentXY.y,robotTheta); // mapVSICK(0,0,0); #ifdef USE_LIDAR mapSICK(currentXY.x,currentXY.y,robotTheta); #endif showMap(); // printf("MAPPING\n"); } mapCount= (mapCount+1)%MAPDELAY; #endif //USE_MAP sendSpeed(lSpeed,rSpeed); Sleep(5); } #ifdef DUMP_GPS fclose(fp); #endif return 0; }
// //PnYn MnDTnH nMnS: -P1Y2M3DT10H30M // // [-]{'P'{[n'Y'][n'M'][n'D']['T'][n'H'][n'M'][n'S']}} // // Note: the n above shall be >= 0 // if no time element found, 'T' shall be absent // void TimeVal::parseDuration() { initParser(); // must start with '-' or 'P' // unsigned char c = parser_context.fBuffer[parser_context.fStart++]; if ( (c != DURATION_STARTER) && (c != '-') ) { throw TimeValXMLParseErrorException("DateTime_dur_Start_dashP", parser_context.fBuffer); } // 'P' must ALWAYS be present in either case if ( (c == '-') && (parser_context.fBuffer[parser_context.fStart++]!= DURATION_STARTER )) { throw TimeValXMLParseErrorException("DateTime_dur_noP",parser_context.fBuffer); } // java code //date[utc]=(c=='-')?'-':0; //parser_context.fValue[utc] = UTC_STD; parser_context.fValue[utc] = (parser_context.fBuffer[0] == '-'? UTC_NEG : UTC_STD); int negate = ( parser_context.fBuffer[0] == '-' ? -1 : 1); // // No negative value is allowed after 'P' // // eg P-1234, invalid // if (indexOf(parser_context.fStart, parser_context.fEnd, '-') != NOT_FOUND) { throw TimeValXMLParseErrorException("DateTime_dur_DashNotFirst", parser_context.fBuffer); } //at least one number and designator must be seen after P bool designator = false; int endDate = indexOf(parser_context.fStart, parser_context.fEnd, DATETIME_SEPARATOR); if ( endDate == NOT_FOUND ) { endDate = parser_context.fEnd; // 'T' absent } //find 'Y' int end = indexOf(parser_context.fStart, endDate, DURATION_Y); if ( end != NOT_FOUND ) { //scan year parser_context.fValue[CentYear] = negate * parseInt(parser_context.fStart, end); parser_context.fStart = end+1; designator = true; } end = indexOf(parser_context.fStart, endDate, DURATION_M); if ( end != NOT_FOUND ) { //scan month parser_context.fValue[Month] = negate * parseInt(parser_context.fStart, end); parser_context.fStart = end+1; designator = true; } end = indexOf(parser_context.fStart, endDate, DURATION_D); if ( end != NOT_FOUND ) { //scan day parser_context.fValue[Day] = negate * parseInt(parser_context.fStart,end); parser_context.fStart = end+1; designator = true; } if ( (parser_context.fEnd == endDate) && // 'T' absent (parser_context.fStart != parser_context.fEnd) ) // something after Day { throw TimeValXMLParseErrorException("DateTime_dur_inv_b4T", parser_context.fBuffer); } if ( parser_context.fEnd != endDate ) // 'T' present { //scan hours, minutes, seconds // // skip 'T' first end = indexOf(++parser_context.fStart, parser_context.fEnd, DURATION_H); if ( end != NOT_FOUND ) { //scan hours parser_context.fValue[Hour] = negate * parseInt(parser_context.fStart, end); parser_context.fStart = end+1; designator = true; } end = indexOf(parser_context.fStart, parser_context.fEnd, DURATION_M); if ( end != NOT_FOUND ) { //scan min parser_context.fValue[Minute] = negate * parseInt(parser_context.fStart, end); parser_context.fStart = end+1; designator = true; } end = indexOf(parser_context.fStart, parser_context.fEnd, DURATION_S); if ( end != NOT_FOUND ) { //scan seconds int mlsec = indexOf (parser_context.fStart, end, MILISECOND_SEPARATOR); /*** * Schema Errata: E2-23 * at least one digit must follow the decimal point if it appears. * That is, the value of the seconds component must conform * to the following pattern: [0-9]+(.[0-9]+)? */ if ( mlsec != NOT_FOUND ) { /*** * make usure there is something after the '.' and before the end. */ if ( mlsec+1 == end ) { throw TimeValXMLParseErrorException("DateTime_dur_inv_seconds",parser_context.fBuffer); } parser_context.fValue[Second] = negate * parseInt(parser_context.fStart, mlsec); parser_context.fValue[MiliSecond] = negate * parseInt(mlsec+1, end); } else { parser_context.fValue[Second] = negate * parseInt(parser_context.fStart,end); } parser_context.fStart = end+1; designator = true; } // no additional data should appear after last item // P1Y1M1DT is illigal value as well if ( (parser_context.fStart != parser_context.fEnd) || parser_context.fBuffer[--parser_context.fStart] == DATETIME_SEPARATOR ) { throw TimeValXMLParseErrorException("DateTime_dur_NoTimeAfterT", parser_context.fBuffer); } } if ( !designator ) { throw TimeValXMLParseErrorException("DateTime_dur_NoElementAtAll", parser_context.fBuffer); } }
static void *XoReadExiCommon(struct ioStream *ioStr, char *roottype,int flags,int *err) { Parser testParser; struct appData parsingData; char buf[INPUT_BUFFER_SIZE]; BinaryBuffer buffer; errorCode tmp_err_code = UNEXPECTED_ERROR; memset (&parsingData,0,sizeof(parsingData)); parsingData.ctxt.roottype = roottype; parsingData.ctxt.flags = flags; parsingData.ctxt.ns.flags = flags; parsingData.parser = &testParser; _XoAllocCtxt(&parsingData.ctxt); buffer.buf = buf; buffer.bufLen = INPUT_BUFFER_SIZE; buffer.bufContent = 0; // Parsing steps: // I: First, define an external stream for the input to the parser if any buffer.ioStrm = *ioStr; // II: Second, initialize the parser object #if EXIP_VERSION==276 tmp_err_code = initParser(&testParser, buffer, g_schemaPtr, &parsingData); #endif #if EXIP_VERSION>=289 tmp_err_code = initParser(&testParser, buffer, &parsingData); #endif if(tmp_err_code != ERR_OK) { _XoFreeCtxt(&parsingData.ctxt); return NULL; } // III: Initialize the parsing data and hook the callback handlers to the parser object parsingData.expectAttributeData = 0; parsingData.stack = NULL; parsingData.unclosedElement = 0; parsingData.prefixesCount = 0; testParser.handler.fatalError = sample_fatalError; testParser.handler.error = sample_fatalError; testParser.handler.startDocument = sample_startDocument; testParser.handler.endDocument = sample_endDocument; testParser.handler.startElement = sample_startElement; testParser.handler.attribute = sample_attribute; testParser.handler.stringData = sample_stringData; testParser.handler.endElement = sample_endElement; testParser.handler.decimalData = sample_decimalData; testParser.handler.intData = sample_intData; testParser.handler.floatData = sample_floatData; testParser.handler.booleanData = sample_booleanData; testParser.handler.dateTimeData = sample_dateTimeData; testParser.handler.binaryData = sample_binaryData; testParser.handler.qnameData = sample_qnameData; #if EXIP_VERSION==276 testParser.handler.retrieveSchema = sample_retrieveSchema; #endif // IV: Parse the header of the stream tmp_err_code = parseHeader(&testParser, FALSE); #if EXIP_VERSION>=289 // IV.1: Set the schema to be used for parsing. // The schemaID mode and schemaID field can be read at // parser.strm.header.opts.schemaIDMode and // parser.strm.header.opts.schemaID respectively // If schemaless mode, use setSchema(&parser, NULL); EXIPSchema *schemaPtr = sample_retrieveSchema(&parsingData); setSchema(&testParser, schemaPtr); #endif //_lookupSchema(); // V: Parse the body of the EXI stream while(tmp_err_code == ERR_OK) { tmp_err_code = parseNext(&testParser); PRINT ("parseNext ret=%d\n", tmp_err_code); } // PCA parsingData.xo_obj = parsingData.ctxt.obj[0]; // VI: Free the memory allocated by the parser and schema object destroyParser(&testParser); _XoFreeCtxt(&parsingData.ctxt); PRINT ("End parsing xo_obj=%p\n", parsingData.xo_obj); return parsingData.xo_obj; }
int main(int argc, char* argv[]) { UErrorCode status = U_ZERO_ERROR; const char *arg = NULL; const char *outputDir = NULL; /* NULL = no output directory, use current */ const char *inputDir = NULL; const char *encoding = ""; int i; UBool illegalArg = FALSE; U_MAIN_INIT_ARGS(argc, argv); options[JAVA_PACKAGE].value = "com.ibm.icu.impl.data"; options[BUNDLE_NAME].value = "LocaleElements"; argc = u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "%s: error in command line argument \"%s\"\n", argv[0], argv[-argc]); illegalArg = TRUE; } else if(argc<2) { illegalArg = TRUE; } if(options[WRITE_POOL_BUNDLE].doesOccur && options[USE_POOL_BUNDLE].doesOccur) { fprintf(stderr, "%s: cannot combine --writePoolBundle and --usePoolBundle\n", argv[0]); illegalArg = TRUE; } if(options[FORMAT_VERSION].doesOccur) { const char *s = options[FORMAT_VERSION].value; if(uprv_strlen(s) != 1 || (s[0] < '1' && '3' < s[0])) { fprintf(stderr, "%s: unsupported --formatVersion %s\n", argv[0], s); illegalArg = TRUE; } else if(s[0] == '1' && (options[WRITE_POOL_BUNDLE].doesOccur || options[USE_POOL_BUNDLE].doesOccur) ) { fprintf(stderr, "%s: cannot combine --formatVersion 1 with --writePoolBundle or --usePoolBundle\n", argv[0]); illegalArg = TRUE; } else { setFormatVersion(s[0] - '0'); } } if((options[JAVA_PACKAGE].doesOccur || options[BUNDLE_NAME].doesOccur) && !options[WRITE_JAVA].doesOccur) { fprintf(stderr, "%s error: command line argument --java-package or --bundle-name " "without --write-java\n", argv[0]); illegalArg = TRUE; } if(options[VERSION].doesOccur) { fprintf(stderr, "%s version %s (ICU version %s).\n" "%s\n", argv[0], GENRB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); if(!illegalArg) { return U_ZERO_ERROR; } } if(illegalArg || options[HELP1].doesOccur || options[HELP2].doesOccur) { /* * Broken into chunks because the C89 standard says the minimum * required supported string length is 509 bytes. */ fprintf(stderr, "Usage: %s [OPTIONS] [FILES]\n" "\tReads the list of resource bundle source files and creates\n" "\tbinary version of resource bundles (.res files)\n", argv[0]); fprintf(stderr, "Options:\n" "\t-h or -? or --help this usage text\n" "\t-q or --quiet do not display warnings\n" "\t-v or --verbose print extra information when processing files\n" "\t-V or --version prints out version number and exits\n" "\t-c or --copyright include copyright notice\n"); fprintf(stderr, "\t-e or --encoding encoding of source files\n" "\t-d of --destdir destination directory, followed by the path, defaults to %s\n" "\t-s or --sourcedir source directory for files followed by path, defaults to %s\n" "\t-i or --icudatadir directory for locating any needed intermediate data files,\n" "\t followed by path, defaults to %s\n", u_getDataDirectory(), u_getDataDirectory(), u_getDataDirectory()); fprintf(stderr, "\t-j or --write-java write a Java ListResourceBundle for ICU4J, followed by optional encoding\n" "\t defaults to ASCII and \\uXXXX format.\n" "\t --java-package For --write-java: package name for writing the ListResourceBundle,\n" "\t defaults to com.ibm.icu.impl.data\n"); fprintf(stderr, "\t-b or --bundle-name For --write-java: root resource bundle name for writing the ListResourceBundle,\n" "\t defaults to LocaleElements\n" "\t-x or --write-xliff write an XLIFF file for the resource bundle. Followed by\n" "\t an optional output file name.\n" "\t-k or --strict use pedantic parsing of syntax\n" /*added by Jing*/ "\t-l or --language for XLIFF: language code compliant with BCP 47.\n"); fprintf(stderr, "\t-C or --noBinaryCollation do not generate binary collation image;\n" "\t makes .res file smaller but collator instantiation much slower;\n" "\t maintains ability to get tailoring rules\n" "\t-R or --omitCollationRules do not include collation (tailoring) rules;\n" "\t makes .res file smaller and maintains collator instantiation speed\n" "\t but tailoring rules will not be available (they are rarely used)\n"); fprintf(stderr, "\t --formatVersion write a .res file compatible with the requested formatVersion (single digit);\n" "\t for example, --formatVersion 1\n"); fprintf(stderr, "\t --writePoolBundle write a pool.res file with all of the keys of all input bundles\n" "\t --usePoolBundle [path-to-pool.res] point to keys from the pool.res keys pool bundle if they are available there;\n" "\t makes .res files smaller but dependent on the pool bundle\n" "\t (--writePoolBundle and --usePoolBundle cannot be combined)\n"); return illegalArg ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; } if(options[VERBOSE].doesOccur) { setVerbose(TRUE); } if(options[QUIET].doesOccur) { setShowWarning(FALSE); } if(options[STRICT].doesOccur) { setStrict(TRUE); } if(options[COPYRIGHT].doesOccur){ setIncludeCopyright(TRUE); } if(options[SOURCEDIR].doesOccur) { inputDir = options[SOURCEDIR].value; } if(options[DESTDIR].doesOccur) { outputDir = options[DESTDIR].value; } if(options[ENCODING].doesOccur) { encoding = options[ENCODING].value; } if(options[ICUDATADIR].doesOccur) { u_setDataDirectory(options[ICUDATADIR].value); } /* Initialize ICU */ u_init(&status); if (U_FAILURE(status) && status != U_FILE_ACCESS_ERROR) { /* Note: u_init() will try to open ICU property data. * failures here are expected when building ICU from scratch. * ignore them. */ fprintf(stderr, "%s: can not initialize ICU. status = %s\n", argv[0], u_errorName(status)); exit(1); } status = U_ZERO_ERROR; if(options[WRITE_JAVA].doesOccur) { write_java = TRUE; outputEnc = options[WRITE_JAVA].value; } if(options[WRITE_XLIFF].doesOccur) { write_xliff = TRUE; if(options[WRITE_XLIFF].value != NULL){ xliffOutputFileName = options[WRITE_XLIFF].value; } } initParser(); /*added by Jing*/ if(options[LANGUAGE].doesOccur) { language = options[LANGUAGE].value; } LocalPointer<SRBRoot> newPoolBundle; if(options[WRITE_POOL_BUNDLE].doesOccur) { newPoolBundle.adoptInsteadAndCheckErrorCode(new SRBRoot(NULL, TRUE, status), status); if(U_FAILURE(status)) { fprintf(stderr, "unable to create an empty bundle for the pool keys: %s\n", u_errorName(status)); return status; } else { const char *poolResName = "pool.res"; char *nameWithoutSuffix = static_cast<char *>(uprv_malloc(uprv_strlen(poolResName) + 1)); if (nameWithoutSuffix == NULL) { fprintf(stderr, "out of memory error\n"); return U_MEMORY_ALLOCATION_ERROR; } uprv_strcpy(nameWithoutSuffix, poolResName); *uprv_strrchr(nameWithoutSuffix, '.') = 0; newPoolBundle->fLocale = nameWithoutSuffix; } } if(options[USE_POOL_BUNDLE].doesOccur) { const char *poolResName = "pool.res"; FileStream *poolFile; int32_t poolFileSize; int32_t indexLength; /* * TODO: Consolidate inputDir/filename handling from main() and processFile() * into a common function, and use it here as well. * Try to create toolutil functions for dealing with dir/filenames and * loading ICU data files without udata_open(). * Share code with icupkg? * Also, make_res_filename() seems to be unused. Review and remove. */ CharString poolFileName; if (options[USE_POOL_BUNDLE].value!=NULL) { poolFileName.append(options[USE_POOL_BUNDLE].value, status); } else if (inputDir) { poolFileName.append(inputDir, status); } poolFileName.appendPathPart(poolResName, status); if (U_FAILURE(status)) { return status; } poolFile = T_FileStream_open(poolFileName.data(), "rb"); if (poolFile == NULL) { fprintf(stderr, "unable to open pool bundle file %s\n", poolFileName.data()); return 1; } poolFileSize = T_FileStream_size(poolFile); if (poolFileSize < 32) { fprintf(stderr, "the pool bundle file %s is too small\n", poolFileName.data()); return 1; } poolBundle.fBytes = new uint8_t[(poolFileSize + 15) & ~15]; if (poolFileSize > 0 && poolBundle.fBytes == NULL) { fprintf(stderr, "unable to allocate memory for the pool bundle file %s\n", poolFileName.data()); return U_MEMORY_ALLOCATION_ERROR; } UDataSwapper *ds; const DataHeader *header; int32_t bytesRead = T_FileStream_read(poolFile, poolBundle.fBytes, poolFileSize); if (bytesRead != poolFileSize) { fprintf(stderr, "unable to read the pool bundle file %s\n", poolFileName.data()); return 1; } /* * Swap the pool bundle so that a single checked-in file can be used. * The swapper functions also test that the data looks like * a well-formed .res file. */ ds = udata_openSwapperForInputData(poolBundle.fBytes, bytesRead, U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, &status); if (U_FAILURE(status)) { fprintf(stderr, "udata_openSwapperForInputData(pool bundle %s) failed: %s\n", poolFileName.data(), u_errorName(status)); return status; } ures_swap(ds, poolBundle.fBytes, bytesRead, poolBundle.fBytes, &status); udata_closeSwapper(ds); if (U_FAILURE(status)) { fprintf(stderr, "ures_swap(pool bundle %s) failed: %s\n", poolFileName.data(), u_errorName(status)); return status; } header = (const DataHeader *)poolBundle.fBytes; if (header->info.formatVersion[0] < 2) { fprintf(stderr, "invalid format of pool bundle file %s\n", poolFileName.data()); return U_INVALID_FORMAT_ERROR; } const int32_t *pRoot = (const int32_t *)( (const char *)header + header->dataHeader.headerSize); poolBundle.fIndexes = pRoot + 1; indexLength = poolBundle.fIndexes[URES_INDEX_LENGTH] & 0xff; if (indexLength <= URES_INDEX_POOL_CHECKSUM) { fprintf(stderr, "insufficient indexes[] in pool bundle file %s\n", poolFileName.data()); return U_INVALID_FORMAT_ERROR; } int32_t keysBottom = 1 + indexLength; int32_t keysTop = poolBundle.fIndexes[URES_INDEX_KEYS_TOP]; poolBundle.fKeys = (const char *)(pRoot + keysBottom); poolBundle.fKeysLength = (keysTop - keysBottom) * 4; poolBundle.fChecksum = poolBundle.fIndexes[URES_INDEX_POOL_CHECKSUM]; for (i = 0; i < poolBundle.fKeysLength; ++i) { if (poolBundle.fKeys[i] == 0) { ++poolBundle.fKeysCount; } } // 16BitUnits[] begins with strings-v2. // The strings-v2 may optionally be terminated by what looks like // an explicit string length that exceeds the number of remaining 16-bit units. int32_t stringUnitsLength = (poolBundle.fIndexes[URES_INDEX_16BIT_TOP] - keysTop) * 2; if (stringUnitsLength >= 2 && getFormatVersion() >= 3) { poolBundle.fStrings = new PseudoListResource(NULL, status); if (poolBundle.fStrings == NULL) { fprintf(stderr, "unable to allocate memory for the pool bundle strings %s\n", poolFileName.data()); return U_MEMORY_ALLOCATION_ERROR; } // The PseudoListResource constructor call did not allocate further memory. assert(U_SUCCESS(status)); const UChar *p = (const UChar *)(pRoot + keysTop); int32_t remaining = stringUnitsLength; do { int32_t first = *p; int8_t numCharsForLength; int32_t length; if (!U16_IS_TRAIL(first)) { // NUL-terminated numCharsForLength = 0; for (length = 0; length < remaining && p[length] != 0; ++length) {} } else if (first < 0xdfef) { numCharsForLength = 1; length = first & 0x3ff; } else if (first < 0xdfff && remaining >= 2) { numCharsForLength = 2; length = ((first - 0xdfef) << 16) | p[1]; } else if (first == 0xdfff && remaining >= 3) { numCharsForLength = 3; length = ((int32_t)p[1] << 16) | p[2]; } else { break; // overrun } // Check for overrun before changing remaining, // so that it is always accurate after the loop body. if ((numCharsForLength + length) >= remaining || p[numCharsForLength + length] != 0) { break; // overrun or explicitly terminated } int32_t poolStringIndex = stringUnitsLength - remaining; // Maximum pool string index when suffix-sharing the last character. int32_t maxStringIndex = poolStringIndex + numCharsForLength + length - 1; if (maxStringIndex >= RES_MAX_OFFSET) { // pool string index overrun break; } p += numCharsForLength; remaining -= numCharsForLength; if (length != 0) { StringResource *sr = new StringResource(poolStringIndex, numCharsForLength, p, length, status); if (sr == NULL) { fprintf(stderr, "unable to allocate memory for a pool bundle string %s\n", poolFileName.data()); return U_MEMORY_ALLOCATION_ERROR; } poolBundle.fStrings->add(sr); poolBundle.fStringIndexLimit = maxStringIndex + 1; // The StringResource constructor did not allocate further memory. assert(U_SUCCESS(status)); } p += length + 1; remaining -= length + 1; } while (remaining > 0); if (poolBundle.fStrings->fCount == 0) { delete poolBundle.fStrings; poolBundle.fStrings = NULL; } } T_FileStream_close(poolFile); setUsePoolBundle(TRUE); if (isVerbose() && poolBundle.fStrings != NULL) { printf("number of shared strings: %d\n", (int)poolBundle.fStrings->fCount); int32_t length = poolBundle.fStringIndexLimit + 1; // incl. last NUL printf("16-bit units for strings: %6d = %6d bytes\n", (int)length, (int)length * 2); } } if(!options[FORMAT_VERSION].doesOccur && getFormatVersion() == 3 && poolBundle.fStrings == NULL && !options[WRITE_POOL_BUNDLE].doesOccur) { // If we just default to formatVersion 3 // but there are no pool bundle strings to share // and we do not write a pool bundle, // then write formatVersion 2 which is just as good. setFormatVersion(2); } if(options[INCLUDE_UNIHAN_COLL].doesOccur) { puts("genrb option --includeUnihanColl ignored: \n" "CLDR 26/ICU 54 unihan data is small, except\n" "the ucadata-unihan.icu version of the collation root data\n" "is about 300kB larger than the ucadata-implicithan.icu version."); } if((argc-1)!=1) { printf("genrb number of files: %d\n", argc - 1); } /* generate the binary files */ for(i = 1; i < argc; ++i) { status = U_ZERO_ERROR; arg = getLongPathname(argv[i]); CharString theCurrentFileName; if (inputDir) { theCurrentFileName.append(inputDir, status); } theCurrentFileName.appendPathPart(arg, status); if (U_FAILURE(status)) { break; } gCurrentFileName = theCurrentFileName.data(); if (isVerbose()) { printf("Processing file \"%s\"\n", theCurrentFileName.data()); } processFile(arg, encoding, inputDir, outputDir, NULL, newPoolBundle.getAlias(), options[NO_BINARY_COLLATION].doesOccur, status); } poolBundle.close(); if(U_SUCCESS(status) && options[WRITE_POOL_BUNDLE].doesOccur) { char outputFileName[256]; newPoolBundle->write(outputDir, NULL, outputFileName, sizeof(outputFileName), status); if(U_FAILURE(status)) { fprintf(stderr, "unable to write the pool bundle: %s\n", u_errorName(status)); } } u_cleanup(); /* Dont return warnings as a failure */ if (U_SUCCESS(status)) { return 0; } return status; }
int mal_init(void){ #ifdef NEED_MT_LOCK_INIT MT_lock_init( &mal_contextLock, "mal_contextLock"); MT_lock_init( &mal_namespaceLock, "mal_namespaceLock"); MT_lock_init( &mal_remoteLock, "mal_remoteLock"); MT_lock_init( &mal_profileLock, "mal_profileLock"); MT_lock_init( &mal_copyLock, "mal_copyLock"); MT_lock_init( &mal_delayLock, "mal_delayLock"); #endif /* "/2" is arbitrarily used / chosen, as on systems with * hyper-threading enabled, using all hardware threads rather than * "only" all physical cores does not necessarily yield a linear * performance benefit */ MT_sema_init( &mal_parallelism, (GDKnr_threads > 1 ? GDKnr_threads/2: 1), "mal_parallelism"); tstAligned(); MCinit(); if (mdbInit()) return -1; if (monet_memory == 0) monet_memory = MT_npages() * MT_pagesize(); initNamespace(); initParser(); initHeartbeat(); initResource(); #ifdef HAVE_JSONSTORE startHttpdaemon(); #endif RECYCLEinit(); if( malBootstrap() == 0) return -1; /* set up the profiler if needed, output sent to console */ /* Use the same shortcuts as stethoscope */ if ( mal_trace && *mal_trace) { char *s; setFilterAll(); openProfilerStream(mal_clients[0].fdout); for ( s= mal_trace; *s; s++) switch(*s){ case 'a': activateCounter("aggregate");break; case 'b': activateCounter("rbytes"); activateCounter("wbytes");break; case 'c': activateCounter("cpu");break; case 'e': activateCounter("event");break; case 'f': activateCounter("function");break; case 'i': activateCounter("pc");break; case 'm': activateCounter("memory");break; case 'p': activateCounter("process");break; case 'r': activateCounter("reads");break; case 's': activateCounter("stmt");break; case 't': activateCounter("ticks");break; case 'u': activateCounter("user");break; case 'w': activateCounter("writes");break; case 'y': activateCounter("type");break; case 'D': activateCounter("dot");break; case 'I': activateCounter("thread");break; case 'T': activateCounter("time");break; case 'S': activateCounter("start"); } startProfiling(); } else mal_trace =0; return 0; }
errorCode decode(EXIPSchema* schemaPtr, unsigned char outFlag, FILE *infile, size_t (*inputStream)(void* buf, size_t size, void* stream)) { Parser testParser; char buf[INPUT_BUFFER_SIZE]; BinaryBuffer buffer; errorCode tmp_err_code = UNEXPECTED_ERROR; struct appData parsingData; buffer.buf = buf; buffer.bufLen = INPUT_BUFFER_SIZE; buffer.bufContent = 0; // Parsing steps: // I: First, define an external stream for the input to the parser if any, otherwise set to NULL buffer.ioStrm.readWriteToStream = inputStream; buffer.ioStrm.stream = infile; // II: Second, initialize the parser object TRY(initParser(&testParser, buffer, &parsingData)); // III: Initialize the parsing data and hook the callback handlers to the parser object. // If out-of-band options are defined use testParser.strm.header.opts to set them parsingData.expectAttributeData = 0; parsingData.stack = NULL; parsingData.unclosedElement = 0; parsingData.prefixesCount = 0; parsingData.outputFormat = outFlag; testParser.handler.fatalError = sample_fatalError; testParser.handler.error = sample_fatalError; testParser.handler.startDocument = sample_startDocument; testParser.handler.endDocument = sample_endDocument; testParser.handler.startElement = sample_startElement; testParser.handler.attribute = sample_attribute; testParser.handler.stringData = sample_stringData; testParser.handler.endElement = sample_endElement; testParser.handler.decimalData = sample_decimalData; testParser.handler.intData = sample_intData; testParser.handler.floatData = sample_floatData; testParser.handler.booleanData = sample_booleanData; testParser.handler.dateTimeData = sample_dateTimeData; testParser.handler.binaryData = sample_binaryData; // IV: Parse the header of the stream TRY(parseHeader(&testParser, FALSE)); // IV.1: Set the schema to be used for parsing. // The schemaID mode and schemaID field can be read at // parser.strm.header.opts.schemaIDMode and // parser.strm.header.opts.schemaID respectively // If schemaless mode, use setSchema(&parser, NULL); TRY(setSchema(&testParser, schemaPtr)); // V: Parse the body of the EXI stream while(tmp_err_code == ERR_OK) { tmp_err_code = parseNext(&testParser); } // VI: Free the memory allocated by the parser destroyParser(&testParser); if(tmp_err_code == PARSING_COMPLETE) return ERR_OK; else return tmp_err_code; }
DOMDocument* XQillaBuilderImpl::parseURI(const char* const systemId) { initParser(); AbstractDOMParser::parse(systemId); return getDocumentAndAddGrammar(); }
errorCode decodeHeader(EXIStream* strm, boolean outOfBandOpts) { errorCode tmp_err_code = UNEXPECTED_ERROR; unsigned int bits_val = 0; boolean boolVal = FALSE; DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">Start EXI header decoding\n")); TRY(readBits(strm, 2, &bits_val)); if(bits_val == 2) // The header Distinguishing Bits i.e. no EXI Cookie { strm->header.has_cookie = 0; DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">No EXI cookie detected\n")); } else if(bits_val == 0)// ASCII code for $ = 00100100 (36) { TRY(readBits(strm, 6, &bits_val)); if(bits_val != 36) return INVALID_EXI_HEADER; TRY(readBits(strm, 8, &bits_val)); if(bits_val != 69) // ASCII code for E = 01000101 (69) return INVALID_EXI_HEADER; TRY(readBits(strm, 8, &bits_val)); if(bits_val != 88) // ASCII code for X = 01011000 (88) return INVALID_EXI_HEADER; TRY(readBits(strm, 8, &bits_val)); if(bits_val != 73) // ASCII code for I = 01001001 (73) return INVALID_EXI_HEADER; strm->header.has_cookie = 1; DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">EXI cookie detected\n")); TRY(readBits(strm, 2, &bits_val)); if(bits_val != 2) // The header Distinguishing Bits are required return INVALID_EXI_HEADER; } else { return INVALID_EXI_HEADER; } // Read the Presence Bit for EXI Options TRY(readNextBit(strm, &boolVal)); if(boolVal == TRUE) // There are EXI options { strm->header.has_options = TRUE; // validation checks. If the options are included then // they cannot be set by an out-of-band mechanism. // If out-of-band options are set - // rise a warning and overwrite them. // Only the options from the header will be used if(outOfBandOpts == TRUE) { DEBUG_MSG(WARNING, DEBUG_CONTENT_IO, (">Ignored out-of-band set EXI options\n")); makeDefaultOpts(&strm->header.opts); } } else // Out-of-band set EXI options { DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">No EXI options field in the header\n")); strm->header.has_options = FALSE; if(outOfBandOpts == FALSE) { DEBUG_MSG(ERROR, DEBUG_CONTENT_IO, (">No EXI options in the header and no out-of-band options specified. \n")); return HEADER_OPTIONS_MISMATCH; } } // Read the Version type TRY(readNextBit(strm, &boolVal)); strm->header.is_preview_version = boolVal; strm->header.version_number = 1; do { TRY(readBits(strm, 4, &bits_val)); strm->header.version_number += bits_val; if(bits_val < 15) break; } while(1); DEBUG_MSG(INFO, DEBUG_CONTENT_IO, (">EXI version: %d\n", strm->header.version_number)); if(strm->header.has_options == 1) { Parser optionsParser; struct ops_AppData appD; TRY(initParser(&optionsParser, strm->buffer, &appD)); optionsParser.strm.context.bitPointer = strm->context.bitPointer; optionsParser.strm.context.bufferIndx = strm->context.bufferIndx; optionsParser.strm.gStack = NULL; makeDefaultOpts(&optionsParser.strm.header.opts); SET_STRICT(optionsParser.strm.header.opts.enumOpt); optionsParser.handler.fatalError = ops_fatalError; optionsParser.handler.error = ops_fatalError; optionsParser.handler.startDocument = ops_startDocument; optionsParser.handler.endDocument = ops_endDocument; optionsParser.handler.startElement = ops_startElement; optionsParser.handler.attribute = ops_attribute; optionsParser.handler.stringData = ops_stringData; optionsParser.handler.endElement = ops_endElement; optionsParser.handler.intData = ops_intData; optionsParser.handler.booleanData = ops_boolData; appD.o_strm = &optionsParser.strm; appD.parsed_ops = &strm->header.opts; appD.prevElementLnID = 0; appD.prevElementUriID = 0; appD.permanentAllocList = &strm->memList; TRY_CATCH(setSchema(&optionsParser, (EXIPSchema*) &ops_schema), destroyParser(&optionsParser)); TRY_CATCH(createValueTable(&optionsParser.strm.valueTable), destroyParser(&optionsParser)); while(tmp_err_code == ERR_OK) { tmp_err_code = parseNext(&optionsParser); } destroyParser(&optionsParser); if(tmp_err_code != PARSING_COMPLETE) return tmp_err_code; strm->buffer.bufContent = optionsParser.strm.buffer.bufContent; strm->context.bitPointer = optionsParser.strm.context.bitPointer; strm->context.bufferIndx = optionsParser.strm.context.bufferIndx; if(WITH_COMPRESSION(strm->header.opts.enumOpt) || GET_ALIGNMENT(strm->header.opts.enumOpt) != BIT_PACKED) { // Padding bits if(strm->context.bitPointer != 0) { strm->context.bitPointer = 0; strm->context.bufferIndx += 1; } } } return checkOptionValues(&strm->header.opts); }
int main(int argc, char* argv[]) { UErrorCode status = U_ZERO_ERROR; const char *arg = NULL; const char *outputDir = NULL; /* NULL = no output directory, use current */ const char *inputDir = NULL; const char *encoding = ""; int i; U_MAIN_INIT_ARGS(argc, argv); argc = u_parseArgs(argc, argv, (int32_t)(sizeof(options)/sizeof(options[0])), options); /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "%s: error in command line argument \"%s\"\n", argv[0], argv[-argc]); } else if(argc<2) { argc = -1; } if(options[VERSION].doesOccur) { fprintf(stderr, "%s version %s (ICU version %s).\n" "%s\n", argv[0], GENRB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); return U_ZERO_ERROR; } if(argc<0 || options[HELP1].doesOccur || options[HELP2].doesOccur) { /* * Broken into chucks because the C89 standard says the minimum * required supported string length is 509 bytes. */ fprintf(stderr, "Usage: %s [OPTIONS] [FILES]\n" "\tReads the list of resource bundle source files and creates\n" "\tbinary version of reosurce bundles (.res files)\n", argv[0]); fprintf(stderr, "Options:\n" "\t-h or -? or --help this usage text\n" "\t-q or --quiet do not display warnings\n" "\t-v or --verbose print extra information when processing files\n" "\t-V or --version prints out version number and exits\n" "\t-c or --copyright include copyright notice\n"); fprintf(stderr, "\t-e or --encoding encoding of source files\n" "\t-d of --destdir destination directory, followed by the path, defaults to %s\n" "\t-s or --sourcedir source directory for files followed by path, defaults to %s\n" "\t-i or --icudatadir directory for locating any needed intermediate data files,\n" "\t followed by path, defaults to %s\n", u_getDataDirectory(), u_getDataDirectory(), u_getDataDirectory()); fprintf(stderr, "\t-j or --write-java write a Java ListResourceBundle for ICU4J, followed by optional encoding\n" "\t defaults to ASCII and \\uXXXX format.\n" "\t-p or --package-name For ICU4J: package name for writing the ListResourceBundle for ICU4J,\n" "\t defaults to com.ibm.icu.impl.data\n"); fprintf(stderr, "\t-b or --bundle-name bundle name for writing the ListResourceBundle for ICU4J,\n" "\t defaults to LocaleElements\n" "\t-x or --write-xliff write a XLIFF file for the resource bundle. Followed by an optional output file name.\n" "\t-k or --strict use pedantic parsing of syntax\n" /*added by Jing*/ "\t-l or --language For XLIFF: language code compliant with ISO 639.\n"); return argc < 0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; } if(options[VERBOSE].doesOccur) { setVerbose(TRUE); } if(options[QUIET].doesOccur) { setShowWarning(FALSE); } if(options[STRICT].doesOccur) { setStrict(TRUE); } if(options[COPYRIGHT].doesOccur){ setIncludeCopyright(TRUE); } if(options[SOURCEDIR].doesOccur) { inputDir = options[SOURCEDIR].value; } if(options[DESTDIR].doesOccur) { outputDir = options[DESTDIR].value; } if(options[PACKAGE_NAME].doesOccur) { gPackageName = options[PACKAGE_NAME].value; if(!strcmp(gPackageName, "ICUDATA")) { gPackageName = U_ICUDATA_NAME; } if(gPackageName[0] == 0) { gPackageName = NULL; } } if(options[ENCODING].doesOccur) { encoding = options[ENCODING].value; } if(options[ICUDATADIR].doesOccur) { u_setDataDirectory(options[ICUDATADIR].value); } /* Initialize ICU */ u_init(&status); if (U_FAILURE(status) && status != U_FILE_ACCESS_ERROR) { /* Note: u_init() will try to open ICU property data. * failures here are expected when building ICU from scratch. * ignore them. */ fprintf(stderr, "%s: can not initialize ICU. status = %s\n", argv[0], u_errorName(status)); exit(1); } status = U_ZERO_ERROR; if(options[WRITE_JAVA].doesOccur) { write_java = TRUE; outputEnc = options[WRITE_JAVA].value; } if(options[BUNDLE_NAME].doesOccur) { bundleName = options[BUNDLE_NAME].value; } if(options[WRITE_XLIFF].doesOccur) { write_xliff = TRUE; if(options[WRITE_XLIFF].value != NULL){ xliffOutputFileName = options[WRITE_XLIFF].value; } } if(options[NO_BINARY_COLLATION].doesOccur) { initParser(FALSE); } else { initParser(TRUE); } /*added by Jing*/ if(options[LANGUAGE].doesOccur) { language = options[LANGUAGE].value; } /* generate the binary files */ for(i = 1; i < argc; ++i) { status = U_ZERO_ERROR; arg = getLongPathname(argv[i]); if (inputDir) { uprv_strcpy(theCurrentFileName, inputDir); uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING); } else { *theCurrentFileName = 0; } uprv_strcat(theCurrentFileName, arg); if (isVerbose()) { printf("Processing file \"%s\"\n", theCurrentFileName); } processFile(arg, encoding, inputDir, outputDir, gPackageName, &status); } /* Dont return warnings as a failure */ if (! U_FAILURE(status)) { return 0; } return status; }
Parser::Parser() { initParser(); }
END_TEST START_TEST (test_strict_option) { EXIPSchema schema; Parser testParser; char buf[OUTPUT_BUFFER_SIZE]; errorCode tmp_err_code = UNEXPECTED_ERROR; BinaryBuffer buffer; char exipath[MAX_PATH_LEN + strlen(EMPTY_TYPE_DEFAULT)]; size_t pathlen; FILE *infile; struct appData parsingData; buffer.buf = buf; buffer.bufContent = 0; buffer.bufLen = OUTPUT_BUFFER_SIZE; buffer.ioStrm.readWriteToStream = NULL; buffer.ioStrm.stream = NULL; // Parsing steps: // I.A: First, read in the schema parseSchema(EMPTY_TYPE_SCHEMA, &schema); // I.B: Define an external stream for the input to the parser if any pathlen = strlen(dataDir); memcpy(exipath, dataDir, pathlen); exipath[pathlen] = '/'; memcpy(&exipath[pathlen+1], EMPTY_TYPE_STRICT, strlen(EMPTY_TYPE_STRICT)+1); infile = fopen(exipath, "rb" ); if(!infile) fail("Unable to open file %s", exipath); buffer.ioStrm.readWriteToStream = readFileInputStream; buffer.ioStrm.stream = infile; // II: Second, initialize the parser object tmp_err_code = initParser(&testParser, buffer, &schema, &parsingData); fail_unless (tmp_err_code == ERR_OK, "initParser returns an error code %d", tmp_err_code); // III: Initialize the parsing data and hook the callback handlers to the parser object parsingData.eventCount = 0; parsingData.expectAttributeData = 0; testParser.handler.fatalError = sample_fatalError; testParser.handler.error = sample_fatalError; testParser.handler.startElement = sample_startElement; testParser.handler.attribute = sample_attribute; testParser.handler.stringData = sample_stringData; testParser.handler.intData = sample_intData; // IV: Parse the header of the stream tmp_err_code = parseHeader(&testParser); fail_unless (tmp_err_code == ERR_OK, "parsing the header returns an error code %d", tmp_err_code); // V: Parse the body of the EXI stream while(tmp_err_code == ERR_OK) { tmp_err_code = parseNext(&testParser); } // VI: Free the memory allocated by the parser object destroyParser(&testParser); fail_unless (tmp_err_code == PARSING_COMPLETE, "Error during parsing of the EXI body %d", tmp_err_code); }
int main(int argc, char* argv[]) { UErrorCode status = U_ZERO_ERROR; const char *arg = NULL; const char *outputDir = NULL; /* NULL = no output directory, use current */ const char *inputDir = NULL; const char *encoding = ""; int i; U_MAIN_INIT_ARGS(argc, argv); argc = u_parseArgs(argc, argv, (int32_t)(sizeof(options)/sizeof(options[0])), options); /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "%s: error in command line argument \"%s\"\n", argv[0], argv[-argc]); } else if(argc<2) { argc = -1; } if(options[WRITE_POOL_BUNDLE].doesOccur && options[USE_POOL_BUNDLE].doesOccur) { fprintf(stderr, "%s: cannot combine --writePoolBundle and --usePoolBundle\n", argv[0]); argc = -1; } if(options[FORMAT_VERSION].doesOccur) { const char *s = options[FORMAT_VERSION].value; if(uprv_strlen(s) != 1 || (s[0] != '1' && s[0] != '2')) { fprintf(stderr, "%s: unsupported --formatVersion %s\n", argv[0], s); argc = -1; } else if(s[0] == '1' && (options[WRITE_POOL_BUNDLE].doesOccur || options[USE_POOL_BUNDLE].doesOccur) ) { fprintf(stderr, "%s: cannot combine --formatVersion 1 with --writePoolBundle or --usePoolBundle\n", argv[0]); argc = -1; } else { setFormatVersion(s[0] - '0'); } } if(options[VERSION].doesOccur) { fprintf(stderr, "%s version %s (ICU version %s).\n" "%s\n", argv[0], GENRB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); return U_ZERO_ERROR; } if(argc<0 || options[HELP1].doesOccur || options[HELP2].doesOccur) { /* * Broken into chunks because the C89 standard says the minimum * required supported string length is 509 bytes. */ fprintf(stderr, "Usage: %s [OPTIONS] [FILES]\n" "\tReads the list of resource bundle source files and creates\n" "\tbinary version of reosurce bundles (.res files)\n", argv[0]); fprintf(stderr, "Options:\n" "\t-h or -? or --help this usage text\n" "\t-q or --quiet do not display warnings\n" "\t-v or --verbose print extra information when processing files\n" "\t-V or --version prints out version number and exits\n" "\t-c or --copyright include copyright notice\n"); fprintf(stderr, "\t-e or --encoding encoding of source files\n" "\t-d of --destdir destination directory, followed by the path, defaults to %s\n" "\t-s or --sourcedir source directory for files followed by path, defaults to %s\n" "\t-i or --icudatadir directory for locating any needed intermediate data files,\n" "\t followed by path, defaults to %s\n", u_getDataDirectory(), u_getDataDirectory(), u_getDataDirectory()); fprintf(stderr, "\t-j or --write-java write a Java ListResourceBundle for ICU4J, followed by optional encoding\n" "\t defaults to ASCII and \\uXXXX format.\n"); /* This option is deprecated and should not be used ever. "\t-p or --package-name For ICU4J: package name for writing the ListResourceBundle for ICU4J,\n" "\t defaults to com.ibm.icu.impl.data\n"); */ fprintf(stderr, "\t-b or --bundle-name bundle name for writing the ListResourceBundle for ICU4J,\n" "\t defaults to LocaleElements\n" "\t-x or --write-xliff write an XLIFF file for the resource bundle. Followed by\n" "\t an optional output file name.\n" "\t-k or --strict use pedantic parsing of syntax\n" /*added by Jing*/ "\t-l or --language for XLIFF: language code compliant with BCP 47.\n"); fprintf(stderr, "\t-C or --noBinaryCollation do not generate binary collation image;\n" "\t makes .res file smaller but collator instantiation much slower;\n" "\t maintains ability to get tailoring rules\n" "\t-R or --omitCollationRules do not include collation (tailoring) rules;\n" "\t makes .res file smaller and maintains collator instantiation speed\n" "\t but tailoring rules will not be available (they are rarely used)\n"); fprintf(stderr, "\t --formatVersion write a .res file compatible with the requested formatVersion (single digit);\n" "\t for example, --formatVersion 1\n"); fprintf(stderr, "\t --writePoolBundle write a pool.res file with all of the keys of all input bundles\n" "\t --usePoolBundle [path-to-pool.res] point to keys from the pool.res keys pool bundle if they are available there;\n" "\t makes .res files smaller but dependent on the pool bundle\n" "\t (--writePoolBundle and --usePoolBundle cannot be combined)\n"); return argc < 0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; } if(options[VERBOSE].doesOccur) { setVerbose(TRUE); } if(options[QUIET].doesOccur) { setShowWarning(FALSE); } if(options[STRICT].doesOccur) { setStrict(TRUE); } if(options[COPYRIGHT].doesOccur){ setIncludeCopyright(TRUE); } if(options[SOURCEDIR].doesOccur) { inputDir = options[SOURCEDIR].value; } if(options[DESTDIR].doesOccur) { outputDir = options[DESTDIR].value; } /* This option is deprecated and should never be used. if(options[PACKAGE_NAME].doesOccur) { gPackageName = options[PACKAGE_NAME].value; if(!strcmp(gPackageName, "ICUDATA")) { gPackageName = U_ICUDATA_NAME; } if(gPackageName[0] == 0) { gPackageName = NULL; } }*/ if(options[ENCODING].doesOccur) { encoding = options[ENCODING].value; } if(options[ICUDATADIR].doesOccur) { u_setDataDirectory(options[ICUDATADIR].value); } /* Initialize ICU */ u_init(&status); if (U_FAILURE(status) && status != U_FILE_ACCESS_ERROR) { /* Note: u_init() will try to open ICU property data. * failures here are expected when building ICU from scratch. * ignore them. */ fprintf(stderr, "%s: can not initialize ICU. status = %s\n", argv[0], u_errorName(status)); exit(1); } status = U_ZERO_ERROR; if(options[WRITE_JAVA].doesOccur) { write_java = TRUE; outputEnc = options[WRITE_JAVA].value; } if(options[BUNDLE_NAME].doesOccur) { bundleName = options[BUNDLE_NAME].value; } if(options[WRITE_XLIFF].doesOccur) { write_xliff = TRUE; if(options[WRITE_XLIFF].value != NULL){ xliffOutputFileName = options[WRITE_XLIFF].value; } } initParser(options[NO_BINARY_COLLATION].doesOccur, options[NO_COLLATION_RULES].doesOccur); /*added by Jing*/ if(options[LANGUAGE].doesOccur) { language = options[LANGUAGE].value; } if(options[WRITE_POOL_BUNDLE].doesOccur) { newPoolBundle = bundle_open(NULL, TRUE, &status); if(U_FAILURE(status)) { fprintf(stderr, "unable to create an empty bundle for the pool keys: %s\n", u_errorName(status)); return status; } else { const char *poolResName = "pool.res"; char *nameWithoutSuffix = uprv_malloc(uprv_strlen(poolResName) + 1); if (nameWithoutSuffix == NULL) { fprintf(stderr, "out of memory error\n"); return U_MEMORY_ALLOCATION_ERROR; } uprv_strcpy(nameWithoutSuffix, poolResName); *uprv_strrchr(nameWithoutSuffix, '.') = 0; newPoolBundle->fLocale = nameWithoutSuffix; } } if(options[USE_POOL_BUNDLE].doesOccur) { const char *poolResName = "pool.res"; FileStream *poolFile; int32_t poolFileSize; int32_t indexLength; /* * TODO: Consolidate inputDir/filename handling from main() and processFile() * into a common function, and use it here as well. * Try to create toolutil functions for dealing with dir/filenames and * loading ICU data files without udata_open(). * Share code with icupkg? * Also, make_res_filename() seems to be unused. Review and remove. */ if (options[USE_POOL_BUNDLE].value!=NULL) { uprv_strcpy(theCurrentFileName, options[USE_POOL_BUNDLE].value); uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING); } else if (inputDir) { uprv_strcpy(theCurrentFileName, inputDir); uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING); } else { *theCurrentFileName = 0; } uprv_strcat(theCurrentFileName, poolResName); poolFile = T_FileStream_open(theCurrentFileName, "rb"); if (poolFile == NULL) { fprintf(stderr, "unable to open pool bundle file %s\n", theCurrentFileName); return 1; } poolFileSize = T_FileStream_size(poolFile); if (poolFileSize < 32) { fprintf(stderr, "the pool bundle file %s is too small\n", theCurrentFileName); return 1; } poolBundle.fBytes = (uint8_t *)uprv_malloc((poolFileSize + 15) & ~15); if (poolFileSize > 0 && poolBundle.fBytes == NULL) { fprintf(stderr, "unable to allocate memory for the pool bundle file %s\n", theCurrentFileName); return U_MEMORY_ALLOCATION_ERROR; } else { UDataSwapper *ds; const DataHeader *header; int32_t bytesRead = T_FileStream_read(poolFile, poolBundle.fBytes, poolFileSize); int32_t keysBottom; if (bytesRead != poolFileSize) { fprintf(stderr, "unable to read the pool bundle file %s\n", theCurrentFileName); return 1; } /* * Swap the pool bundle so that a single checked-in file can be used. * The swapper functions also test that the data looks like * a well-formed .res file. */ ds = udata_openSwapperForInputData(poolBundle.fBytes, bytesRead, U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, &status); if (U_FAILURE(status)) { fprintf(stderr, "udata_openSwapperForInputData(pool bundle %s) failed: %s\n", theCurrentFileName, u_errorName(status)); return status; } ures_swap(ds, poolBundle.fBytes, bytesRead, poolBundle.fBytes, &status); udata_closeSwapper(ds); if (U_FAILURE(status)) { fprintf(stderr, "ures_swap(pool bundle %s) failed: %s\n", theCurrentFileName, u_errorName(status)); return status; } header = (const DataHeader *)poolBundle.fBytes; if (header->info.formatVersion[0]!=2) { fprintf(stderr, "invalid format of pool bundle file %s\n", theCurrentFileName); return U_INVALID_FORMAT_ERROR; } poolBundle.fKeys = (const char *)header + header->dataHeader.headerSize; poolBundle.fIndexes = (const int32_t *)poolBundle.fKeys + 1; indexLength = poolBundle.fIndexes[URES_INDEX_LENGTH] & 0xff; if (indexLength <= URES_INDEX_POOL_CHECKSUM) { fprintf(stderr, "insufficient indexes[] in pool bundle file %s\n", theCurrentFileName); return U_INVALID_FORMAT_ERROR; } keysBottom = (1 + indexLength) * 4; poolBundle.fKeys += keysBottom; poolBundle.fKeysLength = (poolBundle.fIndexes[URES_INDEX_KEYS_TOP] * 4) - keysBottom; poolBundle.fChecksum = poolBundle.fIndexes[URES_INDEX_POOL_CHECKSUM]; } for (i = 0; i < poolBundle.fKeysLength; ++i) { if (poolBundle.fKeys[i] == 0) { ++poolBundle.fKeysCount; } } T_FileStream_close(poolFile); setUsePoolBundle(TRUE); } if(options[INCLUDE_UNIHAN_COLL].doesOccur) { gIncludeUnihanColl = TRUE; } if((argc-1)!=1) { printf("genrb number of files: %d\n", argc - 1); } /* generate the binary files */ for(i = 1; i < argc; ++i) { status = U_ZERO_ERROR; arg = getLongPathname(argv[i]); if (inputDir) { uprv_strcpy(theCurrentFileName, inputDir); uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING); } else { *theCurrentFileName = 0; } uprv_strcat(theCurrentFileName, arg); if (isVerbose()) { printf("Processing file \"%s\"\n", theCurrentFileName); } processFile(arg, encoding, inputDir, outputDir, gPackageName, &status); } uprv_free(poolBundle.fBytes); if(options[WRITE_POOL_BUNDLE].doesOccur) { char outputFileName[256]; bundle_write(newPoolBundle, outputDir, NULL, outputFileName, sizeof(outputFileName), &status); bundle_close(newPoolBundle, &status); if(U_FAILURE(status)) { fprintf(stderr, "unable to write the pool bundle: %s\n", u_errorName(status)); } } /* Dont return warnings as a failure */ if (U_SUCCESS(status)) { return 0; } return status; }