- EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
-
- gettimeofday(&now, NULL);
-
- fprintf(out, "; MIT Network Host Table\n;\n");
- fprintf(out, "; \t%cAuthor: $\n", '$');
- fprintf(out, "; \t%cDate: $\n", '$');
- fprintf(out, "; \t%cRevision: $\n;\n", '$');
- fprintf(out, "; Host table generated by Moira at %s;\n",
- ctime(&now.tv_sec));
-
- EXEC SQL DECLARE y CURSOR FOR SELECT
- mach_id, name FROM hostalias;
- EXEC SQL OPEN y;
- aliases = create_hash(1001);
- while (1) {
- EXEC SQL FETCH y INTO :id, :name;
- if (sqlca.sqlcode != 0) break;
- if (id == 0) continue;
- if (*strtrim(name) == 0) continue;
- if ((i = strlen(name)) < 9 || strcmp(&name[i-8], ".MIT.EDU")) {
- fprintf(stderr, "Name %s not in MIT domain\n", name);
- continue;
- } else {
- name[i-8] = 0;
+ EXEC SQL DECLARE y CURSOR FOR SELECT mach_id, name FROM hostalias;
+ EXEC SQL OPEN y;
+ aliases = create_hash(1001);
+ while (1)
+ {
+ EXEC SQL FETCH y INTO :id, :name;
+ if (sqlca.sqlcode)
+ break;
+ if (id == 0)
+ continue;
+ if (!*strtrim(name))
+ continue;
+ if ((i = strlen(name)) < 9 || !strchr(name, '.') ||
+ strcmp(strchr(name, '.'), ".MIT.EDU"))
+ {
+ fprintf(stderr, "Ignoring alias %s\n", name);
+ continue;
+ }
+ else
+ name[i - 8] = 0;
+ if ((p = hash_lookup(aliases, id)))
+ {
+ p = realloc(p, strlen(p) + strlen(name) + 2);
+ sprintf(strchr(p, '\0'), ",%s", name);
+ hash_update(aliases, id, p);