/* * printthebuffer() * * Description: * Iterates through the buffer and uses "putc" to print it. * * Inputs: none * * Outputs: none */ void printthebuffer(void) { int i; /* Return. */ carriage_return(); /* Iterate though command buffer and print each char. */ for (i = 0; i <= command_length[active_terminal]; i++) { putc(command_buffer[active_terminal][i], active_terminal); } }
int do_article() { register char *s; ART_POS artsize; /* size in bytes of article */ bool hide_this_line = FALSE; /* hidden header line? */ ART_LINE linenum; /* line # on page, 1 origin */ #ifdef ULSMARTS bool under_lining = FALSE; /* are we underlining a word? */ #endif register char *bufptr = art_buf; /* pointer to input buffer */ register int outpos; /* column position of output */ static char prompt_buf[64]; /* place to hold prompt */ bool notesfiles = FALSE; /* might there be notesfiles junk? */ char oldmode = mode; #ifdef INNERSEARCH register int outputok; #endif if (fstat(artfp->_file,&filestat)) /* get article file stats */ return DA_CLEAN; if (filestat.st_mode & S_IFMT != S_IFREG) return DA_NORM; artsize = filestat.st_size; /* from that get article size */ sprintf(prompt_buf, "%%sEnd of article %ld (of %ld)--what next? [%%s]", (long)art,(long)lastart); /* format prompt string */ prompt = prompt_buf; int_count = 0; /* interrupt count is 0 */ firstpage = (topline < 0); for (;;) { /* for each page */ assert(art == openart); if (do_fseek) { #ifdef ASYNC_PARSE parse_maybe(art); /* make sure header is ours */ #endif artpos = vrdary(artline); if (artpos < 0) artpos = -artpos; /* labs(), anyone? */ if (firstpage) artpos = (ART_POS)0; fseek(artfp,artpos,0); if (artpos < htype[PAST_HEADER].ht_minpos) in_header = SOME_LINE; do_fseek = FALSE; restart = Nullch; } if (firstpage) { if (firstline) { interp(art_buf, (sizeof art_buf), firstline); #ifdef CLEAREOL maybe_eol(); /* PWP */ #endif CLEAREOL fputs(art_buf,stdout) FLUSH; artopen(art); /* rewind article in case interp */ /* forced a header parse */ } else { ART_NUM i; #ifdef CLEAREOL maybe_eol(); /* PWP */ #endif CLEAREOL printf("Article %ld",(long)art); i = (((ART_NUM)toread[ng]) - 1 + was_read(art)); #ifdef DELAYMARK if (i || dmcount) { printf(" (%ld more",(long)i); if (dmcount) printf(" + %ld Marked to return)",(long)dmcount); putchar(')'); } #else if (i) printf(" (%ld more)",(long)i); #endif if (htype[NGS_LINE].ht_flags & HT_HIDE) printf(" in %s", ngname); fputs(":\n",stdout) FLUSH; } start_header(art); forcelast = FALSE; /* we will have our day in court */ restart = Nullch; artline = 0; /* start counting lines */ artpos = 0; vwtary(artline,artpos); /* remember pos in file */ } for (linenum=(firstpage?2:1); in_header || ( #ifdef INNERSEARCH innersearch ? innermore() : #endif linenum<(firstpage?initlines:(special?slines:LINES)) ); linenum++) { /* for each line on page */ if (int_count) { /* exit via interrupt? */ putchar('\n') FLUSH; /* get to left margin */ int_count = 0; /* reset interrupt count */ mode = oldmode; return DA_NORM; /* skip out of loops */ } if (restart) { /* did not finish last line? */ bufptr = restart; /* then start again here */ restart = Nullch; /* and reset the flag */ } else { /* not a restart */ if (fgets(art_buf,LBUFLEN,artfp)==Nullch) { /* if all done */ mode = oldmode; return DA_NORM; /* skip out of loops */ } bufptr = art_buf; /* so start at beginning */ art_buf[LBUFLEN-1] = '\0'; /* make sure string ends */ } blinebeg = bufptr; /* remember where we began */ alinebeg = artpos; /* both in buffer and file */ if (in_header && bufptr == art_buf) hide_this_line = parseline(art_buf,do_hiding,hide_this_line); else if (notesfiles && do_hiding && bufptr == art_buf && *art_buf == '#' && isupper(art_buf[1]) && art_buf[2] == ':' ) { fgets(art_buf,sizeof(art_buf),artfp); if (index(art_buf,'!') != Nullch) fgets(art_buf,sizeof(art_buf),artfp); htype[PAST_HEADER].ht_minpos = ftell(artfp); /* exclude notesfiles droppings */ hide_this_line = TRUE; /* and do not print either */ notesfiles = FALSE; } #ifdef CUSTOMLINES if (hideline && bufptr == art_buf && execute(&hide_compex,art_buf) ) hide_this_line = TRUE; #endif if (in_header && htype[in_header].ht_flags & HT_MAGIC) { if (in_header == NGS_LINE) { hide_this_line = (index(art_buf,',') == Nullch); } else if (in_header == EXPIR_LINE) { if (!(htype[EXPIR_LINE].ht_flags & HT_HIDE)) hide_this_line = (strlen(art_buf) < 10); } } if (in_header == SUBJ_LINE && htype[SUBJ_LINE].ht_flags & HT_MAGIC) { /* is this the subject? */ int length; length = strlen(art_buf)-1; artline++; art_buf[length] = '\0'; /* wipe out newline */ #ifdef NOFIREWORKS no_ulfire(); #endif notesfiles = (instr(&art_buf[length-10]," - (nf") != Nullch); if (oldsubject) { length += 7; fputs("(SAME) ",stdout); oldsubject = FALSE; } if (length+UG > COLS) { /* rarely true */ linenum++; vwtary(artline,vrdary(artline-1)+COLS); artline++; } s = art_buf + 8; *s++ = '\0'; /* make into 2 strings */ #ifdef CLEAREOL maybe_eol(); /* PWP */ #endif CLEAREOL fputs(art_buf,stdout) FLUSH; /* print up through : */ if (!UG) putchar(' '); underprint(s); /* print subject underlined */ putchar('\n') FLUSH; /* and finish the line */ } else if (hide_this_line && do_hiding) { /* do not print line? */ linenum--; /* compensate for linenum++ */ if (!in_header) hide_this_line = FALSE; } else { /* just a normal line */ if (highlight==artline) { /* this line to be highlit? */ if (marking == STANDOUT) { #ifdef NOFIREWORKS if (erase_screen) no_sofire(); #endif standout(); } else { #ifdef NOFIREWORKS if (erase_screen) no_ulfire(); #endif underline(); } if (*bufptr == '\n') putchar(' '); } #ifdef INNERSEARCH outputok = !hide_everything; /* get it into register, hopefully */ #endif #ifdef CLEAREOL #ifdef INNERSEARCH if (outputok) #endif maybe_eol(); /* PWP */ #endif CLEAREOL #ifdef CUSTOMLINES if (pagestop && bufptr == art_buf && execute(&page_compex,art_buf) ) linenum = 32700; #endif for (outpos = 0; outpos < COLS; ) { /* while line has room */ if (*bufptr >= ' ') { /* normal char? */ #ifdef ULSMARTS if (*bufptr == '_') { if (bufptr[1] == '\b') { if (!under_lining && highlight!=artline #ifdef INNERSEARCH && outputok #endif ) { under_lining++; if (UG) { if (bufptr != buf && bufptr[-1] == ' ') { outpos--; backspace(); } } underline(); } bufptr += 2; } } else { if (under_lining) { under_lining = 0; un_underline(); if (UG) { if (*bufptr == ' ') goto skip_put; outpos++; } } } #endif #ifdef INNERSEARCH if (outputok) #endif { #ifdef ROTATION if (rotate && !in_header && isalpha(*bufptr)) { if ((*bufptr & 31) <= 13) putchar(*bufptr+13); else putchar(*bufptr-13); } else #endif putchar(*bufptr); } if (*UC && ((highlight==artline && marking == 1) #ifdef ULSMARTS || under_lining #endif )) { backspace(); underchar(); } skip_put: bufptr++; outpos++; } else if (*bufptr == '\n' || !*bufptr) { /* newline? */ #ifdef ULSMARTS if (under_lining) { under_lining = 0; un_underline(); } #endif #ifdef DEBUGGING if (debug & DEB_INNERSRCH && outpos < COLS - 6) { standout(); printf("%4d",artline); un_standout(); } #endif #ifdef INNERSEARCH if (outputok) #endif putchar('\n') FLUSH; restart = 0; outpos = 1000; /* signal normal \n */ } else if (*bufptr == '\t') { /* tab? */ #ifdef INNERSEARCH if (outputok) #endif putchar(*bufptr); bufptr++; outpos += 8 - outpos % 8; } else if (*bufptr == '\f') { /* form feed? */ #ifdef INNERSEARCH if (outputok) #endif fputs("^L",stdout); if (bufptr == blinebeg && highlight != artline) linenum = 32700; /* how is that for a magic number? */ bufptr++; outpos += 2; } else { /* other control char */ #ifdef INNERSEARCH if (outputok) #endif { putchar('^'); if (highlight == artline && *UC && marking == 1) { backspace(); underchar(); putchar(*bufptr+64); backspace(); underchar(); } else putchar(*bufptr+64); } bufptr++; outpos += 2; } } /* end of column loop */ if (outpos < 1000) {/* did line overflow? */ restart = bufptr; /* restart here next time */ if (AM) { /* automatic margins on tty? */ if (!XN && *bufptr == '\n') /* need we simulate XN? */ restart = 0; /* skip the newline */ } else { /* cursor just hangs there */ #ifdef INNERSEARCH if (outputok) #endif putchar('\n') FLUSH; /* so move it down ourselves */ if (*bufptr == '\n') restart = 0; /* simulate XN if need be */ } #ifdef CLEAREOL /* #ifdef INNERSEARCH if (outputok) #endif maybe_eol(); */ /* PWP *//* comment this out for now until I am sure it is needed*/ #endif CLEAREOL } /* handle normal end of output line formalities */ if (highlight == artline) { /* were we highlighting line? */ if (marking == STANDOUT) un_standout(); else un_underline(); highlight = -1; /* no more we are */ } artline++; /* count the line just printed */ if (artline - LINES + 1 > topline) /* did we just scroll top line off? */ topline = artline - LINES + 1; /* then recompute top line # */ } /* determine actual position in file */ if (restart) /* stranded somewhere in the buffer? */ artpos += restart - blinebeg; /* just calculate position */ else /* no, ftell will do */ artpos = ftell(artfp); /* so do ftell */ vwtary(artline,artpos); /* remember pos in file */ } /* end of line loop */ #ifdef INNERSEARCH innersearch = 0; if (hide_everything) { hide_everything = FALSE; *buf = Ctl('l'); goto fake_command; } #endif if (linenum >= 32700)/* did last line have formfeed? */ vwtary(artline-1,-vrdary(artline-1)); /* remember by negating pos in file */ special = FALSE; /* end of page, so reset page length */ firstpage = FALSE; /* and say it is not 1st time thru */ /* extra loop bombout */ if (artpos == artsize) {/* did we just now reach EOF? */ mode = oldmode; return DA_NORM; /* avoid --MORE--(100%) */ } /* not done with this article, so pretend we are a pager */ reask_pager: unflush_output(); /* disable any ^O in effect */ standout(); /* enter standout mode */ printf("--MORE--(%ld%%)",(long)(artpos*100/artsize)); un_standout(); /* leave standout mode */ fflush(stdout); /* reinp_pager: /* unused, commented for lint */ eat_typeahead(); #ifdef DEBUGGING if (debug & DEB_CHECKPOINTING) { printf("(%d %d %d)",checkcount,linenum,artline); fflush(stdout); } #endif if (checkcount >= docheckwhen && linenum == LINES && (artline > 40 || checkcount >= docheckwhen+10) ) { /* while he is reading a whole page */ /* in an article he is interested in */ checkcount = 0; checkpoint_rc(); /* update .newsrc */ } collect_subjects(); /* loads subject cache until */ /* input is pending */ mode = 'p'; getcmd(buf); if (errno) { if (LINES < 100 && !int_count) *buf = '\f';/* on CONT fake up refresh */ else { *buf = 'q'; /* on INTR or paper just quit */ } } carriage_return(); #ifndef CLEAREOL erase_eol(); /* and erase the prompt */ #else if (erase_screen && can_home_clear) /* PWP was here */ clear_rest(); else erase_eol(); /* and erase the prompt */ #endif CLEAREOL fflush(stdout); fake_command: /* used by innersearch */ /* parse and process pager command */ switch (page_switch()) { case PS_ASK: /* reprompt "--MORE--..." */ goto reask_pager; case PS_RAISE: /* reparse on article level */ mode = oldmode; return DA_RAISE; case PS_TOEND: /* fast pager loop exit */ mode = oldmode; return DA_TOEND; case PS_NORM: /* display more article */ break; } } /* end of page loop */ }
void test(bool* result) { SCREEN_Screen scr; scr = screen(80, 25); update(result, tposeq("initial cursor", mkpos(0, 0), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(5, 10)); update(result, tposeq("cursor_address", mkpos(5, 10), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(12, 5)); carriage_return(&scr); update(result, tposeq("carriage_return", mkpos(0, 5), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(12, 5)); newline(&scr); update(result, tposeq("newline", mkpos(0, 6), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(10, 6)); tab(&scr); update(result, tposeq("tab", mkpos(16, 6), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(1, 6)); column_address(&scr, 16); update(result, tposeq("column_address", mkpos(16, 6), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(16, 6)); row_address(&scr, 12); update(result, tposeq("row_address", mkpos(16, 12), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(15, 6)); cursor_down(&scr); update(result, tposeq("cursor_down", mkpos(15, 7), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(15, 6)); cursor_home(&scr); update(result, tposeq("cursor_home", mkpos(0, 0), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(6, 8)); cursor_left(&scr); update(result, tposeq("cursor_left", mkpos(5, 8), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(6, 8)); cursor_right(&scr); update(result, tposeq("cursor_right", mkpos(7, 8), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(6, 8)); cursor_to_ll(&scr); update(result, tposeq("cursor_to_ll", mkpos(0, 24), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(6, 8)); cursor_up(&scr); update(result, tposeq("cursor_up", mkpos(6, 7), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(26, 9)); parm_left_cursor(&scr, 23); update(result, tposeq("parm_left_cursor", mkpos(3, 9), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(3, 9)); parm_right_cursor(&scr, 23); update(result, tposeq("parm_right_cursor", mkpos(26, 9), cursor(&scr))); scr = screen(80, 25); cursor_address(&scr, mkpos(26, 4)); parm_down_cursor(&scr, 11); update(result, tposeq("parm_down_cursor", mkpos(26, 15), cursor(&scr))); scr = screen(6, 4); cursor_address(&scr, mkpos(2, 3)); put_char(&scr, 'a'); SCREEN_Cell want_0 = {'a', SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, {false, false}}; update(result, tcelleq("put_char puts", want_0, cellat(&scr, mkpos(2,3)))); scr = screen(6, 4); cursor_address(&scr, mkpos(2, 3)); put_char(&scr, 'a'); update(result, tposeq("put_char moves", mkpos(3, 3), cursor(&scr))); scr = screen(6, 4); cursor_address(&scr, mkpos(5, 1)); put_char(&scr, 'a'); update(result, tposeq("put_char am", mkpos(0, 2), cursor(&scr))); scr = screen(6, 4); put_chars(&scr, "abcdefGHIJKLmno"); SCREEN_Cell want_1 = {'J', SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, {false, false}}; update(result, tcelleq("put_char multiple", want_1, cellat(&scr, mkpos(3,1)))); scr = screen(6, 4); put_chars(&scr, "abcdefGHIJKLmno"); clear_screen(&scr); update(result, tposeq("clear_screen homes", mkpos(0, 0), cursor(&scr))); scr = screen(6, 4); put_chars(&scr, "abcdefGHIJKLmno"); clear_screen(&scr); SCREEN_Cell want_2 = {' ', SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, {false, false}}; update(result, tcelleq("clear_screen clears", want_2, cellat(&scr, mkpos(3,1)))); scr = screen(6, 4); cursor_address(&scr, mkpos(0, 3)); put_chars(&scr, "abcdefGHIJKLmno"); SCREEN_Cell want_3 = {'J', SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, {false, false}}; update(result, tcelleq("put_char scrolls at end", want_3, cellat(&scr, mkpos(3,2)))); scr = screen(6, 3); put_chars(&scr, "abcdefGHIJKLmno"); cursor_home(&scr); clr_eos(&scr); SCREEN_Cell want_4 = {' ', SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, {false, false}}; update(result, tcelleq("put_char scrolls at end", want_4, cellat(&scr, mkpos(4,1)))); scr = screen(6, 4); cursor_down(&scr); put_chars(&scr, "abcdefGHIJKLmno"); cursor_address(&scr, mkpos(0, 3)); newline(&scr); SCREEN_Cell want_5 = {'K', SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, {false, false}}; update(result, tcelleq("newline at bottom scrolls", want_5, cellat(&scr, mkpos(4,1)))); scr = screen(6, 4); put_chars(&scr, "abcdefGHIJKLmno"); cursor_address(&scr, mkpos(0, 0)); insert_line(&scr); SCREEN_Cell want_6 = {' ', SCREEN_COLOR_WHITE, SCREEN_COLOR_BLACK, {false, false}}; update(result, tcelleq("insert_line clears full line", want_6, cellat(&scr, mkpos(5,0)))); scr = screen(24, 4); cursor_address(&scr, mkpos(20, 1)); tab(&scr); update(result, tposeq("tab at eol", mkpos(0, 2), cursor(&scr))); }
int page_switch() { register char *s; switch (*buf) { case 'd': case Ctl('d'): /* half page */ special = TRUE; slines = LINES / 2 + 1; if (marking && *blinebeg != '\f' #ifdef CUSTOMLINES && (!pagestop || blinebeg != art_buf || !execute(&page_compex,blinebeg)) #endif ) { up_line(); highlight = --artline; restart = blinebeg; artpos = alinebeg; } return PS_NORM; case '!': /* shell escape */ escapade(); return PS_ASK; #ifdef INNERSEARCH case Ctl('i'): gline = 3; sprintf(cmd_buf,"^[^%c]",*blinebeg); compile(&gcompex,cmd_buf,TRUE,TRUE); goto caseG; case Ctl('g'): gline = 3; compile(&gcompex,"^Subject:",TRUE,TRUE); goto caseG; case 'g': /* in-article search */ if (!finish_command(FALSE))/* get rest of command */ return PS_ASK; s = buf+1; if (isspace(*s)) s++; if ((s = compile(&gcompex,s,TRUE,TRUE)) != Nullch) { /* compile regular expression */ printf("\n%s\n",s) FLUSH; return PS_ASK; } carriage_return(); erase_eol(); /* erase the prompt */ /* FALL THROUGH */ caseG: case 'G': { /* ART_LINE lines_to_skip = 0; */ ART_POS start_where; if (gline < 0 || gline > LINES-2) gline = LINES-2; #ifdef DEBUGGING if (debug & DEB_INNERSRCH) printf("Start here? %d >=? %d\n",topline + gline + 1,artline) FLUSH; #endif if (*buf == Ctl('i') || topline+gline+1 >= artline) start_where = artpos; /* in case we had a line wrap */ else { start_where = vrdary(topline+gline+1); if (start_where < 0) start_where = -start_where; } if (start_where < htype[PAST_HEADER].ht_minpos) start_where = htype[PAST_HEADER].ht_minpos; fseek(artfp,(long)start_where,0); innersearch = 0; /* assume not found */ while (fgets(buf, sizeof buf, artfp) != Nullch) { /* lines_to_skip++; NOT USED NOW */ #ifdef DEBUGGING if (debug & DEB_INNERSRCH) printf("Test %s",buf) FLUSH; #endif if (execute(&gcompex,buf) != Nullch) { innersearch = ftell(artfp); break; } } if (!innersearch) { fseek(artfp,artpos,0); fputs("(Not found)",stdout) FLUSH; return PS_ASK; } #ifdef DEBUGGING if (debug & DEB_INNERSRCH) printf("On page? %ld <=? %ld\n",(long)innersearch,(long)artpos) FLUSH; #endif if (innersearch <= artpos) { /* already on page? */ if (innersearch < artpos) { artline = topline+1; while (vrdary(artline) < innersearch) artline++; } highlight = artline - 1; #ifdef DEBUGGING if (debug & DEB_INNERSRCH) printf("@ %d\n",highlight) FLUSH; #endif topline = highlight - gline; if (topline < -1) topline = -1; *buf = '\f'; /* fake up a refresh */ innersearch = 0; return page_switch(); } else { /* who knows how many lines it is? */ do_fseek = TRUE; hide_everything = TRUE; } return PS_NORM; } #else case 'g': case 'G': case Ctl('g'): notincl("g"); return PS_ASK; #endif case '\n': /* one line */ special = TRUE; slines = 2; return PS_NORM; #ifdef ROTATION case 'X': rotate = !rotate; /* FALL THROUGH */ #endif case 'l': case '\f': /* refresh screen */ #ifdef DEBUGGING if (debug & DEB_INNERSRCH) { printf("Topline = %d",topline) FLUSH; gets(buf); } #endif clear(); do_fseek = TRUE; artline = topline; if (artline < 0) artline = 0; firstpage = (topline < 0); return PS_NORM; case 'b': case '\b': /* I like backspace for this -- PWP */ /* Leaving it undocumented in case */ /* I want to steal the key--LAW */ case Ctl('b'): { /* back up a page */ ART_LINE target; #ifndef CLEAREOL clear(); #else if (can_home_clear) /* if we can home do it -- PWP */ home_cursor(); else clear(); #endif CLEAREOL do_fseek = TRUE; /* reposition article file */ target = topline - (LINES - 2); artline = topline; do { artline--; } while (artline >= 0 && artline > target && vrdary(artline-1) >= 0); topline = artline; /* remember top line of screen */ /* (line # within article file) */ if (artline < 0) artline = 0; firstpage = (topline < 0); return PS_NORM; } case 'h': { /* help */ int cmd; if ((cmd = help_page()) > 0) pushchar(cmd); return PS_ASK; } case '\177': case '\0': /* treat del,break as 'n' */ *buf = 'n'; /* FALL THROUGH */ case 'k': case 'K': case 'n': case 'N': case Ctl('n'): case 's': case 'S': case 'u': case 'w': case 'W': case '|': mark_as_read(art); /* mark article as read */ /* FALL THROUGH */ case '#': case '$': case '&': case '-': case '.': case '/': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '=': case '?': case 'c': case 'C': case 'f': case 'F': case 'j': case Ctl('k'): case 'm': case 'M': case 'p': case 'P': case Ctl('p'): case 'Q': case 'r': case 'R': case Ctl('r'): case 'v': case 'Y': #ifndef ROTATION case 'x': case 'X': #endif case Ctl('x'): case '^': #ifdef ROTATION rotate = FALSE; #endif reread = FALSE; do_hiding = TRUE; if (index("nNpP",*buf) == Nullch && index("wWsS!&|/?123456789.",*buf) != Nullch) { setdfltcmd(); standout(); /* enter standout mode */ printf(prompt,mailcall,dfltcmd); /* print prompt, whatever it is */ un_standout(); /* leave standout mode */ putchar(' '); fflush(stdout); } return PS_RAISE; /* and pretend we were at end */ #ifdef ROTATION case 'x': rotate = TRUE; /* FALL THROUGH */ #endif case 'y': case Ctl('v'): /* I like emacs -- PWP */ /* Leaving it undocumented in case */ /* I want to steal the key--LAW */ case ' ': /* continue current article */ if (erase_screen) { /* -e? */ #ifndef CLEAREOL clear(); /* clear screen */ #else if (can_home_clear) /* if we can home do it -- PWP */ home_cursor(); else clear(); /* else clear screen */ #endif CLEAREOL if (*blinebeg != '\f' #ifdef CUSTOMLINES && (!pagestop || blinebeg != art_buf || !execute(&page_compex,blinebeg)) #endif ) { restart = blinebeg; artline--; /* restart this line */ artpos = alinebeg; if (marking) /* and mark repeated line */ highlight = artline; } topline = artline; /* and remember top line of screen */ /* (line # within article file) */ } else if (marking && *blinebeg != '\f' #ifdef CUSTOMLINES && (!pagestop || blinebeg != art_buf || !execute(&page_compex,blinebeg)) #endif ) { /* are we marking repeats? */ up_line(); /* go up one line */ highlight = --artline;/* and get ready to highlight */ restart = blinebeg; /* the old line */ artpos = alinebeg; } return PS_NORM; case 'q': /* quit this article? */ do_hiding = TRUE; return PS_TOEND; default: fputs(hforhelp,stdout) FLUSH; settle_down(); return PS_ASK; } }
void outputter(SCREEN_Screen* scr, int terminator, GetCharFunction getf) { while (1) { unsigned char c = getf(); if (c == terminator) { return; } switch (c) { case '\a': break; // TODO: alert? case '\t': tab(scr); break; case '\n': cursor_down(scr); break; case '\b': cursor_left(scr); break; case '\r': carriage_return(scr); break; case 0x1b: { c = getf(); switch (c) { case '[': { int x; if (getnum(getf, &x, &c)) { if (x == 1 && c == 'K') { clr_bol(scr); } else { switch (c) { case 'm': mode(scr, x); break; case 'A': parm_up_cursor(scr, x); break; case 'B': parm_down_cursor(scr, x); break; case 'C': parm_right_cursor(scr, x); break; case 'D': parm_left_cursor(scr, x); break; case 'G': column_address(scr, (x-1)); break; case 'L': parm_insert_line(scr, x); break; case 'M': parm_delete_line(scr, x); break; case 'P': parm_dch(scr, x); break; case 'S': parm_index(scr, x); break; case 'T': parm_rindex(scr, x); break; case 'X': erase_chars(scr, x); break; case '@': parm_ich(scr, x); break; case 'd': row_address(scr, (x-1)); break; case ';': { int y; if (getnum(getf, &y, &c)) { switch (c) { case 'm': mode(scr, x); mode(scr, y); break; case 'H': cursor_address(scr, mkpos(y-1, x-1)); break; default: fprintf(stderr, "unhandled: ESC[%i;%i%c\n", x, y, c); break; } } else { fprintf(stderr, "unhandled: ESC[%i;%c\n", x, c); } } break; default: fprintf(stderr, "unahndled: ESC[%i%c\n", x, c); break; } } } else { switch (c) { case '@': insert_character(scr); break; case 'A': cursor_up(scr); break; case 'B': cursor_down(scr); break; case 'C': cursor_right(scr); break; case 'D': cursor_left(scr); break; case 'H': cursor_home(scr); break; case 'I': tab(scr); break; case 'J': clr_eos(scr); break; case 'K': clr_eol(scr); break; case 'L': insert_line(scr); break; case 'M': delete_line(scr); break; case 'P': delete_character(scr); break; case 'm': exit_attribute_mode(scr); break; default: fprintf(stderr, "unhandled: ESC[%c\n", c); break; } } } break; case 'M': scroll_reverse(scr); break; default: fprintf(stderr, "unhandled: ESC%c\n", c); break; } } break; default: { wchar_t wc; if ((c & 0x80) == 0x00) { wc = c; } else if ((c & 0xE0) == 0xC0) { char c1 = 0x1F & c; char c2 = 0x3F & getf(); wc = (c1 << 6) | c2; } else if ((c & 0xF0) == 0xE0) { char c1 = 0x0F & c; char c2 = 0x3F & getf(); char c3 = 0x3F & getf(); wc = (c1 << 12) | (c2 << 6) | c3; } else if ((c & 0xF8) == 0xF0) { char c1 = 0x07 & c; char c2 = 0x3F & getf(); char c3 = 0x3F & getf(); char c4 = 0x3F & getf(); wc = (c1 << 18) | (c2 << 12) | (c3 << 6) | c4; } else if ((c & 0xFC) == 0xF8) { char c1 = 0x03 & c; char c2 = 0x3F & getf(); char c3 = 0x3F & getf(); char c4 = 0x3F & getf(); char c5 = 0x3F & getf(); wc = (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | c5; } else if ((c & 0xFE) == 0xFC) { char c1 = 0x01 & c; char c2 = 0x3F & getf(); char c3 = 0x3F & getf(); char c4 = 0x3F & getf(); char c5 = 0x3F & getf(); char c6 = 0x3F & getf(); wc = (c1 << 30) | (c2 << 24) | (c3 << 18) | (c4 << 12) | (c5 < 6) | c6; } else { fprintf(stderr, "bad utf-8 sequence: c=0x%02x\n", c); wc = '\0'; } put_char(scr, wc); } break; } } }