home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / NCSATELN / TEL23SRC.ZIP / VS / VSINTERN.C < prev   
Encoding:
C/C++ Source or Header  |  1991-08-21  |  18.3 KB  |  886 lines

  1. #ifdef lint
  2. static char *SCCSid="%W%    (NCSA)    %G%";
  3. #endif
  4. /*
  5.  *
  6.  *      Virtual Screen Kernel Internal Routines
  7.  *                      (vsintern.c)
  8.  *  National Center for Supercomputing Applications
  9.  *
  10.  *      by Gaige B. Paulsen
  11.  *
  12.  *    This file contains the private internal calls for the NCSA
  13.  *  Virtual Screen Kernel.
  14.  *
  15.  *        Version Date    Notes
  16.  *        ------- ------  ---------------------------------------------------
  17.  *        0.01    861102  Initial coding -GBP
  18.  *        0.50    861113  First compiled edition -GBP
  19.  *        0.70    861114  Internal operation confirmed -GBP
  20.  *        2.1        871130    NCSA Telnet 2.1 -GBP
  21.  *        2.2     880715    NCSA Telnet 2.2 -GBP
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #ifdef MSC
  28. #include <malloc.h>
  29. #endif
  30. #ifdef MEMORY_DEBUG
  31. #include "memdebug.h"
  32. #endif
  33. #include "vsdata.h"
  34. #include "vskeys.h"
  35. #include "externs.h"
  36.  
  37. #define AL(x) VSIw->attrst[x]
  38. #define VL(x) VSIw->linest[x]
  39. #define vtp VSIw->top
  40. #define btm VSIw->bottom
  41. #define VSIclrattrib 0
  42. #define Rrt VSIw->Rright
  43. #define Rlt VSIw->Rleft
  44. #define Rtp VSIw->Rtop
  45. #define Rbm VSIw->Rbottom
  46.  
  47. /* clip a requested area of the screen to the actuall virtual screen window */
  48. int VSIclip(x1,y1,x2,y2,n,offset)
  49. int *x1,        /* the requested left edge */
  50.     *x2,        /* the requested right edge */
  51.     *y1,        /* the requested top edge */
  52.     *y2,        /* the requested bottom edge */
  53.     *n,            /* the requested width of the virtual window */
  54.     *offset;
  55. {
  56.     if(*n>=0) {     /* set the requested right edge of the window */
  57.         *x2=*x1+*n-1; 
  58.         *y2=*y1; 
  59.       }    /* end if */
  60.     if((*x1>Rrt) || (*y2<Rtp))        /* check for invalid invalid left and bottom edges */
  61.         return(-1);
  62.     if(*x2>Rrt)        /* clip the right edge to the right edge of the virtual screen */
  63.         *x2=Rrt;
  64.     if(*y2>Rbm)        /* clip the bottom edge to the bottom edge of the virtual screen */
  65.         *y2=Rbm;
  66.  
  67.     *x1-=Rlt;         /* adjust to represent actual screen coor. */
  68.     *x2-=Rlt;
  69.     *y1-=Rtp; 
  70.     *y2-=Rtp;
  71.  
  72.     *offset=-*x1; 
  73.     if(*offset<0)
  74.         *offset=0;
  75.     if(*x1<0)        /* clip left edge to top of virtual screen */
  76.         *x1=0;
  77.     if(*y1<0)        /* clip top edge to top of virtual screen */
  78.         *y1=0;
  79.     *n=*x2-*x1+1;    /* set the width of the clipped region */
  80.     if((*n<=0) || (*y2-*y1<0)) /* check whether the clipped region really exists */
  81.         return(-1);
  82.     return(0);
  83. }
  84.  
  85. int VSIcdellines(w,top,bottom,n,scrolled)
  86. int w,
  87.     top,bottom,
  88.     n,
  89.     scrolled;
  90. {
  91.     int x1=0,
  92.         x2=VSIw->maxwidth,
  93.         tn=(-1),
  94.         offset;
  95.  
  96.     if(VSIclip(&x1,&top,&x2,&bottom,&tn,&offset))
  97.         return(-1);
  98.     tn=bottom-top;
  99.     if(tn<n) 
  100.         n=tn;
  101.     RSdellines(w,top,bottom,n,scrolled);
  102.     return(0);                /* I delete the whole thing! */
  103. }
  104.  
  105. int VSIcinslines(w,top,bottom,n,scrolled)
  106. int w,
  107.     top,
  108.     bottom,
  109.     n,
  110.     scrolled;
  111. {
  112.     int x1=0,
  113.         x2=VSIw->maxwidth,
  114.         tn=(-1),
  115.         offset;
  116.  
  117.     if(VSIclip(&x1,&top,&x2,&bottom,&tn,&offset))
  118.         return(-1);
  119.     tn=bottom-top;
  120.     if(tn<n) 
  121.         n=tn;
  122.     RSinslines(w,top,bottom,n,scrolled);
  123.     return(0);
  124. }
  125.  
  126. void VSIcurson(w,x,y,ForceMove)
  127. int w,
  128.     x,y,
  129.     ForceMove;
  130. {
  131.     int 
  132. #ifdef OLD_WAY
  133.         ox=x,oy=y,
  134. #endif
  135.         x2,y2,
  136.         n=1,
  137.         offset;
  138.  
  139.     if(!VSIclip(&x,&y,&x2,&y2,&n,&offset)) 
  140.         RScurson(w,x,y);
  141.     else 
  142.         if(ForceMove) {
  143.             x2=Rbm-Rtp;
  144.             if(x2>=VSPBOTTOM)
  145.                 VSsetrgn(VSIwn,Rlt,VSPBOTTOM-x2,Rrt,VSPBOTTOM);
  146.             else {
  147.                 if(y>0) 
  148.                     VSscrolforward(VSIwn,y);
  149.                 else     
  150.                     VSscrolback(VSIwn,-y);
  151.               }    /* end else */
  152. /* Restore from previous */
  153. #ifdef OLD_WAY
  154.             x=ox; 
  155.             y=oy;
  156.             n=1;
  157.             if(!VSIclip(&x,&y,&x2,&y2,&n,&offset)) 
  158.                 RScurson(w,x,y);
  159. #endif
  160.           }    /* end if */
  161. }
  162.  
  163. void VSIcuroff(w)
  164. int w;
  165. {
  166.     int x=VSIw->x,
  167.         y=VSIw->y,
  168.         x2,y2,
  169.         n=1,
  170.         offset;
  171.  
  172.     if(!VSIclip(&x,&y,&x2,&y2,&n,&offset)) 
  173.         RScursoff(w);
  174. }
  175.  
  176. VSline *VSInewline(void )
  177. {
  178.     VSline *t2;
  179.     char *t;
  180.  
  181.     if((t=malloc(VSIw->allwidth+1)) !=NULL) {
  182.         if((t2=(VSline *)malloc(sizeof(VSline))) !=NULL)
  183.             t2->text=t;
  184.         else {                         /* Return on bad malloc */
  185.             free(t); 
  186.             return(NULL); 
  187.           } /* end else */
  188.       }    /* end if */
  189.     else  
  190.         return(NULL);            /* Return on bad malloc */
  191.     t2->next=t2->prev=NULL;
  192.     return(t2);
  193. }
  194.  
  195. void VSIlistndx(ts,as)
  196. VSline *ts,*as;
  197. {
  198.     int i;
  199.  
  200.     for(i=0; i<=VSPBOTTOM; i++) {
  201.         AL(i)=as;
  202.         VL(i)=ts;
  203.         ts=ts->next;
  204.         as=as->next;
  205.       }    /* end for */
  206. }
  207.  
  208. void VSIscroff()
  209. {
  210.     VSline *tmp;
  211.     int i;
  212.  
  213.     if(VL(VSPBOTTOM)->next !=NULL) {
  214.         for(i=0; i<=VSPBOTTOM; i++) {
  215.             if(VL(VSPBOTTOM)->next==VSIw->buftop)
  216.                 VSIw->buftop=VSIw->buftop->next;    /* if we are in old terr. loop */
  217.             VSIw->scrntop=VSIw->scrntop->next;
  218.             VSIlistndx(VSIw->scrntop,AL(1));
  219.           }
  220.       }
  221.     else {
  222.         for(i=0; i<=VSPBOTTOM; i++) {
  223.             if((VSIw->numlines<VSIw->maxlines)&&(tmp=VSInewline()) !=NULL ) {
  224.                     VL(VSPBOTTOM)->next=tmp;            /* ADD A LINE */
  225.                     tmp->prev=VL(VSPBOTTOM);
  226.                     VSIw->numlines++;
  227.               }
  228.             else {
  229.                 if(VL(VSPBOTTOM)->next==NULL) {
  230.                     VL(VSPBOTTOM)->next=VSIw->buftop;    /* Make it circular */
  231.                     VSIw->buftop->prev=VL(VSPBOTTOM);
  232.                   }
  233.                 if(VL(VSPBOTTOM)->next==VSIw->buftop)
  234.                     VSIw->buftop=VSIw->buftop->next;/* if we are in old terr. loop*/
  235.               }
  236.             VSIw->scrntop=VSIw->scrntop->next;
  237.             VSIlistndx(VSIw->scrntop,AL(1));
  238.           }
  239.         RSbufinfo(VSIwn,VSIw->numlines,VSIw->Rtop,VSIw->Rbottom);
  240.       }
  241. }
  242.  
  243. void VSIelo(s)
  244. int s;
  245. {
  246.     char *tt,*ta;
  247.     int i;
  248.  
  249. /*    VSIwrapnow(&i,&j); */
  250.     if(s<0) 
  251.         s=VSIw->y;
  252.     ta=&AL(s)->text[0];
  253.     tt=&VL(s)->text[0];
  254.     for(i=0; i<=VSIw->allwidth; i++) {
  255.         *ta++=VSIclrattrib;
  256.         *tt++=' ';
  257.       }    /* end for */
  258. }
  259.  
  260. void VSIes(void)
  261. {
  262.     int i;
  263.     int x1=0,y1=0,
  264.         x2=VSIw->maxwidth,y2=VSPBOTTOM,
  265.         n=(-1),
  266.         offset;
  267.  
  268.     if(VSIw->ESscroll)
  269.         VSIscroff();
  270.     for(i=0; i<=VSPBOTTOM; i++)
  271.         VSIelo(i);
  272.     if(!VSIclip(&x1,&y1,&x2,&y2,&n,&offset)) 
  273.         RSerase(VSIwn,x1,y1,x2,y2);
  274.     VSIw->vistop=VSIw->scrntop;
  275. }
  276.  
  277. void VSItabclear(void)
  278. {
  279.     int x=0;
  280.  
  281.     while(x<=VSIw->allwidth) {
  282.         VSIw->tabs[x]=' ';
  283.         x++;
  284.       }    /* end while */
  285. }
  286.  
  287. void VSItabinit()
  288. {
  289.     int x=0;
  290.  
  291.     VSItabclear();
  292.  
  293.     while(x<=VSIw->allwidth) { 
  294.         VSIw->tabs[x]='x';
  295.         x+=8;
  296.       }    /* end while */
  297.     VSIw->tabs[VSIw->allwidth]='x';
  298. }
  299.  
  300. void VSIreset()
  301. {
  302.     VSIw->top=0;
  303.     VSIw->bottom=VSPBOTTOM;
  304.     VSIw->parmptr=0;
  305.     VSIw->escflg=0;
  306.     VSIw->DECAWM=0;
  307.     VSIw->DECCKM=0;
  308.     VSIw->DECPAM=0;
  309. /*     VSIw->DECORG=0;        */
  310. /*     VSIw->Pattrib=-1;    */
  311.     VSIw->IRM=0;
  312.     VSIw->attrib=0;
  313.     VSIw->x=0;
  314.     VSIw->y=0;
  315.     VSIw->charset=0;
  316.     VSIes();
  317.     VSItabinit();
  318.     set_vtwrap(VSIwn,VSIw->DECAWM);        /* QAK - 7/27/90: added because resetting the virtual screen's wrapping flag doesn't reset telnet window's wrapping */
  319. }
  320.  
  321. void VSIlistmove(TD,BD,TI,BI)
  322. VSline *TD,*BD,*TI,*BI;
  323. {
  324.     if(TD->prev!=NULL) 
  325.         TD->prev->next=BD->next;    /* Maintain circularity */
  326.     if(BD->next!=NULL) 
  327.         BD->next->prev=TD->prev;
  328.     TD->prev=TI;                    /* Place the node in its new home */
  329.     BD->next=BI;
  330.     if(TI!=NULL) 
  331.         TI->next=TD;                /* Ditto prev->prev */
  332.     if(BI!=NULL) 
  333.         BI->prev=BD;
  334. }
  335.  
  336. void VSIdellines(n,s)
  337. int n,s;
  338. {
  339.     int i,j,
  340.         attop=(VSIw->vistop==VSIw->scrntop);
  341.     char *ta,*tt;
  342.     VSline *as,*ts,
  343.         *TD,*BD,
  344.         *TI,*BI,
  345.         *itt,*ita;
  346.  
  347.     if(s<0) 
  348.         s=VSIw->y;
  349.     if(s+n-1>VSIw->bottom) 
  350.         n=VSIw->bottom -s +1;
  351.     ts=VL(0)->prev;
  352.     TD=VL(s);
  353.     BD=VL(s+n-1);
  354.     TI=VL(VSIw->bottom);
  355.     BI=TI->next;
  356.     itt=TD;
  357.     if(TI!=BD)
  358.         VSIlistmove(TD,BD,TI,BI);
  359.     if(s==0 || n>VSPBOTTOM) 
  360.         as=AL(n);
  361.     else 
  362.         as=AL(0);
  363.     TD=AL(s);
  364.     BD=AL(s+n-1);
  365.     TI=AL(VSIw->bottom);
  366.     BI=TI->next;
  367.     if(TD!=BI&&TI!=BD)
  368.         VSIlistmove(TD,BD,TI,BI);
  369.     ita=TD;
  370.     for(i=0; i<n; i++) {
  371.         ta=ita->text;
  372.         tt=itt->text;
  373.         for(j=0; j<=VSIw->allwidth; j++) {
  374.             *tt++=' ';
  375.             *ta++=VSIclrattrib;
  376.           }    /* end for */
  377.         ita=ita->next;
  378.         itt=itt->next;
  379.       }    /* end for */
  380.     VSIw->scrntop=ts->next;
  381.     if(attop) 
  382.         VSIw->vistop=VSIw->scrntop;
  383.     VSIlistndx(ts->next,as);
  384.     VSIcdellines(VSIwn,s,VSIw->bottom,n,-1);        /* Destroy selection area if this is called */
  385. }
  386.  
  387. void VSIinslines(n,s)
  388. int n,s;
  389. {
  390.     int i,j,
  391.         attop=(VSIw->vistop==VSIw->scrntop);
  392.     char *ta,*tt;
  393.     VSline *as,*ts,
  394.         *TD,*BD,
  395.         *TI,*BI,
  396.         *itt,*ita;
  397.  
  398.     if(s<0) 
  399.         s=VSIw->y;
  400.     if(s+n-1>VSIw->bottom) 
  401.         n=VSIw->bottom -s +1;
  402.     ts=VL(0)->prev;
  403.     BI=VL(s);
  404.     TI=BI->prev;
  405.     TD=VL(VSIw->bottom-n+1);
  406.     BD=VL(VSIw->bottom);
  407.     itt=TD;
  408.     if(TD!=BI) 
  409.         VSIlistmove(TD,BD,TI,BI);
  410.     if(s==0 || n>VSPBOTTOM) 
  411.         as=AL(VSIw->bottom-n+1);
  412.     else 
  413.         as=AL(0);
  414.     BI=AL(s);
  415.     TI=BI->prev;
  416.     TD=AL(VSIw->bottom-n+1);
  417.     BD=AL(VSIw->bottom);
  418.     if(TD!=BI && TI!=BD)
  419.         VSIlistmove(TD,BD,TI,BI);
  420.     ita=TD;
  421.     for(i=0; i<n; i++) {
  422.         tt=itt->text;
  423.         ta=ita->text;
  424.         for(j=0; j<=VSIw->allwidth; j++) {
  425.             *tt++=' ';
  426.             *ta++=VSIclrattrib;
  427.           }    /* end for */
  428.         itt=itt->next;
  429.         ita=ita->next;
  430.       }    /* end for */
  431.     VSIw->scrntop=ts->next;
  432.     if(attop) 
  433.         VSIw->vistop=VSIw->scrntop;
  434.     VSIlistndx(ts->next,as);
  435.     VSIcinslines(VSIwn,s,VSIw->bottom,n,-1);  /* Destroy selection area if this is called tooo */
  436. }
  437.  
  438. /* scroll the virtual screen up one line */
  439. void VSIscroll(void)
  440. {
  441.     char *temp,*tempa;
  442.     VSline *tmp;
  443.     int i;
  444.     int tx1=0,ty1=0,
  445.         tx2,ty2,
  446.         tn=132,
  447.         offset;
  448.  
  449.     if(!VSIclip(&tx1,&ty1,&tx2,&ty2,&tn,&offset))
  450.         RSdrawsep(VSIwn,ty1,1);                    /* Draw Separator */
  451.     if((!VSIw->savelines) || (VSIw->top!=0) || (VSIw->bottom!=VSPBOTTOM))    /* if we are not using scroll back, or still in the middle of the screen, delete the line which scroll off the top */
  452.         VSIdellines(1,VSIw->top);
  453.     else {
  454.         if((VL(VSPBOTTOM)->next==NULL) && (VSIw->numlines<VSIw->maxlines) && (tmp=VSInewline())!=NULL) {
  455.             VL(VSPBOTTOM)->next=tmp;            /* ADD A LINE to the scroll back list */
  456.             tmp->prev=VL(btm);
  457.             VSIw->numlines++;
  458.             RSbufinfo(VSIwn,VSIw->numlines,VSIw->Rtop,VSIw->Rbottom);
  459.           }    /* end if */
  460.         else {
  461.             if(VL(btm)->next==NULL) {
  462.                 VL(btm)->next=VSIw->buftop;    /* Make it circular */
  463.                 VSIw->buftop->prev=VL(btm);
  464.               }    /* end if */
  465.             if(VL(btm)->next==VSIw->buftop)
  466.                 VSIw->buftop=VSIw->buftop->next;    /* if we are in old terr. loop*/
  467.           }    /* end else */
  468. #ifdef OLD_WAY
  469.         attop=(VSIw->vistop==VSIw->scrntop);        /* set this when scrollback isn't possible yet */
  470. #endif
  471.         VSIw->scrntop=VSIw->scrntop->next;        /* move the top of the screen down one position */
  472.         VSIlistndx(VSIw->scrntop,AL(1));
  473.         if(VSIcdellines(VSIwn,VSIw->Rtop,VSIw->Rbottom,1,1)) {        /* scroll real screen up, but Dont destroy select */
  474.                 /* If we did not show on screen then we must do this */
  475.             if(VSIw->Rtop>-VSIw->numlines) {    /* If we are not at the top..... */
  476.                 VSIw->Rtop--;                    /* Then we should move down  */
  477.                 VSIw->Rbottom--;
  478.               }
  479.             else {                                /* But if we're at the top.... */
  480.                                                 /* The region remains the same .. */
  481.                 VSIw->vistop=VSIw->vistop->next;/* and move the vistop as */
  482.                 RSdellines(VSIwn,0,Rbm-Rtp,1,1);/* we also delete the top line */
  483.               }                                /* well.... (but don't destroy selection)  */
  484.           }
  485.         else {
  486.             VSIw->vistop=VSIw->vistop->next;
  487.           }
  488.         tempa=AL(VSPBOTTOM)->text;
  489.         temp=VL(VSPBOTTOM)->text;
  490.         for(i=0;i<=VSIw->allwidth; i++) {
  491.             temp[i]=' ';
  492.             tempa[i]=0;
  493.           }
  494.       }    /* end else */
  495.     tx1=ty1=0;
  496.     tn=132;
  497.     if(!VSIclip(&tx1,&ty1,&tx2,&ty2,&tn,&offset))
  498.         RSdrawsep(VSIwn,ty1,1);                    /* Draw Separator */
  499. }
  500.  
  501. /* increment the y position we are on in the virtual screen, and check whether
  502.  *    that means we need to scroll
  503. */
  504. void VSIindex(void)
  505. {
  506. #ifdef OLD_WAY
  507.     if(++VSIw->y > VSIw->bottom) {
  508.         VSIw->y=VSIw->bottom;
  509.         VSIscroll();
  510.       }    /* end if */
  511. #endif
  512.      if(VSIw->y==VSIw->bottom)
  513.          VSIscroll();
  514.      else
  515.          VSIw->y++;
  516. }
  517.  
  518. void VSIwrapnow(xp,yp)
  519. int *xp,*yp;
  520. {
  521.     if(VSIw->x > VSIw->maxwidth) {
  522.         VSIw->x=0;
  523.         VSIindex();
  524.       }    /* end if */
  525.     *xp=VSIw->x;
  526.     *yp=VSIw->y;
  527. }
  528.  
  529. void VSIeeol(void)
  530. {
  531.     char *tt,*ta;
  532.     int x1=VSIw->x,y1=VSIw->y,
  533.         x2=VSIw->maxwidth,y2=VSIw->y,
  534.         n=(-1),
  535.         offset;
  536.     register int i;
  537.  
  538.     VSIwrapnow(&x1,&y1);
  539.     y2=y1;
  540.     ta=&AL(y1)->text[x1];
  541.     tt=&VL(y1)->text[x1];
  542.     for(i=VSIw->allwidth-x1+1; i>0; i--) {
  543.         *ta++=VSIclrattrib;
  544.         *tt++=' ';
  545.       }    /* end for */
  546.     if(!VSIclip(&x1,&y1,&x2,&y2,&n,&offset)) 
  547.         RSerase(VSIwn,x1,y1,x2,y2);
  548. }
  549.  
  550. void VSIdelchars(x)
  551. int x; 
  552. {
  553.     int i;
  554.     int x1=VSIw->x,y1=VSIw->y,
  555.         x2=VSIw->maxwidth,y2=VSIw->y,
  556.         n=(-1),
  557.         offset;
  558.     char *tempa,*temp;
  559.  
  560.     VSIwrapnow(&x1,&y1);
  561.     y2=y1;
  562.     if(x>VSIw->maxwidth) 
  563.         x=VSIw->maxwidth;
  564.     tempa=VSIw->attrst[y1]->text;
  565.     temp=VSIw->linest[y1]->text;
  566.     for(i=x1; i<=VSIw->maxwidth-x; i++) {
  567.         temp[i]=temp[x+i];
  568.         tempa[i]=tempa[x+i];
  569.       }    /* end for */
  570.     for(i=VSIw->maxwidth-x+1; i<=VSIw->allwidth; i++) {
  571.         temp[i]=' ';
  572.         tempa[i]=VSIclrattrib;
  573.       }    /* end for */
  574.     if(!VSIclip(&x1,&y1,&x2,&y2,&n,&offset))
  575.         if(VSIw->VSIDC)
  576.             RSdelchars(VSIwn,x1,y1,x);
  577.         else
  578.             RSdraw(VSIwn,x1,y1,VSIw->attrib,n,&VSIw->linest[y1]->text[x1]);
  579. }
  580.  
  581. void VSIrindex(void)
  582. {
  583. #ifdef OLD_WAY
  584.     if(--VSIw->y < VSIw->top ) {
  585.         VSIw->y=VSIw->top;
  586.         VSIinslines(1,VSIw->top);
  587.       }    /* end if */
  588. #endif
  589.     if(VSIw->y==VSIw->top)
  590.         VSIinslines(1,VSIw->top);
  591.     else
  592.         VSIw->y--;
  593. }
  594.  
  595. void VSIebol(void)
  596. {
  597.     char *tt,*ta;
  598.     int x1=0,y1=VSIw->y,
  599.         x2=VSIw->x,y2=VSIw->y,
  600.         n=(-1),
  601.         offset;
  602.     register int i;
  603.  
  604.     VSIwrapnow(&x2,&y1);
  605.     y2=y1;
  606.     ta=&AL(y1)->text[0];
  607.     tt=&VL(y1)->text[0];
  608.     for(i=0;i<=x2; i++) {
  609.         *ta++=VSIclrattrib;
  610.         *tt++=' ';
  611.       }    /* end for */
  612.     if(!VSIclip(&x1,&y1,&x2,&y2,&n,&offset)) 
  613.         RSerase(VSIwn,x1,y1,x2,y2);
  614. }
  615.  
  616. void VSIel(s)
  617. int s;
  618. {
  619.     char *tt,*ta;
  620.     int x1=0,y1=s,
  621.         x2=VSIw->maxwidth,y2=s,
  622.         n=(-1),
  623.         offset;
  624.     register int i;
  625.  
  626.     if(s<0) {
  627.         VSIwrapnow(&x1,&y1);
  628.         s=y2=y1;
  629.         x1=0;
  630.       }    /* end if */
  631.     ta=&AL(s)->text[0];
  632.     tt=&VL(s)->text[0];
  633.     for(i=0; i<=VSIw->allwidth; i++) {
  634.         *ta++=VSIclrattrib;
  635.         *tt++=' ';
  636.       }    /* end for */
  637.     if(!VSIclip(&x1,&y1,&x2,&y2,&n,&offset)) 
  638.         RSerase(VSIwn,x1,y1,x2,y2);
  639. }
  640.  
  641. void VSIeeos(void)
  642. {
  643.     register int i;
  644.     int x1=0,y1=VSIw->y+1,
  645.         x2=VSIw->maxwidth,y2=VSPBOTTOM,
  646.         n=(-1),
  647.         offset;
  648.  
  649.     VSIwrapnow(&x1,&y1);
  650.     y1++;
  651.     x1=0;
  652.     i=y1;
  653.     if(!VSIclip(&x1,&y1,&x2,&y2,&n,&offset)) 
  654.         RSerase(VSIwn,x1,y1,x2,y2);
  655.     VSIeeol();
  656.     while(i<=VSPBOTTOM) {
  657.         VSIelo(i);
  658.         i++;
  659.       }    /* end while */
  660.     if(VSIw->y < VSPBOTTOM && (VSIw->x <= VSIw->maxwidth))
  661.         if(!VSIclip(&x1,&y1,&x2,&y2,&n,&offset)) 
  662.             RSerase(VSIwn,x1,y1,x2,y2);
  663. }
  664.  
  665. void VSIebos(void)
  666. {
  667.     register int i;
  668.     int x1,y1,
  669.         x2=VSIw->maxwidth,y2,
  670.         n=(-1),
  671.         offset;
  672.  
  673.     VSIwrapnow(&x1,&y1);
  674.     y2=y1-1;
  675.     x1=0;
  676.     y1=0;
  677.     VSIebol();
  678.     i=0;
  679.     while(i<(y2+1))    {            /* Equiv of VSIw->y */
  680.         VSIelo(i);
  681.         i++;
  682.       }    /* end while */
  683.     if(y2>=0)                         /* Equiv of VSIw->y>0 */
  684.         if(!VSIclip(&x1,&y1,&x2,&y2,&n,&offset)) 
  685.             RSerase(VSIwn,x1,y1,x2,y2);
  686. }
  687.  
  688. void VSIrange(void)                  /* check and resolve range errors on x and y */
  689. {
  690.     int wrap=0;
  691.  
  692.     if(VSIw->DECAWM)
  693.         wrap=1;
  694.     if(VSIw->x<0)
  695.         VSIw->x=0;
  696.     if(VSIw->x>(VSIw->maxwidth+wrap))
  697.         VSIw->x=VSIw->maxwidth+wrap;
  698.     if(VSIw->y<0)
  699.         VSIw->y=0;
  700.     if(VSIw->y>VSPBOTTOM)
  701.         VSIw->y=VSPBOTTOM;
  702. }
  703.  
  704. void VTsendpos(void)        /* send cursor position to host */
  705. {
  706.     char tempbuf[15];
  707.     int x=VSIw->x,
  708.         y=VSIw->y;
  709.  
  710.     if(x > VSIw->maxwidth) {
  711.         x=0;
  712.         y++;
  713.       }    /* end if */
  714.     if(y>VSPBOTTOM) 
  715.         y=VSPBOTTOM;
  716.     sprintf(tempbuf,"\033[%d;%dR",y+1,x+1);
  717.     RSsendstring(VSIwn,tempbuf,strlen(tempbuf));
  718. }
  719.  
  720. void VTsendstat(void)        /* send OK status back to host */
  721. {
  722.     RSsendstring(VSIwn,"\033[0n",4);
  723. }
  724.  
  725. void VTsendident(void)        /* send terminal capabilities to host */
  726. {
  727. #define THISWAY
  728. #ifdef THISWAY
  729.     RSsendstring(VSIwn,"\033[?6c",5);       /* GPO & AVO options supported */
  730. #else
  731.     RSsendstring(VSIwn,"\033[?1c",5);       /* GPO & AVO options supported */
  732. #endif
  733. }
  734.  
  735. void VTalign(void)    /* vt100 alignment, fill screen with 'E's */
  736. {
  737.     char *tt;
  738.     register int i,j;
  739.  
  740.     VSIes();        /* erase the screen */
  741.  
  742.     for(j=0; j<VSPBOTTOM; j++) {
  743.         tt=&VL(j)->text[0];
  744.         for(i=0; i<=VSIw->maxwidth; i++)
  745.             *tt++='E';
  746.       }    /* end for */
  747.     VSredraw(VSIwn,0,0,(VSIw->Rright-VSIw->Rleft),(VSIw->Rbottom-VSIw->Rtop));
  748. }
  749.  
  750. /* reset all the ANSI parameters back to the default state */
  751. void VSIapclear(void)
  752. {
  753.     for(VSIw->parmptr=5; VSIw->parmptr>=0; VSIw->parmptr--)
  754.         VSIw->parms[VSIw->parmptr]=-1;
  755.     VSIw->parmptr=0;
  756. }
  757.  
  758. void VSIsetoption(toggle)
  759. int toggle;
  760. {
  761.     int WindWidth=(VSIw->Rright-VSIw->Rleft);
  762.  
  763.     switch(VSIw->parms[0]) {
  764.         case -2:
  765.             switch(VSIw->parms[1]) {
  766.                 case 1:        /* set/reset cursor key mode */
  767.                     VSIw->DECCKM=toggle;
  768.                     break;
  769.  
  770. #ifdef NOT_SUPPORTED
  771.                 case 2:        /* set/reset ANSI/vt52 mode */
  772.                     break;
  773. #endif
  774.  
  775.                 case 3:        /* set/reset column mode */
  776.                     VSIw->x=VSIw->y=0;      /* Clear the screen, mama! */
  777.                     VSIes();
  778.                     if(toggle)        /* 132 column mode */
  779.                         VSIw->maxwidth=VSIw->allwidth;
  780.                     else
  781.                         VSIw->maxwidth=79;
  782.                     RSmargininfo(VSIwn,VSIw->maxwidth-WindWidth,VSIw->Rleft);
  783.                     break;
  784.  
  785. #ifdef NOT_SUPPORTED
  786.                 case 4:        /* set/reset scrolling mode */
  787.                 case 5:        /* set/reset screen mode */
  788.                 case 6:        /* set/rest origin mode */
  789.                     VSIw->DECORG = toggle;
  790.                     break;
  791. #endif
  792.  
  793.                 case 7:        /* set/reset wrap mode */
  794.                     VSIw->DECAWM=toggle;
  795.                     set_vtwrap(VSIwn,VSIw->DECAWM);        /* QAK - 7/27/90: added because resetting the virtual screen's wrapping flag doesn't reset telnet window's wrapping */
  796.                     break;
  797.  
  798. #ifdef NOT_SUPPORTED
  799.                 case 8:        /* set/reset autorepeat mode */
  800.                 case 9:        /* set/reset interlace mode */
  801.                     break;
  802. #endif
  803.  
  804.                 default:
  805.                     break;
  806.               }    /* end switch */
  807.             break;
  808.  
  809.         case 4:
  810.             VSIw->IRM=toggle;
  811.             break;
  812.  
  813.         default:
  814.             break;
  815.  
  816.       }    /* end switch */
  817. }
  818.  
  819. void VSItab(void)
  820. {
  821.     if(VSIw->x>=VSIw->maxwidth)
  822.         VSIw->x=VSIw->maxwidth;
  823.     VSIw->x++;
  824.     while((VSIw->tabs[VSIw->x] != 'x') && (VSIw->x < VSIw->maxwidth)) 
  825.         VSIw->x++;
  826. }
  827.  
  828. void VSIinschar(x)
  829. int x;
  830. {
  831.     int i,j;
  832.     char *tempa,*temp;
  833.  
  834.     VSIwrapnow(&i,&j);
  835.  
  836.     tempa=VSIw->attrst[VSIw->y]->text;
  837.     temp=VSIw->linest[VSIw->y]->text;
  838.     for(i=VSIw->maxwidth-x; i>=VSIw->x; i--) {
  839.         temp[x+i]=temp[i];
  840.         tempa[x+i]=tempa[i];
  841.       }    /* end for */
  842.     for(i=VSIw->x; i<VSIw->x+x; i++) {
  843.         temp[i]=' ';
  844.         tempa[i]=VSIclrattrib;
  845.       }    /* end for */
  846. }
  847.  
  848. void VSIinsstring(len,start)
  849. int len;
  850. char *start;
  851. {
  852.     if(VSIw->VSIDC)
  853.         RSinsstring(VSIwn,VSIw->x-len,VSIw->y,VSIw->attrib,len,start);
  854.     else
  855.         RSdraw(VSIwn,VSIw->x-len,VSIw->y,VSIw->attrib,VSIw->maxwidth-VSIw->x+len+1,start);
  856. }
  857.  
  858. void VSIsave(void)
  859. {
  860.     VSIw->Px=VSIw->x;
  861.     VSIw->Py=VSIw->y;
  862.     VSIw->Pattrib=VSIw->attrib;
  863. }
  864.  
  865. void VSIrestore(void)
  866. {
  867.     VSIw->x=VSIw->Px;
  868.     VSIw->y=VSIw->Py;
  869.     VSIrange();
  870.     VSIw->attrib=VSinattr(VSIw->Pattrib);
  871. }
  872.  
  873. void VSIdraw(VSIwn,x,y,a,len,c)
  874. int VSIwn,
  875.     x,y,
  876.     a,
  877.     len;
  878. char *c;
  879. {
  880.     int x2,y2,
  881.         offset;
  882.  
  883.     if(!VSIclip(&x,&y,&x2,&y2,&len,&offset))
  884.         RSdraw(VSIwn,x,y,a,len,c+offset);
  885. }
  886.