Use quotefmtinstall(); and %q when printing values in ndb/query and ndb/ipquery. Added quote parsing in libndb allowing strings quoted with " or ' and embedded "" or '' inserts a single " or ' in the usual style; double quotes don't feel like the plan9 way, but I kept support for backward compatability. This useful for txt='' and hinfo='' strings. -Steve Reference: /n/sources/patch/maybe/ndb-quotefmt Date: Fri Jan 22 13:35:32 CET 2010 Signed-off-by: steve@quintile.net --- /sys/src/cmd/ndb/ipquery.c Fri Jan 22 13:19:29 2010 +++ /sys/src/cmd/ndb/ipquery.c Fri Jan 22 13:19:27 2010 @@ -22,7 +22,7 @@ tt = ndbipinfo(db, attr, val, rattr, nrattr); for(t = tt; t; t = t->entry) - print("%s=%s ", t->attr, t->val); + print("%s=%q ", t->attr, t->val); print("\n"); ndbfree(tt); } @@ -42,6 +42,7 @@ if(argc < 3) usage(); + quotefmtinstall(); db = ndbopen(dbfile); if(db == 0){ fprint(2, "no db files\n"); --- /sys/src/cmd/ndb/query.c Fri Jan 22 13:19:33 2010 +++ /sys/src/cmd/ndb/query.c Fri Jan 22 13:19:31 2010 @@ -58,7 +58,7 @@ /* all entries */ for(t = ndbsearch(db, &s, attr, val); t; t = ndbsnext(&s, attr, val)){ for(nt = t; nt; nt = nt->entry) - Bprint(&bout, "%s=%s ", nt->attr, nt->val); + Bprint(&bout, "%s=%q ", nt->attr, nt->val); Bprint(&bout, "\n"); ndbfree(t); } @@ -99,6 +99,7 @@ usage(); } + quotefmtinstall(); if(Binit(&bout, 1, OWRITE) == -1) sysfatal("Binit: %r"); db = ndbopen(dbfile); --- /sys/src/libndb/ndbaux.c Fri Jan 22 13:19:36 2010 +++ /sys/src/libndb/ndbaux.c Fri Jan 22 13:19:34 2010 @@ -5,6 +5,31 @@ #include #include "ndbhf.h" +/* + * strip quotes, deals with adjacent quotes + * implies a single quote. + * beware: modifies the source string + */ +static int +unquote(char **buf) +{ + char q, *base, *w, *r; + + base = *buf; + q = *base++; + r = w = base; + while(*r && *r != '\n'){ + if(r[0] == q) + if(r[1] == q) + r++; + else + break; + *w++ = *r++; + } + *buf = r; + return w - base; +} + /* * parse a single tuple @@ -38,13 +63,9 @@ EATWHITE(cp); if(*cp == '='){ cp++; - if(*cp == '"'){ - p = ++cp; - while(*cp != '\n' && *cp != '"') - cp++; - len = cp - p; - if(*cp == '"') - cp++; + if(*cp == '"' || *cp == '\''){ + p = cp+1; + len = unquote(&cp); } else if(*cp == '#'){ len = 0; } else {