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