]> andersk Git - moira.git/blame - regtape/nodups.qc
put in better error checking and commit's between actions
[moira.git] / regtape / nodups.qc
CommitLineData
834f8184 1/* $Header$ */
2
3#include <stdio.h>
4#include <ctype.h>
5#include <moira.h>
6
7struct user {
8 int users_id;
9 char first[33];
10 char last[33];
11 int status;
12};
13
14extern int errno;
15int debug;
16char *program;
17
18
19main(argc, argv)
20int argc;
21char **argv;
22{
23 char buf[1024], first[33], last[33];
24 int i;
25 char *inputfile;
26 FILE *in;
27 struct user *u;
28 struct user users[32];
29 struct user *get_user();
30
31 program = argv[0];
32
33 for (i = 1; i < argc; i++) {
34 if (!strcmp(argv[i], "-d"))
35 debug++;
36 else if (!strcmp(argv[i], "-D"))
37 setenv("ING_SET", "set printqry");
38 else if (argv[i][0] == '-')
39 usage(argv);
40 else if (inputfile != NULL)
41 usage(argv);
42 else inputfile = argv[i];
43 }
44
45 if (inputfile) {
46 in = fopen(inputfile, "r");
47 if (in == NULL) {
48 com_err(program, errno, "opening file \"%s\" for input", inputfile);
49 exit(1);
50 }
51 } else
52 in = stdin;
53
54## ingres sms
55
56 i = 0;
57 while (!feof(in)) {
58 fgets(buf, sizeof(buf), in);
59 u = get_user(buf);
60 if (!u) continue;
61 if (strcmp(u->last, users[0].last) ||
62 strcmp(u->first, users[0].first)) {
63 /* We've got a matching group! */
64 process_users(users, i);
65 bcopy(u, &(users[0]), sizeof(*u));
66 i = 1;
67 } else {
68 bcopy(u, &(users[i]), sizeof(*u));
69 i++;
70 }
71 }
72}
73
74usage(argv)
75char **argv;
76{
77 fprintf(stderr, "Usage: %s [-w] [-D]\n", argv[0]);
78 exit(1);
79}
80
81struct user *get_user(buf)
82char *buf;
83{
84 static struct user u;
85
86 if (sscanf(buf, "| %d|%s |%s | %d|", &u.users_id, u.first,
87 u.last, &u.status) != 4) {
88 com_err(program, 0, " parsing input line %s", buf);
89 return(NULL);
90 }
91 return(&u);
92}
93
94
95process_users(users, count)
96struct user users[];
97int count;
98##{
99 char buf[256];
100 int i;
101## char login[9], id[17], class[9], modtime[26], modwith[9], xmodtime[26];
102## char login2[9], id2[17], class2[9], modtime2[26],modwith2[9],xmodtime2[26];
103## char login3[9], id3[17], class3[9], modtime3[26],modwith3[9],xmodtime3[26];
104## int users_id, users_id2, users_id3, status, status2, status3, rowcount;
105
106 printf("\nGot %d users named %s %s\n", count, users[0].first, users[0].last);
107 if (count < 2) return;
108
109 users_id = users[0].users_id;
110## range of u is users
111## retrieve (login = u.#login, id = u.mit_id, class = u.mit_year,
112## modtime = u.#modtime, modwith = u.#modwith,
113## xmodtime = u.#xmodtime, status = u.#status)
114## where u.#users_id = users_id
115
116 users_id2 = users[1].users_id;
117## retrieve (login2 = u.#login, id2 = u.mit_id, class2 = u.mit_year,
118## modtime2 = u.#modtime, modwith2 = u.#modwith,
119## xmodtime2 = u.#xmodtime, status2 = u.#status)
120## where u.#users_id = users_id2
121
122 modtime[20] = modtime2[20] = xmodtime[20] = xmodtime2[20] = 0;
123
124 printf("A: %s %5d %d\t\t\tB: %s %5d %d\n", login, users_id, status,
125 login2, users_id2, status2);
126 printf(" %s %s\t\t %s %s\n", class, id, class2, id2);
127 printf(" %s %s\t %s %s\n", modtime, modwith, modtime2, modwith2);
128 printf(" %s\t\t\t %s\n", xmodtime, xmodtime2);
129
130 if (count > 2) {
131 for (i = 2; i < count; i++) {
132 users_id3 = users[i].users_id;
133## retrieve (login3 = u.#login, id3 = u.mit_id, class3 = u.mit_year,
134## modtime3 = u.#modtime, modwith3 = u.#modwith,
135## xmodtime3 = u.#xmodtime, status3 = u.#status)
136## where u.#users_id = users_id3
137 modtime3[20] = xmodtime3[20] = 0;
138 printf("\n%c: %s %5d %d\n", 'A' + i,
139 login3, users_id3, status3);
140 printf(" %s %s\n", class3, id3);
141 printf(" %s %s\n", modtime3, modwith3);
142 printf(" %s\n", xmodtime3);
143 }
144 }
145
146 if (count == 2) {
147 if (status == 3 || status2 == 3) return;
148 if ((status == 0 || status == 4) &&
149 !isdigit(id[0]) && !isdigit(xmodtime[0])) {
150 printf("DELETING %s\n", login);
151## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
152## modby=8873) where u.#users_id = users_id
153## inquire_equel(rowcount = "rowcount")
154 if (rowcount != 1)
155 printf("Failed!\007\007\007\n");
156 else
157 printf("User %s marked for deletion.\n", login);
158 return;
159 }
160 if ((status2 == 0 || status2 == 4) &&
161 !isdigit(id2[0]) && !isdigit(xmodtime2[0])) {
162 printf("DELETING %s\n", login2);
163## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
164## modby=8873) where u.#users_id = users_id2
165## inquire_equel(rowcount = "rowcount")
166 if (rowcount != 1)
167 printf("Failed!\007\007\007\n");
168 else
169 printf("User %s marked for deletion.\n", login2);
170 return;
171 }
172 }
173
174 printf("\n0,sp: Do nothing\n1: Delete B\n2: Delete A\n");
175 printf("3: A<-B's ID; Delete B\n4: B<-A's ID; Delete A\n");
176 if (count > 2)
177 printf("5: Delete C\n");
178 if (count > 3)
179 printf("6: Delete D\n");
180 printf("?");fflush(stdout);
181 gets(buf);
182 switch (buf[0]) {
183 case '1':
184## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
185## modby=8873) where u.#users_id = users_id2
186## inquire_equel(rowcount = "rowcount")
187 if (rowcount != 1)
188 printf("Failed!\007\007\007\n");
189 else
190 printf("User %s marked for deletion.\n", login2);
191 break;
192 case '2':
193## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
194## modby=8873) where u.#users_id = users_id
195## inquire_equel(rowcount = "rowcount")
196 if (rowcount != 1)
197 printf("Failed!\007\007\007\n");
198 else
199 printf("User %s marked for deletion.\n", login);
200 break;
201 case '3':
202## replace u (#mit_id = id2, #modtime=date("now"), #modwith="nodups",
203## modby=8873) where u.#users_id = users_id
204## inquire_equel(rowcount = "rowcount")
205 if (rowcount != 1)
206 printf("Failed!\007\007\007\n");
207## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
208## modby=8873) where u.#users_id = users_id2
209## inquire_equel(rowcount = "rowcount")
210 if (rowcount != 1)
211 printf("Failed!\007\007\007\n");
212 else
213 printf("User %s updated, %s marked for deletion.\n", login, login2);
214 break;
215 case '4':
216## replace u (#mit_id = id, #modtime=date("now"), #modwith="nodups",
217## modby=8873) where u.#users_id = users_id2
218## inquire_equel(rowcount = "rowcount")
219 if (rowcount != 1)
220 printf("Failed!\007\007\007\n");
221## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
222## modby=8873) where u.#users_id = users_id
223## inquire_equel(rowcount = "rowcount")
224 if (rowcount != 1)
225 printf("Failed!\007\007\007\n");
226 else
227 printf("User %s updated, %s marked for deletion.\n", login2, login);
228 break;
229 case '5':
230 users_id = users[2].users_id;
231## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
232## modby=8873) where u.#users_id = users_id
233## inquire_equel(rowcount = "rowcount")
234 if (rowcount != 1)
235 printf("Failed!\007\007\007\n");
236 else
237 printf("User %d marked for deletion.\n", users[2].users_id);
238 break;
239 case '6':
240 users_id = users[3].users_id;
241## replace u (#status = 3, #modtime=date("now"), #modwith="nodups",
242## modby=8873) where u.#users_id = users_id
243## inquire_equel(rowcount = "rowcount")
244 if (rowcount != 1)
245 printf("Failed!\007\007\007\n");
246 else
247 printf("User %d marked for deletion.\n", users[3].users_id);
248 break;
249 case 'q':
250 exit(0);
251 default:
252 printf("Leaving unchanged\n");
253 }
254##}
This page took 0.822738 seconds and 5 git commands to generate.