void print(Table_T files) { int i; void **array = Table_toArray(files, NULL); qsort(array, Table_length(files), 2*sizeof (*array), compare); for (i = 0; array[i]; i += 2) { if (*(char *)array[i] != '\0') printf("\t%s:", (char *)array[i]); { void **lines = Set_toArray(array[i+1], NULL); qsort(lines, Set_length(array[i+1]), sizeof (*lines), cmpint); int j, c; for (j = 0; lines[j]; j++) { printf(" %d", *(int *)lines[j]); c = 0; while (lines[j+1] && *(int *)lines[j+1] == *(int *)lines[j] + 1) { j++; c = 1; } if (c) printf("-%d", *(int *)lines[j]); } FREE(lines); } printf("\n"); } FREE(array); }
void print(Table_T files){ int i; void **array = Table_toArray(files, NULL); qsort(array, Table_length(files), 2 * sizeof(*array), compare); for (i = 0; array[i]; i += 2){ if (*(char *)array[i] != '\0'){ printf("\t%s:", (char *)array[i]); } // print the line numbers in the set array[i+1] { int j; void **lines = Set_toArray(array[i + 1], NULL); qsort(lines, Set_length(array[i+1], sizeof(*lines), cmpint); for (j = 0; lines[j]; j++){ printf(" %d", *(int *)lines[j]); } FREE(lines); } printf("\n"); } FREE(array); }
/*prints all values contained in a set*/ void print_set(Set_T* set) { int set_len = Set_length(*set); void **set_array = Set_toArray(*set, NULL); for (int i=0; i<set_len; i++) { printf("%s\n", (char *)set_array[i]); } free(set_array); }
void Oec_IdSet_free(T *_this_p) { assert(_this_p && *_this_p); T _this_ = *_this_p; //Set_T s = _this_->members; void **array = Set_toArray(_this_->members, NULL); for ( int i = 0; array[i]; i++ ) { ID_ITEM *titem = (ID_ITEM *) array[i]; if (titem) { Mem_free( titem, __FILE__, __LINE__ ); } } Mem_free(array, __FILE__, __LINE__); Set_free(&_this_->members); Mem_free(_this_, __FILE__, __LINE__); }
//todo: skip testing the idx keys of both item and titem static bool _processSet( Table_T items, Set_T itemset, item_ *item, int key_idx ) { OE_TLOG(0, "Oed_Dispatcher _processSet\n"); //i18n assert(item); assert(items); assert(itemset); bool done = false; //when you get a match, remove template and invoke callback void **array = Set_toArray(itemset, NULL); for ( int i = 0; array[i]; i++ ) { OE_TLOG(0, "Oed_Dispatcher _processSet template %i\n", i); //i18n item_ *titem = (item_ *) array[i]; int titem_key_idx = titem->key_idx; bool matched = true; for (int j = 0; matched && titem->object[j]; j++) { if (j == titem_key_idx) continue; //this was the key that put this // template into this set, don't // re-test it char *tobj = (char *) titem->object[j]; bool kmatched = false; for (int k = 0; !kmatched && item->object[k]; k++) { if (k == key_idx) continue; //this was the key that got us the set, // don't re-test it char *iobj = (char *) item->object[k]; OE_TLOG(0, " _processSet template %i fld: %s tst: %s\n", i, iobj, tobj); //i18n if (strcmp(iobj, tobj) == 0) { kmatched = true; } else if (strcmp("_", tobj) == 0) kmatched = true; //wildcard } matched = kmatched; } if (matched) { OE_TLOG(0, " _processSet matched %i\n", i); //i18n //a match if (titem->match_handler) { OE_TLOG(0, " _processSet matched running handler %i\n", i); //i18n _process_fun(titem->match_handler, titem->args); //this might happen if someone registered //something that should only timeout like //a timer but idiotically specified a //possible pattern and the pattern hit. } bool consume = titem->consume; // note, this is the point to implement persistent subs _remove_item(items, titem, false); //always remove the item. if (consume) { done = true; break; //must be a take } } } Mem_free(array, __FILE__, __LINE__); return done; }