]> andersk Git - moira.git/blob - gen/pobox.pc
break out of case statement, don't fall through.
[moira.git] / gen / pobox.pc
1 /* $Id$
2  *
3  * This generates a list of everyone's poboxes for the mitdir.
4  *
5  * Copyright (C) 1992-1998 by the Massachusetts Institute of Technology.
6  * For copying and distribution information, please see the file
7  * <mit-copyright.h>.
8  */
9
10 #include <mit-copyright.h>
11 #include <moira.h>
12
13 #include <sys/stat.h>
14 #include <sys/types.h>
15
16 #include <ctype.h>
17 #include <stdio.h>
18 #include <string.h>
19
20 #include "util.h"
21
22 EXEC SQL INCLUDE sqlca;
23
24 RCSID("$Header$");
25
26 char *whoami = "pobox.gen";
27 char *db = "moira/moira";
28
29 int main(int argc, char **argv)
30 {
31   FILE *out = stdout;
32   char *outf = NULL, outft[MAXPATHLEN];
33   int i;
34   EXEC SQL BEGIN DECLARE SECTION;
35   char login[USERS_LOGIN_SIZE], id[USERS_CLEARID_SIZE];
36   char string[STRINGS_STRING_SIZE];
37   EXEC SQL END DECLARE SECTION;
38
39   EXEC SQL CONNECT :db;
40
41   if (argc == 2)
42     {
43       outf = argv[1];
44       sprintf(outft, "%s~", outf);
45       if (!(out = fopen(outft, "w")))
46         {
47           fprintf(stderr, "unable to open %s for output\n", outf);
48           exit(MR_OCONFIG);
49         }
50     }
51   else if (argc != 1)
52     {
53       fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
54       exit(MR_ARGS);
55     }
56   else
57     outf = NULL;
58
59   /* The following is declarative, not executed,
60    * and so is dependent on where it is in the file,
61    * not in the order of execution of statements.
62    */
63   EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
64
65   EXEC SQL DECLARE x CURSOR FOR SELECT
66     clearid, login
67     FROM users WHERE status != 3 AND potype != 'NONE' AND potype != 'SMTP';
68   EXEC SQL OPEN x;
69   while (1)
70     {
71       EXEC SQL FETCH x INTO :id, :login;
72       if (sqlca.sqlcode)
73         break;
74       strtrim(login);
75       strtrim(id);
76       if (isdigit(id[0]))
77         fprintf(out, "%s %s@MIT.EDU\n", id, login);
78     }
79
80   EXEC SQL CLOSE x;
81
82   EXEC SQL DECLARE y CURSOR FOR SELECT
83     u.clearid, s.string
84     FROM users u, strings s
85     WHERE u.status != 3 and u.potype = 'SMTP' and u.box_id = s.string_id;
86   EXEC SQL OPEN y;
87   while (1)
88     {
89       EXEC SQL FETCH y INTO :id, :string;
90       if (sqlca.sqlcode)
91         break;
92       strtrim(string);
93       strtrim(id);
94       if (isdigit(id[0]))
95         {
96           if ((i = strlen(string)) > 7 &&
97               !strcasecmp(".local", string + i - 6))
98             {
99               string[i - 6] = '\0';
100               fprintf(out, "%s %s.mit.edu\n", id, string);
101             }
102           else if (!strchr(string, '@'))
103             fprintf(out, "%s %s@mit.edu\n", id, string);
104           else
105             fprintf(out, "%s %s\n", id, string);
106         }
107     }
108
109   EXEC SQL CLOSE y;
110
111   EXEC SQL COMMIT;
112
113   if (fclose(out))
114     {
115       perror("close failed");
116       exit(MR_CCONFIG);
117     }
118   if (outf)
119     fix_file(outf);
120   exit(MR_SUCCESS);
121
122 sqlerr:
123   db_error(sqlca.sqlcode);
124   exit(MR_DBMS_ERR);
125 }
This page took 0.051691 seconds and 5 git commands to generate.