home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume2 / window / part4 / printw.c.new < prev    next >
Encoding:
Text File  |  1986-11-30  |  1.8 KB  |  86 lines

  1. /*
  2.  * printw and friends
  3.  *
  4.  * 1/26/81 (Berkeley) @(#)printw.c    1.1
  5.  */
  6.  
  7. # include    "curses.ext"
  8.  
  9. /*
  10.  *    This routine implements a printf on the standard screen.
  11.  *    
  12.  *    Modified by David Owen, U.C.S.D. 10.5.83 to allow arbitrary
  13.  *    length strings to "printw". In "sprintw" the error status is 
  14.  *    checked on return from the "doprnt" and if set, the
  15.  *    call is repeated with a bigger buffer.
  16.  */
  17. printw(fmt, args)
  18. char    *fmt;
  19. int    args; {
  20.  
  21.     return _sprintw(stdscr, fmt, &args);
  22. }
  23.  
  24. /*
  25.  *    This routine implements a printf on the given window.
  26.  */
  27. wprintw(win, fmt, args)
  28. WINDOW    *win;
  29. char    *fmt;
  30. int    args; {
  31.  
  32.     return _sprintw(win, fmt, &args);
  33. }
  34. /*
  35.  *    This routine actually executes the printf and adds it to the window
  36.  *
  37.  *    This is really a modified version of "sprintf".  As such,
  38.  * it assumes that sprintf interfaces with the other printf functions
  39.  * in a certain way.  If this is not how your system works, you
  40.  * will have to modify this routine to use the interface that your
  41.  * "sprintf" uses.
  42.  */
  43. _sprintw(win, fmt, args)
  44. WINDOW    *win;
  45. char    *fmt;
  46. int    *args; {
  47.  
  48.     FILE    junk;
  49.     char    buf[BUFSIZ],*bptr;
  50.     int count,res;
  51.     count = 0;
  52.  
  53.     junk._flag = _IOWRT + _IOSTRG;
  54.     junk._ptr = buf;
  55.     junk._base = buf;
  56.     junk._cnt = BUFSIZ;
  57. /*Make sure error flag set if ever "flsbuf" is called*/
  58.     junk._file = -1;
  59.     for(;;){
  60.         _doprnt(fmt, args, &junk);
  61.         putc('\0', &junk);
  62. /*If there was a write error increase buffer and try again*/
  63.         if(junk._flag & _IOERR){
  64.             if(count) 
  65.                 free(bptr);
  66.             else
  67.                 count = BUFSIZ;
  68.             count += BUFSIZ;
  69.             if((bptr = (char *)malloc(count)) == NULL){
  70.                 fprintf(stderr,"sprintw:no malloc space\n");
  71.                 return(-1);
  72.             }
  73.             junk._flag = _IOWRT + _IOSTRG;
  74.             junk._ptr = bptr;
  75.             junk._base = bptr;
  76.             junk._cnt = count;
  77.             junk._file = -1;
  78.             continue;
  79.         }
  80.         res = waddstr(win,junk._base);
  81.         if(count) free(bptr);
  82.         return(res);
  83.     }
  84. }
  85.  
  86.