1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-07-21 16:14:14 -04:00

Add the attrpr() function; add a missing va_end() call in center()

The attrpr() function prints a string with a particular set of Curses
attributes.
This commit is contained in:
John Zaitseff 2011-07-04 19:41:55 +10:00
parent ca64093a07
commit 568c3738b2
2 changed files with 50 additions and 7 deletions

View File

@ -153,8 +153,8 @@ void end_screen (void)
WINDOW *newtxwin (int nlines, int ncols, int begin_y, int begin_x) WINDOW *newtxwin (int nlines, int ncols, int begin_y, int begin_x)
{ {
WINDOW *win; WINDOW *win;
txwin_t *nw; txwin_t *nw;
win = newwin(nlines, ncols, begin_y, begin_x); win = newwin(nlines, ncols, begin_y, begin_x);
@ -201,8 +201,8 @@ WINDOW *newtxwin (int nlines, int ncols, int begin_y, int begin_x)
int deltxwin (void) int deltxwin (void)
{ {
txwin_t *cur, *prev; txwin_t *cur, *prev;
int r; int ret;
if (topwin == NULL) { if (topwin == NULL) {
@ -221,10 +221,10 @@ int deltxwin (void)
curwin = stdscr; curwin = stdscr;
} }
r = delwin(cur->win); ret = delwin(cur->win);
free(cur); free(cur);
return r; return ret;
} }
@ -264,6 +264,7 @@ int txrefresh (void)
{ {
txwin_t *p; txwin_t *p;
touchwin(stdscr); touchwin(stdscr);
wnoutrefresh(stdscr); wnoutrefresh(stdscr);
@ -301,13 +302,17 @@ int center (WINDOW *win, int y, const bool clrline, const char *format, ...)
int maxy, maxx; int maxy, maxx;
int fill; int fill;
char *buf = malloc(OUTBUFSIZE); char *buf;
buf = malloc(OUTBUFSIZE);
if (buf == NULL) { if (buf == NULL) {
err_exit("out of memory"); err_exit("out of memory");
} }
va_start(args, format); va_start(args, format);
len = vsnprintf(buf, OUTBUFSIZE, format, args); len = vsnprintf(buf, OUTBUFSIZE, format, args);
va_end(args);
if (len < 0) { if (len < 0) {
return ERR; return ERR;
} }
@ -334,3 +339,34 @@ int center (WINDOW *win, int y, const bool clrline, const char *format, ...)
free(buf); free(buf);
return ret; return ret;
} }
/*-----------------------------------------------------------------------
Function: attrpr - Print a string with special attributes
Arguments: win - Window to use
attr_start - Attribute to set at the start of wprintw()
attr_end - Attribute to set at the end of wprintw()
format - printf()-like format string
... - printf()-like arguments
Returns: int - Return code from wprintw()
This function sets the window attribute to attr_start, then prints the
given string (using wprintw()), then sets the attribute to attr_end.
*/
int attrpr (WINDOW *win, int attr_start, int attr_end, const char *format, ...)
{
va_list args;
int ret;
wattrset(win, attr_start);
va_start(args, format);
ret = vwprintw(win, format, args);
va_end(args);
wattrset(win, attr_end);
return ret;
}

View File

@ -94,14 +94,21 @@ extern void init_screen (void);
extern void end_screen (void); extern void end_screen (void);
// Simplified panel-like window functions // Simplified panel-like window functions
extern WINDOW *newtxwin (int nlines, int ncols, int begin_y, int begin_x); extern WINDOW *newtxwin (int nlines, int ncols, int begin_y, int begin_x);
extern int deltxwin (void); extern int deltxwin (void);
extern int delalltxwin (void); extern int delalltxwin (void);
extern int txrefresh (void); extern int txrefresh (void);
// Output routines
extern int center (WINDOW *win, int y, const bool clrline, extern int center (WINDOW *win, int y, const bool clrline,
const char *format, ...) const char *format, ...)
__attribute__((format (printf, 4, 5))); __attribute__((format (printf, 4, 5)));
extern int attrpr (WINDOW *win, int attr_start, int attr_end,
const char *format, ...)
__attribute__((format (printf, 4, 5)));
#endif /* included_INTF_H */ #endif /* included_INTF_H */