From 4182ba75b23b3e63fcf96fffd0e7bb9a0c7cd49a Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 24 Apr 2015 18:05:21 +0000 Subject: [PATCH] Remove tip(1), superseded by cu(1). ok deraadt sthen bmercer --- usr.bin/Makefile | 4 +- usr.bin/tip/Makefile | 13 - usr.bin/tip/cmds.c | 976 ------------------------------------------- usr.bin/tip/cmdtab.c | 54 --- usr.bin/tip/hunt.c | 123 ------ usr.bin/tip/log.c | 75 ---- usr.bin/tip/partab.c | 53 --- usr.bin/tip/remote.c | 197 --------- usr.bin/tip/tip.1 | 558 ------------------------- usr.bin/tip/tip.c | 520 ----------------------- usr.bin/tip/tip.h | 228 ---------- usr.bin/tip/tipout.c | 210 ---------- usr.bin/tip/value.c | 431 ------------------- 13 files changed, 2 insertions(+), 3440 deletions(-) delete mode 100644 usr.bin/tip/Makefile delete mode 100644 usr.bin/tip/cmds.c delete mode 100644 usr.bin/tip/cmdtab.c delete mode 100644 usr.bin/tip/hunt.c delete mode 100644 usr.bin/tip/log.c delete mode 100644 usr.bin/tip/partab.c delete mode 100644 usr.bin/tip/remote.c delete mode 100644 usr.bin/tip/tip.1 delete mode 100644 usr.bin/tip/tip.c delete mode 100644 usr.bin/tip/tip.h delete mode 100644 usr.bin/tip/tipout.c delete mode 100644 usr.bin/tip/value.c diff --git a/usr.bin/Makefile b/usr.bin/Makefile index c905c2a1a71..7bff58386a1 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.150 2015/03/27 01:59:26 schwarze Exp $ +# $OpenBSD: Makefile,v 1.151 2015/04/24 18:05:21 nicm Exp $ .include @@ -23,7 +23,7 @@ SUBDIR= apply arch at aucat audioctl awk banner \ sdiff script sed sendbug shar showmount signify skey \ skeyaudit skeyinfo skeyinit sndiod \ sort spell split sqlite3 ssh stat su systat \ - sudo tail talk tcpbench tee telnet tftp tic tip time \ + sudo tail talk tcpbench tee telnet tftp tic time \ tmux top touch tput tr true tset tsort tty usbhidaction usbhidctl \ ul uname unexpand unifdef uniq units \ unvis users uudecode uuencode vacation vi vis vmstat w wall wc \ diff --git a/usr.bin/tip/Makefile b/usr.bin/tip/Makefile deleted file mode 100644 index 4ab78981666..00000000000 --- a/usr.bin/tip/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $OpenBSD: Makefile,v 1.17 2015/02/07 10:07:15 deraadt Exp $ - -PROG= tip -MAN= tip.1 - -CFLAGS+=-I${.CURDIR} -DDEFBR=9600 -DDEFFS=BUFSIZ -LDADD= -lutil -DPADD= ${LIBUTIL} - -SRCS= cmds.c cmdtab.c hunt.c log.c partab.c remote.c tip.c \ - tipout.c value.c - -.include diff --git a/usr.bin/tip/cmds.c b/usr.bin/tip/cmds.c deleted file mode 100644 index c7c96288862..00000000000 --- a/usr.bin/tip/cmds.c +++ /dev/null @@ -1,976 +0,0 @@ -/* $OpenBSD: cmds.c,v 1.42 2010/07/02 07:32:16 nicm Exp $ */ -/* $NetBSD: cmds.c,v 1.7 1997/02/11 09:24:03 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "tip.h" - -#include -#include -#include - -/* - * tip - * - * miscellaneous commands - */ - -int quant[] = { 60, 60, 24 }; - -char null = '\0'; -char *sep[] = { "second", "minute", "hour" }; -static char *argv[10]; /* argument vector for take and put */ - -static void transfer(char *, int, char *); -static void stopsnd(int); /* SIGINT handler during file transfers */ -static void intcopy(int); /* interrupt routine for file transfers */ -static void transmit(FILE *, char *, char *); -static void send(int); -static void execute(char *); -static int args(char *, char **, int); -static void prtime(char *, time_t); -static void tandem(char *); -static void hardwareflow(char *); -void linedisc(char *); -static int anyof(char *, char *); - -/* - * FTP - remote ==> local - * get a file from the remote host - */ -void -getfl(int c) -{ - char buf[256], *cp; - - putchar(c); - /* - * get the UNIX receiving file's name - */ - if (prompt("Local file name? ", copyname, sizeof(copyname))) - return; - cp = expand(copyname); - if ((sfd = creat(cp, 0666)) < 0) { - printf("\r\n%s: cannot creat\r\n", copyname); - return; - } - - /* - * collect parameters - */ - if (prompt("List command for remote system? ", buf, sizeof(buf))) { - unlink(copyname); - return; - } - transfer(buf, sfd, vgetstr(EOFREAD)); -} - -/* - * Cu-like take command - */ -void -cu_take(int c) -{ - int fd, argc; - char line[BUFSIZ], *cp; - - if (prompt("[take] ", copyname, sizeof(copyname))) - return; - if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || - argc > 2) { - printf("usage: from [to]\r\n"); - return; - } - if (argc == 1) - argv[1] = argv[0]; - cp = expand(argv[1]); - if ((fd = creat(cp, 0666)) < 0) { - printf("\r\n%s: cannot create\r\n", argv[1]); - return; - } - (void)snprintf(line, sizeof(line), "cat %s;echo ''|tr '\\012' '\\01'", argv[0]); - transfer(line, fd, "\01"); -} - -static jmp_buf intbuf; - -/* - * Bulk transfer routine -- - * used by getfl(), cu_take(), and pipefile() - */ -static void -transfer(char *buf, int fd, char *eofchars) -{ - int ct, eof; - char c, buffer[BUFSIZ]; - char *p = buffer; - size_t cnt; - time_t start; - sig_t f; - char r; - - if (vgetnum(FRAMESIZE) > BUFSIZ || vgetnum(FRAMESIZE) < 1) { - printf("framesize must be >= 1 and <= %d\r\n", BUFSIZ); - close(fd); - return; - } - - parwrite(FD, buf, size(buf)); - quit = 0; - write(tipout_fd, "W", 1); - read(tipout_fd, (char *)&ccc, 1); /* Wait until read process stops */ - - /* - * finish command - */ - r = '\r'; - parwrite(FD, &r, 1); - do - read(FD, &c, 1); - while ((c&STRIP_PAR) != '\n'); - tcsetattr(0, TCSAFLUSH, &defchars); - - (void) setjmp(intbuf); - f = signal(SIGINT, intcopy); - start = time(0); - for (ct = 0; !quit;) { - eof = read(FD, &c, 1) <= 0; - c &= STRIP_PAR; - if (quit) - continue; - if (eof || any(c, eofchars)) - break; - if (c == 0) - continue; /* ignore nulls */ - if (c == '\r') - continue; - *p++ = c; - - if (c == '\n' && vgetnum(VERBOSE)) - printf("\r%d", ++ct); - if ((cnt = (p-buffer)) == vgetnum(FRAMESIZE)) { - if (write(fd, buffer, cnt) != cnt) { - printf("\r\nwrite error\r\n"); - quit = 1; - } - p = buffer; - } - } - if ((cnt = (p-buffer))) - if (write(fd, buffer, cnt) != cnt) - printf("\r\nwrite error\r\n"); - - if (vgetnum(VERBOSE)) - prtime(" lines transferred in ", time(0)-start); - tcsetattr(0, TCSAFLUSH, &term); - write(tipout_fd, (char *)&ccc, 1); - signal(SIGINT, f); - close(fd); -} - -/* - * FTP - remote ==> local process - * send remote input to local process via pipe - */ -/*ARGSUSED*/ -void -pipefile(int c) -{ - int pdes[2]; - char buf[256]; - int status, p; - pid_t cpid; - - if (prompt("Local command? ", buf, sizeof(buf))) - return; - - if (pipe(pdes)) { - printf("can't establish pipe\r\n"); - return; - } - - if ((cpid = fork()) < 0) { - printf("can't fork!\r\n"); - return; - } else if (cpid) { - if (prompt("List command for remote system? ", buf, sizeof(buf))) { - close(pdes[0]), close(pdes[1]); - kill (cpid, SIGKILL); - } else { - close(pdes[0]); - signal(SIGPIPE, intcopy); - transfer(buf, pdes[1], vgetstr(EOFREAD)); - signal(SIGPIPE, SIG_DFL); - while ((p = wait(&status)) > 0 && p != cpid) - ; - } - } else { - int f; - - dup2(pdes[0], 0); - close(pdes[0]); - for (f = 3; f < 20; f++) - close(f); - execute(buf); - printf("can't execl!\r\n"); - exit(0); - } -} - -/* - * Interrupt service routine for FTP - */ -/*ARGSUSED*/ -static void -stopsnd(int signo) -{ - stop = 1; - signal(SIGINT, SIG_IGN); -} - -/* - * FTP - local ==> remote - * send local file to remote host - * terminate transmission with pseudo EOF sequence - */ -void -sendfile(int c) -{ - FILE *fp; - char *fnamex; - - putchar(c); - /* - * get file name - */ - if (prompt("Local file name? ", fname, sizeof(fname))) - return; - - /* - * look up file - */ - fnamex = expand(fname); - if ((fp = fopen(fnamex, "r")) == NULL) { - printf("%s: cannot open\r\n", fname); - return; - } - transmit(fp, vgetstr(EOFWRITE), NULL); - if (!vgetnum(ECHOCHECK)) - tcdrain(FD); -} - -/* - * Bulk transfer routine to remote host -- - * used by sendfile() and cu_put() - */ -static void -transmit(FILE *fp, char *eofchars, char *command) -{ - char *pc, lastc; - int c, ccount, lcount; - time_t start_t, stop_t; - sig_t f; - - write(tipout_fd, "W", 1); /* put TIPOUT into a wait state */ - stop = 0; - f = signal(SIGINT, stopsnd); - tcsetattr(0, TCSAFLUSH, &defchars); - read(tipout_fd, (char *)&ccc, 1); - if (command != NULL) { - for (pc = command; *pc; pc++) - send(*pc); - if (vgetnum(ECHOCHECK)) - read(FD, (char *)&c, 1); /* trailing \n */ - else { - tcdrain(FD); - sleep(5); /* wait for remote stty to take effect */ - } - } - lcount = 0; - lastc = '\0'; - start_t = time(0); - while (1) { - ccount = 0; - do { - c = getc(fp); - if (stop) - goto out; - if (c == EOF) - goto out; - if (c == 0177 && !vgetnum(RAWFTP)) - continue; - lastc = c; - if (c < 040) { - if (c == '\n') { - if (!vgetnum(RAWFTP)) - c = '\r'; - } else if (c == '\t') { - if (!vgetnum(RAWFTP)) { - if (vgetnum(TABEXPAND)) { - send(' '); - while ((++ccount % 8) != 0) - send(' '); - continue; - } - } - } else - if (!vgetnum(RAWFTP)) - continue; - } - send(c); - } while (c != '\r' && !vgetnum(RAWFTP)); - if (vgetnum(VERBOSE)) - printf("\r%d", ++lcount); - if (vgetnum(ECHOCHECK)) { - timedout = 0; - alarm((unsigned int)vgetnum(ETIMEOUT)); - do { /* wait for prompt */ - read(FD, (char *)&c, 1); - if (timedout || stop) { - if (timedout) - printf("\r\ntimed out at eol\r\n"); - alarm(0); - goto out; - } - } while ((c&STRIP_PAR) != vgetnum(PROMPT)); - alarm(0); - } - } -out: - if (lastc != '\n' && !vgetnum(RAWFTP)) - send('\r'); - if (eofchars) { - for (pc = eofchars; *pc; pc++) - send(*pc); - } - stop_t = time(0); - fclose(fp); - signal(SIGINT, f); - if (vgetnum(VERBOSE)) { - if (vgetnum(RAWFTP)) - prtime(" chars transferred in ", stop_t-start_t); - else - prtime(" lines transferred in ", stop_t-start_t); - } - write(tipout_fd, (char *)&ccc, 1); - tcsetattr(0, TCSAFLUSH, &term); -} - -/* - * Cu-like put command - */ -/*ARGSUSED*/ -void -cu_put(int c) -{ - FILE *fp; - char line[BUFSIZ]; - int argc; - char *copynamex; - - if (prompt("[put] ", copyname, sizeof(copyname))) - return; - if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || - argc > 2) { - printf("usage: from [to]\r\n"); - return; - } - if (argc == 1) - argv[1] = argv[0]; - copynamex = expand(argv[0]); - if ((fp = fopen(copynamex, "r")) == NULL) { - printf("%s: cannot open\r\n", copynamex); - return; - } - if (vgetnum(ECHOCHECK)) - (void)snprintf(line, sizeof(line), "cat>%s\r", argv[1]); - else - (void)snprintf(line, sizeof(line), - "stty -echo;cat>%s;stty echo\r", argv[1]); - transmit(fp, "\04", line); -} - -/* - * FTP - send single character - * wait for echo & handle timeout - */ -static void -send(int c) -{ - char cc; - int retry = 0; - - cc = c; - parwrite(FD, &cc, 1); - if (vgetnum(CDELAY) > 0 && c != '\r') - usleep(vgetnum(CDELAY)); - if (!vgetnum(ECHOCHECK)) { - if (vgetnum(LDELAY) > 0 && c == '\r') - usleep(vgetnum(LDELAY)); - return; - } -tryagain: - timedout = 0; - alarm((unsigned int)vgetnum(ETIMEOUT)); - read(FD, &cc, 1); - alarm(0); - if (timedout) { - printf("\r\ntimeout error (%s)\r\n", ctrl(c)); - if (retry++ > 3) - return; - parwrite(FD, &null, 1); /* poke it */ - goto tryagain; - } -} - -/*ARGSUSED*/ -void -timeout(int signo) -{ - int saved_errno = errno; - - signal(SIGALRM, timeout); - timedout = 1; - - errno = saved_errno; -} - -/* - * Stolen from consh() -- puts a remote file on the output of a local command. - * Identical to consh() except for where stdout goes. - */ -void -pipeout(int c) -{ - char buf[256]; - int status, p; - pid_t cpid; - time_t start = time(NULL); - - putchar(c); - if (prompt("Local command? ", buf, sizeof(buf))) - return; - write(tipout_fd, "W", 1); /* put TIPOUT into a wait state */ - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - tcsetattr(0, TCSAFLUSH, &defchars); - read(tipout_fd, (char *)&ccc, 1); - /* - * Set up file descriptors in the child and - * let it go... - */ - if ((cpid = fork()) < 0) - printf("can't fork!\r\n"); - else if (cpid) { - start = time(NULL); - while ((p = wait(&status)) > 0 && p != cpid) - ; - } else { - int i; - - dup2(FD, 1); - for (i = 3; i < 20; i++) - close(i); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - execute(buf); - printf("can't find `%s'\r\n", buf); - exit(0); - } - if (vgetnum(VERBOSE)) - prtime("away for ", time(0)-start); - write(tipout_fd, (char *)&ccc, 1); - tcsetattr(0, TCSAFLUSH, &term); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); -} - -/* - * Fork a program with: - * 0 <-> remote tty in - * 1 <-> remote tty out - * 2 <-> local tty stderr - */ -void -consh(int c) -{ - char buf[256]; - int status, p; - pid_t cpid; - time_t start = time(NULL); - - putchar(c); - if (prompt("Local command? ", buf, sizeof(buf))) - return; - write(tipout_fd, "W", 1); /* put TIPOUT into a wait state */ - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - tcsetattr(0, TCSAFLUSH, &defchars); - read(tipout_fd, (char *)&ccc, 1); - /* - * Set up file descriptors in the child and - * let it go... - */ - if ((cpid = fork()) < 0) - printf("can't fork!\r\n"); - else if (cpid) { - start = time(0); - while ((p = wait(&status)) > 0 && p != cpid) - ; - } else { - dup2(FD, 0); - dup2(3, 1); - closefrom(3); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - execute(buf); - printf("can't find `%s'\r\n", buf); - exit(0); - } - if (vgetnum(VERBOSE)) - prtime("away for ", time(0)-start); - write(tipout_fd, (char *)&ccc, 1); - tcsetattr(0, TCSAFLUSH, &term); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); -} - -/* - * Escape to local shell - */ -/*ARGSUSED*/ -void -shell(int c) -{ - int status; - char *cp; - pid_t shpid; - - printf("[sh]\r\n"); - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - unraw(); - if ((shpid = fork())) { - while (shpid != wait(&status)); - raw(); - printf("\r\n!\r\n"); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - return; - } else { - signal(SIGQUIT, SIG_DFL); - signal(SIGINT, SIG_DFL); - if ((cp = strrchr(vgetstr(SHELL), '/')) == NULL) - cp = vgetstr(SHELL); - else - cp++; - execl(vgetstr(SHELL), cp, (char *)NULL); - printf("\r\ncan't execl!\r\n"); - exit(1); - } -} - -/* - * TIPIN portion of scripting - * initiate the conversation with TIPOUT - */ -void -setscript(void) -{ - char c; - - /* - * enable TIPOUT side for dialogue - */ - write(tipout_fd, "S", 1); - if (vgetnum(SCRIPT)) - write(tipout_fd, vgetstr(RECORD), size(vgetstr(RECORD))); - write(tipout_fd, "\n", 1); - /* - * wait for TIPOUT to finish - */ - read(tipout_fd, &c, 1); - if (c == 'n') - printf("can't create %s\r\n", vgetstr(RECORD)); -} - -/* - * Change current working directory of - * local portion of tip - */ -/*ARGSUSED*/ -void -chdirectory(int c) -{ - char dirname[PATH_MAX]; - char *cp = dirname; - - if (prompt("[cd] ", dirname, sizeof(dirname))) { - if (stoprompt) - return; - cp = vgetstr(HOME); - } - if (chdir(cp) < 0) - printf("%s: bad directory\r\n", cp); - printf("!\r\n"); -} - -void -tipabort(char *msg) -{ - signal(SIGTERM, SIG_IGN); - kill(tipout_pid, SIGTERM); - logent(vgetstr(HOST), vgetstr(DEVICE), "call terminated"); - if (msg != NULL) - printf("\r\n%s", msg); - printf("\r\n[EOT]\r\n"); - (void)uu_unlock(uucplock); - unraw(); - exit(0); -} - -/*ARGSUSED*/ -void -finish(int c) -{ - char *dismsg; - - if ((dismsg = vgetstr(DISCONNECT)) != NULL) { - write(FD, dismsg, strlen(dismsg)); - sleep(5); - } - tipabort(NULL); -} - -/*ARGSUSED*/ -static void -intcopy(int signo) -{ - raw(); - quit = 1; - longjmp(intbuf, 1); -} - -static void -execute(char *s) -{ - char *cp; - - if ((cp = strrchr(vgetstr(SHELL), '/')) == NULL) - cp = vgetstr(SHELL); - else - cp++; - execl(vgetstr(SHELL), cp, "-c", s, (char *)NULL); -} - -static int -args(char *buf, char *a[], int num) -{ - char *p = buf, *start; - char **parg = a; - int n = 0; - - do { - while (*p && (*p == ' ' || *p == '\t')) - p++; - start = p; - if (*p) - *parg = p; - while (*p && (*p != ' ' && *p != '\t')) - p++; - if (p != start) - parg++, n++; - if (*p) - *p++ = '\0'; - } while (*p && n < num); - - return(n); -} - -static void -prtime(char *s, time_t a) -{ - int i; - int nums[3]; - - for (i = 0; i < 3; i++) { - nums[i] = (int)(a % quant[i]); - a /= quant[i]; - } - printf("%s", s); - while (--i >= 0) - if (nums[i] || (i == 0 && nums[1] == 0 && nums[2] == 0)) - printf("%d %s%c ", nums[i], sep[i], - nums[i] == 1 ? '\0' : 's'); - printf("\r\n!\r\n"); -} - -/*ARGSUSED*/ -void -variable(int c) -{ - char buf[256]; - - if (prompt("[set] ", buf, sizeof(buf))) - return; - vlex(buf); - if (vtable[BEAUTIFY].v_flags & V_CHANGED) { - vtable[BEAUTIFY].v_flags &= ~V_CHANGED; - write(tipout_fd, "B", 1); - } - if (vtable[SCRIPT].v_flags & V_CHANGED) { - vtable[SCRIPT].v_flags &= ~V_CHANGED; - setscript(); - /* - * So that "set record=blah script" doesn't - * cause two transactions to occur. - */ - if (vtable[RECORD].v_flags & V_CHANGED) - vtable[RECORD].v_flags &= ~V_CHANGED; - } - if (vtable[RECORD].v_flags & V_CHANGED) { - vtable[RECORD].v_flags &= ~V_CHANGED; - if (vgetnum(SCRIPT)) - setscript(); - } - if (vtable[TAND].v_flags & V_CHANGED) { - vtable[TAND].v_flags &= ~V_CHANGED; - if (vgetnum(TAND)) - tandem("on"); - else - tandem("off"); - } - if (vtable[LECHO].v_flags & V_CHANGED) { - vtable[LECHO].v_flags &= ~V_CHANGED; - vsetnum(HALFDUPLEX, vgetnum(LECHO)); - } - if (vtable[PARITY].v_flags & V_CHANGED) { - vtable[PARITY].v_flags &= ~V_CHANGED; - setparity(NULL); - } - if (vtable[HARDWAREFLOW].v_flags & V_CHANGED) { - vtable[HARDWAREFLOW].v_flags &= ~V_CHANGED; - if (vgetnum(HARDWAREFLOW)) - hardwareflow("on"); - else - hardwareflow("off"); - } - if (vtable[LINEDISC].v_flags & V_CHANGED) { - vtable[LINEDISC].v_flags &= ~V_CHANGED; - linedisc(NULL); - } -} - -/*ARGSUSED*/ -void -listvariables(int c) -{ - value_t *p; - char buf[BUFSIZ]; - - puts("v\r"); - for (p = vtable; p->v_name; p++) { - fputs(p->v_name, stdout); - switch (p->v_flags & V_TYPEMASK) { - case V_STRING: - if (p->v_string) { - strnvis(buf, p->v_string, sizeof(buf), - VIS_WHITE|VIS_OCTAL); - printf(" %s", buf); - } - putchar('\r'); - putchar('\n'); - break; - case V_NUMBER: - printf(" %d\r\n", p->v_number); - break; - case V_BOOL: - printf(" %s\r\n", p->v_number ? "true" : "false"); - break; - case V_CHAR: - vis(buf, p->v_number, VIS_WHITE|VIS_OCTAL, 0); - printf(" %s\r\n", buf); - break; - } - } -} - -/* - * Turn tandem mode on or off for remote tty. - */ -static void -tandem(char *option) -{ - struct termios rmtty; - - tcgetattr(FD, &rmtty); - if (strcmp(option, "on") == 0) { - rmtty.c_iflag |= IXOFF; - term.c_iflag |= IXOFF; - } else { - rmtty.c_iflag &= ~IXOFF; - term.c_iflag &= ~IXOFF; - } - tcsetattr(FD, TCSADRAIN, &rmtty); - tcsetattr(0, TCSADRAIN, &term); -} - -/* - * Turn hardware flow control on or off for remote tty. - */ -static void -hardwareflow(char *option) -{ - struct termios rmtty; - - tcgetattr(FD, &rmtty); - if (strcmp(option, "on") == 0) - rmtty.c_iflag |= CRTSCTS; - else - rmtty.c_iflag &= ~CRTSCTS; - tcsetattr(FD, TCSADRAIN, &rmtty); -} - -/* - * Change line discipline to the specified one. - */ -void -linedisc(char *option) -{ - int ld = (int)vgetnum(LINEDISC); - - ioctl(FD, TIOCSETD, &ld); -} - -/* - * Send a break. - */ -/*ARGSUSED*/ -void -genbrk(int c) -{ - ioctl(FD, TIOCSBRK, NULL); - sleep(1); - ioctl(FD, TIOCCBRK, NULL); -} - -/* - * Suspend tip - */ -void -suspend(int c) -{ - unraw(); - kill(c == CTRL('y') ? getpid() : 0, SIGTSTP); - raw(); -} - -/* - * expand a file name if it includes shell meta characters - */ -char * -expand(char name[]) -{ - static char xname[BUFSIZ]; - char cmdbuf[BUFSIZ]; - int l; - char *cp, *Shell; - int s, pivec[2]; - pid_t pid; - - if (!anyof(name, "~{[*?$`'\"\\")) - return(name); - /* sigint = signal(SIGINT, SIG_IGN); */ - if (pipe(pivec) < 0) { - perror("pipe"); - /* signal(SIGINT, sigint) */ - return(name); - } - (void)snprintf(cmdbuf, sizeof(cmdbuf), "echo %s", name); - if ((pid = vfork()) == 0) { - Shell = vgetstr(SHELL); - if (Shell == NULL) - Shell = _PATH_BSHELL; - close(pivec[0]); - close(1); - dup(pivec[1]); - close(pivec[1]); - close(2); - execl(Shell, Shell, "-c", cmdbuf, (char *)NULL); - _exit(1); - } - if (pid == -1) { - perror("fork"); - close(pivec[0]); - close(pivec[1]); - return(NULL); - } - close(pivec[1]); - l = read(pivec[0], xname, BUFSIZ); - close(pivec[0]); - while (wait(&s) != pid); - ; - s &= 0377; - if (s != 0 && s != SIGPIPE) { - fprintf(stderr, "\"Echo\" failed\n"); - return(NULL); - } - if (l < 0) { - perror("read"); - return(NULL); - } - if (l == 0) { - fprintf(stderr, "\"%s\": No match\n", name); - return(NULL); - } - if (l == BUFSIZ) { - fprintf(stderr, "Buffer overflow expanding \"%s\"\n", name); - return(NULL); - } - xname[l] = 0; - for (cp = &xname[l-1]; *cp == '\n' && cp > xname; cp--) - ; - *++cp = '\0'; - return(xname); -} - -/* - * Are any of the characters in the two strings the same? - */ -static int -anyof(char *s1, char *s2) -{ - int c; - - while ((c = *s1++)) - if (any(c, s2)) - return(1); - return(0); -} diff --git a/usr.bin/tip/cmdtab.c b/usr.bin/tip/cmdtab.c deleted file mode 100644 index 74d8827e096..00000000000 --- a/usr.bin/tip/cmdtab.c +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: cmdtab.c,v 1.10 2010/06/29 16:44:38 nicm Exp $ */ -/* $NetBSD: cmdtab.c,v 1.3 1994/12/08 09:30:46 jtc Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "tip.h" - -esctable_t etable[] = { - { '!', "shell", shell }, - { '<', "receive file from remote host", getfl }, - { '>', "send file to remote host", sendfile }, - { 't', "take file from remote UNIX", cu_take }, - { 'p', "put file to remote UNIX", cu_put }, - { '|', "pipe remote file", pipefile }, - { '$', "pipe local command to remote host", pipeout }, - { 'C', "connect program to remote host", consh }, - { 'c', "change directory", chdirectory }, - { '.', "exit from tip", finish }, - { CTRL('d'), "exit from tip", finish }, - { CTRL('y'), "suspend tip (local+remote)", suspend }, - { CTRL('z'), "suspend tip (local only)", suspend }, - { 's', "set variable", variable }, - { 'v', "list variables", listvariables }, - { '?', "get this summary", help }, - { '#', "send break", genbrk }, - { 0, 0, 0 } -}; diff --git a/usr.bin/tip/hunt.c b/usr.bin/tip/hunt.c deleted file mode 100644 index a7ec77b787f..00000000000 --- a/usr.bin/tip/hunt.c +++ /dev/null @@ -1,123 +0,0 @@ -/* $OpenBSD: hunt.c,v 1.19 2010/07/03 03:38:22 nicm Exp $ */ -/* $NetBSD: hunt.c,v 1.6 1997/04/20 00:02:10 mellon Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include "tip.h" - -static jmp_buf deadline; -static int deadflag; - -static void dead(int); - -/*ARGSUSED*/ -static void -dead(int signo) -{ - deadflag = 1; - longjmp(deadline, 1); -} - -/* Find and open the host. Returns the fd, or exits on error. */ -int -hunt(char *hosts) -{ - char *copy, *last, *host, *device; - struct termios tio; - int fd, tried; - sig_t old_alrm; - - if (hosts == NULL) { - hosts = getenv("HOST"); - if (hosts == NULL) - errx(3, "no host specified"); - } - - if ((copy = strdup(hosts)) == NULL) - err(1, "strdup"); - last = copy; - - old_alrm = signal(SIGALRM, dead); - - tried = 0; - while ((host = strsep(&last, ",")) != NULL) { - device = getremote(host); - - uucplock = strrchr(device, '/'); - if (uucplock == NULL) - uucplock = strdup(device); - else - uucplock = strdup(uucplock + 1); - if (uucplock == NULL) - err(1, "strdup"); - if (uu_lock(uucplock) != UU_LOCK_OK) - continue; - - deadflag = 0; - if (setjmp(deadline) == 0) { - alarm(10); - - fd = open(device, - O_RDWR | (vgetnum(DC) ? O_NONBLOCK : 0)); - if (fd < 0) - perror(device); - } - alarm(0); - - tried++; - if (fd >= 0 && !deadflag) { - tcgetattr(fd, &tio); - if (!vgetnum(DC)) - tio.c_cflag |= HUPCL; - if (tcsetattr(fd, TCSAFLUSH, &tio) != 0) - errx(1, "tcsetattr"); - - if (ioctl(fd, TIOCEXCL) != 0) - errx(1, "ioctl"); - - signal(SIGALRM, old_alrm); - return (fd); - } - - uu_unlock(uucplock); - free(uucplock); - } - free(copy); - - signal(SIGALRM, old_alrm); - if (tried == 0) { - printf("all ports busy\n"); - exit(3); - } - printf("link down\n"); - exit(3); -} diff --git a/usr.bin/tip/log.c b/usr.bin/tip/log.c deleted file mode 100644 index b92cc81e700..00000000000 --- a/usr.bin/tip/log.c +++ /dev/null @@ -1,75 +0,0 @@ -/* $OpenBSD: log.c,v 1.13 2010/07/01 21:28:01 nicm Exp $ */ -/* $NetBSD: log.c,v 1.4 1994/12/24 17:56:28 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "tip.h" - -static FILE *flog = NULL; - -/* - * Log file maintenance routines - */ -void -logent(char *group, char *acu, char *message) -{ - char *user, *timestamp; - struct passwd *pwd; - time_t t; - - if (flog == NULL) - return; - if (flock(fileno(flog), LOCK_EX) < 0) { - perror("flock"); - return; - } - if ((user = getlogin()) == NULL) { - if ((pwd = getpwuid(getuid())) == NULL) - user = "???"; - else - user = pwd->pw_name; - } - t = time(0); - timestamp = ctime(&t); - timestamp[24] = '\0'; - fprintf(flog, "%s (%s) <%s, %s> %s\n", - user, timestamp, group, - acu, message); - (void) fflush(flog); - (void) flock(fileno(flog), LOCK_UN); -} - -void -loginit(void) -{ - flog = fopen(vgetstr(LOG), "a"); - if (flog == NULL) - fprintf(stderr, "can't open log file %s.\r\n", vgetstr(LOG)); -} diff --git a/usr.bin/tip/partab.c b/usr.bin/tip/partab.c deleted file mode 100644 index c25c12f704f..00000000000 --- a/usr.bin/tip/partab.c +++ /dev/null @@ -1,53 +0,0 @@ -/* $OpenBSD: partab.c,v 1.6 2009/10/27 23:59:44 deraadt Exp $ */ -/* $NetBSD: partab.c,v 1.4 1996/12/29 10:38:21 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Even parity table for 0-0177 - */ -const unsigned char evenpartab[] = { - 0000,0201,0202,0003,0204,0005,0006,0207, - 0210,0011,0012,0213,0014,0215,0216,0017, - 0220,0021,0022,0223,0024,0225,0226,0027, - 0030,0231,0232,0033,0234,0035,0036,0237, - 0240,0041,0042,0243,0044,0245,0246,0047, - 0050,0251,0252,0053,0254,0055,0056,0257, - 0060,0261,0262,0063,0264,0065,0066,0267, - 0270,0071,0072,0273,0074,0275,0276,0077, - 0300,0101,0102,0303,0104,0305,0306,0107, - 0110,0311,0312,0113,0314,0115,0116,0317, - 0120,0321,0322,0123,0324,0125,0126,0327, - 0330,0131,0132,0333,0134,0335,0336,0137, - 0140,0341,0342,0143,0344,0145,0146,0347, - 0350,0151,0152,0353,0154,0355,0356,0157, - 0360,0161,0162,0363,0164,0365,0366,0167, - 0170,0371,0372,0173,0374,0175,0176,0377, -}; diff --git a/usr.bin/tip/remote.c b/usr.bin/tip/remote.c deleted file mode 100644 index 6fb2bafe6fd..00000000000 --- a/usr.bin/tip/remote.c +++ /dev/null @@ -1,197 +0,0 @@ -/* $OpenBSD: remote.c,v 1.33 2010/08/01 20:27:51 nicm Exp $ */ -/* $NetBSD: remote.c,v 1.5 1997/04/20 00:02:45 mellon Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include "tip.h" - -static char *db_array[3] = { _PATH_REMOTE, 0, 0 }; - -#define cgetflag(f) (cgetcap(bp, f, ':') != NULL) - -char * -getremote(char *host) -{ - char *bp, *rempath, *strval; - int stat; - long val; - - rempath = getenv("REMOTE"); - if (rempath != NULL) { - if (*rempath != '/') - /* we have an entry */ - cgetset(rempath); - else { /* we have a path */ - db_array[1] = rempath; - db_array[2] = _PATH_REMOTE; - } - } - - if ((stat = cgetent(&bp, db_array, host)) < 0) { - if (vgetstr(DEVICE) != NULL || - (host[0] == '/' && access(host, R_OK | W_OK) == 0)) { - if (vgetstr(DEVICE) == NULL) - vsetstr(DEVICE, host); - vsetstr(HOST, host); - if (!vgetnum(BAUDRATE)) - vsetnum(BAUDRATE, DEFBR); - vsetnum(FRAMESIZE, DEFFS); - return (vgetstr(DEVICE)); - } - switch (stat) { - case -1: - fprintf(stderr, "%s: unknown host %s\n", __progname, - host); - break; - case -2: - fprintf(stderr, - "%s: can't open host description file\n", - __progname); - break; - case -3: - fprintf(stderr, - "%s: possible reference loop in host description file\n", __progname); - break; - } - exit(3); - } - - /* String options. Use if not already set. */ - if (vgetstr(DEVICE) == NULL && cgetstr(bp, "dv", &strval) >= 0) - vsetstr(DEVICE, strval); - if (vgetstr(CONNECT) == NULL && cgetstr(bp, "cm", &strval) >= 0) - vsetstr(CONNECT, strval); - if (vgetstr(DISCONNECT) == NULL && cgetstr(bp, "di", &strval) >= 0) - vsetstr(DISCONNECT, strval); - if (vgetstr(EOL) == NULL && cgetstr(bp, "el", &strval) >= 0) - vsetstr(EOL, strval); - if (vgetstr(EOFREAD) == NULL && cgetstr(bp, "ie", &strval) >= 0) - vsetstr(EOFREAD, strval); - if (vgetstr(EOFWRITE) == NULL && cgetstr(bp, "oe", &strval) >= 0) - vsetstr(EOFWRITE, strval); - if (vgetstr(EXCEPTIONS) == NULL && cgetstr(bp, "ex", &strval) >= 0) - vsetstr(EXCEPTIONS, strval); - if (vgetstr(RECORD) == NULL && cgetstr(bp, "re", &strval) >= 0) - vsetstr(RECORD, strval); - if (vgetstr(PARITY) == NULL && cgetstr(bp, "pa", &strval) >= 0) - vsetstr(PARITY, strval); - - /* Numbers with default values. Set if currently zero (XXX ugh). */ - if (vgetnum(BAUDRATE) == 0) { - if (cgetnum(bp, "br", &val) < 0) - vsetnum(BAUDRATE, DEFBR); - else - vsetnum(BAUDRATE, val); - } - if (vgetnum(LINEDISC) == 0) { /* XXX relies on TTYDISC == 0 */ - if (cgetnum(bp, "ld", &val) < 0) - vsetnum(LINEDISC, TTYDISC); - else - vsetnum(LINEDISC, val); - } - if (vgetnum(FRAMESIZE) == 0) { - if (cgetnum(bp, "fs", &val) < 0) - vsetnum(FRAMESIZE, DEFFS); - else - vsetnum(FRAMESIZE, val); - } - - /* Numbers - default values already set in vinit() or zero. */ - if (cgetnum(bp, "es", &val) >= 0) - vsetnum(ESCAPE, val); - if (cgetnum(bp, "fo", &val) >= 0) - vsetnum(FORCE, val); - if (cgetnum(bp, "pr", &val) >= 0) - vsetnum(PROMPT, val); - if (cgetnum(bp, "rc", &val) >= 0) - vsetnum(RAISECHAR, val); - - /* Numbers - default is zero. */ - if (cgetnum(bp, "dl", &val) < 0) - vsetnum(LDELAY, 0); - else - vsetnum(LDELAY, val); - if (cgetnum(bp, "cl", &val) < 0) - vsetnum(CDELAY, 0); - else - vsetnum(CDELAY, val); - if (cgetnum(bp, "et", &val) < 0) - vsetnum(ETIMEOUT, 0); - else - vsetnum(ETIMEOUT, val); - - /* Flag options. */ - if (cgetflag("hd")) /* XXX overrides command line */ - vsetnum(HALFDUPLEX, 1); - if (cgetflag("ra")) - vsetnum(RAISE, 1); - if (cgetflag("ec")) - vsetnum(ECHOCHECK, 1); - if (cgetflag("be")) - vsetnum(BEAUTIFY, 1); - if (cgetflag("nb")) - vsetnum(BEAUTIFY, 0); - if (cgetflag("sc")) - vsetnum(SCRIPT, 1); - if (cgetflag("tb")) - vsetnum(TABEXPAND, 1); - if (cgetflag("vb")) /* XXX overrides command line */ - vsetnum(VERBOSE, 1); - if (cgetflag("nv")) /* XXX overrides command line */ - vsetnum(VERBOSE, 0); - if (cgetflag("ta")) - vsetnum(TAND, 1); - if (cgetflag("nt")) - vsetnum(TAND, 0); - if (cgetflag("rw")) - vsetnum(RAWFTP, 1); - if (cgetflag("hd")) - vsetnum(HALFDUPLEX, 1); - if (cgetflag("dc")) - vsetnum(DC, 1); - if (cgetflag("hf")) - vsetnum(HARDWAREFLOW, 1); - - if (vgetstr(RECORD) == NULL) - vsetstr(RECORD, "tip.record"); - if (vgetstr(EXCEPTIONS) == NULL) - vsetstr(EXCEPTIONS, "\t\n\b\f"); - - vsetstr(HOST, host); - if (vgetstr(DEVICE) == NULL) { - fprintf(stderr, "%s: missing device spec\n", host); - exit(3); - } - return (vgetstr(DEVICE)); -} diff --git a/usr.bin/tip/tip.1 b/usr.bin/tip/tip.1 deleted file mode 100644 index 85da49aeb08..00000000000 --- a/usr.bin/tip/tip.1 +++ /dev/null @@ -1,558 +0,0 @@ -.\" $OpenBSD: tip.1,v 1.43 2014/03/17 20:05:27 tedu Exp $ -.\" $NetBSD: tip.1,v 1.7 1994/12/08 09:31:05 jtc Exp $ -.\" -.\" Copyright (c) 1980, 1990, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)tip.1 8.4 (Berkeley) 4/18/94 -.\" -.Dd $Mdocdate: March 17 2014 $ -.Dt TIP 1 -.Os -.Sh NAME -.Nm tip -.Nd serial terminal emulator -.Sh SYNOPSIS -.Nm -.Op Fl nv -.Op Fl Ar speed -.Op Ar system-name -.Sh DESCRIPTION -.Nm -is used to connect to another system over a serial link. -In the era before modern networks, it was typically used to -connect to a modem in order to dial in to a remote host. -It is now frequently used for tasks such as attaching to the -serial console of another machine for administrative or -debugging purposes. -.Pp -The options are as follows: -.Bl -tag -width 4n -.It Fl n -No escape (disable tilde). -.It Fl v -Set verbose mode. -.El -.Pp -If -.Ar speed -is specified, it will override any baudrate specified in the system -description being used. -.Pp -If neither -.Ar speed -nor -.Ar system-name -are specified, -.Ar system-name -will be set to the value of the -.Ev HOST -environment variable. -.Pp -If -.Ar speed -is specified but -.Ar system-name -is not, -.Ar system-name -will be set to a value of 'tip' with -.Ar speed -appended. -For example, -.Ic tip -1200 -will set -.Ar system-name -to 'tip1200'. -.Pp -Line access is logged to -.Pa /var/log/aculog . -This file does not exist by default and has to be created -to enable logging. -.Pp -Typed characters are normally transmitted directly to the remote -machine (which does the echoing as well). -A tilde -.Pq Ql ~ -appearing as the first character of a line is an escape signal; the -following are recognized: -.Bl -tag -offset indent -width Fl -.It Ic ~^D No or Ic ~. -Drop the connection and exit. -Only the connection is dropped \(en the login session is not terminated. -.It Ic ~c Op Ar name -Change directory to -.Ar name -(no argument implies change to home directory). -.It Ic ~! -Escape to a shell (exiting the shell will return to -.Nm ) . -.It Ic ~\*(Gt -Copy file from local to remote. -.Nm -prompts for the name of a local file to transmit. -.It Ic ~\*(Lt -Copy file from remote to local. -.Nm -prompts first for the name of the file to be sent, then for a command -to be executed on the remote machine. -.It Ic ~p Ar from Op Ar to -Send a file to a remote -.Ux -host. -This command causes the remote -.Ux -system to run the following command string, -sending it the -.Sq from -file: -.Bd -literal -offset indent -stty -echo; cat \*(Gt 'to'; stty echo -.Ed -.Pp -If the -.Sq to -file isn't specified, the -.Sq from -file name is used. -This command is actually a -.Ux -specific version of the -.Ic ~\*(Gt -command. -.It Ic ~t Ar from Op Ar to -Take a file from a remote -.Ux -host. -As in the -.Ic ~p -command, the -.Sq to -file defaults to the -.Sq from -file name if it isn't specified. -The remote host executes the following command string -to send the file to -.Nm : -.Bd -literal -offset indent -cat 'from'; echo '' | tr '\e012' '\e01' -.Ed -.It Ic ~| -Pipe the output from a remote command to a local -.Ux -process. -The command string sent to the local -.Ux -system is processed by the shell. -.It Ic ~$ -Pipe the output from a local -.Ux -process to the remote host. -The command string sent to the local -.Ux -system is processed by the shell. -.It Ic ~C -Fork a child process on the local system to perform special protocols -such as XMODEM. -The child program will be run with the following arrangement of -file descriptors: -.Bd -literal -offset indent -0 \*(Lt-\*(Gt remote tty in -1 \*(Lt-\*(Gt remote tty out -2 \*(Lt-\*(Gt local tty stderr -.Ed -.It Ic ~# -Send a -.Dv BREAK -to the remote system. -For systems which don't support the necessary -.Fn ioctl -call, the break is simulated by a sequence of line speed changes and -DEL characters. -.It Ic ~s -Set a variable (see the discussion below). -.It Ic ~v -List all variables and their values (if set). -.It Ic ~^Z -Stop -.Nm -(only available with job control). -.It Ic ~^Y -Stop only the -.Dq local side -of -.Nm -(only available with job control); the -.Dq remote side -of -.Nm , -the side that displays output from the remote host, is left running. -.It Ic ~? -Get a summary of the tilde escapes. -.El -.Pp -To find the system description, and thus the operating characteristics -of -.Ar system-name , -.Nm -searches for a system description with a name identical to -.Ar system-name . -The search order is -.Bl -enum -offset indent -.It -If the environment variable -.Ev REMOTE -does not start with a -.Ql / -it is assumed to be a system description, and is considered first. -.It -If the environment variable -.Ev REMOTE -begins with a -.Ql / -it is assumed to be a path to a -.Xr remote 5 -database, and the specified database is searched. -.It -The default -.Xr remote 5 -database, -.Pa /etc/remote , -is searched. -.El -.Pp -See -.Xr remote 5 -for full documentation on system descriptions. -.Pp -The -.Ar br -capability is used in system descriptions to specify the baud rate -with which to establish a connection. -If the value specified is not suitable, the baud rate to be used may -be given on the command line, e.g.\& -.Ql tip -300 mds . -.Pp -The -.Ar dv -capability is used to specify the device -with which to establish a connection. -For reasons outlined in -.Xr tty 4 , -.Xr cua 4 -devices should be used on architectures which have them. -For those which do not, -.Xr tty 4 -devices can be used. -Users in group -.Dq dialer -are permitted to use -.Xr cua 4 -devices by default; -permissions on -.Pa /dev/tty00 -or -.Pa /dev/ttya -can be changed, -but they will revert to their defaults -after an upgrade or (re)install. -.Pp -When -.Nm -establishes a connection, it sends out the connection message -specified in the -.Ar cm -capability of the system description being used. -.Pp -When -.Nm -prompts for an argument, for example during setup of a file transfer, the -line typed may be edited with the standard erase and kill characters. -A null line in response to a prompt, or an interrupt, will abort the -dialogue and return the user to the remote machine. -.Pp -.Nm -guards against multiple users connecting to a remote system by opening -modems and terminal lines with exclusive access, and by honoring the -locking protocol used by -.Xr uucico . -.Pp -During file transfers -.Nm -provides a running count of the number of lines transferred. -When using the -.Ic ~\*(Gt -and -.Ic ~\*(Lt -commands, the -.Dq eofread -and -.Dq eofwrite -variables are used to recognize end-of-file when reading, and specify -end-of-file when writing (see below). -File transfers normally depend on hardwareflow or tandem mode for flow control. -If the remote system does not support hardwareflow or tandem mode, -.Dq echocheck -may be set to indicate -.Nm -should synchronize with the remote system on the echo of each -transmitted character. -.Ss VARIABLES -.Nm -maintains a set of variables which control its operation. -Some of these variables are read-only to normal users (root is allowed -to change anything of interest). -Variables may be displayed and set through the -.Sq s -escape. -The syntax for variables is patterned after -.Xr vi 1 -and -.Xr Mail 1 . -Supplying -.Dq all -as an argument to the set command displays all variables readable by -the user. -Alternatively, the user may request display of a particular variable -by attaching a -.Ql \&? -to the end. -For example, -.Dq escape? -displays the current escape character. -.Pp -Variables are numeric, string, character, or boolean values. -Boolean variables are set merely by specifying their name; they may be -reset by prepending a -.Ql \&! -to the name. -Other variable types are set by concatenating an -.Ql = -and the value. -The entire assignment must not have any blanks in it. -A single set command may be used to interrogate as well as set a -number of variables. -Variables may be initialized at run time by placing set commands -(without the -.Ql ~s -prefix) in the initialization file -.Pa ~/.tiprc ; -the -.Fl v -option additionally causes -.Nm -to display the sets as they are made. -Certain common variables have abbreviations. -The following is a list of common variables, their abbreviations, and -their default values: -.Bl -tag -width Ar -.It Ar baudrate -(num) The baud rate at which the connection was established; -abbreviated -.Ar ba . -.It Ar beautify -(bool) Discard unprintable characters when a session is being -scripted; abbreviated -.Ar be . -.It Ar echocheck -(bool) Synchronize with the remote host during file transfer by -waiting for the echo of the last character transmitted; default is -.Ar off . -.It Ar eofread -(str) The set of characters which signify an end-of-transmission -during a -.Ic ~\*(Lt -file transfer command; abbreviated -.Ar eofr . -.It Ar eofwrite -(str) The string sent to indicate end-of-transmission during a -.Ic ~\*(Gt -file transfer command; abbreviated -.Ar eofw . -.It Ar eol -(str) The set of characters which indicate an end-of-line. -.Nm -will recognize escape characters only after an end-of-line. -.It Ar escape -(char) The command prefix (escape) character; abbreviated -.Ar es ; -default value is -.Ql ~ . -.It Ar exceptions -(str) The set of characters which should not be discarded due to the -beautification switch; abbreviated -.Ar ex ; -default value is -.Dq \et\en\ef\eb . -.It Ar force -(char) The character used to force literal data transmission; -abbreviated -.Ar fo ; -default value is -.Ql ^P . -.It Ar framesize -(num) The amount of data (in bytes) to buffer between filesystem -writes when receiving files; abbreviated -.Ar fr . -.It Ar hardwareflow -(bool) Whether hardware flow control (CRTSCTS) is enabled for the -connection; abbreviated -.Ar hf ; -default value is -.Ql off . -.It Ar host -(str) The name of the host to which you are connected; abbreviated -.Ar ho . -.It Ar linedisc -(num) The line discipline to use; abbreviated -.Ar ld . -.It Ar prompt -(char) The character which indicates an end-of-line on the remote -host; abbreviated -.Ar pr ; -default value is -.Ql \en . -This value is used to synchronize during data transfers. -The count of lines transferred during a file transfer command is based -on receipt of this character. -.It Ar raise -(bool) Upper case mapping mode; abbreviated -.Ar ra ; -default value is -.Ar off . -When this mode is enabled, all lowercase letters will be mapped to -uppercase by -.Nm -for transmission to the remote machine. -.It Ar raisechar -(char) The input character used to toggle uppercase mapping mode; -abbreviated -.Ar rc ; -default value is -.Ql ^A . -.It Ar record -(str) The name of the file in which a session script is recorded; -abbreviated -.Ar rec ; -default value is -.Dq tip.record . -.It Ar script -(bool) Session scripting mode; abbreviated -.Ar sc ; -default is -.Ar off . -When -.Ar script -is -.Li true , -.Nm -will record everything transmitted by the remote machine in the script -record file specified in -.Ar record . -If the -.Ar beautify -switch is on, only printable -.Tn ASCII -characters will be included in the script file (those characters -between 040 and 0177). -The variable -.Ar exceptions -is used to indicate characters which are an exception to the normal -beautification rules. -.It Ar tabexpand -(bool) Expand tabs to spaces during file transfers; abbreviated -.Ar tab ; -default value is -.Ar false . -Each tab is expanded to 8 spaces. -.It Ar tandem -(bool) Use XON/XOFF flow control to throttle data from the remote host; -abbreviated -.Ar ta . -The default value is -.Ar true -unless the -.Ar nt -capability has been specified in -.Pa /etc/remote , -in which case the default value is -.Ar false . -.It Ar verbose -(bool) Verbose mode; abbreviated -.Ar verb ; -default is -.Ar true . -When verbose mode is enabled, -.Nm -prints messages while dialing, shows the current number of lines -transferred during a file transfer operations, and more. -.El -.Sh ENVIRONMENT -.Bl -tag -width Fl -.It Ev HOME -The home directory to use for the -.Ic ~c -command. -.It Ev HOST -The default value for -.Ar system-name -if none is specified via the command line. -.It Ev REMOTE -A system description, or an absolute path to a -.Xr remote 5 -system description database. -.It Ev SHELL -The name of the shell to use for the -.Ic ~!\& -command; default value is -.Dq /bin/sh . -.El -.Sh FILES -.Bl -tag -width "/var/spool/lock/LCK..*" -compact -.It Pa ~/.tiprc -initialization file -.It Pa tip.record -record file -.It Pa /etc/remote -global -.Xr remote 5 -database -.It Pa /var/log/aculog -line access log -.It Pa /var/spool/lock/LCK..* -lock file -.El -.Sh SEE ALSO -.Xr cu 1 , -.Xr remote 5 -.Sh HISTORY -The -.Nm -command appeared in -.Bx 4.2 . -.Sh BUGS -The full set of variables is undocumented and should, probably, be -pared down. diff --git a/usr.bin/tip/tip.c b/usr.bin/tip/tip.c deleted file mode 100644 index 6497828cc82..00000000000 --- a/usr.bin/tip/tip.c +++ /dev/null @@ -1,520 +0,0 @@ -/* $OpenBSD: tip.c,v 1.56 2015/04/18 18:28:38 deraadt Exp $ */ -/* $NetBSD: tip.c,v 1.13 1997/04/20 00:03:05 mellon Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * tip - UNIX link to other systems - * tip [-v] [-speed] system-name - */ - -#include -#include - -#include - -#include "tip.h" - -static void intprompt(int); -static void tipin(void); -static int escape(void); - -int -main(int argc, char *argv[]) -{ - char *sys = NULL; - const char *errstr; - int baud; - int i, pair[2]; - - vinit(); - - /* XXX preserve previous braindamaged behavior */ - vsetnum(DC, 1); - - if (argc > 4) { - fprintf(stderr, "usage: tip [-nv] [-speed] [system-name]\n"); - exit(1); - } - if (!isatty(0)) { - fprintf(stderr, "%s: must be interactive\n", __progname); - exit(1); - } - - for (; argc > 1; argv++, argc--) { - if (argv[1][0] != '-') - sys = argv[1]; - else switch (argv[1][1]) { - - case 'v': - vflag++; - break; - - case 'n': - noesc++; - break; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - baud = strtonum(&argv[1][1], 0, INT_MAX, &errstr); - if (errstr) { - fprintf(stderr, "incorrect speed: %s\n", errstr); - exit(1); - } - vsetnum(BAUDRATE, baud); - break; - - default: - fprintf(stderr, "%s: %s, unknown option\n", __progname, - argv[1]); - break; - } - } - - (void)signal(SIGINT, cleanup); - (void)signal(SIGQUIT, cleanup); - (void)signal(SIGHUP, cleanup); - (void)signal(SIGTERM, cleanup); - (void)signal(SIGCHLD, SIG_DFL); - - FD = hunt(sys); - setbuf(stdout, NULL); - - loginit(); - setparity("none"); /* set the parity table */ - - if (ttysetup(vgetnum(BAUDRATE))) { - fprintf(stderr, "%s: bad baud rate %d\n", __progname, - vgetnum(BAUDRATE)); - (void)uu_unlock(uucplock); - exit(3); - } - con(); - - i = fcntl(FD, F_GETFL); - if (i == -1) { - perror("fcntl"); - cleanup(0); - } - i = fcntl(FD, F_SETFL, i & ~O_NONBLOCK); - if (i == -1) { - perror("fcntl"); - cleanup(0); - } - - tcgetattr(0, &defterm); - gotdefterm = 1; - term = defterm; - term.c_lflag &= ~(ICANON|IEXTEN|ECHO); - term.c_iflag &= ~(INPCK|ICRNL); - term.c_oflag &= ~OPOST; - term.c_cc[VMIN] = 1; - term.c_cc[VTIME] = 0; - defchars = term; - term.c_cc[VINTR] = term.c_cc[VQUIT] = term.c_cc[VSUSP] = - term.c_cc[VDSUSP] = term.c_cc[VDISCARD] = - term.c_cc[VLNEXT] = _POSIX_VDISABLE; - raw(); - - (void)signal(SIGALRM, timeout); - - if (vgetnum(LINEDISC) != TTYDISC) { - int ld = (int)vgetnum(LINEDISC); - ioctl(FD, TIOCSETD, &ld); - } - - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0) { - (void)uu_unlock(uucplock); - err(3, "socketpair"); - } - - /* - * Everything's set up now: - * connection established (hardwired or dialup) - * line conditioned (baud rate, mode, etc.) - * internal data structures (variables) - * so, fork one process for local side and one for remote. - */ - printf("\07connected\r\n"); - tipin_pid = getpid(); - switch (tipout_pid = fork()) { - case -1: - (void)uu_unlock(uucplock); - err(3, "fork"); - case 0: - close(pair[1]); - tipin_fd = pair[0]; - tipout(); - default: - close(pair[0]); - tipout_fd = pair[1]; - tipin(); - } - /*NOTREACHED*/ - exit(0); -} - -void -con(void) -{ - if (vgetstr(CONNECT) != NULL) - parwrite(FD, vgetstr(CONNECT), size(vgetstr(CONNECT))); - logent(vgetstr(HOST), vgetstr(DEVICE), "call completed"); -} - -void -cleanup(int signo) -{ - (void)uu_unlock(uucplock); - if (odisc) - ioctl(0, TIOCSETD, &odisc); - unraw(); - if (signo && tipout_pid) { - kill(tipout_pid, signo); - wait(NULL); - } - exit(0); -} - -/* - * put the controlling keyboard into raw mode - */ -void -raw(void) -{ - tcsetattr(0, TCSADRAIN, &term); -} - - -/* - * return keyboard to normal mode - */ -void -unraw(void) -{ - if (gotdefterm) - tcsetattr(0, TCSADRAIN, &defterm); -} - -static jmp_buf promptbuf; - -/* - * Print string ``s'', then read a string - * in from the terminal. Handles signals & allows use of - * normal erase and kill characters. - */ -int -prompt(char *s, char *p, size_t sz) -{ - int c; - char *b = p; - sig_t oint, oquit; - - stoprompt = 0; - oint = signal(SIGINT, intprompt); - oquit = signal(SIGQUIT, SIG_IGN); - unraw(); - printf("%s", s); - if (setjmp(promptbuf) == 0) - while ((c = getchar()) != EOF && (*p = c) != '\n' && --sz > 0) - p++; - *p = '\0'; - - raw(); - (void)signal(SIGINT, oint); - (void)signal(SIGQUIT, oquit); - return (stoprompt || p == b); -} - -/* - * Interrupt service routine during prompting - */ -/*ARGSUSED*/ -static void -intprompt(int signo) -{ - (void)signal(SIGINT, SIG_IGN); - stoprompt = 1; - printf("\r\n"); - longjmp(promptbuf, 1); -} - -/* - * ****TIPIN TIPIN**** - */ -static void -tipin(void) -{ - int bol = 1; - int gch; - char ch; - - /* - * Kinda klugey here... - * check for scripting being turned on from the .tiprc file, - * but be careful about just using setscript(), as we may - * send a SIGEMT before tipout has a chance to set up catching - * it; so wait a second, then setscript() - */ - if (vgetnum(SCRIPT)) { - sleep(1); - setscript(); - } - - while (1) { - gch = getchar(); - if (gch == EOF) - cleanup(0); - gch &= STRIP_PAR; - if (gch == vgetnum(ESCAPE) && bol) { - if (!noesc) { - if (!(gch = escape())) - continue; - } - } else if (gch == vgetnum(RAISECHAR)) { - vsetnum(RAISE, !vgetnum(RAISE)); - continue; - } else if (gch == '\r') { - bol = 1; - ch = gch; - parwrite(FD, &ch, 1); - if (vgetnum(HALFDUPLEX)) - printf("\r\n"); - continue; - } else if (gch == vgetnum(FORCE)) { - gch = getchar(); - if (gch == EOF) - cleanup(0); - gch &= STRIP_PAR; - } - bol = any(gch, vgetstr(EOL)); - if (vgetnum(RAISE) && islower(gch)) - gch = toupper(gch); - ch = gch; - parwrite(FD, &ch, 1); - if (vgetnum(HALFDUPLEX)) - printf("%c", ch); - } -} - -extern esctable_t etable[]; - -/* - * Escape handler -- - * called on recognition of ``escapec'' at the beginning of a line - */ -static int -escape(void) -{ - int gch; - esctable_t *p; - char c = vgetnum(ESCAPE); - - gch = getchar(); - if (gch == EOF) - cleanup(0); - gch &= STRIP_PAR; - for (p = etable; p->e_char; p++) - if (p->e_char == gch) { - printf("%s", ctrl(c)); - (*p->e_func)(gch); - return (0); - } - /* ESCAPE ESCAPE forces ESCAPE */ - if (c != gch) - parwrite(FD, &c, 1); - return (gch); -} - -int -any(int cc, char *p) -{ - char c = cc; - while (p && *p) - if (*p++ == c) - return (1); - return (0); -} - -size_t -size(char *s) -{ - size_t i = 0; - - while (s && *s++) - i++; - return (i); -} - -char * -interp(char *s) -{ - static char buf[256]; - char *p = buf, c, *q; - - while ((c = *s++)) { - for (q = "\nn\rr\tt\ff\033E\bb"; *q; q++) - if (*q++ == c) { - *p++ = '\\'; *p++ = *q; - goto next; - } - if (c < 040) { - *p++ = '^'; *p++ = c + 'A'-1; - } else if (c == 0177) { - *p++ = '^'; *p++ = '?'; - } else - *p++ = c; - next: - ; - } - *p = '\0'; - return (buf); -} - -char * -ctrl(char c) -{ - static char s[3]; - - if (c < 040 || c == 0177) { - s[0] = '^'; - s[1] = c == 0177 ? '?' : c+'A'-1; - s[2] = '\0'; - } else { - s[0] = c; - s[1] = '\0'; - } - return (s); -} - -/* - * Help command - */ -void -help(int c) -{ - esctable_t *p; - - printf("%c\r\n", c); - for (p = etable; p->e_char; p++) { - printf("%2s", ctrl(vgetnum(ESCAPE))); - printf("%-2s %s\r\n", ctrl(p->e_char), p->e_help); - } -} - -/* - * Set up the "remote" tty's state - */ -int -ttysetup(int speed) -{ - struct termios cntrl; - - if (tcgetattr(FD, &cntrl)) - return (-1); - cfsetspeed(&cntrl, speed); - cntrl.c_cflag &= ~(CSIZE|PARENB); - cntrl.c_cflag |= CS8; - if (vgetnum(DC)) - cntrl.c_cflag |= CLOCAL; - if (vgetnum(HARDWAREFLOW)) - cntrl.c_cflag |= CRTSCTS; - cntrl.c_iflag &= ~(ISTRIP|ICRNL); - cntrl.c_oflag &= ~OPOST; - cntrl.c_lflag &= ~(ICANON|ISIG|IEXTEN|ECHO); - cntrl.c_cc[VMIN] = 1; - cntrl.c_cc[VTIME] = 0; - if (vgetnum(TAND)) - cntrl.c_iflag |= IXOFF; - return (tcsetattr(FD, TCSAFLUSH, &cntrl)); -} - -static char partab[0200]; - -/* - * Do a write to the remote machine with the correct parity. - * We are doing 8 bit wide output, so we just generate a character - * with the right parity and output it. - */ -void -parwrite(int fd, char *buf, size_t n) -{ - int i; - char *bp; - - bp = buf; - if (bits8 == 0) - for (i = 0; i < n; i++) { - *bp = partab[(*bp) & 0177]; - bp++; - } - if (write(fd, buf, n) < 0) { - if (errno == EIO) - tipabort("Lost carrier."); - /* this is questionable */ - abort();;// - perror("write"); - } -} - -/* - * Build a parity table with appropriate high-order bit. - */ -void -setparity(char *defparity) -{ - int i, flip, clr, set; - char *parity; - extern const unsigned char evenpartab[]; - - if (vgetstr(PARITY) == NULL) - vsetstr(PARITY, defparity); - parity = vgetstr(PARITY); - if (strcmp(parity, "none") == 0) { - bits8 = 1; - return; - } - bits8 = 0; - flip = 0; - clr = 0377; - set = 0; - if (strcmp(parity, "odd") == 0) - flip = 0200; /* reverse bit 7 */ - else if (strcmp(parity, "zero") == 0) - clr = 0177; /* turn off bit 7 */ - else if (strcmp(parity, "one") == 0) - set = 0200; /* turn on bit 7 */ - else if (strcmp(parity, "even") != 0) { - (void) fprintf(stderr, "%s: unknown parity value\r\n", parity); - (void) fflush(stderr); - } - for (i = 0; i < 0200; i++) - partab[i] = ((evenpartab[i] ^ flip) | set) & clr; -} diff --git a/usr.bin/tip/tip.h b/usr.bin/tip/tip.h deleted file mode 100644 index 781003d0dbc..00000000000 --- a/usr.bin/tip/tip.h +++ /dev/null @@ -1,228 +0,0 @@ -/* $OpenBSD: tip.h,v 1.53 2015/02/07 10:07:15 deraadt Exp $ */ -/* $NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tip.h 8.1 (Berkeley) 6/6/93 - */ - -/* - * tip - terminal interface program - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* tip paths. */ -#define _PATH_ACULOG "/var/log/aculog" -#define _PATH_REMOTE "/etc/remote" - -/* Variable table entry. */ -typedef struct { - char *v_name; /* variable name */ - int v_flags; /* type and flags */ - char *v_abbrev; /* possible abbreviation */ - - char *v_string; - int v_number; -} value_t; -extern value_t vtable[]; /* variable table */ - -#define V_STRING 01 /* string valued */ -#define V_BOOL 02 /* true-false value */ -#define V_NUMBER 04 /* numeric value */ -#define V_CHAR 010 /* character value */ -#define V_TYPEMASK 017 - -#define V_CHANGED 020 /* to show modification */ -#define V_READONLY 040 /* variable is not writable */ -#define V_INIT 0100 /* static data space used for initialization */ - -/* Variable table indexes. */ -enum { - BEAUTIFY = 0, - BAUDRATE, - CONNECT, - DEVICE, - EOFREAD, - EOFWRITE, - EOL, - ESCAPE, - EXCEPTIONS, - FORCE, - FRAMESIZE, - HOST, - LOG, - PROMPT, - RAISE, - RAISECHAR, - RECORD, - REMOTE, - SCRIPT, - TABEXPAND, - VERBOSE, - SHELL, - HOME, - ECHOCHECK, - DISCONNECT, - TAND, - LDELAY, - CDELAY, - ETIMEOUT, - RAWFTP, - HALFDUPLEX, - LECHO, - PARITY, - HARDWAREFLOW, - LINEDISC, - DC -}; - -/* - * Escape command table definitions -- - * lookup in this table is performed when ``escapec'' is recognized - * at the begining of a line (as defined by the eolmarks variable). -*/ - -typedef - struct { - char e_char; /* char to match on */ - char *e_help; /* help string */ - void (*e_func)(int); /* command */ - } - esctable_t; - -extern int vflag; /* verbose during reading of .tiprc file */ -extern int noesc; /* no escape `~' char */ - -struct termios term; /* current mode of terminal */ -struct termios defterm; /* initial mode of terminal */ -struct termios defchars; /* current mode with initial chars */ -int gotdefterm; - -FILE *fscript; /* FILE for scripting */ - -int FD; /* open file descriptor to remote host */ -int vflag; /* print .tiprc initialization sequence */ -int noesc; /* no `~' escape char */ -int sfd; /* for ~< operation */ -pid_t tipin_pid; /* pid of tipin */ -int tipin_fd; /* tipin side of socketpair */ -pid_t tipout_pid; /* pid of tipout */ -int tipout_fd; /* tipout side of socketpair */ -volatile sig_atomic_t stop; /* stop transfer session flag */ -volatile sig_atomic_t quit; /* same; but on other end */ -volatile sig_atomic_t stoprompt;/* for interrupting a prompt session */ -volatile sig_atomic_t timedout; /* ~> transfer timedout */ -int bits8; /* terminal is 8-bit mode */ -#define STRIP_PAR (bits8 ? 0377 : 0177) - -char fname[PATH_MAX]; /* file name buffer for ~< */ -char copyname[PATH_MAX]; /* file name buffer for ~> */ -char ccc; /* synchronization character */ -char *uucplock; /* name of lock file for uucp's */ - -int odisc; /* initial tty line discipline */ -extern int disc; /* current tty discpline */ - -extern char *__progname; /* program name */ - -/* cmds.c */ -char *expand(char *); -void chdirectory(int); -void consh(int); -void cu_put(int); -void cu_take(int); -void finish(int); -void genbrk(int); -void getfl(int); -void listvariables(int); -void parwrite(int, char *, size_t); -void pipefile(int); -void pipeout(int); -void sendfile(int); -void setscript(void); -void shell(int); -void suspend(int); -void timeout(int); -void tipabort(char *); -void variable(int); - -/* hunt.c */ -int hunt(char *); - -/* log.c */ -void logent(char *, char *, char *); -void loginit(void); - -/* remote.c */ -char *getremote(char *); - -/* tip.c */ -void con(void); -char *ctrl(char); -char *interp(char *); -int any(int, char *); -int prompt(char *, char *, size_t); -size_t size(char *); -void cleanup(int); -void help(int); -void parwrite(int, char *, size_t); -void raw(void); -void setparity(char *); -int ttysetup(int); -void unraw(void); - -/* tipout.c */ -void tipout(void); - -/* value.c */ -void vinit(void); -void vlex(char *); -char *vgetstr(int); -int vgetnum(int); -void vsetstr(int, char *); -void vsetnum(int, int); diff --git a/usr.bin/tip/tipout.c b/usr.bin/tip/tipout.c deleted file mode 100644 index 65fcec2605b..00000000000 --- a/usr.bin/tip/tipout.c +++ /dev/null @@ -1,210 +0,0 @@ -/* $OpenBSD: tipout.c,v 1.23 2010/07/01 21:28:01 nicm Exp $ */ -/* $NetBSD: tipout.c,v 1.5 1996/12/29 10:34:12 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include - -#include "tip.h" - -/* - * tip - * - * lower fork of tip -- handles passive side - * reading from the remote host - */ - -static void tipout_wait(void); -static void tipout_script(void); -static void tipout_write(char *, size_t); -static void tipout_sighandler(int); - -volatile sig_atomic_t tipout_die; - -/* - * TIPOUT wait state routine -- - * sent by TIPIN when it wants to possess the remote host - */ -static void -tipout_wait(void) -{ - write(tipin_fd, &ccc, 1); - read(tipin_fd, &ccc, 1); -} - -/* - * Scripting command interpreter -- - * accepts script file name over the pipe and acts accordingly - */ -static void -tipout_script(void) -{ - char c, line[256]; - char *pline = line; - char reply; - - read(tipin_fd, &c, 1); - while (c != '\n' && pline - line < sizeof(line)) { - *pline++ = c; - read(tipin_fd, &c, 1); - } - *pline = '\0'; - if (vgetnum(SCRIPT) && fscript != NULL) - fclose(fscript); - if (pline == line) { - vsetnum(SCRIPT, 0); - reply = 'y'; - } else { - if ((fscript = fopen(line, "a")) == NULL) - reply = 'n'; - else { - reply = 'y'; - vsetnum(SCRIPT, 1); - } - } - write(tipin_fd, &reply, 1); -} - -/* - * Write remote input out to stdout (and script file if enabled). - */ -static void -tipout_write(char *buf, size_t len) -{ - char *cp; - - for (cp = buf; cp < buf + len; cp++) - *cp &= STRIP_PAR; - - write(STDOUT_FILENO, buf, len); - - if (vgetnum(SCRIPT) && fscript != NULL) { - if (!vgetnum(BEAUTIFY)) - fwrite(buf, 1, len, fscript); - else { - for (cp = buf; cp < buf + len; cp++) { - if ((*cp >= ' ' && *cp <= '~') || - any(*cp, vgetstr(EXCEPTIONS))) - putc(*cp, fscript); - } - } - } -} - -/* ARGSUSED */ -static void -tipout_sighandler(int signo) -{ - tipout_die = 1; -} - -/* - * ****TIPOUT TIPOUT**** - */ -void -tipout(void) -{ - struct pollfd pfds[2]; - char buf[BUFSIZ], ch; - ssize_t len; - int flag; - - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - - tipout_die = 0; - signal(SIGTERM, tipout_sighandler); - signal(SIGHUP, tipout_sighandler); - - pfds[0].fd = tipin_fd; - pfds[0].events = POLLIN; - - pfds[1].fd = FD; - pfds[1].events = POLLIN; - - while (!tipout_die) { - if (poll(pfds, 2, INFTIM) == -1) { - if (errno == EINTR || errno == EAGAIN) - continue; - goto fail; - } - - if (pfds[0].revents & (POLLHUP|POLLERR)) - goto fail; - if (pfds[0].revents & POLLIN) { - switch (read(tipin_fd, &ch, 1)) { - case 0: - goto fail; - case -1: - if (errno == EINTR || errno == EAGAIN) - break; - goto fail; - default: - switch (ch) { - case 'W': /* wait state */ - tipout_wait(); - break; - case 'S': /* script file */ - tipout_script(); - break; - case 'B': /* toggle beautify */ - flag = !vgetnum(BEAUTIFY); - vsetnum(BEAUTIFY, flag); - break; - } - break; - } - } - - if (pfds[1].revents & (POLLHUP|POLLERR)) - goto fail; - if (pfds[1].revents & POLLIN) { - switch (len = read(FD, buf, BUFSIZ)) { - case 0: - goto fail; - case -1: - if (errno == EINTR || errno == EAGAIN) - continue; - goto fail; - default: - tipout_write(buf, len); - break; - } - } - } - -fail: - if (vgetnum(SCRIPT) && fscript != NULL) - fclose(fscript); - kill(tipin_pid, SIGTERM); - exit(0); -} diff --git a/usr.bin/tip/value.c b/usr.bin/tip/value.c deleted file mode 100644 index 7dbfc892f4e..00000000000 --- a/usr.bin/tip/value.c +++ /dev/null @@ -1,431 +0,0 @@ -/* $OpenBSD: value.c,v 1.33 2010/08/23 19:05:08 nicm Exp $ */ -/* $NetBSD: value.c,v 1.6 1997/02/11 09:24:09 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include "tip.h" - -/* - * Variable manipulation. - */ - -value_t vtable[] = { - { "beautify", V_BOOL, "be", NULL, 0 }, - { "baudrate", V_NUMBER, "ba", NULL, 0 }, - { "connect", V_STRING|V_READONLY, "cm", NULL, 0 }, - { "device", V_STRING|V_READONLY, "dv", NULL, 0 }, - { "eofread", V_STRING, "eofr", NULL, 0 }, - { "eofwrite", V_STRING, "eofw", NULL, 0 }, - { "eol", V_STRING, NULL, NULL, 0 }, - { "escape", V_CHAR, "es", NULL, 0 }, - { "exceptions", V_STRING, "ex", NULL, 0 }, - { "force", V_CHAR, "fo", NULL, 0 }, - { "framesize", V_NUMBER, "fr", NULL, 0 }, - { "host", V_STRING|V_READONLY, "ho", NULL, 0 }, - { "log", V_STRING, NULL, NULL, 0 }, - { "prompt", V_CHAR, "pr", NULL, 0 }, - { "raise", V_BOOL, "ra", NULL, 0 }, - { "raisechar", V_CHAR, "rc", NULL, 0 }, - { "record", V_STRING, "rec", NULL, 0 }, - { "remote", V_STRING|V_READONLY, NULL, NULL, 0 }, - { "script", V_BOOL, "sc", NULL, 0 }, - { "tabexpand", V_BOOL, "tab", NULL, 0 }, - { "verbose", V_BOOL, "verb", NULL, 0 }, - { "SHELL", V_STRING, NULL, NULL, 0 }, - { "HOME", V_STRING, NULL, NULL, 0 }, - { "echocheck", V_BOOL, "ec", NULL, 0 }, - { "disconnect", V_STRING, "di", NULL, 0 }, - { "tandem", V_BOOL, "ta", NULL, 0 }, - { "linedelay", V_NUMBER, "ldelay", NULL, 0 }, - { "chardelay", V_NUMBER, "cdelay", NULL, 0 }, - { "etimeout", V_NUMBER, "et", NULL, 0 }, - { "rawftp", V_BOOL, "raw", NULL, 0 }, - { "halfduplex", V_BOOL, "hdx", NULL, 0 }, - { "localecho", V_BOOL, "le", NULL, 0 }, - { "parity", V_STRING, "par", NULL, 0 }, - { "hardwareflow", V_BOOL, "hf", NULL, 0 }, - { "linedisc", V_NUMBER, "ld", NULL, 0 }, - { "direct", V_BOOL, "dc", NULL, 0 }, - { NULL, 0, NULL, NULL, 0 }, -}; - -static int vlookup(char *); -static void vtoken(char *); -static size_t vprint(value_t *); -static void vprintall(void); -static char *vinterp(char *, int); - -/* Get a string value. */ -char * -vgetstr(int value) -{ - value_t *vp = &vtable[value]; - int type; - - type = vp->v_flags & V_TYPEMASK; - if (type != V_STRING) - errx(1, "variable %s not a string", vp->v_name); - return (vp->v_string); -} - -/* Get a number value. */ -int -vgetnum(int value) -{ - value_t *vp = &vtable[value]; - int type; - - type = vp->v_flags & V_TYPEMASK; - if (type != V_NUMBER && type != V_BOOL && type != V_CHAR) - errx(1, "variable %s not a number", vp->v_name); - return (vp->v_number); -} - -/* Set a string value. */ -void -vsetstr(int value, char *string) -{ - value_t *vp = &vtable[value]; - int type; - - type = vp->v_flags & V_TYPEMASK; - if (type != V_STRING) - errx(1, "variable %s not a string", vp->v_name); - - if (value == RECORD && string != NULL) - string = expand(string); - - free(vp->v_string); - if (string != NULL) { - vp->v_string = strdup(string); - if (vp->v_string == NULL) - err(1, "strdup"); - } else - vp->v_string = NULL; -} - -/* Set a number value. */ -void -vsetnum(int value, int number) -{ - value_t *vp = &vtable[value]; - int type; - - type = vp->v_flags & V_TYPEMASK; - if (type != V_NUMBER && type != V_BOOL && type != V_CHAR) - errx(1, "variable %s not a number", vp->v_name); - - vp->v_number = number; -} - -/* Print a single variable and its value. */ -static size_t -vprint(value_t *p) -{ - char *cp; - size_t width; - - width = size(p->v_name); - switch (p->v_flags & V_TYPEMASK) { - case V_BOOL: - if (!p->v_number) { - width++; - putchar('!'); - } - printf("%s", p->v_name); - break; - case V_STRING: - printf("%s=", p->v_name); - width++; - if (p->v_string) { - cp = interp(p->v_string); - width += size(cp); - printf("%s", cp); - } - break; - case V_NUMBER: - width += 6; - printf("%s=%-5d", p->v_name, p->v_number); - break; - case V_CHAR: - printf("%s=", p->v_name); - width++; - if (p->v_number) { - cp = ctrl(p->v_number); - width += size(cp); - printf("%s", cp); - } - break; - } - return (width); -} - -/* Print all variables. */ -static void -vprintall(void) -{ - value_t *vp; - size_t width; - -#define MIDDLE 35 - width = 0; - for (vp = vtable; vp->v_name; vp++) { - if (vp->v_flags & V_READONLY) - continue; - if (width > 0 && width < MIDDLE) { - while (width++ < MIDDLE) - putchar(' '); - } - width += vprint(vp); - if (width > MIDDLE) { - printf("\r\n"); - width = 0; - } - } -#undef MIDDLE -} - -/* Find index of variable by name or abbreviation. */ -static int -vlookup(char *s) -{ - value_t *vp; - u_int i; - - for (i = 0; vtable[i].v_name != NULL; i++) { - vp = &vtable[i]; - if (strcmp(vp->v_name, s) == 0 || - (vp->v_abbrev != NULL && strcmp(vp->v_abbrev, s) == 0)) - return (i); - } - return (-1); -} - -void -vinit(void) -{ - struct passwd *pw; - value_t *vp; - char file[FILENAME_MAX], *cp; - int written; - FILE *fp; - - /* Clear the table and set the defaults. */ - for (vp = vtable; vp->v_name != NULL; vp++) { - vp->v_string = NULL; - vp->v_number = 0; - } - vsetnum(BEAUTIFY, 1); - vsetnum(ESCAPE, '~'); - vsetnum(FORCE, CTRL('p')); - vsetnum(PROMPT, '\n'); - vsetnum(TAND, 1); - vsetnum(VERBOSE, 1); - vsetstr(LOG, _PATH_ACULOG); - - /* Read environment variables. */ - if ((cp = getenv("HOME")) != NULL) - vsetstr(HOME, cp); - else { - pw = getpwuid(getuid()); - if (pw != NULL && pw->pw_dir != NULL) - vsetstr(HOME, pw->pw_dir); - else - vsetstr(HOME, "/"); - } - if ((cp = getenv("SHELL")) != NULL) - vsetstr(SHELL, cp); - else - vsetstr(SHELL, _PATH_BSHELL); - - /* Read the .tiprc file in the HOME directory. */ - written = snprintf(file, sizeof(file), "%s/.tiprc", vgetstr(HOME)); - if (written < 0 || written >= sizeof(file)) { - (void)fprintf(stderr, "Home directory path too long: %s\n", - vgetstr(HOME)); - } else { - if ((fp = fopen(file, "r")) != NULL) { - char *tp; - - while (fgets(file, sizeof(file), fp) != NULL) { - if (vflag) - printf("set %s", file); - if ((tp = strrchr(file, '\n'))) - *tp = '\0'; - vlex(file); - } - fclose(fp); - } - } -} - -void -vlex(char *s) -{ - char *cp; - - if (strcmp(s, "all") == 0) - vprintall(); - else { - do { - if ((cp = vinterp(s, ' '))) - cp++; - vtoken(s); - s = cp; - } while (s); - } -} - -/* Set a variable from a token. */ -static void -vtoken(char *s) -{ - value_t *vp; - int i, value; - char *cp; - const char *cause; - - if ((cp = strchr(s, '='))) { - *cp = '\0'; - if ((i = vlookup(s)) != -1) { - vp = &vtable[i]; - if (vp->v_flags & V_READONLY) { - printf("access denied\r\n"); - return; - } - cp++; - switch (vp->v_flags & V_TYPEMASK) { - case V_STRING: - vsetstr(i, cp); - break; - case V_BOOL: - vsetnum(i, 1); - break; - case V_NUMBER: - value = strtonum(cp, 0, INT_MAX, &cause); - if (cause != NULL) { - printf("%s: number %s\r\n", s, cause); - return; - } - vsetnum(i, value); - break; - case V_CHAR: - if (cp[0] != '\0' && cp[1] != '\0') { - printf("%s: character too big\r\n", s); - return; - } - vsetnum(i, *cp); - } - vp->v_flags |= V_CHANGED; - return; - } - } else if ((cp = strchr(s, '?'))) { - *cp = '\0'; - if ((i = vlookup(s)) != -1) { - if (vprint(&vtable[i]) > 0) - printf("\r\n"); - return; - } - } else { - if (*s != '!') - i = vlookup(s); - else - i = vlookup(s + 1); - if (i != -1) { - vp = &vtable[i]; - if (vp->v_flags & V_READONLY) { - printf("%s: access denied\r\n", s); - return; - } - if ((vp->v_flags & V_TYPEMASK) != V_BOOL) { - printf("%s: not a boolean\r\n", s); - return; - } - vsetnum(i, *s != '!'); - vp->v_flags |= V_CHANGED; - return; - } - } - printf("%s: unknown variable\r\n", s); -} - -static char * -vinterp(char *s, int stop) -{ - char *p = s, c; - int num; - - while ((c = *s++) && c != stop) { - switch (c) { - - case '^': - if (*s) - *p++ = *s++ - 0100; - else - *p++ = c; - break; - - case '\\': - num = 0; - c = *s++; - if (c >= '0' && c <= '7') - num = (num<<3)+(c-'0'); - else { - char *q = "n\nr\rt\tb\bf\f"; - - for (; *q; q++) - if (c == *q++) { - *p++ = *q; - goto cont; - } - *p++ = c; - cont: - break; - } - if ((c = *s++) >= '0' && c <= '7') { - num = (num<<3)+(c-'0'); - if ((c = *s++) >= '0' && c <= '7') - num = (num<<3)+(c-'0'); - else - s--; - } else - s--; - *p++ = num; - break; - - default: - *p++ = c; - } - } - *p = '\0'; - return (c == stop ? s-1 : NULL); -} -- 2.20.1