home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_02 / wputc.c < prev    next >
C/C++ Source or Header  |  1991-03-17  |  3KB  |  171 lines

  1. /*! wputc
  2.  *
  3.  *
  4.  *   put a char to video at the current cursor position
  5.  *   uses wputstyle to control output.
  6.  *
  7.  */
  8.  
  9. #include  "wscreen.h"
  10. #include  "wsys.h"
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. /* reduce ugliness of code */
  18. #define style   (w0->winputstyle)
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. int wputc (char c)
  26.     {
  27.  
  28.     int domore = 1;    /* set to 0 if fill window prematurely */
  29.  
  30.     char ansi_char;
  31.  
  32.  
  33.     if (style & WPUTANSI)
  34.         {
  35.         ansi_char = c;
  36.         }
  37.     else    {
  38.         ansi_char = 0;
  39.         }
  40.  
  41.  
  42.  
  43.     switch(ansi_char)
  44.     {
  45.     case('\a'):   /*ring bell*/
  46.         break;
  47.     case('\b'):     /* backspace */
  48.         if (--(w0-> winx) <0 )
  49.             if (w0-> winy >0) {
  50.                 /* go to last column, prior line
  51.                  */
  52.                 w0-> winx =  w0->winxmax;
  53.                 --(w0-> winy);
  54.                 }
  55.             else    /*ignore illegal backspace */
  56.                 w0-> winx = 0;
  57.         break;
  58.     case('\f'):   /*formfeed = clear page */
  59.         wclear();
  60.         break;
  61.     case('\n'):   /*new line*/
  62.         /* for new lines,
  63.          * need to scroll if at bottom of window and putstyle=scroll
  64.          * need to linefeed if putstyle = n2rn ( ie: /n ===> /r/n)
  65.          */
  66.         if (    w0-> winy == w0->winymax )
  67.             {
  68.             if (style & WPUTSCROLL )
  69.                 {
  70.                 wscroll();
  71.                 }
  72.             else     {
  73.                 domore =0;
  74.                 }
  75.             }
  76.         else    {
  77.             ++(w0-> winy);
  78.             if ( style & WPUTN2RN )
  79.                 {
  80.                 /* want to line feed after \n */
  81.                 (w0-> winx) =0;
  82.                 }
  83.             }
  84.         break;
  85.     case('\r'):    /*carriage return*/
  86.         (w0-> winx) = 0;
  87.         break;
  88.     case('\t'):    /*tab*/
  89.         w0-> winx = wtabwidth* (1+ (w0-> winx)/wtabwidth) ;
  90.         if (w0-> winx > w0-> winxmax )
  91.             {
  92.             w0-> winx = 0;
  93.             }
  94.         break;
  95.     case('\v'):    /* vertical tab*/
  96.         if (w0-> winy < w0-> winymax)
  97.             {
  98.             ++(w0-> winy);
  99.             }
  100.         else
  101.             {
  102.             /* at last line of window */
  103.             if (style & WPUTSCROLL )
  104.                 {
  105.                 wscroll();
  106.                 }
  107.             else    {
  108.                 domore =0;
  109.                 }
  110.             }
  111.         break;
  112.     default:
  113.         /* printable character
  114.          */
  115.         wputcabs ( w0->winleft + w0->winx,
  116.                    w0->wintop  + w0->winy,
  117.                    c, w0-> winattr,
  118.                    WGOVERWRITE );
  119.  
  120.  
  121.         if (++(w0->winx) > w0->winxmax )
  122.             {
  123.             /* move to first char of next line
  124.              */
  125.             w0-> winx = 0;
  126.             if ( ++(w0-> winy) > w0->winymax )
  127.                 {
  128.                 /* gone past last line
  129.                  * move up to last line again.
  130.                  */
  131.  
  132.                 --(w0->winy);
  133.  
  134.                 if ( style & WPUTSCROLL )
  135.                     {
  136.                     wscroll();
  137.                     }
  138.                 else    {
  139.                     /* no scrolling requested -
  140.                      */
  141.                     domore =0;
  142.                     }
  143.                 }
  144.  
  145.             if ( ! ( style & WPUTWRAP ) )
  146.                 {
  147.                 /* crossed right edge of window,
  148.                  * but user doesn't want to wrap around
  149.                  */
  150.                 domore =0;
  151.                 w0->winx = w0->winxmax;
  152.                 }
  153.             }
  154.     }  /* end switch on *s for putting single char */
  155.  
  156.  
  157.  
  158.  
  159.     /* move cursor and calculate new screen buffer ptrs
  160.      */
  161.     wgoto (w0->winx, w0->winy);
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.     return (domore);
  169.     }
  170.  
  171. /*-------------------- END WPUTC ------------------------*/