Relay-Version: version Notes 2.6.8 86/05/15 (HP beta); site wdl1.UUCP From: herder@myab.UUCP (Jan Herder) Date: Tue, 8 Jul 86 18:08:20 PDT Date-Received: Fri, 11 Jul 86 13:52:42 PDT Subject: Ugly fix to make larn run on a non vt100 Message-ID: <147@myab.UUCP> Path: wdl1!sun!decwrl!decvax!bellcore!ulysses!allegra!princeton!caip!topaz!husc6!seismo!mcvax!enea!chalmers!myab!herder Newsgroups: net.sources.games Reply-To: herder@myab.UUCP (Jan Herder) Lines: 1179 This is a set of files that makes it possible to run larn on non vt100s. It's done by integrating a stripped down version of the vt100 emulator vtem into larn. The first file "patchfile" is a context diff. To apply it do "patch < patchfile". It's only been tested on SYSV.2.2. To make it work on BSD you need to change "-lcurses" into "-ltermcap" in Makefile. There is also a bug fix for napms in the diff file. This bug made napms loop forever when called with 0 as an argument. #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # patchfile # out.c # term.c # vtem.h # This archive created: Tue Jul 8 18:46:19 1986 export PATH; PATH=/bin:/usr/bin:$PATH echo shar: "extracting 'patchfile'" '(4817 characters)' if test -f 'patchfile' then echo shar: "will not over-write existing file 'patchfile'" else sed 's/^ X//' << \SHAR_EOF > 'patchfile' X*** Makefile Tue Jul 8 17:59:25 1986 X--- ../Makefile Tue Jul 8 17:35:24 1986 X*************** X*** 18,24 X # BIGCURSOR - This may speed up execution on machines where memory is cheap X # SAVEINHOME - put save files in users HOME instead of LARNHOME X X! OPTIONS = -DWIZZARD -DWIZID=320 -DEXTRA -DBSD X X # if running a Unisoft 68000 system V, use assembly language assist X # SOBJS= savelevel.o strlen.o strcpy.o lprcatstr.o X X--- 18,24 ----- X # BIGCURSOR - This may speed up execution on machines where memory is cheap X # SAVEINHOME - put save files in users HOME instead of LARNHOME X X! OPTIONS = -DWIZZARD -DWIZID=27 -DEXTRA -DSYSV X X # if running a Unisoft 68000 system V, use assembly language assist X # SOBJS= savelevel.o strlen.o strcpy.o lprcatstr.o X*************** X*** 32,38 X OBJS= main.o object.o create.o tok.o display.o global.o data.o termio.o\ X fileio.o monster.o store.o diag.o help.o config.o nap.o bill.o scores.o\ X signal.o altar.o fountain.o movem.o throne.o chest.o cursor.o regen.o\ X! fortune.o strcpy.o X X DOTFILES= .larn.help .larnmaze .larnopts .lfortune\ X .mail601 .mail602 .mail603 .mail604 .mail605 X X--- 32,38 ----- X OBJS= main.o object.o create.o tok.o display.o global.o data.o termio.o\ X fileio.o monster.o store.o diag.o help.o config.o nap.o bill.o scores.o\ X signal.o altar.o fountain.o movem.o throne.o chest.o cursor.o regen.o\ X! fortune.o strcpy.o out.o term.o X X DOTFILES= .larn.help .larnmaze .larnopts .lfortune\ X .mail601 .mail602 .mail603 .mail604 .mail605 X*************** X*** 41,47 X X larn: larn11.0 X larn11.0: $(OBJS) $(SOBJS) X! cc -o larn11.0 $(FLAGS) $(OBJS) $(SOBJS) X X all: larn install X X X--- 41,47 ----- X X larn: larn11.0 X larn11.0: $(OBJS) $(SOBJS) X! cc -o larn11.0 $(FLAGS) $(OBJS) $(SOBJS) -lcurses X X all: larn install X X*************** X*** 49,54 X cc -c $(FLAGS) $< X X $(OBJS): header.h X X install: X if test ! -d $(LARNHOME) ; then mkdir $(LARNHOME); fi X X--- 49,56 ----- X cc -c $(FLAGS) $< X X $(OBJS): header.h X+ X+ out.o term.o: vtem.h X X install: X if test ! -d $(LARNHOME) ; then mkdir $(LARNHOME); fi X*** fileio.c Tue Jul 8 18:32:08 1986 X--- ../fileio.c Tue Jul 8 18:13:30 1986 X*************** X*** 140,146 X register int num2; X if (len > 500) /* dont copy data if can just write it */ X { X! lflush(); write(lfd,buf,len); X #ifdef EXTRA X c[BYTESOUT] += len; X #endif X X--- 140,150 ----- X register int num2; X if (len > 500) /* dont copy data if can just write it */ X { X! lflush(); X! if(lfd == 1) X! vtwrite(lfd,buf,len); X! else X! write(lfd,buf,len); X #ifdef EXTRA X c[BYTESOUT] += len; X #endif X*************** X*** 361,368 X #ifdef EXTRA X c[BYTESOUT] += lpoint; X #endif X! if (write(lfd,lpbuf,lpoint) != lpoint) X! write(1,"error writing to output file\n",29); X } X lpnt = lpbuf; X } X X--- 365,375 ----- X #ifdef EXTRA X c[BYTESOUT] += lpoint; X #endif X! if(lfd == 1) X! vtwrite(lfd,lpbuf,lpoint); X! else X! if (write(lfd,lpbuf,lpoint) != lpoint) X! write(1,"error writing to output file\n",29); X } X lpnt = lpbuf; X } X*** main.c Tue Jul 8 18:32:21 1986 X--- ../main.c Tue Jul 8 12:12:29 1986 X*************** X*** 43,48 X int j,hard; X char *ttype,*getenv(),*ptr,*getlogin(); X struct cel *malloc(); X userid = getuid(); /* obtain the user's login id number */ X if ((ptr = getlogin()) == 0) X if ((ptr = getenv("USER")) == 0) X X--- 43,49 ----- X int j,hard; X char *ttype,*getenv(),*ptr,*getlogin(); X struct cel *malloc(); X+ X userid = getuid(); /* obtain the user's login id number */ X if ((ptr = getlogin()) == 0) X if ((ptr = getenv("USER")) == 0) X*************** X*** 93,106 X #endif TIMECHECK X X lcreat(0); newgame(); /* set the initial clock */ hard= -1; X! ttype = getenv("TERM"); X! for (j=1, i=0; i times(&stats)) X ; X } X SHAR_EOF if test 4817 -ne "`wc -c < 'patchfile'`" then echo shar: "error transmitting 'patchfile'" '(should have been 4817 characters)' fi fi echo shar: "extracting 'out.c'" '(10262 characters)' if test -f 'out.c' then echo shar: "will not over-write existing file 'out.c'" else sed 's/^ X//' << \SHAR_EOF > 'out.c' X/* X * vtem - A termcap driven VT100 emulator for BSD Unix X * X * Version 1.1 X * X * Public domain software. X * Written by Leif Samuelsson (leif@erisun) in December, 1985 X */ X X#include "vtem.h" X Xtypedef Bool int; Xtypedef enum { NORMAL, GRAPHICS } char_set; X Xstatic int row, col, save_row, save_col, top_margin, bottom_margin; Xstatic char_set g0_set, g1_set; Xstatic Bool blink, bold, reverse, underline, save_blink, save_bold, X save_reverse, save_underline, origin_mode, vt52_mode, wrap, X shift_out; X Xstatic short tabs[80]; Xstatic int arg[10], argno; Xstatic int glen; Xstatic char *gbuf; X X/* arow is absolute row, taking top_margin into account */ X#define arow (row + (origin_mode ? (top_margin - 1) : 0)) X Xvtget() X{ X if(glen-- > 0) X return *gbuf++; X else X return EOF; X} X X/* nextch - read output and interpret control characters. X * Return first non-control character. X */ Xint nextch() X{ Xregister int ch; X X while ((ch = vtget()) != EOF) { X switch (ch) { X case '\0': /* Ignore nulls and DELs */ X case '\177': X break; X case '\007': /* Bell */ X ring_bell(); break; X case '\b': /* BackSpace */ X if (col > 1) { X col--; X backspace(); X } break; X case '\t': /* Tab */ X while (col < 80 && !tabs[col++]); X set_cursor(col-1, arow-1); break; X X case '\n': /* Line Feed */ X do_linefeed(); break; X case '\r': /* Carriage Return */ X if (col > 1) { X col = 1; X cr(); X } break; X case '\016': X shift_out = 1; break; X case '\017': X shift_out = 0; break; X default: X return(ch); X } X } X return(ch); X} X Xvtinit() X{ Xregister int ch; X X gettermtype(); X do_reset(); X} X Xvtwrite(fd,buf,len) Xchar *buf; X{ X register int ch; X X gbuf = buf; X glen = len; X while ((ch = nextch()) != EOF) { X if (ch == '\033') { /* Escape character */ X if (vt52_mode) X do_vt52_escape(); X else X do_ansi_escape(); X } X else if (ch >= ' ') { /* Printing character */ X if ((shift_out ? g1_set : g0_set) == GRAPHICS) { X if (ch >= '_') X ch = " *#HFCLo+NV+++++---__++++!<>P##. "[ch - '_']; X } X if (col == 81) { X if (wrap) { X col = 1; X set_cursor(col-1, arow-1); X do_linefeed(); X } X else { X col = 80; X set_cursor(col-1, arow-1); X } X } X if (col == 80) { X if (arow != 24) X putchar(ch); /* Must ignore last pos */ X set_cursor(col-1, arow-1); X if (wrap) X col++; X } X else { X putchar(ch); X col++; X } X } X } X fflush(stdout); X} X X/* do_ansi_escape - reads and interprets an ANSI escape sequence X */ X Xdo_ansi_escape() X{ Xregister int ch; X X if ((ch = nextch()) == EOF) X return; X switch (ch) { X case '#': X do_hash(); X break; X case '(': X case ')': X do_character_sets(ch); break; X case '7': X save_row = row; X save_col = col; X save_blink = blink; X save_bold = bold; X save_reverse = reverse; X save_underline = underline; X break; X case '8': X if (save_row > 0) { X row = save_row; X col = save_col; X set_cursor(col-1, arow-1); X if (blink = save_blink) X start_blink(); X if (bold = save_bold) X start_bold(); X if (reverse = save_reverse) X start_reverse(); X if (underline = save_underline) X start_underline(); X } break; X X case 'D': X do_linefeed(); break; X X case 'E': X if (col > 1) { X col = 1; X cr(); X } X do_linefeed(); break; X X case 'H': X tabs[col-1] = 1; break; X X case 'M': X do_reverse_lf(); break; X X case '[': X do_csi(); break; X X case 'c': X do_reset(); break; X } X} X X/* do_csi - the real ANSI interpreter X */ Xdo_csi() X{ Xregister int i, ch; Xint private; X X if ((ch = nextch()) == EOF) X return; X X /* Check if private VT100 esc sequence */ X private = 0; X if (ch == '?') { X private = 1; X if ((ch = nextch()) == EOF) X return; X } X X /* Parse arguments */ X argno = 0; X while ((ch >= '0' && ch <= '9') || ch == ';') { X arg[argno] = 0; X while (ch >= '0' && ch <= '9') { X arg[argno] = arg[argno] * 10 + (ch - '0'); X if ((ch = nextch()) == EOF) X return; X } X if (ch == ';') X if ((ch = nextch()) == EOF) X return; X argno++; X } X X if (private) { X if (argno != 1) X return; X switch (ch) { X case 'h': X switch (arg[0]) { X case 6: X origin_mode = 1; break; X case 7: X wrap = 1; break; X } break; X case 'l': X switch (arg[0]) { X case 2: X vt52_mode = 1; break; X case 6: X origin_mode = 0; break; X case 7: X wrap = 0; break; X } break; X } X } X else { X switch (ch) { X case 'A': X i = (argno == 1 && arg[0] > 0) ? arg[0] : 1; X while (i-- && arow > 1 && arow != top_margin) { X cursor_up(); X row--; X } break; X X case 'B': X i = (argno == 1 && arg[0] > 0) ? arg[0] : 1; X while (i-- && arow < 24 && arow != bottom_margin) { X cursor_down(); X row++; X } break; X X case 'C': X i = (argno == 1 && arg[0] > 0) ? arg[0] : 1; X while (i-- && col < 80) { X cursor_right(); X col++; X } break; X X case 'D': X i = (argno == 1 && arg[0] > 0) ? arg[0] : 1; X while (i-- && col > 1) { X backspace(); X col--; X } break; X X case 'H': X case 'f': X do_set_cursor(); break; X case 'J': X do_erase_in_display(); break; X case 'K': X do_erase_in_line(); break; X case 'L': X do_insert_line(); break; X case 'M': X do_delete_line(); break; X case 'g': X do_clear_tabs(); break; X case 'm': X do_attributes(); break; X case 'r': X do_set_scroll_region(); X } X } X} X X/* do_vt52_escape - interprets VT52 escape sequences X */ Xdo_vt52_escape() X{ Xregister int ch; X X if ((ch = nextch()) == EOF) X return; X switch (ch) { X case '<': X vt52_mode = 0; break; X case 'A': X if (row > 1) { X cursor_up(); X row--; X } break; X case 'B': X if (row < bottom_margin-top_margin+1) { X cursor_down(); X row++; X } break; X case 'C': X if (col < 80) { X cursor_right(); X col++; X } break; X case 'D': X if (col > 1) { X backspace(); X col--; X } break; X case 'H': X row = col = 1; X set_cursor(col-1, arow-1); break; X case 'I': X do_reverse_lf(); break; X case 'J': X clear_eos(); break; X case 'K': X clear_eol(col-1, arow-1); break; X case 'Y': X do_vt52_set_cursor(); break; X } X} X X Xdo_set_cursor() X{ X if (arg[0] == 0) X arg[0]++; X if (arg[1] == 0) X arg[1]++; X switch (argno) { X case 0: X arg[0] = 1; X argno++; X /* Fall through */ X X case 1: X arg[1] = 1; /* Correct? */ X argno++; X /* Fall through... */ X X case 2: X row = arg[0]; X col = arg[1]; X set_cursor(col-1, arow-1); X break; X } X} X Xdo_vt52_set_cursor() X{ Xregister int ch1, ch2; X X if ((ch1 = nextch()) == EOF) X return; X if ((ch2 = nextch()) == EOF) X return; X ch1 -= 0x1f; X ch2 -= 0x1f; X if (ch1 >= 1 && ch1 <= 24 && ch2 >= 1 && ch2 <= 80) { X row = ch1; X col = ch2; X set_cursor(col-1, arow-1); X } X} X Xdo_erase_in_display() X{ X switch (argno) { X case 0: X arg[0] = 0; X argno++; X /* Fall through */ X case 1: X switch (arg[0]) { X case 0: X clear_eos(); X break; X case 1: X clear_bos(col-1, arow-1); X break; X case 2: X clear_screen(); X set_cursor(col-1, arow-1); X break; X } X break; X } X} X Xdo_erase_in_line() X{ X switch(argno) { X case 0: X arg[0] = 0; X argno++; X /* fall through */ X case 1: X switch (arg[0]) { X case 0: X clear_eol(col-1, arow-1); X break; X case 1: X clear_bol(col-1, arow-1); X break; X case 2: X cr(); X clear_eol(0, arow-1); X set_cursor(col-1, arow-1); X break; X } break; X } X} X Xdo_clear_tabs() X{ Xregister int i; X X if (argno == 0) X arg[argno++] = 0; X switch (arg[0]) { X case 0: X tabs[col-1] = 0; break; X case 3: X for (i = 0; i<80; i++) X tabs[i] = 0; break; X } X} X Xdo_attributes() X{ Xregister int i; X X if (argno == 0) { X arg[0] = 0; X argno++; X } X for (i=0; i 1) { X row--; X reverse_lf(); X } X} X Xdo_hash() X{ Xregister int ch, i, j; X X if ((ch = nextch()) == EOF) X return; X switch(ch) { X case '8': X for (i=1; i<=24; i++) { X set_cursor(0, i-1); X for (j=1; j <= ((i==24)?79:80); j++) X putchar('E'); X } X row = col = 1; X set_cursor(col-1, arow-1); /* Correct? */ X break; X } X} X X/* do_characters_sets - Not implemented X */ Xdo_character_sets(ch) Xregister int ch; X{ Xregister int ch2; X X if ((ch2 = nextch()) == EOF) X return; X switch (ch2) { X case 'A': X case 'B': X if (ch == '(') X g0_set = NORMAL; X else X g1_set = NORMAL; X break; X case '0': X if (ch == '(') X g0_set = GRAPHICS; X else X g1_set = GRAPHICS; X break; X } X} X X/* do_reset - Reset emulator and screen X */ Xdo_reset() X{ Xregister int i; X X clear_screen(); X row = 1; X col = 1; X top_margin = 1; X bottom_margin = 24; X origin_mode = 0; X vt52_mode = 0; X wrap = 1; X g0_set = NORMAL; X g1_set = NORMAL; X shift_out = 0; X save_row = -1; /* So we know we haven't saved */ X for (i=0; i<80; i++) X tabs[i] = ((i/8)*8 == i); X} X X/* The following are routines for VT102 compatibility X */ X Xdo_insert_line() X{ X/* Not yet implemented */ X} X Xdo_delete_line() X{ X/* Not yet implemented */ X} SHAR_EOF if test 10262 -ne "`wc -c < 'out.c'`" then echo shar: "error transmitting 'out.c'" '(should have been 10262 characters)' fi fi echo shar: "extracting 'term.c'" '(4663 characters)' if test -f 'term.c' then echo shar: "will not over-write existing file 'term.c'" else sed 's/^ X//' << \SHAR_EOF > 'term.c' X/* X * vt - A termcap driven VT100 emulator for BSD Unix X * X * Version 1.1 X * X * Public domain software. X * Written by Leif Samuelsson (leif@erisun) in December, 1985 X */ X X X/* This module contains termcap and tty routines */ X X#include "vtem.h" X Xextern char *tgetstr(), *tgoto(); X X/* Variables for saving original terminal parameters */ X int oldlb, newlb, oldl, newl; X X/* Terminal attributes */ Xchar tbuf[1024]; XBool BS; Xint CO, LI; Xchar *AL, *BC, *BL, *CD, *CL, *CE, *CM, *CR, *CS, *DL, *DO, X *KE, *KS, *MB, *MD, *ME, *MR, *ND, *NL, *SE, *SO, *SR, X *TI, *TE, *UE, *UP, *US, *MAL, *MDL; X Xputchar_x(c) Xchar c; X{ X putchar(c); X} X X X/* gettermtype - Finds terminal type and reads termcap entry for it. X */ Xgettermtype() X{ Xchar tptr[1024]; Xchar *termtyp; Xchar *tbufptr; X X termtyp=getenv("TERM"); X switch(tgetent(tptr,termtyp)) { X case -1: X printf("Can't read termcap\n"); X exit(1); X case 0: X printf("Can't find your terminal type (%s) in termcap\n", termtyp); X exit(1); X } X tbufptr=tbuf; X AL = tgetstr("al", &tbufptr); X BC = tgetstr("bc", &tbufptr); X BL = tgetstr("bl", &tbufptr); X if (!BL) X BL = "\007"; X BS = tgetflag("bs",&tbufptr); X if (!BC && BS) X BC = "\b"; X CD = tgetstr("cd", &tbufptr); X CL = tgetstr("cl", &tbufptr); X CE = tgetstr("ce", &tbufptr); X CM = tgetstr("cm", &tbufptr); X CR = tgetstr("cr", &tbufptr); X if (!CR) X CR = "\r"; X CS = tgetstr("cs", &tbufptr); X DL = tgetstr("dl", &tbufptr); X DO = tgetstr("do", &tbufptr); X if (!DO) X DO = "\n"; X KE = tgetstr("ke", &tbufptr); X KS = tgetstr("ks", &tbufptr); X ND = tgetstr("nd", &tbufptr); X NL = tgetstr("nl", &tbufptr); X if (!NL) X NL = "\n"; X if(tgetnum("sg") <= 0){ X MB = tgetstr("mb", &tbufptr); X ME = tgetstr("me", &tbufptr); X MR = tgetstr("mr", &tbufptr); X SO = tgetstr("so", &tbufptr); X SE = tgetstr("se", &tbufptr); X UE = tgetstr("ue", &tbufptr); X US = tgetstr("us", &tbufptr); X } X SR = tgetstr("sr", &tbufptr); X TI = tgetstr("ti", &tbufptr); X TE = tgetstr("te", &tbufptr); X UP = tgetstr("up", &tbufptr); X MAL = tgetstr("AL", &tbufptr); X MDL = tgetstr("DL", &tbufptr); X CO = tgetnum("co"); X LI = tgetnum("li"); X if(!TI) { X TI = tgetstr("vs", &tbufptr); X TE = tgetstr("ve", &tbufptr); X } X X if (CO < 80 || LI < 24) { X printf("Sorry, but vtem requires 24 by 80 lines.\r\n"); X exit(1); X } X if (!CM) { X printf("Sorry, but vtem requires cursor motion capability (cm).\r\n"); X exit(1); X } X if (!CL) { X printf("Sorry, but vtem requires clear screen capability (cl).\r\n"); X exit(1); X } X if (!UP) { X printf("Sorry, but vtem requires cursor up capability (up).\r\n"); X exit(1); X } X} X X X/* clear_bos - clear from beginning of screen to cursor X */ Xclear_bos(c,r) Xint c,r; X{ Xregister int i; X X for (i=0; i 'vtem.h' X#include X#include X X#define FALSE 0 X#define TRUE 1 X Xtypedef short Bool; X Xextern char *getenv(); Xextern putchar_x(); X Xextern struct tchars oldtchars, newtchars; Xextern struct ltchars oldltchars, newltchars; Xextern int oldlb, newlb, oldl, newl; X Xextern int master; X Xextern Bool BS; Xextern int CO, LI; Xextern char *AL, *BC, *BL, *CD, *CL, *CE, *CM, *CR, *CS, *DL, *DO, *KE, *KS, *MB, *MD, *ME, *MR, *ND, *NL, *SE, *SO, *SR, *TI, *TE, *UE, *UP, *US, *MAL, *MDL; X X#define tputs_x(s) (tputs(s, 0, putchar_x)) X X#define backspace() (tputs_x(BC)) X#define clear_screen() (tputs_x(CL)) X#define set_cursor(c, r) (tputs_x(tgoto(CM, (c), (r)))) X#define linefeed() (tputs_x(NL)) X#define cr() (tputs_x(CR)) SHAR_EOF if test 720 -ne "`wc -c < 'vtem.h'`" then echo shar: "error transmitting 'vtem.h'" '(should have been 720 characters)' fi fi exit 0 # End of shell archive