]> andersk Git - moira.git/blame - gen/pobox.pc
Command line printer manipulation client, and build goo.
[moira.git] / gen / pobox.pc
CommitLineData
c441a31a 1/* $Id$
c7fb2d10 2 *
3 * This generates a list of everyone's poboxes for the mitdir.
4 *
7ac48069 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>.
c7fb2d10 8 */
9
10#include <mit-copyright.h>
c7fb2d10 11#include <moira.h>
7ac48069 12
c7fb2d10 13#include <sys/stat.h>
7ac48069 14#include <sys/types.h>
15
c7fb2d10 16#include <ctype.h>
7ac48069 17#include <stdio.h>
18#include <string.h>
19
20#include "util.h"
21
c7fb2d10 22EXEC SQL INCLUDE sqlca;
23
7ac48069 24RCSID("$Header$");
25
c7fb2d10 26char *whoami = "pobox.gen";
9c04b191 27char *db = "moira/moira";
c7fb2d10 28
5eaef520 29int main(int argc, char **argv)
c7fb2d10 30{
5eaef520 31 FILE *out = stdout;
dfaf9b68 32 char *outf = NULL, outft[MAXPATHLEN];
a589d269 33 int i;
5eaef520 34 EXEC SQL BEGIN DECLARE SECTION;
dfaf9b68 35 char login[USERS_LOGIN_SIZE], id[USERS_CLEARID_SIZE];
36 char string[STRINGS_STRING_SIZE];
5eaef520 37 EXEC SQL END DECLARE SECTION;
c7fb2d10 38
5eaef520 39 EXEC SQL CONNECT :db;
c7fb2d10 40
5eaef520 41 if (argc == 2)
42 {
5eaef520 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);
c7fb2d10 49 }
c7fb2d10 50 }
5eaef520 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;
c7fb2d10 58
5eaef520 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;
c7fb2d10 64
5eaef520 65 EXEC SQL DECLARE x CURSOR FOR SELECT
66 clearid, login
97316c60 67 FROM users WHERE status != 3 AND potype != 'NONE';
5eaef520 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);
c7fb2d10 78 }
79
5eaef520 80 EXEC SQL CLOSE x;
c7fb2d10 81
5eaef520 82 EXEC SQL COMMIT;
c7fb2d10 83
5eaef520 84 if (fclose(out))
85 {
86 perror("close failed");
87 exit(MR_CCONFIG);
c7fb2d10 88 }
5eaef520 89 if (outf)
90 fix_file(outf);
91 exit(MR_SUCCESS);
c7fb2d10 92
5eaef520 93sqlerr:
94 db_error(sqlca.sqlcode);
95 exit(MR_DBMS_ERR);
c7fb2d10 96}
This page took 0.208845 seconds and 5 git commands to generate.