void ts_error(int state, const char *format,...) { va_list args; int tlen = 128, len = 0; char *buf; reset_cfg(); reset_dict(); reset_prs(); va_start(args, format); buf = palloc(tlen); len = vsnprintf(buf, tlen - 1, format, args); if (len >= tlen) { tlen = len + 1; buf = repalloc(buf, tlen); vsnprintf(buf, tlen - 1, format, args); } va_end(args); /* ?? internal error ?? */ elog(state, "%s", buf); pfree(buf); }
unsigned char *lzw_decode( struct lzw_state *state, unsigned code, unsigned char outbuf[DICTSIZE]) { unsigned char *outbuf_curs = &outbuf[DICTSIZE]; struct dict_entry *entry, *child; if(state->current == NULL) { *(--outbuf_curs) = state->dict[code].ch; state->current = state->dict + state->dict[code].ch; } else if(code >= state->next_code) { // this is a bit tricky: we need to emit the first character in the // state chain leading up to current both first and last in the output. unsigned char *last = --outbuf_curs; for(entry = state->current ; entry->parent; entry = entry->parent) *(--outbuf_curs) = entry->ch; // entry points to first item in state chain here *(--outbuf_curs) = *last = entry->ch; for(unsigned char *curs = outbuf_curs+1; curs < outbuf+DICTSIZE; curs++) printf("decode emit %c ", *curs); // we also need add a dict entry with the current state chain's first // entry appended, and step using that character child = alloc_dict_entry(state, state->current, entry->ch); assert(child); // encoder didn't reset, so we better not printf("decode add dict %u ", child->code); print_reverse(child); printf("\n"); state->current = step(state->current, entry->ch); } else { for(entry = state->dict + code; entry->parent; entry = entry->parent) *(--outbuf_curs) = entry->ch; // entry points to first item in state chain here *(--outbuf_curs) = entry->ch; for(unsigned char *curs = outbuf_curs+1; curs < outbuf+DICTSIZE; curs++) printf("decode emit %c\n", *curs); child = alloc_dict_entry(state, state->current, entry->ch); if(!child) { printf("decode reset dict\n"); reset_dict(state); } else { printf("decode add dict %u ", child->code); print_reverse(child); printf("\n"); } state->current = state->dict + code; } printf("decode cursor @ "); print_reverse(state->current); printf(" (%u)\n", state->current->code); return outbuf_curs; }
int lzw_encode( struct lzw_state *state, unsigned char ch, unsigned *code) { int status = 0; struct dict_entry *child; printf("encode '%c'\n", ch); if(state->current == NULL) { printf("encode ... (!current)\n"); state->current = state->dict + ch; } else if((child = step(state->current, ch))) { printf("encode ... (step)\n"); // have transition via ch state->current = child; } else { printf("encode emit %u\n", state->current->code); // don't have transition via ch *code = state->current->code; status = 1; child = alloc_dict_entry(state, state->current, ch); if(!child) { printf("encode reset dict\n"); reset_dict(state); } else { printf("encode add dict %u ", child->code); print_reverse(child); printf("\n"); } state->current = state->dict + ch; } printf("encode cursor @ "); print_reverse(state->current); printf(" (%u)\n", state->current->code); return status; }
void menu_enter(){ ///\fn void menu_enter() ///\brief Selectarea optiunii. /// ///Implementarea selectarii dorite in cadrul unei optiunilor din menu. system("cls"); // se ia fiecare caz de meniu si fiecare caz de element de meniu in parte. switch(current_menu){ // main menu case 0 : { switch (highlighted_item){ case 0 : {//input one word one_word(); break; } case 1 : {//From file from_file(); break; } case 2 : {//Live live_input(); break; } case 3 : {//options-menu current_menu = 1; highlighted_item = 0; break; } case 4 : {//Exit printf("\n\n\tGood bye!"); Sleep(750); exit(0); break; } } break; } //options-menu case 1 : { switch (highlighted_item){ case 0 : {//Update words apparitions update_app_words(); break; } case 1 : {//Insert an word to dictionary insert_word(); break; } case 2 : {//Delete an word from dictionary delete_word(); break; } case 3 : {//Reset dictionary reset_dict(); break; } case 4 : {//Build dictionary from file build_dict(); break; } case 5 : {//Add words to dictionary from file update_words(); break; } case 6 : {//select_suggestions_funcition current_menu = 2; highlighted_item = sugg_funct; break; } case 7 : {//back current_menu = 0; highlighted_item = 0; break; } } break; } //select suggestion functions case 2 : { switch (highlighted_item){ case 0 : {//leven sugg_funct = 0; break; } case 1 : {//leven 2.0 sugg_funct = 1; break; } case 2 : {//back current_menu = 1; highlighted_item = 0; break; } } } } print_menu(); Sleep(50); }