static UResourceBundle* getZoneByName(const UResourceBundle* top, const UnicodeString& id, UResourceBundle *oldbundle, UErrorCode& status) { // load the Rules object UResourceBundle *tmp = ures_getByKey(top, kNAMES, NULL, &status); // search for the string int32_t idx = findInStringArray(tmp, id, status); if((idx == -1) && U_SUCCESS(status)) { // not found status = U_MISSING_RESOURCE_ERROR; //ures_close(oldbundle); //oldbundle = NULL; } else { U_DEBUG_TZ_MSG(("gzbn: oldbundle= size %d, type %d, %s\n", ures_getSize(tmp), ures_getType(tmp), u_errorName(status))); tmp = ures_getByKey(top, kZONES, tmp, &status); // get Zones object from top U_DEBUG_TZ_MSG(("gzbn: loaded ZONES, size %d, type %d, path %s %s\n", ures_getSize(tmp), ures_getType(tmp), ures_getPath(tmp), u_errorName(status))); oldbundle = ures_getByIndex(tmp, idx, oldbundle, &status); // get nth Zone object U_DEBUG_TZ_MSG(("gzbn: loaded z#%d, size %d, type %d, path %s, %s\n", idx, ures_getSize(oldbundle), ures_getType(oldbundle), ures_getPath(oldbundle), u_errorName(status))); } ures_close(tmp); if(U_FAILURE(status)) { //ures_close(oldbundle); return NULL; } else { return oldbundle; } }
const UChar* TimeZone::dereferOlsonLink(const UnicodeString& id) { const UChar *result = NULL; UErrorCode ec = U_ZERO_ERROR; UResourceBundle *rb = ures_openDirect(NULL, kZONEINFO, &ec); // resolve zone index by name UResourceBundle *names = ures_getByKey(rb, kNAMES, NULL, &ec); int32_t idx = findInStringArray(names, id, ec); result = ures_getStringByIndex(names, idx, NULL, &ec); // open the zone bundle by index ures_getByKey(rb, kZONES, rb, &ec); ures_getByIndex(rb, idx, rb, &ec); if (U_SUCCESS(ec)) { if (ures_getType(rb) == URES_INT) { // this is a link - dereference the link int32_t deref = ures_getInt(rb, &ec); const UChar* tmp = ures_getStringByIndex(names, deref, NULL, &ec); if (U_SUCCESS(ec)) { result = tmp; } } } ures_close(names); ures_close(rb); return result; }
const UChar* TimeZone::getRegion(const UnicodeString& id) { const UChar *result = WORLD; UErrorCode ec = U_ZERO_ERROR; UResourceBundle *rb = ures_openDirect(NULL, kZONEINFO, &ec); // resolve zone index by name UResourceBundle *res = ures_getByKey(rb, kNAMES, NULL, &ec); int32_t idx = findInStringArray(res, id, ec); // get region mapping ures_getByKey(rb, kREGIONS, res, &ec); const UChar *tmp = ures_getStringByIndex(res, idx, NULL, &ec); if (U_SUCCESS(ec)) { result = tmp; } ures_close(res); ures_close(rb); return result; }
/* build arguments' internal interrelations */ void build_args_map(EtalisExecNode* Node,term_t lhs,term_t rhs) { /* assuming that all arguments are int. Further Datatypes will be supported in the future. */ /* Arity of all the involved events */ /* Note : need to test if this is more efficient than directly calling the struct's members*/ int arg_count = Node->leftChild->event.arity+Node->rightChild->event.arity+Node->parentEvent->event.arity; int arg_iterator=0; char* arguments=calloc(arg_count*256,sizeof(char)); char Goal[256]; char Goal2[256]; char WhereGoal[256]; termToString(rhs,Goal2,arguments); termToString(lhs,Goal,arguments); char* arguments_cond=calloc(arg_count*256,sizeof(char)); termToStringVerbatim(rhs,WhereGoal,arguments_cond); int extra_args=0; /* used if a where clause is available */ char* orig_args=arguments; if(Node->has_condition == ETALIS_TRUE) { while(*arguments) { if(*arguments == '_') extra_args++; arguments++; } extra_args = extra_args - arg_count; arguments=orig_args; char * whereRightBound; char * whereLeftBound; whereRightBound = WhereGoal + strlen(WhereGoal); while(*whereRightBound != ',') whereRightBound--; whereRightBound--; whereLeftBound = strstr(WhereGoal,"wheref"); whereLeftBound = whereLeftBound+7; int leftParenth=0, rightParenth=0; while(*whereLeftBound != '\0') { if(*whereLeftBound == ')') rightParenth++; if(*whereLeftBound == '(') leftParenth++; if(leftParenth == rightParenth && leftParenth != 0) break; whereLeftBound++; } whereLeftBound=whereLeftBound+2; char* constraints_verbatim = malloc(256*sizeof(char)); strncpy(constraints_verbatim,whereLeftBound,strlen(whereLeftBound)-strlen(whereRightBound)); Node->whereNode->conditions=constraints_verbatim; printf("CONSTRAINTS: %s\n",constraints_verbatim); } #ifdef DEBUG printf("rule args : %s\n",arguments); #endif char** argument_array = malloc((arg_count+extra_args)*sizeof(char*)); char* pch; pch = strtok(arguments,"_"); while(pch != NULL) { argument_array[arg_iterator] = malloc(sizeof(char)*strlen(pch)); strcpy(argument_array[arg_iterator],pch); arg_iterator++; pch = strtok(NULL,"_"); } #ifdef DEBUG for(arg_iterator=0;arg_iterator<(arg_count+extra_args);arg_iterator++) printf("arg[%d] : %s\n",arg_iterator,argument_array[arg_iterator]); #endif argument_link* temp_arg =NULL; size_t left_s = Node->leftChild->event.arity; size_t right_s = Node->rightChild->event.arity; size_t cplx_s = Node->parentEvent->event.arity; /* handling of left event args : Usually these are unbound */ Node->leftChild->arg_links = calloc(Node->leftChild->event.arity,sizeof(argument_link)); temp_arg = Node->leftChild->arg_links; for(arg_iterator=0;arg_iterator<(Node->leftChild->event.arity);arg_iterator++) { (temp_arg+arg_iterator)->event_= UNBOUND_ARGUMENT; (temp_arg+arg_iterator)->argument_number = UNBOUND_ARGUMENT; } /* handling of right event args */ /* todo check for the unbound event case */ Node->rightChild->arg_links = calloc(Node->rightChild->event.arity,sizeof(argument_link)); temp_arg = Node->rightChild->arg_links; for(arg_iterator=0;arg_iterator<(Node->rightChild->event.arity);arg_iterator++) { int pos=-1; pos = findInStringArray(0,left_s,argument_array,argument_array[left_s+arg_iterator]); (temp_arg+arg_iterator)->event_= (pos == -1 ? UNBOUND_ARGUMENT : 1 ); (temp_arg+arg_iterator)->argument_number = (pos == -1 ? UNBOUND_ARGUMENT : pos ); } #ifdef DEBUG for(arg_iterator=0;arg_iterator<right_s;arg_iterator++) printf("ARG[%d] of right event is bound to Event %d : arg [%d]\n",arg_iterator,Node->rightChild->arg_links[arg_iterator].event_,Node->rightChild->arg_links[arg_iterator].argument_number); #endif /* handling of additional clauses : where, etc ..*/ if(Node->has_condition == ETALIS_TRUE) { Node->whereNode->arg_links=(argument_link*)malloc(sizeof(argument_link)*extra_args); /* search for the conditions in the events */ temp_arg = Node->whereNode->arg_links; for(arg_iterator=0;arg_iterator<extra_args;arg_iterator++) { int pos=-1; pos= findInStringArray(0,left_s,argument_array,argument_array[left_s+right_s+arg_iterator]); if (pos == -1) /* Unbound event */ { (temp_arg+arg_iterator)->event_= UNBOUND_ARGUMENT; (temp_arg+arg_iterator)->argument_number = UNBOUND_ARGUMENT; continue; } else { (temp_arg+arg_iterator)->event_= 1; (temp_arg+arg_iterator)->argument_number = pos; continue; } /* this should be fixed */ pos= findInStringArray(left_s,right_s+left_s,argument_array,argument_array[left_s+right_s+arg_iterator]); } } /* handling of complex event args */ Node->parentEvent->arg_links = (argument_link*)malloc(Node->parentEvent->event.arity*sizeof(argument_link)); temp_arg = Node->parentEvent->arg_links; for(arg_iterator=0;arg_iterator<(Node->parentEvent->event.arity);arg_iterator++) { int pos=-1; pos = findInStringArray(0,left_s+right_s,argument_array,argument_array[extra_args+left_s+right_s+arg_iterator]); if (pos == -1) /* Unbound event */ { (temp_arg+arg_iterator)->event_= UNBOUND_ARGUMENT; (temp_arg+arg_iterator)->argument_number = UNBOUND_ARGUMENT; continue; } else if (pos <left_s) { (temp_arg+arg_iterator)->event_=1; (temp_arg+arg_iterator)->argument_number = pos; continue; } else if (pos-left_s < right_s) { (temp_arg+arg_iterator)->event_=2; (temp_arg+arg_iterator)->argument_number = pos-left_s; /* todo correct offset */ continue; } } #ifdef DEBUG for(arg_iterator=0;arg_iterator<cplx_s;arg_iterator++) printf("ARG[%d] of complex event is bound to Event %d : arg [%d]\n",arg_iterator,Node->parentEvent->arg_links[arg_iterator].event_,Node->parentEvent->arg_links[arg_iterator].argument_number); #endif /* free temporary data */ /* todo fixme win7 Heap FTH : look here : http://stackoverflow.com/questions/1621059/breakpoints-out-of-nowhere-when-debugging-with-gdb-inside-ntdll */ /* for(arg_iterator=0;arg_iterator<arg_count;arg_iterator++) free(argument_array[arg_iterator]); */ free(argument_array); free(arguments); return; }