static void db_more(void) { char *p; int quit_output = 0; for (p = "--db_more--"; *p; p++) cnputc(*p); switch(cngetc()) { case ' ': db_output_line = 0; break; case 'q': case CTRL('c'): db_output_line = 0; quit_output = 1; break; default: db_output_line--; break; } p = "\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b"; while (*p) cnputc(*p++); if (quit_output) { db_error(0); /* NOTREACHED */ } }
void putchar(int c) { cnputc(c); if (c == '\n') cnputc('\r'); }
static void db_more() { register char *p; boolean_t quit_output = FALSE; for (p = "--db_more--"; *p; p++) cnputc(*p); switch(cngetc()) { case ' ': db_output_line = 0; break; case 'q': case CTRL('c'): db_output_line = 0; quit_output = TRUE; break; default: db_output_line--; break; } p = "\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b"; while (*p) cnputc(*p++); if (quit_output) { db_error(0); /* NOTREACHED */ } }
void cninit(void) { struct consdev *cp; dev_ops_t cn_ops; int x; if (cn_inited) return; /* * Collect information about all possible consoles * and find the one with highest priority */ for (cp = constab; cp->cn_probe; cp++) { (*cp->cn_probe)(cp); if (cp->cn_pri > CN_DEAD && (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri)) cn_tab = cp; } /* * Found a console, initialize it. */ if ((cp = cn_tab)) { /* * Initialize as console */ (*cp->cn_init)(cp); /* * Look up its dev_ops pointer in the device table and * place it in the device indirection table. */ if (dev_name_lookup(cp->cn_name, &cn_ops, &x) == FALSE) panic("cninit: dev_name_lookup failed"); dev_set_indirection("console", cn_ops, minor(cp->cn_dev)); #if CONSBUFSIZE > 0 /* * Now that the console is initialized, dump any chars in * the temporary console buffer. */ if (consbufused) { char *cbp = consbp; do { if (*cbp) cnputc(*cbp); if (++cbp == &consbuf[CONSBUFSIZE]) cbp = consbuf; } while (cbp != consbp); consbufused = FALSE; } #endif /* CONSBUFSIZE > 0 */ cn_inited = TRUE; return; } /* * No console device found, not a problem for BSD, fatal for Mach */ panic("can't find a console device"); }
int rump_tputchar(int c, int flags, struct tty *tp) { cnputc(c); return 0; }
/* * 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 */ }
/* * 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 */ }
/* * Force pending whitespace. */ void db_force_whitespace(void) { register int last_print, next_tab; last_print = db_last_non_space; while (last_print < db_output_position) { next_tab = NEXT_TAB(last_print); if (next_tab <= db_output_position) { cnputc('\t'); last_print = next_tab; } else { cnputc(' '); last_print++; } } db_last_non_space = db_output_position; }
/* * Force pending whitespace. */ void db_force_whitespace(void) { int last_print, next_tab; last_print = db_last_non_space; while (last_print < db_output_position) { next_tab = NEXT_TAB(last_print); if (next_tab <= db_output_position) { while (last_print < next_tab) { /* DON'T send a tab!!! */ cnputc(' '); last_print++; } } else { cnputc(' '); last_print++; } } db_last_non_space = db_output_position; }
void putchar(int c) { switch (c) { case '\177': /* DEL erases */ cnputc('\b'); cnputc(' '); case '\b': cnputc('\b'); if (pch_pos) pch_pos--; break; case '\t': do cnputc(' '); while (++pch_pos % 8) ; break; case '\n': case '\r': cnputc(c); pch_pos = 0; break; default: cnputc(c); pch_pos++; break; } }
/* * End line if too long. */ void db_end_line(void) { if (db_output_position >= db_max_width-1) { /* auto new line */ if (!db_auto_wrap) cnputc('\n'); db_output_position = 0; db_last_non_space = 0; db_last_gen_return = 1; db_output_line++; } }
/* * 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(); }
void db_hang(int tries, char *word, struct _abc *sabc) { const char *p; int i; int c; #ifdef ABC_BITMASK int m; #endif for (p = hangpic; *p; p++) cnputc((*p >= '0' && *p <= '9') ? ((tries <= (*p) - '0') ? substchar[(*p) - '0'] : ' ') : *p); for (p = word; *p; p++) { c = TOLOWER(*p); cnputc(ISLOWALPHA(c) && ABC_ISCLR(c) ? '-' : *p); } #ifdef ABC_WRONGSTR db_printf(" (%s)\r", ABC_WRONGSTR); #else db_printf(" ("); #ifdef ABC_BITMASK m = sabc->wrong; for (i = 'a'; i <= 'z'; ++i, m >>= 1) if (m&1) cnputc(i); #else for (i = 'a'; i <= 'z'; ++i) if (ABC_ISWRONG(i)) cnputc(i); #endif db_printf(")\r"); #endif }
boolean_t db_reserve_output_position(int increment) { if (db_max_width >= DB_MIN_MAX_WIDTH && db_output_position + increment >= db_max_width) { /* auto new line */ if (!db_auto_wrap || db_last_non_space != db_output_position) cnputc('\n'); db_output_position = 0; db_last_non_space = 0; db_last_gen_return = 1; db_output_line++; return TRUE; } return FALSE; }
int getchar(void) { int c; c = cngetc(); #if 0 if (c == 0x1b) /* ESC ? */ call_kdp(); #endif 0 if (c == '\r') c = '\n'; cnputc(c); return c; }
void cnputc(char c) { #if NBM > 0 if (SCREEN_ISA_CONSOLE()) { /* this does its own rcputc */ screen_blitc(SCREEN_CONS_UNIT(), c); } else #endif /* NBM > 0 */ { rcputc(c); (*console_putc)( cnunit, cnline, c);/* insist on a console still */ } if (c == '\n') cnputc('\r'); }
void db_advance_output_position(int new_output_position, int blank) { if (db_max_width >= DB_MIN_MAX_WIDTH && new_output_position >= db_max_width) { /* auto new line */ if (!db_auto_wrap || blank) cnputc('\n'); db_output_position = 0; db_last_non_space = 0; db_last_gen_return = 1; db_output_line++; } else { db_output_position = new_output_position; } }
void db_delete(int n, int bwd) { char *p; if (bwd) { db_lc -= n; db_putnchars(BACKUP, n); } for (p = db_lc; p < db_le-n; p++) { *p = *(p+n); cnputc(*p); } db_putnchars(BLANK, n); db_putnchars(BACKUP, db_le - db_lc); db_le -= n; }
int printk (char *fmt, ...) { va_list args; int n, flags; char *p, *msg, *buf_end; static int msg_level = -1; save_flags (flags); cli (); va_start (args, fmt); n = vsnprintf (buf + 3, sizeof (buf) - 3, fmt, args); assert (n <= sizeof (buf) - 3); buf_end = buf + 3 + n; va_end (args); for (p = buf + 3; p < buf_end; p++) { msg = p; if (msg_level < 0) { if (p[0] != '<' || p[1] < '0' || p[1] > '7' || p[2] != '>') { p -= 3; p[0] = '<'; p[1] = DEFAULT_MESSAGE_LOGLEVEL + '0'; p[2] = '>'; } else msg += 3; msg_level = p[1] - '0'; } for (; p < buf_end; p++) if (*p == '\n') break; if (msg_level < console_loglevel) while (msg <= p) cnputc (*msg++); if (*p == '\n') msg_level = -1; } restore_flags (flags); return n; }
void db_console(void) { if (i_bit(CBUS_PUT_CHAR, my_word)) { volatile u_char c = cbus_ochar; i_bit_clear(CBUS_PUT_CHAR, my_word); cnputc(c); } else if (i_bit(CBUS_GET_CHAR, my_word)) { if (cbus_wait_char) cbus_ichar = cngetc(); else cbus_ichar = cnmaygetc(); i_bit_clear(CBUS_GET_CHAR, my_word); #ifndef notdef } else if (!cnmaygetc()) { #else /* notdef */ } else if (com_is_char() && !com_getc(TRUE)) { #endif /* notdef */ simple_unlock(&db_lock); db_cpu = my_cpu; } }
int putchar(int c) { cnputc(c); }
void db_putnchars(int c, int count) { while (--count >= 0) cnputc(c); }
void db_putstring(char *s, int count) { while (--count >= 0) cnputc(*s++); }
/* returns TRUE at end-of-line */ int db_inputchar(int c) { static int escstate; if (escstate == 1) { /* ESC seen, look for [ or O */ if (c == '[' || c == 'O') escstate++; else escstate = 0; /* re-init state machine */ return (0); } else if (escstate == 2) { escstate = 0; /* * If a valid cursor key has been found, translate * into an emacs-style control key, and fall through. * Otherwise, drop off. */ switch (c) { case 'A': /* up */ c = CTRL('p'); break; case 'B': /* down */ c = CTRL('n'); break; case 'C': /* right */ c = CTRL('f'); break; case 'D': /* left */ c = CTRL('b'); break; default: return (0); } } switch (c) { case CTRL('['): escstate = 1; break; case CTRL('b'): /* back up one character */ if (db_lc > db_lbuf_start) { cnputc(BACKUP); db_lc--; } break; case CTRL('f'): /* forward one character */ if (db_lc < db_le) { cnputc(*db_lc); db_lc++; } break; case CTRL('a'): /* beginning of line */ while (db_lc > db_lbuf_start) { cnputc(BACKUP); db_lc--; } break; case CTRL('e'): /* end of line */ while (db_lc < db_le) { cnputc(*db_lc); db_lc++; } break; case CTRL('h'): case 0177: /* erase previous character */ if (db_lc > db_lbuf_start) db_delete(1, DEL_BWD); break; case CTRL('d'): /* erase next character */ if (db_lc < db_le) db_delete(1, DEL_FWD); break; case CTRL('u'): /* kill entire line: */ /* at first, delete to beginning of line */ if (db_lc > db_lbuf_start) db_delete(db_lc - db_lbuf_start, DEL_BWD); /* FALLTHROUGH */ case CTRL('k'): /* delete to end of line */ if (db_lc < db_le) db_delete(db_le - db_lc, DEL_FWD); break; case CTRL('t'): /* twiddle last 2 characters */ if (db_lc >= db_lbuf_start + 2) { c = db_lc[-2]; db_lc[-2] = db_lc[-1]; db_lc[-1] = c; cnputc(BACKUP); cnputc(BACKUP); cnputc(db_lc[-2]); cnputc(db_lc[-1]); } break; case CTRL('r'): db_putstring("^R\n", 3); redraw: if (db_le > db_lbuf_start) { db_putstring(db_lbuf_start, db_le - db_lbuf_start); db_putnchars(BACKUP, db_le - db_lc); } break; case CTRL('p'): /* Make previous history line the active one. */ if (db_lhistcur >= 0) { bcopy(db_lhistory + db_lhistcur * db_lhistlsize, db_lbuf_start, db_lhistlsize); db_lhistcur--; goto hist_redraw; } break; case CTRL('n'): /* Make next history line the active one. */ if (db_lhistcur < db_lhistidx - 1) { db_lhistcur += 2; bcopy(db_lhistory + db_lhistcur * db_lhistlsize, db_lbuf_start, db_lhistlsize); } else { /* * ^N through tail of history, reset the * buffer to zero length. */ *db_lbuf_start = '\0'; db_lhistcur = db_lhistidx; } hist_redraw: db_putnchars(BACKUP, db_le - db_lbuf_start); db_putnchars(BLANK, db_le - db_lbuf_start); db_putnchars(BACKUP, db_le - db_lbuf_start); db_le = index(db_lbuf_start, '\0'); if (db_le[-1] == '\r' || db_le[-1] == '\n') *--db_le = '\0'; db_lc = db_le; goto redraw; case -1: /* * eek! the console returned eof. * probably that means we HAVE no console.. we should try bail * XXX */ return (0); case '\n': case '\r': *db_le++ = c; return (1); default: if (db_le == db_lbuf_end) { cnputc('\007'); } else if (c >= ' ' && c <= '~') { char *p; for (p = db_le; p > db_lc; p--) *p = *(p-1); *db_lc++ = c; db_le++; cnputc(c); db_putstring(db_lc, db_le - db_lc); db_putnchars(BACKUP, db_le - db_lc); } break; } return (0); }
/* returns TRUE at end-of-line */ int db_inputchar(int c) { switch (c) { case CTRL('b'): /* back up one character */ if (db_lc > db_lbuf_start) { cnputc(BACKUP); db_lc--; } break; case CTRL('f'): /* forward one character */ if (db_lc < db_le) { cnputc(*db_lc); db_lc++; } break; case CTRL('a'): /* beginning of line */ while (db_lc > db_lbuf_start) { cnputc(BACKUP); db_lc--; } break; case CTRL('e'): /* end of line */ while (db_lc < db_le) { cnputc(*db_lc); db_lc++; } break; case CTRL('w'): /* erase word back */ while (db_lc > db_lbuf_start && db_lc[-1] != BLANK) db_delete(1, DEL_BWD); break; case CTRL('h'): case 0177: /* erase previous character */ if (db_lc > db_lbuf_start) db_delete(1, DEL_BWD); break; case CTRL('d'): /* erase next character */ if (db_lc < db_le) db_delete(1, DEL_FWD); break; case CTRL('k'): /* delete to end of line */ if (db_lc < db_le) db_delete(db_le - db_lc, DEL_FWD); break; case CTRL('u'): /* delete line */ db_delete_line(); break; case CTRL('t'): /* twiddle last 2 characters */ if (db_lc >= db_lbuf_start + 2) { c = db_lc[-2]; db_lc[-2] = db_lc[-1]; db_lc[-1] = c; cnputc(BACKUP); cnputc(BACKUP); cnputc(db_lc[-2]); cnputc(db_lc[-1]); } break; #if DB_HISTORY_SIZE != 0 case CTRL('p'): DEC_DB_CURR(); while (db_history_curr != db_history_last) { DEC_DB_CURR(); if (*db_history_curr == '\0') break; } db_delete_line(); if (db_history_curr == db_history_last) { INC_DB_CURR(); db_le = db_lc = db_lbuf_start; } else { char *p; INC_DB_CURR(); for (p = db_history_curr, db_le = db_lbuf_start;*p; ) { *db_le++ = *p++; if (p == db_history + db_history_size) p = db_history; } db_lc = db_le; } db_putstring(db_lbuf_start, db_le - db_lbuf_start); break; case CTRL('n'): while (db_history_curr != db_history_last) { if (*db_history_curr == '\0') break; INC_DB_CURR(); } if (db_history_curr != db_history_last) { INC_DB_CURR(); db_delete_line(); if (db_history_curr != db_history_last) { char *p; for (p = db_history_curr, db_le = db_lbuf_start; *p;) { *db_le++ = *p++; if (p == db_history + db_history_size) p = db_history; } db_lc = db_le; } db_putstring(db_lbuf_start, db_le - db_lbuf_start); } break; #endif case CTRL('r'): db_putstring("^R\n", 3); if (db_le > db_lbuf_start) { db_putstring(db_lbuf_start, db_le - db_lbuf_start); db_putnchars(BACKUP, db_le - db_lc); } break; case '\n': case '\r': #if DB_HISTORY_SIZE != 0 /* * Check whether current line is the same * as previous saved line. If it is, don`t * save it. */ if (db_history_curr == db_history_prev) { char *pp, *pc; /* * Is it the same? */ for (pp = db_history_prev, pc = db_lbuf_start; pc != db_le && *pp; ) { if (*pp != *pc) break; if (++pp == db_history + db_history_size) pp = db_history; pc++; } if (!*pp && pc == db_le) { /* * Repeated previous line. Don`t save. */ db_history_curr = db_history_last; *db_le++ = c; return TRUE; } } if (db_le != db_lbuf_start) { char *p; db_history_prev = db_history_last; for (p = db_lbuf_start; p != db_le; p++) { *db_history_last++ = *p; if (db_history_last == db_history + db_history_size) db_history_last = db_history; } *db_history_last++ = '\0'; } db_history_curr = db_history_last; #endif *db_le++ = c; return TRUE; default: if (db_le == db_lbuf_end) { cnputc('\007'); } else if (c >= ' ' && c <= '~') { char *p; for (p = db_le; p > db_lc; p--) *p = *(p-1); *db_lc++ = c; db_le++; cnputc(c); db_putstring(db_lc, db_le - db_lc); db_putnchars(BACKUP, db_le - db_lc); } break; } return FALSE; }
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 */ }
static void do_cnputc(char c, vm_offset_t offset) { cnputc(c); }
/* * 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(); }