int strStr(char *haystack, char *needle) { if (*needle == '\0') { return 0; } int sz0 = strlen(haystack), sz1 = strlen(needle); if (sz0 < sz1) { return -1; } Hash hs0, hs1; initHash(&hs0, haystack, sz1); initHash(&hs1, needle, sz1); int i; unsigned long long ptn = getHash(&hs1); unsigned long long val; for (i = 0; i != sz0 - sz1 + 1; i++) { val = getHash(&hs0); if (val == ptn) { LOG("index %d find match hash %llu\n", i, val); if (strncmp(haystack + i, needle, sz1) == 0) { return i; } } rollHash(&hs0); } return -1; }
TimeUnitFormat& TimeUnitFormat::operator=(const TimeUnitFormat& other) { if (this == &other) { return *this; } MeasureFormat::operator=(other); for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR; i < TimeUnit::UTIMEUNIT_FIELD_COUNT; i = (TimeUnit::UTimeUnitFields)(i+1)) { deleteHash(fTimeUnitToCountToPatterns[i]); fTimeUnitToCountToPatterns[i] = NULL; } for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR; i < TimeUnit::UTIMEUNIT_FIELD_COUNT; i = (TimeUnit::UTimeUnitFields)(i+1)) { UErrorCode status = U_ZERO_ERROR; fTimeUnitToCountToPatterns[i] = initHash(status); if (U_SUCCESS(status)) { copyHash(other.fTimeUnitToCountToPatterns[i], fTimeUnitToCountToPatterns[i], status); } else { delete fTimeUnitToCountToPatterns[i]; fTimeUnitToCountToPatterns[i] = NULL; } } fStyle = other.fStyle; return *this; }
// Init VSL library and read from stream VSLLib::VSLLib(std::istream& i, unsigned optimizeMode) : _lib_name(""), _first(0), _last(0) { initHash(); update(i); optimize(optimizeMode); }
int main(int argc, char *argv[]) { int i, len; // char buf1[1000]; int inputID; char buf[1000]; //多宣告一個buf2暫存字串, buf2儲存name FILE *f; struct hashtable h; struct node *check; initHash(&h, 13); if (argc >= 2) { f =fopen(argv[1], "r"); //open with read only mod if ( f == NULL) { printf("file open fail, please check filename and privilege\n"); return 1; } while (fscanf(f, "%d %s", inputID, buf) != EOF) { //改成兩個input, 以空格間隔 addHash(&h, inputID, buf); } } else { printf("please specify filename as the first argument\n"); } // test hash table printf("Please input your studentID:"); scanf("%d", &inputID); check = existHash(&h, &inputID); //檢查時, 用學號檢查 if (check != NULL ) { printf("Your student name is %s\n", check->name); } else { printf("You student ID is not exist!!\n"); } return 0; }
CurrencyPluralInfo& CurrencyPluralInfo::operator=(const CurrencyPluralInfo& info) { if (this == &info) { return *this; } deleteHash(fPluralCountToCurrencyUnitPattern); UErrorCode status = U_ZERO_ERROR; fPluralCountToCurrencyUnitPattern = initHash(status); copyHash(info.fPluralCountToCurrencyUnitPattern, fPluralCountToCurrencyUnitPattern, status); if ( U_FAILURE(status) ) { return *this; } delete fPluralRules; delete fLocale; if (info.fPluralRules) { fPluralRules = info.fPluralRules->clone(); } else { fPluralRules = NULL; } if (info.fLocale) { fLocale = info.fLocale->clone(); } else { fLocale = NULL; } return *this; }
// Init VSL library and read from file VSLLib::VSLLib(const string& lib_name, unsigned optimizeMode) : _lib_name(lib_name), _first(0), _last(0) { initHash(); update(lib_name); optimize(optimizeMode); }
/** * postSort() runs after the sort has been performed. For HphpArray, postSort() * handles rebuilding the hash. Also, if resetKeys is true, postSort() will * renumber the keys 0 thru n-1. */ void HphpArray::postSort(bool resetKeys) { assert(m_size > 0); auto const ht = hashTab(); initHash(ht, hashSize()); m_hLoad = 0; if (resetKeys) { for (uint32_t pos = 0; pos < m_used; ++pos) { auto& e = data()[pos]; if (e.hasStrKey()) decRefStr(e.key); e.setIntKey(pos); ht[pos] = pos; } m_nextKI = m_size; } else { auto mask = m_tableMask; auto data = this->data(); for (uint32_t pos = 0; pos < m_used; ++pos) { auto& e = data[pos]; auto ei = findForNewInsert(ht, mask, e.hasIntKey() ? e.ikey : e.hash()); *ei = pos; } } m_hLoad = m_size; }
void TimeUnitFormat::checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& err) { if (U_FAILURE(err)) { return; } // there should be patterns for each plural rule in each time unit. // For each time unit, // for each plural rule, following is unit pattern fall-back rule: // ( for example: "one" hour ) // look for its unit pattern in its locale tree. // if pattern is not found in its own locale, such as de_DE, // look for the pattern in its parent, such as de, // keep looking till found or till root. // if the pattern is not found in root either, // fallback to plural count "other", // look for the pattern of "other" in the locale tree: // "de_DE" to "de" to "root". // If not found, fall back to value of // static variable DEFAULT_PATTERN_FOR_xxx, such as "{0} h". // // Following is consistency check to create pattern for each // plural rule in each time unit using above fall-back rule. // StringEnumeration* keywords = getPluralRules().getKeywords(err); if (U_SUCCESS(err)) { const UnicodeString* pluralCount; while ((pluralCount = keywords->snext(err)) != NULL) { if ( U_SUCCESS(err) ) { for (int32_t i = 0; i < TimeUnit::UTIMEUNIT_FIELD_COUNT; ++i) { // for each time unit, // get all the patterns for each plural rule in this locale. Hashtable* countToPatterns = fTimeUnitToCountToPatterns[i]; if ( countToPatterns == NULL ) { countToPatterns = initHash(err); if (U_FAILURE(err)) { delete countToPatterns; return; } fTimeUnitToCountToPatterns[i] = countToPatterns; } MessageFormat** formatters = (MessageFormat**)countToPatterns->get(*pluralCount); if( formatters == NULL || formatters[style] == NULL ) { // look through parents const char* localeName = getLocaleID(err); CharString pluralCountChars; pluralCountChars.appendInvariantChars(*pluralCount, err); searchInLocaleChain(style, key, localeName, (TimeUnit::UTimeUnitFields)i, *pluralCount, pluralCountChars.data(), countToPatterns, err); } } } } } delete keywords; }
/* ========================================================================== * Function that calls my reload to Index function (reloadIndexHash()) * on a file, reads the file and reconstitutes the hash index. * * *** Content *** * Read in characters from file until file is over, and split up the string * by a whitespace (strtok) and place the relevant parts into the hash table * ========================================================================== */ HashTable *ReadFile(char *filePath) { FILE *fp; fp = fopen(filePath, "r"); if (!fp) { fprintf(stderr, "HashTable reload file failed to open.\n"); exit (1); } HashTable *reloadIndex; reloadIndex = initHash(); char *indexInfo = LoadDocIndex(filePath); // get index.dat into a string char *readIn = NULL; readIn = (char*)calloc(strlen(indexInfo) + 1, sizeof(char)); for ( ;; ) { if (fgets(readIn, strlen(indexInfo) + 1, fp) == NULL) { break; // no more lines in file, stop infinite loop } else { char *document; char *word; // get the first white-spaced delimited element in index.dat // if properly formatted, this will be the word character. char copy[strlen(readIn) + 1]; strcpy(copy, readIn); // want to free readIn later // don't need the number of docnodes. skip over word = strtok(copy, " "); strtok(NULL, " "); while ((document = strtok(NULL, " ")) != NULL) { // "document" now refers to docID char *freqChar = strtok(NULL, " "); // every other number is frequency if (strchr(document, '\n')) { break; // this means that freq will be NULL, so break out } int ID = GetDocID(document); int freq = atoi(freqChar); reloadIndexHash(word, ID, freq, reloadIndex); } } } fclose(fp); free(readIn); free(indexInfo); // char returned by LoadDoc() needs to be freed return reloadIndex; }
int main(int argc, char *argv[]){ Hash_t aHash; SetElem_t *pElem; DoubleLinkedList_t aLinkedList; struct DoubleLinkedListElem *pListElem; aHash = initHash(16); pElem = calloc(1, sizeof(SetElem_t)); pElem->key.intKey = 3; dirHash_insert(aHash, pElem); pElem = calloc(1, sizeof(SetElem_t)); pElem->key.intKey = 8; dirHash_insert(aHash, pElem); aLinkedList = dirHash_search(aHash, 5); printf("%x\n", aLinkedList); if (aLinkedList){ dumpDoubleLinkedList_int(aLinkedList); } aLinkedList = dirHash_search(aHash, 3); printf("%x\n", aLinkedList); if (aLinkedList){ dumpDoubleLinkedList_int(aLinkedList); } pElem = calloc(1, sizeof(SetElem_t)); pElem->key.intKey = 3; dirHash_insert(aHash, pElem); aLinkedList = dirHash_search(aHash, 3); printf("%x\n", aLinkedList); if (aLinkedList){ dumpDoubleLinkedList_int(aLinkedList); } pListElem = aLinkedList->next; dirHash_delete(aHash, pListElem); aLinkedList = dirHash_search(aHash, 3); printf("%x\n", aLinkedList); if (aLinkedList){ dumpDoubleLinkedList_int(aLinkedList); } aLinkedList = dirHash_search(aHash, 8); printf("%x\n", aLinkedList); if (aLinkedList){ dumpDoubleLinkedList_int(aLinkedList); } pListElem = aLinkedList->next; dirHash_delete(aHash, pListElem); aLinkedList = dirHash_search(aHash, 8); printf("%x\n", aLinkedList); if (aLinkedList){ dumpDoubleLinkedList_int(aLinkedList); } }
TimeUnitFormat::TimeUnitFormat(const TimeUnitFormat& other) : MeasureFormat(other), fStyle(other.fStyle) { for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR; i < TimeUnit::UTIMEUNIT_FIELD_COUNT; i = (TimeUnit::UTimeUnitFields)(i+1)) { UErrorCode status = U_ZERO_ERROR; fTimeUnitToCountToPatterns[i] = initHash(status); if (U_SUCCESS(status)) { copyHash(other.fTimeUnitToCountToPatterns[i], fTimeUnitToCountToPatterns[i], status); } else { delete fTimeUnitToCountToPatterns[i]; fTimeUnitToCountToPatterns[i] = NULL; } } }
int main() { //start statment initHash(symbolTable, tableSize); while(1) { int error = 0; char input[100]; char commands[100]; printf("* "); getInput(input); separateCommand(input, commands); handleCommand(commands); } //end statment return 0; }
/** * postSort() runs after the sort has been performed. For MixedArray, postSort() * handles rebuilding the hash. Also, if resetKeys is true, postSort() will * renumber the keys 0 thru n-1. */ void MixedArray::postSort(bool resetKeys) { // nothrow guarantee assert(m_size > 0); auto const ht = hashTab(); initHash(ht, m_scale); if (resetKeys) { for (uint32_t pos = 0; pos < m_used; ++pos) { auto& e = data()[pos]; if (e.hasStrKey()) decRefStr(e.skey); e.setIntKey(pos); ht[pos] = pos; } m_nextKI = m_size; } else { auto mask = this->mask(); auto data = this->data(); for (uint32_t pos = 0; pos < m_used; ++pos) { auto& e = data[pos]; *findForNewInsert(ht, mask, e.probe()) = pos; } } }
void OneSideHashJoin::init(DbEnv *env_){ assert(innerOpeNode != NULL && outerOpeNode != NULL); env = env_; innerOpeNode->init(env); outerOpeNode->init(env); innerAttriNum = innerOpeNode->getAttriNum(); outerAttriNum = outerOpeNode->getAttriNum(); attriNum = innerAttriNum + outerAttriNum; initAttriRec(attriNum); innerOpeNode->getAttriRec(attriRec, innerAttriNum); outerOpeNode->getAttriRec(attriRec + innerAttriNum, outerAttriNum); initPosVal(); setJoinPos(); //initHashTable(); initHash(); storeInnerNode(); getRowFlag = 0; }
void DiskRW(char fileWrite[]){ char* page = NULL; int num_page = 32;//the size of buffer int page_size = 64; //the size of page initHash(num_page); //init hash function BufMgr* bm = new BufMgr(fileWrite, num_page, 1024*1024, page_size, page_size); int page_no = 0; int offset = 0; bm->PinPage(page_no, page); /*FILE* in = fopen("a.txt", "r"); char c; while(!feof(in)){ fscanf(in,"%c",&c); writeBytes(bm, page, &c, 1, page_no,offset); } fclose(in);*/ /*for(vector<str>::iterator Iter=StrList.begin();Iter!=StrList.end();Iter++) for(int i=0;i<Iter->len;i++) writeBytes(bm, page, &Iter->s[i], 1, page_no, offset);*/ /*int total_page = page_no; int total_offset = offset; page_no = 0; offset = 0; while(page_no <= total_page){ readBytes(bm,&c,1,page,page_no,offset); printf("%c",c); }*/ /*delete bm; bm = NULL;*/ }
int main() { initHash(num_page); //init hash function char Target[800]="A"; int Threshold=4; time_t Start1,End1; //time_t Start2,End2; //initFreebase(); time(&Start1); join1(Target,Threshold); time(&End1); printf("Join 1 Used Time is:%d\n",(int)difftime(End1,Start1)); /*time(&Start2); join2(Target,Threshold); time(&End2); printf("Join 2 Used Time is:%d\n",(int)difftime(End2,Start2));*/ return 0; }
TimeUnitFormat& TimeUnitFormat::operator=(const TimeUnitFormat& other) { if (this == &other) { return *this; } delete fNumberFormat; for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR; i < TimeUnit::UTIMEUNIT_FIELD_COUNT; i = (TimeUnit::UTimeUnitFields)(i+1)) { deleteHash(fTimeUnitToCountToPatterns[i]); fTimeUnitToCountToPatterns[i] = NULL; } delete fPluralRules; if (other.fNumberFormat) { fNumberFormat = (NumberFormat*)other.fNumberFormat->clone(); } else { fNumberFormat = NULL; } fLocale = other.fLocale; for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR; i < TimeUnit::UTIMEUNIT_FIELD_COUNT; i = (TimeUnit::UTimeUnitFields)(i+1)) { UErrorCode status = U_ZERO_ERROR; fTimeUnitToCountToPatterns[i] = initHash(status); if (U_SUCCESS(status)) { copyHash(other.fTimeUnitToCountToPatterns[i], fTimeUnitToCountToPatterns[i], status); } else { delete fTimeUnitToCountToPatterns[i]; fTimeUnitToCountToPatterns[i] = NULL; } } if (other.fPluralRules) { fPluralRules = (PluralRules*)other.fPluralRules->clone(); } else { fPluralRules = NULL; } fStyle = other.fStyle; return *this; }
/** * postSort() runs after the sort has been performed. For HphpArray, postSort() * handles rebuilding the hash. Also, if resetKeys is true, postSort() will * renumber the keys 0 thru n-1. */ void HphpArray::postSort(bool resetKeys) { assert(m_size > 0); size_t tableSize = computeTableSize(m_tableMask); initHash(m_hash, tableSize); m_hLoad = 0; if (resetKeys) { for (uint32_t pos = 0; pos < m_used; ++pos) { Elm* e = &m_data[pos]; if (e->hasStrKey()) decRefStr(e->key); e->setIntKey(pos); m_hash[pos] = pos; } m_nextKI = m_size; } else { for (uint32_t pos = 0; pos < m_used; ++pos) { Elm* e = &m_data[pos]; ElmInd* ei = findForNewInsert(e->hasIntKey() ? e->ikey : e->hash()); *ei = pos; } } m_hLoad = m_size; }
void main() { int is_success; is_success = hcreate(100); initHash(); ENTRY item; ENTRY* result; item.key = "auto"; result = hsearch(item, FIND); id* id_back = result->data; int count_back = id_back->count; printf("count: %d\n",count_back); /* Entry* result; Entity* entity = (Entity*)malloc(sizeof(Entity)); entity->count = 1; result->data = entity; int count_back = (**result).count; //Entity* entity_back = result->data; //entity_back->count += 1; //int count_back = entity_back->count; */ }
/** * postSort() runs after the sort has been performed. For HphpArray, postSort() * handles rebuilding the hash. Also, if resetKeys is true, postSort() will * renumber the keys 0 thru n-1. */ void HphpArray::postSort(bool resetKeys) { ASSERT(m_size > 0); size_t tableSize = computeTableSize(m_tableMask); initHash(m_hash, tableSize); m_hLoad = 0; if (resetKeys) { for (ElmInd pos = 0; pos <= m_lastE; ++pos) { Elm* e = &m_data[pos]; if (e->hasStrKey() && e->key->decRefCount() == 0) { e->key->release(); } e->setIntKey(pos); m_hash[pos] = pos; } m_nextKI = m_size; } else { for (ElmInd pos = 0; pos <= m_lastE; ++pos) { Elm* e = &m_data[pos]; ElmInd* ei = findForNewInsert(e->hasIntKey() ? e->ikey : e->hash); *ei = pos; } } m_hLoad = m_size; }
RandomHash(D tnum_, ABST abst = SINGLE) : round(0) { initHash(); }
void CurrencyPluralInfo::setupCurrencyPluralPattern(const Locale& loc, UErrorCode& status) { if (U_FAILURE(status)) { return; } fPluralCountToCurrencyUnitPattern = initHash(status); if (U_FAILURE(status)) { return; } UErrorCode ec = U_ZERO_ERROR; UResourceBundle *rb = ures_open(NULL, loc.getName(), &ec); UResourceBundle *numberPatterns = ures_getByKey(rb, gNumberPatternsTag, NULL, &ec); int32_t ptnLen; // TODO: 0 to be NumberFormat::fNumberStyle const UChar* numberStylePattern = ures_getStringByIndex(numberPatterns, 0, &ptnLen, &ec); int32_t numberStylePatternLen = ptnLen; const UChar* negNumberStylePattern = NULL; int32_t negNumberStylePatternLen = 0; // TODO: Java // parse to check whether there is ";" separator in the numberStylePattern UBool hasSeparator = false; if (U_SUCCESS(ec)) { for (int32_t styleCharIndex = 0; styleCharIndex < ptnLen; ++styleCharIndex) { if (numberStylePattern[styleCharIndex] == gNumberPatternSeparator) { hasSeparator = true; // split the number style pattern into positive and negative negNumberStylePattern = numberStylePattern + styleCharIndex + 1; negNumberStylePatternLen = ptnLen - styleCharIndex - 1; numberStylePatternLen = styleCharIndex; } } } ures_close(numberPatterns); if (U_FAILURE(ec)) { ures_close(rb); return; } UResourceBundle *currencyRes = ures_getByKeyWithFallback(rb, gCurrUnitPtnTag, NULL, &ec); #ifdef CURRENCY_PLURAL_INFO_DEBUG std::cout << "in set up\n"; #endif StringEnumeration* keywords = fPluralRules->getKeywords(ec); if (U_SUCCESS(ec)) { const char* pluralCount; while ((pluralCount = keywords->next(NULL, ec)) != NULL) { if ( U_SUCCESS(ec) ) { int32_t ptnLen; UErrorCode err = U_ZERO_ERROR; const UChar* patternChars = ures_getStringByKeyWithFallback( currencyRes, pluralCount, &ptnLen, &err); if (U_SUCCESS(err) && ptnLen > 0) { UnicodeString* pattern = new UnicodeString(patternChars, ptnLen); #ifdef CURRENCY_PLURAL_INFO_DEBUG char result_1[1000]; pattern->extract(0, pattern->length(), result_1, "UTF-8"); std::cout << "pluralCount: " << pluralCount << "; pattern: " << result_1 << "\n"; #endif pattern->findAndReplace(gPart0, UnicodeString(numberStylePattern, numberStylePatternLen)); pattern->findAndReplace(gPart1, gTripleCurrencySign); if (hasSeparator) { UnicodeString negPattern(patternChars, ptnLen); negPattern.findAndReplace(gPart0, UnicodeString(negNumberStylePattern, negNumberStylePatternLen)); negPattern.findAndReplace(gPart1, gTripleCurrencySign); pattern->append(gNumberPatternSeparator); pattern->append(negPattern); } #ifdef CURRENCY_PLURAL_INFO_DEBUG pattern->extract(0, pattern->length(), result_1, "UTF-8"); std::cout << "pluralCount: " << pluralCount << "; pattern: " << result_1 << "\n"; #endif fPluralCountToCurrencyUnitPattern->put(UnicodeString(pluralCount), pattern, status); } } } } delete keywords; ures_close(currencyRes); ures_close(rb); }
int main(int argc, char *argv[]) { int numThreads, time, initListSize, elementsRange; Input input = parseArgs(argc, argv, &numThreads, &time, &initListSize, &elementsRange); struct allocator allocator; int allocSize = HEAP_SIZE; #if !defined(OA) allocSize = 6000000;//15000000 #elif defined(MOA) allocSize=(numThreads>32 || (numThreads==32 && input.fractionInserts>0.2))?50000:allocSize; //for 32 threads a heap of 20000 items is too small. #endif init_allocator(&allocator, lalloc, numThreads, dirties, allocSize, HPsPerThread); #ifdef HASH_OP int logLen=0, size=(int)(initListSize/LOAD_FACTOR); while(size/=2) logLen++; assert(logLen!=0);//don't know why, but the HASH don't work well. if(logLen<9) logLen=9; assert(1<<logLen >= ARR_ENTRIES_PER_BIT); initHash(&hash, logLen); #endif for (int i = 0; i < numThreads; i++) { tg[i].input = input; tg[i].input.threadID = i; tg[i].dirty = dirties+i; tg[i].entryAllocator = lalloc+i; } // end of for loop, initializing the threads data initialize_ds(initListSize, elementsRange, tg); for (int i = 0; i < numThreads; i++) { if(pthread_create(&workerThreads[i], NULL, start_routine, &tg[i])){ printf("Error occurred when creating thread %d\n", i); exit(1); } } ////////////START TEST run = TRUE; __sync_synchronize(); sleep(time); stop=TRUE; __sync_synchronize(); ////////////END TEST for (int i=0; i< numThreads; ++i) { // join all threads pthread_join(workerThreads[i], NULL); } //TIME g_timer_stop(t); #ifndef MALLOC destroyAllocator(&allocator); #endif #if defined(OA) int numPhases = allocator.phase.phase/2-INIT_PHASE; #else int numPhases = 0; #endif num_ops = (long long)num_ops / (long double)time; const double M=1000000; printf(HG_VER "Threads=%d, Thpt=%ld, ThptM=%.1f, Phases=%d, Time=%f, InitSize=%d, Range=%d, SearchFrac=%.2f\n", numThreads, num_ops, num_ops/M, numPhases, (double)time, initListSize, elementsRange, 1-tg[0].input.fractionInserts-tg[0].input.fractionDeletes); printf("___ %ld %d %.2f\n", num_ops, numThreads, 1-tg[0].input.fractionInserts-tg[0].input.fractionDeletes); #if !defined(MOA) && !defined(OA) extern int alcctr; printf("alcctr = %d\n", alcctr); //extern int m; //printf("m =%d\n", m); #endif //TIME printf("___ %f %d %.2f\n", totalTime, numThreads, 1 - atof(argv[6]) - atof(argv[5])); return 0; }
void CurrencyPluralInfo::setupCurrencyPluralPattern(const Locale& loc, UErrorCode& status) { if (U_FAILURE(status)) { return; } if (fPluralCountToCurrencyUnitPattern) { deleteHash(fPluralCountToCurrencyUnitPattern); } fPluralCountToCurrencyUnitPattern = initHash(status); if (U_FAILURE(status)) { return; } NumberingSystem *ns = NumberingSystem::createInstance(loc,status); UErrorCode ec = U_ZERO_ERROR; UResourceBundle *rb = ures_open(NULL, loc.getName(), &ec); UResourceBundle *numElements = ures_getByKeyWithFallback(rb, gNumberElementsTag, NULL, &ec); rb = ures_getByKeyWithFallback(numElements, ns->getName(), rb, &ec); rb = ures_getByKeyWithFallback(rb, gPatternsTag, rb, &ec); int32_t ptnLen; const UChar* numberStylePattern = ures_getStringByKeyWithFallback(rb, gDecimalFormatTag, &ptnLen, &ec); // Fall back to "latn" if num sys specific pattern isn't there. if ( ec == U_MISSING_RESOURCE_ERROR && uprv_strcmp(ns->getName(),gLatnTag)) { ec = U_ZERO_ERROR; rb = ures_getByKeyWithFallback(numElements, gLatnTag, rb, &ec); rb = ures_getByKeyWithFallback(rb, gPatternsTag, rb, &ec); numberStylePattern = ures_getStringByKeyWithFallback(rb, gDecimalFormatTag, &ptnLen, &ec); } int32_t numberStylePatternLen = ptnLen; const UChar* negNumberStylePattern = NULL; int32_t negNumberStylePatternLen = 0; // TODO: Java // parse to check whether there is ";" separator in the numberStylePattern UBool hasSeparator = false; if (U_SUCCESS(ec)) { for (int32_t styleCharIndex = 0; styleCharIndex < ptnLen; ++styleCharIndex) { if (numberStylePattern[styleCharIndex] == gNumberPatternSeparator) { hasSeparator = true; // split the number style pattern into positive and negative negNumberStylePattern = numberStylePattern + styleCharIndex + 1; negNumberStylePatternLen = ptnLen - styleCharIndex - 1; numberStylePatternLen = styleCharIndex; } } } ures_close(numElements); ures_close(rb); delete ns; if (U_FAILURE(ec)) { return; } UResourceBundle *currRb = ures_open(U_ICUDATA_CURR, loc.getName(), &ec); UResourceBundle *currencyRes = ures_getByKeyWithFallback(currRb, gCurrUnitPtnTag, NULL, &ec); #ifdef CURRENCY_PLURAL_INFO_DEBUG std::cout << "in set up\n"; #endif StringEnumeration* keywords = fPluralRules->getKeywords(ec); if (U_SUCCESS(ec)) { const char* pluralCount; while ((pluralCount = keywords->next(NULL, ec)) != NULL) { if ( U_SUCCESS(ec) ) { int32_t ptnLen; UErrorCode err = U_ZERO_ERROR; const UChar* patternChars = ures_getStringByKeyWithFallback( currencyRes, pluralCount, &ptnLen, &err); if (U_SUCCESS(err) && ptnLen > 0) { UnicodeString* pattern = new UnicodeString(patternChars, ptnLen); #ifdef CURRENCY_PLURAL_INFO_DEBUG char result_1[1000]; pattern->extract(0, pattern->length(), result_1, "UTF-8"); std::cout << "pluralCount: " << pluralCount << "; pattern: " << result_1 << "\n"; #endif pattern->findAndReplace(UnicodeString(TRUE, gPart0, 3), UnicodeString(numberStylePattern, numberStylePatternLen)); pattern->findAndReplace(UnicodeString(TRUE, gPart1, 3), UnicodeString(TRUE, gTripleCurrencySign, 3)); if (hasSeparator) { UnicodeString negPattern(patternChars, ptnLen); negPattern.findAndReplace(UnicodeString(TRUE, gPart0, 3), UnicodeString(negNumberStylePattern, negNumberStylePatternLen)); negPattern.findAndReplace(UnicodeString(TRUE, gPart1, 3), UnicodeString(TRUE, gTripleCurrencySign, 3)); pattern->append(gNumberPatternSeparator); pattern->append(negPattern); } #ifdef CURRENCY_PLURAL_INFO_DEBUG pattern->extract(0, pattern->length(), result_1, "UTF-8"); std::cout << "pluralCount: " << pluralCount << "; pattern: " << result_1 << "\n"; #endif fPluralCountToCurrencyUnitPattern->put(UnicodeString(pluralCount, -1, US_INV), pattern, status); } } } } delete keywords; ures_close(currencyRes); ures_close(currRb); }
int main (int argc, char **argv) { char* inputFile = NULL; char* outputFile = NULL; unsigned int nstreams= 0; unsigned int maxfilehandles = 250; void *fcbin; fcbT fcb; int nrectypes; int *recordtypes; int i; int a; VTF3_handler_t *handlers; void **firsthandlerargs; size_t bytesread; OTF_FileManager* manager= NULL; int buffersize = 1024 * 1024; OTF_FileCompression compression= OTF_FILECOMPRESSION_UNCOMPRESSED; char iofile[128]; fcb.ioonly= 0; /* argument handling */ if ( 1 >= argc ) { SHOW_HELPTEXT; exit(0); } for ( i = 1; i < argc; i++ ) { if ( ( 0 == strcmp( "-i", argv[i] ) ) && ( i+1 < argc ) ) { inputFile= argv[i+1]; ++i; } else if ( ( 0 == strcmp( "-o", argv[i] ) ) && ( i+1 < argc ) ) { fcb.outputFile= strdup( argv[i+1] ); ++i; } else if ( ( 0 == strcmp( "-n", argv[i] ) ) && ( i+1 < argc ) ) { nstreams = atoi( argv[i+1] ); ++i; } else if ( ( 0 == strcmp( "-f", argv[i] ) ) && ( i+1 < argc ) ) { maxfilehandles = atoi( argv[i+1] ); ++i; } else if ( ( 0 == strcmp( "-b", argv[i] ) ) && ( i+1 < argc ) ) { buffersize = atoi( argv[i+1] ); ++i; } else if ( 0 == strcmp( "-io", argv[i] ) ) { fcb.ioonly= 1; } else if ( ( 0 == strcmp( "-z", argv[i] ) ) && ( i+1 < argc ) ) { compression= atoi( argv [i+1] ); ++i; } else if ( 0 == strcmp( "--help", argv[i] ) || 0 == strcmp( "-h", argv[i] ) ) { SHOW_HELPTEXT; exit(0); } else if ( 0 == strcmp( "-V", argv[i] ) ) { printf( "%u.%u.%u \"%s\"\n", OTF_VERSION_MAYOR, OTF_VERSION_MINOR, OTF_VERSION_SUB, OTF_VERSION_STRING); exit( 0 ); } else { if ( '-' != argv[i][0] ) { inputFile= argv[i]; } else { fprintf( stderr, "ERROR: Unknown option '%s'\n", argv[i] ); exit(1); } } } /* check parameters */ if ( NULL == inputFile ) { printf( " no input file specified\n" ); exit(1); } if ( NULL == outputFile ) { /* printf( " no output file specified\n" ); exit(1); */ outputFile= strdup( "out.otf" ); } if ( maxfilehandles < 1 ) { printf( " there must be at least 1 available filehandle\n" ); exit(1); } fcb.processes= NULL; fcb.processcount= 0; fcb.threadnums= 0; fcb.processgroups= NULL; fcb.processgroupcount= 0; fcb.reservedIds= NULL; fcb.reservedIdsc= 0; fcb.pghash= initHash(); fcb.handleid= 0; /* Open FileManager */ if( 0 == fcb.ioonly ) { manager= OTF_FileManager_open( maxfilehandles ); assert( NULL != manager ); /* Open OTF Writer */ fcb.outputFile= OTF_stripFilename( fcb.outputFile ); fcb.writer = OTF_Writer_open( fcb.outputFile, nstreams, manager ); OTF_Writer_setBufferSizes( fcb.writer, buffersize ); OTF_Writer_setCompression( fcb.writer, compression ); } /* Initialize VTF3. */ (void) VTF3_InitTables (); /* Again, how many different record types do exist ? */ nrectypes = VTF3_GetRecTypeArrayDim (); /* Allocate three auxiliary arrays for the record types, the record handler entry point pointers and some data. */ recordtypes = (int *) malloc ((size_t) nrectypes * sizeof (int)); handlers = (VTF3_handler_t *) malloc ((size_t) nrectypes * sizeof (VTF3_handler_t)); firsthandlerargs = (void **) malloc ((size_t) nrectypes * sizeof (void *)); /* Store the record types onto the appropriate array. Pay attention, the caller does not know their ordering scheme. */ (void) VTF3_GetRecTypeArray (recordtypes); /* What follows, this is the final handler table setup. */ if( 0 == fcb.ioonly ) { for (i = 0; i < nrectypes; i++) { if ( VTF3_RECTYPE_CLSTRREGVAL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleClstrregval; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_COMMENT == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleComment; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_CPUREGVAL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleCpuregval; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFACT == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefact; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFACT_OBSOL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefact_obsol; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCLKPERIOD == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefclkperiod; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCLSTR == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefclstr; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCLSTRREG == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefclstrreg; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCLSTRREGCLASS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefclstrregclass; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCOMMUNICATOR == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefcommunicator; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCPUGRP == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefcpugrp; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCPUNAME == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefcpuname; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCPUREG == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefcpureg; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCPUREGCLASS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefcpuregclass; firsthandlerargs[i] = &fcb; continue; } /* if ( VTF3_RECTYPE_DEFCREATOR == recordtypes[i] ) { */ /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ /* handlers[i] = (VTF3_handler_t) handleDefcreator; firsthandlerargs[i] = &fcb; continue; } */ if ( VTF3_RECTYPE_DEFGLOBALOP == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefglobalop; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFIOFILE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefiofile; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFKPARREG == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefkparreg; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFMSGNAME == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefmsgname; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFOPENMPNAME == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefopenmpname; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFOPENMPTYPE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefopenmptype; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFPATTERN == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefpattern; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFPATTERNSHAPE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefpatternshape; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFREDFUNC_OBSOL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefredfunc_obsol; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSAMP == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefsamp; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSAMPCLASS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefsampclass; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSCL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefscl; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSCLFILE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefsclfile; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSTATE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefstate; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSTATE_OBSOL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefstate_obsol; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSYSCPUNAMES == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefsyscpunames; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSYSCPUNUMS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefsyscpunums; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFTHREADNUMS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefthreadnums; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFTIMEOFFSET == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDeftimeoffset; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFUNMERGED == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefunmerged; firsthandlerargs[i] = &fcb; continue; } /* if ( VTF3_RECTYPE_DEFVERSION == recordtypes[i] ) { */ /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ /* handlers[i] = (VTF3_handler_t) handleDefversion; firsthandlerargs[i] = writer; continue; } */ if ( VTF3_RECTYPE_DOWNTO == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDownto; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_EXCHANGE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleExchange; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_EXCHANGE_OBSOL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleExchange_obsol; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_FILEIOBEGIN == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleFileiobegin; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_FILEIOEND == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleFileioend; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_GLOBALOP == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleGlobalop; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_KPARREGBARSUM == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleKparregbarsum; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_KPARREGBEGIN == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleKparregbegin; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_KPARREGEND == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleKparregend; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_MUTEXACQUIRE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleMutexacquire; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_MUTEXRELEASE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleMutexrelease; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_OPENMPENTER == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleOpenmpenter; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_OPENMPLEAVE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleOpenmpleave; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_PATTERN == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handlePattern; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_RECVMSG == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleRecvmsg; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_SAMP == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleSamp; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_SENDMSG == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleSendmsg; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_SRCINFO_OBSOL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleSrcinfo_obsol; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_UNRECOGNIZABLE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleUnrecognizable; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_UPFROM == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleUpfrom; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_UPTO == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleUpto; firsthandlerargs[i] = &fcb; continue; } } } else { /* 1 == fcb.ioonly */ for (i = 0; i < nrectypes; i++) { if ( VTF3_RECTYPE_DEFSYSCPUNUMS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefsyscpunums; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFTHREADNUMS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefthreadnums; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_FILEIOBEGIN == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleFileiobegin; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_FILEIOEND == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleFileioend; firsthandlerargs[i] = &fcb; continue; } } } /* Open the input device */ fcbin = VTF3_OpenFileInput ( inputFile, handlers, firsthandlerargs, 0); /* Free the auxiliary arrays. */ (void) free (firsthandlerargs); (void) free (handlers); (void) free (recordtypes); if ( NULL == fcbin ) { fprintf( stderr, "cannot open input file '%s'\n", inputFile ); exit( 1 ); } /* Now push the operation to portion-wise process the input file contents. */ if( 0 == fcb.ioonly ) { OTF_Writer_writeDefCreator( fcb.writer, 0, VTF32OTFCREATOR ); /* generate a standardfile group - vampir needs a filegroup(communicator) group 0 would be invalid */ OTF_Writer_writeDefFileGroup( fcb.writer, 0, 1, "Default" ); } do { bytesread = VTF3_ReadFileInputLtdBytes (fcbin, 50000); } while (bytesread != 0); if ( NULL == fcb.processes ) { fprintf( stderr, "ERROR: Missing NCPU record\n" ); exit(1); } /* create defprocess records with thread hierarchie */ if( 0 == fcb.ioonly ) { for( i = 0; i < fcb.processcount; i++ ) { OTF_Writer_writeDefProcess( fcb.writer, 0, i + 1, fcb.processes[i][0].name, 0); for( a = 1; a < fcb.threadnums[i]; ++a ) { OTF_Writer_writeDefProcess( fcb.writer, 0, (i + 1) + (a << 16), fcb.processes[i][a].name, i + 1); } } } /* create defprocessgroup records */ for( i= 0;i < (int)fcb.processgroupcount; ++i ) { if( 0 == fcb.ioonly ) { OTF_Writer_writeDefProcessGroup( fcb.writer, 0 /* uint32_t stream */, fcb.processgroups[i].id /* uint32_t procGroup */, fcb.processgroups[i].name /* const char* name */, fcb.processgroups[i].size /* uint32_t numberOfProcs */, fcb.processgroups[i].procs /* const uint32_t* procs */ ); } free( fcb.processgroups[i].procs ); free( fcb.processgroups[i].name ); } free( fcb.processgroups ); /* free process-array */ for( i = 0; i < fcb.processcount; ++i ) { for( a = 0; a < fcb.threadnums[i]; ++a ) { writeFileIOBuffer( i + (a<<16)/*cpuid*/, &fcb.processes[i][a], fcb.outputFile ); /* delete iofiles */ if( 0 == fcb.ioonly ) { sprintf( iofile, "%s.%i.io", fcb.outputFile, i + (a<<16) ); unlink( iofile ); } Stack_delete( fcb.processes[i][a].stack ); if ( 0 != fcb.processes[i][a].name ) { free( fcb.processes[i][a].name ); } } free( fcb.processes[i] ); } free( fcb.processes ); /* Close all devices. */ (void) VTF3_Close (fcbin); if( 0 == fcb.ioonly ) { OTF_Writer_close( fcb.writer ); OTF_FileManager_close( manager ); } closeHash( fcb.pghash ); free( fcb.outputFile ); return 0; }
int main(int argc, char *argv[]) { PRIVATE int pid = 0; PRIVATE int c = 0, i = 0, fds = 0, status = 0; int digit_optind = 0; PRIVATE struct passwd *pwd_ent; PRIVATE struct group *grp_ent; PRIVATE char **ptr; char *tmp_ptr = NULL; char *pid_file = NULL; char *user = NULL; char *group = NULL; #ifdef LINUX struct rlimit rlim; getrlimit( RLIMIT_CORE, &rlim ); #ifdef DEBUG rlim.rlim_cur = rlim.rlim_max; printf( "DEBUG - RLIMIT_CORE: %ld\n", rlim.rlim_cur ); #else rlim.rlim_cur = 0; #endif setrlimit( RLIMIT_CORE, &rlim ); #endif /* setup config */ config = ( Config_t * )XMALLOC( sizeof( Config_t ) ); XMEMSET( config, 0, sizeof( Config_t ) ); /* get real uid and gid, we may want to drop privs */ config->gid = getgid(); config->uid = getuid(); while (1) { int this_option_optind = optind ? optind : 1; #ifdef HAVE_GETOPT_LONG int option_index = 0; static struct option long_options[] = { {"atime", no_argument, 0, 'a' }, {"debug", required_argument, 0, 'd' }, {"exdir", required_argument, 0, 'e' }, {"exfile", required_argument, 0, 'E' }, {"help", no_argument, 0, 'h' }, {"md5", no_argument, 0, 'm' }, {"preserve", no_argument, 0, 'p' }, {"quick", no_argument, 0, 'q' }, {"sha256", no_argument, 0, 's' }, {"version", no_argument, 0, 'v' }, {"write", required_argument, 0, 'w' }, {0, no_argument, 0, 0} }; c = getopt_long(argc, argv, "ad:e:E:hmpqsvw:", long_options, &option_index); #else c = getopt( argc, argv, "ad:e:E:hmpqsvw:" ); #endif if (c EQ -1) break; switch (c) { case 'a': /* enable atime change reporting */ config->show_atime = TRUE; case 'p': if ( config->uid != 0 ) { fprintf( stderr, "ERR - Insufficient priviledges to preserve ATIME, aborting\n" ); print_help(); return( EXIT_FAILURE ); } config->preserve_atime = TRUE; break; case 'd': /* show debig info */ config->debug = atoi( optarg ); config->mode = MODE_INTERACTIVE; break; case 'e': /* exclude a specific directory from the diff */ if ( ( config->exclusions = (char **)XMALLOC( sizeof( char * ) * 2 ) ) EQ NULL ) { fprintf( stderr, "ERR - Unable to allocate memory for exclusion list\n" ); return( EXIT_FAILURE ); } if ( ( config->exclusions[0] = XMALLOC( MAXPATHLEN + 1 ) ) EQ NULL ) { fprintf( stderr, "ERR - Unable to allocate memory for exclusion list\n" ); XFREE( config->exclusions ); return( EXIT_FAILURE ); } if ( optarg[0] != '/' ) { config->exclusions[0][0] = '/'; XSTRNCPY( config->exclusions[0]+1, optarg, MAXPATHLEN - 1 ); } else XSTRNCPY( config->exclusions[0], optarg, MAXPATHLEN ); config->exclusions[1] = 0; break; case 'E': /* exclude a list of directories in the specific file */ //if ( loadExclusions( optarg ) != TRUE ) // return( EXIT_FAILURE ); //break; fprintf( stderr, "ERR - Feature not currently supported\n" ); print_help(); return( EXIT_SUCCESS ); case 'h': /* show help info */ print_help(); return( EXIT_SUCCESS ); case 'm': /* md5 hash files */ config->hash = TRUE; config->md5_hash = TRUE; config->digest_size = 16; config->sha256_hash = FALSE; break; case 'q': /* do quick checks only */ config->quick = TRUE; break; case 's': /* sha256 hash files */ config->hash = TRUE; config->sha256_hash = TRUE; config->digest_size = 32; config->md5_hash = FALSE; break; case 'v': /* show the version */ print_version(); return( EXIT_SUCCESS ); case 'w': /* define the dir to store logs in */ if ( ( config->outfile = ( char * )XMALLOC( MAXPATHLEN + 1 ) ) EQ NULL ) { /* XXX problem */ } XMEMSET( config->outfile, 0, MAXPATHLEN + 1 ); XSTRNCPY( config->outfile, optarg, MAXPATHLEN ); break; default: fprintf( stderr, "Unknown option code [0%o]\n", c); } } /* turn off quick mode if hash mode is enabled */ if ( config->hash ) config->quick = FALSE; /* check dirs and files for danger */ if ( time( &config->current_time ) EQ -1 ) { fprintf( stderr, "ERR - Unable to get current time\n" ); /* cleanup buffers */ cleanup(); return EXIT_FAILURE; } /* initialize program wide config options */ config->hostname = (char *)XMALLOC( MAXHOSTNAMELEN+1 ); /* get processor hostname */ if ( gethostname( config->hostname, MAXHOSTNAMELEN ) != 0 ) { fprintf( stderr, "Unable to get hostname\n" ); strncpy( config->hostname, "unknown", MAXHOSTNAMELEN ); } /* setup gracefull shutdown */ signal( SIGINT, sigint_handler ); signal( SIGTERM, sigterm_handler ); signal( SIGFPE, sigfpe_handler ); signal( SIGILL, sigill_handler ); signal( SIGSEGV, sigsegv_handler ); #ifndef MINGW signal( SIGHUP, sighup_handler ); signal( SIGBUS, sigbus_handler ); #endif /**** * * lets get this party started * ****/ show_info(); if ( ( baseDir = (char *)XMALLOC( PATH_MAX ) ) EQ NULL ) { fprintf( stderr, "ERR - Unable to allocate memory for baseDir string\n" ); cleanup(); return( EXIT_FAILURE ); } if ( ( compDir = (char *)XMALLOC( PATH_MAX ) ) EQ NULL ) { fprintf( stderr, "ERR - Unable to allocate memory for compDir string\n" ); cleanup(); return( EXIT_FAILURE ); } compDirHash = initHash( 52 ); while (optind < argc ) { if ( ( compDirLen = strlen( argv[optind] ) ) >= PATH_MAX ) { fprintf( stderr, "ERR - Argument too long\n" ); if ( baseDirHash != NULL ) freeHash( baseDirHash ); freeHash( compDirHash ); cleanup(); return( EXIT_FAILURE ); } else { strncpy( compDir, argv[optind++], PATH_MAX-1 ); /* process directory tree */ if ( processDir( compDir ) EQ FAILED ) { if ( baseDirHash != NULL ) freeHash( baseDirHash ); freeHash( compDirHash ); cleanup(); return( EXIT_FAILURE ); } if ( baseDirHash != NULL ) { /* compare the old tree to the new tree to find missing files */ if ( traverseHash( baseDirHash, findMissingFiles ) != TRUE ) { freeHash( baseDirHash ); freeHash( compDirHash ); cleanup(); return( EXIT_FAILURE ); } } /* Prep for next dir to compare */ if ( baseDirHash != NULL ) freeHash( baseDirHash ); baseDirHash = compDirHash; compDirHash = initHash( getHashSize( baseDirHash ) ); baseDirLen = compDirLen; strncpy( baseDir, compDir, compDirLen ); } } if ( baseDirHash != NULL ) freeHash( baseDirHash ); if ( compDirHash != NULL ) freeHash( compDirHash ); /**** * * we are done * ****/ cleanup(); return( EXIT_SUCCESS ); }
void Hash::resizeHash(size_t bytes) { freeHash(); initHash(bytes); }
void TimeUnitFormat::readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts, UErrorCode& err) { if (U_FAILURE(err)) { return; } // fill timeUnitToCountToPatterns from resource file // err is used to indicate wrong status except missing resource. // status is an error code used in resource lookup. // status does not affect "err". UErrorCode status = U_ZERO_ERROR; UResourceBundle *rb, *unitsRes; rb = ures_open(U_ICUDATA_UNIT, getLocaleID(status), &status); unitsRes = ures_getByKey(rb, key, NULL, &status); unitsRes = ures_getByKey(unitsRes, "duration", unitsRes, &status); if (U_FAILURE(status)) { ures_close(unitsRes); ures_close(rb); return; } int32_t size = ures_getSize(unitsRes); for ( int32_t index = 0; index < size; ++index) { // resource of one time unit UResourceBundle* oneTimeUnit = ures_getByIndex(unitsRes, index, NULL, &status); if (U_SUCCESS(status)) { const char* timeUnitName = ures_getKey(oneTimeUnit); if (timeUnitName == NULL) { ures_close(oneTimeUnit); continue; } UResourceBundle* countsToPatternRB = ures_getByKey(unitsRes, timeUnitName, NULL, &status); if (countsToPatternRB == NULL || U_FAILURE(status)) { ures_close(countsToPatternRB); ures_close(oneTimeUnit); continue; } TimeUnit::UTimeUnitFields timeUnitField = TimeUnit::UTIMEUNIT_FIELD_COUNT; if ( uprv_strcmp(timeUnitName, gTimeUnitYear) == 0 ) { timeUnitField = TimeUnit::UTIMEUNIT_YEAR; } else if ( uprv_strcmp(timeUnitName, gTimeUnitMonth) == 0 ) { timeUnitField = TimeUnit::UTIMEUNIT_MONTH; } else if ( uprv_strcmp(timeUnitName, gTimeUnitDay) == 0 ) { timeUnitField = TimeUnit::UTIMEUNIT_DAY; } else if ( uprv_strcmp(timeUnitName, gTimeUnitHour) == 0 ) { timeUnitField = TimeUnit::UTIMEUNIT_HOUR; } else if ( uprv_strcmp(timeUnitName, gTimeUnitMinute) == 0 ) { timeUnitField = TimeUnit::UTIMEUNIT_MINUTE; } else if ( uprv_strcmp(timeUnitName, gTimeUnitSecond) == 0 ) { timeUnitField = TimeUnit::UTIMEUNIT_SECOND; } else if ( uprv_strcmp(timeUnitName, gTimeUnitWeek) == 0 ) { timeUnitField = TimeUnit::UTIMEUNIT_WEEK; } else { ures_close(countsToPatternRB); ures_close(oneTimeUnit); continue; } Hashtable* countToPatterns = fTimeUnitToCountToPatterns[timeUnitField]; if (countToPatterns == NULL) { countToPatterns = initHash(err); if (U_FAILURE(err)) { ures_close(countsToPatternRB); ures_close(oneTimeUnit); delete countToPatterns; break; } } int32_t count = ures_getSize(countsToPatternRB); const char* pluralCount; for ( int32_t pluralIndex = 0; pluralIndex < count; ++pluralIndex) { // resource of count to pattern UnicodeString pattern = ures_getNextUnicodeString(countsToPatternRB, &pluralCount, &status); if (U_FAILURE(status)) { continue; } UnicodeString pluralCountUniStr(pluralCount, -1, US_INV); if (!pluralCounts.contains(&pluralCountUniStr)) { continue; } MessageFormat* messageFormat = new MessageFormat(pattern, getLocale(err), err); if ( U_SUCCESS(err) ) { MessageFormat** formatters = (MessageFormat**)countToPatterns->get(pluralCountUniStr); if (formatters == NULL) { formatters = (MessageFormat**)uprv_malloc(UTMUTFMT_FORMAT_STYLE_COUNT*sizeof(MessageFormat*)); formatters[UTMUTFMT_FULL_STYLE] = NULL; formatters[UTMUTFMT_ABBREVIATED_STYLE] = NULL; countToPatterns->put(pluralCountUniStr, formatters, err); if (U_FAILURE(err)) { uprv_free(formatters); } } if (U_SUCCESS(err)) { //delete formatters[style]; formatters[style] = messageFormat; } } if (U_FAILURE(err)) { ures_close(countsToPatternRB); ures_close(oneTimeUnit); ures_close(unitsRes); ures_close(rb); delete messageFormat; delete countToPatterns; return; } } if (fTimeUnitToCountToPatterns[timeUnitField] == NULL) { fTimeUnitToCountToPatterns[timeUnitField] = countToPatterns; } ures_close(countsToPatternRB); } ures_close(oneTimeUnit); } ures_close(unitsRes); ures_close(rb); }
RandomHash(int tnum_ = 1, ABST abst = SINGLE) : tnum(tnum_), round(0) { initHash(); }
int main (int argc, char *argv[]) { if (argc != 4) return 3; int M = strtol(argv[1], NULL, 10); //get numerical value from string //open input file FILE *in = fopen(argv[2], "r"); if (!in) return 2; //open output file FILE *out = fopen(argv[3], "w"); if (!out) { fclose(in); return 2; } //buffer input which will be used to parse commands //aux is used to check return value of function fgets //aux tells us when to stop reading char *aux = NULL, *buffer = NULL; buffer = malloc(BSIZE * sizeof(char)); if (!buffer) { fclose(in); fclose(out); return 2; } THash *H = initHash(M); if (!H) { fclose(in); fclose(out); free(buffer); return 2; } aux = fgets(buffer, BSIZE, in); while (aux) { if (buffer[0] == '\n') break; //limit case when end of file reached (almost) and last line is '\n' buffer[strlen(buffer) - 1] = '\0'; //try to parse commands //if command is put and memory cannot be allocated then exit program (clean) if (parse(H, buffer, out) == -1) { fclose(in); fclose(out); free(buffer); destroyHash(&H, freeInf); return 2; } aux = fgets(buffer, BSIZE, in); } //free everything destroyHash(&H, freeInf); fclose(in); fclose(out); free(buffer); return 0; }