/** * my_readline() * * Wrapper for readline(). Prepares appropriate prompt, locks screen * output. Recodes the result to utf-8. * * @return A pointer to utf8 string or NULL. */ static gchar *my_readline(void) { /* main loop could call current_prompt() * and break the buffer */ char *prompt = g_strdup(current_prompt()); char *res, *tmp; in_readline++; res = readline(prompt); in_readline--; if (config_print_line) { tmp = g_strdup_printf("%s%s\n", prompt, (res) ? res : ""); window_write(window_current->id, tmp); g_free(tmp); } else { window_refresh(); } g_free(prompt); return res; }
int bitSWrite(BitStream *bs,char * file) { FILE * fp; int nw,i; DListE *e; fp=fopen(file,"wt"); assert(fp); assert(0==bs->nu); byte_write(fp,bs->nu); assert(bs->pe==0xb7); byte_write(fp,bs->pe); assert(get_cr(28)==0);//reserved==0 for(i=0;i<4;i++) { byte_write(fp,bs->cregs[i]); } // byte_write(fp,bs->idunno); nw=dlistCount(&bs->windows); byte_write(fp,(nw>>8)&0x0ff); byte_write(fp,nw&0x0ff); e=dlistFirst(&bs->windows); while(e) { BitSWindow * w=(BitSWindow *)e; window_write(fp,w); e=dlistENext(e); } assert(bs->po==0xe7); byte_write(fp,bs->po); fclose(fp); return 0; }
/* * ui_readline_print() * * wy¶wietla dany tekst na ekranie, uwa¿aj±c na trwaj±ce w danych chwili * readline(). */ void ui_readline_print(window_t *w, int separate, const /*locale*/ char *xline) { int old_end = rl_end, id = w->id; char *old_prompt = NULL, *line_buf = NULL; const char *line = NULL; if (config_timestamp) { /* XXX: recode timestamp? for fun or wcs? */ string_t s = string_init(NULL); const char *p = xline; const char *buf = timestamp(formated_config_timestamp); string_append(s, "\033[0m"); string_append(s, buf); string_append_c(s, ' '); while (*p) { string_append_c(s, *p); if (*p == '\n' && *(p + 1)) { string_append(s, buf); string_append_c(s, ' '); } p++; } line = line_buf = string_free(s, 0); } else line = xline; /* je¶li nie piszemy do aktualnego, to zapisz do bufora i wyjd¼ */ if (id != window_current->id) { window_write(id, line); /* XXX trzeba jeszcze waln±æ od¶wie¿enie prompta */ goto done; } /* je¶li mamy ukrywaæ wszystko, wychodzimy */ if (pager_lines == -2) goto done; window_write(window_current->id, line); /* ukryj prompt, je¶li jeste¶my w trakcie readline */ if (in_readline) { old_prompt = g_strdup(rl_prompt); rl_end = 0; /* set_prompt(NULL);*/ rl_redisplay(); /* XXX: string width instead? * or cleartoeol? */ printf("\r%*c\r", (int) xstrlen(old_prompt), ' '); } printf("%s", line); if (pager_lines >= 0) { pager_lines++; if (pager_lines >= screen_lines - 2) { const gchar *prompt = format_find("readline_more"); char *lprompt = ekg_recode_to_locale(prompt); char *tmp; /* XXX: lprompt pretty const, make it static? */ in_readline++; set_prompt(lprompt); pager_lines = -1; tmp = readline(lprompt); g_free(lprompt); in_readline--; if (tmp) { free(tmp); /* allocd by readline */ pager_lines = 0; } else { printf("\n"); pager_lines = -2; } printf("\033[A\033[K"); /* XXX brzydko */ } } /* je¶li jeste¶my w readline, poka¿ z powrotem prompt */ if (in_readline) { rl_end = old_end; set_prompt(old_prompt); g_free(old_prompt); rl_forced_update_display(); } done: if (line_buf) g_free(line_buf); }