int more(char *fpath, int promptend) { extern char *strcasestr(); static char *head[4] = {"§@ªÌ", "¼ÐÃD", "®É¶¡", "Âà«H"}; char *ptr, *word, buf[1024], *ch1; struct stat st; FILE *fp; usint pagebreak[MAXPAGES], pageno, lino; int line, ch, viewed, pos, numbytes; int header = 0; int local = 0; char search_char0 = 0; static char search_str[81] = ""; typedef char *(*FPTR) (); static FPTR fptr; int searching = 0; int scrollup = 0; char *http[80] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; /* Ptt */ char pagemode = 0; char pagecount = 0; inmore = 1; memset(pagebreak, 0, sizeof(pagebreak)); if (*search_str) search_char0 = *search_str; *search_str = 0; if (!(fp = fopen(fpath, "r"))) { inmore = 0; return -1; } if (fstat(fileno(fp), &st)) { inmore = 0; fclose(fp); return -1; } pagebreak[0] = pageno = viewed = line = pos = 0; clear(); while ((numbytes = readln(fp, buf)) || (line == t_lines)) { if (scrollup) { rscroll(); move(0, 0); } if (numbytes) /* ¤@¯ë¸ê®Æ³B²z */ { if (!viewed) /* begin of file */ { if (showansi) /* header processing */ { if (!strncmp(buf, str_author1, LEN_AUTHOR1)) { line = 3; word = buf + LEN_AUTHOR1; local = 1; } else if (!strncmp(buf, str_author2, LEN_AUTHOR2)) { line = 4; word = buf + LEN_AUTHOR2; } while (pos < line) { if (!local) str_decode(word); if (!pos && ((ptr = strstr(word, str_post1)) || (ptr = strstr(word, str_post2)))) { ptr[-1] = '\0'; /* hialan §ïÃC¦â */ clrtoeol(); prints("[1;36m¢~\033[46;37m%s\033[m%-55.55s[1;33;46m%.4s[m\033[1;33m%-13s\033[36m¢¡[0m\n", head[0], word, ptr, ptr + 5); } else if (pos < (local ? 3 : 4)) { clrtoeol(); prints("[1;36m¢x\033[46;37m%s\033[m%-72.72s[1;36m¢x\033[m\n", head[pos], word); } viewed += numbytes; numbytes = readln(fp, buf); if (!pos && viewed >= 79) /* ²Ä¤@¦æ¤Óªø¤F */ { if (memcmp(buf, head[1], 2)) /* ²Ä¤G¦æ¤£¬O [¼Ð....] */ { viewed += numbytes; /* Ū¤U¤@¦æ¶i¨Ó³B²z */ numbytes = readln(fp, buf); } } pos++; } if (pos) { header = 1; outs("[1;36m¢¢¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w\033[0;30;47m y)¦^À³ /)·j´M¤å¦r =[]<>)¥DÃD¦¡¾\\Ū \033[0;1;36m¢£[m\n"); line = pos = (local ? 4 : 5); } } lino = pos; word = NULL; } /* ¡°³B²z¤Þ¥ÎªÌ & ¤Þ¨¥ */ if ((buf[1] == ' ') && (buf[0] == ':' || buf[0] == '>')) word = "[36m"; if ((buf[1] == ' ') && (buf[0] == ':' || buf[0] == '>') && (buf[2] == ':' || buf[2] == '>')) word = "[33m"; if ((buf[0] == '¡' && buf[1] == '°') || !strncmp(buf, "==>", 3)) word = "[1;36m"; ch1 = buf; while (1) /* Ptt */ { int i; char e, *ch2; if (ch2 = strstr(ch1, "gopher://")); else if (ch2 = strstr(ch1, "mailto:")); else if (ch2 = strstr(ch1, "board://")); /* ¤ä´©ª½±µ¶i¤J¬ÝªO */ else break; for (e = 0; ch2[e] != ' ' && ch2[e] != '\n' && ch2[e] != '\0' && ch2[e] != '"' && ch2[e] != ';' && ch2[e] != ']'; e++); for (i = 0; http[i] && i < 80; i++) if (!strncmp(http[i], ch2, e) && http[e] == 0) break; if (!http[i]) { http[i] = (char *)malloc(e + 1); strncpy(http[i], ch2, e); http[i][e] = 0; pagecount++; } ch1 = &ch2[7]; } if (word) outs(word); { char msg[500], *pos; if (*search_str && (pos = fptr(buf, search_str))) { char SearchStr[41]; char buf1[100], *pos1; strncpy(SearchStr, pos, strlen(search_str)); SearchStr[strlen(search_str)] = 0; searching = 0; sprintf(msg, "%.*s[7m%s[0m", pos - buf, buf, SearchStr); while (pos = fptr(pos1 = pos + strlen(search_str), search_str)) { sprintf(buf1, "%.*s[7m%s[0m", pos - pos1, pos1, SearchStr); strcat(msg, buf1); } strcat(msg, pos1); outs(Ptt_prints(msg, NO_RELOAD)); } else { outs(Ptt_prints(buf, NO_RELOAD)); } } if (word) { outs("[0m"); word = NULL; } outc('\n'); if (beep) { bell(); beep = 0; } if (line < b_lines) /* ¤@¯ë¸ê®ÆŪ¨ú */ line++; if (line == b_lines && searching == -1) { if (pageno > 0) fseek(fp, (off_t) (viewed = pagebreak[--pageno]), SEEK_SET); else searching = 0; lino = pos = line = 0; clear(); continue; } if (scrollup) { move(line = b_lines, 0); clrtoeol(); for (pos = 1; pos < b_lines; pos++) viewed += readln(fp, buf); } else if (pos == b_lines) /* ±²°Ê¿Ã¹õ */ scroll(); else pos++; if (!scrollup && ++lino >= b_lines && pageno < MAXPAGES - 1) { pagebreak[++pageno] = viewed; lino = 1; } if (scrollup) { lino = scrollup; scrollup = 0; } viewed += numbytes; /* ²ÖpŪ¹L¸ê®Æ */ } else line = b_lines; /* end of END */ if (promptend && (!searching && line == b_lines || viewed == st.st_size)) { move(b_lines, 0); if (viewed == st.st_size) { if (searching == 1) searching = 0; } else if (pageno == 1 && lino == 1) { if (searching == -1) searching = 0; } prints("%s ÂsÄý P.%d(%d%%) ", COLOR2, pageno, (viewed * 100) / st.st_size); prints("%s ¡ö¡ô¡õ¡÷|PgUp|PgDn|Home|End)¾ÉÄý h)»¡©ú \033[m", COLOR3); move(b_lines, 0); /* ¸Ñ¨Mª½±µ¸õ¨ì¬ÝªOªºBug */ while (line == b_lines || (line > 0 && viewed == st.st_size)) { switch (ch = igetkey()) { case 'h': case 'H': case '?': show_file("etc/help/MORE.help", 0, 24, ONLY_COLOR); pressanykey_old(NULL); if (pageno) pageno--; lino = line = 0; break; case ':': { char buf[10]; int i = 0; getdata(b_lines - 1, 0, "Goto Page: ", buf, 5, DOECHO, 0); sscanf(buf, "%d", &i); if (0 < i && i < MAXPAGES && (i == 1 || pagebreak[i - 1])) pageno = i - 1; else if (pageno) pageno--; lino = line = 0; break; } case '/': { char ans[4] = "n"; *search_str = search_char0; getdata(b_lines - 1, 0, "[·j´M]ÃöÁä¦r:", search_str, 40, DOECHO, 0); if (*search_str) { searching = 1; if (getdata(b_lines - 1, 0, "°Ï¤À¤j¤p¼g(Y/N/Q)? [N] ", ans, 4, LCECHO, 0) && *ans == 'y') fptr = strstr; else fptr = strcasestr; } if (*ans == 'q') searching = 0; if (pageno) pageno--; lino = line = 0; break; } case 'n': if (*search_str) { searching = 1; if (pageno) pageno--; lino = line = 0; } break; case 'N': if (*search_str) { searching = -1; if (pageno) pageno--; lino = line = 0; } break; case 'r': case 'R': case 'Y': case 'y': case 'A': case 'a': case 'F': case 'B': case KEY_LEFT: case 'q': case 'b': case 'f': case ']': /* Kaede ¬°¤F¥DÃD¾\Ū¤è«K */ case '[': /* Kaede ¬°¤F¥DÃD¾\Ū¤è«K */ case '=': /* Kaede ¬°¤F¥DÃD¾\Ū¤è«K */ fclose(fp); inmore = 0; return ch; case Ctrl('F'): case KEY_PGDN: line = 1; break; case 't': if (viewed == st.st_size) { /* ch ']' */ fclose(fp); inmore = 0; return ']'; } line = 1; break; case ' ': if (viewed == st.st_size) { /* ch 'f' */ fclose(fp); inmore = 0; return 'f'; } line = 1; break; case KEY_RIGHT: if (viewed == st.st_size) { /* ch 'q' */ fclose(fp); inmore = 0; return 'q'; } line = 1; pagemode = 0; break; case '\r': case '\n': if (pagemode) { more_web(http[pagemode - 1], YEA); /* pagebreak[0] = pageno = viewed = line = pos = 0; */ pagemode = 0; *search_str = 0; if (pageno) pageno--; lino = line = 0; break; } case KEY_DOWN: if (viewed == st.st_size || promptend == 2 && (ch == '\r' || ch == '\n')) { /* ch 'f' */ fclose(fp); inmore = 0; return 'f'; } line = t_lines - 2; break; case '$': case 'G': case KEY_END: line = t_lines; break; case '0': case 'g': case KEY_HOME: pageno = line = 0; break; case 'E': if (strcmp(fpath, "etc/ve.hlp")) { /* ch 'q' */ fclose(fp); inmore = 0; vedit(fpath, HAS_PERM(PERM_SYSOP) ? 0 : 2); return 'q'; } break; case KEY_ESC: if (KEY_ESC_arg == 'n') { edit_note(); if (pageno) pageno--; lino = line = 0; } else if (KEY_ESC_arg == 'c') capture_screen(); break; case Ctrl('I'): if (!pagecount) break; pagemode = (pagemode % pagecount) + 1; strcpy(search_str, http[pagemode - 1]); fptr = strstr; if (pageno) pageno--; lino = line = 0; break; case KEY_UP: line = -1; break; case Ctrl('B'): case KEY_PGUP: if (pageno > 1) { if (lino < 2) pageno -= 2; else pageno--; lino = line = 0; } else if (pageno && lino > 1) pageno = line = 0; break; case Ctrl('H'): if (pageno > 1) { if (lino < 2) pageno -= 2; else pageno--; lino = line = 0; } else if (pageno && lino > 1) pageno = line = 0; else { /* ch 'b' */ fclose(fp); inmore = 0; return 'b'; } } } if (line > 0) { move(b_lines, 0); clrtoeol(); refresh(); } else if (line < 0) { /* Line scroll up */ if (pageno <= 1) { if (lino == 1 || !pageno) { /* ch 'b' */ fclose(fp); inmore = 0; return 'b'; } /* ¶¤º¤W±² sheng 20020113 */ if (header && lino <= 6 - local) { fseek(fp, (off_t) (viewed = pagebreak[scrollup = lino = pageno = 0] = 0), SEEK_SET); clear(); } } if (pageno && lino > 1) { line = lino - 2; if (pageno == 1 && header) line = lino - 3; scrollup = lino - 1; fseek(fp, (off_t) (viewed = pagebreak[pageno - 1]), SEEK_SET); while (line--) viewed += readln(fp, buf); } else if (pageno > 1) { scrollup = b_lines - 1; line = b_lines - 2; if (pageno == 2 && header) line = b_lines - 3; fseek(fp, (off_t) (viewed = pagebreak[--pageno - 1]), SEEK_SET); while (line--) viewed += readln(fp, buf); } line = pos = 0; } else { pos = 0; fseek(fp, (off_t) (viewed = pagebreak[pageno]), SEEK_SET); clear(); } } } fclose(fp); if (promptend) { pressanykey(NULL); clear(); } else outs(reset_color); inmore = 0; return 'q'; /* ch 'q'*/ }
int vedit(const char *filename, const char *saveheader, char *bname) { int ch, foo; int lastcharindent = -1; BOOL firstkey = TRUE; char bakfile[PATHLEN]; int old_rows = t_lines, old_columns = t_columns; sethomefile(bakfile, curuser.userid, UFNAME_EDIT); if ((saveheader || uinfo.mode == EDITPLAN || uinfo.mode == EDITBMWEL) && isfile(bakfile) /* lthuang */ #ifdef GUEST && strcmp(curuser.userid, GUEST) #endif ) { clear(); outs(_msg_edit_8); if (getkey() != '2') mycp(bakfile, filename); } if (!isfile(filename)) unlink(bakfile); if (saveheader) do_article_sig(filename); read_file(filename); top_of_win = firstline; currline = firstline; curr_window_line = 0; currpnt = 0; ansi_mode = FALSE; clear(); display_buffer(); move(curr_window_line, currpnt); while ((ch = getkey()) != EOF) { if (firstkey) { firstkey = FALSE; show_help_msg(); } if (talkrequest) /* lthuang */ { backup_file(bakfile); talkreply(); pressreturn(); ch = CTRL('G'); /* redraw screen */ } else if (msqrequest) /* lthuang */ { msqrequest = FALSE; msq_reply(); #if 0 ch = CTRL('G'); #endif } if (old_rows != t_lines || old_columns != t_columns) { static const char *msg_resized = "[1;34;47m螢幕大小已改變, 按(Ctrl-G)回到頁首![m"; old_rows = t_lines; old_columns = t_columns; top_of_win = firstline; currline = top_of_win; curr_window_line = 0; currpnt = 0; shift = 0; redraw_everything = TRUE; move(t_lines / 2, (t_columns - strlen(msg_resized)) / 2); outs(msg_resized); while (getkey() != CTRL('G')); } else if (ch < 0x100 && isprint2(ch)) { insert_char(ch); lastcharindent = -1; } else switch (ch) { case KEY_UP: if (lastcharindent == -1) lastcharindent = currpnt; if (!currline->prev) { bell(); break; } curr_window_line--; currline = currline->prev; currpnt = (currline->len > lastcharindent) ? lastcharindent : currline->len; break; case KEY_DOWN: if (lastcharindent == -1) lastcharindent = currpnt; if (!currline->next) { bell(); break; } curr_window_line++; currline = currline->next; currpnt = (currline->len > lastcharindent) ? lastcharindent : currline->len; break; default: lastcharindent = -1; switch (ch) { case CTRL('T'): top_of_win = back_line(lastline, b_lines - 2); currline = lastline; curr_window_line = getlineno(); currpnt = 0; redraw_everything = TRUE; break; case CTRL('S'): top_of_win = firstline; currline = top_of_win; curr_window_line = 0; currpnt = 0; redraw_everything = TRUE; break; case '\t': do { insert_char(' '); } while (currpnt & 0x7); break; case CTRL('U'): case CTRL('V'): insert_char(0x1b); break; case CTRL('C'): insert_char(0x1b); insert_char('['); insert_char('m'); break; case KEY_RIGHT: case CTRL('F'): if (currline->len == currpnt) { if (!currline->next) bell(); else { currpnt = 0; curr_window_line++; currline = currline->next; } } else currpnt++; break; case KEY_LEFT: case CTRL('B'): if (currpnt == 0) { if (!currline->prev) bell(); else { currline = currline->prev; currpnt = currline->len; curr_window_line--; } } else currpnt--; break; case CTRL('G'): clear(); redraw_everything = TRUE; break; case CTRL('Z'): vedit_help(); break; case KEY_PGUP: case CTRL('P'): top_of_win = back_line(top_of_win, b_lines - 2); currline = top_of_win; currpnt = 0; curr_window_line = 0; redraw_everything = TRUE; break; case KEY_PGDN: case CTRL('N'): top_of_win = forward_line(top_of_win, b_lines - 2); currline = top_of_win; currpnt = 0; curr_window_line = 0; redraw_everything = TRUE; break; case KEY_HOME: case CTRL('A'): currpnt = 0; break; case KEY_END: case CTRL('E'): currpnt = currline->len; break; case CTRL('R'): #if 0 backup_file(bakfile); #endif msq_reply(); #if 0 redraw_everything = TRUE; /* lthuang */ #endif break; case CTRL('Q'): ansi_mode = TRUE; display_buffer(); pressreturn(); ansi_mode = FALSE; display_buffer(); break; case CTRL('X'): case CTRL('W'): backup_file(bakfile); clear(); foo = write_file(filename, saveheader, bname); if (foo == BACKUP_EDITING) return foo; else if (foo != KEEP_EDITING) { unlink(bakfile); return foo; } redraw_everything = TRUE; /* lthuang */ break; case '\r': case '\n': split(currline, currpnt); /* lthuang: reduce the times of backup */ if (total_num_of_line % 7 == 0) backup_file(bakfile); break; case '\177': case CTRL('H'): if (currpnt == 0) { if (!currline->prev) { bell(); break; } curr_window_line--; currline = currline->prev; currpnt = currline->len; if (*killsp(currline->next->data) == '\0') { delete_line(currline->next); redraw_everything = TRUE; } else { join_currline(); } if (curr_window_line == -1) { curr_window_line = 0; top_of_win = currline; rscroll(); } break; } currpnt--; delete_char(); break; case CTRL('D'): if (currline->len == currpnt) join_currline(); else delete_char(); break; case CTRL('Y'): currpnt = 0; currline->len = 0; delete_currline(); break; case CTRL('K'): if (currline->len == 0) delete_currline(); else if (currline->len == currpnt) join_currline(); else { currline->len = currpnt; currline->data[currpnt] = '\0'; } break; default: break; } break; } if (curr_window_line == -1) { curr_window_line = 0; if (!top_of_win->prev) { indigestion(6); bell(); } else { top_of_win = top_of_win->prev; rscroll(); } } if (curr_window_line == t_lines - 1) { curr_window_line = t_lines - 2; if (!top_of_win->next) { indigestion(7); bell(); } else { top_of_win = top_of_win->next; scroll(); } } /* lthuang: 99/07 */ if (currpnt - shift >= t_columns - 1) { shift = (currpnt / (t_columns - 1)) * (t_columns - 1) - 1; redraw_everything = TRUE; } else if (currpnt - shift < 0) { shift = 0; redraw_everything = TRUE; } if (redraw_everything) { display_buffer(); redraw_everything = FALSE; } else { move(curr_window_line, 0); clrtoeol(); /* lthuang */ vedit_outs(currline->data); } move(curr_window_line, currpnt - shift); /* lthuang: 99/07 */ } if (uinfo.mode == POSTING || uinfo.mode == SMAIL) unlink(filename); return ABORT_EDITING; }