iPXE
print.c
Go to the documentation of this file.
1 #include <curses.h>
2 #include <stdio.h>
3 #include <stddef.h>
4 #include <ipxe/vsprintf.h>
5 #include "mucurses.h"
6 
7 /** @file
8  *
9  * MuCurses printing functions
10  *
11  */
12 
13 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
14 
15 /**
16  * Add a single-byte character and rendition to a window and advance
17  * the cursor
18  *
19  * @v *win window to be rendered in
20  * @v ch character to be added at cursor
21  * @ret rc return status code
22  */
23 int waddch ( WINDOW *win, const chtype ch ) {
24  _wputch( win, ch, WRAP );
25  return OK;
26 }
27 
28 /**
29  * Add string of single-byte characters to a window
30  *
31  * @v *win window to be rendered in
32  * @v *str standard c-style string
33  * @v n max number of chars from string to render
34  * @ret rc return status code
35  */
36 int waddnstr ( WINDOW *win, const char *str, int n ) {
37  _wputstr( win, str, WRAP, n );
38  return OK;
39 }
40 
44 };
45 
46 static void _printw_handler ( struct printf_context *ctx, unsigned int c ) {
47  struct printw_context *wctx =
48  container_of ( ctx, struct printw_context, ctx );
49 
50  _wputch( wctx->win, c | wctx->win->attrs, WRAP );
51 }
52 
53 /**
54  * Print formatted output in a window
55  *
56  * @v *win subject window
57  * @v *fmt formatted string
58  * @v varglist argument list
59  * @ret rc return status code
60  */
61 int vw_printw ( WINDOW *win, const char *fmt, va_list varglist ) {
62  struct printw_context wctx;
63 
64  wctx.win = win;
66  vcprintf ( &(wctx.ctx), fmt, varglist );
67  return OK;
68 }
69 
70 /**
71  * Print formatted output to a window
72  *
73  * @v *win subject window
74  * @v *fmt formatted string
75  * @v ... string arguments
76  * @ret rc return status code
77  */
78 int wprintw ( WINDOW *win, const char *fmt, ... ) {
79  va_list args;
80  int i;
81 
82  va_start ( args, fmt );
83  i = vw_printw ( win, fmt, args );
84  va_end ( args );
85  return i;
86 }
MuCurses header file.
static __always_inline void off_t int c
Definition: librm.h:173
#define va_end(ap)
Definition: stdarg.h:9
void(* handler)(struct printf_context *ctx, unsigned int c)
Character handler.
Definition: vsprintf.h:57
void _wputstr(WINDOW *win, const char *str, int wrap, int n) __nonnull
Write a standard c-style string to a window.
Definition: mucurses.c:121
Curses Window struct.
Definition: curses.h:89
printf() and friends
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
MuCurses core implementation specific header file.
Definition: sis900.h:208
uint8_t ch
Definition: registers.h:83
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct printf_context ctx
Definition: print.c:42
attr_t attrs
window attributes
Definition: curses.h:93
WINDOW * win
Definition: print.c:43
void _wputch(WINDOW *win, chtype ch, int wrap) __nonnull
Write a single character rendition to a window.
Definition: mucurses.c:50
A printf context.
Definition: vsprintf.h:47
__builtin_va_list va_list
Definition: stdarg.h:6
int ssize_t const char * fmt
Definition: vsprintf.h:72
uint32_t chtype
Definition: curses.h:29
#define va_start(ap, last)
Definition: stdarg.h:7
#define WRAP
Definition: mucurses.h:12
size_t vcprintf(struct printf_context *ctx, const char *fmt, va_list args)
Write a formatted string to a printf context.
Definition: vsprintf.c:187