home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tel2305s.zip / ENGINE / RSPC.C < prev    next >
C/C++ Source or Header  |  1992-03-28  |  14KB  |  594 lines

  1. /*
  2. *    RSpc.c
  3. *
  4. *   real screen interface for Gaige Paulsen's 
  5. *   Virtual screen driver
  6. *
  7. *   Tim Krauskopf
  8. *
  9. *    Date        Notes
  10. *    --------------------------------------------
  11. *    11/25/86    Start -TKK
  12. *    6/89        code cleanup for 2.3 release -QAK
  13. */
  14.  
  15. /*
  16. * Includes
  17. */
  18. #ifdef MOUSE
  19. #include "mouse.h"
  20. #endif
  21. #ifdef __TURBOC__
  22. #include "turboc.h"
  23. #endif
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <bios.h>        /* for printer functions */
  28. #ifdef MSC
  29. #ifdef __TURBOC__
  30. #include <alloc.h>
  31. #else
  32. #include <malloc.h>
  33. #endif
  34. #endif
  35. #include "whatami.h"
  36. #include "windat.h"
  37. #include "vskeys.h"
  38. #include "hostform.h"
  39. #include "nkeys.h"
  40. #include "externs.h"
  41. #include "keymap.h"
  42. #include "map_out.h"
  43.  
  44. /*
  45. *    Global Variables
  46. */
  47. extern struct config def;
  48. extern int numline;                /* numline of lines in display */
  49. extern int beep_notify;         /* musical note display flag */
  50.  
  51. /*
  52. *    Local Variables
  53. */
  54. static int lastatt=255,            /* last attribute value written to screen*/
  55.     lastw=255,
  56.     thevis=0;                    /* which window is visible */
  57.  
  58. int transtable[]={      /*  Graphics translation set  */
  59.      32,  4,177,  9, 12, 13, 10,248,
  60.     241, 10, 10,217,191,218,192,197,
  61.     196,196,196,196, 95,195,180,193,
  62.     194,179,243,242,227,168,156,250,
  63.      32, 32, 32, 32, 32, 32, 32, 32,
  64.      32, 32, 32, 32 };
  65.  
  66.  
  67. /***************************************************************************/
  68. /*   map_output:
  69. *       Takes a character and converts it to the IBM PC extended character
  70. *   set which, in the outputtable array, is mapped to the output mapping
  71. *   set up in telnet.out
  72. */
  73. #define map_output(ch)  ((int)outputtable[ch-95])
  74.  
  75. /***************************************************************************/
  76. /*   translate:
  77. *       Takes a character and converts it to the IBM PC extended character
  78. *   set which, in the transtable array, is mapped to the VT100 graphics
  79. *   characters, with minor conflicts.
  80. */
  81. #define translate(ch)   ((int)((ch>94) ? transtable[ch-95] : ch))
  82.  
  83. #ifdef NOT_USED
  84. /*************************************************************************/
  85. /*
  86. *    RSokmem()
  87. *
  88. *    returns whether memory is ok (QAK ?)
  89. */
  90. unsigned int RSokmem(int size)
  91. {
  92. #ifdef MSC
  93. #if defined (__TURBOC__) | defined(__WATCOMC__)
  94.     return(1);
  95. #else
  96.     return(_freect(size));
  97. #endif
  98. #else
  99.     return(1);
  100. #endif
  101. }
  102. #endif
  103.  
  104. /*************************************************************************/
  105. /*
  106. *    RSbell()
  107. *
  108. *    rings a bell
  109. */
  110. void RSbell(int w)
  111. {
  112. /*
  113. *  might add something to indicate which window
  114. */
  115.     n_sound(1000,12);        /* PC bell routine */
  116.     if (beep_notify) {
  117.         screens[w]->sstat=14;
  118.         statline();
  119.     }
  120. }
  121.  
  122. /*************************************************************************/
  123. /*
  124. *    RSvis()
  125. *
  126. *    sets the visible window to be the window number passed to it
  127. */
  128. void RSvis(int w)
  129. {
  130.     thevis=w;                /* this is visible window */
  131. }
  132.  
  133. void RSinitall() {}
  134.  
  135. void RSinsstring(int w,int x,int y,int attrib,int len,char *s)
  136. {
  137. /* Needed for possible future functionality */
  138.     w=w;
  139.     x=x;
  140.     y=y;
  141.     attrib=attrib;
  142.     len=len;
  143.     s=s;
  144. }
  145.  
  146. void RSdelchars(int w,int x,int y,int n)
  147. {
  148. /* Needed for possible future functionality */
  149.     w=w;
  150.     x=x;
  151.     y=y;
  152.     n=n;
  153. }
  154.  
  155. void RSbufinfo(int w,int numlines,int top,int bottom)
  156. {
  157. /* Needed for possible future functionality */
  158.     w=w;
  159.     numlines=numlines;
  160.     top=top;
  161.     bottom=bottom;
  162. }
  163.  
  164. void RSdrawsep(int w,int y,int data)
  165. {
  166. /* Needed for possible future functionality */
  167.     w=w;
  168.     y=y;
  169.     data=data;
  170. }
  171.  
  172. void RSmargininfo(int w,int x,int data)
  173. {
  174. /* Needed for possible future functionality */
  175.     w=w;
  176.     x=x;
  177.     data=data;
  178. }
  179.  
  180. void RSdelcols(int w,int n)
  181. {
  182. /* Needed for possible future functionality */
  183.     w=w;
  184.     n=n;
  185. }
  186.  
  187. void RSinscols(int w,int n)
  188. {
  189. /* Needed for possible future functionality */
  190.     w=w;
  191.     n=n;
  192. }
  193.  
  194.  
  195. /*************************************************************************/
  196. void RScursoff(int w)
  197. {
  198.     w=w;
  199.         /* do nothing, MAC routine */
  200. }
  201.  
  202. /*************************************************************************/
  203. /*
  204. *    RScurson()
  205. *
  206. *    move the cursor to a x,y position on the real screen
  207. */
  208. void RScurson(int w,int y,int x)
  209. {
  210.     if(w!=thevis)
  211.         return;                            /* not visible */
  212. /*
  213. *  this is really the cursor positioning routine.  If cursor is turned off,
  214. *  then it needs to be turned back on.
  215. */
  216.     n_cur(x,y);
  217. /*  add code to save cursor position for a given window */
  218. }
  219.  
  220. /*************************************************************************/
  221. /*
  222. *    RSdraw()
  223. *
  224. *    put a string at a position on the real screen
  225. */
  226. void RSdraw(int w,int y,int x,int a,int len,unsigned char *ptr)
  227. {
  228.     int i;
  229.  
  230.     if(w!=thevis) {    /*  indicate that something happened */
  231.         x=n_row();
  232.         y=n_col();
  233.         if(screens[w]->sstat!='*') {
  234.             if(screens[w]->sstat==47)
  235.                 screens[w]->sstat=92;
  236.             else
  237.                 if(screens[w]->sstat!=14)
  238.                     screens[w]->sstat=47;
  239.           }
  240.         statline();
  241.         n_cur(x,y);                            /* restore cursor where belongs */
  242.         return;
  243.       }
  244. /*
  245. * call my own draw routine
  246. */
  247.     if(w!=lastw || a!=lastatt)         /* need to parse attribute bit */
  248.         RSsetatt(a,w);
  249.     n_cur(x,y);
  250.     if(VSisgrph(lastatt))
  251.         for(i=0; i<len; i++)
  252.             ptr[i]=(char)translate((int)ptr[i]);
  253.     else {        /* ok, we're not in graphics mode, check whether we are mapping the output for this session */
  254.         if(current->mapoutput) {    /* check whether we should map the characters output for this session */
  255.             for(i=0; i<len; i++)    /* go through the entire line, mapping the characters output to the screen */
  256.                 ptr[i]=outputtable[(unsigned char)ptr[i]];
  257.           }    /* end if */
  258.       }    /* end else */
  259.     if(Scmode())
  260.         n_cheat(ptr,len);
  261.     else
  262.         n_draw(ptr,len); 
  263. }
  264.  
  265. /*************************************************************************/
  266. /*
  267. *    RSsetatt()
  268. *
  269. *    set the attribute for real screen printing
  270. */
  271. void RSsetatt(int a,int w)
  272. {
  273.     int c;
  274.  
  275.     if(VSisundl(a))
  276.         c=screens[w]->colors[1];
  277.     else
  278.         if(VSisrev(a))
  279.             c=screens[w]->colors[2];
  280.         else
  281.             c=screens[w]->colors[0];
  282.     if(VSisblnk(a))
  283.         c |= 128;                /* set blink bit */
  284.     if(VSisbold(a))
  285.         c |= 8;                    /* set brightness bit */
  286.     n_color(c);
  287.     lastatt=a;
  288.     lastw=w;
  289. }
  290.  
  291. /*************************************************************************/
  292. /*
  293. *    RSdellines()
  294. *
  295. *    blank out a section of a series of lines
  296. */
  297. void RSdellines(int w,int t,int b,int n,int select)
  298. {
  299.     int c;
  300.  
  301.     if(w!=thevis || n<1)
  302.         return;                            /* not visible */
  303.     c=n_color(screens[w]->colors[0]);
  304.     n_scrup(n,t,0,b,79);
  305.     n_color(c);
  306.     select=select;
  307. }
  308.  
  309. /*************************************************************************/
  310. /*
  311. *    RSerase
  312. *
  313. *    blank out a reactangular section of the screen
  314. */
  315. void RSerase(int w,int y1,int x1,int y2,int x2)
  316. {
  317.     int c;
  318.  
  319.     if(w!=thevis)
  320.         return;                            /* not visible */
  321.     c=n_color(screens[w]->colors[0]);
  322.     n_scrup(0,x1,y1,x2,y2);
  323.     n_color(c);
  324. }
  325.  
  326. /*************************************************************************/
  327. /*
  328. *    RSinslines()
  329. *
  330. *    scroll down a section of the screen in order to fit lines above them
  331. */
  332. void RSinslines(int w,int t,int b,int n,int select)
  333. {
  334.     int c;
  335.  
  336.     if(w!=thevis || n<1)
  337.         return;                            /* not visible */
  338.     c=n_color(screens[w]->colors[0]);
  339.     n_scrdn(n,t,0,b,79);
  340.     n_color(c);
  341.     select=select;
  342. }
  343.  
  344. /*************************************************************************/
  345. /*
  346. *    RSsendstring()
  347. *
  348. *    send a string over the network
  349. */
  350. void RSsendstring(int w,char *ptr,int len)
  351. {
  352.     netwrite(screens[w]->pnum,ptr,len);
  353. }
  354.  
  355.  
  356. /*    Keyboard translations from the PC to VT100
  357. *        Tim Krauskopf            Sept. 1986
  358. *
  359. *    original: ISP 1984
  360. *    Re-written to handle arbitrary keyboard re-mapping,
  361. *         Quincey Koziol        Aug. 1990
  362. */
  363.  
  364. /***************************************************************************/
  365. /*  takes a key value and checks whether it is a mapped key,
  366. *        then checks whether it is a 'special' key (i.e. vt100 keys, and
  367. *        maybe other kermit verbs), pass the characters on to the
  368. *        TCP port in pnum.
  369. */
  370. void vt100key(unsigned int c)
  371. {
  372.     key_node *temp_key;        /* pointer to the key map node which matches the character code */
  373.  
  374.     if(!IS_KEY_MAPPED(c)) {        /* if the key is not mapped, just send it */
  375.         if(c<128 || (current->ibinary))       /* make certain it is just an ascii char which gets sent, unless we are transmitting binary data */
  376.             netwrite(current->pnum,(char *)&c,1);
  377.       }    /* end if */
  378.     else {        /* key is mapped */
  379.         if(IS_KEY_SPECIAL(c)) {        /* check whether this is a special key code (i.e. a kermit verb) */
  380.             if((temp_key=find_key(c))!=NULL)    /* get the pointer to the correct key mapping node */
  381.                 VSkbsend(current->vs,(unsigned char)(*temp_key).key_data.vt100_code,(int)!(current->echo));    /* send the vt100 sequence */
  382.           }    /* end if */
  383.         else {        /* just pass along the string the key is mapped to */
  384.             if((temp_key=find_key(c))!=NULL) {    /* get the pointer to the correct key mapping node */
  385.                 if((*temp_key).key_data.key_str!=NULL) {    /* verify that the string has been allocated */
  386.                     RSsendstring(current->vs,(*temp_key).key_data.key_str,strlen((*temp_key).key_data.key_str));
  387.                     if(!(current->echo))
  388.                         VSwrite(current->vs,(*temp_key).key_data.key_str,strlen((*temp_key).key_data.key_str));
  389.                   }    /* end if */
  390.               }    /* end if */
  391.           }    /* end else */
  392.       }    /* end else */
  393. }   /* end vt100key() */
  394.  
  395. /***********************************************************************/
  396. /*  non-blocking RSgets()
  397. *   This routine will continually add to a string that is re-submitted
  398. *   until a special character is hit.  It never blocks.
  399. *
  400. *   As long as editing characters (bksp, Ctrl-U) and printable characters
  401. *   are pressed, this routine will update the string.  When any other special
  402. *   character is hit, that character is returned.  
  403. */
  404. static char bk[]={8,' ',8};
  405.  
  406. int RSgets(int w,char *s,int lim,char echo)
  407. {
  408.     int c,count,i;
  409.     char *save;
  410.  
  411.     count=strlen(s);
  412.     save=s;
  413.     s+=count;
  414.     while(0<(c=n_chkchar())) {
  415.         switch(c) {                 /* allow certain editing chars */
  416.             case 8:                    /* backspace */
  417.             case BACKSPACE:            /* backspace */
  418.                 if(count) {
  419.                     if(echo)
  420.                         VSwrite(w,bk,3);
  421.                     count--;        /* one less character */
  422.                     s--;            /* move pointer backward */
  423.                   } /* end if */
  424.                 break;
  425.  
  426.             case 21:
  427.                 if(echo)
  428.                     for(i=0; i<s-save; i++)
  429.                         VSwrite(w,bk,3);
  430.                 s=save;
  431.                 break;
  432.  
  433.             case 13:
  434.             case 9:
  435.             case TAB:
  436.                 *s='\0';            /* terminate the string */
  437.                 return(c);
  438.  
  439.             default:
  440.                 if(count==lim) {            /* to length limit */
  441.                     RSbell(w);
  442.                     *s='\0';                /* terminate */
  443.                     return(0);
  444.                   }
  445.                 if(c>31 && c<127) { /* check for printable ASCII */
  446.                     if(echo)
  447.                         VSwrite(w,(char *)&c,1);
  448.                     *s++=(char)c;            /* add to string */
  449.                     count++;                /* length of string */
  450.                   }
  451.                 else {
  452.                     if(c>0 && c<27) {   /* print ASCII control char */
  453.                         c+=64;
  454.                         if(echo) {
  455.                             VSwrite(w,"^",1);
  456.                             VSwrite(w,(char *)&c,1);
  457.                           }
  458.                         c-=64;
  459.                       }
  460.                     *s='\0';            /* terminate the string */
  461.                     return(c);
  462.                   }
  463.             break;
  464.           }
  465.       }
  466.     *s='\0';            /* terminate the string */
  467.     return(c);
  468. }
  469.  
  470. /***********************************************************************/
  471. /*  non-blocking gets()
  472. *   This routine will call netsleep while waiting for keypresses during
  473. *   a gets.  Replaces the library gets.
  474. *
  475. *   As long as editing characters (bksp, Ctrl-U) and printable characters
  476. *   are pressed, this routine will continue.  When any other special
  477. *   character is hit, NULL is returned.  the return key causes a normal return.
  478. */
  479. char *nbgets(char *s,int lim)
  480. {
  481.     int c,count,i;
  482.     char *save;
  483.  
  484.     count=0;
  485.     save=s;
  486.     while(1) {
  487.         c=n_chkchar();
  488.         if(c<=0) {
  489.             Stask();            /* keep communications going */
  490.             continue;            /* check for a character immediately */
  491.           }
  492.         switch (c) {                /* allow certain editing chars */
  493.             case 8:                    /* backspace */
  494.             case BACKSPACE:            /* backspace */
  495.                 if(count) {
  496.                     n_putchar((char)8);
  497.                     n_putchar(' ');
  498.                     n_putchar((char)8);
  499.                     count--;        /* one less character */
  500.                     s--;            /* move pointer backward */
  501.                   }
  502.                 break;
  503.  
  504.             case 13:                    /* carriage return,=ok */
  505.                 n_puts("");
  506.                 *s='\0';                /* terminate the string */
  507.                 return((char *)save);    /* return ok */
  508.  
  509.             case 21:        /* ctrl-u */
  510.                 for(i=0; i<s-save; i++) {
  511.                     n_putchar(8);
  512.                     n_putchar(' ');
  513.                     n_putchar(8);
  514.                   }
  515.                 s=save;
  516.                 break;
  517.  
  518.             default:
  519.                 if(c>31 && c<127) {
  520.                     if(count<lim) {
  521.                         n_putchar((char)c);
  522.                         *s++=(char)c;            /* add to string */
  523.                         count++;                /* length of string */
  524.                       }
  525.                   }
  526.                 else {
  527.                     n_puts("");
  528.                     *s='\0';            /* terminate the string */
  529.                     return((char *)NULL);
  530.                   }
  531.             break;
  532.           }
  533.       }
  534. }
  535.  
  536. /************************************************************************/
  537. /*  nbgetch
  538. *   check the keyboard for a character, don't block to wait for it,
  539. *   but don't return to the caller until it is there.
  540. */
  541. int nbgetch(void)
  542. {
  543.     int c;
  544.  
  545.     while(0>=(c=n_chkchar()))         /* there is a key? */
  546.         Stask();                    /* no key yet, update everything */
  547.     return(c);
  548. }
  549.  
  550. #ifdef NOT_USED
  551. /************************************************************************/
  552. /* nbget
  553. *   demux at least one packet each time, check the keyboard for a key, 
  554. *   return any key pressed to the caller.
  555. */
  556. int nbget(void)
  557. {
  558.     int c;
  559.  
  560.     demux(0);                /* only one packet */
  561.     if(0>=(c=n_chkchar()))
  562.         return(-1);            /* no key ready */
  563.     return(c);
  564. }
  565. #endif
  566.  
  567. /***********************************************************************/
  568. /* ftpstart
  569. *  update status line with new file length remaining
  570. */
  571. void ftpstart(char dir,char *buf)
  572. {
  573.     int r,c,cl;
  574.     long int fpos;
  575.  
  576.     r=n_row();
  577.     c=n_col();
  578.     cl=n_color(current->colors[0]);
  579.     if(dir)
  580.         dir='<';
  581.     else
  582.         dir='>';
  583.     Sftpname(&buf[100]);    /* get file name */
  584.     Sftpstat(&fpos);        /* get position in file */
  585.     n_cur(numline+1,49);
  586.     sprintf(buf,"FTP %c %14s %10lu",dir,&buf[100],fpos);
  587.     if(Scmode()) 
  588.         n_cheat(buf,strlen(buf));
  589.     else
  590.         n_draw(buf,strlen(buf));
  591.     n_color(cl);
  592.     n_cur(r,c);
  593. }
  594.