3 * This generates a list of everyone's poboxes for the mitdir.
5 * Copyright (C) 1992-1998 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>
22 EXEC SQL INCLUDE sqlca;
26 char *whoami = "pobox.gen";
27 char *db = "moira/moira";
29 int main(int argc, char **argv)
32 char *outf = NULL, outft[64];
35 EXEC SQL BEGIN DECLARE SECTION;
36 char login[9], id[18], string[257];
37 EXEC SQL END DECLARE SECTION;
43 if (stat(argv[1], &sb) == 0)
45 if (ModDiff(&flag, "users", sb.st_mtime))
49 fprintf(stderr, "File %s does not need to be rebuilt.\n",
55 sprintf(outft, "%s~", outf);
56 if (!(out = fopen(outft, "w")))
58 fprintf(stderr, "unable to open %s for output\n", outf);
64 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
70 /* The following is declarative, not executed,
71 * and so is dependent on where it is in the file,
72 * not in the order of execution of statements.
74 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
76 EXEC SQL DECLARE x CURSOR FOR SELECT
78 FROM users WHERE status != 3 and potype = 'POP';
82 EXEC SQL FETCH x INTO :id, :login;
88 fprintf(out, "%s %s@MIT.EDU\n", id, login);
93 EXEC SQL DECLARE y CURSOR FOR SELECT
95 FROM users u, strings s
96 WHERE u.status != 3 and u.potype = 'SMTP' and u.box_id = s.string_id;
100 EXEC SQL FETCH y INTO :id, :string;
107 if ((i = strlen(string)) > 7 &&
108 !strcasecmp(".local", string + i - 6))
110 string[i - 6] = '\0';
111 fprintf(out, "%s %s.mit.edu\n", id, string);
113 else if (!strchr(string, '@'))
114 fprintf(out, "%s %s@mit.edu\n", id, string);
116 fprintf(out, "%s %s\n", id, string);
126 perror("close failed");
134 db_error(sqlca.sqlcode);