📄 extract.c
字号:
if (answer(command, "Errors were found. Continue (y/n)? ", "yn") == 'n') return ERROR; waddch(command, '\n'); } werase(source); return OK;}/* * processfile() * Scan through the message file and for each line modify the old * program using the REWRITE rule given in the patterns file. */long line3, line2, line1; /* offsets to lines seen */processfile(msg, cat, old, new, setnum)FILE *msg, *cat, *old, *new; /* file pointers */int setnum; /* set number DJL 002 */{ static int msgnum = 1; /* current message number */ int linenum; /* line field from msgline */ long offset; /* offset field from msgline */ int len; /* length of text */ char text[LINESIZE]; /* the actual text */ int num; /* message number to use */ int cmd; /* actual command user gave */ struct element *match; /* pointer to a matching string */ struct element elem; /* used to save a string */ char comment[LINESIZE]; /* temporary used for comments */ line3 = line2 = line1 = 0L; while (fscanf(msg, "%d %ld %d %[^\n]", &linenum, &offset, &len, text) != EOF) { /* see if we have seen this */ match = lookupstr(text, len); /* skip if we are ignoring text */ if (match && (match->flags & STR_IGNORE)) continue; /* display the text */ copy(old, new, offset); display(line3, new, old, len); wrefresh(source);again: switch(cmd = getcommand(match ? DUPLICATE : EXTRACT )) { case DUPLICATE: if ( ! match) { answer(command, "No string to duplicate. Press <RETURN> ", "\n"); goto again; } num = match->msgnum; /* FALL THROUGH */ case EXTRACT: if (cmd != DUPLICATE) num = msgnum++; wmove(source, texty, textx); wclrtobot(source); wmove(source, texty, textx); /* wstandout(source); */ rewrite(text, len, setnum, num, new); /* wstandend(source); */ fseek(old, (long)len, 1); redisplay(old); wrefresh(source); if (cmd != DUPLICATE) { wprintw(message, "%s%d\t%s\n", msgprefix, num, text); wrefresh(message); fprintf(cat, "%s%d\t%s\n", msgprefix, num, text); elem.len = len; elem.flags = 0; elem.linenum = linenum; elem.msgnum = num; savestr(text, &elem); } break; case IGNORE: /* ignore text now */ case ADD: /* add to ignore file */ elem.len = len; elem.flags = STR_IGNORE; elem.linenum = linenum; savestr(text, &elem); if (cmd == IGNORE) break; if (addignore(ignfile, text, len) == ERROR) answer(command, "Cannot write to ignore file. Press <RETURN> ", "\n"); break; case PASS: /* pass by this string */ continue; case COMMENT: /* put text in message file */ for (;;) { int y,x; waddstr(command, "Input text for message file and press <RETURN>\n"); wrefresh(command); wgetstr(message, comment); cmd = answer(command, "Text OK (y/n/q) ? ", "ynq"); if (cmd == 'y') break; getyx(message, y, x); wmove(message, y - 1, x); wdeleteln(message); wrefresh(message); if (cmd == 'q') goto again; } wrefresh(message); fprintf(cat, "%s\n", comment); goto again; case QUIT: if (answer(command, "Really quit (y/n) ? ", "yn") == 'y') { errors++; /* to set exit status */ windup(); /* exit() will cleanup */ /* NOTREACHED */ } goto again; case HELP: showhelp(); goto again; } } copy(old, new, (long)EOF); /* copy to EOF */}/* * getcommand() * Display the options available for the user and get the users * choice. The default will be highlighted. */getcommand(def)int def; /* the default selection */{ int inp; /* users input character */ int opt; /* selected option */ char **cp; /* pointer to list of options */ opt = def; werase(command); for (;;) { dispopt(opt); wmove(command, 1, 0); waddstr(command, "Select option and press <RETURN> "); wrefresh(command); inp = wgetch(command); if (inp == '\n') return opt; inp = toupper(inp); for (cp = opts; *cp; cp++) if (**cp == inp) { opt = cp - opts; break; } }}/* * dispopt() * Display the options available for the user and highlight the * appropriate one. */dispopt(high)int high; /* option number to highlight */{ int col = 0; /* current column number */ char **cp; /* pointer to list of options */ for (cp = opts; *cp; cp++) { wmove(command, 0, col); col += OPTSIZE; if (high == 0) wstandout(command); waddstr(command, *cp); if (high-- == 0) wstandend(command); }}/* * copy() * Copy from current position in old to offset to the file new. * If the offset if EOF copy to EOF */copy(old, new, offset)FILE *old, *new;long offset;{ long current; int c; current = ftell(old); if (offset == (long)EOF) while ((c = fgetc(old)) != EOF) fputc(c, new); else if (current > offset) { error("Bad offset in", curfile); return ERROR; } while (current++ < offset) { if ((c = fgetc(old)) == EOF) { error("Unexpected EOF in ", curfile); return ERROR; } fputc(c, new); if (c == '\n') { line3 = line2; line2 = line1; line1 = ftell(new); } } return OK;}/* * display() */display(newoffset, new, old, highlen)long newoffset;int highlen;FILE *new, *old;{ int c; long saveoffset = ftell(old); werase(source); fseek(new, newoffset, 0); while ((c = fgetc(new)) != EOF) if(waddch(source, c) == ERR) /* would scroll */ break; wstandout(source); getyx(source, texty, textx); while (highlen-- > 0 && (c = fgetc(old)) != EOF) if(waddch(source, c) == ERR) /* would scroll */ break; wstandend(source); while ((c = fgetc(old)) != EOF) if(waddch(source, c) == ERR) /* would scroll */ break; fseek(new, 0L, 2); fseek(old, saveoffset, 0);}/* * redisplay() * Redo the display from the current position onto the source * window, fills up until the screen would scroll. */redisplay(fp)FILE *fp;{ int c; long saveoffset; saveoffset = ftell(fp); while ((c = fgetc(fp)) != EOF) if (waddch(source, c) == ERR) break; fseek(fp, saveoffset, 0);} /* * rewrite() * Rewrite the message text in the form given by the REWRITE string * from the patterns file. The result is written to new. * The following replacement occurs: * %n => message number * %t => the message text * %l => the length of the text * %r => the raw text i.e. no quotes * %N => newline * %T => tab */rewrite(text, len, setnum, msgnum, new)char *text;int len;int setnum; /* DJL 002 */int msgnum;FILE *new;{ extern char rewstring[]; char *rp, *tp, *cp; char c, save; for (rp = rewstring; c = *rp; rp++) { if (c != '%') { waddch(source, c); fputc(c, new); if (c == '\n') { line3 = line2; line2 = line1; line1 = ftell(new); } } else switch(c = *++rp) { default: error("Bad rewrite string in pattern file", rewstring); return ERROR; case '%': waddch(source, '%'); fputc('%', new); break; case 'n': wprintw(source, "%s%d", msgprefix, msgnum); fprintf(new, "%s%d", msgprefix, msgnum); break; case 's': /* DJL 002 */ if (*msgprefix) { /* DJL 003 */ wprintw(source, "S_%s%d", msgprefix, setnum); fprintf(new, "S_%s%d", msgprefix, setnum); } else { wprintw(source, "%d", setnum); fprintf(new, "%d", setnum); } break; case 'l': wprintw(source, "%d", len); fprintf(new, "%d", len); break; case 't': waddstr(source, text); for (cp = text; c = *cp; cp++) { if (c == '\n') { line3 = line2; line2 = line1; line1 = ftell(new); } fputc(c, new); } break; case 'r': tp = text + strlen(text) - 1; save = *tp; *tp = '\0'; waddstr(source, text + 1); for (cp = text + 1; c = *cp; cp++) { if (c == '\n') { line3 = line2; line2 = line1; line1 = ftell(new); } fputc(c, new); } *tp = save; break; case 'N': line3 = line2; line2 = line1; line1 = ftell(new); fputc('\n', new); waddch(source, '\n'); break; case 'T': fputc('\t', new); waddch(source, '\t'); break; } } return OK;} /* * answer() * Get a one letter answer to the question through window */answer(win, question, valid)WINDOW *win;char *question, *valid;{ char *cp; int c; for (;;) { waddstr(win, question); wrefresh(win); c = wgetch(win); waddch(win, '\n'); c = tolower(c); for (cp = valid; *cp; cp++) if (c == *cp) return c; }}/* * showhelp() * Display some useful help text on the screen. */showhelp(){ static WINDOW *helpwin = (WINDOW *)NULL; static FILE *hp = (FILE *)NULL; char line[LINESIZE]; if (helpwin == (WINDOW *)NULL) { hp = fopen(HELPFILE, "r"); helpwin = newwin(LINES - 1, COLS, 1, 0); } if (hp == (FILE *)NULL) return ERROR; fseek(hp, 0L, 0); /* rewind */ werase(helpwin); /* blast previous screen */ touchwin(helpwin); /* read and display text */ while (fgets(line, LINESIZE, hp)) waddstr(helpwin, line); wrefresh(helpwin); answer(helpwin, "Press <RETURN> to continue ", "\n"); touchwin(stdscr); /* now restore original window */ refresh(); return OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -