home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CURS13_2.ZIP / CHARINS.C < prev    next >
Text File  |  1989-12-08  |  6KB  |  172 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(win,c,xlat)
  31.   WINDOW    *win;
  32.   char         c;
  33.   bool         xlat;
  34.   {
  35.   int        *temp1;
  36.   int        *temp2;
  37.   int        *end;
  38.   int         x = win->_curx;
  39.   int         y = win->_cury;
  40.   int         maxx = win->_maxx - 1;
  41.  
  42.   if((c < ' ') && (c == '\n' || c == '\r' || c == '\t' || c == '\b'))
  43.     return(_chadd(win,c,xlat));
  44.   end = &win->_line[y][x];
  45.   temp1 = &win->_line[y][maxx];
  46.   temp2 = temp1 - 1;
  47.   if((c < ' ') && xlat)            /* if CTRL-char make space for 2 */
  48.     temp2--;
  49.   while (temp1 > end)
  50.     *temp1-- = *temp2--;
  51.   win->_maxchng[y] = maxx;
  52.   if ((win->_minchng[y] == _NO_CHANGE) || (win->_minchng[y] > x))
  53.     win->_minchng[y] = x;
  54.   return(_chadd(win,c,xlat));        /* fixes CTRL-chars too */
  55.   } /* _chins */
  56.  
  57. /****************************************************************/
  58. /* Insch() inserts character 'c' at the cursor position in    */
  59. /* stdscr. The cursor is advanced.                */
  60. /****************************************************************/
  61.  
  62. int insch(c)
  63.   char c;
  64.   {
  65.   return(_chins(stdscr,c,TRUE));
  66.   } /* insch */
  67.  
  68. /****************************************************************/
  69. /* Winsch() inserts character 'c' at the cursor position in    */
  70. /* window 'win'. The cursor is advanced.            */
  71. /****************************************************************/
  72.  
  73. int winsch(win,c)
  74.   WINDOW *win;
  75.   char c;
  76.   {
  77.   return(_chins(win,c,TRUE));
  78.   } /* winsch */
  79.  
  80. /****************************************************************/
  81. /* Mvinsch() moves the stdscr cursor to a new position, then    */
  82. /* inserts character 'c' at the cursor position in stdscr. The    */
  83. /* cursor is advanced.                        */
  84. /****************************************************************/
  85.  
  86. int mvinsch(y,x,c)
  87.   int  y;
  88.   int  x;
  89.   char c;
  90.   {
  91.   if (wmove(stdscr,y,x) == ERR)
  92.     return(ERR);
  93.   return(_chins(stdscr,c,TRUE));
  94.   } /* mvinsch */
  95.  
  96. /****************************************************************/
  97. /* Mvwinsch() moves the cursor of window 'win' to a new posi-    */
  98. /* tion, then inserts character 'c' at the cursor position in    */
  99. /* window 'win'. The cursor is advanced.            */
  100. /****************************************************************/
  101.  
  102. int mvwinsch(win,y,x,c)
  103.   WINDOW *win;
  104.   int  y;
  105.   int  x;
  106.   char c;
  107.   {
  108.   if (wmove(win,y,x) == ERR)
  109.     return(ERR);
  110.   return(_chins(win,c,TRUE));
  111.   } /* mvwinsch */
  112.  
  113. /****************************************************************/
  114. /* Insrawch() inserts character 'c' at the cursor position in    */
  115. /* stdscr. Control characters are not interpreted, and the    */
  116. /* cursor is advanced.                        */
  117. /****************************************************************/
  118.  
  119. int insrawch(c)
  120.   char c;
  121.   {
  122.   return(_chins(stdscr,c,FALSE));
  123.   } /* insrawch */
  124.  
  125. /****************************************************************/
  126. /* Winsrawch() inserts character 'c' at the cursor position in    */
  127. /* window 'win'. Control characters are not interpreted, and    */
  128. /* the cursor is advanced.                    */
  129. /****************************************************************/
  130.  
  131. int winsrawch(win,c)
  132.   WINDOW *win;
  133.   char c;
  134.   {
  135.   return(_chins(win,c,FALSE));
  136.   } /* winsrawch */
  137.  
  138. /****************************************************************/
  139. /* Mvinsrawch() moves the stdscr cursor to a new position, then    */
  140. /* inserts character 'c' at the cursor position in stdscr.    */
  141. /* Control characters are not interpreted, and    the cursor is    */
  142. /* advanced.                            */
  143. /****************************************************************/
  144.  
  145. int mvinsrawch(y,x,c)
  146.   int  y;
  147.   int  x;
  148.   char c;
  149.   {
  150.   if (wmove(stdscr,y,x) == ERR)
  151.     return(ERR);
  152.   return(_chins(stdscr,c,FALSE));
  153.   } /* mvinsrawch */
  154.  
  155. /****************************************************************/
  156. /* Mvwinsrawch() moves the cursor of window 'win' to a new    */
  157. /* position, then inserts character 'c' at the cursor position    */
  158. /* in window 'win'. Control characters are not interpreted, and    */
  159. /* the cursor is advanced.                    */
  160. /****************************************************************/
  161.  
  162. int mvwinsrawch(win,y,x,c)
  163.   WINDOW *win;
  164.   int  y;
  165.   int  x;
  166.   char c;
  167.   {
  168.   if (wmove(win,y,x) == ERR)
  169.     return(ERR);
  170.   return(_chins(win,c,FALSE));
  171.   } /* mvwinsrawch */
  172.