home *** CD-ROM | disk | FTP | other *** search
/ GRIPS 2: Government Rast…rocessing Software & Data / GRIPS_2.cdr / dos / ncsa_tel / contribu / byu_tel2.hqx / vs / vsintern.c < prev    next >
Text File  |  1990-05-03  |  17KB  |  878 lines

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