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 FILE_SECBOOT ( PERMITTED );
15 
16 /**
17  * Add a single-byte character and rendition to a window and advance
18  * the cursor
19  *
20  * @v *win window to be rendered in
21  * @v ch character to be added at cursor
22  * @ret rc return status code
23  */
24 int waddch ( WINDOW *win, const chtype ch ) {
25  _wputch( win, ch, WRAP );
26  return OK;
27 }
28 
29 /**
30  * Add string of single-byte characters to a window
31  *
32  * @v *win window to be rendered in
33  * @v *str standard c-style string
34  * @v n max number of chars from string to render
35  * @ret rc return status code
36  */
37 int waddnstr ( WINDOW *win, const char *str, int n ) {
38  _wputstr( win, str, WRAP, n );
39  return OK;
40 }
41 
45 };
46 
47 static void _printw_handler ( struct printf_context *ctx, unsigned int c ) {
48  struct printw_context *wctx =
49  container_of ( ctx, struct printw_context, ctx );
50 
51  _wputch( wctx->win, c | wctx->win->attrs, WRAP );
52 }
53 
54 /**
55  * Print formatted output in a window
56  *
57  * @v *win subject window
58  * @v *fmt formatted string
59  * @v varglist argument list
60  * @ret rc return status code
61  */
62 int vw_printw ( WINDOW *win, const char *fmt, va_list varglist ) {
63  struct printw_context wctx;
64 
65  wctx.win = win;
67  vcprintf ( &(wctx.ctx), fmt, varglist );
68  return OK;
69 }
70 
71 /**
72  * Print formatted output to a window
73  *
74  * @v *win subject window
75  * @v *fmt formatted string
76  * @v ... string arguments
77  * @ret rc return status code
78  */
79 int wprintw ( WINDOW *win, const char *fmt, ... ) {
80  va_list args;
81  int i;
82 
83  va_start ( args, fmt );
84  i = vw_printw ( win, fmt, args );
85  va_end ( args );
86  return i;
87 }
MuCurses header file.
#define va_end(ap)
Definition: stdarg.h:10
void(* handler)(struct printf_context *ctx, unsigned int c)
Character handler.
Definition: vsprintf.h:58
void _wputstr(WINDOW *win, const char *str, int wrap, int n) __nonnull
Write a standard c-style string to a window.
Definition: mucurses.c:122
Curses Window struct.
Definition: curses.h:90
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:36
struct printf_context ctx
Definition: print.c:43
attr_t attrs
window attributes
Definition: curses.h:94
WINDOW * win
Definition: print.c:44
void _wputch(WINDOW *win, chtype ch, int wrap) __nonnull
Write a single character rendition to a window.
Definition: mucurses.c:51
A printf context.
Definition: vsprintf.h:48
__builtin_va_list va_list
Definition: stdarg.h:7
int ssize_t const char * fmt
Definition: vsprintf.h:73
uint32_t chtype
Definition: curses.h:30
#define va_start(ap, last)
Definition: stdarg.h:8
#define WRAP
Definition: mucurses.h:13
size_t vcprintf(struct printf_context *ctx, const char *fmt, va_list args)
Write a formatted string to a printf context.
Definition: vsprintf.c:188