home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / cursesp.zip / PRNTSCAN.C < prev    next >
C/C++ Source or Header  |  1991-12-02  |  8KB  |  190 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 <stdio.h>
  27. #include <curses.h>
  28. #include <curspriv.h>
  29.  
  30. char _curses_prntscan_rcsid[] = "@(#)prntscan.c v1.3 - 881005";
  31.  
  32. static  int     pblen(void);            /* gets length of buffer */
  33. static  char    printscanbuf[513];      /* buffer used during I/O */
  34.  
  35. /****************************************************************/
  36. /* Wprintw(win,fmt,args) does a printf() in window 'win'.       */
  37. /****************************************************************/
  38.  
  39. int     wprintw(win,fmt,A1,A2,A3,A4,A5)
  40.   WINDOW        *win;
  41.   char          *fmt;
  42.   long  A1, A2, A3, A4, A5;
  43.   {
  44.   sprintf(printscanbuf,fmt,A1,A2,A3,A4,A5);
  45.   if (waddstr(win,printscanbuf) == ERR)
  46.     return(ERR);
  47.   return(pblen());
  48.   } /* wprintw */
  49.  
  50. /****************************************************************/
  51. /* Printw(fmt,args) does a printf() in stdscr.                  */
  52. /****************************************************************/
  53.  
  54. int     printw(fmt,A1,A2,A3,A4,A5)
  55.   char          *fmt;
  56.   double         A1,A2,A3,A4,A5;
  57.   {
  58.   sprintf(printscanbuf,fmt,A1,A2,A3,A4,A5);
  59.   if(waddstr(stdscr,printscanbuf) == ERR)
  60.     return(ERR);
  61.   return(pblen());
  62.   } /* printw */
  63.  
  64. /****************************************************************/
  65. /* Mvprintw(fmt,args) moves the stdscr cursor to a new posi-    */
  66. /* tion, then does a printf() in stdscr.                        */
  67. /****************************************************************/
  68.  
  69. int     mvprintw(y,x,fmt,A1,A2,A3,A4,A5)
  70.   int            y;
  71.   int            x;
  72.   char          *fmt;
  73.   double         A1,A2,A3,A4,A5;
  74.   {
  75.   if (wmove(stdscr,y,x) == ERR)
  76.     return(ERR);
  77.   sprintf(printscanbuf,fmt,A1,A2,A3,A4,A5);
  78.   if(waddstr(stdscr,printscanbuf) == ERR)
  79.     return(ERR);
  80.   return(pblen());
  81.   } /* mvprintw */
  82.  
  83. /****************************************************************/
  84. /* Mvwprintw(win,fmt,args) moves the window 'win's cursor to    */
  85. /* a new position, then does a printf() in window 'win'.        */
  86. /****************************************************************/
  87.  
  88. int     mvwprintw(win,y,x,fmt,A1,A2,A3,A4,A5)
  89.   WINDOW        *win;
  90.   int            y;
  91.   int            x;
  92.   char          *fmt;
  93.   double         A1,A2,A3,A4,A5;
  94.   {
  95.   if (wmove(win,y,x) == ERR)
  96.     return(ERR);
  97.   sprintf(printscanbuf,fmt,A1,A2,A3,A4,A5);
  98.   if(waddstr(win,printscanbuf) == ERR)
  99.     return(ERR);
  100.   return(pblen());
  101.   } /* mvwprintw */
  102.  
  103. /****************************************************************/
  104. /* Wscanw(win,fmt,args) gets a string via window 'win', then    */
  105. /* scans the string using format 'fmt' to extract the values    */
  106. /* and put them in the variables pointed to the arguments.      */
  107. /****************************************************************/
  108.  
  109. int wscanw(win,fmt,A1,A2,A3,A4,A5)
  110.   WINDOW        *win;
  111.   char          *fmt;
  112.   double         A1,A2,A3,A4,A5;                /* really pointers */
  113.   {
  114.   wrefresh(win);                                /* set cursor */
  115.   if (wgetstr(win,printscanbuf) == ERR)         /* get string */
  116.     return(ERR);
  117.   return(sscanf(printscanbuf,fmt,A1,A2,A3,A4,A5));
  118.   } /* wscanw */
  119.  
  120. /****************************************************************/
  121. /* Scanw(fmt,args) gets a string via stdscr, then scans the     */
  122. /* string using format 'fmt' to extract the values and put them */
  123. /* in the variables pointed to the arguments.                   */
  124. /****************************************************************/
  125.  
  126. int scanw(fmt,A1,A2,A3,A4,A5)
  127.   char          *fmt;
  128.   double         A1,A2,A3,A4,A5;                /* really pointers */
  129.   {
  130.   wrefresh(stdscr);                             /* set cursor */
  131.   if (wgetstr(stdscr,printscanbuf) == ERR)      /* get string */
  132.     return(ERR);
  133.   return(sscanf(printscanbuf,fmt,A1,A2,A3,A4,A5));
  134.   } /* scanw */
  135.  
  136. /****************************************************************/
  137. /* Mvscanw(y,x,fmt,args) moves stdscr's cursor to a new posi-   */
  138. /* tion, then gets a string via stdscr and scans the string     */
  139. /* using format 'fmt' to extract the values and put them in the */
  140. /* variables pointed to the arguments.                          */
  141. /****************************************************************/
  142.  
  143. int mvscanw(y,x,fmt,A1,A2,A3,A4,A5)
  144.   int            y;
  145.   int            x;
  146.   char          *fmt;
  147.   double         A1,A2,A3,A4,A5;                /* really pointers */
  148.   {
  149.   if (wmove(stdscr,y,x) == ERR)
  150.     return(ERR);
  151.   wrefresh(stdscr);                             /* set cursor */
  152.   if (wgetstr(stdscr,printscanbuf) == ERR)      /* get string */
  153.     return(ERR);
  154.   return(sscanf(printscanbuf,fmt,A1,A2,A3,A4,A5));
  155.   } /* mvscanw */
  156.  
  157. /****************************************************************/
  158. /* Mvwscanw(win,y,x,fmt,args) moves window 'win's cursor to a   */
  159. /* new position, then gets a string via 'win' and scans the     */
  160. /* string using format 'fmt' to extract the values and put them */
  161. /* in the variables pointed to the arguments.                   */
  162. /****************************************************************/
  163.  
  164. int mvwscanw(win,y,x,fmt,A1,A2,A3,A4,A5)
  165.   WINDOW        *win;
  166.   int            y;
  167.   int            x;
  168.   char          *fmt;
  169.   double         A1,A2,A3,A4,A5;                /* really pointers */
  170.   {
  171.   if (wmove(win,y,x) == ERR)
  172.     return(ERR);
  173.   wrefresh(win);                                /* set cursor */
  174.   if (wgetstr(win,printscanbuf) == ERR)         /* get string */
  175.     return(ERR);
  176.   return(sscanf(printscanbuf,fmt,A1,A2,A3,A4,A5));
  177.   } /* mvwscanw */
  178.  
  179. /****************************************************************/
  180. /* Pblen() returns the length of the string in printscanbuf.    */
  181. /****************************************************************/
  182.  
  183. static  int pblen()
  184.   {
  185.   char *p = printscanbuf;
  186.   
  187.   while(*p++);
  188.   return((int)(p-printscanbuf-1));
  189.   } /* plben */
  190.