1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 1996-2005 Paul Mackerras.
5 #include <linux/string.h>
10 static bool paginating
, paginate_skipping
;
11 static unsigned long paginate_lpp
; /* Lines Per Page */
12 static unsigned long paginate_pos
;
14 void xmon_start_pagination(void)
17 paginate_skipping
= false;
21 void xmon_end_pagination(void)
26 void xmon_set_pagination_lpp(unsigned long lpp
)
31 static int xmon_readchar(void)
38 static int xmon_write(const char *ptr
, int nb
)
41 const char *p
= ptr
, *q
;
42 const char msg
[] = "[Hit a key (a:all, q:truncate, any:next page)]";
47 if (paginating
&& paginate_skipping
)
51 while (paginating
&& (q
= strchr(p
, '\n'))) {
52 rv
+= udbg_write(p
, q
- p
+ 1);
56 if (paginate_pos
>= paginate_lpp
) {
57 udbg_write(msg
, strlen(msg
));
59 switch (xmon_readchar()) {
64 paginate_skipping
= true;
72 udbg_write("\r\n", 2);
74 if (paginate_skipping
)
80 return rv
+ udbg_write(p
, nb
- (p
- ptr
));
83 int xmon_putchar(int c
)
89 return xmon_write(&ch
, 1) == 1? c
: -1;
92 static char line
[256];
96 static int xmon_getchar(void)
104 if (c
== -1 || c
== 4)
106 if (c
== '\r' || c
== '\n') {
114 if (lineptr
> line
) {
122 while (lineptr
> line
) {
130 if (lineptr
>= &line
[sizeof(line
) - 1])
138 lineleft
= lineptr
- line
;
147 char *xmon_gets(char *str
, int nb
)
152 for (p
= str
; p
< str
+ nb
- 1; ) {
167 void xmon_printf(const char *format
, ...)
170 static char xmon_outbuf
[1024];
173 va_start(args
, format
);
174 n
= vsnprintf(xmon_outbuf
, sizeof(xmon_outbuf
), format
, args
);
177 rc
= xmon_write(xmon_outbuf
, n
);
180 /* No udbg hooks, fallback to printk() - dangerous */
181 pr_cont("%s", xmon_outbuf
);
185 void xmon_puts(const char *str
)
187 xmon_write(str
, strlen(str
));