summaryrefslogtreecommitdiffstats
path: root/sys/ddb/db_output.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2003-07-31 17:27:52 +0000
committerjhb <jhb@FreeBSD.org>2003-07-31 17:27:52 +0000
commit7a022c490241980d564815f3a9eb35f1899334d6 (patch)
tree2e3958472b2e92004d1cf78c61cbb91760f2f2b8 /sys/ddb/db_output.c
parente77fe07b3a80c9ac29de7086418b3c8db6b99374 (diff)
downloadFreeBSD-src-7a022c490241980d564815f3a9eb35f1899334d6.zip
FreeBSD-src-7a022c490241980d564815f3a9eb35f1899334d6.tar.gz
Add a one-shot callout facility to db_printf() that executes the registered
callout when a specified number of lines have been output. This can be used to implement pagers for ddb commands that output a lot of text. A simple paging function is included that automatically rearms itself when fired. Reviewed by: bde, julian
Diffstat (limited to 'sys/ddb/db_output.c')
-rw-r--r--sys/ddb/db_output.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/sys/ddb/db_output.c b/sys/ddb/db_output.c
index b1efb45..2fa8554 100644
--- a/sys/ddb/db_output.c
+++ b/sys/ddb/db_output.c
@@ -62,6 +62,10 @@ db_expr_t db_tab_stop_width = 8; /* how wide are tab stops? */
#define NEXT_TAB(i) \
((((i) + db_tab_stop_width) / db_tab_stop_width) * db_tab_stop_width)
db_expr_t db_max_width = 79; /* output line width */
+static int db_newlines; /* # lines this page */
+static int db_maxlines = -1; /* max lines per page */
+static db_page_calloutfcn_t *db_page_callout = NULL;
+static void *db_page_callout_arg = NULL;
static void db_putchar(int c, void *arg);
@@ -98,6 +102,7 @@ db_putchar(c, arg)
int c; /* character to output */
void * arg;
{
+
if (c > ' ' && c <= '~') {
/*
* Printing character.
@@ -115,6 +120,13 @@ db_putchar(c, arg)
db_output_position = 0;
db_last_non_space = 0;
db_check_interrupt();
+ if (db_maxlines > 0 && db_page_callout != NULL) {
+ db_newlines++;
+ if (db_newlines >= db_maxlines) {
+ db_maxlines = -1;
+ db_page_callout(db_page_callout_arg);
+ }
+ }
}
else if (c == '\r') {
/* Return */
@@ -139,6 +151,60 @@ db_putchar(c, arg)
}
/*
+ * Register callout for providing a pager for output.
+ */
+void
+db_setup_paging(db_page_calloutfcn_t *callout, void *arg, int maxlines)
+{
+
+ db_page_callout = callout;
+ db_page_callout_arg = arg;
+ db_maxlines = maxlines;
+ db_newlines = 0;
+}
+
+/*
+ * A simple paging callout function. If the argument is not null, it
+ * points to an integer that will be set to 1 if the user asks to quit.
+ */
+void
+db_simple_pager(void *arg)
+{
+ int c;
+
+ db_printf("--More--\r");
+ for (;;) {
+ c = cngetc();
+ switch (c) {
+ case '\n':
+ /* Just one more line. */
+ db_setup_paging(db_simple_pager, arg, 1);
+ return;
+ case ' ':
+ /* Another page. */
+ db_setup_paging(db_simple_pager, arg,
+ DB_LINES_PER_PAGE);
+ return;
+ case 'q':
+ case 'Q':
+ case 'x':
+ case 'X':
+ /* Quit */
+ if (arg != NULL) {
+ *(int *)arg = 1;
+ db_printf("\n");
+ return;
+ }
+#if 0
+ /* FALLTHROUGH */
+ default:
+ cnputc('\007');
+#endif
+ }
+ }
+}
+
+/*
* Return output position
*/
int
OpenPOWER on IntegriCloud