Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!adelie!necntc!ncoast!allbery From: nwd@j.cc.purdue.edu (Daniel Lawrence) Newsgroups: comp.sources.misc Subject: MicroEmacs 3.9 (Part 12 of 16) Message-ID: <5688@ncoast.UUCP> Date: Mon, 16-Nov-87 21:34:43 EST Article-I.D.: ncoast.5688 Posted: Mon Nov 16 21:34:43 1987 Date-Received: Fri, 20-Nov-87 06:44:49 EST Sender: allbery@ncoast.UUCP Lines: 1395 Approved: allbery@ncoast.UUCP X-Archive: comp.sources.misc/microemacs-3.9/11 # This is a shar archive. # Remove everything above this line. # Run the file through sh, not csh. # (type `sh mes.12') # If you do not see the message # `mes.12 completed!' # then the file was incomplete. echo extracting - tcap.c sed 's/^X//' > tcap.c << 'FRIDAY_NIGHT' X/* tcap: Unix V5, V7 and BS4.2 Termcap video driver X for MicroEMACS X*/ X X#define termdef 1 /* don't define "term" external */ X X#include X#include "estruct.h" X#include "edef.h" X X#if TERMCAP X X#define MARGIN 8 X#define SCRSIZ 64 X#define NPAUSE 10 /* # times thru update to pause */ X#define BEL 0x07 X#define ESC 0x1B X Xextern int ttopen(); Xextern int ttgetc(); Xextern int ttputc(); Xextern int tgetnum(); Xextern int ttflush(); Xextern int ttclose(); Xextern int tcapkopen(); Xextern int tcapkclose(); Xextern int tcapmove(); Xextern int tcapeeol(); Xextern int tcapeeop(); Xextern int tcapbeep(); Xextern int tcaprev(); Xextern int tcapcres(); Xextern int tcapopen(); Xextern int tput(); Xextern char *tgoto(); X#if COLOR Xextern int tcapfcol(); Xextern int tcapbcol(); X#endif X X#define TCAPSLEN 315 Xchar tcapbuf[TCAPSLEN]; Xchar *UP, PC, *CM, *CE, *CL, *SO, *SE; X XTERM term = { X NULL, /* these four values are set dynamically at open time */ X NULL, X NULL, X NULL, X MARGIN, X SCRSIZ, X NPAUSE, X tcapopen, X ttclose, X tcapkopen, X tcapkclose, X ttgetc, X ttputc, X ttflush, X tcapmove, X tcapeeol, X tcapeeop, X tcapbeep, X tcaprev, X tcapcres X#if COLOR X , tcapfcol, X tcapbcol X#endif X}; X Xtcapopen() X X{ X char *getenv(); X char *t, *p, *tgetstr(); X char tcbuf[1024]; X char *tv_stype; X char err_str[72]; X X if ((tv_stype = getenv("TERM")) == NULL) X { X puts("Environment variable TERM not defined!"); X exit(1); X } X X if ((tgetent(tcbuf, tv_stype)) != 1) X { X sprintf(err_str, "Unknown terminal type %s!", tv_stype); X puts(err_str); X exit(1); X } X X X if ((term.t_nrow=(short)tgetnum("li")-1) == -1){ X puts("termcap entry incomplete (lines)"); X exit(1); X } X term.t_mrow = term.t_nrow; X X if ((term.t_ncol=(short)tgetnum("co")) == -1){ X puts("Termcap entry incomplete (columns)"); X exit(1); X } X term.t_mcol = term.t_ncol; X X p = tcapbuf; X t = tgetstr("pc", &p); X if(t) X PC = *t; X X CL = tgetstr("cl", &p); X CM = tgetstr("cm", &p); X CE = tgetstr("ce", &p); X UP = tgetstr("up", &p); X SE = tgetstr("se", &p); X SO = tgetstr("so", &p); X if (SO != NULL) X revexist = TRUE; X X if(CL == NULL || CM == NULL || UP == NULL) X { X puts("Incomplete termcap entry\n"); X exit(1); X } X X if (CE == NULL) /* will we be able to use clear to EOL? */ X eolexist = FALSE; X X if (p >= &tcapbuf[TCAPSLEN]) X { X puts("Terminal description too big!\n"); X exit(1); X } X ttopen(); X} X Xtcapkopen() X X{ X strcpy(sres, "NORMAL"); X} X Xtcapkclose() X X{ X} X Xtcapmove(row, col) Xregister int row, col; X{ X putpad(tgoto(CM, col, row)); X} X Xtcapeeol() X{ X putpad(CE); X} X Xtcapeeop() X{ X putpad(CL); X} X Xtcaprev(state) /* change reverse video status */ X Xint state; /* FALSE = normal video, TRUE = reverse video */ X X{ X static int revstate = FALSE; X if (state) { X if (SO != NULL) X putpad(SO); X } else X if (SE != NULL) X putpad(SE); X} X Xtcapcres() /* change screen resolution */ X X{ X return(TRUE); X} X Xspal(dummy) /* change palette string */ X X{ X /* Does nothing here */ X} X X#if COLOR Xtcapfcol() /* no colors here, ignore this */ X{ X} X Xtcapbcol() /* no colors here, ignore this */ X{ X} X#endif X Xtcapbeep() X{ X ttputc(BEL); X} X Xputpad(str) Xchar *str; X{ X tputs(str, 1, ttputc); X} X Xputnpad(str, n) Xchar *str; X{ X tputs(str, n, ttputc); X} X X X#if FLABEL Xfnclabel(f, n) /* label a function key */ X Xint f,n; /* default flag, numeric argument [unused] */ X X{ X /* on machines with no function keys...don't bother */ X return(TRUE); X} X#endif X#else X Xhello() X{ X} X X#endif FRIDAY_NIGHT echo extracting - termio.c sed 's/^X//' > termio.c << 'FRIDAY_NIGHT' X/* X * The functions in this file negotiate with the operating system for X * characters, and write characters in a barely buffered fashion on the display. X * All operating systems. X */ X#include X#include "estruct.h" X#include "edef.h" X X#if MSDOS & TURBO X#include X#endif X X#if AMIGA X#define NEW 1006L X#define AMG_MAXBUF 1024L Xstatic long terminal; Xstatic char scrn_tmp[AMG_MAXBUF+1]; Xstatic long scrn_tmp_p = 0; X#endif X X#if VMS X#include X#include X#include X#include X#include X#include X X#define NIBUF 128 /* Input buffer size */ X#define NOBUF 1024 /* MM says bug buffers win! */ X#define EFN 0 /* Event flag */ X Xchar obuf[NOBUF]; /* Output buffer */ Xint nobuf; /* # of bytes in above */ Xchar ibuf[NIBUF]; /* Input buffer */ Xint nibuf; /* # of bytes in above */ Xint ibufi; /* Read index */ Xint oldmode[3]; /* Old TTY mode bits */ Xint newmode[3]; /* New TTY mode bits */ Xshort iochan; /* TTY I/O channel */ X#endif X X#if CPM X#include X#endif X X#if MSDOS & (LATTICE | MSC | TURBO | AZTEC | MWC86) Xunion REGS rg; /* cpu register for use of DOS calls */ Xint nxtchar = -1; /* character held from type ahead */ X#endif X X#if RAINBOW X#include "rainbow.h" X#endif X X#if USG /* System V */ X#include X#include X#include Xint kbdflgs; /* saved keyboard fd flags */ Xint kbdpoll; /* in O_NDELAY mode */ Xint kbdqp; /* there is a char in kbdq */ Xchar kbdq; /* char we've already read */ Xstruct termio otermio; /* original terminal characteristics */ Xstruct termio ntermio; /* charactoristics to use inside */ X#endif X X#if V7 | BSD X#undef CTRL X#include /* for stty/gtty functions */ X#include Xstruct sgttyb ostate; /* saved tty state */ Xstruct sgttyb nstate; /* values for editor mode */ Xstruct tchars otchars; /* Saved terminal special character set */ Xstruct tchars ntchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; X /* A lot of nothing */ X#if BSD X#include /* to get at the typeahead */ Xextern int rtfrmshell(); /* return from suspended shell */ X#define TBUFSIZ 128 Xchar tobuf[TBUFSIZ]; /* terminal output buffer */ X#endif X#endif X X/* X * This function is called once to set up the terminal device streams. X * On VMS, it translates TT until it finds the terminal, then assigns X * a channel to it and sets it raw. On CPM it is a no-op. X */ Xttopen() X{ X#if AMIGA X char oline[NSTRING]; X#if AZTEC X extern Enable_Abort; /* Turn off ctrl-C interrupt */ X X Enable_Abort = 0; /* for the Manx compiler */ X#endif X strcpy(oline, "RAW:0/0/640/200/"); X strcat(oline, PROGNAME); X strcat(oline, " "); X strcat(oline, VERSION); X strcat(oline, "/Amiga"); X terminal = Open(oline, NEW); X#endif X#if VMS X struct dsc$descriptor idsc; X struct dsc$descriptor odsc; X char oname[40]; X int iosb[2]; X int status; X X odsc.dsc$a_pointer = "TT"; X odsc.dsc$w_length = strlen(odsc.dsc$a_pointer); X odsc.dsc$b_dtype = DSC$K_DTYPE_T; X odsc.dsc$b_class = DSC$K_CLASS_S; X idsc.dsc$b_dtype = DSC$K_DTYPE_T; X idsc.dsc$b_class = DSC$K_CLASS_S; X do { X idsc.dsc$a_pointer = odsc.dsc$a_pointer; X idsc.dsc$w_length = odsc.dsc$w_length; X odsc.dsc$a_pointer = &oname[0]; X odsc.dsc$w_length = sizeof(oname); X status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc); X if (status!=SS$_NORMAL && status!=SS$_NOTRAN) X exit(status); X if (oname[0] == 0x1B) { X odsc.dsc$a_pointer += 4; X odsc.dsc$w_length -= 4; X } X } while (status == SS$_NORMAL); X status = SYS$ASSIGN(&odsc, &iochan, 0, 0); X if (status != SS$_NORMAL) X exit(status); X status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0, X oldmode, sizeof(oldmode), 0, 0, 0, 0); X if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL) X exit(status); X newmode[0] = oldmode[0]; X newmode[1] = oldmode[1] | TT$M_NOECHO; X newmode[1] &= ~(TT$M_TTSYNC|TT$M_HOSTSYNC); X newmode[2] = oldmode[2] | TT2$M_PASTHRU; X status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0, X newmode, sizeof(newmode), 0, 0, 0, 0); X if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL) X exit(status); X term.t_nrow = (newmode[1]>>24) - 1; X term.t_ncol = newmode[0]>>16; X X#endif X#if CPM X#endif X X#if MSDOS & (HP150 == 0) & LATTICE X /* kill the ctrl-break interupt */ X rg.h.ah = 0x33; /* control-break check dos call */ X rg.h.al = 1; /* set the current state */ X rg.h.dl = 0; /* set it OFF */ X intdos(&rg, &rg); /* go for it! */ X#endif X X#if USG X ioctl(0, TCGETA, &otermio); /* save old settings */ X ntermio.c_iflag = 0; /* setup new settings */ X ntermio.c_oflag = 0; X ntermio.c_cflag = otermio.c_cflag; X ntermio.c_lflag = 0; X ntermio.c_line = otermio.c_line; X ntermio.c_cc[VMIN] = 1; X ntermio.c_cc[VTIME] = 0; X ioctl(0, TCSETA, &ntermio); /* and activate them */ X kbdflgs = fcntl( 0, F_GETFL, 0 ); X kbdpoll = FALSE; X#endif X X#if V7 | BSD X gtty(0, &ostate); /* save old state */ X gtty(0, &nstate); /* get base of new state */ X nstate.sg_flags |= RAW; X nstate.sg_flags &= ~(ECHO|CRMOD); /* no echo for now... */ X stty(0, &nstate); /* set mode */ X ioctl(0, TIOCGETC, &otchars); /* Save old characters */ X ioctl(0, TIOCSETC, &ntchars); /* Place new character into K */ X#if BSD X /* provide a smaller terminal output buffer so that X the type ahead detection works better (more often) */ X setbuffer(stdout, &tobuf[0], TBUFSIZ); X signal(SIGTSTP,SIG_DFL); /* set signals so that we can */ X signal(SIGCONT,rtfrmshell); /* suspend & restart emacs */ X#endif X#endif X /* on all screens we are not sure of the initial position X of the cursor */ X ttrow = 999; X ttcol = 999; X} X X/* X * This function gets called just before we go back home to the command X * interpreter. On VMS it puts the terminal back in a reasonable state. X * Another no-operation on CPM. X */ Xttclose() X{ X#if AMIGA X#if LATTICE X amg_flush(); X Close(terminal); X#endif X#if AZTEC X amg_flush(); X Enable_Abort = 1; /* Fix for Manx */ X Close(terminal); X#endif X#endif X X#if VMS X int status; X int iosb[1]; X X ttflush(); X status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0, X oldmode, sizeof(oldmode), 0, 0, 0, 0); X if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL) X exit(status); X status = SYS$DASSGN(iochan); X if (status != SS$_NORMAL) X exit(status); X#endif X#if CPM X#endif X#if MSDOS & (HP150 == 0) & LATTICE X /* restore the ctrl-break interupt */ X rg.h.ah = 0x33; /* control-break check dos call */ X rg.h.al = 1; /* set the current state */ X rg.h.dl = 1; /* set it ON */ X intdos(&rg, &rg); /* go for it! */ X#endif X X#if USG X ioctl(0, TCSETA, &otermio); /* restore terminal settings */ X fcntl(0, F_SETFL, kbdflgs); X#endif X X#if V7 | BSD X stty(0, &ostate); X ioctl(0, TIOCSETC, &otchars); /* Place old character into K */ X#endif X} X X/* X * Write a character to the display. On VMS, terminal output is buffered, and X * we just put the characters in the big array, after checking for overflow. X * On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on X * MS-DOS (use the very very raw console output routine). X */ Xttputc(c) X#if AMIGA X char c; X#endif X{ X#if AMIGA X scrn_tmp[scrn_tmp_p++] = c; X if(scrn_tmp_p>=AMG_MAXBUF) X amg_flush(); X#endif X#if VMS X if (nobuf >= NOBUF) X ttflush(); X obuf[nobuf++] = c; X#endif X X#if CPM X bios(BCONOUT, c, 0); X#endif X X#if MSDOS & MWC86 X putcnb(c); X#endif X X#if MSDOS & (LATTICE | AZTEC) & ~IBMPC X bdos(6, c, 0); X#endif X X#if RAINBOW X Put_Char(c); /* fast video */ X#endif X X X#if V7 | USG | BSD X fputc(c, stdout); X#endif X} X X#if AMIGA Xamg_flush() X{ X if(scrn_tmp_p) X Write(terminal,scrn_tmp,scrn_tmp_p); X scrn_tmp_p = 0; X} X#endif X X/* X * Flush terminal buffer. Does real work where the terminal output is buffered X * up. A no-operation on systems where byte at a time terminal I/O is done. X */ Xttflush() X{ X#if AMIGA X amg_flush(); X#endif X#if VMS X int status; X int iosb[2]; X X status = SS$_NORMAL; X if (nobuf != 0) { X status = SYS$QIOW(EFN, iochan, IO$_WRITELBLK|IO$M_NOFORMAT, X iosb, 0, 0, obuf, nobuf, 0, 0, 0, 0); X if (status == SS$_NORMAL) X status = iosb[0] & 0xFFFF; X nobuf = 0; X } X return (status); X#endif X X#if CPM X#endif X X#if MSDOS X#endif X X#if V7 | USG | BSD X fflush(stdout); X#endif X} X X/* X * Read a character from the terminal, performing no editing and doing no echo X * at all. More complex in VMS that almost anyplace else, which figures. Very X * simple on CPM, because the system can do exactly what you want. X */ Xttgetc() X{ X#if AMIGA X char ch; X amg_flush(); X Read(terminal, &ch, 1L); X return(255 & (int)ch); X#endif X#if VMS X int status; X int iosb[2]; X int term[2]; X X while (ibufi >= nibuf) { X ibufi = 0; X term[0] = 0; X term[1] = 0; X status = SYS$QIOW(EFN, iochan, IO$_READLBLK|IO$M_TIMED, X iosb, 0, 0, ibuf, NIBUF, 0, term, 0, 0); X if (status != SS$_NORMAL) X exit(status); X status = iosb[0] & 0xFFFF; X if (status!=SS$_NORMAL && status!=SS$_TIMEOUT) X exit(status); X nibuf = (iosb[0]>>16) + (iosb[1]>>16); X if (nibuf == 0) { X status = SYS$QIOW(EFN, iochan, IO$_READLBLK, X iosb, 0, 0, ibuf, 1, 0, term, 0, 0); X if (status != SS$_NORMAL X || (status = (iosb[0]&0xFFFF)) != SS$_NORMAL) X exit(status); X nibuf = (iosb[0]>>16) + (iosb[1]>>16); X } X } X return (ibuf[ibufi++] & 0xFF); /* Allow multinational */ X#endif X X#if CPM X return (biosb(BCONIN, 0, 0)); X#endif X X#if RAINBOW X int Ch; X X while ((Ch = Read_Keyboard()) < 0); X X if ((Ch & Function_Key) == 0) X if (!((Ch & 0xFF) == 015 || (Ch & 0xFF) == 0177)) X Ch &= 0xFF; X X return Ch; X#endif X X#if MSDOS & MWC86 X return (getcnb()); X#endif X X#if MSDOS & (LATTICE | MSC | TURBO | AZTEC) X int c; /* character read */ X X /* if a char already is ready, return it */ X if (nxtchar >= 0) { X c = nxtchar; X nxtchar = -1; X return(c); X } X X /* call the dos to get a char */ X rg.h.ah = 7; /* dos Direct Console Input call */ X intdos(&rg, &rg); X c = rg.h.al; /* grab the char */ X return(c & 255); X#endif X X#if V7 | BSD X return(127 & fgetc(stdin)); X#endif X X#if USG X if( kbdqp ) X kbdqp = FALSE; X else X { X if( kbdpoll && fcntl( 0, F_SETFL, kbdflgs ) < 0 ) X return FALSE; X kbdpoll = FALSE; X while (read(0, &kbdq, 1) != 1) X ; X } X return ( kbdq & 127 ); X#endif X} X X#if TYPEAH & (~ST520) X/* typahead: Check to see if any characters are already in the X keyboard buffer X*/ X Xtypahead() X X{ X#if MSDOS & (MSC | TURBO) X if (kbhit() != 0) X return(TRUE); X else X return(FALSE); X#endif X X#if MSDOS & (LATTICE | AZTEC | MWC86) X int c; /* character read */ X int flags; /* cpu flags from dos call */ X X if (nxtchar >= 0) X return(TRUE); X X rg.h.ah = 6; /* Direct Console I/O call */ X rg.h.dl = 255; /* does console input */ X#if LATTICE | AZTEC X flags = intdos(&rg, &rg); X#else X intcall(&rg, &rg, 0x21); X flags = rg.x.flags; X#endif X c = rg.h.al; /* grab the character */ X X /* no character pending */ X if ((flags & 64) != 0) X return(FALSE); X X /* save the character and return true */ X nxtchar = c; X return(TRUE); X#endif X X#if BSD X int x; /* holds # of pending chars */ X X return((ioctl(0,FIONREAD,&x) < 0) ? 0 : x); X#endif X X#if USG X if( !kbdqp ) X { X if( !kbdpoll && fcntl( 0, F_SETFL, kbdflgs | O_NDELAY ) < 0 ) X return(FALSE); X kbdqp = (1 == read( 0, &kbdq, 1 )); X } X return ( kbdqp ); X#endif X return(FALSE); X} X#endif X FRIDAY_NIGHT echo extracting - tipc.c sed 's/^X//' > tipc.c << 'FRIDAY_NIGHT' X/* X * The routines in this file provide support for the TI-PC and other X * compatible terminals. It goes directly to the graphics RAM to do X * screen output. It compiles into nothing if not a TI-PC driver X */ X X#define termdef 1 /* don't define "term" external */ X X#include X#include "estruct.h" X#include "edef.h" X X#if TIPC X X#define NROW 25 /* Screen size. */ X#define NCOL 80 /* Edit if you want to. */ X#define MARGIN 8 /* size of minimim margin and */ X#define SCRSIZ 64 /* scroll size for extended lines */ X#define NPAUSE 200 /* # times thru update to pause */ X#define BEL 0x07 /* BEL character. */ X#define ESC 0x1B /* ESC character. */ X#define SPACE 32 /* space character */ X#define SCADD 0xDE000L /* address of screen RAM */ X X#define CHAR_ENABLE 0x08 /* TI attribute to show char */ X#define TI_REVERSE 0x10 /* TI attribute to reverse char */ X#define BLACK 0+CHAR_ENABLE /* TI attribute for Black */ X#define BLUE 1+CHAR_ENABLE /* TI attribute for Blue */ X#define RED 2+CHAR_ENABLE /* TI attribute for Red */ X#define MAGENTA 3+CHAR_ENABLE /* TI attribute for Magenta */ X#define GREEN 4+CHAR_ENABLE /* TI attribute for Green */ X#define CYAN 5+CHAR_ENABLE /* TI attribute for Cyan */ X#define YELLOW 6+CHAR_ENABLE /* TI attribute for Yellow */ X#define WHITE 7+CHAR_ENABLE /* TI attribute for White */ X X Xextern int ttopen(); /* Forward references. */ Xextern int ttgetc(); Xextern int ttputc(); Xextern int ttflush(); Xextern int ttclose(); Xextern int timove(); Xextern int tieeol(); Xextern int tieeop(); Xextern int tibeep(); Xextern int tiopen(); Xextern int tirev(); Xextern int ticres(); Xextern int ticlose(); Xextern int tiputc(); X X#if COLOR Xextern int tifcol(); Xextern int tibcol(); X Xint cfcolor = -1; /* current forground color */ Xint cbcolor = -1; /* current background color */ Xint ctrans[] = /* ansi to ti color translation table */ X {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE}; X#endif X X/* X * Standard terminal interface dispatch table. Most of the fields point into X * "termio" code. X */ XTERM term = { X NROW-1, X NROW-1, X NCOL, X NCOL, X MARGIN, X SCRSIZ, X NPAUSE, X tiopen, X ticlose, X ttgetc, X tiputc, X ttflush, X timove, X tieeol, X tieeop, X tibeep, X tirev, X ticres X#if COLOR X , tifcol, X tibcol X#endif X}; X Xextern union REGS rg; X X#if COLOR Xsetatt( attr ) Xint attr; X{ X rg.h.ah = 0x16; /* set the forground character attribute */ X rg.h.bl = attr; X int86( 0x49, &rg, &rg ); X} X Xtifcol(color) /* set the current output color */ X Xint color; /* color to set */ X X{ X cfcolor = ctrans[color]; X setatt ( cfcolor ); X} X Xtibcol(color) /* set the current background color */ X Xint color; /* color to set */ X X{ X cbcolor = ctrans[color]; X} X#endif X Xtimove(row, col) X{ X rg.h.ah = 2; /* set cursor position function code */ X rg.h.dh = col; X rg.h.dl = row; X int86(0x49, &rg, &rg); X} X Xtieeol() /* erase to the end of the line */ X X{ X int ccol; /* current column cursor lives */ X int crow; /* row */ X X /* find the current cursor position */ X rg.h.ah = 3; /* read cursor position function code */ X int86(0x49, &rg, &rg); X ccol = rg.h.dh; /* record current column */ X crow = rg.h.dl; /* and row */ X X rg.h.ah = 0x09; /* Write character at cursor position */ X rg.h.al = ' '; /* Space */ X rg.h.bl = cfcolor; X rg.x.cx = NCOL-ccol; /* Number of characters to write */ X int86(0x49, &rg, &rg); X X} X Xtiputc(ch) /* put a character at the current position in the X current colors */ X Xint ch; X X{ X rg.h.ah = 0x0E; /* write char to screen with current attrs */ X rg.h.al = ch; X int86(0x49, &rg, &rg); X} X Xtieeop() /* Actually a clear screen */ X{ X X rg.h.ah = 0x13; /* Clear Text Screen and Home Cursor */ X int86(0x49, &rg, &rg); X} X Xtirev(state) /* change reverse video state */ X Xint state; /* TRUE = reverse, FALSE = normal */ X X{ X setatt( state ? cbcolor : cfcolor ); X} X Xticres() /* change screen resolution */ X X{ X return(TRUE); X} X Xspal() /* change palette string */ X X{ X /* Does nothing here */ X} X Xtibeep() X{ X bdos(6, BEL, 0); X} X Xtiopen() X{ X strcpy(sres, "NORMAL"); X revexist = TRUE; X ttopen(); X} X Xticlose() X X{ X#if COLOR X tifcol(7); X tibcol(0); X#endif X ttclose(); X} X#else Xtihello() X{ X} X#endif X FRIDAY_NIGHT echo extracting - vmsvt.c sed 's/^X//' > vmsvt.c << 'FRIDAY_NIGHT' X/* X * Advanced VMS terminal driver X * X * Knows about any terminal defined in SMGTERMS.TXT and TERMTABLE.TXT X * located in SYS$SYSTEM. X * X * Author: Curtis Smith X * Last Updated: 07/14/87 X */ X X#include /* Standard I/O package */ X#include "estruct.h" /* Emacs' structures */ X#include "edef.h" /* Emacs' definitions */ X X#if VMSVT X X#include /* Descriptor definitions */ X X/* These would normally come from iodef.h and ttdef.h */ X#define IO$_SENSEMODE 0x27 /* Sense mode of terminal */ X#define TT$_UNKNOWN 0x00 /* Unknown terminal */ X X/** Forward references **/ Xint vmsopen(), ttclose(), vmskopen(), vmskclose(), ttgetc(), ttputc(); Xint ttflush(), vmsmove(), vmseeol(), vmseeop(), vmsbeep(), vmsrev(); Xint vmscres(); Xextern int eolexist, revexist; Xextern char sres[]; X X#if COLOR Xint vmsfcol(), vmsbcol(); X#endif X X/** SMG stuff **/ Xstatic char * begin_reverse, * end_reverse, * erase_to_end_line; Xstatic char * erase_whole_display; Xstatic int termtype; X X#define SMG$K_BEGIN_REVERSE 0x1bf X#define SMG$K_END_REVERSE 0x1d6 X#define SMG$K_SET_CURSOR_ABS 0x23a X#define SMG$K_ERASE_WHOLE_DISPLAY 0x1da X#define SMG$K_ERASE_TO_END_LINE 0x1d9 X X X/* Dispatch table. All hard fields just point into the terminal I/O code. */ XTERM term = { X 24 - 1, /* Max number of rows allowable */ X /* Filled in */ - 1, /* Current number of rows used */ X 132, /* Max number of columns */ X /* Filled in */ 0, /* Current number of columns */ X 64, /* Min margin for extended lines*/ X 8, /* Size of scroll region */ X 100, /* # times thru update to pause */ X vmsopen, /* Open terminal at the start */ X ttclose, /* Close terminal at end */ X vmskopen, /* Open keyboard */ X vmskclose, /* Close keyboard */ X ttgetc, /* Get character from keyboard */ X ttputc, /* Put character to display */ X ttflush, /* Flush output buffers */ X vmsmove, /* Move cursor, origin 0 */ X vmseeol, /* Erase to end of line */ X vmseeop, /* Erase to end of page */ X vmsbeep, /* Beep */ X vmsrev, /* Set reverse video state */ X vmscres /* Change screen resolution */ X#if COLOR X , vmsfcol, /* Set forground color */ X vmsbcol /* Set background color */ X#endif X}; X X/*** X * ttputs - Send a string to ttputc X * X * Nothing returned X ***/ Xttputs(string) Xchar * string; /* String to write */ X{ X if (string) X while (*string != '\0') X ttputc(*string++); X} X X X/*** X * vmsmove - Move the cursor (0 origin) X * X * Nothing returned X ***/ Xvmsmove(row, col) Xint row; /* Row position */ Xint col; /* Column position */ X{ X char buffer[32]; X int ret_length; X static int request_code = SMG$K_SET_CURSOR_ABS; X static int max_buffer_length = sizeof(buffer); X static int arg_list[3] = { 2 }; X register char * cp; X X register int i; X X /* Set the arguments into the arg_list array X * SMG assumes the row/column positions are 1 based (boo!) X */ X arg_list[1] = row + 1; X arg_list[2] = col + 1; X X if ((smg$get_term_data( /* Get terminal data */ X &termtype, /* Terminal table address */ X &request_code, /* Request code */ X &max_buffer_length, /* Maximum buffer length */ X &ret_length, /* Return length */ X buffer, /* Capability data buffer */ X arg_list) /* Argument list array */ X X /* We'll know soon enough if this doesn't work */ X & 1) == 0) { X ttputs("OOPS"); X return; X } X X /* Send out resulting sequence */ X i = ret_length; X cp = buffer; X while (i-- > 0) X ttputc(*cp++); X} X X X/*** X * vmsrev - Set the reverse video status X * X * Nothing returned X ***/ Xvmsrev(status) Xint status; /* TRUE if setting reverse */ X{ X if (status) X ttputs(begin_reverse); X else X ttputs(end_reverse); X} X X/*** X * vmscres - Change screen resolution (which it doesn't) X * X * Nothing returned X ***/ Xvmscres() X{ X /* But it could. For vt100/vt200s, one could switch from X 80 and 132 columns modes */ X} X X X#if COLOR X/*** X * vmsfcol - Set the forground color (not implimented) X * X * Nothing returned X ***/ Xvmsfcol() X{ X} X X/*** X * vmsbcol - Set the background color (not implimented) X * X * Nothing returned X ***/ Xvmsbcol() X{ X} X#endif X X/*** X * vmseeol - Erase to end of line X * X * Nothing returned X ***/ Xvmseeol() X{ X ttputs(erase_to_end_line); X} X X X/*** X * vmseeop - Erase to end of page (clear screen) X * X * Nothing returned X ***/ Xvmseeop() X{ X ttputs(erase_whole_display); X} X X X/*** X * vmsbeep - Ring the bell X * X * Nothing returned X ***/ Xvmsbeep() X{ X ttputc('\007'); X} X X X/*** X * vmsgetstr - Get an SMG string capability by name X * X * Returns: Escape sequence X * NULL No escape sequence available X ***/ Xchar * vmsgetstr(request_code) Xint request_code; /* Request code */ X{ X register char * result; X static char seq_storage[1024]; X static char * buffer = seq_storage; X static int arg_list[2] = { 1, 1 }; X int max_buffer_length, ret_length; X X /* Precompute buffer length */ X X max_buffer_length = (seq_storage + sizeof(seq_storage)) - buffer; X X /* Get terminal commands sequence from master table */ X X if ((smg$get_term_data( /* Get terminal data */ X &termtype, /* Terminal table address */ X &request_code, /* Request code */ X &max_buffer_length,/* Maximum buffer length */ X &ret_length, /* Return length */ X buffer, /* Capability data buffer */ X arg_list) /* Argument list array */ X X /* If this doesn't work, try again with no arguments */ X X & 1) == 0 && X X (smg$get_term_data( /* Get terminal data */ X &termtype, /* Terminal table address */ X &request_code, /* Request code */ X &max_buffer_length,/* Maximum buffer length */ X &ret_length, /* Return length */ X buffer) /* Capability data buffer */ X X /* Return NULL pointer if capability is not available */ X X & 1) == 0) X return NULL; X X /* Check for empty result */ X if (ret_length == 0) X return NULL; X X /* Save current position so we can return it to caller */ X X result = buffer; X X /* NIL terminate the sequence for return */ X X buffer[ret_length] = 0; X X /* Advance buffer */ X X buffer += ret_length + 1; X X /* Return capability to user */ X return result; X} X X X/** I/O information block definitions **/ Xstruct iosb { /* I/O status block */ X short i_cond; /* Condition value */ X short i_xfer; /* Transfer count */ X long i_info; /* Device information */ X}; Xstruct termchar { /* Terminal characteristics */ X char t_class; /* Terminal class */ X char t_type; /* Terminal type */ X short t_width; /* Terminal width in characters */ X long t_mandl; /* Terminal's mode and length */ X long t_extend; /* Extended terminal characteristics */ X}; Xstatic struct termchar tc; /* Terminal characteristics */ X X/*** X * vmsgtty - Get terminal type from system control block X * X * Nothing returned X ***/ Xvmsgtty() X{ X short fd; X int status; X struct iosb iostatus; X $DESCRIPTOR(devnam, "SYS$INPUT"); X X /* Assign input to a channel */ X status = sys$assign(&devnam, &fd, 0, 0); X if ((status & 1) == 0) X exit (status); X X /* Get terminal characteristics */ X status = sys$qiow( /* Queue and wait */ X 0, /* Wait on event flag zero */ X fd, /* Channel to input terminal */ X IO$_SENSEMODE, /* Get current characteristic */ X &iostatus, /* Status after operation */ X 0, 0, /* No AST service */ X &tc, /* Terminal characteristics buf */ X sizeof(tc), /* Size of the buffer */ X 0, 0, 0, 0); /* P3-P6 unused */ X X /* De-assign the input device */ X if ((sys$dassgn(fd) & 1) == 0) X exit(status); X X /* Jump out if bad status */ X if ((status & 1) == 0) X exit(status); X if ((iostatus.i_cond & 1) == 0) X exit(iostatus.i_cond); X} X X X/*** X * vmsopen - Get terminal type and open terminal X * X * Nothing returned X ***/ Xvmsopen() X{ X /* Get terminal type */ X vmsgtty(); X if (tc.t_type == TT$_UNKNOWN) { X printf("Terminal type is unknown!\n"); X printf("Try set your terminal type with SET TERMINAL/INQUIRE\n"); X printf("Or get help on SET TERMINAL/DEVICE_TYPE\n"); X exit(3); X } X X /* Access the system terminal definition table for the */ X /* information of the terminal type returned by IO$_SENSEMODE */ X if ((smg$init_term_table_by_type(&tc.t_type, &termtype) & 1) == 0) X return -1; X X /* Set sizes */ X term.t_nrow = ((unsigned int) tc.t_mandl >> 24) - 1; X term.t_ncol = tc.t_width; X X /* Get some capabilities */ X begin_reverse = vmsgetstr(SMG$K_BEGIN_REVERSE); X end_reverse = vmsgetstr(SMG$K_END_REVERSE); X revexist = begin_reverse != NULL && end_reverse != NULL; X erase_to_end_line = vmsgetstr(SMG$K_ERASE_TO_END_LINE); X eolexist = erase_to_end_line != NULL; X erase_whole_display = vmsgetstr(SMG$K_ERASE_WHOLE_DISPLAY); X X /* Set resolution */ X strcpy(sres, "NORMAL"); X X /* Open terminal I/O drivers */ X ttopen(); X} X X X/*** X * vmskopen - Open keyboard (not used) X * X * Nothing returned X ***/ Xvmskopen() X{ X} X X X/*** X * vmskclose - Close keyboard (not used) X * X * Nothing returned X ***/ Xvmskclose() X{ X} X X X/*** X * fnclabel - Label function keys (not used) X * X * Nothing returned X ***/ X#if FLABEL Xfnclabel(f, n) /* label a function key */ Xint f,n; /* default flag, numeric argument [unused] */ X{ X /* on machines with no function keys...don't bother */ X return(TRUE); X} X#endif X X X/*** X * spal - Set palette type (Are you kidding?) X * X * Nothing returned X ***/ Xspal() X{ X} X X#else X X/*** X * hellovms - Avoid error because of empty module X * X * Nothing returned X ***/ Xhellovms() X{ X} X X#endif FRIDAY_NIGHT echo mes.12 completed! # That's all folks!