commit ad877efe03cbb52cb7c2ca61ae5a6b042044e651
parent 8aa2c5a89d869bca13c2b6f64132cc59fc0a6f64
Author: rpa <rpa@laika>
Date: Sun, 2 Apr 2023 22:30:54 +0000
wdb/print: a pretty printer
Diffstat:
1 file changed, 25 insertions(+), 9 deletions(-)
diff --git a/src/wdb/print.c b/src/wdb/print.c
@@ -6,31 +6,47 @@
given uuids prints entries for human consumption
*/
-char *wdb;
+char *wdb = nil;
char *data;
Biobuf *bout;
void
usage(void)
{
- fprint(2, "usage: %s uuid [uuid ...]\n", argv0);
+ fprint(2, "usage: %s [-w dir] uuid [uuid ...]\n", argv0);
exits("usage");
}
+int
+fetchval(char *buf, char *uuid, char *field)
+{
+ int n;
+ char *path = smprint("%s/data/%s/%s", wdb, uuid, field);
+ int fd = open(path, OREAD);
+ free(path);
+ if (fd < 0) sysfatal("%r");
+ n = read(fd, buf, 8096);
+ close(fd);
+ return n;
+}
+
void
printuuid(char *uuid)
{
- char path[1024];
- sprint(path, "%s/%s", data, uuid);
-
- Bprint(bout, "%s/\n", path);
-
+ char *buf = malloc(8096);
+ int n = fetchval(buf, uuid, "name");
+ if (n > 0) buf[n - 1] = '\0';
+ Bprint(bout, "%s/\n%s\n", uuid, buf);
+ free(buf);
}
void
main(int argc, char **argv)
{
ARGBEGIN{
+ case 'w':
+ wdb = EARGF(usage());
+ break;
default:
usage();
}ARGEND;
@@ -39,11 +55,11 @@ main(int argc, char **argv)
bout = Bfdopen(1, OWRITE);
- wdb = smprint("/usr/rpa/lib/wdb");
- data = smprint("%s/data", wdb);
+ if (wdb == nil) wdb = smprint("/n/wdb");
int i;
for (i = 0; i < argc; i++) {
+ if (i > 0) Bprint(bout, "----\n");
printuuid(argv[i]);
}
}