diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-07-02 07:40:04 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-07-02 07:40:04 +0000 |
commit | 751b1334adc4c8ca2968246b70aab0d375b48f63 (patch) | |
tree | cdddf81b8904a5782550d66745999f544fe7281d /usr.bin/tip | |
parent | 850e3e1c8bafd475a6b42f0366a7c831f72425bb (diff) |
Clear table and set defaults manually, also move table into value.c.
Diffstat (limited to 'usr.bin/tip')
-rw-r--r-- | usr.bin/tip/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/tip/cu.c | 9 | ||||
-rw-r--r-- | usr.bin/tip/tip.c | 6 | ||||
-rw-r--r-- | usr.bin/tip/value.c | 82 | ||||
-rw-r--r-- | usr.bin/tip/vars.c | 115 |
5 files changed, 85 insertions, 131 deletions
diff --git a/usr.bin/tip/Makefile b/usr.bin/tip/Makefile index c071f1fc80b..04d1f2965e1 100644 --- a/usr.bin/tip/Makefile +++ b/usr.bin/tip/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.14 2010/06/29 20:09:39 nicm Exp $ +# $OpenBSD: Makefile,v 1.15 2010/07/02 07:40:03 nicm Exp $ PROG= tip LINKS= ${BINDIR}/tip ${BINDIR}/cu @@ -9,6 +9,6 @@ LDADD= -lutil DPADD= ${LIBUTIL} SRCS= cmds.c cmdtab.c cu.c hunt.c log.c partab.c remote.c tip.c \ - tipout.c value.c vars.c + tipout.c value.c .include <bsd.prog.mk> diff --git a/usr.bin/tip/cu.c b/usr.bin/tip/cu.c index 3b511ba7ea6..978d4862dc1 100644 --- a/usr.bin/tip/cu.c +++ b/usr.bin/tip/cu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cu.c,v 1.35 2010/07/02 05:52:48 nicm Exp $ */ +/* $OpenBSD: cu.c,v 1.36 2010/07/02 07:40:03 nicm Exp $ */ /* $NetBSD: cu.c,v 1.5 1997/02/11 09:24:05 mrg Exp $ */ /* @@ -148,15 +148,18 @@ getopt: signal(SIGTERM, cleanup); signal(SIGCHLD, SIG_DFL); + vinit(); + /* * The "cu" host name is used to define the * attributes of the generic dialer. */ - (void)snprintf(sbuf, sizeof(sbuf), "cu%d", vgetnum(BAUDRATE)); + snprintf(sbuf, sizeof(sbuf), "cu%d", vgetnum(BAUDRATE)); FD = hunt(sbuf); setbuf(stdout, NULL); + loginit(); - vinit(); + switch (parity) { case -1: setparity("even"); diff --git a/usr.bin/tip/tip.c b/usr.bin/tip/tip.c index e2817c26a6f..de70e2a2ea3 100644 --- a/usr.bin/tip/tip.c +++ b/usr.bin/tip/tip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tip.c,v 1.51 2010/07/02 07:32:16 nicm Exp $ */ +/* $OpenBSD: tip.c,v 1.52 2010/07/02 07:40:03 nicm Exp $ */ /* $NetBSD: tip.c,v 1.13 1997/04/20 00:03:05 mellon Exp $ */ /* @@ -103,10 +103,12 @@ main(int argc, char *argv[]) (void)signal(SIGTERM, cleanup); (void)signal(SIGCHLD, SIG_DFL); + vinit(); + FD = hunt(sys); setbuf(stdout, NULL); + loginit(); - vinit(); /* init variables */ setparity("none"); /* set the parity table */ if (ttysetup(vgetnum(BAUDRATE))) { diff --git a/usr.bin/tip/value.c b/usr.bin/tip/value.c index ae2d1f915d6..82eb2f5b3e4 100644 --- a/usr.bin/tip/value.c +++ b/usr.bin/tip/value.c @@ -1,4 +1,4 @@ -/* $OpenBSD: value.c,v 1.29 2010/07/02 07:09:57 nicm Exp $ */ +/* $OpenBSD: value.c,v 1.30 2010/07/02 07:40:03 nicm Exp $ */ /* $NetBSD: value.c,v 1.6 1997/02/11 09:24:09 mrg Exp $ */ /* @@ -30,12 +30,54 @@ * SUCH DAMAGE. */ +#include <paths.h> + #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 }, +}; + #define MIDDLE 35 static int vlookup(char *); @@ -85,15 +127,13 @@ vsetstr(int value, char *string) if (value == RECORD && string != NULL) string = expand(string); - if (!(vp->v_flags & V_INIT)) - free(vp->v_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; - vp->v_flags &= ~V_INIT; } /* Set a number value. */ @@ -129,15 +169,39 @@ vlookup(char *s) void vinit(void) { - char file[FILENAME_MAX], *cp; - int written; - FILE *fp; + struct passwd *pw; + value_t *vp; + char file[FILENAME_MAX], *cp; + int written; + FILE *fp; /* Read environment variables. */ - if ((cp = getenv("HOME"))) + if ((cp = getenv("HOME")) != NULL) vsetstr(HOME, cp); - if ((cp = getenv("SHELL"))) + 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); + + /* 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 the .tiprc file in the HOME directory. */ written = snprintf(file, sizeof(file), "%s/.tiprc", vgetstr(HOME)); diff --git a/usr.bin/tip/vars.c b/usr.bin/tip/vars.c deleted file mode 100644 index 140ccd40557..00000000000 --- a/usr.bin/tip/vars.c +++ /dev/null @@ -1,115 +0,0 @@ -/* $OpenBSD: vars.c,v 1.18 2010/07/02 07:32:16 nicm Exp $ */ -/* $NetBSD: vars.c,v 1.3 1994/12/08 09:31:19 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" - -#include <paths.h> - -/* - * Definition of variables - */ -value_t vtable[] = { - { "beautify", V_BOOL, - "be", NULL, 1 }, - { "baudrate", V_NUMBER|V_INIT, - "ba", NULL, 0 }, - { "connect", V_STRING|V_INIT|V_READONLY, - "cm", NULL, 0 }, - { "device", V_STRING|V_INIT|V_READONLY, - "dv", NULL, 0 }, - { "eofread", V_STRING|V_INIT, - "eofr", NULL, 0 }, - { "eofwrite", V_STRING|V_INIT, - "eofw", NULL, 0 }, - { "eol", V_STRING|V_INIT, - NULL, NULL, 0 }, - { "escape", V_CHAR, - "es", NULL, '~' }, - { "exceptions", V_STRING|V_INIT, - "ex", NULL, 0 }, - { "force", V_CHAR, - "fo", NULL, CTRL('p') }, - { "framesize", V_NUMBER|V_INIT, - "fr", NULL, 0 }, - { "host", V_STRING|V_INIT|V_READONLY, - "ho", NULL, 0 }, - { "log", V_STRING|V_INIT, - NULL, _PATH_ACULOG, 0 }, - { "prompt", V_CHAR, - "pr", NULL, '\n' }, - { "raise", V_BOOL, - "ra", NULL, 0 }, - { "raisechar", V_CHAR, - "rc", NULL, 0 }, - { "record", V_STRING|V_INIT, - "rec", NULL, 0 }, - { "remote", V_STRING|V_INIT|V_READONLY, - NULL, NULL, 0 }, - { "script", V_BOOL, - "sc", NULL, 0 }, - { "tabexpand", V_BOOL, - "tab", NULL, 0 }, - { "verbose", V_BOOL, - "verb", NULL, 1 }, - { "SHELL", V_STRING|V_INIT, - NULL, _PATH_BSHELL, 0 }, - { "HOME", V_STRING|V_INIT, - NULL, NULL, 0 }, - { "echocheck", V_BOOL, - "ec", NULL, 0 }, - { "disconnect", V_STRING|V_INIT, - "di", NULL, 0 }, - { "tandem", V_BOOL, - "ta", NULL, 1 }, - { "linedelay", V_NUMBER|V_INIT, - "ldelay", NULL, 0 }, - { "chardelay", V_NUMBER|V_INIT, - "cdelay", NULL, 0 }, - { "etimeout", V_NUMBER|V_INIT, - "et", NULL, 0 }, - { "rawftp", V_BOOL, - "raw", NULL, 0 }, - { "halfduplex", V_BOOL, - "hdx", NULL, 0 }, - { "localecho", V_BOOL, - "le", NULL, 0 }, - { "parity", V_STRING|V_INIT, - "par", NULL, 0 }, - { "hardwareflow", V_BOOL, - "hf", NULL, 0 }, - { "linedisc", V_NUMBER|V_INIT, - "ld", NULL, 0 }, - { "direct", V_BOOL, - "dc", NULL, 0 }, - { NULL, 0, - NULL, NULL, 0 } -}; |