home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CURSES.LZH / PRNTSCAN.C < prev    next >
C/C++ Source or Header  |  1980-01-01  |  7KB  |  189 lines

  1. /****************************************************************/
  2. /* Printw() and scanw() routines of the PCcurses package    */
  3. /*                                */
  4. /****************************************************************/
  5. /* This version of curses is based on ncurses, a curses version    */
  6. /* originally written by Pavel Curtis at Cornell University.    */
  7. /* I have made substantial changes to make it run on IBM PC's,    */
  8. /* and therefore consider myself free to make it public domain.    */
  9. /*        Bjorn Larsson (...mcvax!enea!infovax!bl)    */
  10. /****************************************************************/
  11. /*             IMPLEMENTATION NOTE            */
  12. /* These routines make a local copy of their parameter stack,    */
  13. /* assuming at most 5 'double' arguments were passed (== 40    */
  14. /* bytes == 20 int's == 10 long's == 10-20 pointers {depending    */
  15. /* on memory model}, etc). This means the invocation of the    */
  16. /* routines themselves requires at least 80 bytes of stack just    */
  17. /* for the parameters, and the sprintf() and sscanf() functions    */
  18. /* will require more. Therefore, this module should be compiled    */
  19. /* with stack checking on to avoid stack overflow errors.    */
  20. /****************************************************************/
  21. /* 1.0:    Release:                    870515    */
  22. /* 1.2:    Rcsid[] string for maintenance:            881002    */
  23. /* 1.3:    MSC -W3, Turbo'C' -w -w-pro checkes:        881005    */
  24. /****************************************************************/
  25.  
  26. #include <curses.h>
  27. #include <curspriv.h>
  28.  
  29. char _curses_prntscan_rcsid[] = "@(#)prntscan.c v1.3 - 881005";
  30.  
  31. static    int    pblen();        /* gets length of buffer */
  32. static    char    printscanbuf[513];    /* buffer used during I/O */
  33.  
  34. /****************************************************************/
  35. /* Wprintw(win,fmt,args) does a printf() in window 'win'.    */
  36. /****************************************************************/
  37.  
  38. int    wprintw(win,fmt,A1,A2,A3,A4,A5)
  39.   WINDOW    *win;
  40.   char        *fmt;
  41.   double     A1,A2,A3,A4,A5;
  42.   {
  43.   sprintf(printscanbuf,fmt,A1,A2,A3,A4,A5);
  44.   if (waddstr(win,printscanbuf) == ERR)
  45.     return(ERR);
  46.   return(pblen());
  47.   } /* wprintw */
  48.  
  49. /****************************************************************/
  50. /* Printw(fmt,args) does a printf() in stdscr.            */
  51. /****************************************************************/
  52.  
  53. int    printw(fmt,A1,A2,A3,A4,A5)
  54.   char        *fmt;
  55.   double     A1,A2,A3,A4,A5;
  56.   {
  57.   sprintf(printscanbuf,fmt,A1,A2,A3,A4,A5);
  58.   if(waddstr(stdscr,printscanbuf) == ERR)
  59.     return(ERR);
  60.   return(pblen());
  61.   } /* printw */
  62.  
  63. /****************************************************************/
  64. /* Mvprintw(fmt,args) moves the stdscr cursor to a new posi-    */
  65. /* tion, then does a printf() in stdscr.            */
  66. /****************************************************************/
  67.  
  68. int    mvprintw(y,x,fmt,A1,A2,A3,A4,A5)
  69.   int         y;
  70.   int         x;
  71.   char        *fmt;
  72.   double     A1,A2,A3,A4,A5;
  73.   {
  74.   if (wmove(stdscr,y,x) == ERR)
  75.     return(ERR);
  76.   sprintf(printscanbuf,fmt,A1,A2,A3,A4,A5);
  77.   if(waddstr(stdscr,printscanbuf) == ERR)
  78.     return(ERR);
  79.   return(pblen());
  80.   } /* mvprintw */
  81.  
  82. /****************************************************************/
  83. /* Mvwprintw(win,fmt,args) moves the window 'win's cursor to    */
  84. /* a new position, then does a printf() in window 'win'.    */
  85. /****************************************************************/
  86.  
  87. int    mvwprintw(win,y,x,fmt,A1,A2,A3,A4,A5)
  88.   WINDOW    *win;
  89.   int         y;
  90.   int         x;
  91.   char        *fmt;
  92.   double     A1,A2,A3,A4,A5;
  93.   {
  94.   if (wmove(win,y,x) == ERR)
  95.     return(ERR);
  96.   sprintf(printscanbuf,fmt,A1,A2,A3,A4,A5);
  97.   if(waddstr(win,printscanbuf) == ERR)
  98.     return(ERR);
  99.   return(pblen());
  100.   } /* mvwprintw */
  101.  
  102. /****************************************************************/
  103. /* Wscanw(win,fmt,args) gets a string via window 'win', then    */
  104. /* scans the string using format 'fmt' to extract the values    */
  105. /* and put them in the variables pointed to the arguments.    */
  106. /****************************************************************/
  107.  
  108. int wscanw(win,fmt,A1,A2,A3,A4,A5)
  109.   WINDOW    *win;
  110.   char        *fmt;
  111.   double     A1,A2,A3,A4,A5;        /* really pointers */
  112.   {
  113.   wrefresh(win);                /* set cursor */
  114.   if (wgetstr(win,printscanbuf) == ERR)        /* get string */
  115.     return(ERR);
  116.   return(sscanf(printscanbuf,fmt,A1,A2,A3,A4,A5));
  117.   } /* wscanw */
  118.  
  119. /****************************************************************/
  120. /* Scanw(fmt,args) gets a string via stdscr, then scans the    */
  121. /* string using format 'fmt' to extract the values and put them    */
  122. /* in the variables pointed to the arguments.            */
  123. /****************************************************************/
  124.  
  125. int scanw(fmt,A1,A2,A3,A4,A5)
  126.   char        *fmt;
  127.   double     A1,A2,A3,A4,A5;        /* really pointers */
  128.   {
  129.   wrefresh(stdscr);                /* set cursor */
  130.   if (wgetstr(stdscr,printscanbuf) == ERR)    /* get string */
  131.     return(ERR);
  132.   return(sscanf(printscanbuf,fmt,A1,A2,A3,A4,A5));
  133.   } /* scanw */
  134.  
  135. /****************************************************************/
  136. /* Mvscanw(y,x,fmt,args) moves stdscr's cursor to a new posi-    */
  137. /* tion, then gets a string via stdscr and scans the string    */
  138. /* using format 'fmt' to extract the values and put them in the    */
  139. /* variables pointed to the arguments.                */
  140. /****************************************************************/
  141.  
  142. int mvscanw(y,x,fmt,A1,A2,A3,A4,A5)
  143.   int         y;
  144.   int         x;
  145.   char        *fmt;
  146.   double     A1,A2,A3,A4,A5;        /* really pointers */
  147.   {
  148.   if (wmove(stdscr,y,x) == ERR)
  149.     return(ERR);
  150.   wrefresh(stdscr);                /* set cursor */
  151.   if (wgetstr(stdscr,printscanbuf) == ERR)    /* get string */
  152.     return(ERR);
  153.   return(sscanf(printscanbuf,fmt,A1,A2,A3,A4,A5));
  154.   } /* mvscanw */
  155.  
  156. /****************************************************************/
  157. /* Mvwscanw(win,y,x,fmt,args) moves window 'win's cursor to a    */
  158. /* new position, then gets a string via 'win' and scans the    */
  159. /* string using format 'fmt' to extract the values and put them    */
  160. /* in the variables pointed to the arguments.            */
  161. /****************************************************************/
  162.  
  163. int mvwscanw(win,y,x,fmt,A1,A2,A3,A4,A5)
  164.   WINDOW    *win;
  165.   int         y;
  166.   int         x;
  167.   char        *fmt;
  168.   double     A1,A2,A3,A4,A5;        /* really pointers */
  169.   {
  170.   if (wmove(win,y,x) == ERR)
  171.     return(ERR);
  172.   wrefresh(win);                /* set cursor */
  173.   if (wgetstr(win,printscanbuf) == ERR)        /* get string */
  174.     return(ERR);
  175.   return(sscanf(printscanbuf,fmt,A1,A2,A3,A4,A5));
  176.   } /* mvwscanw */
  177.  
  178. /****************************************************************/
  179. /* Pblen() returns the length of the string in printscanbuf.    */
  180. /****************************************************************/
  181.  
  182. static    int pblen()
  183.   {
  184.   char *p = printscanbuf;
  185.   
  186.   while(*p++);
  187.   return(p-printscanbuf-1);
  188.   } /* plben */
  189.