home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / netsrcs / pthcprn < prev    next >
Internet Message Format  |  1987-03-06  |  19KB

  1. From matt@ncr-sd.UUCP Fri Mar  6 20:49:31 1987
  2. Path: beno!seismo!lll-lcc!ptsfa!ihnp4!ncr-sd!matt
  3. From: matt@ncr-sd.SanDiego.NCR.COM (Matt Costello)
  4. Newsgroups: net.sources
  5. Subject: Pathprune (to shorten pathalias files)
  6. Keywords: pathalias pathprune
  7. Message-ID: <1411@ncr-sd.SanDiego.NCR.COM>
  8. Date: 7 Mar 87 01:49:31 GMT
  9. Reply-To: matt@ncr-sd.UUCP (Matt Costello)
  10. Followup-To: comp.sources.d
  11. Distribution: world
  12. Organization: NCR Corporation, Rancho Bernardo
  13. Lines: 675
  14.  
  15. :    shar:    Shell Archiver
  16. # Run this text with /bin/sh to create:
  17. #    README
  18. #    pathprune.1
  19. #    pathprune.c
  20.  
  21. sed 's/^X//' <<'SHAR_EOF' >README; chmod 644 README
  22. XHere is a program to make your paths file (from pathalias) smaller
  23. Xby removing redundant entries.  I wrote it because we currently
  24. Xcreate two different paths files for the systems in our domain.
  25. XMost systems get a file containing only the hosts within the domain,
  26. Xwhile the domain gateway(s) get the full database distributed in
  27. Xthe newsgroups mod.map and ncr.maps.  The large paths file is too
  28. Xlarge (~500k) to want to ship all over.  Pathprune can often remove
  29. Xenough of a paths file to make transmission of it using uucp feasible.
  30. X
  31. X
  32. XThe two tables here show the actual compression on two different systems,
  33. Xwith the pathalias entries broken down into three types:
  34. X    gateway        domain gateway entry (starts with a '.')
  35. X    domain        host belongs to a domain (host has a '.' in it)
  36. X    host        simple host name (in the .uucp domain)
  37. X
  38. XThe numbers listed are the number of lines and percentage of original
  39. Xlines.  The "domain" values are slightly skewed because Berkeley lists
  40. X344 hosts in the berkeley.edu domain without any domain gateway.
  41. X
  42. Xfor ncr-sd (domain gateway)
  43. X            orig        -v              -vt             -vut
  44. Xgateway      199     128  0.64       124  0.62       124  0.62
  45. Xdomain      1540     652  0.42       652  0.42       652  0.42
  46. Xhost        8515    8515  1.00      8515  1.00      8515  1.00
  47. Xtotal      10254    9295  0.91      9291  0.91      9291  0.91
  48. X
  49. Xfor se-sd (internal node)
  50. X            orig        -v              -vt             -vut
  51. Xgateway      199     124  0.62       120  0.60       120  0.60
  52. Xdomain      1540     623  0.40       623  0.40       623  0.40
  53. Xhost        8515    8515  1.00      8515  1.00         2  0.00
  54. Xtotal      10254    9262  0.90      9258  0.90       745  0.07
  55. X
  56. X
  57. XThe program will compile under both SYSV and BSD4.2, and will
  58. Xshould also compile under V7.  See the beginning of the source
  59. Xfile for compilation instructions.  It does use getopt(3).
  60. SHAR_EOF
  61. sed 's/^X//' <<'SHAR_EOF' >pathprune.1; chmod 644 pathprune.1
  62. X.\" @(#)pathprune.1    matt.costello@sandiego.ncr.com 87/03/06
  63. X.TH PATHPRUNE 1 
  64. X.SH NAME
  65. Xpathprune \- prune unnecessary entries in pathalias database
  66. X.SH SYNOPSIS
  67. X.B pathprune
  68. X[
  69. X.B \-vutj
  70. X] [
  71. X.BI \-d \0domain
  72. X] [
  73. X.BI \-h \0domain
  74. X] [
  75. X.BI \-r \0domain
  76. X] [
  77. X.I infile
  78. X[
  79. X.I outfile
  80. X] ]
  81. X.ad b
  82. X.SH DESCRIPTION
  83. X.I Pathprune
  84. Xprunes unnecessary entries from a sorted \fIpathalias\fR(1) database.
  85. XIt does this by reading a sorted database and then writing out a
  86. Xsmaller one.  It preserves the original sorted order.
  87. X.PP
  88. XAny subdomain gateway whose path is the same as the parent domain
  89. Xgateway is unnecessary.  The subdomain gateway is also unnecessary if
  90. Xits path passes through the parent domain gateway.  This is subject
  91. Xto one very important rule; if the path is \fB%s\fR then the domain gateway
  92. Xis always necessary.  This rule allows the local mailer to detect invalid
  93. Xhosts in the domains for which it is a gateway.
  94. X.PP
  95. XA host entry is unnecessary if its path arrives at or passes through
  96. Xthe corresponding domain gateway entry.  For simple host names this is the
  97. Xpseudo-domain ".uucp".
  98. X.PP
  99. XThis can more easily explained by example.  Assume the input of:
  100. X.tr ~.
  101. X.RS
  102. X.nf
  103. X~com            ncr-sd!scubed!seismo!%s
  104. X~ncr.com        ncr-sd!%s
  105. X~sandiego.ncr.com    ncr-sd!%s
  106. X~other            ncr-sd!%s
  107. X~uucp            ncr-sd!%s
  108. Xfalstaf.sandiego.ncr.com    ncr-sd!falstaf!%s
  109. Xncr-sd.sandiego.ncr.com    ncr-sd!%s
  110. Xse-sd.sandiego.ncr.com    %s
  111. Xtower5.sandiego.ncr.com    tower5!%s
  112. X.fi
  113. X.RE
  114. XAfter processing, the output will be:
  115. X.RS
  116. X.nf
  117. X~com            ncr-sd!scubed!seismo!%s
  118. X~ncr.com        ncr-sd!%s
  119. X~other            ncr-sd!%s
  120. X~uucp            ncr-sd!%s
  121. Xse-sd.sandiego.ncr.com    %s
  122. Xtower5.sandiego.ncr.com    tower5!%s
  123. X.fi
  124. X.RE
  125. XThe domain gateway .sandiego.ncr.com was removed because .ncr.com will get
  126. Xus to the same place.  If the \fB\-t\fR option had been specified the .com
  127. Xand .ncr.com gateways would also have been removed.  All hosts that lie
  128. Xbeyond the .ncr.com (or .other for \fB\-t\fR) gateway were also removed
  129. Xas being unnecessary.
  130. X.PP
  131. XThe
  132. X.I pathprune
  133. Xoptions are:
  134. X.TP 6
  135. X.B \-v
  136. XReport some statistics on the standard error output.
  137. X.TP
  138. X.B \-u
  139. XDelete simple hosts (host.uucp) if they pass through the domain gateway for
  140. X".uucp".
  141. X.TP
  142. X.B \-t
  143. XPossibly delete the gateways for top-level domain names.  The pseudo-domain
  144. Xgateway for ".other" must be present; this domain gateway is used as a
  145. Xsmarter machine for domain names.
  146. X.TP
  147. X.B \-j
  148. XJunk all hosts that do not belong to a valid top-level domain.
  149. X.TP
  150. X.BI \-d \0domain
  151. XPreserve the domain gateway for \fIdomain\fR and any subdomain gateways of
  152. X\fIdomain\fR.  Normally subdomain gateways will be removed if they pass
  153. Xthrough the domain gateway.  This option will preserve these gateways in
  154. Xthe database in case the database is used for domain qualification.
  155. XSpecifying \fB\-d other\fR will preserve all domain gateways in the database.
  156. X.TP
  157. X.BI \-h \0domain
  158. XPreserve all host names in the \fIdomain\fR, or subdomains of \fIdomain\fR.
  159. X.TP
  160. X.BI \-r \0domain
  161. XRemove all host names in the \fIdomain\fR, or subdomains of \fIdomain\fR.
  162. XThis is useful for domains like berkeley.edu which list several
  163. Xhundred hosts in the domain, but have no domain gateway.  Of course, you
  164. Xcould always confuse ucbvax by listing it as the domain gateway.
  165. X.IP
  166. XSpecifying \fB\-r uucp\fR will remove all simple host names.
  167. X.PP
  168. XThe \fB\-d\fR, \fB\-h\fR and \fB\-r\fR options may be specified as
  169. Xmany times as wanted.
  170. X.SH BUGS
  171. X.I Pathprune
  172. Xassumes bang-routed paths and will not match gateway paths containing '@'s.
  173. X.br
  174. X.B .other
  175. Xis specific to NCR's version of smail.
  176. X.SH "SEE ALSO"
  177. Xpathalias(1)
  178. X.SH AUTHOR
  179. XMatt Costello    <matt.costello@sandiego.ncr.com>
  180. SHAR_EOF
  181. sed 's/^X//' <<'SHAR_EOF' >pathprune.c; chmod 444 pathprune.c
  182. X#ifndef lint
  183. Xstatic char sccsID[] = "@(#)pathprune.c    1.1 Delta: 14:58:26 3/6/87";
  184. X#endif
  185. X/*
  186. X *  Prune down a pathalias file by throwing out all unnecessary entries.
  187. X *
  188. X *  Usage
  189. X *    pathprune [options] [ infile [outfile] ]
  190. X *
  191. X *    -u    prune .uucp(implied) entries
  192. X *    -t    prune top level (via .other) entries
  193. X *    -d dom    sacred domain, do not prune domain gateways
  194. X *    -h dom    sacred hosts, do not prune hosts in this domain (or subdomains)
  195. X *    -r dom    remove all hosts in this domain (and subdomains)
  196. X *    -j    junk all hosts with bogus top-level domains
  197. X *    -v    verbose, print statistics
  198. X *
  199. X *  Compilation
  200. X *    cc -O -o pathprune pathprune.c            # for USG systems
  201. X *    cc -DBSD -O -o pathprune pathprune.c getopt.o    # for BSD systems
  202. X *
  203. X *  Disclaimer
  204. X *    Pathprune is in the public domain.  It may be used by any person or
  205. X *    organization, in any way and for any purpose.  There is no warranty
  206. X *    of any kind for this program.  What you see is what you get.
  207. X *
  208. X *  History
  209. X *    1.1    Mar 6, 1987
  210. X *        Written by Matt Costello
  211. X */
  212. X# include <stdio.h>
  213. X
  214. X# define VOID    (void)    /* define empty for non-voids */
  215. X# define UUCPNAME    "uucp"
  216. X# define OTHERNAME    "other"
  217. X
  218. X# ifdef BSD
  219. X
  220. X# include <strings.h>
  221. X# define strchr(s,c) index(s,c)
  222. X# define strrchr(s,c) rindex(s,c)
  223. Xextern char    *gets();
  224. X
  225. Xchar *
  226. Xstrtok( str, delims )
  227. Xregister char *str, *delims;
  228. X{
  229. X    static char *strnext;
  230. X    char *token;
  231. X    if (!str) str=strnext;
  232. X    while (*str && index(delims,*str))
  233. X        str++;    /* skip leading delimiters */
  234. X    if (!*str)
  235. X        return (NULL);
  236. X    token = str;
  237. X    while (*str && !index(delims,*str))
  238. X        str++;    /* skip token characters */
  239. X    if (*str)    strnext = str;
  240. X    else         *strnext++ = '\0';
  241. X    return (token);
  242. X}
  243. X
  244. X# else /* !BSD */
  245. X
  246. X# include <string.h>
  247. X# include <memory.h>
  248. Xextern void    exit();
  249. Xextern void    perror();
  250. X
  251. X# endif /* !BSD */
  252. X
  253. Xextern char    *malloc();
  254. Xextern char    *calloc();
  255. Xchar        *stralloc();        /* FORWARD */
  256. X
  257. Xstruct dnode {
  258. X    struct dnode *lnode;    /* pointer to littler node name */
  259. X    struct dnode *bnode;    /* pointer to bigger node name */
  260. X    struct dnode *children;    /* pointer to childrens node names */
  261. X    struct dnode *order;    /* pointer to next node in original order */
  262. X    char *fullname;        /* full name of this domain gateway */
  263. X    char *nodename;        /* last portion of the domain name */
  264. X    char *pathname;        /* path name to gateway for this node */
  265. X    char *line;        /* the full line from the paths file */
  266. X    int flags;
  267. X};
  268. X# define SACRED_DOMAIN    001
  269. X# define SACRED_HOST    002
  270. X# define REMOVE_HOST    004
  271. X
  272. Xstruct dnode *rootnode = NULL;    /* root of the domain (node) tree */
  273. Xstruct dnode *look_node();    /* look for a node */
  274. Xstruct dnode *add_node();    /* look for a node */
  275. X
  276. Xstruct dnode *firstnode = NULL;    /* to keep original order */
  277. Xstruct dnode *lastnode = NULL;    /* for performance */
  278. X
  279. Xchar *        otherpath = "!!!!!!!";
  280. Xchar *        uucppath = "!!!!!!!";
  281. Xint        flg_topdel;
  282. Xint        flg_dontprune;
  283. Xint        flg_junkbogus;
  284. Xint        flg_uucpdel;
  285. Xint        flg_removeuucp;
  286. Xint        flg_verbose;
  287. X
  288. Xint    gw_in, gw_out;
  289. Xint    dom_in, dom_out;
  290. Xint    hst_in, hst_out;
  291. X
  292. Xmain(argc,argv)
  293. Xint argc;
  294. Xchar **argv;
  295. X{
  296. X    register struct dnode *p;
  297. X    register i;
  298. X    extern int optind;
  299. X    extern char *optarg;
  300. X    char linebuf[BUFSIZ];
  301. X
  302. X    while ((i = getopt(argc,argv,"utjvd:h:r:")) != EOF) switch (i) {
  303. X        case 'u':    /* prune host.uucp entries where possible */
  304. X            flg_uucpdel++;
  305. X            break;
  306. X        case 't':    /* prune top level domain names */
  307. X            flg_topdel++;
  308. X            break;
  309. X        case 'j':    /* just hosts in bogus top-level domains */
  310. X            flg_junkbogus++;
  311. X            break;
  312. X        case 'v':
  313. X            flg_verbose++;
  314. X            break;
  315. X        case 'd':
  316. X            domflag( optarg, SACRED_DOMAIN );
  317. X            break;
  318. X        case 'h':
  319. X            domflag( optarg, SACRED_HOST );
  320. X            break;
  321. X        case 'r':
  322. X            domflag( optarg, REMOVE_HOST );
  323. X            break;
  324. X
  325. X        default:
  326. XUsage:
  327. XVOID fputs("Usage: pathprune [-vutj] [-[dhr] dom] [ infile [outfile] ]\n",
  328. X                stderr );
  329. X            exit(2);
  330. X    }
  331. X    if ( (optind < argc) &&
  332. X         (freopen( argv[optind++], "r", stdin ) == NULL) ) {
  333. X        VOID fputs("pathprune: cannot open ", stderr );
  334. X        perror( argv[--optind] );
  335. X        exit(1);
  336. X    }
  337. X    if ( (optind < argc) &&
  338. X         (freopen( argv[optind++], "w", stdout ) == NULL) ) {
  339. X        VOID fputs("pathprune: cannot create ", stderr );
  340. X        perror( argv[--optind] );
  341. X        exit(1);
  342. X    }
  343. X    if (optind < argc) {
  344. X        goto Usage;
  345. X    }
  346. X
  347. X
  348. X    /*  Read in the file a line at a time.  There are two kinds of lines:
  349. X     *  node lines and gateway lines.  While we are reading gateway lines
  350. X     *  we just read them in and save them.  Once we get a non-gateway
  351. X     *  line, we prune.
  352. X     */
  353. X
  354. X    /*  Read in all the domain gateways.
  355. X     */
  356. X    for (;;) {
  357. X        if (gets( linebuf ) == NULL)
  358. X            fatal("unexpected EOF");
  359. X        if (linebuf[0] != '.')
  360. X            break;
  361. X        gw_in++;
  362. X        add_gateway( linebuf );
  363. X    }
  364. X    if (rootnode == NULL)
  365. X        fatal("no domain gateways");
  366. X
  367. X    /*  Now prune out any unnecessary domain gateways.  They will be
  368. X     *  unnecessary if they are a subdomain and the path passes
  369. X     *  through the domain gateway.  We will leave alone any entries
  370. X     *  for ourselves (%s) because we may use them to qualify.
  371. X     */
  372. X    if ((p = look_node( &rootnode, UUCPNAME )) != NULL) {
  373. X        uucppath = p->pathname;
  374. X        p->flags |= SACRED_DOMAIN;
  375. X        if (p->flags & REMOVE_HOST)
  376. X            flg_removeuucp++;
  377. X    }
  378. X    if ((p = look_node( &rootnode, OTHERNAME )) != NULL) {
  379. X        if (flg_topdel)
  380. X            otherpath = p->pathname;
  381. X        if (p->flags & SACRED_DOMAIN)
  382. X            flg_dontprune++;
  383. X        p->flags |= SACRED_DOMAIN;
  384. X    }
  385. X
  386. X    if (!flg_dontprune)
  387. X        prune_gateway( rootnode, otherpath );
  388. X
  389. X    /*  Now print out the gateway entries in the original order.
  390. X     */
  391. X    for ( p = firstnode; p != NULL; p = p->order ) {
  392. X        if (p->line != NULL) {
  393. X            gw_out++;
  394. X            VOID puts( p->line );
  395. X        }
  396. X    }
  397. X
  398. X    /*  All the remaining lines in the file will be node names.
  399. X     *  Look up the domain name to see what gateway we would use;
  400. X     *  If the gateway is on the path to the node name then we do
  401. X     *  not need this entry.
  402. X     *  If they are simple node names we have to pass them right
  403. X     *  through unless we have a usefull ".uucp" gateway along
  404. X     *  the way.
  405. X     */
  406. X    for (;;) {
  407. X        check_needed( linebuf );
  408. X
  409. X        /*  Now get another line.
  410. X         */
  411. X        if (gets( linebuf ) == NULL)
  412. X            break;
  413. X        if (linebuf[0] == '.')
  414. X            fatal("unexpected domain gateway");
  415. X    }
  416. X
  417. X    if (flg_verbose) {
  418. X        VOID fprintf(stderr,"gateway\t%8d%8d\t%5.2f\n",
  419. X            gw_in, gw_out, (double)gw_out / (double)gw_in );
  420. X        VOID fprintf(stderr,"domain\t%8d%8d\t%5.2f\n",
  421. X            dom_in, dom_out, (double)dom_out / (double)dom_in );
  422. X        VOID fprintf(stderr,"host\t%8d%8d\t%5.2f\n",
  423. X            hst_in, hst_out, (double)hst_out / (double)hst_in );
  424. X    }
  425. X
  426. X    exit(0);
  427. X}
  428. X
  429. X
  430. Xdomflag( name, flags )
  431. Xregister char *name;
  432. Xint flags;
  433. X{
  434. X    register struct dnode **pp;
  435. X    register struct dnode *p;
  436. X    register char *s;
  437. X
  438. X    pp = &rootnode;
  439. X    while ((s = strrchr( name, '.' )) != NULL) {
  440. X        *s++ = '\0';    /* to most significant part of domain name */
  441. X        p = add_node( pp, s );
  442. X        pp = &(p->children);
  443. X    }
  444. X    if (*name)
  445. X        p = add_node( pp, name );
  446. X
  447. X    p->flags |= flags;
  448. X}
  449. X
  450. Xadd_gateway( buf )
  451. Xregister char *buf;
  452. X{
  453. X    register struct dnode **pp;
  454. X    register struct dnode *p;
  455. X    register char *s;
  456. X    char * line;
  457. X    char * gw;
  458. X    char * path;
  459. X
  460. X    /*  Save the original line because we will need it later.
  461. X     */
  462. X    line = stralloc( buf );
  463. X
  464. X    if ((gw = strtok( buf, " \t" )) == NULL)
  465. X        fatal("missing gateway on line");
  466. X    gw = stralloc( gw );
  467. X    if ((path = strtok( (char *)NULL, " \t" )) == NULL)
  468. X        fatal("missing path on gateway line");
  469. X    path = stralloc( path );
  470. X
  471. X    /*  Go down through all the nodes looking for this one.
  472. X     *  We won't actually find it but will create everything
  473. X     *  along the way.
  474. X     */
  475. X    pp = &rootnode;
  476. X    while ((s = strrchr( buf, '.' )) != NULL) {
  477. X        *s++ = '\0';    /* to most significant part of domain name */
  478. X        p = add_node( pp, s );
  479. X        pp = &(p->children);
  480. X    }
  481. X
  482. X    /*  Make sure that this one hasn't already been used.
  483. X     */
  484. X    if (p->line != NULL)
  485. X        fatal("duplicate gateway name found");
  486. X    p->line = line;
  487. X    p->fullname = gw;
  488. X    p->pathname = path;
  489. X
  490. X    /*  Build the correct pointers so we can process these nodes
  491. X     *  in the original order when it comes time to print them
  492. X     *  back out.
  493. X     */
  494. X    if (firstnode == NULL)
  495. X        firstnode = p;
  496. X    if (lastnode != NULL)
  497. X        lastnode->order = p;
  498. X    lastnode = p;
  499. X}
  500. X
  501. X
  502. Xstruct dnode *
  503. Xlook_node( pp, name )
  504. Xregister struct dnode **pp;
  505. Xregister char *name;
  506. X{
  507. X    register i;
  508. X    /*  Search down the node tree looking for a node with the
  509. X     *  given name.
  510. X     */
  511. X    while (*pp != NULL) {
  512. X        i = strcmp( name, (*pp)->nodename );
  513. X        if (i == 0)
  514. X            return (*pp);
  515. X        else if (i < 0)
  516. X            pp = &((*pp)->lnode);
  517. X        else
  518. X            pp = &((*pp)->bnode);
  519. X    }
  520. X    return (NULL);
  521. X}
  522. X
  523. Xstruct dnode *
  524. Xadd_node( pp, name )
  525. Xregister struct dnode **pp;
  526. Xregister char *name;
  527. X{
  528. X    register i;
  529. X    /*  Search down the node tree looking for a node with the
  530. X     *  given name.
  531. X     */
  532. X    while (*pp != NULL) {
  533. X        i = strcmp( name, (*pp)->nodename );
  534. X        if (i == 0)
  535. X            return (*pp);
  536. X        else if (i < 0)
  537. X            pp = &((*pp)->lnode);
  538. X        else
  539. X            pp = &((*pp)->bnode);
  540. X    }
  541. X
  542. X    /*  Couldn't find such a node, so create one.
  543. X     */
  544. X    *pp = (struct dnode *) calloc( 1, sizeof(struct dnode) );
  545. X    if (*pp == NULL)
  546. X        fatal("cannot allocate node");
  547. X    (*pp)->nodename = stralloc( name );
  548. X    return (*pp);
  549. X}
  550. X
  551. Xprune_gateway( p, parpath )
  552. Xregister struct dnode *p;
  553. Xregister char *parpath;        /* parents path */
  554. X{
  555. X    register parlen = strlen( parpath ) - 2;
  556. X    while (p != NULL) {
  557. X        /*  Do the left side of the tree first.
  558. X         */
  559. X        prune_gateway( p->lnode, parpath );
  560. X
  561. X        /*  Check to see if we share a common path with our
  562. X         *  parent.  If we do this is a redundant gateway and
  563. X         *  can be eliminated.
  564. X         */
  565. X        if ( (parlen <= 0) || (p->line == NULL) ||
  566. X             (p->flags & SACRED_DOMAIN) ||
  567. X             (strcmp( p->pathname, "%s" ) == 0) ) {
  568. X            /*  We leave these alone.
  569. X             */
  570. X        } else if (strncmp( p->pathname, parpath, parlen ) == 0) {
  571. X            /*  This is not one we need to know.  Remove it
  572. X             *  from the ranks of the living.
  573. X             */
  574. X            p->line = NULL;
  575. X        }
  576. X
  577. X        /*  Check our subdomains for uselessness.
  578. X         */
  579. X        if (!(p->flags & SACRED_DOMAIN))
  580. X            prune_gateway( p->children,
  581. X                       (p->line) ? p->pathname : parpath );
  582. X
  583. X        /*  Do the right side of the tree using tail
  584. X         *  recursion.
  585. X         */
  586. X        p = p->bnode;
  587. X    }
  588. X}
  589. X
  590. X
  591. Xcheck_needed( buf )
  592. Xregister char *buf;
  593. X{
  594. X    register struct dnode **pp;
  595. X    register struct dnode *p;
  596. X    register char *s;
  597. X    char * path;
  598. X    char * gwpath;
  599. X    int    isdomain;
  600. X    char    tmpbuf[BUFSIZ];
  601. X
  602. X    VOID strcpy( tmpbuf, buf );
  603. X    /*  Extract the host/domain name.  */
  604. X    if (strtok( tmpbuf, " \t" ) == NULL)
  605. X        fatal("blank line");
  606. X    if (strchr( tmpbuf, '.' ) != NULL) {
  607. X        isdomain = 1;
  608. X        dom_in++;
  609. X    } else {
  610. X        isdomain = 0;
  611. X        hst_in++;
  612. X    }
  613. X    /*  Extract the path.  */
  614. X    if ((path = strtok( (char *)NULL, " \t" )) == NULL)
  615. X        fatal("missing path");
  616. X    if (strcmp(path, "%s") == 0) {
  617. X        /*  This is for us.  We don't dare delete it.
  618. X         */
  619. X        goto keep;
  620. X    }
  621. X
  622. X    /*  Go down through all the nodes looking for this one.
  623. X     *  We won't actually find it but will create everything
  624. X     *  along the way.
  625. X     */
  626. X    if (isdomain)
  627. X        gwpath = otherpath;    /*  It is in a domain.  */
  628. X    else if (flg_removeuucp)
  629. X        return;            /*  They all go away.  */
  630. X    else if (flg_uucpdel)
  631. X        gwpath = uucppath;    /*  .uucp may be sufficient  */
  632. X    else
  633. X        gwpath = NULL;        /*  Keep this one.  */
  634. X    pp = &rootnode;
  635. X    while ((s = strrchr( tmpbuf, '.' )) != NULL) {
  636. X        *s++ = '\0';    /* to most significant part of domain name */
  637. X        p = look_node( pp, s );
  638. X        if (p == NULL) {
  639. X            /*  Haven't seen this domain before.  If this is
  640. X             *  a bugs top-level domain name we want to junk it.
  641. X             */
  642. X            if (flg_junkbogus && pp == &rootnode)
  643. X                return;
  644. X            break;
  645. X        }
  646. X        if (p->flags & SACRED_HOST) {
  647. X            gwpath = NULL;
  648. X            break;
  649. X        }
  650. X        if (p->flags & REMOVE_HOST) {
  651. X            /*  Don't want any hosts in this domain.  */
  652. X            return;
  653. X        }
  654. X        if (p->line != NULL)
  655. X            gwpath = p->pathname;
  656. X        pp = &(p->children);
  657. X    }
  658. X
  659. X    if ( (gwpath == NULL) || (strcmp( gwpath, "%s" ) == 0) ||
  660. X         (strncmp( path, gwpath, strlen(gwpath)-2 ) != 0) ) {
  661. Xkeep:
  662. X        if (isdomain)    dom_out++;
  663. X        else        hst_out++;
  664. X        VOID puts( buf );
  665. X    }
  666. X}
  667. X
  668. Xchar *
  669. Xstralloc( str )
  670. Xchar *str;
  671. X{
  672. X    register char *s;
  673. X    if ((s = malloc( (unsigned)(strlen(str) + 1) )) == NULL)
  674. X        fatal("cannot allocate string");
  675. X    VOID strcpy( s, str );
  676. X    return (s);
  677. X}
  678. X
  679. Xfatal( reason )
  680. Xchar * reason;
  681. X{
  682. X    VOID fprintf(stderr,"pathprune: %s\n", reason );
  683. X    exit(1);
  684. X}
  685. SHAR_EOF
  686. exit 0
  687. -- 
  688. Matt Costello    <matt.costello@SanDiego.NCR.COM>
  689.         {sdcsvax,cbatt,dcdwest,nosc.ARPA,ihnp4}!ncr-sd!matt
  690.  
  691.  
  692.