home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / s / s001 / 1.ddi / PFC / SRC / _VDSPC.C next >
Encoding:
C/C++ Source or Header  |  1990-04-04  |  7.7 KB  |  268 lines

  1. /* (c) 1985, Phoenix Computer Products Corp. and Novum Organum, Inc. */
  2. #include "pdefs.h"
  3. #include "psys.h"
  4.  
  5. #define    VS_ATRCHR    '^'
  6. #define    TABSIZ        8
  7.  
  8. static    int    _row, _col;    /* screen position */
  9. static    int    _nchars;    /* max # of chars to use from string */
  10. static    int    _smode, _cmode;    /* _dsp mode constants */
  11. static    int    _oldstate;    /* place to save the attribute state */
  12. static    int    _attr = 0x07;    /* IBM-PC attribute */
  13. static    int    _srchchr;    /* CRET if VA_TTY is on, EOS otherwise */
  14.                 /*    to control scanning for TTY chars  */
  15.  
  16.         int _vdsp();
  17. static  PFI _dsp = _vdsp;  /* video display function */
  18.  
  19.  
  20. /* These two little routines just save and return the IBM-PC attribute */
  21.  
  22. _vdspsattr( ibmattr )
  23.     _attr = ibmattr; 
  24. }
  25.  
  26. int    _vdspattr()
  27.     return( _attr ); 
  28. }
  29.  
  30. /* This internal routine handles the attribute control sequences within    *
  31. *  strings.  Other pieces of the string are passed through to _vdspstty    *
  32. *  later in this file.                            */
  33.  
  34.  
  35.  
  36. _vdsps( int row, int col, int nchars, int astate, char *str, void **pargs )
  37. {
  38.     int    chr, offset;
  39.     char    *strnfmtp();
  40.     char    _fmtbuf[256];
  41.  
  42.     _setargs( row, col, nchars, astate );    /* set static variables */
  43.  
  44.     if    ((!(vstattr() & VA_PCT)) && (stridxc('%',str) != NOTFND))
  45.     {
  46. //          str = strnfmtp(_fmtbuf,sizeof(_fmtbuf),str,(int *)pargs);
  47.           vsprintf(_fmtbuf, str, pargs);
  48.           str = _fmtbuf;
  49.     }
  50.     if    (!(vstattr() & VA_CARET)) /* if the attribute stuff is on */
  51.         {            /* look for attribute control stuff */
  52.         while    ( (offset = stridxc(VS_ATRCHR,str)) != NOTFND )
  53.             {
  54.             _vdspstty(offset,str);    /* do display up to stuff */
  55.             str += offset + 1;
  56.  
  57.             chr = *str++;
  58.             switch    ( TOUPPER(chr) )/* check out the control char*/
  59.                 {
  60.             case EOS: goto end;    /* EndOfString -- all done */
  61.             case 'B': vsttogattr(VA_BLINK); break;
  62.             case 'H': vsttogattr(VA_HIINTY); break;
  63.             case 'R': vsttogattr(VA_REVVID); break;
  64.             case 'U': vsttogattr(VA_ULN); break;
  65.             default : str--; break;
  66.             case VS_ATRCHR:
  67.                   _vdspctty(1,VS_ATRCHR); /* display '^' */
  68.                   break;
  69.                 }
  70.  
  71.             }
  72.         }
  73.     _vdspstty( _nchars, str );    /* do the part of the string after  */
  74.                     /* the last control sequence or the */
  75.                     /* whole string if the control      */
  76.                     /* sequence jazz is turned off      */
  77. end:    
  78.     if    ((nchars < VD_ALLOFIT) && (_nchars > 0))
  79.         {
  80.         chr = BLNK;
  81.         (*_dsp) ( _cmode, _row, _col, _nchars, &chr, _attr );
  82.         }
  83.  
  84.     if    ( _oldstate != VD_CURSTAT ) /* if the state was changed */
  85.         vstsetcur( _oldstate );        /* change it back */
  86. }
  87.  
  88. /* This internal routine handles the pieces of a string which have already  *
  89. *  been scanned for attribute control sequences.  It handles TTY characters *
  90. *  by calling _vdspctty, which appears later in this file, and the normal   *
  91. *  parts of the string with _dsp, which is a separate assembler routine.    */
  92.  
  93. static    _vdspstty( nchars, str )
  94.     int    nchars;
  95.     char    *str;
  96. {
  97.     int    offset;
  98.  
  99.     while    ( _nchars > 0  )
  100.         {
  101.         offset = stridxle( _srchchr, str );    /* look for TTY char */
  102.  
  103.         if    ( offset > 0 )        /* do STR up to the TTY char */
  104.             {
  105.             /* limit the number of characters to write */
  106.             if    ( offset > nchars )
  107.                 offset = nchars;
  108.             if    ( offset > _nchars )
  109.                 offset = _nchars;
  110.  
  111.         /* the normal part of a string gets displayed right here */
  112.             (*_dsp) (_smode, _row, _col, offset, str, _attr);
  113.             str += offset;
  114.             nchars -= offset;
  115.             _nchars -= offset;
  116.             _col += offset;
  117.             }
  118.         /* EOS comes up as a TTY char since it's less than CRET */
  119.         /* if we've reached the EOS, just quit */
  120.         if    ( *str == EOS || nchars <= 0 ) 
  121.             break;
  122.  
  123.         _vdspctty( 1, *str++ );        /* do the TTY char */
  124.         nchars--;
  125.         }
  126. }
  127.  
  128. /* A little internal routine to handle the attribute changing functions. *
  129. *  Packages the call for handling by _dsp, an assembly language routine. */
  130.  
  131. _vdspa ( row, col, nchars, astate )
  132.     int    row, col, nchars, astate;
  133. {
  134.     _setargs( row, col, nchars, astate );    /* set up statics */
  135.  
  136.     (*_dsp) ( VD_0C1A, _row, _col, _nchars, NULLPTR, _attr ); /* do it */
  137.  
  138.     if    ( _oldstate != VD_CURSTAT )    /* if state was changed */
  139.         vstsetcur( _oldstate );        /* restore it */
  140. }
  141.  
  142.  
  143.  
  144. /* This routine packages up the character display functions for either    *
  145. *  _vdspctty, which is later in this file, or _dsp, a separate assembly *
  146. *  language function elsewhere.                      */
  147.  
  148. _vdspc ( row, col, nchars, astate, chr )
  149.     int    row, col, nchars, chr, astate;
  150. {
  151.     _setargs( row, col, nchars, astate );    /* set up static variables */
  152.  
  153.     if    ( chr <= _srchchr )        /* if a possible TTY-char */
  154.         {
  155.         if    (chr == TAB)
  156.             _nchars = TABSIZ;
  157.         _vdspctty( _nchars, chr );    /* display TTY char */
  158.         }
  159.     else
  160.                         /* normal character display */
  161.         (*_dsp) ( _cmode, _row, _col, _nchars, &chr, _attr );
  162.  
  163.     if    ( _oldstate != VD_CURSTAT )    /* if attribute state altered*/
  164.         vstsetcur( _oldstate );        /* change it back */
  165. }
  166.  
  167.  
  168. /* Internal routine to handle TTY characters for the string and character *
  169. *  display functions.  BKSP, TAB, LNFEED, and CRET characters cause cursor*
  170. *  control, BELL calls sybeep().                      */
  171.  
  172. static    _vdspctty( nchars, chr )
  173.     int    nchars, chr;
  174. {
  175.     int    nrows;
  176.  
  177.     if    ( _nchars <= 0 ) return;
  178.  
  179.     switch    ( chr )
  180.         {
  181.     case BELL:            /* ASCII 7 or CTRL-G */
  182.         while    ( nchars-- )
  183.             sybeep();        /* make noise */
  184.         break;
  185.     case BKSP:            /* ASCII 8 or CTRL-H */
  186.         _col -= nchars;            /* back up cursor */
  187.         if    ( _col < 0 )        /* but not too far */
  188.             _col = 0;
  189.         vidsetloc( _row, _col );        /* move cursor */
  190.         break;
  191.     case TAB:            /* ASCII 9 or CTRL-I  */
  192.         nchars = TABSIZ - (_col % TABSIZ);/* Tabs are every 8 characters */
  193.         if    (nchars > _nchars)
  194.             nchars = _nchars;
  195.         chr = BLNK;
  196.         (*_dsp) ( _cmode, _row, _col, nchars, &chr, _attr );
  197.         _col += nchars;
  198.         _nchars -= nchars;
  199.         break;
  200.     case LNFEED:            /* ASCII 10 or CTRL-J */
  201.         _row += nchars;            /* move down NCHARS rows */
  202.         nrows = vidnrows() - 1;
  203.         if    ( _row > nrows )    /* if off screen */
  204.             {
  205.             vidscroll( _row-nrows );/* scroll screen */
  206.             _row = nrows;        /* and leave on bottom line */
  207.             }
  208.         vidsetloc( _row, _col );        /* move cursor */
  209.         break;
  210.     case CRET:            /* ASCII 13 or CTRL-M */
  211.         vidsetloc( _row, _col = 0 );    /* move to beginning of row */
  212.         break;
  213.     default:            /* graphics chars 0-6,11, and 12 */
  214.         (*_dsp) ( _cmode, _row, _col, nchars, &chr, _attr );
  215.         _col += nchars;
  216.         _nchars -= nchars;
  217.         break;
  218.         }
  219. }
  220.  
  221.  
  222. /* This internal routine sets up the static variables declared at the very *
  223. *  beginning of this file for _vdspc, _vdsps, and _vdspa above.           */
  224.  
  225. static    _setargs( row, col, nchars, astate )
  226.     int    row, col, nchars, astate;
  227. {
  228.     /* if position is referenced to current cursor position */
  229.     if    ( row == VD_CURPOS || col == VD_CURPOS )
  230.         vidgetloc( &_row, &_col );    /* find out cursor position */
  231.                         /* set default _row and _col*/
  232.     if    ( row != VD_CURPOS )
  233.         _row = row;        /* set explicit ROW */
  234.     if    ( col != VD_CURPOS )
  235.         _col = col;        /* set explicit COL */
  236.  
  237.     _nchars = nchars;
  238.  
  239.     _smode = VD_NC1A;        /* normal string mode */
  240.     _cmode = VD_1C1A;        /* normal character mode */
  241.     /* if request is for no attribute, i.e., on-screen attribute is   */
  242.     /* retained when new chars are written.                  */
  243.     if    ( astate == VD_NOATTR )
  244.         {
  245.         _smode = VD_NC0A;    /* set no-attribute modes */
  246.         _cmode = VD_1C0A;
  247.         }
  248.  
  249.     _oldstate = ( astate >= 0 )        /* if not using current state */
  250.             ? vstsetcur ( astate )    /* set new and save old state*/
  251.             : VD_CURSTAT;        /* indicate cur state was used*/
  252.  
  253.                 /* if the TTY enabling attribute is on */
  254.     _srchchr = ( vstattr() & VA_GRAPHICS ) 
  255.             ? EOS    /* defeat searches for TTY chars */
  256.             : CRET;    /* enable searches for TTY chars */
  257. }
  258.  
  259.  
  260. /* the window system installs its own display function for speed's sake */
  261. _vdspsetdsp( pfi )
  262.     PFI pfi;
  263. {
  264.     _dsp = pfi;
  265. }
  266.