TSTree *add_route_data(TSTree *routes, bstring line) { struct bstrList *data = bsplit(line, ' '); // eg. /hello && Hello check(data->qty == 2, "Line '%s' does not have 2 columns", bdata(line)); // insert to routes, root is the first, the 2 and 3 is key anf length of key and value routes = TSTree_insert(routes, bdata(data->entry[0]), blength(data->entry[0]), bstrcpy(data->entry[1])); void *dl = load_dl(data->entry[1]); Handler *handler = Handler_create(bdata(data->entry[0]), dl); bstrListDestroy(data); return routes; error: return NULL; }
char *test_insert() { node = TSTree_insert(node, bdata(&test1), blength(&test1), valueA); mu_assert(node != NULL, "Failed to insert into tst."); node = TSTree_insert(node, bdata(&test2), blength(&test2), value2); mu_assert(node != NULL, "Failed to insert into tst with second name"); node = TSTree_insert(node, bdata(&test3), blength(&test3), reverse); mu_assert(node != NULL, "Failed to insert into tst with reverse name"); node = TSTree_insert(node, bdata(&test4), blength(&test4), value4); mu_assert(node != NULL, "Failed to insert into tst with second name"); return NULL; }
TSTree* add_route_data(TSTree* routes, bstring line) { struct bstrList* data = bsplit(line, ' '); check(data->qty == 2, "Line '%s' does not have 2 columns", bdata(line)); routes = TSTree_insert(routes, bdata(data->entry[0]), blength(data->entry[0]), bstrcpy(data->entry[1])); bstrListDestroy(data); return routes; error: return NULL; }
TSTree *add_route_data(TSTree *routes , bstring line ) /* take line from load route func , break into two parts * store into the tstree , first as key , second as data */ { struct bstrList *data = bsplit(line , ' '); check(data->qty == 2 , "line '%s' does not have 2 columns" , bdata(line)); routes = TSTree_insert(routes , bdata(data->entry[0] ), blength(data->entry[0]), bstrcpy(data->entry[1])); bstrListDestroy(data); return routes; error: return NULL; }