/* ZCPR Vlib routines for C */ /* Cameron W. Cotrill 8/26/89 This is a set of routines that allow access to the ZCPR3 TCAP and implement simple C callable routines for functions supported by the TCAP. This library must be initalized at the start of the program by calling the z3vinit function with a pointer to Z3ENV. All functions return the the value TRUE or FALSE to the caller. TRUE indicates the operation was successful, while FALSE indicates the TCAP does not support the requested function. This module and the Z3TCAP.H header file use some definitions that may need alteration for some compilers. Two can be fixed by moving the following two definitions outside of the comment field. Applications should include Z3TCAP.H and CVFUNC.H to get many functions with little overhead. Version 0.5 re-arranged for searching CRL. Combined CVFUNC.C and CVLIB.C. Version 0.4 features a new decimal conversion routine _2dc() in itoa.c. This new routine simplified some code in goxy(). */ #include #include "Z3TCAP.H" #ifndef BDSC struct z3tcap tcap; /* in the header for Bds C */ #endif /* Initalize CVlib routines by setting up pointer array */ int z3vinit(env) char *env; { char *s, *t, **j; #ifdef BDSC unsigned i; #else unsigned int i; #endif if(env) { s = env + 0x80; tcap.name = s; s+=15; /* Advance to terminal flags */ for(i=15, t= &tcap.flags ; i < 23 ; ++i) *t++ = *s++; /* copy flags, keys, delays */ j = &tcap.cl; for(i = 0 ; i < 10 ; i++) { if(*s) *j++ = s; else *j++ = NULL; while(*s++); } tcap.go = *s++; /* Graphics delay */ j = &tcap.gs; for(i = 0 ; i < 17 ; i++) { if(*s) *j++ = s; else *j++ = NULL; while(*s++); } return(TRUE); } else { /* No tcap, so fill local tcap with nulls */ for(i = 0, s = &tcap.name ; i < sizeof(tcap) ; i++) *s++ = NULL; return(FALSE); } } /* Send cursor motion sequence - 1,1 is home */ int goxy(row, col) int row, col; { char *s, c, cv[4]; int i, j; /* change org to 0,0 */ row = ckrow(--row); col = ckcol(--col); /* decrypt the cursor control string in the TCAP */ if(s = tcap.cm){ while(c = *s) { if(c != '%') _cout(c); else { /* Escape sequence detected */ switch(c = toupper(*(++s))) { case 'I': /* reset org to 1,1 */ ++row; ++col; break; case 'R': /* reverse row,col order */ i = row; row = col; col = i; break; case '>': /* if > x, add y */ if(row > *(++s)) row += *(++s); else ++s; break; rbout: case '.': /* output value as is */ _cout(row); roll: row = col; col = 0; break; case '+': /* add offset and output */ row += *(++s); goto rbout; case '2': /* output as at least 2 ascii */ j = 2; goto dout; case '3': /* output as at least 3 ascii */ j = 3; goto dout; case 'D': /* output as at least 1 ascii */ j = 0; dout: _2dc(cv, row, j, FALSE); _scout(cv); goto roll; } } ++s; } return(TRUE); } else return(FALSE); } /* CVlib functions */ #ifndef ECOC /* Clear screen and home cursor */ int cls() { return(_fdtcap(tcap.cl,tcap.cldly)); } /* Clear from current cursor position to end of line */ int clreol() { return(_fdtcap(tcap.ce,tcap.cedly)); } /* test if cursor control key */ int isc_any(c) int c; { return(isc_up(c) || isc_dn(c) || isc_l(c) || isc_r(c)); } /* test if char is cursor down key */ int isc_dn(c) int c; { return(c == tcap.yd); } /* test if char is cursor left key */ int isc_l(c) int c; { return(c == tcap.yl); } /* test if char is cursor right */ int isc_r(c) int c; { return(c == tcap.yr); } /* test if char is cursor up key */ int isc_up(c) int c; { return(c == tcap.yu); } /* Turn standout (reverse video) on */ int standout() { return(_ftcap(tcap.so)); } /* Turn standout (reverse video) off */ int standend() { return(_ftcap(tcap.se)); } /* Initalize terminal */ int tinit() { return(_ftcap(tcap.ti)); } /* De-initalize terminal */ int tdinit() { return(_ftcap(tcap.te)); } /* return tcap flags */ int tflags() { return(tcap.flags); } /* Delete line cursor is on */ int delline() { return(_ftcap(tcap.dl)); } /* Insert line cursor is on */ int insline() { return(_ftcap(tcap.il)); } /* Clear from cursor to end of screen */ int clreos() { return(_ftcap(tcap.cd)); } /* Turn graphics mode on */ int gm_on() { return(_ftcap(tcap.gs)); } /* Turn graphics mode off */ int gm_off() { return(_ftcap(tcap.ge)); } /* Turn cursor on */ int cur_on() { return(_fdtcap(tcap.cde,tcap.go)); } /* Turn cursor off */ int cur_off() { return(_fdtcap(tcap.cdo,tcap.go)); } /* Display various graphic characters */ int g_gulc() { return(_ftcap(tcap.gulc)); } int g_gurc() { return(_ftcap(tcap.gurc)); } int g_gllc() { return(_ftcap(tcap.gllc)); } int g_glrc() { return(_ftcap(tcap.glrc)); } int g_ghl() { return(_ftcap(tcap.ghl)); } int g_gvl() { return(_ftcap(tcap.gvl)); } int g_gfb() { return(_ftcap(tcap.gfb)); } int g_ghb() { return(_ftcap(tcap.ghb)); } int g_gui() { return(_ftcap(tcap.gui)); } int g_gli() { return(_ftcap(tcap.gli)); } int g_gis() { return(_ftcap(tcap.gis)); } int g_grti() { return(_ftcap(tcap.grti)); } int g_glti() { return(_ftcap(tcap.glti)); } #endif /* Output null terminated cursor control string */ void _scout(str) char *str; { while(*str) _cout(*str++); } /* Generic tcap string output function */ int _ftcap(s) char *s; { if(s) { _scout(s); return(TRUE); } else return(FALSE); } /* Output tcap string and delay */ /* Needs delay added still... */ int _fdtcap(s,dly) char *s; int dly; { _ftcap(s); } /* The following routine is the only one which will cause problems with portability. It must output the character passed to it by using either BDOS function 6 or a direct BIOS conout call. This version is for the BDS compiler. */ int _cout(c) int c; { #ifndef ECOC bdos(6,c); #else _bdos(6,c); #endif } #ifndef BDSC extern char *envadr; #else char *zenv(); #endif /* Check row against env maximum */ int ckrow(row) int row; { char mrow; #ifdef BDSC mrow = *(zenv()+0x32); #else mrow = *(envadr+0x32); #endif return(row > mrow ? mrow : row); } /* Check column against env maximum */ int ckcol(col) int col; { char mcol; #ifdef BDSC mcol = *(zenv()+0x31); #else mcol = *(envadr+0x31); #endif return(col > mcol ? mcol : col); }