rwh@aesat.UUCP (Russell Herman) (05/30/84)
This program searches the site data base from net.news.map. ----------------------------CUT HERE FOR MANUAL PAGE------------------------- .TH Usite 1 .SH NAME Usite - search the net.news.map for any site(s) satisfying any search criterion .SH SYNOPSIS Usite flag val [... flag val] [maps_files] .SH DESCRIPTION This program searches the database consisting of a list of files formatted as in net.news.map, and outputs the site record(s) satisfying any of the search criteria. Compares are case-independent character string matches, NOT regular expressions, NO wildcarding. Available flags are: .TP .B \-na site name .TP .B \-o organization .TP .B \-c contact .TP .B \-p phone .TP .B \-pa Postal-Address .TP .B \-ea Electronic-Address .TP .B \-ne News .TP .B \-m Mail .PP If no file names are supplied, stdin will be used. This enables chaining calls to produce a logical-AND search. .SH FILES none. .SH AUTHOR Russ Herman, utzoo!aesat!rwh .SH DIAGNOSTICS Self-explanatory. .SH BUGS As this was a quick hack, each site entry is read into a fixed core buffer for processing. The maximum line length is 132 characters, and the maximum number of lines for a site entry is 200 lines. If ihnp4 gets many more sites connected, the latter will have to change, or someone else will have to upgrade this program to be a bit smarter. The program does pay attention to the fact that headings start in the first character position of a line, and continuation lines start with whitespace. .SH CHANGES ---------------------------------CUT HERE FOR SOURCE-------------------------- /*$title Usite*/ /*M************************************************************************** **************************************************************************** Program name: Usite File name: Usite.c Version: 3.3 Date: 84/05/14 14:11:57 Author: R. Herman, utzoo!aesat!rwh Function: Search USENET map listing for matching atttribute - print entry **************************************************************************** ****************************************************************************/ static char sccs_id[] = {"@(#)Usite.c 3.3 84/05/14"}; #include <stdio.h> #include <ctype.h> #define MAXLEN 132 #define MAXLINES 200 #define NHDS 8 typedef struct lnk { char *txtptr; struct lnk *nxtlnk; } LINK, *LINKP; struct categs{ char *flag; char *categ; LINKP hdlnk; } hds[NHDS]; /*$sttl *insert name of procedure*/ /*P************************************************************************** Subprogram name: main Function: do it. Interface: INPUTS: flags: -na Name -o Organization -c Contact -p Phone -pa Postal-Address -ea Electronic-Address -ne News -m Mail Description: * insert a complete logic description of the procedure. ***********************************************************************RTN**/ main(argc, argv) char *argv[]; { int i, j, k, n, eofsw, cat, ocat,fnd, ret, ntmpls; char *ss, s[MAXLEN], buf[MAXLINES][MAXLEN]; FILE *fi; char *index(); LINKP q, q1; i = 0, ret = 1; ntmpls = 0; n = 1; hds[0].flag="na"; hds[0].categ="Name:"; hds[1].flag="o"; hds[1].categ="Organization:"; hds[2].flag="c"; hds[2].categ="Contact:"; hds[3].flag="p"; hds[3].categ="Phone:"; hds[4].flag="pa"; hds[4].categ="Postal-Address:"; hds[5].flag="ea"; hds[5].categ="Electronic-Address:"; hds[6].flag="ne"; hds[6].categ="News:"; hds[7].flag="m"; hds[7].categ="Mail:"; while (n < argc) { if (*(ss=argv[n]) != '-') break; ss++; for (i=0; i<NHDS; i++) if (strcmp(hds[i].flag, ss) == 0) { if ((q=(LINKP) malloc(sizeof(LINK))) == NULL){ fputs("Usite: out of memory\n", stderr); exit(2); } q->txtptr = (ss = argv[++n]); for (; *ss; ss++) if (isupper(*ss)) *ss = tolower(*ss); q->nxtlnk = NULL; if ((q1=hds[i].hdlnk) == NULL) hds[i].hdlnk = q; else { for (; q1->nxtlnk!=NULL; q1=q1->nxtlnk) ; q1->nxtlnk = q; } ntmpls++; break; } if (i >= NHDS) { fprintf(stderr, "Usage: Usite illegal flag %s\n", argv[n]); exit(2); } n++; } if (ntmpls == 0) { fputs("Usite - no search strings supplied\n", stderr); exit(2); } if (n == argc) { fi = stdin; n--; } else fi = NULL; /*$page*/ for (; n<argc; n++) { if (fi != stdin) if ((fi=fopen(argv[n], "r")) == NULL) { fprintf(stderr, "Can\'t open %s\n", argv[n]); continue; } nxt0: j=0; nxt1: eofsw = (fgets(&buf[j][0], MAXLEN, fi) == NULL); if (eofsw || buf[j][0] == '\n') { ocat = 0; for (i=0; i<j; i++) { cat=setcat(&buf[i][0]); if (cat < 0) fnd = matched(&buf[i][0], hds[ocat].hdlnk); else { fnd = matched(&buf[i][index(&buf[i][0], ':')-&buf[i][0]]+1, hds[cat].hdlnk); ocat = cat; } if (fnd) { for (k=0; k<j; k++) fputs(&buf[k][0], stdout); putchar('\n'); ret = 0; if (eofsw) goto closit; else goto nxt0; } } if (eofsw) goto closit; else goto nxt0; } else { cat = setcat(&buf[j][0]); if (cat >= -1) { buf[j][strlen(&buf[j][0])] = '\0'; if (j > 0 || (j == 0 && cat == 0)) { if (j < MAXLINES) j++; } } goto nxt1; } closit: fclose(fi); } exit(ret); } /*$page*/ int matched(ss, qq) char ss[]; LINKP qq; { int i, j, tl, sl; while (qq != NULL) { tl = strlen(qq->txtptr); sl = strlen(ss) - tl; for (i=0; i<sl; i++) { for (j=0; j<tl; j++) if ((isupper(ss[i+j]) ? tolower(ss[i+j]) : ss[i+j]) != qq->txtptr[j]) break; if (j >= tl) return(1); } qq = qq->nxtlnk; } return(0); } int setcat(ss) char *ss; { int i; char s[MAXLEN]; if (isspace(*ss)) return(-1); sscanf(ss, "%s", s); for (i=0; i<NHDS; i++) if (strcmp(s, hds[i].categ) == 0) return(i); return(-2); } ----------------------------------CUT LINE-------------------------------------- -- ______ Russ Herman / \ {allegra,ihnp4,linus,decvax}!utzoo!aesat!rwh @( ? ? )@ (416) 821-9190 ( || ) AES Data Inc. ( \__/ ) 1900 Minnesota Ct. \____/ Mississauga, Ont. CANADA L5N 3C9