3 * This generates the network table.
5 * (c) Copyright 1994 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
13 #include <sys/types.h>
17 EXEC SQL INCLUDE sqlca;
20 char *whoami = "network.gen";
28 char *outf = NULL, outft[64], *p, buf[256];
32 EXEC SQL BEGIN DECLARE SECTION;
34 char name[65], description[65];
35 EXEC SQL END DECLARE SECTION;
38 EXEC SQL CONNECT moira;
39 EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED;
42 EXEC SQL DATABASE moira;
46 if (stat(argv[1], &sb) == 0) {
47 if (ModDiff(&flag1, "subnet", sb.st_mtime))
50 fprintf(stderr, "File %s does not need to be rebuilt.\n",
56 sprintf(outft, "%s~", outf);
57 if ((out = fopen(outft, "w")) == NULL) {
58 fprintf(stderr, "unable to open %s for output\n", outf);
61 } else if (argc != 1) {
62 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
68 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
70 gettimeofday(&now, NULL);
72 fprintf(out, "; MIT Network Table\n;\n");
73 fprintf(out, "; \t%cAuthor: $\n", '$');
74 fprintf(out, "; \t%cDate: $\n", '$');
75 fprintf(out, "; \t%cRevision: $\n;\n", '$');
76 fprintf(out, "; Network table generated by Moira at %s;\n",
79 EXEC SQL DECLARE x CURSOR FOR SELECT
80 name, snet_id, saddr, description
81 FROM subnet ORDER BY saddr;
84 EXEC SQL FETCH x INTO :name, :id, :addr, :description;
85 if (sqlca.sqlcode != 0) break;
86 if (id == 0) continue;
87 if (*strtrim(name) == 0) continue;
88 fprintf(out, "NETWORK : %-16.16s : %-13.13s : %s \n", name, inet_ntoa(htonl(addr)),
97 EXEC SQL CLOSE DATABASE;
100 fprintf(out, "; End of automatically generated network table\n");
102 perror("close failed");
110 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
112 if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000)
115 critical_alert("DCM", "Networks build encountered INGRES ERROR %d",