Add memtest support.
[syslinux-debian/hramrach.git] / gpxe / src / hci / mucurses / print.c
blob1608c0a7828f192229c725955025ab451b639b3c
1 #include <curses.h>
2 #include <stdio.h>
3 #include <stddef.h>
4 #include <gpxe/vsprintf.h>
5 #include "mucurses.h"
7 /** @file
9 * MuCurses printing functions
13 FILE_LICENCE ( GPL2_OR_LATER );
15 /**
16 * Add a single-byte character and rendition to a window and advance
17 * the cursor
19 * @v *win window to be rendered in
20 * @v ch character to be added at cursor
21 * @ret rc return status code
23 int waddch ( WINDOW *win, const chtype ch ) {
24 _wputch( win, ch, WRAP );
25 return OK;
28 /**
29 * Add string of single-byte characters to a window
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
36 int waddnstr ( WINDOW *win, const char *str, int n ) {
37 _wputstr( win, str, WRAP, n );
38 return OK;
41 struct printw_context {
42 struct printf_context ctx;
43 WINDOW *win;
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 );
50 _wputch( wctx->win, c | wctx->win->attrs, WRAP );
53 /**
54 * Print formatted output in a window
56 * @v *win subject window
57 * @v *fmt formatted string
58 * @v varglist argument list
59 * @ret rc return status code
61 int vw_printw ( WINDOW *win, const char *fmt, va_list varglist ) {
62 struct printw_context wctx;
64 wctx.win = win;
65 wctx.ctx.handler = _printw_handler;
66 vcprintf ( &(wctx.ctx), fmt, varglist );
67 return OK;
70 /**
71 * Print formatted output to a window
73 * @v *win subject window
74 * @v *fmt formatted string
75 * @v ... string arguments
76 * @ret rc return status code
78 int wprintw ( WINDOW *win, const char *fmt, ... ) {
79 va_list args;
80 int i;
82 va_start ( args, fmt );
83 i = vw_printw ( win, fmt, args );
84 va_end ( args );
85 return i;