home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume07 / newspath.edw < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  12.6 KB

  1. From decwrl!ucbvax!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!allbery Thu Aug  3 08:50:42 PDT 1989
  2. Article 985 of comp.sources.misc:
  3. Path: decwrl!ucbvax!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!allbery
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Newsgroups: comp.sources.misc
  6. Subject: v07i093: pathalias builder alternative.
  7. Keywords: /usr/lib/uucp/paths, pathalias program
  8. Message-ID: <61156@uunet.UU.NET>
  9. Date: 22 Jul 89 01:01:53 GMT
  10. Sender: allbery@uunet.UU.NET
  11. Reply-To: edw@wells.UUCP (Ed Wells)
  12. Organization: Wells Computer Systems Corp., Levittown, Pa. 19058
  13. Lines: 404
  14. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  15.  
  16. Posting-number: Volume 7, Issue 93
  17. Submitted-by: edw@wells.UUCP (Ed Wells)
  18. Archive-name: news2path.edw
  19.  
  20.   In order to create a pathalias file in a restricted space, I wrote a
  21. few programs that keep the intermediate files smaller.  I putting this
  22. in the public domain for others that may like to do the same.  See
  23. the 'read.me' file in the shar archive for more information.
  24.  
  25.   A few things that I will be adding in the future myself is the ability
  26. to build pathalias files for several systems without having to rebuild
  27. the intermediate file again (20/20 hind site ya' know!).
  28.  
  29.   If you add anything to this, please send it back to me.
  30.  
  31.  
  32. ---- Cut Here and unpack ----
  33. #!/bin/sh
  34. # shar:    Shell Archiver  (v1.22)
  35. #
  36. #    Run the following text with /bin/sh to create:
  37. #      read.me
  38. #      pa.paths
  39. #      usa.paths
  40. #      news2path.c
  41. #
  42. if test -f read.me; then echo "File read.me exists"; else
  43. sed 's/^X//' << 'SHAR_EOF' > read.me &&
  44. X
  45. X
  46. X
  47. X
  48. X
  49. X
  50. X
  51. X                          Wells Computer Systems Corp.
  52. X                         Box 343, Levittown, Pa. 19058
  53. X                                 (215)-943-6061
  54. X
  55. X
  56. X
  57. X
  58. X         Here's a little program that I wrote to use the information  stored
  59. X    in  /usr/spool/news/comp/mail/maps/*  directly without having to build a
  60. X    second set of files nearly totaling the same size.
  61. X
  62. X         This program extracts  only  the  information  that  is  needed  to
  63. X    rebuild  a  pathalias file.  It extracts from whatever files are present
  64. X    removing the headers, shar information and all lines that start  with  a
  65. X    '#'  sign.  This leaves only the minimal amount of information needed to
  66. X    start building a paths file.
  67. X
  68. X         I also have two shell scripts that I have provided.  Both of  these
  69. X    shell  programs  accept  one  argument  which is the target system name.
  70. X    Each shell is used to filter the listing down to either just 'usa' list-
  71. X    ings  or 'usa.pa' (Pennsylvania) listings.  I also have the program look
  72. X    for a file named 'local.$1' where $1 gets replaced with the target  name
  73. X    I  am building a file for.  It's in this file that I normally put all of
  74. X    the unlisted/private/local connections to each system that I am building
  75. X    a  paths  file  for.   I also list the 'smart-host' system here also for
  76. X    each system.
  77. X
  78. X         When I'm done, I just take the file named 'paths.$1' (where  $1  is
  79. X    replaced  with the target name) and install it in my /usr/lib/uucp/paths
  80. X    file or send it to the remote site requiring a path.
  81. X
  82. X         This program also requires 3 programs from the  public  domain  for
  83. X    processing  this  information  to  its  final  output.   These  are  the
  84. X    'pathalias', 'pathproc' and 'pathprune' programs.
  85. X
  86. X         This source code is the property of Wells  Computer  Systems  Corp.
  87. X    and  is  being  released  to the Usenet community for any not-for-profit
  88. X    use.
  89. X
  90. X         If you add anything to this, please submit it back to me.
  91. X
  92. X
  93. X
  94. X                                  Enjoy,
  95. X                                       Ed Wells, President
  96. X
  97. X
  98. X
  99. X
  100. X
  101. X
  102. X
  103. X
  104. X
  105. X
  106. X
  107. X                                 July 14, 1989
  108. X
  109. X
  110. SHAR_EOF
  111. chmod 0640 read.me || echo "restore of read.me fails"
  112. set `wc -c read.me`;Sum=$1
  113. if test "$Sum" != "2170"
  114. then echo original size 2170, current size $Sum;fi
  115. fi
  116. if test -f pa.paths; then echo "File pa.paths exists"; else
  117. sed 's/^X//' << 'SHAR_EOF' > pa.paths &&
  118. X#
  119. X# Program name = "pa.paths"
  120. X# @(#)pa.paths    1.7
  121. X# Written by:    Ed Wells, President, Wells Computer Systems Corp.
  122. X#        Wells Computer Systems Corp., Box 343, Levittown, Pa. 19058
  123. X#        (215)-943-6061, Voice
  124. X#        (215)-943-0435, (Data Telebit 19200-1200)
  125. X#        Usenet:    wells!edw / edw@wells
  126. X#        UNIX System V 3.1  /  SCO Xenix V
  127. X#
  128. X# Original date .....    Sat Jan 14 13:47:16 EST 1989
  129. X# Last update     .....    Sat Jan 14 13:47:16 EST 1989 (before SCCS)
  130. X# SCCS delta date ...  3/21/89 -- 10:19:55
  131. X# SCCS extracted  ...  7/14/89 -- 05:55:43
  132. X#
  133. X# Program description    : Used to generate paths for Pennsylvania only.
  134. X#    Inputs        : target system name from standard input.
  135. X#    Outputs        : paths.{target_name}
  136. X#    Status/Errors    : Standard error
  137. X#    Files accessed    : See program
  138. X#    NOTE        : A filename called "local.{target_name} must exist
  139. X#                with a list of locally known systems.
  140. X#
  141. Xsccsid="@(#)pa.paths    1.7 3/21/89\n"
  142. XREVID="Revision 1.7 3/21/89\n"
  143. X#
  144. Xif [ $# -ne 1 ]
  145. X    then    echo "Usage: $0 target_system_name" ; exit 1
  146. Xfi
  147. X#
  148. XNEWS=/usr/spool/news
  149. XLIMIT='.usa.pa.'
  150. XLOCAL="local.$1 ../mail/MY.USENET.REG"
  151. XSELFILE=/ram/sel.file
  152. XTMPFILE=/ram/d.paths
  153. Xtrap "rm -f pp paths $SELFILE $TMPFILE ; exit" 0 1 2 3 15
  154. X#
  155. Xecho "Creating a list of filename to use."
  156. Xfind $NEWS/comp/mail/maps -type f -print >$SELFILE
  157. X#
  158. X# Now create one merged file from the list in $SELFILE.
  159. X#
  160. Xecho "Creating a combined list from the \"$NEWS/comp/mail/maps\" directory"
  161. Xecho "All news/shar headers will be extracted leaving only the file."
  162. Xnews2path $LIMIT <$SELFILE >$TMPFILE
  163. Xrm $SELFILE
  164. X#
  165. Xecho "Using \"pathalias\" to process the combined file."
  166. Xpathalias -fv -l $1 $TMPFILE $LOCAL > paths
  167. X#
  168. Xecho "Using \"pathproc\" to sort/order the file."
  169. Xpathproc < paths > pp
  170. Xif [ ! -s pp ]
  171. Xthen
  172. X    echo pathproc error
  173. X    mv paths pp
  174. Xfi
  175. Xecho "Delete entries not needed with \"pathprune\"."
  176. Xpathprune -v < pp > paths
  177. Xif [ -s paths ]
  178. Xthen
  179. X    rm -f pp
  180. Xelse
  181. X    echo pathprune error
  182. X    mv pp paths
  183. Xfi
  184. X
  185. Xmv paths paths.$1
  186. Xecho "Your completed file is in \"paths.$1\"."
  187. Xexit 0
  188. SHAR_EOF
  189. chmod 0444 pa.paths || echo "restore of pa.paths fails"
  190. set `wc -c pa.paths`;Sum=$1
  191. if test "$Sum" != "1975"
  192. then echo original size 1975, current size $Sum;fi
  193. fi
  194. if test -f usa.paths; then echo "File usa.paths exists"; else
  195. sed 's/^X//' << 'SHAR_EOF' > usa.paths &&
  196. X#
  197. X# Program name = "usa.paths"
  198. X# @(#)usa.paths    1.9
  199. X# Written by:    Ed Wells, President, Wells Computer Systems Corp.
  200. X#        Wells Computer Systems Corp., Box 343, Levittown, Pa. 19058
  201. X#        (215)-943-6061, Voice
  202. X#        (215)-943-0435, (Data Telebit 19200-1200)
  203. X#        Usenet:    wells!edw / edw@wells
  204. X#        UNIX System V 3.1  /  SCO Xenix V
  205. X#
  206. X# Original date .....    Sat Jan 14 13:47:16 EST 1989
  207. X# Last update     .....    Sat Jan 14 13:47:16 EST 1989 (before SCCS)
  208. X# SCCS delta date ...  3/21/89 -- 12:38:26
  209. X# SCCS extracted  ...  7/14/89 -- 05:55:43
  210. X#
  211. X# Program description    : Used to generate paths for USA only.
  212. X#    Inputs        : target system name from standard input.
  213. X#    Outputs        : paths.{target_name}
  214. X#    Status/Errors    : Standard error
  215. X#    Files accessed    : See program
  216. X#    NOTE        : A filename called "local.{target_name} must exist
  217. X#                with a list of locally known systems.
  218. X#
  219. Xsccsid="@(#)usa.paths    1.9 3/21/89\n"
  220. XREVID="Revision 1.9 3/21/89\n"
  221. X#
  222. Xif [ $# -ne 1 ]
  223. X    then    echo "Usage: $0 target_system_name" ; exit 1
  224. Xfi
  225. X#
  226. XNEWS=/usr/spool/news
  227. XLIMIT='.usa.'
  228. XLOCAL="local.$1 ../mail/MY.USENET.REG"
  229. XSELFILE=/tmp/sel.file
  230. XTMPFILE=/tmp/d.paths
  231. Xtrap "rm -f pp paths $SELFILE $TMPFILE ; exit" 0 1 2 3 15
  232. X#
  233. Xecho "Creating a list of filename to use."
  234. Xfind $NEWS/comp/mail/maps -type f -print >$SELFILE
  235. X#
  236. X# Now create one merged file from the list in $SELFILE.
  237. X#
  238. Xecho "Creating a combined list from the \"$NEWS/comp/mail/maps\" directory"
  239. Xecho "All news/shar headers will be extracted leaving only the file."
  240. Xnews2path $LIMIT <$SELFILE >$TMPFILE
  241. Xrm $SELFILE
  242. X#
  243. Xecho "Using \"pathalias\" to process the combined file."
  244. Xpathalias -fv -l $1 $TMPFILE $LOCAL > paths
  245. X#
  246. Xecho "Using \"pathproc\" to sort/order the file."
  247. Xpathproc < paths > pp
  248. Xif [ ! -s pp ]
  249. Xthen
  250. X    echo pathproc error
  251. X    mv paths pp
  252. Xfi
  253. Xecho "Delete entries not needed with \"pathprune\"."
  254. Xpathprune -v < pp > paths
  255. Xif [ -s paths ]
  256. Xthen
  257. X    rm -f pp
  258. Xelse
  259. X    echo pathprune error
  260. X    mv pp paths
  261. Xfi
  262. X
  263. Xmv paths paths.$1
  264. Xecho "Your completed file is in \"paths.$1\"."
  265. Xexit 0
  266. SHAR_EOF
  267. chmod 0444 usa.paths || echo "restore of usa.paths fails"
  268. set `wc -c usa.paths`;Sum=$1
  269. if test "$Sum" != "1966"
  270. then echo original size 1966, current size $Sum;fi
  271. fi
  272. if test -f news2path.c; then echo "File news2path.c exists"; else
  273. sed 's/^X//' << 'SHAR_EOF' > news2path.c &&
  274. X/*
  275. X * Program name = "news2path.c"
  276. X * @(#)news2path.c    1.3
  277. X * Written by:    Ed Wells, President, Wells Computer Systems Corp.
  278. X *        Wells Computer Systems Corp., Box 343, Levittown, Pa. 19058
  279. X *        (215)-943-6061, Voice
  280. X *        (215)-943-0435, (Data Telebit 19200-1200)
  281. X *        Usenet:    wells!edw / edw@wells
  282. X *        UNIX System V 3.1  /  SCO Xenix V
  283. X *
  284. X * Original date .....    Fri Jan 13 09:18:25 EST 1989
  285. X * Last update     .....    Fri Jan 13 09:18:25 EST 1989 (before SCCS)
  286. X * SCCS delta date ...  3/21/89 -- 11:09:09
  287. X * SCCS extracted  ...  3/21/89 -- 11:09:31
  288. X *
  289. X * Program description    : Used to extract header information off of files in
  290. X *            :    the /usr/spool/news/comp/mail/maps directory
  291. X *            :    and provide a processed file for 'pathalias'.
  292. X *    Inputs        : a list of filename(s) on stdin.
  293. X *    Outputs        : stdout
  294. X *    Errors        : stderr
  295. X */
  296. X
  297. X    static    char    sccsid[] = "@(#)news2path.c    1.3 3/21/89\n";
  298. X    static    char    REVID[] = "Revision 1.3 3/21/89\n";
  299. X
  300. X#define    BSIZE        256
  301. X#define    ENDSHAR        "SHAR_EOF"
  302. X#define    LIMITLINE    "echo shar: extracting "
  303. X#define    STR1        "echo"
  304. X#define    STR2        "shar:"
  305. X#define    STR3        "extracting"
  306. X
  307. X#ifndef    FALSE
  308. X#define    FALSE    0
  309. X#endif
  310. X
  311. X#ifndef    TRUE
  312. X#define    TRUE    !FALSE
  313. X#endif
  314. X
  315. X#include    <stdio.h>
  316. X#include    <ctype.h>
  317. X
  318. Xmain(ac, av)
  319. X    int    ac;
  320. X    char    *av[];
  321. X{
  322. X    FILE    *fp, *fopen();
  323. X    char    fname[BSIZE], buf[BSIZE], buf2[BSIZE], *cp, *cp1;
  324. X    char    *fgets(), *strcpy(), *strtok();
  325. X    int    strcmp();
  326. X    int    i, j, firstline;
  327. X
  328. X    if (ac != 2) {
  329. X        fprintf(stderr, "Usage: %s (LIMIT_STRING)\n", av[0]);
  330. X        fprintf(stderr,
  331. X"LIMIT_STRING selects/rejects the file based on finding a matching string\n");
  332. X        fprintf(stderr, "\tUses standard in/out and error.\n\n");
  333. X        fprintf(stderr, "\tstdin  - list of filename(s) to open.\n");
  334. X        fprintf(stderr, "\tstdout - data for 'pathalias'.\n");
  335. X        fprintf(stderr, "\tstderr - Status information.\n");
  336. X        fprintf(stderr,
  337. X"Example: %s u.usa.pa\n", av[0]);
  338. X        exit(1);
  339. X    }
  340. X/*
  341. X * Read while filenames are available on stdin.
  342. X */
  343. X    while ( fscanf(stdin, "%s", fname) > 0) {
  344. X        if ( (fp=fopen(fname, "r")) == NULL) {
  345. X            fprintf(stderr, "ERROR: Can open file (%s)\n", fname);
  346. X            exit(2);
  347. X        }
  348. X        fprintf(stderr, "\"%s\" opened for processing..... ", fname);
  349. X/*
  350. X * Read up until the LIMITLINE is found (or EOF).
  351. X */
  352. X        while (fgets(buf, BSIZE, fp) != NULL) {
  353. X            if (!strncmp(buf, LIMITLINE, strlen(LIMITLINE)))
  354. X                goto select;
  355. X        }
  356. X        fprintf(stderr, "ERROR: LIMIT_STRING missing.\n");
  357. X        exit(2);
  358. X/*
  359. X * Find out if this file should be select (in which case we continue)
  360. X * or rejected.
  361. X */
  362. X    select:
  363. X        cp = buf;
  364. X        while ( (cp1 = strtok(cp, " \r\n")) != NULL ) {
  365. X            strcpy(buf2, cp1);
  366. X            cp = NULL;
  367. X            if (!strcmp(buf2, STR1))
  368. X                continue;
  369. X            if (!strcmp(buf2, STR2))
  370. X                continue;
  371. X            if (!strcmp(buf2, STR3))
  372. X                continue;
  373. X            if ( instr(buf2, av[1]) >= 0 ) {
  374. X                fprintf(stderr, "\t\tSelected!  Proceeding.\n");
  375. X                break;    /* Quit "while" loop, and continue */
  376. X            } else {
  377. X                fprintf(stderr, "\t\tFile ignored!\n");
  378. X                goto nextfile;
  379. X            }
  380. X        }
  381. X/*
  382. X * Read until the first understandable line shows up.
  383. X */
  384. X        firstline = FALSE;
  385. X        while( fgets(buf, BSIZE, fp) != NULL ) {
  386. X            if (buf[0] == '#' && isalpha(buf[1]) &&
  387. X                (buf[2] == ' ' || buf[2] == '\t') ) {
  388. X                firstline = TRUE;
  389. X                break;
  390. X            }
  391. X        }
  392. X
  393. X        while ( fgets(buf, BSIZE, fp) != NULL ) {
  394. X            if ( !strncmp(buf, ENDSHAR, 8) )
  395. X                goto nextfile; /* We are done with this file */
  396. X            if (!strlen(buf))
  397. X                continue;     /* This one is blank    */
  398. X            if (buf[0] == '#')
  399. X                continue;    /* This isn't for us    */
  400. X            fputs(buf, stdout);
  401. X        }
  402. Xnextfile: fclose(fp);
  403. X    }
  404. X    fprintf(stderr,"\n\tSelecting complete\n");
  405. X    exit(0);
  406. X}
  407. SHAR_EOF
  408. chmod 0440 news2path.c || echo "restore of news2path.c fails"
  409. set `wc -c news2path.c`;Sum=$1
  410. if test "$Sum" != "3539"
  411. then echo original size 3539, current size $Sum;fi
  412. fi
  413. exit 0
  414.  
  415. -- 
  416. =========================================================================
  417. Edward E. Wells Jr., President                Voice: (215)-943-6061
  418. Wells Computer Systems Corp., Box 343, Levittown, Pa. 19058
  419. {dsinc,francis,hotps,houxl,lgnp1,mdi386,pebco}!wells!edw
  420.  
  421.  
  422.