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