]> andersk Git - moira.git/commitdiff
redo genwords as an embedded sql program and have it output in a format
authordanw <danw>
Mon, 29 Nov 1999 22:07:44 +0000 (22:07 +0000)
committerdanw <danw>
Mon, 29 Nov 1999 22:07:44 +0000 (22:07 +0000)
more useful for printing coupons.

reg_svr/Makefile.in
reg_svr/genwords.c [deleted file]
reg_svr/genwords.pc [new file with mode: 0644]

index d8d3e7d1e30c8a5b7fea4f86d0ac5be4b237e46b..49814fa0719fcf04844f73524e0aaa3248bc6c2f 100644 (file)
@@ -32,7 +32,7 @@ START_OBJS=   startreg.o
 GENKEY_OBJS=   genkey.o
 GENWORDS_OBJS= genwords.o words.o
 
-CFILES=                reg_svr.c
+CFILES=                reg_svr.c genwords.c
 
 TARGET=                reg_svr startreg genkey genwords
 
@@ -71,4 +71,4 @@ genkey: $(GENKEY_OBJS)
        $(CC) -o $@ $(LDFLAGS) $(GENKEY_OBJS) $(LIBS)
 
 genwords: $(GENWORDS_OBJS)
-       $(CC) -o $@ $(LDFLAGS) $(GENWORDS_OBJS) $(LIBS)
+       $(CC) -o $@ $(LDFLAGS) $(GENWORDS_OBJS) $(LIBS) $(SQL_LIBS)
diff --git a/reg_svr/genwords.c b/reg_svr/genwords.c
deleted file mode 100644 (file)
index e9f9705..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/* $Id$
- *
- * Utility program to generate magic words for a given ID
- *
- * Copyright (C) 1998 by the Massachusetts Institute of Technology
- * For copying and distribution information, please see the file
- * <mit-copyright.h>.
- *
- */
-
-#include <mit-copyright.h>
-#include <moira.h>
-#include "reg_svr.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-RCSID("$Header$");
-
-int main(int argc, char **argv)
-{
-  char *words[6];
-
-  if (argc != 2)
-    {
-      fprintf(stderr, "Usage: genwords id\n");
-      exit(1);
-    }
-
-  if (!read_hmac_key())
-    {
-      fprintf(stderr, "Couldn't read hmac key\n");
-      exit(1);
-    }
-
-  getwordlist(argv[1], words);
-  printf("%s %s %s %s %s %s\n", words[0], words[1], words[2],
-        words[3], words[4], words[5]);
-}
-
-/* used by words.c */
-void *xmalloc(size_t size)
-{
-  /* we won't run out of memory here */
-  return malloc(size);
-}
diff --git a/reg_svr/genwords.pc b/reg_svr/genwords.pc
new file mode 100644 (file)
index 0000000..75f51a8
--- /dev/null
@@ -0,0 +1,88 @@
+/* $Id$
+ *
+ * Utility program to generate magic words for a given ID
+ *
+ * Copyright (C) 1998 by the Massachusetts Institute of Technology
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
+ *
+ */
+
+#include <mit-copyright.h>
+#include <moira.h>
+#include <moira_schema.h>
+#include "reg_svr.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+EXEC SQL INCLUDE sqlca;
+
+RCSID("$Header$");
+
+int main(int argc, char **argv)
+{
+  char *words[6];
+  int verb;
+
+  if (argc > 1 && !strcmp(argv[1], "-v"))
+    {
+      verb++;
+      argv++;
+      argc--;
+    }
+
+  if (argc != 2)
+    {
+      fprintf(stderr, "Usage: genwords [-v] id\n");
+      exit(1);
+    }
+
+  if (!read_hmac_key())
+    {
+      fprintf(stderr, "Couldn't read hmac key\n");
+      exit(1);
+    }
+
+  getwordlist(argv[1], words);
+  if (verb)
+    {
+      EXEC SQL BEGIN DECLARE SECTION;
+      char first[USERS_FIRST_SIZE], middle[USERS_MIDDLE_SIZE];
+      char last[USERS_LAST_SIZE], *id, *database = "moira";
+      EXEC SQL END DECLARE SECTION;
+
+      EXEC SQL CONNECT :database IDENTIFIED BY :database;
+
+      id = argv[1];
+      EXEC SQL SELECT first, middle, last INTO :first, :middle, :last
+       FROM users WHERE clearid = :id;
+      if (sqlca.sqlcode)
+       {
+         sprintf(first, "%d", sqlca.sqlcode);
+         *middle = *last = '\0';
+       }
+      else
+       {
+         strtrim(first);
+         strtrim(middle);
+         strtrim(last);
+       }
+
+      printf("(%s%s%s %s) (%s) (%s) (%s) (%s) (%s) (%s) (%s)\n",
+            first, *middle ? " " : "", middle, last, id,
+            words[0], words[1], words[2], words[3], words[4], words[5]);
+    }
+  else
+    {
+      printf("%s %s %s %s %s %s\n", words[0], words[1], words[2],
+            words[3], words[4], words[5]);
+    }
+}
+
+/* used by words.c */
+void *xmalloc(size_t size)
+{
+  /* we won't run out of memory here */
+  return malloc(size);
+}
This page took 0.079632 seconds and 5 git commands to generate.