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