]> andersk Git - moira.git/blob - regtape/vote.dc
*** empty log message ***
[moira.git] / regtape / vote.dc
1 /* $Header$
2  */
3
4 #include <stdio.h>
5 #include <strings.h>
6 #include <ctype.h>
7 #include <sys/time.h>
8 #include <moira.h>
9 #include <moira_site.h>
10 EXEC SQL INCLUDE sqlca;
11
12
13 struct entry {
14     char *line;
15     char id[19];
16     char login[9];
17 };
18
19 char *whoami;
20 int debug;
21
22
23 main(argc, argv)
24 int argc;
25 char **argv;
26 {
27     FILE *in;
28     struct entry *e, *get_next_entry();
29     int i, wait = 0;
30     char buf[BUFSIZ], *file = NULL, *p, *p1;
31
32     debug = 0;
33     whoami = rindex(argv[0], '/');
34     if (whoami)
35       whoami++;
36     else
37       whoami = argv[0];
38
39     for (i = 1; i < argc; i++) {
40         if (!strcmp(argv[i], "-w"))
41           wait++;
42         else if (!strcmp(argv[i], "-D"))
43           setenv("ING_SET", "set printqry");
44         else if (!strcmp(argv[i], "-d"))
45           debug = 1;
46         else if (file != NULL)
47           fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
48         else
49           file = argv[i];
50     }
51
52     in = fopen(file, "r");
53     if (in == NULL) {
54         fprintf(stderr, "Unable to open %s for input\n", file);
55         exit(1);
56     }
57
58     setlinebuf(stdout);
59     setlinebuf(stderr);
60
61     EXEC SQL CONNECT moira;
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) {
71             p = &(e->line[0]);
72             for (p1 = e->login; *p1; p1++)
73               *p++ = *p1;
74             for (; p < &(e->line[10]); p++)
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
90 struct entry *get_next_entry(in)
91 FILE *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];
100     strncpy(e.id, &buf[0], 9);
101     e.id[9] = 0;
102     e.login[0] = 0;
103     return(&e);
104 }
105
106
107 process_entry(e)
108 struct entry *e;
109 {
110     EXEC SQL BEGIN DECLARE SECTION;
111     char *id, *login;
112     EXEC SQL END DECLARE SECTION;
113
114     id = e->id;
115     login = e->login;
116     EXEC SQL REPEATED SELECT login INTO :login FROM users
117       WHERE clearid = :id;
118     if (sqlca.sqlcode != 0) {
119         fprintf(stderr, "Error %d on %s\n", sqlca.sqlcode, e->line);
120         return(-1);
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 0.517357 seconds and 5 git commands to generate.