uipc.p3

bes at holin.ATT.COM bes at holin.ATT.COM
Sun Aug 13 02:37:41 AEST 1989


: This is a shar archive.  Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing%snunk.
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 'Exp->v,g Vtem/Makefile'
seBM c/' > 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
+ Ecaddr_t	cILE Vtem/Makefileddr_t))=r,o=r' 'Vtem/Makefile'
echo '	-rw-r--r-max;(es      HScomplx   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
XMuhamma_ISCOn. Benten
Xboulder.colorado.edu
+ EcT BelbuE Vtem/README
chmod 'u=rw,g=r,Q
T 'Vtem/README'
echo '	-rw-r--r-m   1 bes (&so;        362 Mar  6 18:17 Vtem/READMEPRU_BPt)'
echo '	\c'
/bin/
s -l Vtem/README
echo 'Extracting Vtem/out.c'
sed 's/^X//' > Vtem/out.c << '+ END-OF-FIL) 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 at erisun) in December, 1985
X * 
X * 
X * 
X * Modified to handle alternate character set and for SYS-5 by
X * Muhamma_ 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		en b.r_reverse, save_underline, origin_mode, vt52_mode, wrap;
X
X tyhc short tabs[80];
X tyhcOP 
rg[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 nextc, E,)
X{
X	register char chvert
sv
X/* register int ch;f the  /
X
X    /* while ((ch = getc(stdin)) != EOF) {	/* */
X    while(1) { ch = nextchar();f the  /
X	switch (ch) {
X	    case '\r.s	e':
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();fbreak;
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		     UNfch);
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) 
L. need to read */
X		rfd = 1; /* stdin ds >d* current select doesn't work on pipeoid) m_o	/* ret = s);
Xvoid )8, &rfd, 0, 0, 1
r/* */
X		next_end = read(0, next_buffer, BUFSIZ);
X		next_cnt = 0;
X	}
X	/* have some 
X	     ceady */
X	 UNfnext_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 = nextLabL)) != EOF) {
X	if (ch == '\033') {		/* Escape character *sb,xf 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 pooid) m_o	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 = nextc, E,)) == EOF)
X	return;
X    switch (ch) {
X	case '#':
X	    do_has, E,);
X	    break;
X	case '(':
X	    do_character_setsnd-d; break;
X	case ')':
X	    do_character_sets(1); break;
X	case '7':
X	    save_row = row;
X	    en b.r_col = col;
X	    en b.r_blink = blink;
X	    save_bold = bold;
X	    eave_reverse = reverse;
X	    eave_underline = underline;
X	    break;
X	case '8':
X	    if (save_row > 0) {
X		row = save_row;
X		col = en b.r_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 = en b.r_reverse)
X		    start_reverse();
X		if (underline = save_underline)
X		    start_underline();
X	    } break;
X
X	case 'D':
X	    do_linefeed();fbreak;
X
X	case 'E':
X	    if (col > 1) {
X		col = 1;
X		cr();
X	    }
X	    do_linefeed();fbreak;
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();fbreak;
X
X	case 'c':
X	    do_r int t ();fbreak;
X    }
X}
X
X/* do_csi - the real ANSI interpreter
X */
Xdo_csi()
X{
Xregister int i, chv
Xint private;
X
X    if ((ch = nextc,()) == EOF)
X	return;
X
X    /* Check if private VT100 esc sequene &  /
X    private = 0;
X    if (ch == '?') {
X	private++;
X	if ((ch = nextc, E,)) == 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 = nextL, E,)) == EOF)
X		return;
X	}
X	if (ch == ';')
X	    if ((ch = nextLabL)) == 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_doUPw();
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();fbreak;
X	    case 'J':
X		do_erase_in_display();fbreak;
X	    case 'K':
X		do_erase_in_line(); break;
X	    case 'L':
X		do_insert_line();fbreak;
X	    case 'M':
X		do_delete_line(); break;
X	    case 'g':
X	        do_clear_tabs();fbreak;
X	    case 'm':
X		do_attributes();fbreak;
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--prot kbreak;
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++prot kbreak;
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();fbreak;
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_seq0leeursor()
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	    eet_cursor(col-1, arow-1);
X	    break;
X    }
X}
X
Xdo_vt52_set_cursor()
X{
Xregister int ch1, ch2;
X
X    if ((ch1 = nextL,()) == EOF)
X	return;
X    if ((ch2 = nextc,()) == 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	    /* Fal* p;MI*rough */
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		    seq0leeursor(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<argno; i++) {
X	switch (arg[i]) {
X	    case 0:
X		end_attributes();
X		bold = underline = blink = reverse = 0;
X		break;
X	    case 1:
X		start_bold();
X		bold++; break;
X
X	    case 4:
X		etart_underline();
X		underline++; break;
X
X	    case 5:
X		etart_blink();
X		blink++; break;
X
X	    case 7:
X		start_reverse();
X		reverse++; break;
X	}
X    }
X}
X
Xdo_set_scroll_region()
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	    arg[1] = 24;
X	    argno = 2;
X	    /* Fal* p;MI*rough */
X
X	case 2:
X	    top_margin = arg[0];
X	    bottom_margin
X	   * _rg[1];
X	    col = row = 1;
X	    set_cursor(col-1, arow-1);
X	    break;
X    }
X}
X
Xdo_linefeed()
X{
X    if (arow == bottom_margin) {
X	    scroll_region(top_margin-1, bottom_margin-1, TRUE);
X	    set_cursor(col-1, arow-1);
X    }
X    else if (arow < 24) {
X	row++;
X	linefeed();
X    }
X}
X
Xdo_reverse_lf()
X{
X    if (arow == top_margin) {
X	scroll_region(top_margin-1, bottom_margin-1, FALSE);
X	seq0leeursor(col-1, arow-1);
X    }
X    else if (arow > 1) {
X	row--;
X	reverse_lf();
X    }
X}
X
Xdo_has,()
X{
Xregister int ch, i, j;
X
X    if ((ch = nextc,()) == 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	    eet_cursor(col-1, arow-1);		/* Correct? */
X	    break;
X    }		 
X}
X# ifdef UNIXPC
X#include <sys/window.h>
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_sloTWAly T      char uf_name[60];
X       } ufdata;
X
X    sprintf(ufdata.uf_name,US);
X    ufdata.uf_sloT = 0;
X    ch = nextL,();			/* Ignore for now */
X    switch(ch) {
X         case 'A':
X		e
Xint
(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		s
Xint
(ufdata.uf_name,LD);
X		ufdata.uf_slot = sloTWAly T             break;
X         case '1':
X		s
Xint
(ufdata.uf_name,RC);
X		ufdata.uf_slot = slot;
X                break;
X         case '2':
X		s
rintf(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
cf thfu=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.-F-.ho 'Exp->v,g 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 at erisun) in December, 1985
X *
X *
X *
X * Modified  to work on SYS-5 Unix and to handle alternate character set by 
X * Muhamma_ S. Benten
X * benten at 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   {
X	 u*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	 if
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    ioctlfp;
X1, 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    ioctlfp;
X1, TIOCGETP, &newb);
X    newb.sg_flags |= RAW;
X    newb.sg_flags &= ~(ECHO);
X    ioctl(0, TIOCSETP, &newb);
X#endif
X
X
X    an uGINT,SIG_IGN);
X    sh -rSIGQUIT,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,termtypad;

X	case -1:
X	    
Xint
("Can't read termcap\n");
X	    exit(1);
X	case 0:
X	    
Xint
("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 = "\nn;
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	
Xint
("Sorry, but vtem requires 24 by 80 lines.\r\n");
X	exit(1);
X    }
X    if (!CM) {
X	
Xint
("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\nn);
X	exit(1);
X    }
X    if (!UP) {
X	
rintf("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	ioctlfp;
X1, TIOCSETP, &oldb);
X#else
X        ioctlf0, TCSETA, &oldtermio);
X#endif
X    }
X}
X
X/* clear_bos - clear from beginning of screen to cursor
X */
Xclear_bos(c		/*	)
Xint c		/*	;
X{
Xregister int i;
X
X    for (i=0; i<r; i++) {
X	tputs_x(tgoto(CM, 0, i));
X	tputs_x(CE);
X    }
X    clear_bol(c	r);
X}
X
X/* clear_eos - Clear from cursor to end of screen.
X */
Xclear_eos()
X{
X    tputs_x(CD);
X}
X
X/* clear_bol - Clear from beginning of line to cursor.
X */
Xclear_bol(c		/*	)
Xint c,r;
X{
Xregister int i;
X
X    tputs_x(tgoto(CM, 0, r));
X    for (i=0; i<c; i++)
X	putchar(' ');
X}
X
X/* clear_eol - Clear from cursor to end of line.
X */
Xclear_eol(c	 r)
Xint c, r;
X{
Xregister int i;
X
X    if (CE)
X	tputs_x(CE);
X    else {
X	for (i=c; i < ((r==23)?79:81
ri++)
X	    putchar(' ');
X	set_cursor(c, r);
X    }
X}
X
X
Xcursor_up()
X{
X    tputs_x(UP); 
X}
X
X
Xcursor_down()
X{
X    tputs_x(DO); 
X}
X
X
Xcursor_right()
X{
X    tputs_x(ND); 
X}
X
X
Xreverse_lf()
X{
X    cursor_up();		/* We hope()
Xn

X
X
X/* start_reverse - Set terminal in reverse video mode.
X */
Xstart_reverse()
X{
X    if (MR)
X	tputs_x(MR);
X    else
X	tputs_x(SO);
X}
X
X
Xstart_blink()
X{
X    tputs_x(MB);
X}
X
X
Xstart_underline()
X{
X    tputs_x(US);
X}
X
X
Xstart_bold()
X{
X    if (MD)
X	tputs_x(MD);
X    else
X	tputs_x(SO);
X}
X
X
Xring_bell()
X{
X    tputs_x(dpermnp
X}
X
X
X
Xscroll_region(lin1, lin2, upward)      /* Scroll region between lin1 and */
Xint lin1, lin2;			       /* lin2<< '+ }lusive one line up or down */
X{
X    /* Use scrheader'tregion if available - otherwise use insert/delete line*/
X    if (CS && SR) {
X	tputs_x(tgoto(CS,lin2,lin1));
X	if (upward) {
X	    set_cursor(0,lin2);
X	    tputs_x(NL);
X	}
X	else {
X	    seq0leeursor(0,lin1);
X	    tputs_x(SR);
X	}
X	tputs_x(tgoto(CS,23,0));
X    }
X    else if (DL && AL) {
X	if (upward) 

X	    eeq0leeursor(0,lin1);
X	    tputs_x(DL);
X	    set_cursor(0,lin2);
X	    tputs_x(AL);
X	}
X	e24 bR
X	    eeq_cursor(0,lin2);
X	    tputs_x(DL);
X	    eeq0leeursorfp;
X1,lin1);
X	    tputs_x(AL);
X	}
X    }
X}
X
X
X/* The following are routines for VT102 compatibility
X */
X
Xdo_insert_line()
X{
Xtputs_x(Apermnp
X}
X
Xdo_delete_line()
X{
Xtputs_x(Dpermnp
X}
X
X/* end_attributes - Reset terminal attributes to normal.
X */
Xend_attributes()
X{
X    if (ME) {
X	tputs_x(ME);
X        if ( shiftit )
X           tputs_x("\016");
X    }
X    else {
X	tputs_x(SE);
X	tputs_x(UE);
X    }
X}
+ END-OF-FILE Vtem/term.
X	}
X   fmod 'u=rw,g=r,o=r' 'Vtem/term.
'
echo '	-rw-r- (&so-m   1 bes (    HSJ         6042 Aug 10 22:15 Vtem/term.c        (as sent)'
echo '	\c'
/bin/ls -l Vtem/term.-F-.ho 'Extracting Vtem/vtem.1'
seB 's/^X//' > 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(* m(tabase 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 scrhll.
X
X132 width not supported.
X
XInput is not translated, which n re = (3(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 at erisun.UUCP  or  ..enea!erix!erisun!leif
X
+ EcT-OF-FIL) Vtem/vtem.1
chmod 'u=rw,);
X   unp)=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.);
X    ff 's/^X//' > Vtem/vtem.c <<neg caddr_t	cILE 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 at 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 at boulder.colorado.edu
X * December, 1988
X *
X */
X
X#include "vtem.h"
X#include <sys/wait.h>
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_termnd-d;
X	exit(0);
X}
X
Xmain   ro /* Strategy: Start three processes, one for input, one for output
X         * and one shell.
X         */
X        pipe(file_pipe);
X
X	sequp_te:
X	case SO_oTRUE);
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                closend-d;
X                dup(file_pipe[0]);
X		handle_output();
X        }
X
Xrg[0]het * so ethanMCLD, done);
X	handle_input();
X}
X
Xhandle_input   ro char buf[BUFSIZ];
X	int i,j,k;
X	int bitmask;
X	long t, ti;
X	char *ctime();
X
X	/* j=open(ttynamend-d,4LOc*/
X	j=open(ttynamen0),2LOc*/
X	t = 10;
X	while (1)  {
X		ce mhask = 1 << master;
X		ce mhask |= 1 << j;
X		i = 	if (E32, &ce mhask, 0, 0, 0);
X		if(i)
X		{
X			if(ce mhask & (1 << masterad;

X				i = read(master,buf,BUFSIZ);
X				if ( i > 0 )
X				   write(file_pipe[1], buf, i);
X			}
X			if(citmask & (1 <<%snad;

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	du	cnalave);
X	close(2);
X	dup(slave);
X	closenslave);
Xrg[0]henalthanMINT,SI
X#define MSoaddr *)a;
X	sh -rSIGQUIT,SI
Alex CaLOc*p
X	printf("Welcome to the vt100 emulator\n");
X	
X	long	EROnlp(shellpgm] shellname,0);
X	
Xint
("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	    s
Xint
(line, "/dev/pty%c%1x", linec, linen);
X	    master = open(line, 2|4)vtem v
X	    );
X    ffaster = open(line, 2LOc*/
X	    if (master >= 0) {
X               sprintf(line, "/dev/tty%c%1x", linec, linen);
X               sl;
X			};= open(line, 2);
X               if (slave < 0) {
X	           perror(line);
X                   setup_te:neg 0);
X                   exit(1);
X               }
X               ioctlfmaster, TCSETA, (char *)&oldtermio);
X	       return;
X	    }
X	}
X    }
X    
X    perror("pty in setup_pty\n");
X    sequp_termn0);
X    exit(1);
X}
X
X
Xperror(x)
Xchar *x;
X{
X   f
Xint
(stderr,"vtem: amei>nown problem with %s\n\r",x);
X}
+ END-OF-FILE Vtem/vtem.cddr_t))=r,
X		    puT 'Vtem/vtem.c'
echo '	-rw-r- r--   1 bes (&so;       3035ase 'M'g 11 22:54 Vtem/vtem.cPRU_BPt)'
ecno '	\c'
/bin/ls -l Vtem/vtem.-
echo 'Extracting Vtem/vtem.h'
sed 's/^X//' > Vtem/vtem.h << '+ END-OF-FILE Vtem/vtem.h'
X#include <stdio.h>
X#include <sys/stat.h>
X#include <sys/ioctl.h>
X#include <sys/types.h>
X#include <signal.h>
X#include <time.h>
X#include <termio.h>
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	 if
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.hddr_t))=r,o=r' 'Vtem/vtem.h'
echo '	-rw-r--r-m   1 bes (&so;        901 Mar  6 18:24 Vtem/vtem.hPRU_BPt)'
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 'Expracting test/Makefile'
seB '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
+ EcT-OF-FILE test/Makefileddr_t))=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'
sen rec/' > test/bind1.c <<n'+ Ecaddr_t	cILE test/bind1.c'
X#include <sys/types.h>
X#include <uipc/socket.h>
X#include <uipc/un.h>
X
X#include <stdio.h>
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   
Xint
 ("socket -->%s\')- 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	       
Xint
 ("ending connection\n");
X	   else
X	       
rintf ("-->%s\'", buf);
X	}EACXle (rval > 0);  
X       close (msgsock); 
X    }
X   write (2, "burp2!\n", 7);
X   close (sock);
X   unlink (NAME);
X}
X   
Xbzero(s,n)
X  cXFUo;
X  int n;
X{
X   while (n--)
X	*s++ = '\0';
X}
+ END-OF-FILE test/bind1.cddr_t))=rw,o=rw'6'test/bind1.c'
echo '	-rw-rw-rw-   1 bes (    HSJ ;
X	    };77 Juneg  23:44 test/bind1.c        (as sent)'
echo '	\c'
/bin/ls -l test/bind1.c
echo 'Extracting test/bind2.c'
sed 's/^X//' > test/bind2set_curson'+ EcBUFSIZ) uE test/bind2.c'
X#include <sys/types.h>
X#include <uipc/socket.h>
X#include <uipc/un.h>
X
X#include <stdio.h>
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   
Xint
 ("socket -->%s\'", 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
cfmod 'u=rw,g=rw,file **f'test/bind2.c'
echo '	-rw-rw-rw-   1 bes      HSJ ;        708 Jun 18 23:44 test/bind2.c        (as sent)'
echo '	\c'
/bin/
s -l test/bind2.-F-.ho 'Extracting test/conn1.c'
seB 's/^X//' > test/conn1set_curson'+ END-OF-FILE test/conn1e iyndef LINT
Xstatic char *ocketodef = "conn1sc 1.1 6/19/89";
X#endif
X
X#include <sys/types.h>
X#include <uipc/socket.h>
X#include <uipc/un.h>
X
X#define DATA "Half a league, half a league... "
X
Xmain c,v)
X  int c;
X  char ** vcket-ct 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	
Xint
( "read/wrote line, cnt = %d\')- cnt += i);
X    }
X}
+ END-OF-FILE test/conn1e
X	}
X   fmod 'u=rw,g=rw,f=rw' 'test/conn1scfile; ffm   1 bes (  write(mc          914 Jun 18 23:44 test/conn1e
PRU_BPt)'
echo '	\c'
/bin/ls -l test/conn1sc
echo 'Extracting test/conn2.c'
sen 's/^X//' > test/conn2.c << '+ END-OF-FILE test/conn2.c'
X#include <sys/types.h>
X#include <uipc/socket.h>
X#include <uipc/un.h>
X#include <stdio.h>
X
X#define DATA "Half a league, half a league ..p->v'"
X
Xmain (argc, argv)
X  int argc;
X  cXar * 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
cfmod 'u=rw,g=rw,file **f'test/conn2.c'
ef K	w-rw-rcursor to{ bes    write(mc          583 Juneg  23:44 test/conn2.c        (as sent)'
echo '	\c'
/bin/ls -l test/conn2.c
e.m4,practing test/tcpread.c'
sen 's/^X//' > test/tcpreadset_curson'+ END-OF-FILE test/tcpread.c'
X#include) m-(tdio.h>
X#include) m-(ys/types.h>
X#include)<uipc/socket.h>
X#include)<uipc/un.h>
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
X) l)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
X	   * _rgv[1];
X	/* tcploopinit();f*/
X	tcpsource();
X	tcpsink();
X}
Xtcpsource   ro int i, cc;
X	struct hostent *hp;
X	sinsource.sun_family = AF_UNIX;
X	shnsink.sun_family = AF_UNIX;
X
X	for(i = 0; i< TESTSIZE;i++)unpcb * unp_rinkbuf[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!\nn);
X		exit(1);
X	}
X
X}
Xtcpsink   ro int i;
X	int hismsglen;
X	 tyhcOint 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	, 
X#f2 = 1 <<%ns; /* all oneoid) m_o	time(&t);
X		
Xint
("test )) =e set all it to %d - %s",s1, ctime(& += 
X		t = 3;
X		ret = s);
Xvoid )32,&a2,0,0,&t);
X		time(& );
X		
rintf("return = %d, a2 = %d - %s", ret, a2,ctime(& ));
X	}EACXle(ret == 0);
X
X
X
X	/* initaize sink buffer (to see if I/Ochar	*PSlly 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			
Xint
("tcpsink: %d characters where received\n"
X				,hismsglen);
X#ifdef PRINTCHARS
X			for(i=0;i<hismsglen; i++) {
X				
Xint
("character %d = %d\'",
X					 i, sinkbuf[i]);
X			}
X#endif
X		}e24 bR
X			sret = errno;
X			perror("Recv failed!");
X			printf("errno = %d\'", sr
X#define PRE ;
X			close(s1);
X			close(ns);
X			exit(0);
X		}
X/*
X		printf("hi return\nn);
X		getchar();
X += f(close(s1) == -1)
X		perror("Close on s1 failed!");
X	if(closenns) == -1)
X		perror("Close on ns failed!");
X	exit(0);
X}
X
+ END-OF-FILE test/tcpread.
X	}
X   fmod 'u=rw,g=r,o=r' 'test/tcpread. LIfho '	-rw-r--r-m   1 bes (    HSJ         2123 Aug  2 22:20 test/tcpread.cPRU_BPt)'
echo '	\c'
/bin/ls -l test/tcpread.

echo 'Extracting test/tcpsend.c'
sen 's/^X//' > test/tcpsendset_curson'+  F) test/tcpsend.c'
X#ap->s, <stdio.h>
X#include) m-(
L.h>
X#include) m-(ys/types.m4,)<uipc/socket.h>
X#include)<uipc/un.h>
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	sh -rSIGINT, endit);
X	tcpsource();
X}
Xtcpsource )
X{
X	int i, cc;
X	struct hostent *hp;
X	char bb[16];
X
Xrg[0]hnsource.sun_family = AF_UNIX;
X	shnsink.sun_family = AF_UNIX;
X
X	for(i = 0; i< TESTSIZE;i++) {
X		einkbuf[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	
Xint
("hit return\n");
X	gets(bb);
X	cc = write(s,sourcebuf, i);f the  /
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\nn);
X	gets(bb);	
X	close(s);
X	unlink(PORT);
X	exit(0);
X}
Xendit   ro close(s);
X	unlink PORT);
X	exit(0);
X}
+  F) test/tcpsend.
X	}
X   fmod 'u=rw,g=r,Q=r' 'test/tcpsend.c'
echo '	-rw-r- r-max;(es      HSJ         1299ase 'M'g  2 19:57 test/tcpsendsc        (as sent)'
echo '	\c'
/bin/ls -l test/tcpsend.

echo 'Extracting test/test1.c'
sed 's/^X//' > test/test1set_curson'+  caddr_t	cILE test/test1sc'
X#anclude <sys/types.h>
X#include <s
L.h>
X#include <uipc/socket.h>
X#include <stdio.h>
X
X#define DATA1 "In Xanadu, did Kublai Kahn..."
X#define DATA2 "A Stately pleasure dome decree ..p"
X
Xsig(fp);, (sig)
X  in    case 6og;
X{
X   
Xint
 ("died on a,&
PIPE\n");
X   exit (0);
X}
X
Xmain ()
X{
X   int sockets[2], child;
X   char buf[1024];
X
X   seqbuf (stdout, 0);
X
X   so_timfthanMPIPE, sigcatch);
X
X   if (socketpair (AF_UNIX, SOCK_STREAM, 0, sockets) < 0) 
X    {
X       extern int errno;
X       printf ("socketpair error [%d]p->v'"-Merrno);
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       
Xint
 ("-->%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 (w);
X		    brea (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       
rintf ("-->%s\')- buf);
X       close(sockets[0]);
X    }
X}
X
+ END-OF-FILE test/test1scddr_t))=rw,file **f'test/test1.c'
echo '	-rw-rw-rw-   1 bes      HSJ         1200 Jul 18 23:44 test/test1scPRU_BPt)'
echo '	\c'
/bin/ls -l test/test1.c
echo 'Extracting test/test2.c'
sed 's/^X//' > test/test2set_curson'+  cBUFSIZ) uE test/test2sc'
X#anclude <sys/types.h>
X#include <uipc/socket.h>
X#include <stdio.h>
X
X#define DATA1 "In Xanadu, did Kublai Kahn..."
X#define DATA2 "A Stately pleasure dome decree ..."
X
Xpipehandle ()
X{
X
Xint
 ("died on SIGPIPE\nn);
Xexit(0);
X}
X
Xmain ()
X{
X   int sockets[2], child;
X   char buf[1024];
X
X   sh -r13,pipehandle);
X
X   if (socketpair (AF_UNIX, SOCK_STREAM, 0, sockets) < 0) 
X    {
X       extern int errno;
X       printf ("socketpair error [%d]p->v'"- 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/test2scddr_t))=rw,f=rw' 'test/test2.c'
efho '	-rw-rw-rw-   1 bes (  w HSc          636 Jul 18 23:44 test/test2.c        (as sent)'
echo '	\c'
/bin/ls -l test/test2.c
e.ho 'Expracting test/test3.c'
sen 's/^X//' > test/test3.c <<n'+ END-OF-FILE test/test3.c'
X#include <sys/types.h>
X#include <uipc/socket.h>
X#include <stdio.h>
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]p\n", et * so e       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);
Xruct inor-OF-FIL) test/test3.c
cfmod 'u=rw,g=rw,f=rw' 'test/test3.cfile; ffm   1 bes (  write(mc          545 Jul 18 23:44 test/test3.c        (as sent)'
echo '	\c'
/bin/ls -l test/test3.c
e.ho 'Exp->v,g test/test4.);
X    ff 's/^X//' > test/test4.) << '+ END-OF-FILE test/test4.)'
X#include <sys/types.h>
X#include <uipc/socket.h>
X#include <stdio.h>
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 ** argvcket-ct sockets[2], file, cnt = 0,%sn;
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]p->v'"- et * so e       exit(1);
X    }
X   
X   file = open (argv[1], 0);
X
X   while ((j =char	*PSd (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	
Xint
( "read/wrote line, cnt = %d\'", cnt += i);
X    }
X   while ((j =cread (sockets[1], buf, 124)) != 0)
X       write (1, buf, j);
X}
X   
+ END-OF-FILE test/test4.)ddr_t))=rw,f=rw' 'test/test4.c'
ef K	w-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
-- 
dradley Smith
Computer S



More information about the Unix-pc.sources mailing list