home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume7 / news2path.edw < prev    next >
Encoding:
Text File  |  1989-07-21  |  12.2 KB  |  414 lines

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