diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-07-01 21:43:39 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-07-01 21:43:39 +0000 |
commit | 8cf53416dff722534d24f784783624d7f704c9d7 (patch) | |
tree | 8f155f2cb22818f811a2777061b71922b473b757 /usr.bin/tip | |
parent | e067fed9184d6feaf132b97c38a0a8f0b65052b2 (diff) |
Split v_value into v_string/v_number, change macros to functions and lo let
there be type checking.
Diffstat (limited to 'usr.bin/tip')
-rw-r--r-- | usr.bin/tip/cmds.c | 12 | ||||
-rw-r--r-- | usr.bin/tip/tip.h | 22 | ||||
-rw-r--r-- | usr.bin/tip/value.c | 68 | ||||
-rw-r--r-- | usr.bin/tip/vars.c | 76 |
4 files changed, 102 insertions, 76 deletions
diff --git a/usr.bin/tip/cmds.c b/usr.bin/tip/cmds.c index a339b6461bc..509aab22514 100644 --- a/usr.bin/tip/cmds.c +++ b/usr.bin/tip/cmds.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmds.c,v 1.40 2010/07/01 21:28:01 nicm Exp $ */ +/* $OpenBSD: cmds.c,v 1.41 2010/07/01 21:43:38 nicm Exp $ */ /* $NetBSD: cmds.c,v 1.7 1997/02/11 09:24:03 mrg Exp $ */ /* @@ -800,8 +800,8 @@ listvariables(int c) fputs(p->v_name, stdout); switch (p->v_flags & V_TYPEMASK) { case V_STRING: - if (p->v_value) { - strnvis(buf, p->v_value, sizeof(buf), + if (p->v_string) { + strnvis(buf, p->v_string, sizeof(buf), VIS_WHITE|VIS_OCTAL); printf(" %s", buf); } @@ -809,13 +809,13 @@ listvariables(int c) putchar('\n'); break; case V_NUMBER: - printf(" %ld\r\n", (long)p->v_value); + printf(" %d\r\n", p->v_number); break; case V_BOOL: - printf(" %s\r\n", p->v_value ? "true" : "false"); + printf(" %s\r\n", p->v_number ? "true" : "false"); break; case V_CHAR: - vis(buf, (int)(long)p->v_value, VIS_WHITE|VIS_OCTAL, 0); + vis(buf, p->v_number, VIS_WHITE|VIS_OCTAL, 0); printf(" %s\r\n", buf); break; } diff --git a/usr.bin/tip/tip.h b/usr.bin/tip/tip.h index af7e45bfcd5..4645d5c4442 100644 --- a/usr.bin/tip/tip.h +++ b/usr.bin/tip/tip.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tip.h,v 1.48 2010/07/01 21:28:01 nicm Exp $ */ +/* $OpenBSD: tip.h,v 1.49 2010/07/01 21:43:38 nicm Exp $ */ /* $NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $ */ /* @@ -61,8 +61,10 @@ typedef struct { char *v_name; /* variable name */ int v_flags; /* type and flags */ char *v_abbrev; /* possible abbreviation */ - char *v_value; /* casted to a union later */ -} value_t; + + char *v_string; + int v_number; +} value_t; extern value_t vtable[]; /* variable table */ #define V_STRING 01 /* string valued */ @@ -75,16 +77,6 @@ extern value_t vtable[]; /* variable table */ #define V_READONLY 040 /* variable is not writable */ #define V_INIT 0100 /* static data space used for initialization */ -#define vgetstr(v) (vtable[v].v_value) -#define vgetnum(v) ((long)(vtable[v].v_value)) - -#define vsetstr(v, s) do { \ - vtable[v].v_value = s; \ - } while (0) -#define vsetnum(v, n) do { \ - vtable[v].v_value = (char *)(long)(n); \ - } while (0) - /* Variable table indexes. */ enum { BEAUTIFY = 0, @@ -232,3 +224,7 @@ void tipout(void); void vinit(void); void vlex(char *); int vstring(char *, char *); +char *vgetstr(int); +int vgetnum(int); +void vsetstr(int, char *); +void vsetnum(int, int); diff --git a/usr.bin/tip/value.c b/usr.bin/tip/value.c index 75b6737f411..b0dc7995d52 100644 --- a/usr.bin/tip/value.c +++ b/usr.bin/tip/value.c @@ -1,4 +1,4 @@ -/* $OpenBSD: value.c,v 1.25 2010/07/01 21:28:01 nicm Exp $ */ +/* $OpenBSD: value.c,v 1.26 2010/07/01 21:43:38 nicm Exp $ */ /* $NetBSD: value.c,v 1.6 1997/02/11 09:24:09 mrg Exp $ */ /* @@ -32,6 +32,10 @@ #include "tip.h" +/* + * Variable manipulation. + */ + #define MIDDLE 35 static value_t *vlookup(char *); @@ -42,9 +46,34 @@ static char *vinterp(char *, int); static size_t col = 0; -/* - * Variable manipulation - */ +/* Get a string value. */ +char * +vgetstr(int value) +{ + return (vtable[value].v_string); +} + +/* Get a number value. */ +int +vgetnum(int value) +{ + return (vtable[value].v_number); +} + +/* Set a string value. */ +void +vsetstr(int value, char *string) +{ + vtable[value].v_string = string; +} + +/* Set a number value. */ +void +vsetnum(int value, int number) +{ + vtable[value].v_number = number; +} + void vinit(void) { @@ -90,30 +119,31 @@ vassign(value_t *p, char *v) switch (p->v_flags & V_TYPEMASK) { case V_STRING: - if (p->v_value && strcmp(p->v_value, v) == 0) + if (p->v_string && strcmp(p->v_string, v) == 0) return; if (!(p->v_flags & V_INIT)) - free(p->v_value); - if ((p->v_value = strdup(v)) == NULL) { + free(p->v_string); + if ((p->v_string = strdup(v)) == NULL) { printf("out of core\r\n"); return; } p->v_flags &= ~V_INIT; break; case V_NUMBER: - if (p->v_value == v) + if (p->v_number == (int)(long)v) return; - p->v_value = v; + p->v_number = (int)(long)v; break; case V_BOOL: - if ((long)p->v_value == (*v != '!')) + if (p->v_number == (*v != '!')) return; - p->v_value = (char *)(long)(*v != '!'); + p->v_number = (*v != '!'); break; case V_CHAR: - if ((char)(long)p->v_value == *v) + if (p->v_number == *v) return; - p->v_value = (char *)(long)*v; + p->v_number = *v; + break; } p->v_flags |= V_CHANGED; } @@ -191,7 +221,7 @@ vprint(value_t *p) switch (p->v_flags & V_TYPEMASK) { case V_BOOL: - if (!p->v_value) { + if (!p->v_number) { col++; putchar('!'); } @@ -201,8 +231,8 @@ vprint(value_t *p) case V_STRING: printf("%s=", p->v_name); col++; - if (p->v_value) { - cp = interp(p->v_value); + if (p->v_string) { + cp = interp(p->v_string); col += size(cp); printf("%s", cp); } @@ -210,14 +240,14 @@ vprint(value_t *p) case V_NUMBER: col += 6; - printf("%s=%-5ld", p->v_name, (long)p->v_value); + printf("%s=%-5d", p->v_name, p->v_number); break; case V_CHAR: printf("%s=", p->v_name); col++; - if (p->v_value) { - cp = ctrl((char)(long)p->v_value); + if (p->v_number) { + cp = ctrl(p->v_number); col += size(cp); printf("%s", cp); } diff --git a/usr.bin/tip/vars.c b/usr.bin/tip/vars.c index ba572b6ae30..4020d51517d 100644 --- a/usr.bin/tip/vars.c +++ b/usr.bin/tip/vars.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vars.c,v 1.16 2010/06/30 00:26:49 nicm Exp $ */ +/* $OpenBSD: vars.c,v 1.17 2010/07/01 21:43:38 nicm Exp $ */ /* $NetBSD: vars.c,v 1.3 1994/12/08 09:31:19 jtc Exp $ */ /* @@ -38,77 +38,77 @@ */ value_t vtable[] = { { "beautify", V_BOOL, - "be", (char *)1 }, + "be", NULL, 1 }, { "baudrate", V_NUMBER|V_INIT, - "ba", 0 }, + "ba", NULL, 0 }, { "connect", V_STRING|V_INIT|V_READONLY, - "cm", 0 }, + "cm", NULL, 0 }, { "device", V_STRING|V_INIT|V_READONLY, - "dv", 0 }, + "dv", NULL, 0 }, { "eofread", V_STRING|V_INIT, - "eofr", 0 }, + "eofr", NULL, 0 }, { "eofwrite", V_STRING|V_INIT, - "eofw", 0 }, + "eofw", NULL, 0 }, { "eol", V_STRING|V_INIT, - NULL, 0 }, + NULL, NULL, 0 }, { "escape", V_CHAR, - "es", (char *)'~' }, + "es", NULL, '~' }, { "exceptions", V_STRING|V_INIT, - "ex", 0 }, + "ex", NULL, 0 }, { "force", V_CHAR, - "fo", (char *)CTRL('p') }, + "fo", NULL, CTRL('p') }, { "framesize", V_NUMBER|V_INIT, - "fr", 0 }, + "fr", NULL, 0 }, { "host", V_STRING|V_INIT|V_READONLY, - "ho", 0 }, + "ho", NULL, 0 }, { "log", V_STRING|V_INIT, - NULL, _PATH_ACULOG }, + NULL, _PATH_ACULOG, 0 }, { "prompt", V_CHAR, - "pr", (char *)'\n' }, + "pr", NULL, '\n' }, { "raise", V_BOOL, - "ra", (char *)0 }, + "ra", NULL, 0 }, { "raisechar", V_CHAR, - "rc", NULL }, + "rc", NULL, 0 }, { "record", V_STRING|V_INIT, - "rec", 0 }, + "rec", NULL, 0 }, { "remote", V_STRING|V_INIT|V_READONLY, - NULL, 0 }, + NULL, NULL, 0 }, { "script", V_BOOL, - "sc", (char *)0 }, + "sc", NULL, 0 }, { "tabexpand", V_BOOL, - "tab", (char *)0 }, + "tab", NULL, 0 }, { "verbose", V_BOOL, - "verb", (char *)1 }, + "verb", NULL, 1 }, { "SHELL", V_STRING|V_INIT, - NULL, _PATH_BSHELL }, + NULL, _PATH_BSHELL, 0 }, { "HOME", V_STRING|V_INIT, - NULL, NULL }, + NULL, NULL, 0 }, { "echocheck", V_BOOL, - "ec", (char *)0 }, + "ec", NULL, 0 }, { "disconnect", V_STRING|V_INIT, - "di", 0 }, + "di", NULL, 0 }, { "tandem", V_BOOL, - "ta", (char *)1 }, + "ta", NULL, 1 }, { "linedelay", V_NUMBER|V_INIT, - "ldelay", 0 }, + "ldelay", NULL, 0 }, { "chardelay", V_NUMBER|V_INIT, - "cdelay", 0 }, + "cdelay", NULL, 0 }, { "etimeout", V_NUMBER|V_INIT, - "et", 0 }, + "et", NULL, 0 }, { "rawftp", V_BOOL, - "raw", (char *)0 }, + "raw", NULL, 0 }, { "halfduplex", V_BOOL, - "hdx", (char *)0 }, + "hdx", NULL, 0 }, { "localecho", V_BOOL, - "le", (char *)0 }, + "le", NULL, 0 }, { "parity", V_STRING|V_INIT, - "par", 0 }, + "par", NULL, 0 }, { "hardwareflow", V_BOOL, - "hf", (char *)0 }, + "hf", NULL, 0 }, { "linedisc", V_NUMBER|V_INIT, - "ld", 0 }, + "ld", NULL, 0 }, { "direct", V_BOOL, - "dc", (char *)0 }, + "dc", NULL, 0 }, { NULL, 0, - NULL, NULL } + NULL, NULL, 0 } }; |