home *** CD-ROM | disk | FTP | other *** search
/ GRIPS 2: Government Rast…rocessing Software & Data / GRIPS_2.cdr / dos / ncsa_tel / tel_2_2_ / source / rspc.c < prev    next >
C/C++ Source or Header  |  1988-07-15  |  10KB  |  517 lines

  1. /*  RSpc
  2. *   real screen interface for Gaige Paulsen's 
  3. *   Virtual screen driver
  4. *
  5. *   Tim Krauskopf
  6. *
  7. *   Date      Notes
  8. *  --------------------------------------------
  9. *  11/25/86   Start -TKK
  10. */
  11.  
  12. #include "stdio.h"
  13. #include "whatami.h"
  14. #include "windat.h"
  15. #include "vskeys.h"
  16.  
  17. unsigned char *malloc();
  18.  
  19. static int lastatt=255,lastw=255,    /* last attribute value written to screen*/
  20.     thevis=0;                        /* which window is visible */
  21.  
  22. /*************************************************************************/
  23.  
  24. RSbell(w)
  25.     int w;
  26.     {
  27. /*
  28. *  might add something to indicate which window
  29. */
  30.     n_sound(1000,12);        /* PC bell routine */
  31.  
  32. }
  33.  
  34. RSvis(w)
  35.     int w;
  36.     {
  37.     thevis = w;                /* this is visible window */
  38. }
  39.  
  40. RSinitall() {}
  41. RSinsstring() {}
  42. RSdelchars() {}
  43. RSbufinfo() {}
  44. RSdrawsep() {}
  45. RSmargininfo() {}
  46. RSdelcols() {}
  47. RSinscols() {}
  48.  
  49. RScursoff(w)
  50.     int w;
  51.     {
  52.         /* do nothing, MAC routine */
  53. }
  54.  
  55. RScurson(w,y,x)
  56.     int w,x,y;
  57.     {
  58.  
  59.     if (w != thevis)
  60.         return(0);                            /* not visible */
  61. /*
  62. *  this is really the cursor positioning routine.  If cursor is turned off,
  63. *  then it needs to be turned back on.
  64. */
  65.     n_cur(x,y);
  66. /*  add code to save cursor position for a given window */
  67.  
  68. }
  69.  
  70. RSdraw(w,y,x,a,len,ptr)
  71.     int w,x,y,a,len;
  72.     char *ptr;
  73.     {
  74.     int i;
  75.  
  76.     if (w != thevis) {
  77.     /*  indicate that something happened */
  78.         x = n_row(); y = n_col();
  79.         if (screens[w]->sstat != '*') {
  80.             if (screens[w]->sstat == 47)
  81.                 screens[w]->sstat = 92;
  82.             else
  83.                 screens[w]->sstat = 47;
  84.         }
  85.  
  86.         statline();
  87.         n_cur(x,y);                            /* restore cursor where belongs */
  88.         return(0);                            /* not visible */
  89.     }
  90. /*
  91. * call my own draw routine
  92. */
  93.     if (w != lastw || a != lastatt)         /* need to parse attribute bit */
  94.         RSsetatt(a,w);
  95.  
  96.     n_cur(x,y);
  97.  
  98.     if (VSisgrph(lastatt)) {
  99.         for (i=0; i<len; i++)
  100.             ptr[i] = translate(ptr[i]);            
  101.     }
  102.  
  103.     if (scmode())
  104.         n_cheat(ptr,len);
  105.     else
  106.         n_draw(ptr,len); 
  107. }
  108.  
  109. RSsetatt(a,w)
  110.     int a,w;
  111.     {
  112.     int c;
  113.  
  114.         if (VSisundl(a))
  115.             c = screens[w]->colors[1];
  116.         else if (VSisrev(a))
  117.             c = screens[w]->colors[2];
  118.         else
  119.             c = screens[w]->colors[0];
  120.  
  121.         if (VSisblnk(a))
  122.             c |= 128;                /* set blink bit */
  123.         if (VSisbold(a))
  124.             c |= 8;                    /* set brightness bit */
  125.  
  126.         n_color(c);
  127.         lastatt = a;
  128.         lastw = w;
  129.  
  130. }
  131.  
  132. RSdellines(w,t,b,n,select)
  133.     int w,t,b,n,select;
  134.     {
  135.     int c;
  136.  
  137.     if (w != thevis || n < 1)
  138.         return(0);                            /* not visible */
  139.  
  140.     c = n_color(screens[w]->colors[0]);
  141.  
  142.     n_scrup(n,t,0,b,79);
  143.  
  144.     n_color(c);
  145.  
  146. }
  147.  
  148. RSerase(w,y1,x1,y2,x2)
  149.     int w,x1,y1,x2,y2;
  150.     {
  151.     int c;
  152.  
  153.     if (w != thevis)
  154.         return(0);                            /* not visible */
  155.  
  156.     c = n_color(screens[w]->colors[0]);
  157.  
  158.     n_scrup(0,x1,y1,x2,y2);
  159.  
  160.     n_color(c);
  161.  
  162. }
  163.  
  164. RSinslines(w,t,b,n,select)
  165.     int w,t,b,n,select;
  166.     {
  167.     int c;
  168.  
  169.     if (w != thevis || n < 1)
  170.         return(0);                            /* not visible */
  171.  
  172.     c = n_color(screens[w]->colors[0]);
  173.  
  174.     n_scrdn(n,t,0,b,79);
  175.  
  176.     n_color(c);
  177. }
  178.  
  179. RSsendstring(w,ptr,len)
  180.     int w,len;
  181.     char *ptr;
  182.     {
  183.  
  184.     netwrite(screens[w]->pnum,ptr,len);
  185.  
  186. }
  187.  
  188. /*
  189. *  VT100 code still needed, waiting for Gaige's routines
  190. */
  191.  
  192. #include "nkeys.h"
  193.  
  194. int transtable[] = {     /*  Graphics translation set  */
  195.             32, 4, 177, 9, 12, 13, 10, 248, 241,
  196.             10, 10, 217, 191, 218, 192, 197, 196,
  197.             196, 196, 196, 95, 195, 180, 193, 194, 
  198.             179, 243, 242, 227, 168, 156, 250, 32, 32,
  199.             32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
  200.  
  201.  
  202. /***************************************************************************/
  203. /*   translate:
  204. *       Takes a character and converts it to the IBM PC extended character
  205. *   set which, in the transtable array, is mapped to the VT100 graphics
  206. *   characters, with minor conflicts.
  207. */
  208. translate(ch)
  209.     int ch;
  210.     {
  211.     if (ch > 94) 
  212.         return(transtable[ ch - 95 ]);
  213.     else
  214.         return(ch);
  215. }
  216.  
  217.  
  218. /*   Keyboard translations from the PC to VT100
  219. *      Tim Krauskopf               Sept. 1986
  220. *
  221. *      original: ISP 1984
  222. */
  223.  
  224.  
  225. /***************************************************************************/
  226. /*  takes a key value and sends it to the TCP port in 'pnum'
  227. *   First, translates all special keys to VT100 key sequences.
  228. */
  229. /*  see vskeys.h for keys in this trans table
  230. */
  231. unsigned char vttrans[128] = {
  232.     19,20,21,22,  16,15,  17,11,0,18,0, 4, 0, 1,2,0,
  233.     0,0,0,0,0,0,0,0,0,0,0, 3, 0,0, 17, 0,
  234.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
  235.     6,7,8,9,10,11,12,13,14,5, 0,0,0, 16, 15, 0,
  236.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  237.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  238.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  239.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  240.     };
  241.  
  242. vt100key(c)
  243.     int c;
  244.     {
  245.     int i;
  246.  
  247.     if (c < 128) {
  248.         netwrite(current->pnum,&c,1);
  249.         return(0);
  250.     }
  251.     else {
  252.         i = vttrans[c-128];
  253.         if (i)
  254.             VSkbsend(current->vs,i+128,!(current->echo));
  255.         else {
  256.             switch(c) {
  257.                 case HOME:
  258.                     netwrite(current->pnum,"\010",1);
  259.                     break;
  260.                 case ENDKEY:
  261.                     VSkbsend(current->vs,VSK4,0);
  262.                     VSkbsend(current->vs,VSK2,0);
  263.                     break;
  264.                 case CTRLHOME:
  265.                     VSkbsend(current->vs,VSF1,0);
  266.                     VSkbsend(current->vs,VSK5,0);
  267.                     break;
  268.                 case CTRLEND:
  269.                     VSkbsend(current->vs,VSF1,0);
  270.                     VSkbsend(current->vs,VSK4,0);
  271.                     break;
  272.                 case PGUP:
  273.                     VSkbsend(current->vs,VSK5,0);
  274.                     VSkbsend(current->vs,VSK8,0);
  275.                     break;
  276.                 case PGDN:
  277.                     VSkbsend(current->vs,VSK4,0);
  278.                     VSkbsend(current->vs,VSK8,0);
  279.                     break;
  280.                 case CTRLPGUP:
  281.                     VSkbsend(current->vs,VSK5,0);
  282.                     VSkbsend(current->vs,VSK7,0);
  283.                     break;
  284.                 case CTRLPGDN:
  285.                     VSkbsend(current->vs,VSK4,0);
  286.                     VSkbsend(current->vs,VSK7,0);
  287.                     break;
  288.                 case F9:
  289.                     netwrite(current->pnum,"\032exit\r\n",7);
  290.                     break;
  291.                 default:
  292.         /* key is not mapped to anything */
  293.                     break;
  294.             }
  295.         }
  296.     }
  297.     return(0);
  298. }
  299.  
  300. /***********************************************************************/
  301. /*  non-blocking RSgets()
  302. *   This routine will continually add to a string that is re-submitted
  303. *   until a special character is hit.  It never blocks.
  304. *
  305. *   As long as editing characters (bksp, Ctrl-U) and printable characters
  306. *   are pressed, this routine will update the string.  When any other special
  307. *   character is hit, that character is returned.  
  308. */
  309. char bk[] = {8,' ',8};
  310.  
  311. RSgets(w,s,lim)
  312.     int w;
  313.     char *s;
  314.     int lim;
  315.     {
  316.     int c,count,i;
  317.     char *save;
  318.  
  319.     count = strlen(s);
  320.     save = s;
  321.     s += count;
  322.  
  323.     while (0 < (c = n_chkchar())) {
  324.  
  325.         switch (c) {                /* allow certain editing chars */
  326.             case 8:                    /* backspace */
  327.                 if (count) {
  328.                     VSwrite(w,bk,3);
  329.                     count--;        /* one less character */
  330.                     s--;            /* move pointer backward */
  331.                 }
  332.                 break;
  333.             case 21:
  334.                 for (i=0; i < s-save; i++) {
  335.                     VSwrite(w,bk,3);
  336.                 }
  337.                 s = save;
  338.                 break;
  339.             case 13:
  340.             case 9:
  341.                 *s = '\0';            /* terminate the string */
  342.                 return(c);
  343.             default:
  344.                 if (count == lim) {            /* to length limit */
  345.                     RSbell();
  346.                     *s = '\0';                /* terminate */
  347.                     return(0);
  348.                 }
  349.  
  350.                 if (c > 31 && c < 127) {
  351.                     VSwrite(w,&c,1);
  352.                     *s++ = c;                /* add to string */
  353.                     count++;                /* length of string */
  354.                 }
  355.                 else {
  356.                     if (c > 0 && c < 27) {
  357.                         c += 64;
  358.                         VSwrite(w,"^",1);
  359.                         VSwrite(w,&c,1);
  360.                         c -= 64;
  361.                     }
  362.                     *s = '\0';            /* terminate the string */
  363.                     return(c);
  364.                 }
  365.  
  366.             break;
  367.         }
  368.  
  369.     }
  370.  
  371.     *s = '\0';            /* terminate the string */
  372.     return(c);
  373.  
  374. }
  375.  
  376. /***********************************************************************/
  377. /*  non-blocking gets()
  378. *   This routine will call netsleep while waiting for keypresses during
  379. *   a gets.  Replaces the library gets.
  380. *
  381. *   As long as editing characters (bksp, Ctrl-U) and printable characters
  382. *   are pressed, this routine will continue.  When any other special
  383. *   character is hit, NULL is returned.  the return key causes a normal return.
  384. */
  385. char *nbgets(s,lim)
  386.     char *s;
  387.     int lim;
  388.     {
  389.     int c,count,i;
  390.     char *save;
  391.  
  392.     count = 0;
  393.     save = s;
  394.  
  395.     while (1) {
  396.         c = n_chkchar();
  397.  
  398.         if (c <= 0) {
  399.             Stask();            /* keep communications going */
  400.             c = 0;
  401.         }
  402.  
  403.         switch (c) {                /* allow certain editing chars */
  404.             case 8:                    /* backspace */
  405.                 if (count) {
  406.                     n_putchar(c);
  407.                     n_putchar(' ');
  408.                     n_putchar(c);
  409.                     count--;        /* one less character */
  410.                     s--;            /* move pointer backward */
  411.                 }
  412.                 break;
  413.             case 13:                /* carriage return, = ok */
  414.                 n_puts("");
  415.                 *s = '\0';            /* terminate the string */
  416.                 return(save);        /* return ok */
  417.                 break;
  418.             case 21:
  419.                 for (i=0; i < s-save; i++) {
  420.                     n_putchar(8);
  421.                     n_putchar(' ');
  422.                     n_putchar(8);
  423.                 }
  424.                 s = save;
  425.                 break;
  426.             case 0:                    /* do nothing */
  427.                 break;
  428.             default:
  429.                 if (c > 31 && c < 127) {
  430.                     if (count < lim) {
  431.                         n_putchar(c);
  432.                         *s++ = c;                /* add to string */
  433.                         count++;                /* length of string */
  434.                     }
  435.                 }
  436.                 else {
  437.                     n_puts("");
  438.                     *s = '\0';            /* terminate the string */
  439.                     return(NULL);
  440.                 }
  441.  
  442.             break;
  443.         }
  444.  
  445.     }
  446. }
  447.  
  448. /************************************************************************/
  449. /*  nbgetch
  450. *   check the keyboard for a character, don't block to wait for it,
  451. *   but don't return to the caller until it is there.
  452. */
  453. nbgetch()
  454.     {
  455.     int c;
  456.  
  457.     while (0 >= (c = n_chkchar()))         /* there is a key? */
  458.         Stask();                    /* no key yet, update everything */
  459.  
  460.     return(c);
  461.  
  462. }
  463.  
  464. /************************************************************************/
  465. /* nbget
  466. *   demux at least one packet each time, check the keyboard for a key, 
  467. *   return any key pressed to the caller.
  468. */
  469. nbget()
  470.     {
  471.     int c;
  472.  
  473.     demux(0);                /* only one packet */
  474.  
  475.     if (0 >= (c = n_chkchar()))
  476.         return(-1);            /* no key ready */
  477.  
  478.     return(c);
  479. }
  480.  
  481.  
  482. /***********************************************************************/
  483. /* ftpstart
  484. *  update status line with new file length remaining
  485. */
  486. ftpstart(dir,buf)
  487.     char dir,*buf;
  488.     {
  489.     int r,c,cl;
  490.     long int fpos;
  491.  
  492.     r = n_row();
  493.     c = n_col();
  494.     cl = n_color(current->colors[0]);
  495.  
  496.     if (dir)
  497.         dir = '<';
  498.     else
  499.         dir = '>';
  500.  
  501.     Sftpname(&buf[100]);    /* get file name */
  502.     Sftpstat(&fpos);        /* get position in file */
  503.  
  504.     n_cur(24,36);
  505.     sprintf(buf,"FTP %c %14s %10lu",dir,&buf[100],fpos);
  506.  
  507.     if (scmode()) 
  508.         n_cheat(buf,strlen(buf));
  509.     else
  510.         n_draw(buf,strlen(buf));
  511.  
  512.     n_color(cl);
  513.     n_cur(r,c);
  514.     return(0);
  515. }
  516.  
  517.