home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / JSAGE / ZSUS / PROGPACK / CFORZ02.LBR / CVLIB.CZ / CVLIB.C
Text File  |  2000-06-30  |  7KB  |  409 lines

  1. /* ZCPR Vlib routines for C */
  2.  
  3. /* Cameron W. Cotrill    8/26/89
  4.  
  5.    This is a set of routines that allow access to the ZCPR3 TCAP
  6.    and implement simple C callable routines for functions supported
  7.    by the TCAP.
  8.  
  9.    This library must be initalized at the start of the program by
  10.    calling the z3vinit function with a pointer to Z3ENV.
  11.  
  12.    All functions return the the value TRUE or FALSE to the caller.
  13.    TRUE indicates the operation was successful, while FALSE indicates
  14.    the TCAP does not support the requested function.
  15.  
  16.    This module and the Z3TCAP.H header file use some definitions that
  17.    may need alteration for some compilers.  Two can be fixed by moving
  18.    the following two definitions outside of the comment field.
  19.  
  20.    Applications should include Z3TCAP.H and CVFUNC.H to get many
  21.    functions with little overhead. 
  22.  
  23.    Version 0.5 re-arranged for searching CRL.  Combined CVFUNC.C and
  24.    CVLIB.C.
  25.  
  26.    Version 0.4 features a new decimal conversion routine _2dc() in
  27.    itoa.c.  This new routine simplified some code in goxy().
  28. */
  29.  
  30. #include <STDIO.H>
  31. #include "Z3TCAP.H"
  32.  
  33. #ifndef BDSC
  34. struct z3tcap tcap;    /* in the header for Bds C */
  35. #endif
  36.  
  37. /* Initalize CVlib routines by setting up pointer array */
  38.  
  39. int z3vinit(env)
  40.     char *env;
  41. {
  42.     char *s, *t, **j;
  43. #ifdef BDSC
  44.     unsigned i;
  45. #else
  46.     unsigned int i;
  47. #endif
  48.  
  49.     if(env) {
  50.         s = env + 0x80;
  51.         tcap.name = s;
  52.         s+=15;            /* Advance to terminal flags */
  53.         for(i=15, t= &tcap.flags ; i <  23 ; ++i)
  54.             *t++ = *s++;    /* copy flags, keys, delays */
  55.         j = &tcap.cl;
  56.         for(i = 0 ; i < 10 ; i++) {
  57.             if(*s)
  58.                 *j++ = s;
  59.             else
  60.                 *j++ = NULL;
  61.             while(*s++);
  62.         }
  63.         tcap.go = *s++;        /* Graphics delay */
  64.         j = &tcap.gs;
  65.         for(i = 0 ; i < 17 ; i++) {
  66.             if(*s)
  67.                 *j++ = s;
  68.             else
  69.                 *j++ = NULL;
  70.             while(*s++);
  71.         }
  72.         return(TRUE);
  73.     } else {
  74.  
  75.         /* No tcap, so fill local tcap with nulls */ 
  76.  
  77.         for(i = 0, s = &tcap.name ; i < sizeof(tcap) ; i++)
  78.             *s++ = NULL;
  79.         return(FALSE);
  80.     }
  81. }
  82.  
  83. /* Send cursor motion sequence - 1,1 is home */
  84.  
  85. int goxy(row, col)
  86.     int row, col;
  87. {
  88.     char *s, c, cv[4];
  89.     int i, j;
  90.  
  91.     /* change org to 0,0 */
  92.  
  93.     row = ckrow(--row);
  94.     col = ckcol(--col);
  95.  
  96.     /* decrypt the cursor control string in the TCAP */
  97.  
  98.     if(s = tcap.cm){
  99.         while(c = *s) {
  100.             if(c != '%')
  101.                 _cout(c);
  102.             else {
  103.                 /* Escape sequence detected */
  104.  
  105.                 switch(c = toupper(*(++s))) {
  106.                     case 'I':    
  107.                     /* reset org to 1,1 */
  108.                         ++row;
  109.                         ++col;
  110.                         break;
  111.                     case 'R':
  112.                     /* reverse row,col order */
  113.                         i = row;
  114.                         row = col;
  115.                         col = i;
  116.                         break;
  117.                     case '>':
  118.                     /* if > x, add y */ 
  119.                         if(row > *(++s))
  120.                             row += *(++s);
  121.                         else    
  122.                             ++s;
  123.                         break;
  124. rbout:                    case '.':
  125.                     /* output value as is */
  126.                         _cout(row);
  127. roll:                        row = col;
  128.                         col = 0;
  129.                         break;
  130.                     case '+':
  131.                     /* add offset and output */
  132.                         row += *(++s);
  133.                         goto rbout;
  134.                     case '2':
  135.                     /* output as at least 2 ascii */ 
  136.                         j = 2;
  137.                         goto dout;
  138.                     case '3':
  139.                     /* output as at least 3 ascii */ 
  140.                         j = 3;
  141.                         goto dout;
  142.                     case 'D':
  143.                     /* output as at least 1 ascii */ 
  144.                         j = 0;
  145. dout:                        _2dc(cv, row, j, FALSE);
  146.                         _scout(cv);
  147.                         goto roll;
  148.                 }
  149.             }
  150.             ++s;
  151.         }
  152.         return(TRUE);
  153.     } else
  154.         return(FALSE);
  155. }
  156.  
  157. /* CVlib functions */
  158.  
  159. #ifndef ECOC
  160. /* Clear screen and home cursor */
  161.  
  162. int cls() {
  163.     return(_fdtcap(tcap.cl,tcap.cldly));
  164. }
  165.  
  166. /* Clear from current cursor position to end of line */
  167.  
  168. int clreol() {
  169.     return(_fdtcap(tcap.ce,tcap.cedly));
  170. }
  171.  
  172. /* test if cursor control key */
  173.  
  174. int isc_any(c)
  175.     int c;
  176. {
  177.     return(isc_up(c) || isc_dn(c) || isc_l(c) || isc_r(c));
  178. }
  179.  
  180. /* test if char is cursor down key */
  181.  
  182. int isc_dn(c)
  183.     int c;
  184. {
  185.     return(c == tcap.yd);
  186. }
  187.  
  188. /* test if char is cursor left key */
  189.  
  190. int isc_l(c)
  191.     int c;
  192. {
  193.     return(c == tcap.yl);
  194. }
  195.  
  196. /* test if char is cursor right */
  197.  
  198. int isc_r(c)
  199.     int c;
  200. {
  201.     return(c == tcap.yr);
  202. }
  203.  
  204. /* test if char is cursor up key */
  205.  
  206. int isc_up(c)
  207.     int c;
  208. {
  209.     return(c == tcap.yu);
  210. }
  211.  
  212. /* Turn standout (reverse video) on */
  213. int standout() {
  214.     return(_ftcap(tcap.so));
  215. }
  216.  
  217. /* Turn standout (reverse video) off */
  218.  
  219. int standend() {
  220.     return(_ftcap(tcap.se));
  221. }
  222.  
  223. /* Initalize terminal */
  224.  
  225. int tinit() {
  226.     return(_ftcap(tcap.ti));
  227. }
  228.  
  229. /* De-initalize terminal */
  230.  
  231. int tdinit() {
  232.     return(_ftcap(tcap.te));
  233. }
  234.  
  235. /* return tcap flags */
  236.  
  237. int tflags() {
  238.     return(tcap.flags);
  239. }
  240.  
  241. /* Delete line cursor is on */
  242.  
  243. int delline() {
  244.     return(_ftcap(tcap.dl));
  245. }
  246.  
  247. /* Insert line cursor is on */
  248.  
  249. int insline() {
  250.     return(_ftcap(tcap.il));
  251. }
  252.  
  253. /* Clear from cursor to end of screen */
  254.  
  255. int clreos() {
  256.     return(_ftcap(tcap.cd));
  257. }
  258.  
  259. /* Turn graphics mode on */
  260.  
  261. int gm_on() {
  262.     return(_ftcap(tcap.gs));
  263. }
  264.  
  265. /* Turn graphics mode off */
  266.  
  267. int gm_off() {
  268.     return(_ftcap(tcap.ge));
  269. }
  270.  
  271. /* Turn cursor on */
  272.  
  273. int cur_on() {
  274.     return(_fdtcap(tcap.cde,tcap.go));
  275. }
  276.  
  277. /* Turn cursor off */
  278.  
  279. int cur_off() {
  280.     return(_fdtcap(tcap.cdo,tcap.go));
  281. }
  282.  
  283. /* Display various graphic characters */
  284.  
  285. int g_gulc() {
  286.     return(_ftcap(tcap.gulc));
  287. }
  288. int g_gurc() {
  289.     return(_ftcap(tcap.gurc));
  290. }
  291. int g_gllc() {
  292.     return(_ftcap(tcap.gllc));
  293. }
  294. int g_glrc() {
  295.     return(_ftcap(tcap.glrc));
  296. }
  297. int g_ghl() {
  298.     return(_ftcap(tcap.ghl));
  299. }
  300. int g_gvl() {
  301.     return(_ftcap(tcap.gvl));
  302. }
  303. int g_gfb() {
  304.     return(_ftcap(tcap.gfb));
  305. }
  306. int g_ghb() {
  307.     return(_ftcap(tcap.ghb));
  308. }
  309. int g_gui() {
  310.     return(_ftcap(tcap.gui));
  311. }
  312. int g_gli() {
  313.     return(_ftcap(tcap.gli));
  314. }
  315. int g_gis() {
  316.     return(_ftcap(tcap.gis));
  317. }
  318. int g_grti() {
  319.     return(_ftcap(tcap.grti));
  320. }
  321. int g_glti() {
  322.     return(_ftcap(tcap.glti));
  323. }
  324. #endif
  325.  
  326. /* Output null terminated cursor control string */
  327.  
  328. void _scout(str)
  329.     char *str;
  330. {
  331.     while(*str)
  332.         _cout(*str++);
  333. }
  334.  
  335. /* Generic tcap string output function */
  336.  
  337. int _ftcap(s)
  338.     char *s;
  339. {
  340.     if(s) {
  341.         _scout(s);
  342.         return(TRUE);
  343.     } else
  344.         return(FALSE);
  345. }
  346.  
  347. /* Output tcap string and delay */
  348. /* Needs delay added still... */
  349.  
  350. int _fdtcap(s,dly)
  351.     char *s;
  352.     int  dly;
  353. {
  354.     _ftcap(s);
  355. }        
  356.  
  357. /* The following routine is the only one which will cause problems
  358.    with portability.  It must output the character passed to it by
  359.    using either BDOS function 6 or a direct BIOS conout call.  This
  360.    version is for the BDS compiler.
  361. */
  362.  
  363. int _cout(c)
  364.     int c;
  365. {
  366. #ifndef ECOC
  367.     bdos(6,c);
  368. #else
  369.     _bdos(6,c);
  370. #endif
  371. }
  372.  
  373. #ifndef BDSC
  374. extern char *envadr;
  375. #else
  376. char *zenv();
  377. #endif
  378.  
  379. /* Check row against env maximum */
  380.  
  381. int ckrow(row)
  382.     int row;
  383. {
  384.     char mrow;
  385.  
  386. #ifdef BDSC
  387.     mrow = *(zenv()+0x32);
  388. #else 
  389.     mrow = *(envadr+0x32);
  390. #endif
  391.     return(row > mrow ? mrow : row);
  392. }
  393.  
  394. /* Check column against env maximum */
  395.  
  396. int ckcol(col)
  397.     int col;
  398. {
  399.     char mcol;
  400.  
  401. #ifdef BDSC
  402.     mcol = *(zenv()+0x31);
  403. #else 
  404.     mcol = *(envadr+0x31);
  405. #endif
  406.     return(col > mcol ? mcol : col);
  407. }
  408.  
  409.