home *** CD-ROM | disk | FTP | other *** search
- #ifdef lint
- static char *SCCSid = "%W% (NCSA) %G%";
- #endif
-
- /*
- *
- * Virtual Screen Kernel Emulation Routines
- * (vsem.c)
- *
- * National Center for Supercomputing Applications
- * by Gaige B. Paulsen
- *
- * This file contains the private emulation calls for the NCSA
- * Virtual Screen Kernel.
- *
- * Version Date Notes
- * ------- ------ ---------------------------------------------------
- * 0.01 861102 Initial coding -GBP
- * 0.10 861111 Added/Modified VT emulator -GBP
- * 0.50 861113 First compiled edition -GBP
- * 2.1 871130 NCSA Telnet 2.1 -GBP
- * 2.2 880715 NCSA Telnet 2.2 -GBP
- */
-
- #include <QuickDraw.h>
- #include <Controls.h>
-
- #include "vsdata.h"
- #include "vskeys.h"
- #include "rsmac.h"
- #include "vsinterf.h" /* BYU 2.4.18 */
- #include "vsintern.h"
-
- void VSem
- (
- register unsigned char *c, /* pointer to character string */
- register int ctr /* length of character string */
- )
- /* basic routine for placing characters on a virtual screen, and
- interpreting control characters and escape sequences. Simple
- interpretation of controls & escapes is done here, while the
- harder stuff is done by calling VSIxx routines in vsintern.c. */
- {
- register int sx;
- register int escflg; /* state of escape sequence interpretation */
- int insert, attrib, extra, offend;
- char *acurrent, *current, *start;
-
- escflg = VSIw->escflg;
-
- while (ctr > 0)
- {
- while ((escflg == 0) && (ctr > 0) && (*c < 32))
- {
- switch (*c)
- {
- case 0x1b: /* esc */
- escflg++;
- break;
- case 0x0e: /* shift out */
- if (VSIw->G1)
- VSIw->attrib = VSgraph(VSIw->attrib);
- else
- VSIw->attrib = VSnotgraph(VSIw->attrib);
- VSIw->charset = 1;
- break;
- case 0x0f: /* shift in */
- if (VSIw->G0)
- VSIw->attrib = VSgraph(VSIw->attrib);
- else
- VSIw->attrib = VSnotgraph(VSIw->attrib);
- VSIw->charset = 0;
- break;
- case 0x07: /* bell */
- RSbell(VSIwn);
- break;
- case 0x08: /* backspace */
- VSIw->x--;
- if (VSIw->x < 0)
- /* hit left margin */
- VSIw->x = 0;
- break;
- case 0x0c: /* ff */
- VSIindex();
- break;
- case 0x09: /* ht */ /* Later change for versatile tabbing */
- VSItab();
- VScapture(c,1); /* BYU 2.4.18 */
- break;
- case 0x0a: /* lf */
- VSIindex();
- break;
- case 0x0d: /* cr */
- VSIw->x = 0;
- VScapture(c,1); /* BYU 2.4.18 */
- break;
- case 0x0b: /* vt */
- VSIindex();
- break;
- #ifdef CISB
- case 0x10: /* dle */
- bp_DLE(c, ctr);
- ctr = 0;
- break;
- case 0x05: /* enq */
- bp_ENQ();
- break;
- #endif CISB
- } /* switch */
- c++;
- ctr--;
- } /* while */
- if ((escflg == 0) && (ctr > 0) && (*c & 0x80)) /* BYU 2.4.12 - VT220 starts here */
- { /* BYU 2.4.12 */
- switch (*c) /* BYU 2.4.12 */
- { /* BYU 2.4.12 */
- case 0x84: /* ind */ /* BYU 2.4.12 - same as ESC D */
- VSIindex(); /* BYU 2.4.12 */
- goto ShortCut; /* BYU 2.4.12 */
- case 0x85: /* nel */ /* BYU 2.4.12 - same as ESC E */
- VSIw->x = 0; /* BYU 2.4.12 */
- VSIindex(); /* BYU 2.4.12 */
- goto ShortCut; /* BYU 2.4.12 */
- case 0x88: /* hts */ /* BYU 2.4.12 - same as ESC H */
- VSIw->tabs[VSIw->x] = 'x'; /* BYU 2.4.12 */
- goto ShortCut; /* BYU 2.4.12 */
- case 0x8d: /* ri */ /* BYU 2.4.12 - same as ESC M */
- VSIrindex(); /* BYU 2.4.12 */
- goto ShortCut; /* BYU 2.4.12 */
- case 0x9b: /* csi */ /* BYU 2.4.12 - same as ESC [ */
- VSIapclear(); /* BYU 2.4.12 */
- escflg = 2; /* BYU 2.4.12 */
- break; /* BYU 2.4.12 */
- case 0x86: /* ssa */ /* BYU 2.4.12 - same as ESC F */
- case 0x87: /* esa */ /* BYU 2.4.12 - same as ESC G */
- case 0x8e: /* ss2 */ /* BYU 2.4.12 - same as ESC N */
- case 0x8f: /* ss3 */ /* BYU 2.4.12 - same as ESC O */
- case 0x90: /* dcs */ /* BYU 2.4.12 - same as ESC P */
- case 0x93: /* sts */ /* BYU 2.4.12 - same as ESC S */
- case 0x96: /* spa */ /* BYU 2.4.12 - same as ESC V */
- case 0x97: /* epa */ /* BYU 2.4.12 - same as ESC W */
- case 0x9d: /* osc */ /* BYU 2.4.12 - same as ESC ] */
- case 0x9e: /* pm */ /* BYU 2.4.12 - same as ESC ^ */
- case 0x9f: /* apc */ /* BYU 2.4.12 - same as ESC _ */
- goto ShortCut; /* BYU 2.4.12 */
- } /* switch */ /* BYU 2.4.12 */
- c++; /* BYU 2.4.12 */
- ctr--; /* BYU 2.4.12 */
- } /* if */ /* BYU 2.4.12 */
- while ((ctr > 0) && (escflg == 0) && (*c >= 32))
- {
- /* display printing characters */
- start = &VSIw->linest[VSIw->y]->text[VSIw->x]; /* start of area needing redrawing */
- current = start; /* where to put next char */
- acurrent = &VSIw->attrst[VSIw->y]->text[VSIw->x]; /* where to put corresponding attribute byte */
- attrib = VSIw->attrib; /* current writing attribute */
- insert = VSIw->IRM; /* insert mode (boolean) */
- offend = 0; /* wrapped to next line (boolean) */
- extra = 0; /* overwriting last character of line (boolean) */
- sx = VSIw->x; /* starting column of area needing redrawing */
- if (VSIw->x > VSIw->maxwidth)
- {
- if (VSIw->DECAWM)
- {
- /* wrap to next line */
- VSIw->x = 0;
- VSIindex();
- }
- else
- /* stay at right margin */
- VSIw->x = VSIw->maxwidth;
- current = start = &VSIw->linest[VSIw->y]->text[VSIw->x];
- acurrent = &VSIw->attrst[VSIw->y]->text[VSIw->x];
- sx = VSIw->x;
- } /* if */
- while ((ctr > 0) && (*c >= 32) && (offend == 0))
- {
- /* write characters within a single line */
- if (insert)
- /* make room for the char */
- VSIinschar(1);
- /* poke the character and its attribute into the
- screen buffer at the current cursor position */
- *current = *c;
- *acurrent = attrib;
- c++;
- ctr--;
- if (VSIw->x < VSIw->maxwidth)
- {
- /* advance the cursor position */
- acurrent++;
- current++;
- VSIw->x++;
- }
- else
- {
- /* hit right margin */
- if (VSIw->DECAWM)
- {
- /* autowrap to start of next line */
- VSIw->x++;
- offend = 1; /* terminate inner loop */
- }
- else
- {
- /* stay at right margin */
- VSIw->x = VSIw->maxwidth;
- extra = 1; /* cursor position doesn't advance */
- } /* if */
- } /* if */
- } /* while */
- /* update the screen to show what I've done */
- extra += VSIw->x - sx + offend; /* BYU 2.4.18 */
- if (insert)
- VSIinsstring(extra, start); /* BYU 2.4.18 */
- /* actually just decides which RS to use */
- else
- VSIdraw(VSIwn, sx, VSIw->y, VSIw->attrib, extra, start); /* BYU 2.4.18 */
- VScapture((unsigned char *) start, extra); /* BYU 2.4.18 */
- } /* while */
-
- while((ctr > 0) && (escflg == 1))
- { /* basic escape sequence processing */
- switch (*c)
- {
- case 0x08:
- VSIw->x--;
- if (VSIw->x < 0)
- VSIw->x = 0;
- break;
- case '[': /* csi */
- VSIapclear();
- escflg++;
- break;
- case '7':
- VSIsave();
- goto ShortCut; /* BYU 2.4.12 */
- case '8':
- VSIrestore();
- goto ShortCut; /* BYU 2.4.12 */
- case 'c':
- VSIreset();
- break;
- case 'D':
- VSIindex();
- goto ShortCut; /* BYU 2.4.12 */
- case 'E':
- VSIw->x = 0;
- VSIindex();
- goto ShortCut; /* BYU 2.4.12 */
- case 'M':
- VSIrindex();
- goto ShortCut; /* BYU 2.4.12 */
- case '>':
- VSIw->DECPAM = 0;
- goto ShortCut; /* BYU 2.4.12 */
- case '=':
- VSIw->DECPAM = 1;
- goto ShortCut; /* BYU 2.4.12 */
- case 'Z':
- VTsendident();
- goto ShortCut; /* BYU 2.4.12 */
- case ' ': /* BYU 2.4.12 */
- case '*': /* BYU 2.4.12 */
- case '#':
- escflg = 3;
- break;
- case '(':
- escflg = 4;
- break;
- case ')':
- escflg = 5;
- break;
- case 'H':
- VSIw->tabs[VSIw->x] = 'x';
- goto ShortCut; /* BYU 2.4.12 */
- #ifdef CISB
- case 'I':
- bp_ESC_I();
- break;
- #endif CISB
- default:
- goto ShortCut; /* BYU 2.4.12 */
- } /* switch */
- c++;
- ctr--;
- } /* while */
- while ((escflg == 2) && (ctr > 0))
- { /* "control sequence" processing */
- switch (*c)
- {
- case 0x08:
- VSIw->x--;
- if (VSIw->x < 0)
- VSIw->x = 0;
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- /* parse numeric parameter */
- if (VSIw->parms[VSIw->parmptr] < 0)
- VSIw->parms[VSIw->parmptr] = 0;
- VSIw->parms[VSIw->parmptr] = VSIw->parms[VSIw->parmptr] * 10;
- VSIw->parms[VSIw->parmptr] += *c - '0';
- break;
- case '?':
- /* DEC-private control sequence */
- VSIw->parms[VSIw->parmptr++] = -2;
- break;
- case ';':
- /* parameter separator */
- VSIw->parmptr++;
- break;
- case 'A': /* cursor up */
- #if 1 /* BYU */
- if (VSIw->parms[0]<1) VSIw->y--; /* BYU */
- else VSIw->y-=VSIw->parms[0]; /* BYU */
- if ( VSIw->y < 0 ) VSIw->y=0; /* BYU */
- #else /* BYU */
- if (VSIw->y < VSIw->top)
- {
- /* outside scrolling region */
- if (VSIw->parms[0] < 1)
- VSIw->y--;
- else
- VSIw->y -= VSIw->parms[0];
- }
- else
- {
- /* don't leave scrolling region */
- if (VSIw->parms[0] < 1)
- VSIw->y--;
- else
- VSIw->y -= VSIw->parms[0];
- if (VSIw->y < VSIw->top)
- VSIw->y = VSIw->top;
- }
- #endif /* BYU */
- VSIrange();
- goto ShortCut; /* BYU 2.4.12 */
- case 'B': /* cursor down */
- #if 1 /* BYU */
- if (VSIw->parms[0]<1) VSIw->y++; /* BYU */
- else VSIw->y+=VSIw->parms[0]; /* BYU */
- if ( VSIw->y > VSIw->lines ) /* BYU */
- VSIw->y=VSIw->lines; /* BYU */
- #else /* BYU */
- if (VSIw->y > VSIw->bottom)
- {
- /* outside scrolling region */
- if (VSIw->parms[0] < 1)
- VSIw->y++;
- else
- VSIw->y += VSIw->parms[0];
- }
- else
- {
- /* don't leave scrolling region */
- if (VSIw->parms[0] < 1)
- VSIw->y++;
- else
- VSIw->y += VSIw->parms[0];
- if (VSIw->y > VSIw->bottom)
- VSIw->y = VSIw->bottom;
- }
- #endif /* BYU */
- VSIrange();
- goto ShortCut; /* BYU 2.4.12 */
- case 'C': /* cursor right */
- if (VSIw->parms[0] < 1)
- VSIw->x++;
- else
- VSIw->x += VSIw->parms[0];
- VSIrange();
- if (VSIw->x > VSIw->maxwidth)
- VSIw->x = VSIw->maxwidth;
- goto ShortCut; /* BYU 2.4.12 */
- case 'D': /* cursor left */
- if (VSIw->parms[0] < 1)
- VSIw->x--;
- else
- VSIw->x -= VSIw->parms[0];
- VSIrange();
- goto ShortCut; /* BYU 2.4.12 */
- case 'f':
- case 'H':
- /* absolute cursor positioning */
- VSIw->x = VSIw->parms[1] - 1;
- if (VSIw->DECORG)
- /* origin mode -- position relative to top of scrolling region */
- VSIw->y = VSIw->parms[0] - 1 + VSIw->top;
- else
- VSIw->y = VSIw->parms[0] - 1;
- VSIrange();
- goto ShortCut; /* BYU 2.4.12 */
- case 'K':
- /* erase to beginning/end/whole of line */
- switch (VSIw->parms[0])
- {
- case -1:
- case 0:
- VSIeeol();
- break;
- case 1:
- VSIebol();
- break;
- case 2:
- VSIel(-1);
- break;
- default:
- goto ShortCut; /* BYU 2.4.12 */
- } /* switch */
- goto ShortCut; /* BYU 2.4.12 */
- case 'J':
- /* erase to beginning/end/whole of screen */
- switch (VSIw->parms[0])
- {
- case -1:
- case 0:
- VSIeeos();
- break;
- case 1:
- VSIebos();
- break;
- case 2:
- VSIes();
- break;
- default:
- goto ShortCut; /* BYU 2.4.12 */
- } /* switch */
- goto ShortCut; /* BYU 2.4.12 */
- case 'm':
- /* set/clear attributes */
- {
- int temp = 0;
- while (temp <= VSIw->parmptr)
- {
- if (VSIw->parms[temp] < 1)
- VSIw->attrib &= 128; /* turn them all off */
- else if (VSIw->parms[temp] > 20)
- /* turn off the appropriate bit */
- VSIw->attrib &= ~(1 << (VSIw->parms[temp] - 21));
- else
- /* turn on the appropriate bit */
- VSIw->attrib |= 1 << (VSIw->parms[temp] - 1);
- temp++;
- } /* while */
- }
- goto ShortCut; /* BYU 2.4.12 */
- case 'q':
- /* flash dem LEDs. What LEDs? */
- goto ShortCut; /* BYU 2.4.12 */
- case 'c':
- VTsendident();
- goto ShortCut; /* BYU 2.4.12 */
- case 'n':
- switch (VSIw->parms[0])
- {
- case 5:
- VTsendstat();
- break;
- case 6:
- VTsendpos();
- break;
- } /* switch */
- goto ShortCut; /* BYU 2.4.12 */
- case 'L':
- if (VSIw->parms[0] < 1)
- VSIw->parms[0] = 1;
- VSIinslines(VSIw->parms[0], -1);
- goto ShortCut; /* BYU 2.4.12 */
- case 'M':
- if (VSIw->parms[0] < 1)
- VSIw->parms[0] = 1;
- VSIdellines(VSIw->parms[0], -1);
- goto ShortCut; /* BYU 2.4.12 */
- case 'P':
- if (VSIw->parms[0] < 1)
- VSIw->parms[0] = 1;
- VSIdelchars(VSIw->parms[0]);
- goto ShortCut; /* BYU 2.4.12 */
- case 'r':
- /* set scrolling region */
- if (VSIw->parms[0] < 0)
- VSIw->top = 0;
- else
- VSIw->top = VSIw->parms[0] - 1;
- if (VSIw->parms[1] < 0)
- VSIw->bottom = VSIw->lines;
- else
- VSIw->bottom = VSIw->parms[1] - 1;
- if (VSIw->top < 0)
- VSIw->top = 0;
- if (VSIw->top > VSIw->lines - 1)
- VSIw->top = VSIw->lines - 1;
- if (VSIw->bottom < 1)
- VSIw->bottom = VSIw->lines;
- if (VSIw->bottom > VSIw->lines)
- VSIw->bottom = VSIw->lines;
- VSIw->x = 0;
- VSIw->y = 0;
- if (VSIw->DECORG)
- VSIw->y = VSIw->top; /* origin mode relative */
- goto ShortCut; /* BYU 2.4.12 */
- case 'h':
- /* set options */
- VSIsetoption(1);
- goto ShortCut; /* BYU 2.4.12 */
- case 'l':
- /* reset options */
- VSIsetoption(0);
- goto ShortCut; /* BYU 2.4.12 */
- case 'g':
- if (VSIw->parms[0] == 3)
- /* clear all tabs */
- VSItabclear();
- else if (VSIw->parms[0] == 0 || VSIw->parms[0] < 0)
- /* clear tab at current position */
- VSIw->tabs[VSIw->x] = ' ';
- goto ShortCut; /* BYU 2.4.12 */
- case '!': /* BYU 2.4.12 - More private DEC stuff? */
- case '\'': /* BYU 2.4.12 - More private DEC stuff? */
- case '\"': /* BYU 2.4.12 - More private DEC stuff? */
- escflg++; /* BYU 2.4.12 */
- break; /* BYU 2.4.12 */
- default: /* Dang blasted strays... */
- goto ShortCut; /* BYU 2.4.12 */
- } /* switch */
- c++;
- ctr--;
- } /* while */
-
- while ((escflg == 3) && (ctr > 0))
- { /* "#" handling */
- /* no support for double-width and double-height characters yet */
- switch (*c)
- {
- case 0x08:
- VSIw->x--;
- if (VSIw->x < 0)
- VSIw->x = 0;
- break;
- case '8': /* alignment display */
- VTalign();
- goto ShortCut; /* BYU 2.4.12 */
- default:
- goto ShortCut; /* BYU 2.4.12 */
- } /* switch */
- c++;
- ctr--;
- } /* while */
-
- while ((escflg == 4) && (ctr > 0))
- { /* "(" handling (selection of G0 character set) */
- switch (*c)
- {
- case 0x08:
- VSIw->x--;
- if (VSIw->x < 0)
- VSIw->x = 0;
- break;
- case 'A': /* UK */
- case 'B': /* US */
- case '1': /* "soft" */
- VSIw->G0 = 0;
- if (!VSIw->charset)
- VSIw->attrib = VSnotgraph(VSIw->attrib);
- goto ShortCut; /* BYU 2.4.12 */
- case '0': /* DEC special graphics */
- case '2': /* "soft" */
- VSIw->G0 = 1;
- if (!VSIw->charset)
- VSIw->attrib = VSgraph(VSIw->attrib);
- goto ShortCut; /* BYU 2.4.12 */
- default:
- goto ShortCut; /* BYU 2.4.12 */
- } /* switch */
- c++;
- ctr--;
- } /* while */
-
- while ((escflg == 5) && (ctr > 0))
- { /* ")" handling (selection of G1 character set) */
- switch (*c)
- {
- case 0x08:
- VSIw->x--;
- if (VSIw->x < 0)
- VSIw->x = 0;
- break;
- case 'A': /* UK */
- case 'B': /* US */
- case '1': /* "soft" */
- VSIw->G1 = 0;
- if (VSIw->charset)
- VSIw->attrib = VSnotgraph(VSIw->attrib);
- goto ShortCut; /* BYU 2.4.12 */
- case '0': /* DEC special graphics */
- case '2': /* "soft" */
- VSIw->G1 = 1;
- if (VSIw->charset)
- VSIw->attrib = VSgraph(VSIw->attrib);
- goto ShortCut; /* BYU 2.4.12 */
- default:
- goto ShortCut; /* BYU 2.4.12 */
- } /* switch */
- c++;
- ctr--;
- } /* while */
-
- if ((escflg > 2) && (ctr > 0))
- {
- ShortCut: /* BYU 2.4.12 - well, sacrificing style for speed */
- escflg = 0;
- c++;
- ctr--;
- } /* if */
- } /* while (ctr > 0) */
- VSIw->escflg = escflg;
- } /* VSem */
-
-