summaryrefslogtreecommitdiffabout
path: root/src/var.c
authorSergey Poznyakoff <gray@gnu.org.ua>2013-05-16 15:32:45 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-05-16 15:32:45 (GMT)
commit979486e1b46a894fc9de2abe6eb8985536a5013c (patch) (side-by-side diff)
treee9e61bcfd9d1945c612a54e080d4fdc2e87cbad5 /src/var.c
parente5fccca3abee9093f4d1e50823addca8e6c778a6 (diff)
downloadgdbm-979486e1b46a894fc9de2abe6eb8985536a5013c.tar.gz
gdbm-979486e1b46a894fc9de2abe6eb8985536a5013c.tar.bz2
Improve handling of the variables.
* src/gdbmtool.c (opendb): Allow for unset variables. * src/gram.y: Improve error detection. * src/lex.l: Handle multiline strings. (pe_file_name): file_name can be NULL. * src/var.c (VARF_PROT): New flag. Protects the variable from being unset. (vartab): Use VARF_PROT if needed. (s2b): Fix return values. (variable_set, variable_unset): Return error if attempting to unset a variable marked with VARF_PROT. * doc/gdbm.info: Update. * doc/gdbmtool.1: Update.
Diffstat (limited to 'src/var.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/var.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/var.c b/src/var.c
index 20db896..54122eb 100644
--- a/src/var.c
+++ b/src/var.c
@@ -20,6 +20,7 @@
#define VARF_DFL 0x00
#define VARF_SET 0x01
#define VARF_INIT 0x02
+#define VARF_PROT 0x04
#define VAR_IS_SET(v) ((v)->flags & (VARF_SET|VARF_INIT))
@@ -48,12 +49,12 @@ static struct variable vartab[] = {
/* Second-level prompt (used within "def" block) */
{ "ps2", VART_STRING, VARF_INIT, { "%_>%_" } },
/* This delimits array members */
- { "delim1", VART_STRING, VARF_INIT, { "," } },
+ { "delim1", VART_STRING, VARF_INIT|VARF_PROT, { "," } },
/* This delimits structure members */
- { "delim2", VART_STRING, VARF_INIT, { "," } },
+ { "delim2", VART_STRING, VARF_INIT|VARF_PROT, { "," } },
{ "confirm", VART_BOOL, VARF_INIT, { num: 1 } },
- { "cachesize", VART_INT, VARF_INIT, { num: DEFAULT_CACHESIZE } },
- { "blocksize", VART_INT, VARF_DFL, { num: 0 } },
+ { "cachesize", VART_INT, VARF_DFL },
+ { "blocksize", VART_INT, VARF_DFL },
{ "open", VART_STRING, VARF_DFL, { NULL }, open_hook },
{ "lock", VART_BOOL, VARF_INIT, { num: 1 } },
{ "mmap", VART_BOOL, VARF_INIT, { num: 1 } },
@@ -142,14 +143,14 @@ s2b (union value *vp, void *val)
if (strcasecmp (trueval[i], val) == 0)
{
vp->bool = 1;
- return 0;
+ return VAR_OK;
}
for (i = 0; falseval[i]; i++)
if (strcasecmp (falseval[i], val) == 0)
{
vp->bool = 0;
- return 1;
+ return VAR_OK;
}
n = strtoul (val, &p, 0);
@@ -226,12 +227,16 @@ variable_set (const char *name, int type, void *val)
valp = &v;
}
else
- valp = NULL;
+ {
+ if (vp->flags & VARF_PROT)
+ return VAR_ERR_BADVALUE;
+ valp = NULL;
+ }
if (vp->hook && (rc = vp->hook (vp, valp)) != VAR_OK)
return rc;
-
- if (vp->type == VART_STRING && (vp->flags && VARF_SET))
+
+ if (vp->type == VART_STRING && (vp->flags & VARF_SET))
free (vp->v.string);
if (!val)
@@ -256,6 +261,8 @@ variable_unset (const char *name)
if (!vp)
return VAR_ERR_NOTDEF;
+ if (vp->flags & VARF_PROT)
+ return VAR_ERR_BADVALUE;
if (vp->hook && (rc = vp->hook (vp, NULL)) != VAR_OK)
return rc;

Return to:

Send suggestions and report system problems to the System administrator.