Xref: utzoo unix-pc.sources:363 comp.sys.att:7291 Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!mailrus!rutgers!mit-eddie!bu-cs!att!dptg!holin!bes From: bes@holin.ATT.COM (Bradley Smith) Newsgroups: unix-pc.sources,comp.sys.att Subject: uipc.p3 Message-ID: <650@holin.ATT.COM> Date: 12 Aug 89 16:37:41 GMT Distribution: unix-pc Organization: AT&T Bell Labs, OIL, Holmdel, NJ Lines: 1973 : This is a shar archive. Extract with sh, not csh. : This archive ends with exit, so do not worry about trailing junk. if test -f 'Vtem' then rm 'Vtem' fi if test -d 'Vtem' then : else echo 'Making Vtem/' mkdir 'Vtem' fi chmod 'u=rwx,g=rx,o=rx' 'Vtem' echo 'Extracting Vtem/Makefile' sed 's/^X//' > Vtem/Makefile << '+ END-OF-FILE Vtem/Makefile' XCFLAGS= -DUNIXPC -DSYSV X# CC=cc X X Xvtem: vtem.o term.o out.o X $(CC) $(LDFLAGS) -o vtem vtem.o term.o out.o -luipc -lcurses X X.c.o: ; $(CC) $(CFLAGS) -c $*.c X Xshar: ; shar README vtem.1 Makefile vtem.h vtem.c term.c out.c test.cat> vtem.shar X Xclean: X rm -f vtem *.o + END-OF-FILE Vtem/Makefile chmod 'u=rw,g=r,o=r' 'Vtem/Makefile' echo ' -rw-r--r-- 1 bes HSJ 264 Aug 12 09:10 Vtem/Makefile (as sent)' echo ' \c' /bin/ls -l Vtem/Makefile echo 'Extracting Vtem/README' sed 's/^X//' > Vtem/README << '+ END-OF-FILE Vtem/README' X X XThis is hacked version of the "vtem" program. It is intended to Xwork on the AT&T Unix-pc and provides a vt100 terminal emulation. XIt has been enhanced to handle the alternate character set of Xthe vt100. Other than the alternate character set it should work Xfine on any unix machine. To test it cat the file test.cat. X X X XMuhammad S. Benten Xboulder.colorado.edu + END-OF-FILE Vtem/README chmod 'u=rw,g=r,o=r' 'Vtem/README' echo ' -rw-r--r-- 1 bes HSJ 362 Mar 6 18:17 Vtem/README (as sent)' echo ' \c' /bin/ls -l Vtem/README echo 'Extracting Vtem/out.c' sed 's/^X//' > Vtem/out.c << '+ END-OF-FILE Vtem/out.c' X/* X * vt - A termcap driven VT100 emulator for BSD Unix X * X * Version 2.0 X * X * Public domain software. X * Written by Leif Samuelsson (leif@erisun) in December, 1985 X * X * X * X * Modified to handle alternate character set and for SYS-5 by X * Muhammad S. Benten X * University of Colorado X * Boulder. X * December, 1988 X * X */ X X#include "vtem.h" Xextern int shiftit; Xtypedef Bool int; X Xstatic int row, col, save_row, save_col, top_margin, bottom_margin; Xstatic Bool blink, bold, reverse, underline, save_blink, save_bold, X save_reverse, save_underline, origin_mode, vt52_mode, wrap; X Xstatic short tabs[80]; Xstatic int arg[10], argno; X X/* arow is absolute row, taking top_margin into account */ X#define arow (row + (origin_mode ? (top_margin - 1) : 0)) X X X/* nextch - read output and interpret control characters. X * Return first non-control character. X */ Xint nextch() X{ X register char ch; /* */ X/* register int ch; /* */ X X /* while ((ch = getc(stdin)) != EOF) { /* */ X while(1) { ch = nextchar(); /* */ X switch (ch) { X case '\177': X case '\0': 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++] == 0) ); 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': /* Ignore shift in/out */ X shiftit=1; X putchar(ch); X break; X case '\017': X shiftit=0; X putchar(ch); X break; X default: X return(ch); X } X if (stdin->_cnt == 0) X fflush(stdout); X } X return(ch); X} Xint next_cnt = -1; Xint next_end = 0; Xchar next_buffer[BUFSIZ]; X Xnextchar() X{ X int ret, rfd; X X next_cnt++; X if(next_cnt == next_end) { /* need to read */ X rfd = 1; /* stdin */ X /* current select doesn't work on pipes */ X /* ret = select(8, &rfd, 0, 0, 0); /* */ X next_end = read(0, next_buffer, BUFSIZ); X next_cnt = 0; X } X /* have some already */ X return(next_buffer[next_cnt]); X} X X X/* handle_output - Main loop of output process. X * Reads and dispatches characters from output stream. X */ Xhandle_output() X{ Xregister int ch; X X gettermtype(); X do_reset(); 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 (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 if (stdin->_cnt == 0) X fflush(stdout); X } X exit(0); 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 do_character_sets(0); break; X case ')': X do_character_sets(1); 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++; 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++; break; X case 7: X wrap++; 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-- && row > 1) { X cursor_up(); X row--; X } break; X X case 'B': X i = (argno == 1 && arg[0] > 0) ? arg[0] : 1; X while (i-- && row < bottom_margin-top_margin+1) { 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# ifdef UNIXPC X#include X#define UK "/usr/lib/wfont/UK.ft" X#define US "/usr/lib/wfont/system.8.ft" X#define LD "/usr/lib/wfont/SCLD.ft" X#define RC "/usr/lib/wfont/ROMC.ft" X#define RG "/usr/lib/wfont/ROMG.ft" X#endif X/* do_characters_sets - Not implemented X */ Xdo_character_sets(slot) Xint slot; X{ X#ifdef UNIXPC Xchar ch; Xstruct { X short uf_slot; X char uf_name[60]; X } ufdata; X X sprintf(ufdata.uf_name,US); X ufdata.uf_slot = 0; X ch = nextch(); /* Ignore for now */ X switch(ch) { X case 'A': X sprintf(ufdata.uf_name,UK); X ufdata.uf_slot = slot; X break; X case 'B': X sprintf(ufdata.uf_name,US); X ufdata.uf_slot = slot; X break; X case '0': X sprintf(ufdata.uf_name,LD); X ufdata.uf_slot = slot; X break; X case '1': X sprintf(ufdata.uf_name,RC); X ufdata.uf_slot = slot; X break; X case '2': X sprintf(ufdata.uf_name,RG); X ufdata.uf_slot = slot; X break; X } X ioctl(1,WIOCLFONT,&ufdata); X#endif 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 save_row = -1; /* So we know we haven't saved */ X for (i=0; i<80; i++) X if ((i/8)*8 == i) X tabs[i] =1; X else X tabs[i] =0; X} + END-OF-FILE Vtem/out.c chmod 'u=rw,g=r,o=r' 'Vtem/out.c' echo ' -rw-r--r-- 1 bes HSJ 11155 Aug 11 23:44 Vtem/out.c (as sent)' echo ' \c' /bin/ls -l Vtem/out.c echo 'Extracting Vtem/term.c' sed 's/^X//' > Vtem/term.c << '+ END-OF-FILE Vtem/term.c' X/* X * vt - A termcap driven VT100 emulator for BSD Unix X * X * Version 2.0 X * X * Public domain software. X * Written by Leif Samuelsson (leif@erisun) in December, 1985 X * X * X * X * Modified to work on SYS-5 Unix and to handle alternate character set by X * Muhammad S. Benten X * benten@boulder.colorado.edu X * December, 1988 X * X */ X X X/* This module contains termcap and tty routines */ X X#include "vtem.h" Xextern int shiftit; Xint shiftit; X Xextern char *tgetstr(), *tgoto(); X X/* Variables for saving original terminal parameters */ X#ifndef SYSV /* V7 style */ X struct sgttyb oldb, newb; X#else X struct termio oldtermio,newtermio; X#endif 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 Xttycbreak() X{ X#ifdef SYSV X ioctl(0, TCGETA, &oldtermio); X ioctl(0, TCGETA, &newtermio); X newtermio.c_oflag=0; X newtermio.c_lflag &= ~(ICANON|ECHO); X newtermio.c_cc[4] = 1; /* at least 1 char */ X newtermio.c_cc[5] = -1; /* wait for ever? */ X ioctl(0, TCSETA, &newtermio); X#else X ioctl(0, TIOCGETP, &newb); X newb.sg_flags |= RAW; X newb.sg_flags &= ~(ECHO); X ioctl(0, TIOCSETP, &newb); X#endif X X X signal(SIGINT,SIG_IGN); X signal(SIGQUIT,SIG_IGN); /* */ 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 MB = tgetstr("mb", &tbufptr); X ME = tgetstr("me", &tbufptr); X MR = tgetstr("mr", &tbufptr); X ND = tgetstr("nd", &tbufptr); X NL = tgetstr("nl", &tbufptr); X if (!NL) X NL = "\n"; X SO = tgetstr("so", &tbufptr); X SE = tgetstr("se", &tbufptr); X SR = tgetstr("sr", &tbufptr); X TI = tgetstr("ti", &tbufptr); X TE = tgetstr("te", &tbufptr); X UE = tgetstr("ue", &tbufptr); X UP = tgetstr("up", &tbufptr); X US = tgetstr("us", &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 Xsetup_term(flg) /* If flg==TRUE, set line in cbreak mode and */ XBool flg; /* initialize the terminal,otherwise restore */ X{ X if (flg) { X ttycbreak(); X if (TI) X tputs_x(TI); /* start CM mode */ X } X else { X if (KE) X tputs_x(KE); /* Restores Keypad */ X if (TE) X tputs_x(TE); /* exit CM mode */ X#ifndef SYSV X ioctl(0, TIOCSETP, &oldb); X#else X ioctl(0, TCSETA, &oldtermio); X#endif 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/vtem.1 << '+ END-OF-FILE Vtem/vtem.1' X.TH VTEM 1 1986-01-24 X.SH NAME Xvtem - a VT100 emulator based on termcap X.SH SYNOPSIS X.I vtem X.SH DESCRIPTION X.I vtem Xruns on BSD4.2 and works by starting a sub-shell and then translating Xoutput escape sequences. It's function is limited by the capabilities Xlisted in the termcap database and the capabilities of the actual Xterminal that it is being run on. X XIt has been tested with Per Lindberg's excellent verifier "vttest" and Xhas been found to give acceptable results on the following terminals: X X Sun windows X.br X PC-Kermit in h19 emulation mode. X.br X VT100 (!) X XOn a Sun, you can use the following Suntools rootmenu entry: X X.nf X"VT100 Tool" shelltool -Ww 80 -Wh 24 -Wl " VT100 Tool" vtem X.fi X.SH BUGS XRelease 1.0 of vtem has the following bugs and limitations: X XRegion scroll will only work on terminals with Xcs or al/dl. X XIt will never write in the last position of the screen, Xbecause of the unpredictable behaviour of many terminals. X XVT102 capabilities are not yet implemented. X XNo soft scroll. X X132 width not supported. X XInput is not translated, which means no function key emulation. X XNo double height or double width lines. X XNo alternate character set, meaning no graphics. X XNo printer support. X XNo status reports, answerback messages, etc. X XNo SETUP mode. X XNo LEDs. X.SH AUTHOR XLeif Samuelsson X.br Xleif@erisun.UUCP or ..enea!erix!erisun!leif X + END-OF-FILE Vtem/vtem.1 chmod 'u=rw,g=r,o=r' 'Vtem/vtem.1' echo ' -rw-r--r-- 1 bes HSJ 1358 Mar 6 18:17 Vtem/vtem.1 (as sent)' echo ' \c' /bin/ls -l Vtem/vtem.1 echo 'Extracting Vtem/vtem.c' sed 's/^X//' > Vtem/vtem.c << '+ END-OF-FILE Vtem/vtem.c' X/* X * vt - A termcap driven VT100 emulator for BSD Unix X * X * Version 2.0 X * X * Public domain software. X * Written by Leif Samuelsson (leif@erisun) in December, 1985 X * X * X * X * Modified to work on SYS-5 Unix and to handle alternate character X * set on the Unix-pc by X * Muhammad S. Benten X * benten@boulder.colorado.edu X * December, 1988 X * X */ X X#include "vtem.h" X#include X Xint master, slave, child1,child2; Xchar linec, linen; Xstruct termio termio; Xint file_pipe[2]; X X Xdone() X{ Xunion wait status; X X if (wait(&status) != child1) X return; X kill(child2,SIGTERM); X setup_term(0); X exit(0); X} X Xmain() X{ X /* Strategy: Start three processes, one for input, one for output X * and one shell. X */ X pipe(file_pipe); X X setup_term(TRUE); X setup_pty(); X if ( (child1 = fork()) == 0 ) { X close(master); X start_shell(); X exit(1); X } X X if ( (child2 = fork()) == 0 ) { X close(0); X dup(file_pipe[0]); X handle_output(); X } X X signal(SIGCLD, done); X handle_input(); X} X Xhandle_input() X{ X char buf[BUFSIZ]; X int i,j,k; X int bitmask; X long t, ti; X char *ctime(); X X /* j=open(ttyname(0),4); /* */ X j=open(ttyname(0),2); /* */ X t = 10; X while (1) { X bitmask = 1 << master; X bitmask |= 1 << j; X i = select(32, &bitmask, 0, 0, 0); X if(i) X { X if(bitmask & (1 << master)) { X i = read(master,buf,BUFSIZ); X if ( i > 0 ) X write(file_pipe[1], buf, i); X } X if(bitmask & (1 << j)) { X i = read(j, buf, BUFSIZ) ; X if ( i > 0 ) X write(master, buf, i); X } X } X } X} X X Xstart_shell() X{ Xint t; Xchar *cp, shellname[20],shellpgm[100], *strrchr(); X X if ((cp = getenv("SHELL")) == (char *)0) X strcpy(shellpgm, "sh"); X else X strcpy(shellpgm, cp); X if ((cp = (char *) strrchr(shellpgm,'/')) == (char *)0) X strcpy(shellname, shellpgm); X else X strcpy(shellname, &cp[1]); X close(0); X dup(slave); X close(1); X dup(slave); X close(2); X dup(slave); X close(slave); X signal(SIGINT,SIG_DFL); X signal(SIGQUIT,SIG_DFL); X printf("Welcome to the vt100 emulator\n"); X execlp(shellpgm, shellname,0); X printf("vtem: Cannot start the shell '%s' \nvtem: Please cheack the SHELL environment variable\n",shellpgm); X sleep(1); X} X X X Xsetup_pty() X{ Xchar line[11]; X X for (linec = 'p'; linec <= 'q'; linec++) { X sprintf(line, "/dev/pty%c0", linec); X if (access(line, 0) != 0) X break; X for (linen = 0; linen < 16; linen++) { X sprintf(line, "/dev/pty%c%1x", linec, linen); X master = open(line, 2|4); /* */ X /* master = open(line, 2); /* */ X if (master >= 0) { X sprintf(line, "/dev/tty%c%1x", linec, linen); X slave = open(line, 2); X if (slave < 0) { X perror(line); X setup_term(0); X exit(1); X } X ioctl(master, TCSETA, (char *)&oldtermio); X return; X } X } X } X X perror("pty in setup_pty\n"); X setup_term(0); X exit(1); X} X X Xperror(x) Xchar *x; X{ X fprintf(stderr,"vtem: Unknown problem with %s\n\r",x); X} + END-OF-FILE Vtem/vtem.c chmod 'u=rw,g=r,o=r' 'Vtem/vtem.c' echo ' -rw-r--r-- 1 bes HSJ 3035 Aug 11 22:54 Vtem/vtem.c (as sent)' echo ' \c' /bin/ls -l Vtem/vtem.c echo 'Extracting Vtem/vtem.h' sed 's/^X//' > Vtem/vtem.h << '+ END-OF-FILE Vtem/vtem.h' X#include X#include X#include X#include X#include 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 X#ifndef SYSV /* for version 7 based systems */ Xextern struct sgttyb oldb, newb; X#else /* for system V or III based systems */ Xextern struct termio oldtermio, newtermio; X#endif Xextern int oldlb, newlb; 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 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)) X + END-OF-FILE Vtem/vtem.h chmod 'u=rw,g=r,o=r' 'Vtem/vtem.h' echo ' -rw-r--r-- 1 bes HSJ 901 Mar 6 18:24 Vtem/vtem.h (as sent)' echo ' \c' /bin/ls -l Vtem/vtem.h if test -f 'test' then rm 'test' fi if test -d 'test' then : else echo 'Making test/' mkdir 'test' fi chmod 'u=rwx,g=rx,o=rx' 'test' echo 'Extracting test/Makefile' sed 's/^X//' > test/Makefile << '+ END-OF-FILE test/Makefile' X# X# Makefile.test X# XRM=/bin/rm X#CC=cc XCFLAGS=-I.. $(VFLAG) -g X XCMDS=test1 test2 test3 test4 bind1 conn1 bind2 conn2 tcpread tcpsend X Xall: $(CMDS) ../lib/libuipc.a X X$(CMDS): $$@.c X $(CC) $(CFLAGS) -O $? -o $@ ../lib/libuipc.a X Xclean: X $(RM) -f $(CMDS) *.o core + END-OF-FILE test/Makefile chmod 'u=rw,g=rw,o=rw' 'test/Makefile' echo ' -rw-rw-rw- 1 bes HSJ 260 Aug 11 22:47 test/Makefile (as sent)' echo ' \c' /bin/ls -l test/Makefile echo 'Extracting test/bind1.c' sed 's/^X//' > test/bind1.c << '+ END-OF-FILE test/bind1.c' X#include X#include X#include X X#include X#define NAME "/tmp/socket" X Xmain() X{ X int sock, msgsock, length; X struct sockaddr_un server; X char buf[1024]; X int rval; X X if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) X { X perror ("opening stream socket"); X exit (1); X } X server.sun_family = AF_UNIX; X strcpy(server.sun_path, NAME); X if (bind (sock, &server, sizeof (struct sockaddr_un))) X { X perror ("binding server to stream socket"); X exit (1); X } X printf ("socket -->%s\n", NAME); X listen (sock, 5); X for (;;) X { X if ((msgsock = accept (sock, 0, 0)) == -1) X perror ("accept"); X else do X { X bzero (buf, sizeof (buf)); X if ((rval = read (msgsock, buf, 1024)) < 0) X { X printf ("read returned %d\n", rval); X perror ("reading stream message"); X } X else if (rval == 0) X printf ("ending connection\n"); X else X printf ("-->%s\n", buf); X } while (rval > 0); X close (msgsock); X } X write (2, "burp2!\n", 7); X close (sock); X unlink (NAME); X} X Xbzero(s,n) X char * s; X int n; X{ X while (n--) X *s++ = '\0'; X} + END-OF-FILE test/bind1.c chmod 'u=rw,g=rw,o=rw' 'test/bind1.c' echo ' -rw-rw-rw- 1 bes HSJ 1177 Jul 18 23:44 test/bind1.c (as sent)' echo ' \c' /bin/ls -l test/bind1.c echo 'Extracting test/bind2.c' sed 's/^X//' > test/bind2.c << '+ END-OF-FILE test/bind2.c' X#include X#include X#include X X#include X#define NAME "/tmp/dgramsock" X Xmain () X{ X int sock, length; X struct sockaddr_un name; X char buf[1024]; X X sock = socket (AF_UNIX, SOCK_DGRAM, 0); X if (sock < 0) X { X perror ("opening dgram socket"); X exit (1); X } X name.sun_family = AF_UNIX; X strcpy (name.sun_path, NAME); X if (bind (sock, &name, sizeof (struct sockaddr_un))) X { X perror ("binding name to datagram socket"); X exit (1); X } X printf ("socket -->%s\n", NAME); X if (read (sock, buf, 1024) < 0) X perror ("Receiving datagram packet"); X printf ("-->%s\n", buf); X close (sock); X unlink (NAME); X} + END-OF-FILE test/bind2.c chmod 'u=rw,g=rw,o=rw' 'test/bind2.c' echo ' -rw-rw-rw- 1 bes HSJ 708 Jul 18 23:44 test/bind2.c (as sent)' echo ' \c' /bin/ls -l test/bind2.c echo 'Extracting test/conn1.c' sed 's/^X//' > test/conn1.c << '+ END-OF-FILE test/conn1.c' X#ifndef LINT Xstatic char *sccsdef = "conn1.c 1.1 6/19/89"; X#endif X X#include X#include X#include X X#define DATA "Half a league, half a league... " X Xmain(c,v) X int c; X char ** v; X{ X int sock; X struct sockaddr_un server; X char buf[1024]; X int file, j, cnt = 0; X X sock = socket (AF_UNIX, SOCK_STREAM, 0); X if (sock < 0) X { X perror ("opening stream socket"); X exit (1); X } X server.sun_family = AF_UNIX; X strcpy(server.sun_path, v[1]); X X if (connect (sock, &server, sizeof (struct sockaddr_un)) < 0) X { X close (sock); X perror ("connecting stream socket"); X exit (1); X } X file = open (v[2], 0); X X while ((j = read (file, buf, 124)) > 0) X { X int i; X X if ((i = write (sock, buf, j)) < 0) X { X perror ("writing"); X break; X } X else X printf( "read/wrote line, cnt = %d\n", cnt += i); X } X} + END-OF-FILE test/conn1.c chmod 'u=rw,g=rw,o=rw' 'test/conn1.c' echo ' -rw-rw-rw- 1 bes HSJ 914 Jul 18 23:44 test/conn1.c (as sent)' echo ' \c' /bin/ls -l test/conn1.c echo 'Extracting test/conn2.c' sed 's/^X//' > test/conn2.c << '+ END-OF-FILE test/conn2.c' X#include X#include X#include X#include X X#define DATA "Half a league, half a league ...\n" X Xmain (argc, argv) X int argc; X char * argv[]; X{ X int sock; X struct sockaddr_un name; X X sock = socket (AF_UNIX, SOCK_DGRAM, 0); X if (sock < 0) X { X perror ("opening dgram socket"); X exit (1); X } X name.sun_family = AF_UNIX; X strcpy (name.sun_path, argv[1]); X if (sendto (sock, DATA, sizeof (DATA), 0, X &name, sizeof (struct sockaddr_un)) < 0) X perror ("sending datagram message"); X close (sock); X} + END-OF-FILE test/conn2.c chmod 'u=rw,g=rw,o=rw' 'test/conn2.c' echo ' -rw-rw-rw- 1 bes HSJ 583 Jul 18 23:44 test/conn2.c (as sent)' echo ' \c' /bin/ls -l test/conn2.c echo 'Extracting test/tcpread.c' sed 's/^X//' > test/tcpread.c << '+ END-OF-FILE test/tcpread.c' X#include X#include X#include X#include X Xchar *PORT; X#define TESTSIZE 512 X Xchar sourcebuf[TESTSIZE]; Xchar sinkbuf[TESTSIZE]; X Xextern int errno; Xstruct sockaddr_un sinsource; Xstruct sockaddr_un sinsink; Xint s, s1, ns; X Xlong t; Xextern char *ctime(); X X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X if(argc != 2) { X fprintf(stderr,"usage: %s port_name\n", argv[0]); X exit(-1); X } X PORT = argv[1]; X /* tcploopinit(); */ X tcpsource(); X tcpsink(); X} Xtcpsource() X{ X int i, cc; X struct hostent *hp; X sinsource.sun_family = AF_UNIX; X sinsink.sun_family = AF_UNIX; X X for(i = 0; i< TESTSIZE;i++) { X sinkbuf[i] = 0; X sourcebuf[i] = i; X } X s1 = socket(AF_UNIX, SOCK_STREAM, 0); X if( s1 == -1) { X perror("Second socket() failed!"); X exit(1); X } X strcpy(sinsource.sun_path,PORT); X strcpy(sinsink.sun_path,PORT); X X X if(bind(s1, &sinsink, sizeof(struct sockaddr_un)) == -1) { X perror("Frist bind failed!"); X exit(1); X } X X if(listen(s1, 5) == -1) { X perror("Listen failed!\n"); X exit(1); X } X X} Xtcpsink() X{ X int i; X int hismsglen; X static int addrlen = 0; X int sret, srd, swr, sex; X long t; X int a2, ret; X char xxx[16]; X X X X ns = accept(s1, (char *) &sinsink, &addrlen); X X X do { X sleep(1); X a2 = 1 << ns; /* all ones */ X time(&t); X printf("test readfds, set all it to %d - %s",s1, ctime(&t)); X t = 3; X ret = select(32,&a2,0,0,&t); X time(&t); X printf("return = %d, a2 = %d - %s", ret, a2,ctime(&t)); X } while(ret == 0); X X X X /* initaize sink buffer (to see if I/O really takes place) */ X X for(i=0;i < TESTSIZE;i++) X sinkbuf[i] = 5; X X X hismsglen = read(ns, sinkbuf, TESTSIZE); X if(hismsglen > 0) { X printf("tcpsink: %d characters where received\n" X ,hismsglen); X#ifdef PRINTCHARS X for(i=0;i test/tcpsend.c << '+ END-OF-FILE test/tcpsend.c' X#include X#include X#include X#include X#include X Xchar *PORT; X#define TESTSIZE 512 X Xchar sourcebuf[TESTSIZE]; Xchar sinkbuf[TESTSIZE]; X Xextern int errno; Xstruct sockaddr_un sinsource; Xstruct sockaddr_un sinsink; Xint s, s1, ns; Xint endit(); X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X if(argc != 2) { X fprintf(stderr,"usage: %s port_name\n", argv[0]); X exit(-1); X } X PORT=argv[1]; X signal(SIGINT, endit); X tcpsource(); X} Xtcpsource() X{ X int i, cc; X struct hostent *hp; X char bb[16]; X X sinsource.sun_family = AF_UNIX; X sinsink.sun_family = AF_UNIX; X X for(i = 0; i< TESTSIZE;i++) { X sinkbuf[i] = 0; X sourcebuf[i] = i; X } X s = socket(AF_UNIX, SOCK_STREAM, 0); X if (s == -1) { X perror("Frist socket() failed!"); X exit(1); X } X strcpy(sinsource.sun_path,PORT); X strcpy(sinsink.sun_path,PORT); X X X if(connect(s, &sinsource, sizeof(struct sockaddr_un)) == -1) { X perror("Connect failed on sinsource!"); X exit(1); X } X X X i=128; X printf("hit return\n"); X gets(bb); X cc = write(s,sourcebuf, i); /* */ X if(cc > 0) { X printf("%d characters sent\n", cc); X i++; X sleep(2); X }else { X perror("Send failed!"); X exit(1); X } X printf("done hi return\n"); X gets(bb); X close(s); X unlink(PORT); X exit(0); X} Xendit() X{ X close(s); X unlink(PORT); X exit(0); X} + END-OF-FILE test/tcpsend.c chmod 'u=rw,g=r,o=r' 'test/tcpsend.c' echo ' -rw-r--r-- 1 bes HSJ 1299 Aug 2 19:57 test/tcpsend.c (as sent)' echo ' \c' /bin/ls -l test/tcpsend.c echo 'Extracting test/test1.c' sed 's/^X//' > test/test1.c << '+ END-OF-FILE test/test1.c' X#include X#include X#include X#include X X#define DATA1 "In Xanadu, did Kublai Kahn..." X#define DATA2 "A Stately pleasure dome decree ..." X Xsigcatch (sig) X int sig; X{ X printf ("died on a SIGPIPE\n"); X exit (0); X} X Xmain () X{ X int sockets[2], child; X char buf[1024]; X X setbuf (stdout, 0); X X signal (SIGPIPE, sigcatch); X X if (socketpair (AF_UNIX, SOCK_STREAM, 0, sockets) < 0) X { X extern int errno; X printf ("socketpair error [%d].\n", errno); X exit(1); X } X X if ((child = fork ()) == -1) X perror ("fork"); X else if (child) X { X close (sockets[0]); X if (read(sockets[1], buf, 1024) < 0) X perror ("reading stream message [1]"); X printf ("-->%s\n", buf); X if (write (sockets[1], DATA1, sizeof (DATA2)) < 0) X perror ("writing stream message [1]"); X close (sockets[1]); X } X else X { X close (sockets[1]); X if (write (sockets[0], DATA2, sizeof (DATA2)) < 0) X perror ("writing stream message [0]"); X if (read(sockets[0], buf, 1024) < 0) X perror ("reading stream message [0]"); X printf ("-->%s\n", buf); X close(sockets[0]); X } X} X + END-OF-FILE test/test1.c chmod 'u=rw,g=rw,o=rw' 'test/test1.c' echo ' -rw-rw-rw- 1 bes HSJ 1200 Jul 18 23:44 test/test1.c (as sent)' echo ' \c' /bin/ls -l test/test1.c echo 'Extracting test/test2.c' sed 's/^X//' > test/test2.c << '+ END-OF-FILE test/test2.c' X#include X#include X#include X X#define DATA1 "In Xanadu, did Kublai Kahn..." X#define DATA2 "A Stately pleasure dome decree ..." X Xpipehandle () X{ Xprintf ("died on SIGPIPE\n"); Xexit(0); X} X Xmain () X{ X int sockets[2], child; X char buf[1024]; X X signal(13,pipehandle); X X if (socketpair (AF_UNIX, SOCK_STREAM, 0, sockets) < 0) X { X extern int errno; X printf ("socketpair error [%d].\n", errno); X exit(1); X } X X close (sockets[1]); X X if (write (sockets[0], DATA2, sizeof (DATA2)) < 0) X perror ("writing stream message"); X X close (sockets[0]); X X while(1); X} + END-OF-FILE test/test2.c chmod 'u=rw,g=rw,o=rw' 'test/test2.c' echo ' -rw-rw-rw- 1 bes HSJ 636 Jul 18 23:44 test/test2.c (as sent)' echo ' \c' /bin/ls -l test/test2.c echo 'Extracting test/test3.c' sed 's/^X//' > test/test3.c << '+ END-OF-FILE test/test3.c' X#include X#include X#include X X#define DATA1 "In Xanadu, did Kublai Kahn..." X#define DATA2 "A Stately pleasure dome decree ..." X Xmain () X{ X int sockets[2], child; X char buf[1024]; X X if (socketpair (AF_UNIX, SOCK_STREAM, 0, sockets) < 0) X { X extern int errno; X printf ("socketpair error [%d].\n", errno); X exit(1); X } X X close (sockets[1]); X X if (read (sockets[0], DATA2, sizeof (DATA2))) X perror ("reading stream message"); X X close (sockets[0]); X X while(1); X} + END-OF-FILE test/test3.c chmod 'u=rw,g=rw,o=rw' 'test/test3.c' echo ' -rw-rw-rw- 1 bes HSJ 545 Jul 18 23:44 test/test3.c (as sent)' echo ' \c' /bin/ls -l test/test3.c echo 'Extracting test/test4.c' sed 's/^X//' > test/test4.c << '+ END-OF-FILE test/test4.c' X#include X#include X#include X X#define DATA1 "In Xanadu, did Kublai Kahn..." X#define DATA2 "A Stately pleasure dome decree ..." X Xmain (argc, argv) X int argc; X char ** argv; X{ X int sockets[2], file, cnt = 0, j; X char buf[124]; X X setbuf (stdout, NULL); X X if (socketpair (AF_UNIX, SOCK_STREAM, 0, sockets) < 0) X { X extern int errno; X printf ("socketpair error [%d].\n", errno); X exit(1); X } X X file = open (argv[1], 0); X X while ((j = read (file, buf, 124)) > 0) X { X int i; X X if ((i = write (sockets[0], buf, j)) < 0) X { X perror ("writing"); X break; X } X else X printf( "read/wrote line, cnt = %d\n", cnt += i); X } X while ((j = read (sockets[1], buf, 124)) != 0) X write (1, buf, j); X} X + END-OF-FILE test/test4.c chmod 'u=rw,g=rw,o=rw' 'test/test4.c' echo ' -rw-rw-rw- 1 bes HSJ 799 Jul 18 23:44 test/test4.c (as sent)' echo ' \c' /bin/ls -l test/test4.c exit 0 -- Bradley Smith Computer Systems Offer Integration Laboratory AT&T Bell Labs, Holmdel, NJ 201-949-0090 att!holin!bes or bes@holin.ATT.COM