char deserve(char *str) { int i; int q; char qt; i = 0; q = 0; qt = 0; while (str[i]) { if (back_line(str, i) && (str[i] == '"' || str[i] == '\'' || str[i] == '`')) { if (!q) qt = str[i]; if (qt == str[i]) q = (q) ? 0 : 1; } i++; } if (q) return (qt); return (0); }
int ft_occ_nb(const char *str, char c) { int i; int x; i = 0; x = 0; while (str[i] != '\0') { if (str[i] == c && back_line((char*)str, i)) x++; i++; } return (x); }
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; }