2 * Copyright (C) 1996-2005 Paul Mackerras.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 #include <linux/string.h>
14 static bool paginating
, paginate_skipping
;
15 static unsigned long paginate_lpp
; /* Lines Per Page */
16 static unsigned long paginate_pos
;
18 void xmon_start_pagination(void)
21 paginate_skipping
= false;
25 void xmon_end_pagination(void)
30 void xmon_set_pagination_lpp(unsigned long lpp
)
35 static int xmon_readchar(void)
42 static int xmon_write(const char *ptr
, int nb
)
45 const char *p
= ptr
, *q
;
46 const char msg
[] = "[Hit a key (a:all, q:truncate, any:next page)]";
51 if (paginating
&& paginate_skipping
)
55 while (paginating
&& (q
= strchr(p
, '\n'))) {
56 rv
+= udbg_write(p
, q
- p
+ 1);
60 if (paginate_pos
>= paginate_lpp
) {
61 udbg_write(msg
, strlen(msg
));
63 switch (xmon_readchar()) {
68 paginate_skipping
= true;
76 udbg_write("\r\n", 2);
78 if (paginate_skipping
)
84 return rv
+ udbg_write(p
, nb
- (p
- ptr
));
87 int xmon_putchar(int c
)
93 return xmon_write(&ch
, 1) == 1? c
: -1;
96 static char line
[256];
100 static int xmon_getchar(void)
108 if (c
== -1 || c
== 4)
110 if (c
== '\r' || c
== '\n') {
118 if (lineptr
> line
) {
126 while (lineptr
> line
) {
134 if (lineptr
>= &line
[sizeof(line
) - 1])
142 lineleft
= lineptr
- line
;
151 char *xmon_gets(char *str
, int nb
)
156 for (p
= str
; p
< str
+ nb
- 1; ) {
171 void xmon_printf(const char *format
, ...)
174 static char xmon_outbuf
[1024];
177 va_start(args
, format
);
178 n
= vsnprintf(xmon_outbuf
, sizeof(xmon_outbuf
), format
, args
);
181 rc
= xmon_write(xmon_outbuf
, n
);
184 /* No udbg hooks, fallback to printk() - dangerous */
185 printk("%s", xmon_outbuf
);
189 void xmon_puts(const char *str
)
191 xmon_write(str
, strlen(str
));