int EiC_load_history(char * fname, int prompt) { #define BufSz 512 int i; char buff[BufSz]; char *line; FILE *fp = fopen(fname,"r"); if(prompt) set_termio(); if(fp) { while(fgets(buff,BufSz-2,fp)) { for(i=0;buff[i] && buff[i] != '\n';++i) ; if(!buff[i]) buff[i++] = '\\'; buff[i] = 0; if(prompt) { printf("Re-enter [%s] (Y/N/E)?",buff); switch(special_getc()) { case 'y': case 'Y': user_puts(" Y\n"); break; case 'e': case 'E': user_puts(" E\n"); copy_line(buff); line = editLine("edit: "); if(*line) EiC_add_history(line); free(line); set_termio(); continue; default: user_puts(" N\n"); continue; } } EiC_add_history(buff); } fclose(fp); i = 1; } else i = 0; if(prompt) reset_termio(); printf("added %d lines\n",HistLineNo); return i; #undef BufSz }
/* redraw the entire line, putting the cursor where it belongs */ static void redraw_line(char *prompt) { int i; user_puts(prompt); user_puts(cur_line); /* put the cursor where it belongs */ for(i=max_pos; i>cur_pos; i--) backspace(); }
unsigned char * EiC_readline(char *prompt) { /* start with a string of MAXBUF chars */ char * editLine(char *); if(line_len!=0) { free(cur_line); line_len=0; } cur_line=alloc((unsigned long)MAXBUF, "readline"); line_len=MAXBUF; /* set the termio so we can do our own input processing */ set_termio(); /* print the prompt */ user_puts(prompt); cur_line[0] = '\0'; cur_pos = 0; max_pos = 0; cur_entry = NULL; return editLine(prompt); }
/* copy line to cur_line, draw it and set cur_pos and max_pos */ static void copy_line(char *line) { while(strlen(line)+1>line_len) { extend_cur_line(); } strcpy(cur_line, line); user_puts(cur_line); cur_pos = max_pos = strlen(cur_line); }
/* redraw the entire line, putting the cursor where it belongs */ static void redraw_line(const char *prompt) { size_t i; fputs(prompt, stderr); user_puts(cur_line); /* put the cursor where it belongs */ i = cur_pos; for (cur_pos = max_pos; cur_pos > i; ) backspace(); }
/* clear cur_line and the screen line */ static void clear_line(char *prompt) { int i; memset(cur_line,0,max_pos); for(i=cur_pos; i>0; i--) backspace(); for(i=0; i<max_pos; i++) user_putc(SPACE); user_putc('\r'); user_puts(prompt); cur_pos = 0; max_pos = 0; }
/* clear to end of line and the screen end of line */ static void clear_eoline(const char *prompt) { size_t save_pos = cur_pos; while (cur_pos < max_pos) { user_putc(SPACE); if (isdoublewidth(cur_line[cur_pos])) user_putc(SPACE); cur_pos += char_seqlen(); } cur_pos = save_pos; while (max_pos > cur_pos) cur_line[--max_pos] = '\0'; putc('\r', stderr); fputs(prompt, stderr); user_puts(cur_line); }
void hexprint(char *s,int x) { char buf[80]; snprintf(buf,256,"%s:0x%x\n",s,x); user_puts(buf); }