iPXE
print.c
Go to the documentation of this file.
00001 #include <curses.h>
00002 #include <stdio.h>
00003 #include <stddef.h>
00004 #include <ipxe/vsprintf.h>
00005 #include "mucurses.h"
00006 
00007 /** @file
00008  *
00009  * MuCurses printing functions
00010  *
00011  */
00012 
00013 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00014 
00015 /**
00016  * Add a single-byte character and rendition to a window and advance
00017  * the cursor
00018  *
00019  * @v *win      window to be rendered in
00020  * @v ch        character to be added at cursor
00021  * @ret rc      return status code
00022  */
00023 int waddch ( WINDOW *win, const chtype ch ) {
00024         _wputch( win, ch, WRAP );
00025         return OK;
00026 }
00027 
00028 /**
00029  * Add string of single-byte characters to a window
00030  *
00031  * @v *win      window to be rendered in
00032  * @v *str      standard c-style string
00033  * @v n         max number of chars from string to render
00034  * @ret rc      return status code
00035  */
00036 int waddnstr ( WINDOW *win, const char *str, int n ) {
00037         _wputstr( win, str, WRAP, n );
00038         return OK;
00039 }
00040 
00041 struct printw_context {
00042         struct printf_context ctx;
00043         WINDOW *win;
00044 };
00045 
00046 static void _printw_handler ( struct printf_context *ctx, unsigned int c ) {
00047         struct printw_context *wctx =
00048                 container_of ( ctx, struct printw_context, ctx );
00049 
00050         _wputch( wctx->win, c | wctx->win->attrs, WRAP );
00051 }
00052 
00053 /**
00054  * Print formatted output in a window
00055  *
00056  * @v *win      subject window
00057  * @v *fmt      formatted string
00058  * @v varglist  argument list
00059  * @ret rc      return status code
00060  */
00061 int vw_printw ( WINDOW *win, const char *fmt, va_list varglist ) {
00062         struct printw_context wctx;
00063 
00064         wctx.win = win;
00065         wctx.ctx.handler = _printw_handler;
00066         vcprintf ( &(wctx.ctx), fmt, varglist );
00067         return OK;
00068 }
00069 
00070 /**
00071  * Print formatted output to a window
00072  *
00073  * @v *win      subject window
00074  * @v *fmt      formatted string
00075  * @v ...       string arguments
00076  * @ret rc      return status code
00077  */
00078 int wprintw ( WINDOW *win, const char *fmt, ... ) {
00079         va_list args;
00080         int i;
00081 
00082         va_start ( args, fmt );
00083         i = vw_printw ( win, fmt, args );
00084         va_end ( args );
00085         return i;
00086 }