void pageup(editor_t *ed, int select) { int i; update_selection(ed, select); if (ed->line < ed->lines) { ed->linepos = ed->toppos = 0; ed->line = ed->topline = 0; } else { for (i = 0; i < ed->lines; i++) { int newpos = prev_line(ed, ed->linepos); if (newpos < 0) return; ed->linepos = newpos; ed->line--; if (ed->topline > 0) { ed->toppos = prev_line(ed, ed->toppos); ed->topline--; } } } ed->refresh = 1; adjust(ed); }
void left(editor_t *ed, int select) { update_selection(ed, select); if (ed->col > 0) { ed->col--; } else { int newpos = prev_line(ed, ed->linepos); if (newpos < 0) return; ed->col = line_length(ed, newpos); ed->linepos = newpos; ed->line--; if (ed->line < ed->topline) { ed->toppos = ed->linepos; ed->topline = ed->line; ed->refresh = 1; } } ed->lastcol = ed->col; adjust(ed); }
/* * If we've got a blank line to write onto, fake half-lines that way. * Otherwise, eat them. We assume that half-line controls occur in pairs. */ static int half_up(int level) { prev_line(); if (cur_line->l_this < cur_line->l_used) { next_line(); return level+1; } return 0; }
void up(editor_t *ed, int select) { int newpos; update_selection(ed, select); newpos = prev_line(ed, ed->linepos); if (newpos < 0) return; ed->linepos = newpos; ed->line--; if (ed->line < ed->topline) { ed->toppos = ed->linepos; ed->topline = ed->line; ed->refresh = 1; } adjust(ed); }
void wordleft(editor_t *ed, int select) { int pos, phase; update_selection(ed, select); pos = ed->linepos + ed->col; phase = 0; while (pos > 0) { int ch = get(ed, pos - 1); if (phase == 0) { if (wordchar(ch)) phase = 1; } else { if (!wordchar(ch)) break; } pos--; if (pos < ed->linepos) { ed->linepos = prev_line(ed, ed->linepos); ed->line--; ed->refresh = 1; } } ed->col = pos - ed->linepos; if (ed->line < ed->topline) { ed->toppos = ed->linepos; ed->topline = ed->line; } ed->lastcol = ed->col; adjust(ed); }
void moveto(editor_t *ed, int pos, int center) { int scroll = 0; for (;;) { int cur = ed->linepos + ed->col; if (pos < cur) { if (pos >= ed->linepos) { ed->col = pos - ed->linepos; } else { ed->col = 0; ed->linepos = prev_line(ed, ed->linepos); ed->line--; if (ed->topline > ed->line) { ed->toppos = ed->linepos; ed->topline--; ed->refresh = 1; scroll = 1; } } } else if (pos > cur) { int next = next_line(ed, ed->linepos); if (next == -1) { ed->col = line_length(ed, ed->linepos); break; } else if (pos < next) { ed->col = pos - ed->linepos; } else { ed->col = 0; ed->linepos = next; ed->line++; if (ed->line >= ed->topline + ed->lines) { ed->toppos = next_line(ed, ed->toppos); ed->topline++; ed->refresh = 1; scroll = 1; } } } else { break; } } if (scroll && center) { int tl = ed->line - ed->lines / 2; if (tl < 0) tl = 0; for (;;) { if (ed->topline > tl) { ed->toppos = prev_line(ed, ed->toppos); ed->topline--; } else if (ed->topline < tl) { ed->toppos = next_line(ed, ed->toppos); ed->topline++; } else { break; } } } }
/* * Filter an entire file, writing the result to the standard output. */ static void ManFilter(FILE *ifp) { int c; int level = 0; int ident = CS_NORMAL; int esc_mode = ATR_NORMAL; while ((c = fgetc(ifp)) != EOF) { switch (c) { case '\b': backspace(); break; case '\r': if (cur_line != 0) cur_line->l_this = 0; break; case '\n': next_line(); cur_line->l_this = 0; break; case '\t': do { put_cell(SPACE, level, ident); } while (cur_line->l_this & 7); break; case '\v': prev_line(); break; case SHIFT_IN: ident = CS_NORMAL; break; case SHIFT_OUT: ident = CS_ALTERNATE; break; case ESCAPE: switch (fgetc(ifp)) { case '[': esc_mode = ansi_escape(ifp, ident, level); break; case '\007': case '7': prev_line(); break; case '\010': case '8': level = half_up(level); break; case '\011': case '9': level = half_down(level); break; default: /* ignore everything else */ break; } break; default: /* ignore other nonprinting characters */ if (isprint(c)) { put_cell(c, level, ident); if (c != SPACE) { if (esc_mode & ATR_BOLD) { backspace(); put_cell(c, level, ident); } if (esc_mode & ATR_UNDER) { backspace(); put_cell('_', level, ident); } } } break; } } while (all_lines != 0) flush_line(); total_lines = 0; }