]> andersk Git - moira.git/blame - regtape/vote.pc
support for Lincoln Lab people: load with class LINCOLN and a high uid
[moira.git] / regtape / vote.pc
CommitLineData
2f791b66 1/* $Header$
2 */
3
4#include <stdio.h>
9f5e5c05 5#include <string.h>
2f791b66 6#include <ctype.h>
7#include <sys/time.h>
8#include <moira.h>
9#include <moira_site.h>
10EXEC SQL INCLUDE sqlca;
11
12
13struct entry {
14 char *line;
b7a336e2 15 char id[19];
2f791b66 16 char login[9];
17};
18
19char *whoami;
20int debug;
21
22
23main(argc, argv)
24int argc;
25char **argv;
26{
27 FILE *in;
28 struct entry *e, *get_next_entry();
29 int i, wait = 0;
9f5e5c05 30 char buf[BUFSIZ], *file = NULL, *p, *p1, *db="moira";
2f791b66 31
32 debug = 0;
9f5e5c05 33 whoami = strrchr(argv[0], '/');
2f791b66 34 if (whoami)
35 whoami++;
36 else
37 whoami = argv[0];
38
9f5e5c05 39 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
40 setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
41
2f791b66 42 for (i = 1; i < argc; i++) {
43 if (!strcmp(argv[i], "-w"))
44 wait++;
45 else if (!strcmp(argv[i], "-D"))
46 setenv("ING_SET", "set printqry");
47 else if (!strcmp(argv[i], "-d"))
48 debug = 1;
49 else if (file != NULL)
50 fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
51 else
52 file = argv[i];
53 }
54
55 in = fopen(file, "r");
56 if (in == NULL) {
57 fprintf(stderr, "Unable to open %s for input\n", file);
58 exit(1);
59 }
60
9f5e5c05 61 EXEC SQL CONNECT :db IDENTIFIED BY :db;
2f791b66 62 if (sqlca.sqlcode != 0) {
63 com_err(whoami, 0, "ingres error %d", sqlca.sqlcode);
64 exit(1);
65 }
66
67 while (e = get_next_entry(in)) {
68 i = process_entry(e);
69 EXEC SQL COMMIT WORK;
70 if (i == 0) {
b7a336e2 71 p = &(e->line[0]);
2f791b66 72 for (p1 = e->login; *p1; p1++)
73 *p++ = *p1;
b7a336e2 74 for (; p < &(e->line[10]); p++)
2f791b66 75 *p = ' ';
76 fputs(e->line, stdout);
77 }
78 if (wait) {
79 printf("Next");
80 fflush(stdout);
81 gets(buf);
82 }
83 }
84
85 exit(0);
86}
87
88
89
90struct entry *get_next_entry(in)
91FILE *in;
92{
93 static struct entry e;
94 static char buf[BUFSIZ];
95
96 if (fgets(buf, sizeof(buf), in) == NULL)
97 return((struct entry *)NULL);
98
99 e.line = &buf[0];
b7a336e2 100 strncpy(e.id, &buf[0], 9);
101 e.id[9] = 0;
102 e.login[0] = 0;
2f791b66 103 return(&e);
104}
105
106
107process_entry(e)
108struct entry *e;
109{
2f791b66 110 EXEC SQL BEGIN DECLARE SECTION;
b7a336e2 111 char *id, *login;
9f5e5c05 112 EXEC SQL VAR login is STRING(9);
2f791b66 113 EXEC SQL END DECLARE SECTION;
114
b7a336e2 115 id = e->id;
2f791b66 116 login = e->login;
9f5e5c05 117 EXEC SQL SELECT login INTO :login FROM users WHERE clearid = :id;
2f791b66 118 if (sqlca.sqlcode != 0) {
b7a336e2 119 fprintf(stderr, "Error %d on %s\n", sqlca.sqlcode, e->line);
120 return(-1);
2f791b66 121 }
122 strncpy(e->login, login, 8);
123 e->login[8] = 0;
124 if (debug)
125 printf("Got username %s\n", login);
126 return(0);
127}
This page took 1.285342 seconds and 5 git commands to generate.