summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-08-03 08:53:59 +0300
committerSergey Poznyakoff <gray@gnu.org>2021-08-03 09:17:34 +0300
commit6aa56437a4c1368383b86351b8bda489a9fd69a4 (patch)
treefbf37e805b34e5064e67bea0b4b98a731be7cabd
parent0c9f46093c491747dd041cd1db9dcb6ba1570004 (diff)
downloadgdbm-6aa56437a4c1368383b86351b8bda489a9fd69a4.tar.gz
gdbmtool: control the format in which new databases are created
* src/gdbmload.c (_gdbm_str2fmt): New function. * src/proto.h (_gdbm_str2fmt): New proto. * src/gdbmtool.c (open_format): New global variable. (opendb): Add open_format to gdbm_open flags * src/gdbmtool.h (open_format): New extern. * src/var.c: Handle the "format" variable. * doc/gdbm.texi: Document the changes.
-rw-r--r--doc/gdbm.texi75
-rw-r--r--src/gdbmload.c21
-rw-r--r--src/gdbmtool.c7
-rw-r--r--src/gdbmtool.h1
-rw-r--r--src/proto.h3
-rw-r--r--src/var.c14
6 files changed, 82 insertions, 39 deletions
diff --git a/doc/gdbm.texi b/doc/gdbm.texi
index 9878839..d49d604 100644
--- a/doc/gdbm.texi
+++ b/doc/gdbm.texi
@@ -86,10 +86,10 @@ Documentation License.''
@top The GNU database manager
GNU @command{dbm} is a library of functions implementing a hashed database
-on a disk file. This manual documents GNU @command{dbm} Version @value{VERSION}
-(@code{gdbm}). The software was originally written by Philip A.@:
-Nelson. This document was originally written by Pierre Gaumond from
-texts written by Phil.
+on a disk file. This manual documents GNU @command{dbm} Version
+@value{VERSION} (@code{gdbm}). The software was originally written by
+Philip A.@: Nelson. This document was originally written by Pierre
+Gaumond from texts written by Phil.
@end ifnottex
@menu
@@ -142,12 +142,12 @@ Other topics:
@detailmenu
--- The Detailed Node Listing ---
-Compatibility with standard @command{dbm} and @command{ndbm}.
+Compatibility with standard @command{dbm} and @command{ndbm}
* ndbm:: NDBM interface functions.
* dbm:: DBM interface functions.
-Examine and modify a GDBM database.
+Examine and modify a GDBM database
* invocation::
* shell::
@@ -2931,6 +2931,29 @@ such as truncating the existing database.
Default is @code{true}.
@end deftypevr
+@deftypevr {gdbmtool variable} string delim1
+A string used to delimit fields of a structured datum on output
+(@pxref{definitions}).
+
+Default is @samp{,} (a comma). This variable cannot be unset.
+@end deftypevr
+
+@deftypevr {gdbmtool variable} string delim2
+A string used to delimit array items when printing a structured datum
+(@pxref{definitions}).
+
+Default is @samp{,} (a comma). This variable cannot be unset.
+@end deftypevr
+
+@deftypevr {gdbmtool variable} string pager
+The name and command line of the pager program to pipe output to.
+This program is used in interactive mode when the estimated number of
+output lines is greater then the number of lines on your screen.
+
+The default value is inherited from the environment variable
+@env{PAGER}. Unsetting this variable disables paging.
+@end deftypevr
+
@deftypevr {gdbmtool variable} string ps1
Primary prompt string. Its value can contain @dfn{conversion
specifiers}, consisting of the @samp{%} character followed by another
@@ -2959,29 +2982,6 @@ lines of a multi-line command.
The default value is @samp{%_>%_}.
@end deftypevr
-@deftypevr {gdbmtool variable} string delim1
-A string used to delimit fields of a structured datum on output
-(@pxref{definitions}).
-
-Default is @samp{,} (a comma). This variable cannot be unset.
-@end deftypevr
-
-@deftypevr {gdbmtool variable} string delim2
-A string used to delimit array items when printing a structured datum
-(@pxref{definitions}).
-
-Default is @samp{,} (a comma). This variable cannot be unset.
-@end deftypevr
-
-@deftypevr {gdbmtool variable} string pager
-The name and command line of the pager program to pipe output to.
-This program is used in interactive mode when the estimated number of
-output lines is greater then the number of lines on your screen.
-
-The default value is inherited from the environment variable
-@env{PAGER}. Unsetting this variable disables paging.
-@end deftypevr
-
@anchor{quiet}
@deftypevr {gdbmtool variable} bool quiet
Whether to display a welcome banner at startup. To affect
@@ -3001,6 +3001,23 @@ Sets the cache size. @xref{Options, GDBM_SETCACHESIZE}.
By default this variable is not set.
@end deftypevr
+@deftypevr {gdbmtool variable} string format
+Defines the format in which new databases will be created. Allowed
+values are:
+
+@table @samp
+@item standard
+Databases will be created in standard format. This is the format used
+by all @command{GDBM} versions prior to 1.21. This value is the
+default.
+
+@item numsync
+Extended format, best for crash-tolerant applications.
+@xref{Numsync}, for a discussion of this format.
+@end table
+
+@end deftypevr
+
@anchor{openvar}
@deftypevr {gdbmtool variable} string open
Open mode. The following values are allowed:
diff --git a/src/gdbmload.c b/src/gdbmload.c
index 2e376cd..c598528 100644
--- a/src/gdbmload.c
+++ b/src/gdbmload.c
@@ -226,7 +226,7 @@ get_parms (struct dump_file *file)
return ferror (file->fp) ? GDBM_FILE_READ_ERROR : 0;
}
-int
+static int
get_len (const char *param, size_t *plen)
{
unsigned long n;
@@ -247,7 +247,7 @@ get_len (const char *param, size_t *plen)
return GDBM_ILLEGAL_DATA;
}
-int
+static int
read_record (struct dump_file *file, char *param, int n, datum *dat)
{
int rc;
@@ -391,6 +391,16 @@ _set_gdbm_meta_info (GDBM_FILE dbf, char *param, int meta_mask)
}
int
+_gdbm_str2fmt (char const *str)
+{
+ if (strcmp (str, "numsync") == 0)
+ return GDBM_NUMSYNC;
+ if (strcmp (str, "standard") == 0)
+ return 0;
+ return -1;
+}
+
+static int
_gdbm_load_file (struct dump_file *file, GDBM_FILE dbf, GDBM_FILE *ofp,
int replace, int meta_mask)
{
@@ -415,8 +425,9 @@ _gdbm_load_file (struct dump_file *file, GDBM_FILE dbf, GDBM_FILE *ofp,
if ((p = getparm (file->header, "format")) != NULL)
{
- if (strcmp (p, "numsync") == 0)
- format = GDBM_NUMSYNC;
+ int n = _gdbm_str2fmt (p);
+ if (n != -1)
+ format = n;
/* FIXME: other values silently ignored */
}
@@ -555,7 +566,7 @@ xdatum_read (FILE *fp, datum *d, size_t *pdmax)
return c;
}
-int
+static int
gdbm_load_bdb_dump (struct dump_file *file, GDBM_FILE dbf, int replace)
{
datum xd[2];
diff --git a/src/gdbmtool.c b/src/gdbmtool.c
index 839277e..88fc660 100644
--- a/src/gdbmtool.c
+++ b/src/gdbmtool.c
@@ -35,7 +35,7 @@ GDBM_FILE gdbm_file = NULL; /* Database to operate upon */
datum key_data; /* Current key */
datum return_data; /* Current data */
int open_mode; /* Default open mode */
-
+int open_format; /* Default format for the open command */
unsigned input_line;
@@ -56,7 +56,7 @@ opendb (char *dbname)
{
int cache_size = 0;
int block_size = 0;
- int flags = 0;
+ int flags = open_format;
int filemode;
GDBM_FILE db;
@@ -138,8 +138,7 @@ checkdb (void)
if (!file_name)
{
file_name = estrdup (GDBMTOOL_DEFFILE);
- terror (_("warning: using default database file %s"),
- file_name);
+ terror (_("warning: using default database file %s"), file_name);
}
return opendb (file_name);
}
diff --git a/src/gdbmtool.h b/src/gdbmtool.h
index 05b42d7..14245e8 100644
--- a/src/gdbmtool.h
+++ b/src/gdbmtool.h
@@ -109,6 +109,7 @@ char *make_prompt (void);
extern char *file_name;
extern int open_mode;
+extern int open_format;
#define GDBMTOOLRC ".gdbmtoolrc"
#define GDBMTOOL_DEFFILE "junk.gdbm"
diff --git a/src/proto.h b/src/proto.h
index dbe5a22..56e7daa 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -53,6 +53,9 @@ int _gdbm_validate_header (GDBM_FILE dbf);
int _gdbm_file_size (GDBM_FILE dbf, off_t *psize);
+/* From gdbmload.c */
+int _gdbm_str2fmt (char const *str);
+
/* From mmap.c */
int _gdbm_mapped_init (GDBM_FILE);
void _gdbm_mapped_unmap (GDBM_FILE);
diff --git a/src/var.c b/src/var.c
index cb25eb3..869c127 100644
--- a/src/var.c
+++ b/src/var.c
@@ -41,6 +41,7 @@ struct variable
};
static int open_hook (struct variable *, union value *);
+static int format_hook (struct variable *, union value *);
static struct variable vartab[] = {
/* Top-level prompt */
@@ -61,6 +62,7 @@ static struct variable vartab[] = {
{ "coalesce", VART_BOOL, VARF_INIT, { .bool = 0 } },
{ "centfree", VART_BOOL, VARF_INIT, { .bool = 0 } },
{ "filemode", VART_INT, VARF_INIT|VARF_OCTAL|VARF_PROT, { .num = 0644 } },
+ { "format", VART_STRING, VARF_INIT, { .string = "standard" }, format_hook },
{ "pager", VART_STRING, VARF_DFL },
{ "quiet", VART_BOOL, VARF_DFL },
{ NULL }
@@ -94,7 +96,17 @@ open_hook (struct variable *var, union value *v)
return VAR_ERR_BADVALUE;
}
-
+
+static int
+format_hook (struct variable *var, union value *v)
+{
+ int n = _gdbm_str2fmt (v->string);
+ if (n == -1)
+ return VAR_ERR_BADVALUE;
+ open_format = n;
+ return VAR_OK;
+}
+
static struct variable *
varfind (const char *name)
{