home *** CD-ROM | disk | FTP | other *** search
- /* (c) 1985, Phoenix Computer Products Corp. and Novum Organum, Inc. */
- #include "pdefs.h"
- #include "psys.h"
-
- #define VS_ATRCHR '^'
- #define TABSIZ 8
-
- static int _row, _col; /* screen position */
- static int _nchars; /* max # of chars to use from string */
- static int _smode, _cmode; /* _dsp mode constants */
- static int _oldstate; /* place to save the attribute state */
- static int _attr = 0x07; /* IBM-PC attribute */
- static int _srchchr; /* CRET if VA_TTY is on, EOS otherwise */
- /* to control scanning for TTY chars */
-
- int _vdsp();
- static PFI _dsp = _vdsp; /* video display function */
-
-
- /* These two little routines just save and return the IBM-PC attribute */
-
- _vdspsattr( ibmattr )
- {
- _attr = ibmattr;
- }
-
- int _vdspattr()
- {
- return( _attr );
- }
-
- /* This internal routine handles the attribute control sequences within *
- * strings. Other pieces of the string are passed through to _vdspstty *
- * later in this file. */
-
-
-
- _vdsps( int row, int col, int nchars, int astate, char *str, void **pargs )
- {
- int chr, offset;
- char *strnfmtp();
- char _fmtbuf[256];
-
- _setargs( row, col, nchars, astate ); /* set static variables */
-
- if ((!(vstattr() & VA_PCT)) && (stridxc('%',str) != NOTFND))
- {
- // str = strnfmtp(_fmtbuf,sizeof(_fmtbuf),str,(int *)pargs);
- vsprintf(_fmtbuf, str, pargs);
- str = _fmtbuf;
- }
- if (!(vstattr() & VA_CARET)) /* if the attribute stuff is on */
- { /* look for attribute control stuff */
- while ( (offset = stridxc(VS_ATRCHR,str)) != NOTFND )
- {
- _vdspstty(offset,str); /* do display up to stuff */
- str += offset + 1;
-
- chr = *str++;
- switch ( TOUPPER(chr) )/* check out the control char*/
- {
- case EOS: goto end; /* EndOfString -- all done */
- case 'B': vsttogattr(VA_BLINK); break;
- case 'H': vsttogattr(VA_HIINTY); break;
- case 'R': vsttogattr(VA_REVVID); break;
- case 'U': vsttogattr(VA_ULN); break;
- default : str--; break;
- case VS_ATRCHR:
- _vdspctty(1,VS_ATRCHR); /* display '^' */
- break;
- }
-
- }
- }
- _vdspstty( _nchars, str ); /* do the part of the string after */
- /* the last control sequence or the */
- /* whole string if the control */
- /* sequence jazz is turned off */
- end:
- if ((nchars < VD_ALLOFIT) && (_nchars > 0))
- {
- chr = BLNK;
- (*_dsp) ( _cmode, _row, _col, _nchars, &chr, _attr );
- }
-
- if ( _oldstate != VD_CURSTAT ) /* if the state was changed */
- vstsetcur( _oldstate ); /* change it back */
- }
-
- /* This internal routine handles the pieces of a string which have already *
- * been scanned for attribute control sequences. It handles TTY characters *
- * by calling _vdspctty, which appears later in this file, and the normal *
- * parts of the string with _dsp, which is a separate assembler routine. */
-
- static _vdspstty( nchars, str )
- int nchars;
- char *str;
- {
- int offset;
-
- while ( _nchars > 0 )
- {
- offset = stridxle( _srchchr, str ); /* look for TTY char */
-
- if ( offset > 0 ) /* do STR up to the TTY char */
- {
- /* limit the number of characters to write */
- if ( offset > nchars )
- offset = nchars;
- if ( offset > _nchars )
- offset = _nchars;
-
- /* the normal part of a string gets displayed right here */
- (*_dsp) (_smode, _row, _col, offset, str, _attr);
- str += offset;
- nchars -= offset;
- _nchars -= offset;
- _col += offset;
- }
- /* EOS comes up as a TTY char since it's less than CRET */
- /* if we've reached the EOS, just quit */
- if ( *str == EOS || nchars <= 0 )
- break;
-
- _vdspctty( 1, *str++ ); /* do the TTY char */
- nchars--;
- }
- }
-
- /* A little internal routine to handle the attribute changing functions. *
- * Packages the call for handling by _dsp, an assembly language routine. */
-
- _vdspa ( row, col, nchars, astate )
- int row, col, nchars, astate;
- {
- _setargs( row, col, nchars, astate ); /* set up statics */
-
- (*_dsp) ( VD_0C1A, _row, _col, _nchars, NULLPTR, _attr ); /* do it */
-
- if ( _oldstate != VD_CURSTAT ) /* if state was changed */
- vstsetcur( _oldstate ); /* restore it */
- }
-
-
-
- /* This routine packages up the character display functions for either *
- * _vdspctty, which is later in this file, or _dsp, a separate assembly *
- * language function elsewhere. */
-
- _vdspc ( row, col, nchars, astate, chr )
- int row, col, nchars, chr, astate;
- {
- _setargs( row, col, nchars, astate ); /* set up static variables */
-
- if ( chr <= _srchchr ) /* if a possible TTY-char */
- {
- if (chr == TAB)
- _nchars = TABSIZ;
- _vdspctty( _nchars, chr ); /* display TTY char */
- }
- else
- /* normal character display */
- (*_dsp) ( _cmode, _row, _col, _nchars, &chr, _attr );
-
- if ( _oldstate != VD_CURSTAT ) /* if attribute state altered*/
- vstsetcur( _oldstate ); /* change it back */
- }
-
-
- /* Internal routine to handle TTY characters for the string and character *
- * display functions. BKSP, TAB, LNFEED, and CRET characters cause cursor*
- * control, BELL calls sybeep(). */
-
- static _vdspctty( nchars, chr )
- int nchars, chr;
- {
- int nrows;
-
- if ( _nchars <= 0 ) return;
-
- switch ( chr )
- {
- case BELL: /* ASCII 7 or CTRL-G */
- while ( nchars-- )
- sybeep(); /* make noise */
- break;
- case BKSP: /* ASCII 8 or CTRL-H */
- _col -= nchars; /* back up cursor */
- if ( _col < 0 ) /* but not too far */
- _col = 0;
- vidsetloc( _row, _col ); /* move cursor */
- break;
- case TAB: /* ASCII 9 or CTRL-I */
- nchars = TABSIZ - (_col % TABSIZ);/* Tabs are every 8 characters */
- if (nchars > _nchars)
- nchars = _nchars;
- chr = BLNK;
- (*_dsp) ( _cmode, _row, _col, nchars, &chr, _attr );
- _col += nchars;
- _nchars -= nchars;
- break;
- case LNFEED: /* ASCII 10 or CTRL-J */
- _row += nchars; /* move down NCHARS rows */
- nrows = vidnrows() - 1;
- if ( _row > nrows ) /* if off screen */
- {
- vidscroll( _row-nrows );/* scroll screen */
- _row = nrows; /* and leave on bottom line */
- }
- vidsetloc( _row, _col ); /* move cursor */
- break;
- case CRET: /* ASCII 13 or CTRL-M */
- vidsetloc( _row, _col = 0 ); /* move to beginning of row */
- break;
- default: /* graphics chars 0-6,11, and 12 */
- (*_dsp) ( _cmode, _row, _col, nchars, &chr, _attr );
- _col += nchars;
- _nchars -= nchars;
- break;
- }
- }
-
-
- /* This internal routine sets up the static variables declared at the very *
- * beginning of this file for _vdspc, _vdsps, and _vdspa above. */
-
- static _setargs( row, col, nchars, astate )
- int row, col, nchars, astate;
- {
- /* if position is referenced to current cursor position */
- if ( row == VD_CURPOS || col == VD_CURPOS )
- vidgetloc( &_row, &_col ); /* find out cursor position */
- /* set default _row and _col*/
- if ( row != VD_CURPOS )
- _row = row; /* set explicit ROW */
- if ( col != VD_CURPOS )
- _col = col; /* set explicit COL */
-
- _nchars = nchars;
-
- _smode = VD_NC1A; /* normal string mode */
- _cmode = VD_1C1A; /* normal character mode */
- /* if request is for no attribute, i.e., on-screen attribute is */
- /* retained when new chars are written. */
- if ( astate == VD_NOATTR )
- {
- _smode = VD_NC0A; /* set no-attribute modes */
- _cmode = VD_1C0A;
- }
-
- _oldstate = ( astate >= 0 ) /* if not using current state */
- ? vstsetcur ( astate ) /* set new and save old state*/
- : VD_CURSTAT; /* indicate cur state was used*/
-
- /* if the TTY enabling attribute is on */
- _srchchr = ( vstattr() & VA_GRAPHICS )
- ? EOS /* defeat searches for TTY chars */
- : CRET; /* enable searches for TTY chars */
- }
-
-
- /* the window system installs its own display function for speed's sake */
- _vdspsetdsp( pfi )
- PFI pfi;
- {
- _dsp = pfi;
- }
-