Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC840302); site mcvax.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!hplabs!hao!seismo!mcvax!piet From: piet@mcvax.UUCP (Piet Beertema) Newsgroups: net.sources Subject: Re: build and access database of paths to systems on map Message-ID: <6079@mcvax.UUCP> Date: Tue, 9-Oct-84 20:53:00 EDT Article-I.D.: mcvax.6079 Posted: Tue Oct 9 20:53:00 1984 Date-Received: Thu, 11-Oct-84 07:30:45 EDT References: <155@scc.UUCP> <165@terak.UUCP> Organization: CWI, Amsterdam Lines: 280 <...> For what it's worth... I haven't seen the "mkmls" source, but from what I infer from the 165@terak (ng net.sources.bugs) it does about the same as the following program. It's a preprocessor for Jeff Donelly's buildmap (pathalias) program, taking as its input the Usenet maps and giving for each site all the sites with which it is linked; the links are taken from both the "News:" and the "Mail:" lines. The program uses dynamically allocated memory only for building the connect table. An adapted version of it takes the new uucpmap(s) as input. The connect table is built in the form of a forward/backward linked list of sites, each site linked to a forward/backward linked list of connections. Thus it can quite easily be modified for other purposes, e.g. to completely replace the buildmap program (haven't done that yet). ----------------------------------------------------------------------------- /* * mkcon: * make links list from USENET map data * * Author: Piet Beertema, CWI, Aug 1983 */ #include#define SAME 0 struct site { char name[16]; struct site *prev; struct site *next; struct con *con; }; struct con { struct site *consite; struct con *prev; struct con *next; }; struct site *first = (struct site *)0; FILE *ifd; main(argc, argv) int argc; char **argv; { register char *lp; register int v, gotline; register struct site *sitep; register struct con *conp; char line[100], verbose; struct site *cursite; struct con *curcon; extern struct site *newsite(); verbose = 0; while (--argc) { if (argv[1][0] == '-') { switch(argv[1][1]) { case 'v': verbose++; break; default: error("bad key: %c\n", argv[1][1]); } argv++; continue; } if ((ifd = fopen(*++argv, "r")) == 0) error("Cannot open %s\n", *argv); if (verbose) fprintf(stderr, "%s... ", *argv); while (gotline || readline(line)) { gotline = 0; lp = line; if (strncmp(lp, "Name:", 5) == SAME) { while (*lp++); if (*lp == '\0') continue; if (first == (struct site *)0) sitep = first = newsite(first, lp); else for (sitep = first; ; sitep = sitep->next) { if ((v = strcmp(lp, sitep->name)) == SAME) break; if (v < 0 || sitep->next == (struct site *)0) { sitep = newsite(sitep, lp, v < 0); break; } } continue; } if (strncmp(lp, "News:", 5) == SAME || strncmp(lp, "Mail:", 5) == SAME) { while (*lp++); setcon(sitep, lp); while (gotline = readline(line)) { if (*(lp = line) != '*') break; setcon(sitep, ++lp); } } } if (verbose) fprintf(stderr, "done\n"); fclose(ifd); } for (sitep = first; sitep; sitep = sitep->next) { printf("%s\t", sitep->name); for (conp = sitep->con; conp; conp = conp->next) printf("%s ", conp->consite->name); printf("\n"); } } readline(line) char *line; { register char *rlp; register int c; rlp = line; while (1) { while ((c = fgetc(ifd)) == '\n'); if (c != ' ' && c != '\t') break; while ((c = fgetc(ifd)) == ' ' || c == '\t'); if (c != '\n') { *rlp++ = '*'; break; } } if (c == EOF) return 0; do { *rlp++ = (c == ' ' || c == '\t') ? '\0' : c; } while ((c = fgetc(ifd)) != '\n'); *rlp++ = '\0'; *rlp++ = '\0'; return 1; } struct site * newsite(siteptr, name, insert) register struct site *siteptr; register char *name; char insert; { register struct site *cursite; cursite = (struct site *)malloc(sizeof (struct site)); if (siteptr == (struct site *)0) cursite->prev = cursite->next = (struct site *)0; else if (insert) { cursite->next = siteptr; if (siteptr->prev) siteptr->prev->next = cursite; cursite->prev = siteptr->prev; siteptr->prev = cursite; if (siteptr == first) first = cursite; } else { siteptr->next = cursite; cursite->next = (struct site *)0; cursite->prev = siteptr; } cursite->con = (struct con *)0; strncpy(cursite->name, name, 15); return cursite; } struct con * newcon(conptr, siteptr, insert) register struct con *conptr; register struct site *siteptr; char insert; { register struct con *curcon; curcon = (struct con *)malloc(sizeof (struct con)); if (conptr == (struct con *)0) curcon->prev = curcon->next = (struct con *)0; else if (insert) { curcon->next = conptr; if (conptr->prev) conptr->prev->next = curcon; curcon->prev = conptr->prev; conptr->prev = curcon; } else { conptr->next = curcon; curcon->next = (struct con *)0; curcon->prev = conptr; } curcon->consite = siteptr; return curcon; } setcon(siteptr, np) register struct site *siteptr; register char *np; { register struct site *sitep; register struct con *conptr; register int v; extern struct site *newsite(), *findsite(); extern struct con *newcon(); while (*np != '\0') { for (sitep = first; ; sitep = sitep->next) { if ((v = strcmp(np, sitep->name)) == SAME) { if ((conptr = sitep->con) == (struct con *)0) sitep->con = newcon(conptr, siteptr, 0); else for (; ; conptr = conptr->next) { if ((v = strcmp(siteptr->name, conptr->consite->name)) == SAME) break; if (v < 0 || conptr->next == (struct con *)0) { if (v < 0 && conptr == sitep->con) sitep->con = newcon(conptr, siteptr, v < 0); else newcon(conptr, siteptr, v < 0); break; } } break; } if (v < 0 || sitep->next == (struct site *)0) { sitep = newsite(sitep, np, v < 0); sitep->con = newcon(sitep->con, siteptr, v < 0); break; } } if ((conptr = siteptr->con) == (struct con *)0) siteptr->con = newcon(conptr, findsite(np), 0); else { for (; ; conptr = conptr->next) { if ((v = strcmp(np, conptr->consite->name)) == SAME) break; if (v < 0 || conptr->next == (struct con *)0) { if (v < 0 && conptr == siteptr->con) siteptr->con = newcon(conptr, findsite(np), v < 0); else newcon(conptr, findsite(np), v < 0); break; } } } while (*np++); } } struct site * findsite(name) { register struct site *sitep; for (sitep = first; sitep; sitep = sitep->next) { if (strcmp(name, sitep->name) == SAME) return sitep; } fprintf(stderr, "Can't find site %s\n", name); exit(1); } error(fmt, arg) { fprintf(stderr, fmt, arg); exit(1); } ---------------------------------------------------------------------------- Piet Beertema, CWI, Amsterdam ...{decvax,philabs}!mcvax!piet