3 * Copyright (C) 1993-1998 by the Massachusetts Institute of Technology
4 * For copying and distribution information, please see the file
8 #include <mit-copyright.h>
10 #include <moira_site.h>
16 EXEC SQL INCLUDE sqlca;
29 struct entry *get_next_entry(FILE *in);
30 int process_entry(struct entry *e);
32 int main(int argc, char **argv)
37 char buf[BUFSIZ], *file = NULL, *p, *p1, *db = "moira";
40 whoami = strrchr(argv[0], '/');
46 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
47 setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
49 for (i = 1; i < argc; i++)
51 if (!strcmp(argv[i], "-w"))
53 else if (!strcmp(argv[i], "-d"))
56 fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
61 in = fopen(file, "r");
64 fprintf(stderr, "Unable to open %s for input\n", file);
68 EXEC SQL CONNECT :db IDENTIFIED BY :db;
71 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
75 while ((e = get_next_entry(in)))
82 for (p1 = e->login; *p1; p1++)
84 for (; p < &(e->line[10]); p++)
86 fputs(e->line, stdout);
99 struct entry *get_next_entry(FILE *in)
101 static struct entry e;
102 static char buf[BUFSIZ];
104 if (!fgets(buf, sizeof(buf), in))
108 strncpy(e.id, &buf[0], 9);
114 int process_entry(struct entry *e)
116 EXEC SQL BEGIN DECLARE SECTION;
118 EXEC SQL VAR login is STRING(9);
119 EXEC SQL END DECLARE SECTION;
123 EXEC SQL SELECT login INTO :login FROM users WHERE clearid = :id;
126 fprintf(stderr, "Error %ld on %s\n", sqlca.sqlcode, e->line);
129 strncpy(e->login, login, 8);
132 printf("Got username %s\n", login);