void dump(void* storage) { switch(*(char*)storage) { case 'd': { Dictionary* dict = (Dictionary*)storage; dump_dict(dict); break; } case 'l': { List* list = (List*)storage; dump_list(list); break; } case 's': { Value* val = (Value*)storage; printf("%s", (char*)val->value); break; } case 'i': { Value* val = (Value*)storage; printf("%d", *(int*)val->value); break; } } }
int main (int argc, char *argv[]) { int i; wstack_type wstack; char buff[100]; SenType sentence; printf("starting, loading dict \n"); /* initial */ if (dict_load() == -1) { printf("load dict err!\n"); return 0; } dump_dict(&dicts[0], 1); printf("creating stack...\n"); create_wstack(&wstack, 50); if (!wstack.array) { printf("stack alloc err!\n"); goto MAINEND; } printf("get a input ...\n"); /* reading sentence from a file or input */ sentence.pdata = buff; sentence.len = sizeof(buff); if (0 > sentence_read(&sentence)) { printf("reading err!\n"); goto MAINEND; } printf("analyzing...\n"); /* core algorithm of word segmentation */ wdseg_full_type wdsegmnt; word_seg(sentence, &wdsegmnt, &wstack); printf("Done, size: %d \n", wdsegmnt.num); /* show result */ for (i = 0; i < wdsegmnt.num; i++) { printf("the %dth anwser: \n", i); show_map(&wdsegmnt.psegmnt[i]); } MAINEND: if (wstack.array) { printf("free stack \n"); free(wstack.array); } if(dicts[0].indexWdPool.pstart) { printf("free dict data \n"); free(dicts[0].indexWdPool.pstart); } if (dicts[0].pindex) { printf("free dict wd \n"); free(dicts[0].index); } return 0; }