changeset 28:fa81221ac9b6

retrieval of required db fields moved into libutil
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 16 Mar 2021 23:37:36 +0000
parents ca8a6f95826a
children aefc9fe653d3
files libutil/dbread.c libutil/dbread.h utils/sws-card-lookup.c
diffstat 3 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libutil/dbread.c	Tue Mar 16 23:22:37 2021 +0000
+++ b/libutil/dbread.c	Tue Mar 16 23:37:36 2021 +0000
@@ -67,6 +67,20 @@
 	return 0;
 }
 
+char *
+dbread_find_key_req(dbs, sought_key)
+	struct dbread_state *dbs;
+	char *sought_key;
+{
+	char *val;
+
+	val = dbread_find_key(dbs, sought_key);
+	if (val)
+		return val;
+	fprintf(stderr, "error: card record has no %s field\n", sought_key);
+	return 0;
+}
+
 dbread_find_record(filename, dbs, sought_key, sought_value)
 	char *filename, *sought_key, *sought_value;
 	struct dbread_state *dbs;
--- a/libutil/dbread.h	Tue Mar 16 23:22:37 2021 +0000
+++ b/libutil/dbread.h	Tue Mar 16 23:37:36 2021 +0000
@@ -18,3 +18,4 @@
 };
 
 extern char *dbread_find_key();
+extern char *dbread_find_key_req();
--- a/utils/sws-card-lookup.c	Tue Mar 16 23:22:37 2021 +0000
+++ b/utils/sws-card-lookup.c	Tue Mar 16 23:37:36 2021 +0000
@@ -48,11 +48,9 @@
 {
 	char *val;
 
-	val = dbread_find_key(&dbs, key);
-	if (!val) {
-		fprintf(stderr, "error: card record has no %s field\n", key);
-		exit(1);
-	}
+	val = dbread_find_key_req(&dbs, key);
+	if (!val)
+		exit(1);	/* error msg already printed */
 	puts(val);
 }