From 50ec57658e82e7d3ea65bd0c606ffbda07e3826a Mon Sep 17 00:00:00 2001 From: lukem Date: Mon, 20 Jun 2005 02:53:38 +0000 Subject: Allow the input [file] field separator to be a string and not just a single character. Use argument-specific value names in the usage string & manual page to simplify searching for the value's use. --- usr.bin/db/db.1 | 57 ++++++++++++++++++++++----------------------- usr.bin/db/db.c | 71 ++++++++++++++++++++++++++++++--------------------------- 2 files changed, 66 insertions(+), 62 deletions(-) (limited to 'usr.bin/db') diff --git a/usr.bin/db/db.1 b/usr.bin/db/db.1 index a44d9ceeea4..d27f3197e3f 100644 --- a/usr.bin/db/db.1 +++ b/usr.bin/db/db.1 @@ -1,6 +1,6 @@ -.\" $NetBSD: db.1,v 1.16 2003/06/26 17:14:13 wiz Exp $ +.\" $NetBSD: db.1,v 1.17 2005/06/20 02:53:38 lukem Exp $ .\" -.\" Copyright (c) 2002 The NetBSD Foundation, Inc. +.\" Copyright (c) 2002-2005 The NetBSD Foundation, Inc. .\" All rights reserved. .\" .\" This code is derived from software contributed to The NetBSD Foundation @@ -34,7 +34,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd May 19, 2003 +.Dd June 20, 2005 .Dt DB 1 .Os . @@ -58,19 +58,19 @@ databases .Op Fl f Ar infile .Ek .Bk -words -.Op Fl O Ar str +.Op Fl O Ar outsep .Ek .Bk -words -.Op Fl S Ar chr +.Op Fl S Ar visitem .Ek .Bk -words -.Op Fl T Ar str +.Op Fl T Ar visspec .Ek .Bk -words -.Op Fl X Ar str +.Op Fl X Ar extravis .Ek .Ar type -.Ar database +.Ar dbfile .Bk -words .Op Ar key Op Ar \&.\&.\&. .Ek @@ -85,10 +85,10 @@ databases .Op Fl f Ar infile .Ek .Bk -words -.Op Fl U Ar chr +.Op Fl U Ar unvisitem .Ek .Ar type -.Ar database +.Ar dbfile .Bk -words .Op Ar key Op Ar \&.\&.\&. .Ek @@ -100,7 +100,7 @@ databases .Op Fl E Ar endian .Ek .Bk -words -.Op Fl F Ar sep +.Op Fl F Ar insep .Ek .Bk -words .Op Fl f Ar infile @@ -109,10 +109,10 @@ databases .Op Fl m Ar mode .Ek .Bk -words -.Op Fl U Ar chr +.Op Fl U Ar unvisitem .Ek .Ar type -.Ar database +.Ar dbfile .Bk -words .Op Ar key Ar value Op Ar \&.\&.\&. .Ek @@ -127,7 +127,8 @@ and databases. .Pp .Nm -has three modes of operation: +has three modes of operation to perform upon +.Ar dbfile : .Bl -tag -width "delete" -offset indent .It read Displays the given @@ -155,7 +156,7 @@ and and keys and values described in .Ar infile (in the latter case, entries are separated by -.Ar sep ) . +.Ar insep ) . .El .Pp There are two mandatory arguments: @@ -165,7 +166,7 @@ is the database type; either or .Sq Sy hash , and -.Ar database +.Ar dbfile is the database file to manipulate. .Pp Options valid for all modes are: @@ -190,7 +191,7 @@ Defaults to .It Fl f Ar infile Contains a list of keys (for read and delete), or -.Ar sep +.Ar insep separated keys and values (for write) to be used as arguments to the given mode. If @@ -225,17 +226,17 @@ Read mode specific options are: .It Fl K Display key. . -.It Fl O Ar str +.It Fl O Ar outsep Field separator string between key and value. Defaults to a single tab .Pq Sq \et . . -.It Fl S Ar chr +.It Fl S Ar visitem Specify items to .Xr strvis 3 encode. The -.Ar chr +.Ar visitem option-argument is a character specifying if the key .Pq Ar k , the value @@ -244,12 +245,12 @@ or both .Pq Ar b should be encoded. . -.It Fl T Ar str +.It Fl T Ar visspec Control how the items specified by the .Fl S option are encoded. The -.Ar str +.Ar visspec option-argument is a string specifying .Xr strvis 3 options. @@ -265,11 +266,11 @@ corresponding options for the meaning of these characters. .It Fl V Display value. . -.It Fl X Ar str +.It Fl X Ar extravis When encoding items with .Fl S option also encode characters in -.Ar str , +.Ar extravis , per .Xr svis 3 . . @@ -296,8 +297,8 @@ Allow duplicate entries. .Fl R to be useful.) . -.It Fl F Ar sep -Field separator between key and value used when parsing +.It Fl F Ar insep +Input field separator string between key and value used when parsing .Ar infile . Defaults to a single space .Pq Sq \ . @@ -316,12 +317,12 @@ If not specified, writing to an existing entry raises an error. Write and delete mode specific options are: .Bl -tag -width Fl -offset indent . -.It Fl U Ar chr +.It Fl U Ar unvisitem Specify items to .Xr strunvis 3 decode. The -.Ar chr +.Ar unvisitem option-argument is a character specifying if the key .Pq Ar k , the value diff --git a/usr.bin/db/db.c b/usr.bin/db/db.c index 0b709d8e544..63e6dfeb5c5 100644 --- a/usr.bin/db/db.c +++ b/usr.bin/db/db.c @@ -1,7 +1,7 @@ -/* $NetBSD: db.c,v 1.13 2004/10/04 10:56:12 lukem Exp $ */ +/* $NetBSD: db.c,v 1.14 2005/06/20 02:53:38 lukem Exp $ */ /*- - * Copyright (c) 2002-2004 The NetBSD Foundation, Inc. + * Copyright (c) 2002-2005 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -39,7 +39,7 @@ #include #ifndef lint #ifdef __RCSID -__RCSID("$NetBSD: db.c,v 1.13 2004/10/04 10:56:12 lukem Exp $"); +__RCSID("$NetBSD: db.c,v 1.14 2005/06/20 02:53:38 lukem Exp $"); #endif /* __RCSID */ #endif /* not lint */ @@ -155,7 +155,7 @@ main(int argc, char *argv[]) break; case 'F': - if (! optarg[0] || optarg[1]) + if (! optarg[0]) errx(1, "Invalid field separator `%s'", optarg); fieldsep = optarg; @@ -525,10 +525,12 @@ parseline(FILE *fp, const char *sep, char **kp, char **vp) *kp = key; if (vp == NULL) /* don't split if don't want value */ return (1); - if ((val = strchr(key, sep[0])) == NULL) + if ((val = strstr(key, sep)) == NULL) val = key + len; - else - *val++ = '\0'; + else { + *val = '\0'; + val += strlen(sep); + } *vp = val; return (1); } @@ -626,35 +628,36 @@ usage(void) const char *p = getprogname(); fprintf(stderr, - "usage: %s [-KiNqV] [-E end] [-f inf] [-O str] [-S chr] [-T str] [-X str]\n" - " type dbfile [key [...]]\n" - " %s -d [-iNq] [-E end] [-f inf] [-U chr] type dbfile [key [...]]\n" - " %s -w [-CDiNqR] [-E end] [-F sep] [-f inf] [-m mod] [-U chr]\n" - " type dbfile [key val [...]]\n" +"usage: %s [-KiNqV] [-E endian] [-f infile] [-O outsep] [-S visitem]\n" +" [-T visspec] [-X extravis] type dbfile [key [...]]\n" +" %s -d [-iNq] [-E endian] [-f infile] [-U unvisitem]\n" +" type dbfile [key [...]]\n" +" %s -w [-CDiNqR] [-E endian] [-F isep] [-f infile] [-m mode]\n" +" [-U unvisitem] type dbfile [key value [...]]\n" ,p ,p ,p ); fprintf(stderr, - "Supported modes:\n" - "\t\tread keys [default]\n" - "\t-d\tdelete keys\n" - "\t-w\twrite (add) keys/values\n" - "Supported options:\n" - "\t-C\tcreate empty (truncated) database\n" - "\t-D\tallow duplicates\n" - "\t-E end\tdatabase endian: `B'ig, `L'ittle, `H'ost [default: H]\n" - "\t-F sep\tfield separator character [default: ' ']\n" - "\t-f inf\tfile of keys (read|delete) or keys/vals (write)\n" - "\t-i\tignore case of key by converting to lower case\n" - "\t-K\tprint key\n" - "\t-m mod\tmode of created database [default: 0644]\n" - "\t-N\tdon't NUL terminate key\n" - "\t-O str\toutput field separator string [default: '\\t']\n" - "\t-q\tquiet operation (missing keys aren't errors)\n" - "\t-R\treplace existing keys\n" - "\t-S chr\titems to strvis(3) encode: 'k'ey, 'v'alue, 'b'oth\n" - "\t-T str\toptions to control -S encoding like vis(1) options\n" - "\t-U chr\titems to strunvis(3) decode: 'k'ey, 'v'alue, 'b'oth\n" - "\t-V\tprint value\n" - "\t-X str\textra characters to encode with -S\n" +"Supported modes:\n" +" read keys [default]\n" +" -d delete keys\n" +" -w write (add) keys/values\n" +"Supported options:\n" +" -C create empty (truncated) database\n" +" -D allow duplicates\n" +" -E endian database endian: `B'ig, `L'ittle, `H'ost [default: H]\n" +" -F isep input field separator string [default: ' ']\n" +" -f infile file of keys (read|delete) or keys/vals (write)\n" +" -i ignore case of key by converting to lower case\n" +" -K print key\n" +" -m mode mode of created database [default: 0644]\n" +" -N don't NUL terminate key\n" +" -O outsep output field separator string [default: '\t']\n" +" -q quiet operation (missing keys aren't errors)\n" +" -R replace existing keys\n" +" -S visitem items to strvis(3) encode: 'k'ey, 'v'alue, 'b'oth\n" +" -T visspec options to control -S encoding like vis(1) options\n" +" -U unvisitem items to strunvis(3) decode: 'k'ey, 'v'alue, 'b'oth\n" +" -V print value\n" +" -X extravis extra characters to encode with -S\n" ); exit(1); } -- cgit