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