home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / bsd / 11777 < prev    next >
Encoding:
Internet Message Format  |  1993-01-24  |  47.5 KB

  1. Path: sparky!uunet!gatech!rpi!batcomputer!munnari.oz.au!goanna!escargot!minyos.xx.rmit.OZ.AU!s902113
  2. From: s902113@minyos.xx.rmit.OZ.AU (Luke Mewburn)
  3. Newsgroups: comp.unix.bsd
  4. Subject: man(1) command enhancements (compression, etc)
  5. Summary: man that handles compressed/gzipped files
  6. Keywords: compress, manual, bugfix, nifty
  7. Message-ID: <1ju3jmINNgeh@escargot.xx.rmit.OZ.AU>
  8. Date: 24 Jan 93 12:55:18 GMT
  9. Organization: RMIT Computer Centre
  10. Lines: 1670
  11. NNTP-Posting-Host: minyos.xx.rmit.oz.au
  12.  
  13. A while back Graham Toal <gtoal@gtoal.com> posted a hacked version
  14. of man which handled compressed manual pages (actually, at the time
  15. I was working on my own version, but his hack was better overall, 
  16. cause his worked with -h/-c with compressed files and mine didn't).
  17.  
  18. Anyway, since I've now installed gzip 0.8.1 on my system, I decided
  19. to hack the new man to handle gzipped files as well. In the process,
  20. I rewrote a script I wrote for A/UX which compresses/gzippes all files
  21. in the manual subtree, including those with links (and restores the
  22. links).
  23.  
  24. After cleaning up the code a bit, and modifying stuff such as the
  25. makewhatis.db generation grok .[zZ] manual pages, I've got it ready
  26. for the general public.
  27.  
  28. One last minute thing: whilst testing the new command, I found that
  29. it would hang if you gave it more than one different manual page to
  30. look for - I don't know if this was a bug that crept in with Graham's
  31. hack, or was always there (i'm inclined to believe the latter). The
  32. bug has also been found/fixed.
  33.  
  34. Well, here's the shar file. It will make it's own subdir, and there
  35. is an INSTALLATION file full of meaningless stuff that you'll only
  36. read after you can't get it working :)
  37.  
  38. Luke.
  39.  
  40. PS: Don't forget that you need to install gzip :)
  41.  
  42. --
  43. #!/bin/sh
  44. # This is a shell archive.  Save it in a file, remove anything before
  45. # this line, and then unpack it by entering "sh file".  Note, it may
  46. # create directories; files and directories will be owned by you and
  47. # have default permissions.
  48. #
  49. # This archive contains:
  50. #
  51. #    zman
  52. #    zman/INSTALLATION
  53. #    zman/README.zman
  54. #    zman/update_widb
  55. #    zman/fixman.OLD
  56. #    zman/man
  57. #    zman/man/tags
  58. #    zman/man/pathnames.h
  59. #    zman/man/man.conf.5
  60. #    zman/man/man.c
  61. #    zman/man/man.1
  62. #    zman/man/config.c
  63. #    zman/man/Makefile
  64. #    zman/whatis
  65. #    zman/whatis/makewhatis.sed
  66. #    zman/whatis/Makefile
  67. #    zman/fixman
  68. #
  69. echo c - zman
  70. mkdir zman > /dev/null 2>&1
  71. echo x - zman/INSTALLATION
  72. sed 's/^X//' >zman/INSTALLATION << 'END-of-zman/INSTALLATION'
  73. XInstallation of new man(1) command and associated files.
  74. X--------------------------------------------------------
  75. X
  76. X    This distribution consists of the source and auxiliary support
  77. Xfiles needed to allow the use of compress(1)ed or gzip(1)ped files.
  78. X
  79. X
  80. X    The code has be derived the original 386BSD and NET/2 manual
  81. Xcode, with changes by the following people:
  82. X
  83. X    Graham Toal <gtoal@gtoal.com>
  84. X- Modifiied man.c to enable the use of compressed manual pages.
  85. X
  86. X    Luke Mewburn <zak@rmit.edu.au>
  87. X- Modified Graham's man.c to also recognize gzipped files.
  88. X- Fixed problem with insertion of '\0' into middle of path var,
  89. X  resulting in man file1 file2 hanging.
  90. X- Fixes to the Makefile which generates the whatis.db to also
  91. X  check compressed/gzipped files
  92. X- A totally original script (fixman) which will gzip all manual
  93. X  pages, and restore any hard/symbolic links.
  94. X
  95. X
  96. X    I (Luke) haven't obtained official permission to distribute
  97. XGraham's changes yet, but I don't think he will mind :)
  98. X
  99. X
  100. X    To install this new kit, you need extract this distribution
  101. Xinto a clean subdirectory (which you've most likely already done if
  102. Xyou are reading this :), then do the following:
  103. X
  104. X1.    Install gzip (0.8.1) or later on your system. A working copy
  105. X    should be available on ref.tfs.com in /usr/packages.
  106. X    The normal sources can be found on your local gnu archive site
  107. X    (for Australia, try: archie.au:/gnu)
  108. X
  109. X    I advise that you rename the old zcat/compress/uncompress
  110. X    to Ozcat/Ocompress/Ouncompress, and ln gzip to compress -
  111. X    that way you use gzip for compress, and gtar -z will also
  112. X    use gzip. (Note that gzip 0.8.1 and later have a patch for
  113. X    gtar 1.11.1 which allows it to recognize -z as gzip and -Z
  114. X    as compress)
  115. X
  116. X    If you do replace zcat with gzip's zcat, ensure that /usr/bin/zcat
  117. X    is a link to the gzip version of zcat.
  118. X
  119. X
  120. X2.    Install the files in the whatis/ subdir into
  121. X    /usr/othersrc/share/man.
  122. X
  123. X
  124. X3.    Install fixman somewhere (/usr/local/bin maybe?)
  125. X
  126. X
  127. X4.    Compile man (in man/) and install it.
  128. X
  129. X
  130. X5.    Goto /usr/share/man, and run fixman. Note, it may compress
  131. X    the whatis.db, so uncompress it again.
  132. X
  133. X    Before you do this, it may be an idea to set the environment
  134. X    variable GZIP to "-9" to get the optimal compression.
  135. X    (Note: the environment variable support is a hack I've sent
  136. X    to Jean-loup which may or may not be implemented in the version
  137. X    of gzip you obtain - I can send you diffs to 0.8.1 if you
  138. X    want them)
  139. X
  140. X
  141. X6.    Goto /usr/othersrc/share/man and type ``make makedb''
  142. X
  143. X
  144. X7.    Install update_widb somewhere. Use this to update whatis.db
  145. X    for a subtree when new manuals have been added.
  146. X
  147. X
  148. X    Now you should have a working manual system, as well as about
  149. X1.5-2 more free MB on your system (which will increase if you go and 
  150. Xrecompress all .Z files with gzip -9 :)
  151. X
  152. X
  153. X    If there are any problems with this, please mail me and I'll
  154. Xtry and resolve them for you.
  155. X
  156. X
  157. XLuke Mewburn <zak@rmit.edu.au>, 930124.
  158. X
  159. XPS: if you don't wish to use gzip, there is a version of fixman called
  160. Xfixman.OLD which should use compress instead - except I've not tested
  161. Xit, so beware.
  162. END-of-zman/INSTALLATION
  163. echo x - zman/README.zman
  164. sed 's/^X//' >zman/README.zman << 'END-of-zman/README.zman'
  165. XThis is a *very* quick hack to man to allow you to compress all the
  166. Xman pages with unix compress and still be able to read them.
  167. X
  168. XJust go to /usr/man and do   compress */*.0 */*/*.0
  169. X
  170. XThere will be a lot of linked man pages that compress refuses to touch.
  171. XEither leave them as is (I did) or unlink them, compress one by hand,
  172. Xand relink all the .Z versions.  (Pref '-s' so you can see in future
  173. Xwhich files were linked to what)
  174. X
  175. XI hope I haven't broken it.  Seems to work on everything I've tried.
  176. X
  177. XI started from the net2 man only because that's the only one I could
  178. Xfind unpacked anywhere - the bsd src distribution is too big for me
  179. Xto unpack on my machine (hey - if I had space, I wouldn't be compressing
  180. Xthe man pages, right?)  If the 386bsd man is changed in any way from
  181. Xthe net2 man, you'll have to fold in the mods yourself.
  182. X
  183. XIn the places in the code where I've been dirty, I've put comments
  184. Xtelling people what to change if they want to spend the time to do
  185. Xthe job properly.
  186. X
  187. XThis was a two-hour hack for my own benefit; if anyone else finds it
  188. Xuseful they're welcome to it.  I won't be supporting it after this.
  189. XIdeally the .Z compression should be done transparently by the filing
  190. Xsystem, which I think is how bsd4.4 will do it? - in which case this
  191. Xhack will be redundant.
  192. X
  193. XGraham Toal <gtoal@gtoal.com>
  194. XPS Create a directory /usr/local/src/man/man for this, and
  195. Xln -s /usr/local/src/man/man/man /usr/bin/man to install it.
  196. XBuild this with cc -o man man.c config.c
  197. X[config.c is straight off the net2 tape - only man.c and pathnames.h were
  198. Xhacked]
  199. END-of-zman/README.zman
  200. echo x - zman/update_widb
  201. sed 's/^X//' >zman/update_widb << 'END-of-zman/update_widb'
  202. Xif [ $# -ne 1 ]; then
  203. X    echo "Usage: $0 dir"
  204. X    echo "    updates the subtree dir in the whatis.db"
  205. X    exit 0
  206. Xfi
  207. X
  208. Xecho "Updating subdir $1 in the whatis.db"
  209. Xfor file in `find $1 -type f -name '*.0' -print`; do \
  210. X    sed -n -f /usr/share/man/makewhatis.sed $file; \
  211. Xdone | col -b >> whatis.db
  212. Xfor file in `find $1 -type f -name '*.0.[zZ]' -print`; do \
  213. X    zcat $file | sed -n -f /usr/share/man/makewhatis.sed; \
  214. Xdone | col -b >> whatis.db
  215. Xsort -u -o whatis.db whatis.db
  216. END-of-zman/update_widb
  217. echo x - zman/fixman.OLD
  218. sed 's/^X//' >zman/fixman.OLD << 'END-of-zman/fixman.OLD'
  219. X#!/bin/sh
  220. X#
  221. X# File: fixman.OLD
  222. X# By:   Luke Mewburn (zak@rmit.EDU.AU)
  223. X# Date: 930117
  224. X# Vers: 2.0.1o
  225. X#
  226. X#
  227. X# Synopsis:
  228. X#    converts a manual tree to compressed format.
  229. X#
  230. X# Usage:
  231. X#    fixman
  232. X#
  233. X#     This converts all compressed and normal files in the current subtree
  234. X# (with links) to compressed files (with # correct links)
  235. X#
  236. X# Bugs:
  237. X#  - slow
  238. X#
  239. X#  - NOT TESTED - you have been warned
  240. X#    --- ------
  241. X#
  242. X
  243. Xls -li `find . \( -type f -o -type l \)` | \
  244. Xsort | \
  245. Xawk '
  246. X{
  247. X    if (NF == 11)
  248. X    {
  249. X    if ($10 == "->")
  250. X    {
  251. X        symlink_arr[ $9 ] = $11
  252. X        printf "echo adding %s, %s to arr\n", $9, $11
  253. X    }
  254. X    next
  255. X    }
  256. X    if (NF != 9 )
  257. X    next
  258. X    links=$3
  259. X    orig=$9
  260. X#    if (index(orig, ".Z") != 0)
  261. X#    {
  262. X#    printf "gunzip %s\n", orig
  263. X#    sub("\.Z$", "", orig)
  264. X#    }
  265. X    if (index(orig, ".Z") == 0)
  266. X    {
  267. X    printf "cat %s | compress -c > %s.Z\n", orig, orig
  268. X    printf "rm -f %s\n", orig
  269. X    printf "echo %s compressed.\n", orig
  270. X    }
  271. X    if (links>1)
  272. X    {
  273. X    inode=$1
  274. X    for (count=1; count <links ; count++)
  275. X    {
  276. X        getline
  277. X        if ($1 != inode)
  278. X        next
  279. X        nxtnam=$9
  280. X        if (index(nxtnam, ".Z") != 0)
  281. X        {
  282. X#        printf "echo skipping %s\n", nxtnam
  283. X        continue;
  284. X        }
  285. X        printf "rm %s\n", $9
  286. X#        sub("\.Z$", "", nxtnam)
  287. X        printf "if ( -e %s.Z ) then\n", orig
  288. X        printf "  ln %s.Z %s.Z\n", orig, nxtnam
  289. X        printf "  echo %s.Z linked to %s.Z.\n", orig, nxtnam
  290. X        print  "else"
  291. X        printf "  ln %s %s\n", orig, nxtnam
  292. X        printf "  echo %s linked to %s.\n", orig, nxtnam
  293. X        print  "endif"
  294. X    }
  295. X    }
  296. X}
  297. X
  298. XEND {
  299. X    printf "\necho re-fixing symbolic links:\n"
  300. X    for ( elm in symlink_arr )
  301. X    {
  302. X    src = symlink_arr[ elm ]
  303. X    printf "rm %s\n", elm
  304. X    printf "if ( -e `dirname %s`/%s.Z ) then\n", elm, src
  305. X    printf "  ln -s %s.Z %s.Z\n", src, elm
  306. X    printf "  echo %s.Z symlinked to %s.Z.\n", elm, src
  307. X    print  "else"
  308. X    printf "  ln -s %s %s\n", src, elm
  309. X    printf "  echo %s symlinked to %s.\n", elm, src
  310. X    print  "endif"
  311. X    }
  312. X}
  313. X' | csh -f
  314. END-of-zman/fixman.OLD
  315. echo c - zman/man
  316. mkdir zman/man > /dev/null 2>&1
  317. echo x - zman/man/tags
  318. sed 's/^X//' >zman/man/tags << 'END-of-zman/man/tags'
  319. END-of-zman/man/tags
  320. echo x - zman/man/pathnames.h
  321. sed 's/^X//' >zman/man/pathnames.h << 'END-of-zman/man/pathnames.h'
  322. X/*
  323. X * Copyright (c) 1989 The Regents of the University of California.
  324. X * All rights reserved.
  325. X *
  326. X * Redistribution and use in source and binary forms, with or without
  327. X * modification, are permitted provided that the following conditions
  328. X * are met:
  329. X * 1. Redistributions of source code must retain the above copyright
  330. X *    notice, this list of conditions and the following disclaimer.
  331. X * 2. Redistributions in binary form must reproduce the above copyright
  332. X *    notice, this list of conditions and the following disclaimer in the
  333. X *    documentation and/or other materials provided with the distribution.
  334. X * 3. All advertising materials mentioning features or use of this software
  335. X *    must display the following acknowledgement:
  336. X *    This product includes software developed by the University of
  337. X *    California, Berkeley and its contributors.
  338. X * 4. Neither the name of the University nor the names of its contributors
  339. X *    may be used to endorse or promote products derived from this software
  340. X *    without specific prior written permission.
  341. X *
  342. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  343. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  344. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  345. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  346. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  347. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  348. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  349. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  350. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  351. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  352. X * SUCH DAMAGE.
  353. X *
  354. X *    @(#)pathnames.h    5.4 (Berkeley) 6/1/90
  355. X */
  356. X
  357. X#define    _PATH_MANCONF    "/etc/man.conf"
  358. X#define    _PATH_PAGER    "/usr/bin/more -s"
  359. X#define    _PATH_WHATIS    "whatis.db"
  360. X#define _PATH_ZCAT    "/usr/bin/zcat"
  361. END-of-zman/man/pathnames.h
  362. echo x - zman/man/man.conf.5
  363. sed 's/^X//' >zman/man/man.conf.5 << 'END-of-zman/man/man.conf.5'
  364. X.\" Copyright (c) 1989, 1991 The Regents of the University of California.
  365. X.\" All rights reserved.
  366. X.\"
  367. X.\" Redistribution and use in source and binary forms, with or without
  368. X.\" modification, are permitted provided that the following conditions
  369. X.\" are met:
  370. X.\" 1. Redistributions of source code must retain the above copyright
  371. X.\"    notice, this list of conditions and the following disclaimer.
  372. X.\" 2. Redistributions in binary form must reproduce the above copyright
  373. X.\"    notice, this list of conditions and the following disclaimer in the
  374. X.\"    documentation and/or other materials provided with the distribution.
  375. X.\" 3. All advertising materials mentioning features or use of this software
  376. X.\"    must display the following acknowledgement:
  377. X.\"    This product includes software developed by the University of
  378. X.\"    California, Berkeley and its contributors.
  379. X.\" 4. Neither the name of the University nor the names of its contributors
  380. X.\"    may be used to endorse or promote products derived from this software
  381. X.\"    without specific prior written permission.
  382. X.\"
  383. X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  384. X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  385. X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  386. X.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  387. X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  388. X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  389. X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  390. X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  391. X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  392. X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  393. X.\" SUCH DAMAGE.
  394. X.\"
  395. X.\"     @(#)man.conf.5    5.6 (Berkeley) 5/10/91
  396. X.\"
  397. X.Dd May 10, 1991
  398. X.Dt MAN.CONF 5
  399. X.Sh NAME
  400. X.Nm man.conf
  401. X.Nd configuration file for
  402. X.Xr man 1
  403. X.Sh DESCRIPTION
  404. XThe
  405. X.Xr man 1 ,
  406. X.Xr apropos 1 ,
  407. Xand
  408. X.Xr whatis 1
  409. Xcommands
  410. Xsearch for manual pages or their database files as specified by the
  411. X.Nm man.conf
  412. Xfile.
  413. XManual pages are expected to be preformatted (see
  414. X.Xr nroff 1 )
  415. Xand named with a trailing ``.0''.
  416. X.Pp
  417. XThe
  418. X.Nm man.conf
  419. Xfile contains two types of lines.
  420. X.Pp
  421. XThe first type of line is a ``section'' line, which contains a
  422. Xsection name followed by a directory path.
  423. XLines in this format specify that manual pages for the section
  424. Xmay be found in the directory.
  425. X.Pp
  426. XDirectories named with a trailing slash character (``/'') are expected
  427. Xto contain subdirectories (see the keyword ``_subdir'' below) instead
  428. Xof manual pages.
  429. XThese subdirectories are searched instead of the directory.
  430. X.Pp
  431. XAll directories (either explicitly specified or named with a trailing
  432. Xslash) may contain subdirectories.
  433. XThe
  434. X.Xr man 1
  435. Xcommand
  436. Xautomatically searches any subdirectory with the same name as the
  437. Xcurrent machine type before the directory is searched.
  438. XNo specification of these subdirectories is necessary in the
  439. X.Nm man.conf
  440. Xfile.
  441. X.Pp
  442. XSection names are unrestricted except for the reserved words specified
  443. Xbelow; in general, however, it is best to avoid anything beginning with
  444. Xan underscore (``_'') in order to avoid future incompatibilities.
  445. X.Pp
  446. XThe section named ``_default'' is the list of directories to be
  447. Xsearched if no section is specified.
  448. X.Pp
  449. XThe second type of line is preceded with a ``keyword''.
  450. XThe possible keywords and their meanings are as follows:
  451. X.Pp
  452. X.Bl -tag -width indent
  453. X.It _subdir
  454. XThe list (in search order) of subdirectories which will be searched in
  455. Xany directory named with a trailing slash (``/'') character.  This
  456. Xlist is also used when a path is specified by the
  457. X.Ev MANPATH
  458. Xenvironment 
  459. Xvariable or the
  460. X.Fl M
  461. Xoption.
  462. X.It _version
  463. XThe version of the configuration file.
  464. X.It _whatdb
  465. XThe full pathname (not just a directory path) for a database to be used
  466. Xby the
  467. X.Xr apropos 1
  468. Xand
  469. X.Xr whatis 1
  470. Xcommands.
  471. X.El
  472. X.Pp
  473. XMultiple specifications for all types of lines (except for ``_version'')
  474. Xare cumulative and the entries are used in the order listed in the file;
  475. Xmultiple entries may be listed per line, as well.
  476. X.Pp
  477. XEmpty lines or lines whose first non-whitespace character is a hash
  478. Xmark (``#'') are ignored.
  479. X.Sh EXAMPLES
  480. XGiven the following
  481. X.Nm man.conf
  482. Xfile:
  483. X.Bd -literal -offset indent
  484. X_version    BSD.1
  485. X_subdir        cat1 cat2 cat3
  486. X_default    /usr/share/man/
  487. Xsect3        /usr/share/man/cat3
  488. X.Ed
  489. X.Pp
  490. XThe default
  491. X.Xr mktemp 3
  492. Xmanual page should be stored in
  493. X.Dq Pa /usr/share/man/cat3/mktemp.0 .
  494. XAny
  495. X.Tn VAX
  496. Xarchitecture specific version of it should be stored in
  497. X.Dq Pa cat3/vax/mktemp.0 .
  498. X.Pp
  499. XThe command
  500. X.Dq Li man mktemp
  501. Xwould search the subdirectories
  502. X.Dq Pa cat1
  503. X.Dq Pa cat2 ,
  504. Xand
  505. X.Dq Pa cat3 ,
  506. Xin
  507. X.Dq Pa /usr/share/man ,
  508. Xin that order, for
  509. X.Dq Pa mktemp.0''.
  510. XIf a subdirectory with the same name as the current machine type
  511. Xexisted in any of them, it would be searched as well.
  512. X.Pp
  513. XThe command
  514. X.Dq Li man sect3 mktemp
  515. Xwould only search
  516. X.Dq Li /usr/share/man/cat3
  517. Xand any possible per machine subdirectory.
  518. X.Sh FILES
  519. X.Bl -tag -width /etc/man.conf -compact
  520. X.It Pa /etc/man.conf
  521. XStandard manual directory search path.
  522. X.El
  523. X.Sh SEE ALSO
  524. X.Xr apropos 1 ,
  525. X.Xr machine 1 ,
  526. X.Xr man 1 ,
  527. X.Xr whatis 1 ,
  528. X.Xr whereis 1
  529. X.Sh HISTORY
  530. XThe
  531. X.Nm
  532. Xfile format
  533. X.Ud .
  534. END-of-zman/man/man.conf.5
  535. echo x - zman/man/man.c
  536. sed 's/^X//' >zman/man/man.c << 'END-of-zman/man/man.c'
  537. X/*
  538. X * Copyright (c) 1987 Regents of the University of California.
  539. X * All rights reserved.
  540. X *
  541. X * Redistribution and use in source and binary forms, with or without
  542. X * modification, are permitted provided that the following conditions
  543. X * are met:
  544. X * 1. Redistributions of source code must retain the above copyright
  545. X *    notice, this list of conditions and the following disclaimer.
  546. X * 2. Redistributions in binary form must reproduce the above copyright
  547. X *    notice, this list of conditions and the following disclaimer in the
  548. X *    documentation and/or other materials provided with the distribution.
  549. X * 3. All advertising materials mentioning features or use of this software
  550. X *    must display the following acknowledgement:
  551. X *    This product includes software developed by the University of
  552. X *    California, Berkeley and its contributors.
  553. X * 4. Neither the name of the University nor the names of its contributors
  554. X *    may be used to endorse or promote products derived from this software
  555. X *    without specific prior written permission.
  556. X *
  557. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  558. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  559. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  560. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  561. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  562. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  563. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  564. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  565. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  566. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  567. X * SUCH DAMAGE.
  568. X */
  569. X
  570. X/*
  571. X * Modified by Graham Toal <gtoal@gtoal.com> to allow compressed
  572. X * manual pages.
  573. X *
  574. X * Modified by Luke Mewburn <zak@rmit.edu.au>:
  575. X *  - allow gzipped manual pages.
  576. X *  - fixed trashing of path variable in manual();
  577. X *  - removed a lot of mallocs/frees which were unnecessary
  578. X */
  579. X
  580. X
  581. X#ifndef lint
  582. Xchar copyright[] =
  583. X"@(#) Copyright (c) 1987 Regents of the University of California.\n\
  584. X All rights reserved.\n";
  585. X#endif /* not lint */
  586. X
  587. X#ifndef lint
  588. Xstatic char sccsid[] = "@(#)man.c    5.25 (386bsd) 01/24/92";
  589. X#endif /* not lint */
  590. X
  591. X#include <sys/param.h>
  592. X#include <sys/file.h>
  593. X#include <errno.h>
  594. X#include <stdio.h>
  595. X#include <ctype.h>
  596. X#include <string.h>
  597. X#include <stdlib.h>
  598. X#include <unistd.h> /* For mktemp */
  599. X#include "pathnames.h"
  600. X
  601. Xextern int errno;
  602. X
  603. Xint f_all, f_cat, f_how, f_where;
  604. Xchar *command, *machine, *p_augment, *p_path, *pager, *progname;
  605. Xextern char **arorder, *pathbuf;
  606. X
  607. Xtypedef struct strlist {
  608. X    char *fname;
  609. X    struct strlist *next;
  610. X} STRLIST;
  611. X
  612. XSTRLIST *delete_list = NULL;
  613. X
  614. Xvoid *
  615. Xqueue_delete(fname)
  616. Xchar *fname;
  617. X{
  618. X    STRLIST *l;
  619. X    l = malloc(sizeof(STRLIST));
  620. X    if (l == NULL)
  621. X        enomem();
  622. X    l->fname = strdup(fname);
  623. X    if (l->fname == NULL)
  624. X        enomem();
  625. X    l->next = delete_list; delete_list = l;
  626. X}
  627. X
  628. Xvoid delete_temps(void)
  629. X{
  630. X    while (delete_list != NULL) {
  631. X        remove(delete_list->fname);
  632. X/*        free(delete_list->fname);  - why slow the exit down...*/
  633. X        delete_list = delete_list->next;
  634. X    }
  635. X}
  636. X
  637. XFILE *
  638. Xmanopen(fname)
  639. Xchar *fname;
  640. X{
  641. X    FILE *fp;
  642. X    int l = strlen(fname);
  643. X    if ((l > 2) && (strcasecmp(fname+l-2, ".Z") == 0)) {
  644. X        /* Should really look up env var first and stick in a variable */
  645. X        command = malloc(strlen(_PATH_ZCAT)+1+strlen(fname)+1);
  646. X        if (command == NULL) enomem();
  647. X        sprintf(command, "%s %s", _PATH_ZCAT, fname);
  648. X/*
  649. X * should really do a check_zcat() like check_pager() -
  650. X * but why bother.  1) it had better be there if people
  651. X * have gone around compressing man pages, and 2) the
  652. X * popen() will fail cleanly enough to give some sort
  653. X * of error message...  Another alternative is my ZFILE *
  654. X * interface which allows a zfopen(filename, mode)
  655. X * and does all the decompressin itself without popen(),
  656. X * but again, since this is for 386bsd and we always
  657. X * have popen(), why bother?    - Graham
  658. X */
  659. X        if ((fp = popen(command, "r")) == NULL) {
  660. X            (void)fprintf(stderr, "man: %s: %s\n", fname, strerror(errno));
  661. X            exit(1);
  662. X        }
  663. X    } else if ((fp = fopen(fname, "r")) == NULL) {
  664. X        (void)fprintf(stderr, "man: %s: %s\n", fname, strerror(errno));
  665. X        exit(1);
  666. X    } else {
  667. X    }
  668. X    if (command != NULL) free(command); command = NULL;
  669. X    return(fp);
  670. X}
  671. X
  672. Xint
  673. Xmain(argc, argv)
  674. X    int argc;
  675. X    register char **argv;
  676. X{
  677. X    extern char *optarg;
  678. X    extern int optind;
  679. X    int ch, res;
  680. X    char *section[2], *check_pager(), *getpath(), **getorder(), *tmp;
  681. X
  682. X    atexit(delete_temps);
  683. X    progname = "man";
  684. X    while ((ch = getopt(argc, argv, "-acfhkM:m:P:w")) != EOF)
  685. X        switch((char)ch) {
  686. X        case 'a':
  687. X            f_all = 1;
  688. X            break;
  689. X        case 'c':
  690. X        case '-':        /* deprecated */
  691. X            f_cat = 1;
  692. X            break;
  693. X        case 'h':
  694. X            f_how = 1;
  695. X            break;
  696. X        case 'm':
  697. X            p_augment = optarg;
  698. X            break;
  699. X        case 'M':
  700. X        case 'P':        /* backward compatibility */
  701. X            p_path = optarg;
  702. X            break;
  703. X        /*
  704. X         * "man -f" and "man -k" are backward compatible, undocumented
  705. X         * ways of calling whatis(1) and apropos(1).
  706. X         */
  707. X        case 'f':
  708. X            jump(argv, "-f", "whatis");
  709. X            /* NOTREACHED */
  710. X        case 'k':
  711. X            jump(argv, "-k", "apropos");
  712. X            /* NOTREACHED */
  713. X        case 'w':
  714. X            f_all = f_where = 1;
  715. X            break;
  716. X        case '?':
  717. X        default:
  718. X            usage();
  719. X        }
  720. X    argv += optind;
  721. X
  722. X    if (!*argv)
  723. X        usage();
  724. X
  725. X    if (!f_cat && !f_how)
  726. X        if (!isatty(1))
  727. X            f_cat = 1;
  728. X        else if (pager = getenv("PAGER"))
  729. X            pager = check_pager(pager);
  730. X        else
  731. X            pager = _PATH_PAGER;
  732. X
  733. X    if (!(machine = getenv("MACHINE")))
  734. X        machine = MACHINE;
  735. X
  736. X    /* see if checking in a specific section */
  737. X    if (argc > 1 && getsection(*argv)) {
  738. X        section[0] = *argv++;
  739. X        section[1] = (char *)NULL;
  740. X    } else {
  741. X        section[0] = "_default";
  742. X        section[1] = (char *)NULL;
  743. X    }
  744. X
  745. X    arorder = getorder();
  746. X    if (p_path || (p_path = getenv("MANPATH"))) {
  747. X        char buf[MAXPATHLEN], **av;
  748. X
  749. X        tmp = strtok(p_path, ":"); 
  750. X        while (tmp) {
  751. X            (void)sprintf(buf, "%s/", tmp);
  752. X            for (av = arorder; *av; ++av)
  753. X                        cadd(buf, strlen(buf), *av);
  754. X            tmp = strtok((char *)NULL, ":"); 
  755. X        }
  756. X        p_path = pathbuf;
  757. X    } else if (!(p_path = getpath(section)) && !p_augment) {
  758. X        (void)fprintf(stderr,
  759. X            "man: no place to search for those manual pages.\n");
  760. X        exit(1);
  761. X    }
  762. X
  763. X    for (; *argv; ++argv) {
  764. X        if (p_augment)
  765. X            res = manual(p_augment, *argv);
  766. X        res = manual(p_path, *argv);
  767. X        if (res || f_where)
  768. X            continue;
  769. X        (void)fprintf(stderr,
  770. X            "man: no entry for %s in the manual.\n", *argv);
  771. X        exit(1);
  772. X    }
  773. X
  774. X    /* use system(3) in case someone's pager is "pager arg1 arg2" */
  775. X    if (command)
  776. X        (void)system(command);
  777. X    exit(0);
  778. X}
  779. X
  780. X/*
  781. X * manual --
  782. X *    given a path, a directory list and a file name, find a file
  783. X *    that matches; check ${directory}/${dir}/{file name} and
  784. X *    ${directory}/${dir}/${machine}/${file name}.
  785. X */
  786. Xmanual(path, name)
  787. X    char *path, *name;
  788. X{
  789. X    register int res;
  790. X    register char *end;
  791. X    char fname[MAXPATHLEN + 1], tpath[MAXPATHLEN+1];
  792. X
  793. X    for (res = 0;; path = end + 1) {
  794. X        if (!*path)                /* foo: */
  795. X            break;
  796. X        if (end = index(path, ':')) {
  797. X            if (end == path + 1)        /* foo::bar */
  798. X                continue;
  799. X                /* stop path getting trashed  - Luke*/
  800. X            res = end - path;
  801. X            strncpy(tpath, path, res);
  802. X            tpath[res] = '\0';
  803. X        }
  804. X        else
  805. X            strcpy(tpath, path);
  806. X        (void)sprintf(fname, "%s/%s.0", tpath, name);
  807. X        if (access(fname, R_OK)) {
  808. X            strcat(fname, ".z");
  809. X            if (access(fname, R_OK)) {
  810. X            fname[strlen(fname)-1] = 'Z';
  811. X            if (access(fname, R_OK)) {
  812. X                (void)sprintf(fname, "%s/%s/%s.0", tpath, machine, name);
  813. X                if (access(fname, R_OK)) {
  814. X                strcat(fname, ".z");
  815. X                if (access(fname, R_OK)) {
  816. X                    fname[strlen(fname)-1] = 'Z';
  817. X                    if (access(fname, R_OK)) {
  818. X                    continue;
  819. X                    }
  820. X                }
  821. X                }
  822. X            }
  823. X            }
  824. X        }
  825. X
  826. X        if (f_where)
  827. X            (void)printf("man: found in %s.\n", fname);
  828. X        else if (f_cat)
  829. X            cat(fname);
  830. X        else if (f_how)
  831. X            how(fname);
  832. X        else
  833. X            add(fname);
  834. X        if (!f_all)
  835. X            return(1);
  836. X        res = 1;
  837. X        if (!end)
  838. X            break;
  839. X        *end = ':';
  840. X    }
  841. X    return(res);
  842. X}
  843. X
  844. X/*
  845. X * how --
  846. X *    display how information
  847. X */
  848. Xhow(fname)
  849. X    char *fname;
  850. X{
  851. X    register FILE *fp;
  852. X
  853. X    register int lcnt, print;
  854. X    register char *p;
  855. X    char buf[BUFSIZ];
  856. X
  857. X    if (!(fp = manopen(fname))) {
  858. X        (void)fprintf(stderr, "man: %s: %s\n", fname, strerror(errno));
  859. X        exit(1);
  860. X    }
  861. X#define    S1    "SYNOPSIS"
  862. X#define    S2    "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS"
  863. X#define    D1    "DESCRIPTION"
  864. X#define    D2    "D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN"
  865. X    for (lcnt = print = 0; fgets(buf, sizeof(buf), fp);) {
  866. X        if (!strncmp(buf, S1, sizeof(S1) - 1) ||
  867. X            !strncmp(buf, S2, sizeof(S2) - 1)) {
  868. X            print = 1;
  869. X            continue;
  870. X        } else if (!strncmp(buf, D1, sizeof(D1) - 1) ||
  871. X            !strncmp(buf, D2, sizeof(D2) - 1))
  872. X            return;
  873. X        if (!print)
  874. X            continue;
  875. X        if (*buf == '\n')
  876. X            ++lcnt;
  877. X        else {
  878. X            for(; lcnt; --lcnt)
  879. X                (void)putchar('\n');
  880. X            for (p = buf; isspace(*p); ++p);
  881. X            (void)fputs(p, stdout);
  882. X        }
  883. X    }
  884. X    (void)fclose(fp);
  885. X}
  886. X/*
  887. X * cat --
  888. X *    cat out the file
  889. X */
  890. Xcat(fname)
  891. X    char *fname;
  892. X{
  893. X    register int n;
  894. X    FILE *fp;
  895. X    char buf[BUFSIZ];
  896. X
  897. X    fp = manopen(fname);
  898. X    for (;;) {
  899. X        n = fread(buf, 1, sizeof(buf), fp);
  900. X        if (n <= 0) break;
  901. X        if (fwrite(buf, 1, n, stdout) != n) {
  902. X            (void)fprintf(stderr,
  903. X                "man: write: %s\n", strerror(errno));
  904. X            exit(1);
  905. X        }
  906. X    }
  907. X    (void)fclose(fp);
  908. X}
  909. X
  910. X/*
  911. X * add --
  912. X *    add a file name to the list for future paging
  913. X */
  914. Xadd(fname)
  915. X    char *fname;
  916. X{
  917. X    static u_int buflen;
  918. X    static int len;
  919. X    static char *cp;
  920. X    int flen;
  921. X
  922. X    if (!command) {
  923. X        if (!(command = malloc(buflen = 1024)))
  924. X            enomem();
  925. X        len = strlen(strcpy(command, pager));
  926. X        cp = command + len;
  927. X    }
  928. X    /* If filename ends in .Z, decompress it and more the tmp file */
  929. X    flen = strlen(fname);
  930. X    if (strcasecmp(fname+flen-2, ".Z") == 0) {
  931. X/*
  932. X * These local arrays should be off the heap, but this
  933. X * is one of those quick hack programs that works and
  934. X * I can't be bothered.  Someone else do it if it's a
  935. X * problem.  Sorry folks.  - Graham
  936. X */
  937. X        char temp[256];
  938. X        char cmnd[256];
  939. X        char rootname[256];
  940. X        char *s;
  941. X        s = fname+flen-2-1;
  942. X        for (;;) {
  943. X            if (s == fname) break;
  944. X            if (*(s-1) == '/') break;
  945. X            s -= 1;
  946. X        }
  947. X        strcpy(rootname, s);
  948. X        rootname[strlen(rootname)-2] = '\0';
  949. X        sprintf(temp, "/tmp/%s.XXXX", rootname);
  950. X        (void)mktemp(temp);
  951. X            /* And queue temp file for deletion */
  952. X        queue_delete(temp);
  953. X        sprintf(cmnd, "%s %s > %s", _PATH_ZCAT, fname, temp);
  954. X        system(cmnd);
  955. X        strcpy(fname, temp);    /* in manual(), fname is an array */
  956. X    }
  957. X    flen = strlen(fname);
  958. X    if (len + flen + 2 > buflen) {        /* +2 == space, EOS */
  959. X        if (!(command = realloc(command, buflen += 1024)))
  960. X            enomem();
  961. X        cp = command + len;
  962. X    }
  963. X    *cp++ = ' ';
  964. X    len += flen + 1;            /* +1 = space */
  965. X    (void)strcpy(cp, fname);
  966. X    cp += flen;
  967. X}
  968. X
  969. X/*
  970. X * check_pager --
  971. X *    check the user supplied page information
  972. X */
  973. Xchar *
  974. Xcheck_pager(name)
  975. X    char *name;
  976. X{
  977. X    register char *p;
  978. X    char *save;
  979. X
  980. X    /*
  981. X     * if the user uses "more", we make it "more -s"; watch out for
  982. X     * PAGER = "mypager /usr/ucb/more"
  983. X     */
  984. X    for (p = name; *p && !isspace(*p); ++p);
  985. X    for (; p > name && *p != '/'; --p);
  986. X    if (p != name)
  987. X        ++p;
  988. X
  989. X    /* make sure it's "more", not "morex" */
  990. X    if (!strncmp(p, "more", 4) && (!p[4] || isspace(p[4]))){
  991. X        save = name;
  992. X        /* allocate space to add the "-s" */
  993. X        if (!(name =
  994. X            malloc((u_int)(strlen(save) + sizeof("-s") + 1))))
  995. X            enomem();
  996. X        (void)sprintf(name, "%s %s", save, "-s");
  997. X    }
  998. X    return(name);
  999. X}
  1000. X
  1001. X/*
  1002. X * jump --
  1003. X *    strip out flag argument and jump
  1004. X */
  1005. Xjump(argv, flag, name)
  1006. X    char **argv, *name;
  1007. X    register char *flag;
  1008. X{
  1009. X    register char **arg;
  1010. X
  1011. X    argv[0] = name;
  1012. X    for (arg = argv + 1; *arg; ++arg)
  1013. X        if (!strcmp(*arg, flag))
  1014. X            break;
  1015. X    for (; *arg; ++arg)
  1016. X        arg[0] = arg[1];
  1017. X    execvp(name, argv);
  1018. X    (void)fprintf(stderr, "%s: Command not found.\n", name);
  1019. X    exit(1);
  1020. X}
  1021. X
  1022. X/*
  1023. X * usage --
  1024. X *    print usage message and die
  1025. X */
  1026. Xusage()
  1027. X{
  1028. X    (void)fprintf(stderr,
  1029. X        "usage: man [-ac] [-M path] [-m path] [section] title ...\n");
  1030. X    exit(1);
  1031. X}
  1032. END-of-zman/man/man.c
  1033. echo x - zman/man/man.1
  1034. sed 's/^X//' >zman/man/man.1 << 'END-of-zman/man/man.1'
  1035. X.\" Copyright (c) 1989, 1990 The Regents of the University of California.
  1036. X.\" All rights reserved.
  1037. X.\"
  1038. X.\" Redistribution and use in source and binary forms, with or without
  1039. X.\" modification, are permitted provided that the following conditions
  1040. X.\" are met:
  1041. X.\" 1. Redistributions of source code must retain the above copyright
  1042. X.\"    notice, this list of conditions and the following disclaimer.
  1043. X.\" 2. Redistributions in binary form must reproduce the above copyright
  1044. X.\"    notice, this list of conditions and the following disclaimer in the
  1045. X.\"    documentation and/or other materials provided with the distribution.
  1046. X.\" 3. All advertising materials mentioning features or use of this software
  1047. X.\"    must display the following acknowledgement:
  1048. X.\"    This product includes software developed by the University of
  1049. X.\"    California, Berkeley and its contributors.
  1050. X.\" 4. Neither the name of the University nor the names of its contributors
  1051. X.\"    may be used to endorse or promote products derived from this software
  1052. X.\"    without specific prior written permission.
  1053. X.\"
  1054. X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  1055. X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1056. X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1057. X.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  1058. X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  1059. X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  1060. X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  1061. X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  1062. X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  1063. X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  1064. X.\" SUCH DAMAGE.
  1065. X.\"
  1066. X.\"     @(#)man.1    6.14 (Berkeley) 4/29/91
  1067. X.\"
  1068. X.Dd April 29, 1991
  1069. X.Dt MAN 1
  1070. X.Os BSD 4
  1071. X.Sh NAME
  1072. X.Nm man
  1073. X.Nd display the on-line manual pages
  1074. X.Sh SYNOPSIS
  1075. X.Nm man
  1076. X.Op Fl achw
  1077. X.Op Fl M Ar path
  1078. X.Op Fl m Ar path
  1079. X.Op Ar section
  1080. X.Ar name Ar ...
  1081. X.Sh DESCRIPTION
  1082. XThe
  1083. X.Nm man
  1084. Xutility
  1085. Xdisplays the
  1086. X.Bx
  1087. Xmanual pages entitled
  1088. X.Ar name .
  1089. X.Pp
  1090. XThe options are as follows:
  1091. X.Bl -tag -width indent
  1092. X.It Fl a
  1093. XDisplay all of the manual pages for a specified
  1094. X.Ar section
  1095. Xand
  1096. X.Ar name
  1097. Xcombination.
  1098. X(Normally, only the first manual page found is displayed.)
  1099. X.It Fl c
  1100. XCopy the manual page to the standard output instead of using
  1101. X.Xr more 1
  1102. Xto paginate it.
  1103. XThis is done by default if the standard output is not a terminal device.
  1104. X.It Fl h
  1105. XDisplay only the
  1106. X.Dq Tn SYNOPSIS
  1107. Xlines of the requested manual pages.
  1108. X.It Fl M
  1109. XOverride the list of standard directories which
  1110. X.Nm man
  1111. Xsearches for manual pages.
  1112. XThe supplied
  1113. X.Ar path
  1114. Xmust be a colon (``:'') separated list of directories.
  1115. XThis search path may also be set using the environment variable
  1116. X.Ev MANPATH .
  1117. XThe subdirectories to be searched as well as their search order
  1118. Xis specified by the ``_subdir'' line in the
  1119. X.Nm man
  1120. Xconfiguration file.
  1121. X.It Fl m
  1122. XAugment the list of standard directories which
  1123. X.Nm man
  1124. Xsearches for manual pages.
  1125. XThe supplied
  1126. X.Ar path
  1127. Xmust be a colon (``:'') separated list of directories.
  1128. XThese directories will be searched before the standard directories or
  1129. Xthe directories specified using the
  1130. X.Fl M
  1131. Xoption or the
  1132. X.Ev MANPATH
  1133. Xenvironment variable.
  1134. X.It Fl w
  1135. XList the pathnames of the manual pages which
  1136. X.Nm man
  1137. Xwould display for the specified
  1138. X.Ar section
  1139. Xand
  1140. X.Ar name
  1141. Xcombination.
  1142. X.El
  1143. X.Pp
  1144. XThe optional
  1145. X.Ar section
  1146. Xrestricts the directories that
  1147. X.Nm man
  1148. Xwill search.
  1149. XThe
  1150. X.Nm man
  1151. Xconfiguration file (see
  1152. X.Xr man_conf 5 )
  1153. Xspecifies the possible
  1154. X.Ar section
  1155. Xvalues that are currently available.
  1156. XIf only a single argument is specified or if the first argument is
  1157. Xnot a valid section,
  1158. X.Nm man
  1159. Xassumes that the argument is the name of a manual page to be displayed.
  1160. X.Sh ENVIRONMENT
  1161. X.Bl -tag -width MANPATHX
  1162. X.It Ev MACHINE
  1163. XAs some manual pages are intended only for use on certain architectures,
  1164. X.Nm man
  1165. Xsearches certain directories applicable to the current machine.
  1166. XMan's
  1167. Xdetermination of the current machine type may be overridden by setting
  1168. Xthe environment variable
  1169. X.Ev MACHINE
  1170. Xto the name of an architecture (see
  1171. X.Xr machine 1 ) .
  1172. XMachine specific areas are checked before general areas.
  1173. X.It Ev MANPATH
  1174. XThe standard search path used by
  1175. X.Nm man
  1176. Xmay be overridden by specifying a path in the
  1177. X.Ev MANPATH
  1178. Xenvironment
  1179. Xvariable.
  1180. XThe format of the path is a colon (``:'') separated list of directories.
  1181. XThe subdirectories to be searched as well as their search order
  1182. Xis specified by the ``_subdir'' line in the
  1183. X.Nm man
  1184. Xconfiguration file.
  1185. X.It Ev PAGER
  1186. XAny value of the environment variable
  1187. X.Ev PAGER
  1188. Xwill be used instead of the standard pagination program
  1189. X.Xr more 1 .
  1190. X.El
  1191. X.Sh FILES
  1192. X.Bl -tag -width /etc/man.conf -compact
  1193. X.It Pa /etc/man.conf
  1194. Xman configuration file (see
  1195. X.Xr man_conf 5 )
  1196. X.El
  1197. X.Sh SEE ALSO
  1198. X.Xr apropos 1 ,
  1199. X.Xr machine 1 ,
  1200. X.Xr whatis 1 ,
  1201. X.Xr whereis 1 ,
  1202. X.Xr man_conf 5
  1203. X.Sh BUGS
  1204. XThe on-line manual pages are, by necessity, forgiving toward stupid
  1205. Xdisplay devices, causing some manual pages to not be as good as their
  1206. Xtypeset counterparts.
  1207. X.Sh HISTORY
  1208. XA
  1209. X.Nm
  1210. Xcommand appeared in
  1211. X.At v6 .
  1212. XThe ability to display manual pages compressed with
  1213. X.Xr compress 1
  1214. Xwas added by Luke Mewburn (zak@rmit.edu.au), 930105.
  1215. END-of-zman/man/man.1
  1216. echo x - zman/man/config.c
  1217. sed 's/^X//' >zman/man/config.c << 'END-of-zman/man/config.c'
  1218. X/*
  1219. X * Copyright (c) 1989 The Regents of the University of California.
  1220. X * All rights reserved.
  1221. X *
  1222. X * Redistribution and use in source and binary forms, with or without
  1223. X * modification, are permitted provided that the following conditions
  1224. X * are met:
  1225. X * 1. Redistributions of source code must retain the above copyright
  1226. X *    notice, this list of conditions and the following disclaimer.
  1227. X * 2. Redistributions in binary form must reproduce the above copyright
  1228. X *    notice, this list of conditions and the following disclaimer in the
  1229. X *    documentation and/or other materials provided with the distribution.
  1230. X * 3. All advertising materials mentioning features or use of this software
  1231. X *    must display the following acknowledgement:
  1232. X *    This product includes software developed by the University of
  1233. X *    California, Berkeley and its contributors.
  1234. X * 4. Neither the name of the University nor the names of its contributors
  1235. X *    may be used to endorse or promote products derived from this software
  1236. X *    without specific prior written permission.
  1237. X *
  1238. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  1239. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1240. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1241. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  1242. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  1243. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  1244. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  1245. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  1246. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  1247. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  1248. X * SUCH DAMAGE.
  1249. X *
  1250. X * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
  1251. X * --------------------         -----   ----------------------
  1252. X * CURRENT PATCH LEVEL:         1       00008
  1253. X * --------------------         -----   ----------------------
  1254. X *
  1255. X * 03 Sep 92    James Dolter        Fixed 1K pathbuf bug
  1256. X */
  1257. X
  1258. X#ifndef lint
  1259. Xstatic char sccsid[] = "@(#)config.c    5.6 (Berkeley) 3/1/91";
  1260. X#endif /* not lint */
  1261. X
  1262. X#include <sys/param.h>
  1263. X#include <stdio.h>
  1264. X#include <errno.h>
  1265. X#include <string.h>
  1266. X#include <stdlib.h>
  1267. X#include <pwd.h>
  1268. X#include "pathnames.h"
  1269. X
  1270. X#define    MAXLINE        1024
  1271. X
  1272. Xextern char *progname;
  1273. Xchar *pathbuf, **arorder;
  1274. X
  1275. Xstatic FILE *cfp;
  1276. X
  1277. X/*
  1278. X * getpath --
  1279. X *    read in the configuration file, calling a function with the line
  1280. X *    from each matching section.
  1281. X */
  1282. Xchar *
  1283. Xgetpath(sects)
  1284. X    char **sects;
  1285. X{
  1286. X    register char **av, *p;
  1287. X    size_t len;
  1288. X    char line[MAXLINE];
  1289. X    static int openconfig();
  1290. X
  1291. X    openconfig();
  1292. X    while (fgets(line, sizeof(line), cfp)) {
  1293. X        if (!index(line, '\n')) {
  1294. X            (void)fprintf(stderr, "%s: config line too long.\n",
  1295. X                progname);
  1296. X            exit(1);
  1297. X        }
  1298. X        p = strtok(line, " \t\n");
  1299. X        if (!p || *p == '#')
  1300. X            continue;
  1301. X        for (av = sects; *av; ++av)
  1302. X            if (!strcmp(p, *av))
  1303. X                break;
  1304. X        if (!*av)
  1305. X            continue;
  1306. X        while (p = strtok((char *)NULL, " \t\n")) {
  1307. X            len = strlen(p);
  1308. X            if (p[len - 1] == '/')
  1309. X                for (av = arorder; *av; ++av)
  1310. X                            cadd(p, len, *av);
  1311. X            else
  1312. X                cadd(p, len, (char *)NULL);
  1313. X        }
  1314. X    }
  1315. X    return(pathbuf);
  1316. X}
  1317. X
  1318. Xcadd(add1, len1, add2)
  1319. Xchar *add1, *add2;
  1320. Xregister size_t len1;
  1321. X{
  1322. X    static size_t buflen;
  1323. X    static char *bp, *endp;
  1324. X    register size_t len2;
  1325. X    register size_t    oldlen;                /* 03 Sep 92*/
  1326. X
  1327. X    len2 = add2 ? strlen(add2) : 0;
  1328. X    if (!bp || bp + len1 + len2 + 2 >= endp) {
  1329. X        oldlen = bp - pathbuf;            /* 03 Sep 92*/
  1330. X        if (!(pathbuf = realloc(pathbuf, buflen += 1024)))
  1331. X            enomem();
  1332. X        bp = pathbuf + oldlen;            /* 03 Sep 92*/
  1333. X        endp = pathbuf + buflen;
  1334. X    }
  1335. X    bcopy(add1, bp, len1);
  1336. X    bp += len1;
  1337. X    if (len2) {
  1338. X        bcopy(add2, bp, len2);
  1339. X        bp += len2;
  1340. X    }
  1341. X    *bp++ = ':';
  1342. X    *bp = '\0';
  1343. X}
  1344. X
  1345. Xstatic
  1346. Xopenconfig()
  1347. X{
  1348. X    if (cfp) {
  1349. X        rewind(cfp);
  1350. X        return;
  1351. X    }
  1352. X    if (!(cfp = fopen(_PATH_MANCONF, "r"))) {
  1353. X        (void)fprintf(stderr, "%s: no configuration file %s.\n",
  1354. X            progname, _PATH_MANCONF);
  1355. X        exit(1);
  1356. X    }
  1357. X}
  1358. X
  1359. Xchar **
  1360. Xgetdb()
  1361. X{
  1362. X    register char *p;
  1363. X    int cnt, num;
  1364. X    char **ar, line[MAXLINE];
  1365. X
  1366. X    ar = NULL;
  1367. X    num = 0;
  1368. X    cnt = -1;
  1369. X    openconfig();
  1370. X    while (fgets(line, sizeof(line), cfp)) {
  1371. X        if (!index(line, '\n')) {
  1372. X            (void)fprintf(stderr, "%s: config line too long.\n",
  1373. X                progname);
  1374. X            exit(1);
  1375. X        }
  1376. X        p = strtok(line, " \t\n");
  1377. X#define    WHATDB    "_whatdb"
  1378. X        if (!p || *p == '#' || strcmp(p, WHATDB))
  1379. X            continue;
  1380. X        while (p = strtok((char *)NULL, " \t\n")) {
  1381. X            if (cnt == num - 1 &&
  1382. X                !(ar = realloc(ar, (num += 30) * sizeof(char **))))
  1383. X                enomem();
  1384. X            if (!(ar[++cnt] = strdup(p)))
  1385. X                enomem();
  1386. X        }
  1387. X    }
  1388. X    if (ar) {
  1389. X        if (cnt == num - 1 &&
  1390. X            !(ar = realloc(ar, ++num * sizeof(char **))))
  1391. X            enomem();
  1392. X        ar[++cnt] = NULL;
  1393. X    }
  1394. X    return(ar);
  1395. X}
  1396. X
  1397. Xchar **
  1398. Xgetorder()
  1399. X{
  1400. X    register char *p;
  1401. X    int cnt, num;
  1402. X    char **ar, line[MAXLINE];
  1403. X
  1404. X    ar = NULL;
  1405. X    num = 0;
  1406. X    cnt = -1;
  1407. X    openconfig();
  1408. X    while (fgets(line, sizeof(line), cfp)) {
  1409. X        if (!index(line, '\n')) {
  1410. X            (void)fprintf(stderr, "%s: config line too long.\n",
  1411. X                progname);
  1412. X            exit(1);
  1413. X        }
  1414. X        p = strtok(line, " \t\n");
  1415. X#define    SUBDIR    "_subdir"
  1416. X        if (!p || *p == '#' || strcmp(p, SUBDIR))
  1417. X            continue;
  1418. X        while (p = strtok((char *)NULL, " \t\n")) {
  1419. X            if (cnt == num - 1 &&
  1420. X                !(ar = realloc(ar, (num += 30) * sizeof(char **))))
  1421. X                enomem();
  1422. X            if (!(ar[++cnt] = strdup(p)))
  1423. X                enomem();
  1424. X        }
  1425. X    }
  1426. X    if (ar) {
  1427. X        if (cnt == num - 1 &&
  1428. X            !(ar = realloc(ar, ++num * sizeof(char **))))
  1429. X            enomem();
  1430. X        ar[++cnt] = NULL;
  1431. X    }
  1432. X    return(ar);
  1433. X}
  1434. X
  1435. Xgetsection(sect)
  1436. X    char *sect;
  1437. X{
  1438. X    register char *p;
  1439. X    char line[MAXLINE];
  1440. X
  1441. X    openconfig();
  1442. X    while (fgets(line, sizeof(line), cfp)) {
  1443. X        if (!index(line, '\n')) {
  1444. X            (void)fprintf(stderr, "%s: config line too long.\n",
  1445. X                progname);
  1446. X            exit(1);
  1447. X        }
  1448. X        p = strtok(line, " \t\n");
  1449. X        if (!p || *p == '#')
  1450. X            continue;
  1451. X        if (!strcmp(p, sect))
  1452. X            return(1);
  1453. X    }
  1454. X    return(0);
  1455. X}
  1456. X
  1457. Xenomem()
  1458. X{
  1459. X    (void)fprintf(stderr, "%s: %s\n", progname, strerror(ENOMEM));
  1460. X    exit(1);
  1461. X}
  1462. END-of-zman/man/config.c
  1463. echo x - zman/man/Makefile
  1464. sed 's/^X//' >zman/man/Makefile << 'END-of-zman/man/Makefile'
  1465. X#    @(#)Makefile    5.12 (Berkeley) 9/30/90
  1466. X
  1467. XPROG=    man
  1468. XSRCS=    config.c man.c
  1469. XMAN1=    man.0
  1470. XMAN5=    man.conf.0
  1471. X
  1472. X#.include "../Makefile.inc"
  1473. X.include <bsd.prog.mk>
  1474. END-of-zman/man/Makefile
  1475. echo c - zman/whatis
  1476. mkdir zman/whatis > /dev/null 2>&1
  1477. echo x - zman/whatis/makewhatis.sed
  1478. sed 's/^X//' >zman/whatis/makewhatis.sed << 'END-of-zman/whatis/makewhatis.sed'
  1479. X#!/usr/bin/sed -
  1480. X#
  1481. X# This file is: /usr/othersrc/share/man/makewhatis.sed
  1482. X#
  1483. X# Copyright (c) 1988 The Regents of the University of California.
  1484. X# All rights reserved.
  1485. X#
  1486. X# Redistribution and use in source and binary forms, with or without
  1487. X# modification, are permitted provided that the following conditions
  1488. X# are met:
  1489. X# 1. Redistributions of source code must retain the above copyright
  1490. X#    notice, this list of conditions and the following disclaimer.
  1491. X# 2. Redistributions in binary form must reproduce the above copyright
  1492. X#    notice, this list of conditions and the following disclaimer in the
  1493. X#    documentation and/or other materials provided with the distribution.
  1494. X# 3. All advertising materials mentioning features or use of this software
  1495. X#    must display the following acknowledgement:
  1496. X#    This product includes software developed by the University of
  1497. X#    California, Berkeley and its contributors.
  1498. X# 4. Neither the name of the University nor the names of its contributors
  1499. X#    may be used to endorse or promote products derived from this software
  1500. X#    without specific prior written permission.
  1501. X#
  1502. X# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  1503. X# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1504. X# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1505. X# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  1506. X# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  1507. X# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  1508. X# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  1509. X# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  1510. X# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  1511. X# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  1512. X# SUCH DAMAGE.
  1513. X#
  1514. X#    @(#)makewhatis.sed    5.5 (Berkeley) 4/17/91
  1515. X#
  1516. X
  1517. X/(\([a-zA-Z0-9]*\).*UNIX Programmer's Manual/ {
  1518. X    s;.*(\([a-zA-Z0-9]*\).*UNIX.*;\1;
  1519. X    h
  1520. X    d
  1521. X}
  1522. X
  1523. X/^NNAAMMEE/!d
  1524. X
  1525. X:name
  1526. X    s;.*;;
  1527. X    N
  1528. X    s;\n;;
  1529. X    # some twits underline the command name
  1530. X    s;_;;g
  1531. X    /^[^     ]/b print
  1532. X    H
  1533. X    b name
  1534. X
  1535. X:print
  1536. X    x
  1537. X    s;\n;;g
  1538. X    /-/!d
  1539. X    s;\([a-z][A-z]\)-[     ][     ]*;\1;
  1540. X    s;\([a-zA-Z0-9,]\)[     ][     ]*;\1 ;g
  1541. X    s;[^a-zA-Z0-9]*\([a-zA-Z0-9]*\)[^a-zA-Z0-9]*\(.*\) - \(.*\);\2 (\1) - \3;
  1542. X    p
  1543. X    q
  1544. END-of-zman/whatis/makewhatis.sed
  1545. echo x - zman/whatis/Makefile
  1546. sed 's/^X//' >zman/whatis/Makefile << 'END-of-zman/whatis/Makefile'
  1547. X#
  1548. X# This file is: /usr/othersrc/share/man/Makefile
  1549. X#
  1550. X#    @(#)Makefile    5.9 (Berkeley) 7/1/91
  1551. X#
  1552. X# PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
  1553. X# --------------------         -----   ----------------------
  1554. X# CURRENT PATCH LEVEL:         1       00026
  1555. X# --------------------         -----   ----------------------
  1556. X#
  1557. X# 05 Aug 92    James Jegers        Fix whatis.db file format
  1558. X# 17 Jan 93     Luke Mewburn        Will look in .[zZ] files
  1559. X
  1560. XSUBDIR=    man1 man3 man4 man5 man7 man8
  1561. XMANDIRS=/usr/share/man /usr/local/man
  1562. X
  1563. Xafterinstall:
  1564. X    install -c -o ${BINOWN} -g ${BINGRP} -m 444 makewhatis.sed \
  1565. X        ${DESTDIR}/usr/share/man/makewhatis.sed
  1566. X    install -c -o ${BINOWN} -g ${BINGRP} -m 444 man0/COPYRIGHT \
  1567. X        ${DESTDIR}/usr/share/man/COPYRIGHT
  1568. X
  1569. Xmakedb:
  1570. X    rm -f whatis.db
  1571. X    for file in `find ${MANDIRS} -type f -name '*.0' -print`; do \
  1572. X        sed -n -f /usr/share/man/makewhatis.sed $$file; \
  1573. X    done | col -b >> whatis.db
  1574. X    for file in `find ${MANDIRS} -type f -name '*.0.[zZ]' -print`; do \
  1575. X        zcat $$file | sed -n -f /usr/share/man/makewhatis.sed; \
  1576. X    done | col -b >> whatis.db
  1577. X    sort -u -o whatis.db whatis.db
  1578. X    install -o ${BINOWN} -g ${BINGRP} -m 444 whatis.db \
  1579. X        ${DESTDIR}/usr/share/man
  1580. X
  1581. X.include <bsd.subdir.mk>
  1582. END-of-zman/whatis/Makefile
  1583. echo x - zman/fixman
  1584. sed 's/^X//' >zman/fixman << 'END-of-zman/fixman'
  1585. X#!/bin/sh
  1586. X#
  1587. X# File: fixman
  1588. X# By:   Luke Mewburn (zak@rmit.EDU.AU)
  1589. X# Date: 930117
  1590. X# Vers: 2.0.2
  1591. X#
  1592. X#
  1593. X# Synopsis:
  1594. X#    converts a manual tree to gzipped format.
  1595. X#
  1596. X# Usage:
  1597. X#    fixman
  1598. X#
  1599. X#     This converts all compressed and normal files in the current subtree
  1600. X# (with links) to gzip -9 files (with # correct links)
  1601. X#
  1602. X# Bugs:
  1603. X#  - slow
  1604. X#
  1605. X
  1606. Xls -li `find . \( -type f -o -type l \)` | \
  1607. Xsort | \
  1608. Xawk '
  1609. X{
  1610. X    if (NF == 11)
  1611. X    {
  1612. X    if ($10 == "->")
  1613. X    {
  1614. X        symlink_arr[ $9 ] = $11
  1615. X        printf "echo adding %s, %s to arr\n", $9, $11
  1616. X    }
  1617. X    next
  1618. X    }
  1619. X    if (NF != 9 )
  1620. X    next
  1621. X    links=$3
  1622. X    orig=$9
  1623. X    if (index(orig, ".Z") != 0)
  1624. X    {
  1625. X    printf "gunzip %s\n", orig
  1626. X    sub("\.Z$", "", orig)
  1627. X    }
  1628. X    if (index(orig, ".z") == 0)
  1629. X    {
  1630. X    printf "gzip -9 -f %s\n", orig
  1631. X    printf "echo %s zipped.\n", orig
  1632. X    }
  1633. X    if (links>1)
  1634. X    {
  1635. X    inode=$1
  1636. X    for (count=1; count <links ; count++)
  1637. X    {
  1638. X        getline
  1639. X        if ($1 != inode)
  1640. X        next
  1641. X        nxtnam=$9
  1642. X        if (index(nxtnam, ".z") != 0)
  1643. X        {
  1644. X#        printf "echo skipping %s\n", nxtnam
  1645. X        continue;
  1646. X        }
  1647. X        printf "rm %s\n", $9
  1648. X        sub("\.Z$", "", nxtnam)
  1649. X        printf "if ( -e %s.z ) then\n", orig
  1650. X        printf "  ln %s.z %s.z\n", orig, nxtnam
  1651. X        printf "  echo %s.z linked to %s.z.\n", orig, nxtnam
  1652. X        print  "else"
  1653. X        printf "  ln %s %s\n", orig, nxtnam
  1654. X        printf "  echo %s linked to %s.\n", orig, nxtnam
  1655. X        print  "endif"
  1656. X    }
  1657. X    }
  1658. X}
  1659. X
  1660. XEND {
  1661. X    printf "\necho re-fixing symbolic links:\n"
  1662. X    for ( elm in symlink_arr )
  1663. X    {
  1664. X    src = symlink_arr[ elm ]
  1665. X    printf "rm %s\n", elm
  1666. X    printf "if ( -e `dirname %s`/%s.z ) then\n", elm, src
  1667. X    printf "  ln -s %s.z %s.z\n", src, elm
  1668. X    printf "  echo %s.z symlinked to %s.z.\n", elm, src
  1669. X    print  "else"
  1670. X    printf "  ln -s %s %s\n", src, elm
  1671. X    printf "  echo %s symlinked to %s.\n", elm, src
  1672. X    print  "endif"
  1673. X    }
  1674. X}
  1675. X' | csh -f
  1676. END-of-zman/fixman
  1677. exit
  1678.  
  1679. --
  1680.                Luke Mewburn [Zak]     zak@rmit.edu.au
  1681.    "Nobody dies on the Discworld, they just become dimensionally
  1682.     disadvantaged."         Terry Pratchett in alt.fan.pratchett
  1683.