home *** CD-ROM | disk | FTP | other *** search
- /*
- * printw and friends
- *
- * 1/26/81 (Berkeley) @(#)printw.c 1.1
- */
-
- # include "curses.ext"
-
- /*
- * This routine implements a printf on the standard screen.
- *
- * Modified by David Owen, U.C.S.D. 10.5.83 to allow arbitrary
- * length strings to "printw". In "sprintw" the error status is
- * checked on return from the "doprnt" and if set, the
- * call is repeated with a bigger buffer.
- */
- printw(fmt, args)
- char *fmt;
- int args; {
-
- return _sprintw(stdscr, fmt, &args);
- }
-
- /*
- * This routine implements a printf on the given window.
- */
- wprintw(win, fmt, args)
- WINDOW *win;
- char *fmt;
- int args; {
-
- return _sprintw(win, fmt, &args);
- }
- /*
- * This routine actually executes the printf and adds it to the window
- *
- * This is really a modified version of "sprintf". As such,
- * it assumes that sprintf interfaces with the other printf functions
- * in a certain way. If this is not how your system works, you
- * will have to modify this routine to use the interface that your
- * "sprintf" uses.
- */
- _sprintw(win, fmt, args)
- WINDOW *win;
- char *fmt;
- int *args; {
-
- FILE junk;
- char buf[BUFSIZ],*bptr;
- int count,res;
- count = 0;
-
- junk._flag = _IOWRT + _IOSTRG;
- junk._ptr = buf;
- junk._base = buf;
- junk._cnt = BUFSIZ;
- /*Make sure error flag set if ever "flsbuf" is called*/
- junk._file = -1;
- for(;;){
- _doprnt(fmt, args, &junk);
- putc('\0', &junk);
- /*If there was a write error increase buffer and try again*/
- if(junk._flag & _IOERR){
- if(count)
- free(bptr);
- else
- count = BUFSIZ;
- count += BUFSIZ;
- if((bptr = (char *)malloc(count)) == NULL){
- fprintf(stderr,"sprintw:no malloc space\n");
- return(-1);
- }
- junk._flag = _IOWRT + _IOSTRG;
- junk._ptr = bptr;
- junk._base = bptr;
- junk._cnt = count;
- junk._file = -1;
- continue;
- }
- res = waddstr(win,junk._base);
- if(count) free(bptr);
- return(res);
- }
- }
-
-