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 / vsem.c < prev    next >
Text File  |  1990-05-03  |  11KB  |  469 lines

  1. #ifdef lint
  2. static char *SCCSid = "%W%    (NCSA)    %G%";
  3. #endif
  4.  
  5. /*
  6.  *
  7.  *      Virtual Screen Kernel Emulation Routines
  8.  *                      (vsem.c)
  9.  *  
  10.  *   National Center for Supercomputing Applications
  11.  *      by Gaige B. Paulsen
  12.  *
  13.  *    This file contains the private emulation calls for the NCSA
  14.  *  Virtual Screen Kernel.
  15.  *
  16.  *      Version Date    Notes
  17.  *      ------- ------  ---------------------------------------------------
  18.  *      0.01    861102  Initial coding -GBP
  19.  *      0.10    861111  Added/Modified VT emulator -GBP
  20.  *      0.50    861113  First compiled edition -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. VSem(c,ctr)
  29. register int ctr;
  30. register unsigned char *c;
  31. {
  32.     register int i,sx;
  33.     register int escflg;
  34.     int insert,ocount,attrib,wrapit,extra,offend;
  35.     char *acurrent,*current,*start;
  36.  
  37.     escflg= VSIw->escflg;
  38.  
  39.     while (ctr>0) {
  40.     while ( (escflg==0) && (ctr>0) && (*c<32) ) {
  41.         switch(*c) {
  42.         case 0x1b:
  43.             escflg++;
  44.             break;
  45.         case 0x0e:
  46.             if (VSIw->G1)
  47.                 VSIw->attrib=VSgraph(VSIw->attrib);
  48.             else
  49.                 VSIw->attrib=VSnotgraph(VSIw->attrib);
  50.             VSIw->charset=1;
  51.             break;
  52.         case 0x0f:
  53.             if (VSIw->G0)
  54.                 VSIw->attrib=VSgraph(VSIw->attrib);
  55.             else
  56.                 VSIw->attrib=VSnotgraph(VSIw->attrib);
  57.             VSIw->charset=0;
  58.             break;
  59.         case 0x07:
  60.             RSbell(VSIwn);
  61.             break;
  62.         case 0x08:
  63.             VSIw->x--;
  64.             if (VSIw->x<0) VSIw->x=0;
  65.             break;
  66.         case 0x0c:
  67.             VSIindex();
  68.             break;
  69.         case 0x09:              /* Later change for versatile tabbing */
  70.             VSItab();
  71.             break;
  72.         case 0x0a:
  73.             VSIindex();
  74.             break;
  75.         case 0x0d:
  76.             VSIw->x=0;
  77.             break;
  78.         case 0x0b:
  79.             VSIindex();
  80.             break;
  81. #ifdef CISB
  82.         case 0x10:
  83.             bp_DLE( c, ctr);
  84.             ctr = 0;
  85.             break;
  86.         case 0x05:
  87.             bp_ENQ();
  88.             break;
  89. #endif CISB
  90.  
  91.         }
  92.         c++;ctr--;
  93.         }
  94.     while( (ctr>0) && (escflg==0) && (*c>=32) ) {
  95.             /* the following line is important, both are * chars */
  96.         current = start = &VSIw->linest[VSIw->y]->text[VSIw->x];
  97.         acurrent = &VSIw->attrst[VSIw->y]->text[VSIw->x];
  98.         attrib = VSIw->attrib;
  99.         insert = VSIw->IRM;           /* boolean */
  100.         ocount = VSIw->x;
  101.         wrapit=0;offend=0;extra=0;
  102.         sx=VSIw->x;
  103.         if ( VSIw->x > VSIw->maxwidth ) {
  104.             if ( VSIw->DECAWM ) {
  105.                 VSIw->x=0;
  106.                 VSIindex();
  107.                 }
  108.             else
  109.                 VSIw->x=VSIw->maxwidth;
  110.             current = start = &VSIw->linest[VSIw->y]->text[VSIw->x];
  111.             acurrent = &VSIw->attrst[VSIw->y]->text[VSIw->x];
  112.             ocount = VSIw->x;
  113.             sx=VSIw->x;
  114.             }
  115.         while( (ctr>0) && (*c>=32) && (offend==0)) {
  116.             if (insert) VSIinschar(1);
  117.             *current = *c;
  118.             *acurrent=attrib;
  119.             c++;
  120.             ctr--;
  121.             if (VSIw->x < VSIw->maxwidth)
  122.                 {acurrent++; current++; VSIw->x++; }
  123.             else {
  124.                 if (VSIw->DECAWM) {
  125.                     VSIw->x++;
  126.                     offend=1;
  127.                     }
  128.                 else {
  129.                     VSIw->x=VSIw->maxwidth;
  130.                     extra=1;
  131.                     }
  132.                 }
  133.             }
  134.  
  135.         if (insert) {
  136.             VSIinsstring(VSIw->x-ocount+offend+extra,start);
  137.                                 /* actually just decides which RS to use */
  138.             }
  139.             else VSIdraw(VSIwn,sx,VSIw->y,VSIw->attrib,VSIw->x-ocount+offend+extra,start);
  140.         }
  141.  
  142. while( (ctr>0) && (escflg==1) ) {
  143.         switch(*c) {
  144.         case 0x08:
  145.             VSIw->x--;
  146.             if (VSIw->x<0) VSIw->x=0;
  147.             break;
  148.         case '[': 
  149.             VSIapclear();
  150.             escflg++;
  151.             break;
  152.         case '7':
  153.             VSIsave();
  154.             escflg = 0;
  155.             break;
  156.         case '8':
  157.             VSIrestore();
  158.             escflg = 0;
  159.             break;
  160.         case 'c':
  161.             VSIreset();
  162.             break;
  163.         case 'D':
  164.             VSIindex();
  165.             escflg = 0;
  166.             break;
  167.         case 'E':
  168.             VSIw->x=0;
  169.             VSIindex();
  170.             escflg = 0;
  171.             break;
  172.         case 'M':
  173.             VSIrindex();
  174.             escflg = 0;
  175.             break;
  176.         case '>':
  177.             VSIw->DECPAM=0;
  178.             escflg = 0;
  179.             break;
  180.         case '=':
  181.             VSIw->DECPAM=1;
  182.             escflg = 0;
  183.             break;
  184.         case 'Z':
  185.             VTsendident();
  186.             escflg = 0;
  187.             break;
  188.         case '#':
  189.             escflg=3;
  190.             break;
  191.         case '(':
  192.             escflg=4;
  193.             break;
  194.         case ')':
  195.             escflg=5;
  196.             break;
  197.         case 'H':
  198.             VSIw->tabs[VSIw->x]='x';
  199.             escflg=0;
  200.             break;
  201. #ifdef CISB
  202.         case 'I':
  203.             bp_ESC_I();
  204.             break;
  205. #endif CISB
  206.         default:
  207.             escflg = 0;
  208.             break;
  209.         }
  210.     c++;ctr--;
  211.     }
  212. while ( (escflg==2) && (ctr>0) ) {
  213.         switch(*c) {
  214.         case 0x08:
  215.             VSIw->x--;
  216.             if (VSIw->x<0) VSIw->x=0;
  217.             break;
  218.         case '0':
  219.         case '1':
  220.         case '2':
  221.         case '3':
  222.         case '4':
  223.         case '5':
  224.         case '6':
  225.         case '7':
  226.         case '8':
  227.         case '9':
  228.             if (VSIw->parms[VSIw->parmptr]<0) VSIw->parms[VSIw->parmptr]=0;
  229.             VSIw->parms[VSIw->parmptr] *= 10;
  230.             VSIw->parms[VSIw->parmptr] += *c-'0';
  231.             break;
  232.         case '?':
  233.             VSIw->parms[VSIw->parmptr++] = -2;
  234.             break;
  235.         case ';':
  236.             VSIw->parmptr++;
  237.             break;
  238.         case 'A':
  239.             if (VSIw->parms[0]<1) VSIw->y--;
  240.                 else VSIw->y-=VSIw->parms[0];
  241.             if ( VSIw->y < VSIw->top ) VSIw->y=VSIw->top;
  242.             VSIrange();
  243.             escflg = 0;
  244.             break;
  245.         case 'B':
  246.             if (VSIw->parms[0]<1) VSIw->y++;
  247.                 else VSIw->y+=VSIw->parms[0];
  248.             if ( VSIw->y > VSIw->bottom ) VSIw->y=VSIw->bottom;
  249.             VSIrange();
  250.             escflg = 0;
  251.             break;
  252.         case 'C':
  253.             if (VSIw->parms[0]<1) VSIw->x++;
  254.                 else VSIw->x+=VSIw->parms[0];
  255.             VSIrange();
  256.             if (VSIw->x > VSIw->maxwidth)
  257.                 VSIw->x = VSIw->maxwidth;
  258.             escflg = 0;
  259.             break;
  260.         case 'D':
  261.             if (VSIw->parms[0]<1) VSIw->x--;
  262.                 else VSIw->x-=VSIw->parms[0];
  263.             VSIrange();
  264.             escflg = 0;
  265.             break;
  266.         case 'f':
  267.         case 'H':
  268.             VSIw->x=VSIw->parms[1]-1;
  269.             if (VSIw->DECORG)
  270.                 VSIw->y=VSIw->parms[0]-1 + VSIw->top;        /* origin mode relative */
  271.             else
  272.                 VSIw->y=VSIw->parms[0]-1;
  273.             VSIrange();
  274.             escflg = 0;
  275.             break;
  276.         case 'K':
  277.             switch(VSIw->parms[0]) {
  278.             case -1:
  279.             case  0:
  280.                 VSIeeol();
  281.                 break;
  282.             case  1:
  283.                 VSIebol();
  284.                 break;
  285.             case  2:
  286.                 VSIel(-1);
  287.                 break;
  288.             default:
  289.                 escflg=0;
  290.                 break;
  291.             }
  292.             escflg = 0;
  293.             break;
  294.         case 'J':
  295.             switch(VSIw->parms[0]) {
  296.             case -1:
  297.             case  0:
  298.                 VSIeeos();
  299.                 break;
  300.             case  1:
  301.                 VSIebos();
  302.                 break;
  303.             case  2:
  304.                 VSIes();
  305.                 break;
  306.             default:
  307.                 escflg=0;
  308.                 break;
  309.             }
  310.             escflg = 0;
  311.             break;
  312.         case 'm':
  313.             { int temp=0;
  314.               while (temp<=VSIw->parmptr) {
  315.               if (VSIw->parms[temp]<1) VSIw->attrib&=128;
  316.               else VSIw->attrib|=1<<(VSIw->parms[temp]-1);
  317.               temp++;
  318.               }
  319.             }
  320.             escflg = 0;
  321.             break;
  322.         case 'q':
  323.             escflg = 0;
  324.             break;
  325.         case 'c':
  326.             VTsendident();
  327.             escflg = 0;
  328.             break;
  329.         case 'n':
  330.             switch(VSIw->parms[0]) {
  331.             case 5:
  332.                 VTsendstat();
  333.                 break;
  334.             case 6:
  335.                 VTsendpos();
  336.                 break;
  337.                 }
  338.             escflg = 0;
  339.             break;
  340.         case 'L':
  341.             if(VSIw->parms[0]<1) VSIw->parms[0]=1;
  342.             VSIinslines(VSIw->parms[0],-1);
  343.             escflg = 0;
  344.             break;
  345.         case 'M':
  346.             if(VSIw->parms[0]<1) VSIw->parms[0]=1;
  347.             VSIdellines(VSIw->parms[0],-1);
  348.             escflg = 0;
  349.             break;
  350.         case 'P':
  351.             if(VSIw->parms[0]<1) VSIw->parms[0]=1;
  352.             VSIdelchars(VSIw->parms[0]);
  353.             escflg = 0;
  354.             break;
  355.         case 'r':
  356.             if (VSIw->parms[0]<0) VSIw->top=0;
  357.                 else VSIw->top=VSIw->parms[0]-1;
  358.             if (VSIw->parms[1]<0) VSIw->bottom=VSPBOTTOM;
  359.                 else VSIw->bottom=VSIw->parms[1]-1;
  360.             if (VSIw->top<0) VSIw->top=0;
  361.             if (VSIw->top>VSPBOTTOM-1) VSIw->top=VSPBOTTOM-1;
  362.             if (VSIw->bottom<1) VSIw->bottom=VSPBOTTOM;
  363.             if (VSIw->bottom>VSPBOTTOM) VSIw->bottom=VSPBOTTOM;
  364.             VSIw->x=0; VSIw->y=0;
  365.             if (VSIw->DECORG)
  366.                 VSIw->y=VSIw->top;    /* origin mode relative */
  367.             escflg = 0;
  368.             break;
  369.         case 'h':
  370.             VSIsetoption(1);
  371.             escflg = 0;
  372.             break;
  373.         case 'l':
  374.             VSIsetoption(0);
  375.             escflg = 0;
  376.             break;
  377.         case 'g':
  378.             if (VSIw->parms[0]==3) VSItabclear();
  379.             else if (VSIw->parms[0]==0 || VSIw->parms[0]<0)
  380.                     VSIw->tabs[VSIw->x]=' ';
  381.             escflg =0;
  382.             break;
  383.         default:            /* Dag blasted strays... */
  384.             escflg=0;
  385.             break;
  386.         }
  387.         c++; ctr--;
  388.     }
  389.  
  390. while ( (escflg==3) && (ctr>0) ) {    /* #  Handling */
  391.     switch(*c) {
  392.         case 0x08:
  393.             VSIw->x--;
  394.             if (VSIw->x<0) VSIw->x=0;
  395.             break;
  396.         case '8':
  397.             VTalign();
  398.             escflg=0;
  399.             break;
  400.         default:
  401.             escflg=0;
  402.             break;
  403.         }
  404.         c++; ctr--;
  405.     }
  406.  
  407. while ( (escflg==4) && (ctr>0) ) {    /* (  Handling */
  408.     switch(*c) {
  409.         case 0x08:
  410.             VSIw->x--;
  411.             if (VSIw->x<0) VSIw->x=0;
  412.             break;
  413.         case 'A':
  414.         case 'B':
  415.         case '1':
  416.             VSIw->G0=0;
  417.             if ( !VSIw->charset )
  418.                 VSIw->attrib=VSnotgraph(VSIw->attrib);
  419.             escflg=0;
  420.             break;
  421.         case '0':
  422.         case '2':
  423.             VSIw->G0=1;
  424.             if ( !VSIw->charset )
  425.                 VSIw->attrib=VSgraph(VSIw->attrib);
  426.             escflg=0;
  427.             break;
  428.         default:
  429.             escflg=0;
  430.             break;
  431.         }
  432.         c++; ctr--;
  433.     }
  434.  
  435. while ( (escflg==5) && (ctr>0) ) {    /* )  Handling */
  436.     switch(*c) {
  437.         case 0x08:
  438.             VSIw->x--;
  439.             if (VSIw->x<0) VSIw->x=0;
  440.             break;
  441.         case 'A':
  442.         case 'B':
  443.         case '1':
  444.             VSIw->G1=0;
  445.             if ( VSIw->charset )
  446.                 VSIw->attrib=VSnotgraph(VSIw->attrib);
  447.             escflg=0;
  448.             break;
  449.         case '0':
  450.         case '2':
  451.             VSIw->G1=1;
  452.             if ( VSIw->charset )
  453.                 VSIw->attrib=VSgraph(VSIw->attrib);
  454.             escflg=0;
  455.             break;
  456.         default:
  457.             escflg=0;
  458.             break;
  459.         }
  460.         c++; ctr--;
  461.     }
  462.  
  463.     if ((escflg>2) && (ctr>0)) {escflg=0; c++; ctr--;}
  464.  
  465.     }
  466.     VSIw->escflg=escflg;
  467. }
  468.  
  469.