/* * A simple paging callout function. It supports several simple more(1)-like * commands as well as a quit command that sets db_pager_quit which db * commands can poll to see if they should terminate early. */ void db_pager(void) { int c, done; db_capture_enterpager(); db_printf("--More--\r"); done = 0; while (!done) { c = cngetc(); switch (c) { case 'e': case 'j': case '\n': /* Just one more line. */ db_maxlines = 1; done++; break; case 'd': /* Half a page. */ db_maxlines = db_lines_per_page / 2; done++; break; case 'f': case ' ': /* Another page. */ db_maxlines = db_lines_per_page; done++; break; case 'q': case 'Q': case 'x': case 'X': /* Quit */ db_maxlines = 0; db_pager_quit = 1; done++; break; #if 0 /* FALLTHROUGH */ default: cnputc('\007'); #endif } } db_printf(" "); db_force_whitespace(); db_printf("\r"); db_newlines = 0; db_capture_exitpager(); }
/* * Output character. Buffer whitespace. */ void db_putchar(int c) { if (db_max_line >= DB_MIN_MAX_LINE && db_output_line >= db_max_line-1) db_more(); if (c > ' ' && c <= '~') { /* * Printing character. * If we have spaces to print, print them first. * Use tabs if possible. */ db_force_whitespace(); cnputc(c); db_output_position++; if (db_max_width >= DB_MIN_MAX_WIDTH && db_output_position >= db_max_width-1) { /* auto new line */ cnputc('\n'); db_output_position = 0; db_last_non_space = 0; db_output_line++; } db_last_non_space = db_output_position; } else if (c == '\n') { /* Return */ cnputc(c); db_output_position = 0; db_last_non_space = 0; db_output_line++; } else if (c == '\t') { /* assume tabs every 8 positions */ db_output_position = NEXT_TAB(db_output_position); } else if (c == ' ') { /* space */ db_output_position++; } else if (c == '\007') { /* bell */ cnputc(c); } /* other characters are assumed non-printing */ }
int db_readline(char *lstart, int lsize) { db_force_whitespace(); /* synch output position */ db_lbuf_start = lstart; db_lbuf_end = lstart + lsize - 1; db_lc = lstart; db_le = lstart; while (!db_inputchar(cngetc())) continue; db_putchar('\n'); /* synch output position */ *db_le = 0; return (db_le - db_lbuf_start); }
/* * Output character. Buffer whitespace. */ void db_putchar(char c) { if (db_max_line >= DB_MIN_MAX_LINE && db_output_line >= db_max_line-1) db_more(); if (c > ' ' && c <= '~') { /* * Printing character. * If we have spaces to print, print them first. * Use tabs if possible. */ db_force_whitespace(); cnputc(c); db_last_gen_return = 0; db_advance_output_position(db_output_position+1, 0); db_last_non_space = db_output_position; } else if (c == '\n') { /* Return */ if (db_last_gen_return) { db_last_gen_return = 0; } else { cnputc(c); db_output_position = 0; db_last_non_space = 0; db_output_line++; db_check_interrupt(); } } else if (c == '\t') { /* assume tabs every 8 positions */ db_advance_output_position(NEXT_TAB(db_output_position), 1); } else if (c == ' ') { /* space */ db_advance_output_position(db_output_position+1, 1); } else if (c == '\007') { /* bell */ cnputc(c); } /* other characters are assumed non-printing */ }
int db_readline(char *lstart, int lsize) { if (lsize != db_lhistlsize) { /* * (Re)initialize input line history. Throw away any * existing history. */ db_lhist_nlines = sizeof(db_lhistory) / lsize; db_lhistlsize = lsize; db_lhistidx = -1; } db_lhistcur = db_lhistidx; db_force_whitespace(); /* synch output position */ db_lbuf_start = lstart; db_lbuf_end = lstart + lsize; db_lc = lstart; db_le = lstart; while (!db_inputchar(cngetc())) continue; db_printf("\n"); /* synch output position */ *db_le = 0; if (db_le - db_lbuf_start > 1) { /* Maintain input line history for non-empty lines. */ if (++db_lhistidx == db_lhist_nlines) { /* Rotate history. */ ovbcopy(db_lhistory + db_lhistlsize, db_lhistory, db_lhistlsize * (db_lhist_nlines - 1)); db_lhistidx--; } bcopy(lstart, db_lhistory + db_lhistidx * db_lhistlsize, db_lhistlsize); } return (db_le - db_lbuf_start); }
/* * Output character. Buffer whitespace. * * Parameters: * arg: character to output */ static void db_putchar(int c, void *arg) { /* * If not in the debugger, output data to both the console and * the message buffer. */ if (!db_active) { if (c == '\r' || c == '\n' || c == '\t' || isprint(c)) { kprintf("%c", c); } else { kprintf("?"); } if (!db_active) return; if (c == '\r' || c == '\n') db_check_interrupt(); return; } crit_enter_hard(); if (c > ' ' && c <= '~') { /* * Printing character. * If we have spaces to print, print them first. * Use tabs if possible. */ db_force_whitespace(); cnputc(c); db_output_position++; db_last_non_space = db_output_position; } else if (c == '\n') { /* Newline */ cnputc(c); db_output_position = 0; db_last_non_space = 0; db_check_interrupt(); } else if (c == '\r') { /* Return */ cnputc(c); db_output_position = 0; db_last_non_space = 0; db_check_interrupt(); } else if (c == '\t') { /* assume tabs every 8 positions */ db_output_position = NEXT_TAB(db_output_position); } else if (c == ' ') { /* space */ db_output_position++; } else if (c == '\007') { /* bell */ cnputc(c); } /* other characters are assumed non-printing */ crit_exit_hard(); }
static void db_putc(int c) { /* * If not in the debugger or the user requests it, output data to * both the console and the message buffer. */ if (!kdb_active || ddb_use_printf) { printf("%c", c); if (!kdb_active) return; if (c == '\r' || c == '\n') db_check_interrupt(); if (c == '\n' && db_maxlines > 0) { db_newlines++; if (db_newlines >= db_maxlines) db_pager(); } return; } /* Otherwise, output data directly to the console. */ if (c > ' ' && c <= '~') { /* * Printing character. * If we have spaces to print, print them first. * Use tabs if possible. */ db_force_whitespace(); cnputc(c); db_capture_writech(c); db_output_position++; db_last_non_space = db_output_position; } else if (c == '\n') { /* Newline */ cnputc(c); db_capture_writech(c); db_output_position = 0; db_last_non_space = 0; db_check_interrupt(); if (db_maxlines > 0) { db_newlines++; if (db_newlines >= db_maxlines) db_pager(); } } else if (c == '\r') { /* Return */ cnputc(c); db_capture_writech(c); db_output_position = 0; db_last_non_space = 0; db_check_interrupt(); } else if (c == '\t') { /* assume tabs every 8 positions */ db_output_position = NEXT_TAB(db_output_position); } else if (c == ' ') { /* space */ db_output_position++; } else if (c == '\007') { /* bell */ cnputc(c); /* No need to beep in a log: db_capture_writech(c); */ } /* other characters are assumed non-printing */ }