3 * This generates a list of everyone's poboxes for the mitdir.
5 * (c) Copyright 1992 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
14 #include <sys/types.h>
18 EXEC SQL INCLUDE sqlca;
20 char *whoami = "pobox.gen";
21 char *db = "moira/moira";
23 int main(int argc, char **argv)
26 char *outf = NULL, outft[64];
29 EXEC SQL BEGIN DECLARE SECTION;
30 char login[9], id[18], string[257];
31 EXEC SQL END DECLARE SECTION;
37 if (stat(argv[1], &sb) == 0)
39 if (ModDiff(&flag, "users", sb.st_mtime))
43 fprintf(stderr, "File %s does not need to be rebuilt.\n",
49 sprintf(outft, "%s~", outf);
50 if (!(out = fopen(outft, "w")))
52 fprintf(stderr, "unable to open %s for output\n", outf);
58 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
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.
68 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
70 EXEC SQL DECLARE x CURSOR FOR SELECT
72 FROM users WHERE status != 3 and potype = 'POP';
76 EXEC SQL FETCH x INTO :id, :login;
82 fprintf(out, "%s %s@MIT.EDU\n", id, login);
87 EXEC SQL DECLARE y CURSOR FOR SELECT
89 FROM users u, strings s
90 WHERE u.status != 3 and u.potype = 'SMTP' and u.box_id = s.string_id;
94 EXEC SQL FETCH y INTO :id, :string;
101 if ((i = strlen(string)) > 7 &&
102 !strcasecmp(".local", string + i - 6))
104 string[i - 6] = '\0';
105 fprintf(out, "%s %s.mit.edu\n", id, string);
107 else if (!strchr(string, '@'))
108 fprintf(out, "%s %s@mit.edu\n", id, string);
110 fprintf(out, "%s %s\n", id, string);
120 perror("close failed");
128 db_error(sqlca.sqlcode);