home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / cursesp.zip / CHARINS.C < prev    next >
C/C++ Source or Header  |  1991-12-02  |  6KB  |  174 lines

  1. /****************************************************************/
  2. /* Winsch() routine 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. /* 1.0: Release:                                        870515  */
  12. /* 1.1: Added 'raw' output routines (allows PC charac-          */
  13. /*      ters < 0x20 to be displayed:                    880306  */
  14. /* 1.2: Max limits off by 1. Fixed thanks to S. Creps:  881002  */
  15. /* 1.3: MSC -W3, Turbo'C' -w -w-pro checkes:            881005  */
  16. /****************************************************************/
  17.  
  18. #include <curses.h>
  19. #include <curspriv.h>
  20.  
  21. char _curses_charins_rcsid[] = "@(#)charins.c v1.3 - 881005";
  22.  
  23. /****************************************************************/
  24. /* _Chins() inserts character 'c' at the cursor position in     */
  25. /* window 'win'. If xlat is true, normal character translation  */
  26. /* is performed; If xlat is false, the character is output 'as  */
  27. /* is'.                                                         */
  28. /****************************************************************/
  29.  
  30. static  int     _chins(WINDOW*, int, int);
  31.  
  32. static  int     _chins(win,c,xlat)
  33.   WINDOW        *win;
  34.   char           c;
  35.   bool           xlat;
  36.   {
  37.   int           *temp1;
  38.   int           *temp2;
  39.   int           *end;
  40.   int            x = win->_curx;
  41.   int            y = win->_cury;
  42.   int            maxx = win->_maxx - 1;
  43.  
  44.   if((c < ' ') && (c == '\n' || c == '\r' || c == '\t' || c == '\b'))
  45.     return(_chadd(win,c,xlat));
  46.   end = &win->_line[y][x];
  47.   temp1 = &win->_line[y][maxx];
  48.   temp2 = temp1 - 1;
  49.   if((c < ' ') && xlat)                 /* if CTRL-char make space for 2 */
  50.     temp2--;
  51.   while (temp1 > end)
  52.     *temp1-- = *temp2--;
  53.   win->_maxchng[y] = maxx;
  54.   if ((win->_minchng[y] == _NO_CHANGE) || (win->_minchng[y] > x))
  55.     win->_minchng[y] = x;
  56.   return(_chadd(win,c,xlat));           /* fixes CTRL-chars too */
  57.   } /* _chins */
  58.  
  59. /****************************************************************/
  60. /* Insch() inserts character 'c' at the cursor position in      */
  61. /* stdscr. The cursor is advanced.                              */
  62. /****************************************************************/
  63.  
  64. int insch(c)
  65.   char c;
  66.   {
  67.   return(_chins(stdscr,c,TRUE));
  68.   } /* insch */
  69.  
  70. /****************************************************************/
  71. /* Winsch() inserts character 'c' at the cursor position in     */
  72. /* window 'win'. The cursor is advanced.                        */
  73. /****************************************************************/
  74.  
  75. int winsch(win,c)
  76.   WINDOW *win;
  77.   char c;
  78.   {
  79.   return(_chins(win,c,TRUE));
  80.   } /* winsch */
  81.  
  82. /****************************************************************/
  83. /* Mvinsch() moves the stdscr cursor to a new position, then    */
  84. /* inserts character 'c' at the cursor position in stdscr. The  */
  85. /* cursor is advanced.                                          */
  86. /****************************************************************/
  87.  
  88. int mvinsch(y,x,c)
  89.   int  y;
  90.   int  x;
  91.   char c;
  92.   {
  93.   if (wmove(stdscr,y,x) == ERR)
  94.     return(ERR);
  95.   return(_chins(stdscr,c,TRUE));
  96.   } /* mvinsch */
  97.  
  98. /****************************************************************/
  99. /* Mvwinsch() moves the cursor of window 'win' to a new posi-   */
  100. /* tion, then inserts character 'c' at the cursor position in   */
  101. /* window 'win'. The cursor is advanced.                        */
  102. /****************************************************************/
  103.  
  104. int mvwinsch(win,y,x,c)
  105.   WINDOW *win;
  106.   int  y;
  107.   int  x;
  108.   char c;
  109.   {
  110.   if (wmove(win,y,x) == ERR)
  111.     return(ERR);
  112.   return(_chins(win,c,TRUE));
  113.   } /* mvwinsch */
  114.  
  115. /****************************************************************/
  116. /* Insrawch() inserts character 'c' at the cursor position in   */
  117. /* stdscr. Control characters are not interpreted, and the      */
  118. /* cursor is advanced.                                          */
  119. /****************************************************************/
  120.  
  121. int insrawch(c)
  122.   char c;
  123.   {
  124.   return(_chins(stdscr,c,FALSE));
  125.   } /* insrawch */
  126.  
  127. /****************************************************************/
  128. /* Winsrawch() inserts character 'c' at the cursor position in  */
  129. /* window 'win'. Control characters are not interpreted, and    */
  130. /* the cursor is advanced.                                      */
  131. /****************************************************************/
  132.  
  133. int winsrawch(win,c)
  134.   WINDOW *win;
  135.   char c;
  136.   {
  137.   return(_chins(win,c,FALSE));
  138.   } /* winsrawch */
  139.  
  140. /****************************************************************/
  141. /* Mvinsrawch() moves the stdscr cursor to a new position, then */
  142. /* inserts character 'c' at the cursor position in stdscr.      */
  143. /* Control characters are not interpreted, and  the cursor is   */
  144. /* advanced.                                                    */
  145. /****************************************************************/
  146.  
  147. int mvinsrawch(y,x,c)
  148.   int  y;
  149.   int  x;
  150.   char c;
  151.   {
  152.   if (wmove(stdscr,y,x) == ERR)
  153.     return(ERR);
  154.   return(_chins(stdscr,c,FALSE));
  155.   } /* mvinsrawch */
  156.  
  157. /****************************************************************/
  158. /* Mvwinsrawch() moves the cursor of window 'win' to a new      */
  159. /* position, then inserts character 'c' at the cursor position  */
  160. /* in window 'win'. Control characters are not interpreted, and */
  161. /* the cursor is advanced.                                      */
  162. /****************************************************************/
  163.  
  164. int mvwinsrawch(win,y,x,c)
  165.   WINDOW *win;
  166.   int  y;
  167.   int  x;
  168.   char c;
  169.   {
  170.   if (wmove(win,y,x) == ERR)
  171.     return(ERR);
  172.   return(_chins(win,c,FALSE));
  173.   } /* mvwinsrawch */
  174.