home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / unix / volume26 / uuhost_2.1 < prev    next >
Encoding:
Text File  |  1992-04-18  |  27.0 KB  |  1,041 lines

  1. Newsgroups: comp.sources.unix
  2. From: jpm@Logix.DE (Jan-Piet Mens)
  3. Subject: v26i018: uuhost - lookup UUCP mail and USENET information
  4. Sender: unix-sources-moderator@pa.dec.com
  5. Approved: vixie@pa.dec.com
  6.  
  7. Submitted-By: jpm@Logix.DE (Jan-Piet Mens)
  8. Posting-Number: Volume 26, Issue 18
  9. Archive-Name: uuhost-2.1
  10.  
  11. [ this package is similar but unrelated to the "uuhosts" program in
  12.   volumes 2 and 3.  --vix ]
  13.  
  14. It is a new [and as far as I'm concerned, better :-] program.
  15. It needs not run as root, the databases are smaller (text only),
  16. and does more for me than all others have done so far :-)
  17.  
  18. Uuhost reads the UUCP maps which live in a directory, and builds a
  19. smallish database, containing just enough data to read the UUCP and
  20. USENET information from the maps.
  21.  
  22.     jpm@Logix.DE (Jan-Piet Mens)
  23.  
  24. #! /bin/sh
  25. # This is a shell archive.  Remove anything before this line, then unpack
  26. # it by saving it into a file and typing "sh file".  To overwrite existing
  27. # files, type "sh file -c".  You can also feed this as standard input via
  28. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  29. # will see the following message at the end:
  30. #        "End of shell archive."
  31. # Contents:  README Copyright Makefile patchlevel.h uuhost.N uuhost.S
  32. #   uulookup.c uusplit.c
  33. # Wrapped by vixie@cognition.pa.dec.com on Sun Apr 19 13:41:09 1992
  34. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  35. if test -f 'README' -a "${1}" != "-c" ; then 
  36.   echo shar: Will not clobber existing file \"'README'\"
  37. else
  38. echo shar: Extracting \"'README'\" \(3609 characters\)
  39. sed "s/^X//" >'README' <<'END_OF_FILE'
  40. UUHOST 2.1
  41. X==========
  42. X    
  43. X    This is uuhost 2.1
  44. X
  45. X    It is a new [and as far as I'm concerned, better :-] program.
  46. X    It needs not run as root, the databases are smaller (text only),
  47. X    and does more for me than all others have done so far :-)
  48. X
  49. X    Uuhost reads the UUCP maps which live in a directory, and builds a
  50. X    smallish database, containing just enough data to read the UUCP and
  51. X    USENET information from the maps.
  52. X    
  53. X    - Edit the Makefile. Set the variables described at the top of the
  54. X      Makefile to desired values.
  55. X
  56. X    - Do a `make'. This should produce 
  57. X        uusplit        executable
  58. X        uulookup    executable
  59. X        uuhost        shell-script
  60. X        uuhost.1    manual page
  61. X
  62. X    - Do a "make install"
  63. X      This will copy  the uuhost program to your LOCALBIN directory, 
  64. X      uusplit to your BINDIR directory, and uulookup to your
  65. X      LOOKUPBINDIR directory. Note: Neither BINDIR nor LOOKUPBINDIR
  66. X      need not be in the user's path.
  67. X      Please install the manual page `uuhost.1' manually.
  68. X
  69. X    - Run "uuhost -l"   It should show you a list of contents of your
  70. X      maps directory.
  71. X
  72. X    - Try "uuhost -r u.usa.ca.1" or similar. That should work too.
  73. X
  74. X    - Now run "uuhost -index" This will take a while. The index is
  75. X      being built. (should not take much longer than five minutes)
  76. X
  77. X    - Try "uuhost hostname" where hostname is a host that you know 
  78. X      about.
  79. X
  80. X    - Set up "uuhost -index" so that it runs once a day. This can be
  81. X      done via crontab:
  82. X
  83. X        00  07  *  *  *  uuhost -index
  84. X
  85. X
  86. X    - Congratulations. Finished.
  87. X
  88. X    - If you have problems, bugs or suggestions,  please contact me. 
  89. X        My name is  Jan-Piet Mens, and my address is
  90. X        <jpm@Logix.DE>
  91. X        
  92. INTERNALS
  93. X=========
  94. X
  95. uuhost -index
  96. X=============
  97. X
  98. This program reads all files in the MAPSDIR directory.
  99. Here is the map entry from the file `u.deu.2' (line 1451) for my site:
  100. X
  101. X    #N    logixwi, logix.de, .logix.de
  102. X    #S    Tandon 486/25;SCO UNIX 3.2.2
  103. X    #O    Logix GmbH
  104. X    #C    Jan-Piet Mens
  105. X    #E    postmaster@logixwi.logix.de
  106. X    #T    +49 611 309797
  107. X    #P    Moritzstrasse 50, D-W-6200 Wiesbaden, Germany
  108. X    #L
  109. X    #W    cs@Germany.EU.net; 910228 / bs@Germany.EU.net ; 911016
  110. X    #U    unido
  111. X    #
  112. X    logixwi    unido(HOURLY)
  113. X    logixwi    .logix.de
  114. X
  115. The `#N' entry contains three names (I call them hostnames, although that
  116. is not quite correct :-) 
  117. The `uusplit' program gets the `#N' line passed to it, prepended by  a 
  118. line number (produced by grep). It will split that line into individual
  119. hostnames, producing:
  120. X
  121. X    logixwi    u.deu.2    1451
  122. X    logix.de    u.deu.2    1451
  123. X    .logix.de    u.deu.2    1451
  124. X
  125. These lines are put into the UUHOSTINDEX database. `uuhost -index' does
  126. this for each `#N' in all files in the MAPSDIR directory. The database is
  127. then sorted by the first field.
  128. X
  129. When `uuhost' looks for a hostname, it parses (with help of `uulookup') the
  130. database, finds (or doesn't) the desired entry, and Charly 's your uncle.
  131. X
  132. Problems, Praise & Bugs
  133. X=======================
  134. X    Please direct these to  Jan-Piet Mens <jpm@Logix.DE>
  135. X
  136. Thanks! to ...
  137. X==============
  138. X
  139. Mon Oct 21 20:38:26 MET 1991
  140. X    From: btr.com!thad (Thaddeus P. Floryan)
  141. X    Message-Id: <9110211245.AA09299@public.BTR.COM>
  142. X
  143. X    One comment: on my systems (3B1, CT MightyFrame, etc.) the 
  144. X    "uuhost -index" would abort due to "Cannot fork: too many processes."
  145. X
  146. X    Finally discovered the problem to be ksh.  By using /bin/sh it 
  147. X    worked fine per:
  148. X
  149. X        $ sh uuhost -index
  150. X
  151. X    Thanks for the great program!
  152. X
  153. X    Thad Floryan [ thad@btr.com (OR) {decwrl, mips, fernwood}!btr!thad ]
  154. X
  155. Tue Oct 22 18:28:27 MET 1991
  156. X    Thad Floryan [ thad@btr.com (OR) {decwrl, mips, fernwood}!btr!thad ]
  157. X    Added #F expansion.
  158. X
  159. Tue Oct 22 19:15:05 MET 1991
  160. X    <pat@rwing>  (Pat Myrto)
  161. X    "Suggest adding option to produce mail address. "
  162. X    I've added -u for doing it. Thanks.
  163. END_OF_FILE
  164. if test 3609 -ne `wc -c <'README'`; then
  165.     echo shar: \"'README'\" unpacked with wrong size!
  166. fi
  167. # end of 'README'
  168. fi
  169. if test -f 'Copyright' -a "${1}" != "-c" ; then 
  170.   echo shar: Will not clobber existing file \"'Copyright'\"
  171. else
  172. echo shar: Extracting \"'Copyright'\" \(403 characters\)
  173. sed "s/^X//" >'Copyright' <<'END_OF_FILE'
  174. X/*
  175. X * UUHOST, Copyright 1992,   Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany]
  176. X * License to freely use and distribute this software is hereby granted 
  177. X * by the author, subject to the condition that this copyright notice 
  178. X * remains intact.  The author retains the exclusive right to publish 
  179. X * derivative works based on this work, including, but not limited
  180. X * to, revised versions of this work.
  181. X */
  182. END_OF_FILE
  183. if test 403 -ne `wc -c <'Copyright'`; then
  184.     echo shar: \"'Copyright'\" unpacked with wrong size!
  185. fi
  186. # end of 'Copyright'
  187. fi
  188. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  189.   echo shar: Will not clobber existing file \"'Makefile'\"
  190. else
  191. echo shar: Extracting \"'Makefile'\" \(3730 characters\)
  192. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  193. X# UUHOST, Copyright 1991,   Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany]
  194. X# License to freely use and distribute this software is hereby granted 
  195. X# by the author, subject to the condition that this copyright notice 
  196. X# remains intact.  The author retains the exclusive right to publish 
  197. X# derivative works based on this work, including, but not limited
  198. X# to, revised versions of this work.
  199. X#        Jan-Piet Mens <jpm@Logix.DE>
  200. X#
  201. X# Define MAPSDIR to be the directory in which your maps are kept.
  202. X#
  203. X#MAPSDIR=/usr/spool/maps
  204. MAPSDIR=/u/local/lib/uucpmaps/uucpmap
  205. X
  206. X# Define UUHOSTINDEX to the location of the UUHOST index file.
  207. X#
  208. UUHOSTINDEX=/u/local/lib/uuhostindex
  209. X
  210. X# LOCALBIN is for the `uuhost' program only. All others go into BINDIR.
  211. X# This directory *should* be in a user's path.
  212. X#
  213. LOCALBIN=/u/local/bin
  214. X
  215. X# Define BINDIR to be the directory into which targets are copied upon
  216. X#  a make install. This directory need _not_ be in a user's $PATH.
  217. X#
  218. BINDIR=/u/local/lib/uucpmaps/bin
  219. X
  220. X# Define LOOKUPBINDIR to be the directory into which the `uulookup' program
  221. X# is copied. Some people like this in their path.
  222. X#
  223. LOOKUPBINDIR=$(LOCALBIN)
  224. X#LOOKUPBINDIR=$(BINDIR)
  225. X
  226. X# Define PATHALIAS to be the name of your pathalias file
  227. X#
  228. X#PATHALIAS=/usr/lib/uucp/paths.uucp
  229. PATHALIAS=/u/local/lib/pathalias
  230. X
  231. X# Define PATHLOOKUP to the the program that gets a hostname, and returns
  232. X# the uucp mail path to that host.
  233. X#
  234. PATHLOOKUP=$(LOOKUPBINDIR)/uulookup -m 
  235. X
  236. X# Define CATPROG to be the program with which to view the u.* maps. If the
  237. X# maps are compressed [which I highly recommend] use `zcat'. Otherwise `cat'.
  238. X#
  239. X#CATPROG=cat
  240. CATPROG=zcat
  241. X
  242. X# LOOKPROG is a program which returns the entry from UUHOSTINDEX
  243. X#
  244. LOOKPROG=$(LOOKUPBINDIR)/uulookup -h 
  245. X
  246. X# The name of your preferred pager (pg,more,less,...,cat ?)
  247. X#
  248. PAGEPROG="less"
  249. X
  250. X# Add -DNEED_STRINGS_H to CFLAGS if you have <strings.h> instead of <string.h>
  251. X#
  252. CC=cc
  253. CFLAGS=-O -s
  254. LIBS=
  255. X
  256. SRCS=uusplit.c uulookup.c
  257. SHARFILES=README Makefile Copyright uuhost.S uuhost.N
  258. HFILES= patchlevel.h
  259. X
  260. all: uusplit uulookup uuhost uuhost.1
  261. X
  262. uuhost: uuhost.S Makefile
  263. X    sed     -e 's|__MAPSDIR__|$(MAPSDIR)|g' \
  264. X        -e 's|__CATPROG__|$(CATPROG)|g'    \
  265. X        -e 's|__PAGEPROG__|$(PAGEPROG)|g' \
  266. X        -e 's|__PATHLOOKUP__|$(PATHLOOKUP)|g' \
  267. X        -e 's|__LOOKPROG__|$(LOOKPROG)|g' \
  268. X        -e 's|__LOOKUPBINDIR__|$(LOOKUPBINDIR)|g'   \
  269. X        -e 's|__BINDIR__|$(BINDIR)|g'   \
  270. X        -e 's|__UUHOSTINDEX__|$(UUHOSTINDEX)|g'    uuhost.S > uuhost
  271. X    chmod +x uuhost
  272. X
  273. uuhost.1: uuhost.N Makefile
  274. X    rm -f uuhost.1
  275. X    sed     -e 's|__MAPSDIR__|$(MAPSDIR)|g' \
  276. X        -e 's|__BINDIR__|$(BINDIR)|g'   \
  277. X        -e 's|__LOOKUPBINDIR__|$(LOOKUPBINDIR)|g'   \
  278. X        -e 's|__PATHALIAS__|$(PATHALIAS)|g'   \
  279. X        -e 's|__UUHOSTINDEX__|$(UUHOSTINDEX)|g'    uuhost.N > uuhost.1
  280. X    chmod 444 uuhost.1
  281. X    
  282. uusplit: uusplit.c Makefile $(HFILES)
  283. X    $(CC) $(CFLAGS) -o uusplit uusplit.c $(LIBS)
  284. X    [ -x /usr/bin/mcs ] && /usr/bin/mcs -d uusplit
  285. X
  286. uulookup: uulookup.c Makefile $(HFILES)
  287. X    $(CC) $(CFLAGS) -DPATHALIAS='"$(PATHALIAS)"' -DUUHOSTINDEX='"$(UUHOSTINDEX)"' -o uulookup uulookup.c $(LIBS)
  288. X    [ -x /usr/bin/mcs ] && /usr/bin/mcs -d uulookup
  289. X
  290. install:  uusplit uulookup uuhost
  291. X    [ -d $(BINDIR) ] || mkdir $(BINDIR)
  292. X    -chmod 755 $(BINDIR)
  293. X    rm -f $(BINDIR)/uusplit && cp uusplit $(BINDIR)
  294. X    chmod 111 $(BINDIR)/uusplit
  295. X    rm -f $(LOOKUPBINDIR)/uulookup && cp uulookup $(LOOKUPBINDIR)
  296. X    chmod 111 $(LOOKUPBINDIR)/uulookup
  297. X    rm -f $(LOCALBIN)/uuhost && cp uuhost $(LOCALBIN)
  298. X    chmod 555 $(LOCALBIN)/uuhost
  299. X
  300. X    touch $(UUHOSTINDEX)
  301. X
  302. X    @echo 
  303. X    @echo 'Please install the manual page "uuhost.1" manually'
  304. X    @echo
  305. clean:
  306. X    rm -f core *.o Part.??
  307. clobber: clean
  308. X    rm -f uusplit uulookup uuhost uuhost.1
  309. X
  310. dist: $(SRCS) $(SHARFILES) $(HFILES)
  311. X    shar49 -n uuhost -a -s 'jpm@Logix.DE' -o Part -l 50 -c \
  312. X        $(SHARFILES) $(SRCS) $(HFILES)
  313. END_OF_FILE
  314. if test 3730 -ne `wc -c <'Makefile'`; then
  315.     echo shar: \"'Makefile'\" unpacked with wrong size!
  316. fi
  317. # end of 'Makefile'
  318. fi
  319. if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  320.   echo shar: Will not clobber existing file \"'patchlevel.h'\"
  321. else
  322. echo shar: Extracting \"'patchlevel.h'\" \(24 characters\)
  323. sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
  324. X#define PATCHLEVEL        2.1
  325. END_OF_FILE
  326. if test 24 -ne `wc -c <'patchlevel.h'`; then
  327.     echo shar: \"'patchlevel.h'\" unpacked with wrong size!
  328. fi
  329. # end of 'patchlevel.h'
  330. fi
  331. if test -f 'uuhost.N' -a "${1}" != "-c" ; then 
  332.   echo shar: Will not clobber existing file \"'uuhost.N'\"
  333. else
  334. echo shar: Extracting \"'uuhost.N'\" \(4250 characters\)
  335. sed "s/^X//" >'uuhost.N' <<'END_OF_FILE'
  336. X.\" nroff -man %s
  337. X.\" UUHOST, Copyright 1992,   Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany]
  338. X.\" License to freely use and distribute this software is hereby granted 
  339. X.\" by the author, subject to the condition that this copyright notice 
  340. X.\" remains intact.  The author retains the exclusive right to publish 
  341. X.\" derivative works based on this work, including, but not limited
  342. X.\" to, revised versions of this work.
  343. X.\"
  344. X.\" $Log: uuhost.N,v $
  345. X.\" Revision 1.2  1992/01/16  09:42:47  jpm
  346. X.\" Cleanup
  347. X.\"
  348. X.\"
  349. X.TH UUHOST 1 "" "Logix GmbH" "Local user commands"
  350. X.SH NAME
  351. uuhost - lookup UUCP mail and USENET information
  352. X.SH SYNOPSIS
  353. X.B uuhost
  354. X[
  355. X.B -l
  356. X]
  357. X[
  358. X.B -r
  359. X.I region
  360. X]
  361. X[ 
  362. X.I hostname
  363. X]
  364. X.br
  365. X.B uuhost
  366. X.I -index
  367. X.br
  368. X.B uulookup
  369. X[
  370. X.B -h
  371. X.I hostname
  372. X]
  373. X[
  374. X.B -m
  375. X.I machine
  376. X]
  377. X[
  378. X.B -u
  379. X.I address
  380. X]
  381. X[
  382. X.B -v
  383. X]
  384. X.SH DESCRIPTION
  385. X.SS UUHOST 
  386. X.RS 1i
  387. X.B uuhost
  388. looks up information on the named host
  389. X.I hostname
  390. in the UUCP map files and presents the information to the user to peruse.
  391. X.PP
  392. X.IP "\fBuuhost\fR \fIhostname\fR"
  393. shows information about the host 
  394. X.I hostname.
  395. X.IP "\fBuuhost\fR \fI-l\fR"
  396. displays a list of uucp map regions available on this system.
  397. X.IP "\fBuuhost\fR -r \fIregion\fR"
  398. displays all the information for the specified
  399. X.I region.
  400. X.IP "\fBuuhost -index\fR"
  401. is reserved for the system administrator. This parses the needed information
  402. out of the UUCP map distribution, and creates the necessary database for
  403. X.B uuhost.
  404. This operation should be done once a night, after the maps have arrived at
  405. this site.
  406. X.B "uuhost -index"
  407. may be called from a crontab entry.
  408. X.PP
  409. X.SS UULOOKUP
  410. X.RS 1i
  411. X.B uulookup 
  412. program parses the
  413. X.I UUHOSTINDEX
  414. or
  415. X.I PATHALIAS
  416. databases depending on the used option.
  417. X.IP "\fBuulookup\fR -h \fIhostname\fR"
  418. looks up information for the host
  419. X.I hostname
  420. in the 
  421. X.I UUHOSTINDEX
  422. database, and presents the found
  423. X.I hostname ,
  424. map-file name, and line number in the map to standard output.
  425. X.IP "\fBuulookup\fR -m \fImachine\fR"
  426. looks up information for the machine
  427. X.I machine
  428. in the 
  429. X.I PATHALIAS
  430. database, and presents the shortest path to that host.
  431. X.IP "\fBuulookup\fR -u \fIaddress\fR"
  432. Will print a uucp bang address to the specified
  433. X.I address,
  434. which may be a bang address as in
  435. X.I site!user
  436. or a domain address as in
  437. X.I user@site.
  438. An
  439. X.I address
  440. like 
  441. X.I user%system@site
  442. will be expanded (if possible) into
  443. X.I address!to!that!site!user%system.
  444. If only a site is specified,
  445. X.I %s
  446. is output instead of the user.
  447. Note that multiple sites are not supported yet.
  448. X.PP
  449. X.IP "\fBuulookup\fR \fI-v\fR ..."
  450. turns on verbose output.
  451. X.SH DIAGNOSTICS
  452. Many, and (hopefully) self-explanatory.
  453. X.SH FILES
  454. X.IP "\fIUUHOSTINDEX\fR"
  455. This is the main index file for
  456. X.B uuhost.
  457. It contains lines of text, with three fields each. The first field is the
  458. name of a host as in
  459. X.I logixwi
  460. followed by a tab character. The second field contains the relative pathname
  461. of the map file 
  462. X.I u.deu.2
  463. in which this host is described. The file name does not have a 
  464. X.I .Z
  465. tacked on to it, even if the maps are in compressed form (this saves 24KB on our file system :-). The third field is the relative line number in the map file
  466. where the description of the host begins. The 
  467. X.B uuhost
  468. index file must be sorted alphabetically. It is parsed by the
  469. X.B uulookup
  470. program with option
  471. X.I -h
  472. X.br
  473. On this system, the 
  474. X.I UUHOSTINDEX
  475. file is called "\fI__UUHOSTINDEX__\fR".
  476. X.IP "\fIPATHALIAS\fR"
  477. This is the 
  478. X.I PATHALIAS 
  479. file as it is used by 
  480. X.I smail
  481. or
  482. X.I sendmail.
  483. It is parsed by the 
  484. X.B uulookup
  485. program with options
  486. X.I -m
  487. and 
  488. X.I -u
  489. X.br
  490. On this system, the
  491. X.I PATHALIAS
  492. file is located at "\fI__PATHALIAS__\fR".
  493. X.IP "\fIMAPSDIR/u.*\fR"
  494. X
  495. This directory (\fI__MAPSDIR__\fR on this system) contains the maps. Either compressed (filenames ending in .Z) 
  496. or uncompressed.
  497. X.SH NOTES
  498. X.B uulookup
  499. is located in the directory
  500. X.B __LOOKUPBINDIR__.
  501. X.br
  502. X.B uulookup
  503. only recognizes one-hop addresses, in other words, 
  504. X.I site1!site2!user
  505. is not recognized.
  506. X.sp
  507. XFor
  508. X.I uulookup
  509. and
  510. X.I uuhost
  511. to work correctly, the
  512. X.I PATHALIAS
  513. database and the 
  514. X.I UUHOSTINDEX
  515. database must be sorted with
  516. X.I sort -u -f
  517. X\.
  518. X.SH CREDITS
  519. Written by Jan-Piet Mens <jpm@Logix.DE>, based on an idea by 
  520. John Quarterman <jsq@sally.utexas.edu>
  521. X.SH SEE ALSO
  522. grep(1), sendmail(1), pathalias(1)
  523. END_OF_FILE
  524. if test 4250 -ne `wc -c <'uuhost.N'`; then
  525.     echo shar: \"'uuhost.N'\" unpacked with wrong size!
  526. fi
  527. # end of 'uuhost.N'
  528. fi
  529. if test -f 'uuhost.S' -a "${1}" != "-c" ; then 
  530.   echo shar: Will not clobber existing file \"'uuhost.S'\"
  531. else
  532. echo shar: Extracting \"'uuhost.S'\" \(2930 characters\)
  533. sed "s/^X//" >'uuhost.S' <<'END_OF_FILE'
  534. X#!/bin/sh
  535. X#
  536. X# UUHOST, Copyright 1992,   Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany]
  537. X# License to freely use and distribute this software is hereby granted 
  538. X# by the author, subject to the condition that this copyright notice 
  539. X# remains intact.  The author retains the exclusive right to publish 
  540. X# derivative works based on this work, including, but not limited
  541. X# to, revised versions of this work.
  542. X#
  543. X# $Id: uuhost.S,v 1.1 1992/01/16 09:43:40 jpm Exp $
  544. X# $Log: uuhost.S,v $
  545. X# Revision 1.1  1992/01/16  09:43:40  jpm
  546. X# Initial revision
  547. X#
  548. X#
  549. X# Set this to the name of the directory containing the uucp maps (u.*)
  550. MAPSDIR="__MAPSDIR__"
  551. X# This is the file where the UUHOST index lives
  552. UUHOSTINDEX="__UUHOSTINDEX__"
  553. X#
  554. X# This is the program that splits up a `#N' line into individual machines
  555. X#
  556. UUSPLITNAME="__BINDIR__/uusplit"
  557. X#
  558. X# CAT is either `cat' if maps are not compressed, or `zcat' if they *are*.
  559. X#
  560. CAT="__CATPROG__"
  561. X#
  562. X# If you don't want to use my `uulookup', you'll have to work at this script.
  563. X#
  564. LOOK="__LOOKPROG__"
  565. PATHLOOKUP="__PATHLOOKUP__"
  566. PAGER="__PAGEPROG__"
  567. X
  568. USAGE="$0 [-l] [-r region] [hostname]"
  569. X
  570. X[ $# -eq 0 ] && { echo "$USAGE" >&2 ; exit 1 ; }
  571. case "$1" in 
  572. X    -l)    ls -C ${MAPSDIR} | sed -e 's/\.Z//g' ; exit 0 ;;
  573. X    -r)    [ $# -eq 2 ] || { echo "$USAGE" >&2 ; exit 2 ; }
  574. X        REGION="${MAPSDIR}/$2"
  575. X        [ ! -r $REGION -a ! -r ${REGION}.Z ] && 
  576. X                { echo "$0: region $2 non-existant"; exit ; }
  577. X        ${CAT} $REGION | ${PAGER}
  578. X        exit 0 ;;
  579. X    -index)
  580. X        [ -w ${UUHOSTINDEX} ] || {
  581. X                echo "$UUHOSTINDEX is not writeable" >&2
  582. X                exit 2 ; }
  583. X
  584. X        echo "Building index '${UUHOSTINDEX}'. Patience." >&2
  585. X        cd ${MAPSDIR}                # Go to dir
  586. X        ls u.* | while read mapname        # Find all u. files
  587. X        do
  588. X            echo ".\c" >&2
  589. X            ${CAT} $mapname | 
  590. X            grep -n '^#N' |         # Only `#N' entries
  591. X            ${UUSPLITNAME} $mapname        # Build list
  592. X        done > ${UUHOSTINDEX}
  593. X        echo "\n" >&2
  594. X        #
  595. X        # there is a bug in my `sort'. Otherwise, I would have put
  596. X        # it in the pipeline above...
  597. X        #
  598. X        sort -f -u ${UUHOSTINDEX} -o ${UUHOSTINDEX}
  599. X        chmod 644 ${UUHOSTINDEX}
  600. X        exit 0 ;;
  601. X    -*)    echo "$USAGE" >&2 ; exit 2 ;;
  602. esac
  603. X
  604. machine=$1
  605. X
  606. X${LOOK} $machine ${UUHOSTINDEX} |         # May give several per machine
  607. X    sort -1 +2 -u |             # Give unique entries for mach
  608. X    while read mach map line        # Get Machinename, mapfile, line
  609. X    do
  610. X        ${PATHLOOKUP} $mach        # E-mail address ?
  611. X
  612. X        echo '\n'
  613. X
  614. X        ${CAT} ${MAPSDIR}/${map} |    # Output file...
  615. X        sed -n -e "$line,/^$/p"  |    # ... starting at `line'
  616. X        sed -e "s/^#N/#Name          /"    \
  617. X            -e "s/^#S/#System-OS     /"    \
  618. X            -e "s/^#O/#Organisation  /"    \
  619. X            -e "s/^#F/#Forwarder(MX) /"    \
  620. X            -e "s/^#R/#Remarks       /"    \
  621. X            -e "s/^#E/#Electr.Adress /"    \
  622. X            -e "s/^#C/#Contact       /"    \
  623. X            -e "s/^#T/#Telephone     /"    \
  624. X            -e "s/^#P/#Postal-Address/"    \
  625. X            -e "s/^#L/#Lat.-Longitude/"    \
  626. X            -e "s/^#W/#Written-By:   /"    \
  627. X            -e "s/^#U/#Usenet links  /"
  628. X        echo "================== ${map} ======================="
  629. X    done | ${PAGER} 
  630. END_OF_FILE
  631. if test 2930 -ne `wc -c <'uuhost.S'`; then
  632.     echo shar: \"'uuhost.S'\" unpacked with wrong size!
  633. fi
  634. chmod +x 'uuhost.S'
  635. # end of 'uuhost.S'
  636. fi
  637. if test -f 'uulookup.c' -a "${1}" != "-c" ; then 
  638.   echo shar: Will not clobber existing file \"'uulookup.c'\"
  639. else
  640. echo shar: Extracting \"'uulookup.c'\" \(5499 characters\)
  641. sed "s/^X//" >'uulookup.c' <<'END_OF_FILE'
  642. X/*
  643. X * UUHOST, Copyright 1992,   Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany]
  644. X * License to freely use and distribute this software is hereby granted 
  645. X * by the author, subject to the condition that this copyright notice 
  646. X * remains intact.  The author retains the exclusive right to publish 
  647. X * derivative works based on this work, including, but not limited
  648. X * to, revised versions of this work.
  649. X *
  650. X * $Id: uulookup.c,v 2.3 1992/01/16 09:40:58 jpm Exp $
  651. X *
  652. X * $Log: uulookup.c,v $
  653. X * Revision 2.3  1992/01/16  09:40:58  jpm
  654. X * Cleanup
  655. X *
  656. X * Revision 2.2  1991/10/22  18:14:09  jpm
  657. X * Added -u option. Thanks to Pat Myrto <pat@rwing> for suggesting it.
  658. X *
  659. X * Revision 2.1  1991/10/19  14:25:54  jpm
  660. X * *** empty log message ***
  661. X *
  662. X *
  663. X */
  664. X
  665. X#include <stdio.h>
  666. X#include <ctype.h>
  667. X#ifdef NEED_STRINGS_H
  668. X# include <strings.h>
  669. X#else
  670. X# include <string.h>
  671. X#endif
  672. X#define MAXBUF    1024
  673. X
  674. X#if defined(__STDC__) || defined(__cplusplus)
  675. X# define P_(s) s
  676. X#else
  677. X# define P_(s) ()
  678. X#endif
  679. X
  680. int main P_((int argc, char **argv));
  681. void splitpath P_((char *usr, char *adr));
  682. int look P_((char *key, char *result));
  683. int strsplit P_((register char *s, int sep, char **arg));
  684. void usage P_((void));
  685. int getopt();
  686. void exit();
  687. X
  688. X#undef P_
  689. X#define FALSE        0
  690. X#define TRUE        1
  691. X#define MAXDOMS        20
  692. X
  693. char *progname;
  694. char *database;            /* For look() */
  695. X
  696. X#ifndef lint
  697. static char rcs_id[] = "@(#)$Id: uulookup.c,v 2.3 1992/01/16 09:40:58 jpm Exp $";
  698. X#endif
  699. void usage();
  700. X
  701. int main(argc, argv)
  702. int argc;
  703. char **argv;
  704. X{
  705. X    char addr[100], user[100], buf[MAXBUF];
  706. X    extern char *optarg;
  707. X    char *doms[MAXDOMS];            /* Each component of domain */
  708. X    int count, i, c, hf = FALSE, mf = FALSE, uf = FALSE;
  709. X    int verbose = FALSE, found;
  710. X
  711. X    progname = argv[0];
  712. X    (void)strcpy(user, "");
  713. X
  714. X    while ((c = getopt(argc, argv, "vh:m:u:")) != EOF)
  715. X        switch (c)
  716. X        {
  717. X            case 'h':
  718. X                database = UUHOSTINDEX;
  719. X                (void)strcpy(addr, optarg);
  720. X                hf = TRUE;
  721. X                break;
  722. X            case 'm':
  723. X                database = PATHALIAS;
  724. X                (void)strcpy(addr, optarg);
  725. X                mf = TRUE;
  726. X                break;
  727. X            case 'u':
  728. X                database = PATHALIAS;
  729. X                (void)strcpy(user, optarg);
  730. X                uf = TRUE;
  731. X                break;
  732. X            case 'v':
  733. X                verbose = TRUE;
  734. X                break;
  735. X            default:
  736. X                usage();
  737. X        }
  738. X
  739. X    if (hf + mf + uf != 1)        /* Options are exclusive */
  740. X        usage();
  741. X
  742. X    if (uf)
  743. X        splitpath(user, addr);
  744. X
  745. X    /*
  746. X     * Split addr into a list of domains. If `addr' has foo.bar.top.level
  747. X     * it will get split into
  748. X     *
  749. X     *    foo.bar.top.level
  750. X     *    .bar.top.level
  751. X     *    .top.level
  752. X     *    .level
  753. X     */
  754. X
  755. X    count = strsplit(addr, '.', doms);
  756. X
  757. X    /*
  758. X     * Forget about the top-level domains. They are not in (my) 
  759. X     * PATHALIAS.
  760. X     */
  761. X
  762. X    --count;
  763. X
  764. X    if (verbose)
  765. X        (void)printf("Trying '%s'\n", addr);
  766. X
  767. X    found = FALSE;
  768. X    if (look(addr, buf) != 0)
  769. X    {
  770. X        for (i = 0; i < count; i++)
  771. X        {
  772. X            if (verbose)
  773. X                (void)printf("Trying '%s'\n", doms[i]);
  774. X            if (look(doms[i] - 1, buf) == 0     /* With dot */
  775. X                || look(doms[i] - 1, buf) == 0)    /* W/o dot */
  776. X            {
  777. X                found = TRUE;
  778. X                break;
  779. X            }
  780. X        }
  781. X    }
  782. X    else found = TRUE;
  783. X
  784. X    if (found == FALSE)
  785. X        if (hf)
  786. X            return fprintf(stderr, "HOST: '%s' not found\n", addr);
  787. X        else 
  788. X            return fprintf(stderr, "Path to '%s' not found\n",addr);
  789. X
  790. X    if (uf == TRUE)
  791. X    {
  792. X        (void)printf(buf, user);
  793. X        (void)putchar('\n');    
  794. X    }
  795. X    else if (mf == TRUE)
  796. X        (void)printf("Path to %s\n\t%s\n", addr, buf);
  797. X    else
  798. X        (void)printf("%s %s\n", addr, buf);
  799. X    return (0);
  800. X}
  801. X
  802. void splitpath(usr, adr)
  803. char *usr;                /* Contains user@site or site!user */
  804. char *adr;                /* Target will contain "site"  */
  805. X{
  806. X    char *strchr(), *ptr, a[100], u[100];
  807. X
  808. X    /*
  809. X     *  user@site  ?
  810. X     *  Copy "site" into `adr' and chop `usr' at '@'
  811. X     */
  812. X
  813. X    if ((ptr = strchr(usr, '@')) != (char *)0)
  814. X    {
  815. X        (void)strcpy(a, ptr + 1);
  816. X        *(ptr) = '\0';
  817. X        (void)strcpy(u, usr);
  818. X    }
  819. X    else if ((ptr = strchr(usr, '!')) != (char *)0)
  820. X    {
  821. X        (void)strcpy(u, ptr + 1);
  822. X        *(ptr) = '\0';
  823. X        (void)strcpy(a, usr);
  824. X    }
  825. X    else 
  826. X    {
  827. X        (void)strcpy(a, usr);
  828. X        (void)strcpy(u, "%s");
  829. X    }
  830. X
  831. X    (void)strcpy(adr, a);
  832. X    (void)strcpy(usr, u);
  833. X}
  834. X    
  835. X/*
  836. X * From "Portable C Software by Mark Horton"
  837. X */
  838. X
  839. int look(key, result)
  840. char *key, *result;
  841. X{
  842. X    long pos, middle, hi, lo;
  843. X    static long pathlength = 0;
  844. X    register char *s;
  845. X    int c, flag;
  846. X    static FILE *fp;
  847. X
  848. X    if (!pathlength)
  849. X    {
  850. X        if ((fp = fopen(database,"r")) == (FILE *)0) {
  851. X            (void)perror(database);
  852. X            pathlength = -1;
  853. X        }
  854. X        else {
  855. X            (void)fseek(fp, 0L, 2);
  856. X            pathlength = ftell(fp);
  857. X        }
  858. X    }
  859. X
  860. X    if (pathlength == -1)
  861. X        return (-2);            /* No database file */
  862. X
  863. X    lo = 0;
  864. X    hi = pathlength;
  865. X    (void)strcpy(result, key);
  866. X    (void)strcat(result, "\t");
  867. X
  868. X    while (1)
  869. X    {
  870. X        pos = middle = (hi + lo + 1) /2;
  871. X        (void)fseek(fp, pos, 0);        /* Find midpoint */
  872. X        if (pos)            /*  to begin of next line */
  873. X            while ((c = getc(fp)) != EOF && c != '\n')
  874. X                ;    /* Nothing */
  875. X            
  876. X        for (flag = 0, s = result; !flag; s++) {    /* Match ? */
  877. X            if (*s == '\0')
  878. X                goto solved;
  879. X            c = getc(fp);
  880. X            flag = tolower(c) - tolower(*s);
  881. X        }
  882. X        if (lo >= middle)        /* Failure ? */
  883. X            return (-1);
  884. X        if (c != EOF && flag < 0)    /* Close window */
  885. X            lo = middle;
  886. X        else
  887. X            hi = middle - 1;
  888. X    }
  889. solved:            /* Just copy result... */
  890. X    while ((c = getc(fp)) != EOF && c != '\n')
  891. X        *result++ = c;
  892. X    *result = '\0';
  893. X    return (0);
  894. X}
  895. X
  896. int strsplit(s, sep, arg)
  897. register char *s;
  898. int sep;
  899. char **arg;
  900. X{
  901. X    int count = 0;
  902. X    int wastoken = 0;
  903. X
  904. X    for (; *s; ++s)
  905. X    {
  906. X        if (!wastoken)
  907. X        {
  908. X            ++count;
  909. X            *arg++ = s;
  910. X        }
  911. X        wastoken = (sep != *s);
  912. X    }
  913. X
  914. X    if (!wastoken)
  915. X    {
  916. X        ++count;
  917. X        *arg++ = s;
  918. X    }
  919. X    *arg = (char *)0;
  920. X    return (count);
  921. X}
  922. X
  923. void usage()
  924. X{
  925. X    (void)fprintf(stderr, "Usage: %s [-h hostname] [-m mailname] [-u user] [-v]\n", progname);
  926. X    exit(1);
  927. X}
  928. END_OF_FILE
  929. if test 5499 -ne `wc -c <'uulookup.c'`; then
  930.     echo shar: \"'uulookup.c'\" unpacked with wrong size!
  931. fi
  932. # end of 'uulookup.c'
  933. fi
  934. if test -f 'uusplit.c' -a "${1}" != "-c" ; then 
  935.   echo shar: Will not clobber existing file \"'uusplit.c'\"
  936. else
  937. echo shar: Extracting \"'uusplit.c'\" \(2167 characters\)
  938. sed "s/^X//" >'uusplit.c' <<'END_OF_FILE'
  939. X/*
  940. X * UUHOST, Copyright 1992,   Jan-Piet Mens [Logix GmbH, Wiesbaden, Germany]
  941. X * License to freely use and distribute this software is hereby granted 
  942. X * by the author, subject to the condition that this copyright notice 
  943. X * remains intact.  The author retains the exclusive right to publish 
  944. X * derivative works based on this work, including, but not limited
  945. X * to, revised versions of this work.
  946. X *
  947. X * $Id: uusplit.c,v 2.2 1992/01/16 09:40:58 jpm Exp $
  948. X *
  949. X * $Log: uusplit.c,v $
  950. X * Revision 2.2  1992/01/16  09:40:58  jpm
  951. X * Cleanup
  952. X *
  953. X * Revision 2.1  1991/10/19  14:27:49  jpm
  954. X * *** empty log message ***
  955. X *
  956. X *
  957. X */
  958. X#include <stdio.h>
  959. X#define MAXBUF        1024
  960. X
  961. X#if defined(__STDC__) || defined(__cplusplus)
  962. X# define P_(s) s
  963. X#else
  964. X# define P_(s) ()
  965. X#endif
  966. X
  967. int main P_((int argc, char **argv));
  968. void split P_((char *bp, char *fname));
  969. void exit();
  970. int strlen();
  971. int atoi();
  972. X
  973. X#undef P_
  974. X
  975. X#ifndef lint
  976. static char rcs_id[] = "@(#)$Id: uusplit.c,v 2.2 1992/01/16 09:40:58 jpm Exp $";
  977. X#endif
  978. X
  979. int main(argc, argv)
  980. int argc;
  981. char **argv;
  982. X{
  983. X    char buf[MAXBUF];
  984. X    char *fname = argv[1];
  985. X    int n = strlen(fname) - 1;
  986. X
  987. X    if (argc != 2)
  988. X        exit(fprintf(stderr,"Usage: %0 filename\n", *argv));
  989. X
  990. X    /*
  991. X     * If filenames end in .Z, chop it off. We don't need that.
  992. X     * Just wastes space ...
  993. X     */
  994. X
  995. X    if (fname[n] == 'Z' && fname[n - 1] == '.')
  996. X        fname[n - 1] = '\0';
  997. X
  998. X    while (fgets(buf, MAXBUF, stdin) != (char *)0)
  999. X        split(buf, argv[1]);
  1000. X    return (0);
  1001. X}
  1002. X
  1003. X/*
  1004. X * `fname' is a relative path to a map: u.deu.2.
  1005. X * `bp' contains an `#N' line from the map which has a line-number
  1006. X *  prepended to it by `grep' , as in
  1007. X *
  1008. X *     1245:#N        logixwi, .logix.de,  logix.de
  1009. X *
  1010. X * Split that line up into lines containing the host name, a filename, and
  1011. X * the line number.
  1012. X *
  1013. X *    logixwi    u.deu.2 1245
  1014. X *    .logix.de       u.deu.2 1245
  1015. X *    logix.de    u.deu.2 1245
  1016. X */
  1017. X
  1018. void split(bp, fname)
  1019. char *bp, *fname;
  1020. X{
  1021. X    char *ptr, *strtok();
  1022. X    int line;
  1023. X
  1024. X    if ((ptr = strtok(bp, ":")) == (char *)0)
  1025. X        (void)fprintf(stderr, "ERROR: no line number\n");
  1026. X    line = atoi(ptr);
  1027. X
  1028. X    ptr = strtok(NULL, " \t,;\n");
  1029. X
  1030. X    while ((ptr = strtok(NULL, " \t,;\n")) != (char *)0)
  1031. X        (void)printf("%s\t%s\t%d\n", ptr, fname, line);
  1032. X}
  1033. END_OF_FILE
  1034. if test 2167 -ne `wc -c <'uusplit.c'`; then
  1035.     echo shar: \"'uusplit.c'\" unpacked with wrong size!
  1036. fi
  1037. # end of 'uusplit.c'
  1038. fi
  1039. echo shar: End of shell archive.
  1040. exit 0
  1041.