summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2010-07-02 05:56:29 +0000
committernicm <nicm@openbsd.org>2010-07-02 05:56:29 +0000
commit1f72b5780f03ed48c193ef398c5ed1e787eb7b53 (patch)
treee9d73c1accfd02ed0ffca0b8421c230ec58a5537
parentRewrite hunt() to put the "rotary action" into it rather than remote.c, and so (diff)
downloadwireguard-openbsd-1f72b5780f03ed48c193ef398c5ed1e787eb7b53.tar.xz
wireguard-openbsd-1f72b5780f03ed48c193ef398c5ed1e787eb7b53.zip
Bye-bye vstring, and add value type checking code to vgetstr/vsetstr/etc.
-rw-r--r--usr.bin/tip/remote.c10
-rw-r--r--usr.bin/tip/tip.h3
-rw-r--r--usr.bin/tip/value.c68
3 files changed, 48 insertions, 33 deletions
diff --git a/usr.bin/tip/remote.c b/usr.bin/tip/remote.c
index c54987f9f6b..e4c7d519462 100644
--- a/usr.bin/tip/remote.c
+++ b/usr.bin/tip/remote.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: remote.c,v 1.29 2010/07/02 05:52:48 nicm Exp $ */
+/* $OpenBSD: remote.c,v 1.30 2010/07/02 05:56:29 nicm Exp $ */
/* $NetBSD: remote.c,v 1.5 1997/04/20 00:02:45 mellon Exp $ */
/*
@@ -119,13 +119,13 @@ getremote(char *host)
vsetstr(PARITY, strval);
if (cgetstr(bp, "es", &strval) >= 0 && strval != NULL)
- vstring("es", strval);
+ vsetstr(ESCAPE, strval);
if (cgetstr(bp, "fo", &strval) >= 0 && strval != NULL)
- vstring("fo", strval);
+ vsetstr(FORCE, strval);
if (cgetstr(bp, "pr", &strval) >= 0 && strval != NULL)
- vstring("pr", strval);
+ vsetstr(PROMPT, strval);
if (cgetstr(bp, "rc", &strval) >= 0 && strval != NULL)
- vstring("rc", strval);
+ vsetstr(RECORD, strval);
if (!vgetnum(BAUDRATE)) {
if (cgetnum(bp, "br", &val) == -1)
diff --git a/usr.bin/tip/tip.h b/usr.bin/tip/tip.h
index 6a01ca642ac..d2ef1cddf6b 100644
--- a/usr.bin/tip/tip.h
+++ b/usr.bin/tip/tip.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tip.h,v 1.50 2010/07/02 05:52:48 nicm Exp $ */
+/* $OpenBSD: tip.h,v 1.51 2010/07/02 05:56:29 nicm Exp $ */
/* $NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $ */
/*
@@ -223,7 +223,6 @@ void tipout(void);
/* value.c */
void vinit(void);
void vlex(char *);
-int vstring(char *, char *);
char *vgetstr(int);
int vgetnum(int);
void vsetstr(int, char *);
diff --git a/usr.bin/tip/value.c b/usr.bin/tip/value.c
index deb2479c374..7516b4482ae 100644
--- a/usr.bin/tip/value.c
+++ b/usr.bin/tip/value.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: value.c,v 1.27 2010/07/01 21:47:09 nicm Exp $ */
+/* $OpenBSD: value.c,v 1.28 2010/07/02 05:56:29 nicm Exp $ */
/* $NetBSD: value.c,v 1.6 1997/02/11 09:24:09 mrg Exp $ */
/*
@@ -50,28 +50,65 @@ static size_t col = 0;
char *
vgetstr(int value)
{
- return (vtable[value].v_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);
+ return (vp->v_string);
}
/* Get a number value. */
int
vgetnum(int value)
{
- return (vtable[value].v_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);
+ return (vp->v_number);
}
/* Set a string value. */
void
vsetstr(int value, char *string)
{
- vtable[value].v_string = 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);
+
+ if (!(vp->v_flags & V_INIT))
+ 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. */
void
vsetnum(int value, int number)
{
- vtable[value].v_number = 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;
}
void
@@ -324,24 +361,3 @@ vinterp(char *s, int stop)
*p = '\0';
return (c == stop ? s-1 : NULL);
}
-
-/*
- * assign variable s with value v (for NUMBER or STRING or CHAR types)
- */
-int
-vstring(char *s, char *v)
-{
- value_t *p;
-
- p = vlookup(s);
- if (p == 0)
- return (1);
- if ((p->v_flags & V_TYPEMASK) == V_NUMBER)
- vassign(p, (char *)(long)atoi(v));
- else {
- if (strcmp(s, "record") == 0)
- v = expand(v);
- vassign(p, v);
- }
- return (0);
-}