2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
26 * $FreeBSD: src/sys/ddb/db_output.c,v 1.26 1999/08/28 00:41:09 peter Exp $
30 * Author: David B. Golub, Carnegie Mellon University
35 * Printf and character output for debugger.
38 #include <sys/param.h>
39 #include <sys/systm.h>
42 #include <machine/stdarg.h>
45 #include <ddb/db_output.h>
48 * Character output - tracks position in line.
49 * To do this correctly, we should know how wide
50 * the output device is - then we could zero
51 * the line position when the output device wraps
52 * around to the start of the next line.
54 * Instead, we count the number of spaces printed
55 * since the last printing character so that we
56 * don't print trailing spaces. This avoids most
59 static int db_output_position = 0; /* output column */
60 static int db_last_non_space = 0; /* last non-space character */
61 db_expr_t db_tab_stop_width = 8; /* how wide are tab stops? */
63 ((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
64 db_expr_t db_max_width = 79; /* output line width */
66 static void db_putchar __P((int c, void *arg));
69 * Force pending whitespace.
74 register int last_print, next_tab;
76 last_print = db_last_non_space;
77 while (last_print < db_output_position) {
78 next_tab = NEXT_TAB(last_print);
79 if (next_tab <= db_output_position) {
80 while (last_print < next_tab) { /* DON'T send a tab!!! */
90 db_last_non_space = db_output_position;
94 * Output character. Buffer whitespace.
98 int c; /* character to output */
101 if (c > ' ' && c <= '~') {
103 * Printing character.
104 * If we have spaces to print, print them first.
105 * Use tabs if possible.
107 db_force_whitespace();
109 db_output_position++;
110 db_last_non_space = db_output_position;
112 else if (c == '\n') {
115 db_output_position = 0;
116 db_last_non_space = 0;
117 db_check_interrupt();
119 else if (c == '\r') {
122 db_output_position = 0;
123 db_last_non_space = 0;
124 db_check_interrupt();
126 else if (c == '\t') {
127 /* assume tabs every 8 positions */
128 db_output_position = NEXT_TAB(db_output_position);
132 db_output_position++;
134 else if (c == '\007') {
138 /* other characters are assumed non-printing */
142 * Return output position
147 return (db_output_position);
155 db_printf(const char *fmt, ...)
163 va_start(listp, fmt);
164 kvprintf (fmt, db_putchar, NULL, db_radix, listp);
172 db_iprintf(const char *fmt,...)
181 for (i = db_indent; i >= 8; i -= 8)
185 va_start(listp, fmt);
186 kvprintf (fmt, db_putchar, NULL, db_radix, listp);
191 * End line if too long.
196 if (db_output_position >= db_max_width)