home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume6 / ya-man < prev    next >
Internet Message Format  |  1989-02-03  |  43KB

  1. Path: lll-winken!ames!pasteur!ucbvax!decwrl!wyse!uunet!allbery
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Newsgroups: comp.sources.misc
  4. Subject: v06i011: replacement "man" program
  5. Message-ID: <47276@uunet.UU.NET>
  6. Date: 24 Jan 89 03:02:49 GMT
  7. Sender: allbery@uunet.UU.NET
  8. Reply-To: chip@vector.UUCP (Chip Rosenthal)
  9. Organization: Dallas Semiconductor
  10. Lines: 1436
  11. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  12.  
  13. Posting-number: Volume 6, Issue 11
  14. Submitted-by: chip@vector.UUCP (Chip Rosenthal)
  15. Archive-name: ya-man
  16.  
  17. The "man" program is a replacement for the system "man" command.  It
  18. offers the following features:
  19.  
  20.     (1)  Ability to organize man directories to your preferences.
  21.     (2)  Understands both normal UNIX and bizarre XENIX naming conventions.
  22.     (3)  Supports packed and compressed files.
  23.     (4)  Supports cross-index, for example to locate strcpy(3) in string(3).
  24.     (5)  Ability to make "man" do what you want - 'cause you now have source.
  25.  
  26. --- cut here -----------------------------------------------------------------
  27. #! /bin/sh
  28. # this is a "shar" archive - run through "/bin/sh" to extract 11 files:
  29. #   README man.h patchlevel.h man.c lookup.c index.c manpage.c man.man catman Install Makefile
  30. # Wrapped by bin@vector on Fri Dec 30 20:46:19 CST 1988
  31. # Unpacking this archive requires:  sed test wc (possibly mkdir)
  32. # Existing files will not be clobbered unless "-c" is specified on the cmd line.
  33. if test -f README -a "$1" != "-c" ; then
  34.     echo "README: file exists - will not be overwritten"
  35. else
  36.     echo "x - README (file 1 of 11, 5523 chars)"
  37.     sed -e 's/^X//' << 'END_OF_FILE_README' > README
  38. X
  39. X             man - Locate and Display Manual Pages
  40. X                 === = ====== === ======= ====== =====
  41. X
  42. XThe "man" program is a replacement for the system "man" command.  It
  43. Xoffers the following features:
  44. X
  45. X    (1)  Ability to organize man directories to your preferences.
  46. X    (2)  Understands both normal UNIX and bizarre XENIX naming conventions.
  47. X    (3)  Supports packed and compressed files.
  48. X    (4)  Supports cross-index, for example to locate strcpy(3) in string(3).
  49. X    (5)  Ability to make "man" do what you want - 'cause you now have source.
  50. X
  51. XIn addition, a "catman" script is included to pre-format man pages en masse.
  52. XThe distributed configuration of this package is for SCO XENIX.  These notes
  53. Xdescribe how to configure it for your system.
  54. X
  55. XInstallation summary:
  56. X
  57. X    1.  Configure "Makefile" and "lookup.c" for your system directory routines.
  58. X    2.  Configure the definitions in "man.h".
  59. X    3.  Configure the tables in "man.c".
  60. X    4.  Run "make all".
  61. X    5.  Install "man", "man.man", and "catman".
  62. X
  63. XI would be interested in receiving any bugfixes, comments, or suggestions.
  64. XI will try to release official patches to USENET as appropriate.  This
  65. Xpackage is copyrighten with the intent to encourage "free" use and
  66. Xdistribution.  Notice is at the end of this file.
  67. X
  68. X
  69. XConfigure "Makefile" and "lookup.c" for your system directory routines.
  70. X========= ========== === ========== === ==== ====== ========= =========
  71. X
  72. X    This package requires your local directory search ("ndir") procedures.
  73. X    As distributed, the package is configured for SCO XENIX's directory
  74. X    library.  For any other sort of system, you will need to change the
  75. X    following:
  76. X
  77. X    Makefile -- change LIBS from "-lx" to "-lndir" or as appropriate.
  78. X    lookup.c -- change "<sys/ndir.h>" to "<ndir.h>" or as appropriate.
  79. X
  80. X
  81. XConfigure the definitions in "man.h".
  82. X========= === =========== == ========
  83. X
  84. X    The following items are defined in "man.h", and you might want
  85. X    to change them:
  86. X
  87. X     FORMAT_CMD    Command to format manual pages.
  88. X     COL_CMD    Command to filter formatted output.
  89. X     SQUEEZE_CMD    Command to squeeze multiple blank lines.
  90. X     PAGE_CMD    Command to page output.
  91. X     COMRESS_CMD    Command to compress file.
  92. X     INDEX_FILE    Path to cross-ref.
  93. X     DEFAULT_TERM    Default device for formatting.
  94. X
  95. X
  96. XConfigure the tables in "man.c".
  97. X========= === ====== == ========
  98. X
  99. X    You will almost certainly want to modify the "Base_dir_list[]", which
  100. X    specifies which directories contain man pages.  You might want to
  101. X    customize some of the other tables in this file.
  102. X
  103. X    Base_dir_list[]
  104. X
  105. X        This specifies which directories have manual pages in them, in
  106. X        the order they are to be searched.  It also specifies whether the
  107. X        directory follows UNIX naming conventions (e.g. "man1") or XENIX
  108. X        naming conventions (e.g. "man.C").  The comments in the source
  109. X        should provide some guidance.
  110. X
  111. X    Unix_section_list[]
  112. X    Xenix_section_list[]
  113. X
  114. X        These lists give the manual sections for UNIX-style man pages
  115. X        (e.g. "1", "2", etc.) and XENIX-style man pages (e.g. "C", "S",
  116. X        etc.)  Please note the section name does not need to correspond
  117. X        to the manpage file suffix.  For example, if you have a "man1/boot.1m"
  118. X        manpage, then you need to have "1" in your "Unix_section_list[]",
  119. X        but not necessarily "1m".  The subdirectories are searched in the
  120. X        order specified here.
  121. X
  122. X        When "man" tries to locate a manual page, it permutes all the
  123. X        directories of "Base_dir_list[]" with one of these section lists.
  124. X    The "xenixish" flag in the "Base_dir_list[]" entry selects whether
  125. X    to use "Unix_section_list[]" or "Xenix_section_list[]".
  126. X
  127. X    Compress_list[]
  128. X
  129. X    This list tells "man" that ".Z" files run through "compress", etc.
  130. X    
  131. X    No_col_list[]
  132. X
  133. X        This list tells "man" which terminal types don't need output run
  134. X        through "col".
  135. X
  136. X
  137. X    By the way ... you might want to edit the catman script so that its
  138. X    DIRLIST corresponds to the "Base_dir_list[]" directories you've defined
  139. X    in man.
  140. X
  141. X
  142. XRun "make all".
  143. X=== ===== =====
  144. X
  145. X    This will create the "man" executable.
  146. X
  147. X
  148. XInstall "man", "man.man", and "catman".
  149. X======= ====== ========== === =========
  150. X
  151. X    The "make install" option is configured to run with my "install"
  152. X    program.  Drop me a line if you want a copy.  Otherwise, do something
  153. X    like:
  154. X
  155. X    cp man /local/bin/man
  156. X    cp catman /local/bin/man
  157. X    cp man.man /usr/man/local/man1/man.1
  158. X
  159. X
  160. X------------------------------------------------------------------------------
  161. XCopyright 1988, Chip Rosenthal.  Permission is granted to use, distribute, or
  162. Xmodify the files in this package as long as you don't charge money for these
  163. Xfiles or packages which include these files beyond reasonable handling and
  164. Xdistribution costs, and if you distribute any portion or executable version
  165. Xof this package, you must make the full distributed package available at no
  166. Xadditional charge and provide notice of such.  The author retains all rights
  167. Xon derivative works.  This software is provided without warranty or guarantee
  168. Xof support.  The author is not responsible for any loss or damage arising
  169. Xfrom use or misuse of this software.
  170. X------------------------------------------------------------------------------
  171. X
  172. X                                                                Chip Rosenthal
  173. X                                                              chip@vector.uucp
  174. X                                                                     26 Dec 88
  175. X@(#) README 1.1 88/12/30 20:42:24
  176. X
  177. END_OF_FILE_README
  178.     size="`wc -c < README`"
  179.     if test 5523 -ne "$size" ; then
  180.     echo "README: extraction error - got $size chars"
  181.     fi
  182. fi
  183. if test -f man.h -a "$1" != "-c" ; then
  184.     echo "man.h: file exists - will not be overwritten"
  185. else
  186.     echo "x - man.h (file 2 of 11, 4098 chars)"
  187.     sed -e 's/^X//' << 'END_OF_FILE_man.h' > man.h
  188. X/*
  189. X * @(#) man.h 1.1 88/12/30 20:42:55
  190. X *
  191. X * Mon Dec 26 17:10:06 CST 1988 - C. Rosenthal (chip@vector.UUCP)
  192. X *    Original composition.
  193. X *
  194. X * Copyright 1988, Chip Rosenthal.
  195. X * Permission granted to use, modify, and distribute the files in this
  196. X * package as described in the accompanying "README" file.
  197. X */
  198. X
  199. X#define    BUFLEN        128
  200. X#define LBUFLEN        1024
  201. X#define TRUE        1
  202. X#define FALSE        0
  203. X#define Dprintf        if (!Debug) ; else fprintf
  204. X
  205. X/*
  206. X * FORMAT_CMD    Command to format manual pages.  "%s" replaced with term type.
  207. X * COL_CMD    Command to filter formatted output.
  208. X * SQUEEZE_CMD    Command to squeeze multiple blank lines.
  209. X * PAGE_CMD    Command to page output.  (Overridden by $PAGER).
  210. X * COMRESS_CMD    Command to compress file.  "%s" replaced with file name.
  211. X * INDEX_FILE    Path to cross-ref.  Undefine to suppress this feature.
  212. X * DEFAULT_TERM    Default device for formatting.  (Overriden by -T option).
  213. X */
  214. X#define FORMAT_CMD    "tbl | eqn | nroff -man -T%s"
  215. X#define COL_CMD        "col"
  216. X#define SQUEEZE_CMD    \
  217. X    "awk '{ if(length(\$0)==0){++n}else{n=-2} ; if(n<0){print} }'"
  218. X#define PAGE_CMD    "less"
  219. X#define COMPRESS_CMD    "compress %s"
  220. X#define INDEX_FILE    "/usr/man/index"
  221. X#define DEFAULT_TERM    "lp"
  222. X
  223. X#ifdef LINT
  224. X#   define SCCSID(STR)
  225. X#else
  226. X#   define SCCSID(STR) static char Sccsid[] = STR;
  227. X#endif
  228. X
  229. X/*
  230. X * Information on a manual page file.
  231. X *
  232. X *      .------------------------- basedir
  233. X *      |             
  234. X *      |              .---------- ( source ? "man" : "cat" )
  235. X *      |              |  .------- section
  236. X *      |              |  |
  237. X *      |              |  | .----- entry
  238. X *      |              |  | |  .-- suffix
  239. X *      |              |  | |  |.- zsuffix
  240. X *      |              |  | |  ||
  241. X *      --------------=---=-==-=--
  242. X *    /usr/man/u_man/man1/ls.1.Z
  243. X *      --------------=---=-==-=--
  244. X *                    |    |  |
  245. X *                    `----`--`--- implied
  246. X */
  247. Xstruct fileinfo {
  248. X    char *basedir;    /* base directory, e.g. "/usr/man/u_man"    */
  249. X    int source;        /* true if roff source, false if pre-formatted    */
  250. X    int xenixish;    /* true if "." before section in dir name    */
  251. X    char *section;    /* section name, e.g. "1"            */
  252. X    char *entry;    /* manpage name, e.g. "ls"            */
  253. X    char *suffix;    /* manpage suffix, e.g. "1"            */
  254. X    char *zsuffix;    /* file compression suffix, e.g. ".Z"        */
  255. X    long mtime;        /* time of modification, or 0 if not found    */
  256. X    char *catcmd;    /* cmd to (possibly uncompress and) cat file    */
  257. X};
  258. X
  259. X/*
  260. X * List of directories to search in the order to search.
  261. X */
  262. Xextern struct base_dir_entry {
  263. X    char *basedir;    /* base dir, contains the "{man,cat}*" dirs    */
  264. X    int xenixish;    /* TRUE for "man.C/ls.C", FALSE for "man1/ls.1"    */
  265. X} Base_dir_list[];
  266. X
  267. X/*
  268. X * List of sections for UNIX-style man pages in search order.
  269. X */
  270. Xextern char *Unix_section_list[];
  271. X
  272. X/*
  273. X * List of sections for XENIX-style man pages in search order.
  274. X */
  275. Xextern char *Xenix_section_list[];
  276. X
  277. X/*
  278. X * List of suffixes which indicate file compression, and how to "cat" them.
  279. X */
  280. Xextern struct zsuffix_entry {
  281. X    char *suffix;    /* suffix appended to the file            */
  282. X    char *catcmd;    /* cmd which dumps the possibly compressed file    */
  283. X} Compress_list[];
  284. X
  285. X/*
  286. X * List of terminals which aren't run through col.
  287. X */
  288. Xextern char *No_col_list[];
  289. X
  290. X/*
  291. X * Execution options - selected through command line arguments.
  292. X */
  293. Xextern int Do_update;        /* format and save manpage if out of date?    */
  294. Xextern int Do_format;        /* format even if not required?              */
  295. Xextern int Do_first_only;    /* show first manpage or all manpages found?  */
  296. Xextern int Do_squeeze;        /* squeeze out multiple blank lines?          */
  297. Xextern int Do_col;        /* run output through col(1)?              */
  298. Xextern int Do_names_only;    /* show pathnames rather display manpages?    */
  299. Xextern int Debug;        /* debug mode                      */
  300. Xextern char *Term;        /* terminal type for formatter output          */
  301. X
  302. X/*
  303. X * Procedures.
  304. X */
  305. Xchar *manpath();    /* Generate pathname to a manpage file.              */
  306. Xint do_index();        /* Search through the index file for a manpage entry. */
  307. Xint do_lookup();    /* Determine whether a manpage file exists.          */
  308. Xint do_manpage();    /* Process the manpage.                      */
  309. X
  310. END_OF_FILE_man.h
  311.     size="`wc -c < man.h`"
  312.     if test 4098 -ne "$size" ; then
  313.     echo "man.h: extraction error - got $size chars"
  314.     fi
  315. fi
  316. if test -f patchlevel.h -a "$1" != "-c" ; then
  317.     echo "patchlevel.h: file exists - will not be overwritten"
  318. else
  319.     echo "x - patchlevel.h (file 3 of 11, 71 chars)"
  320.     sed -e 's/^X//' << 'END_OF_FILE_patchlevel.h' > patchlevel.h
  321. X/*
  322. X * @(#) patchlevel.h 1.1 88/12/30 20:43:12
  323. X */
  324. X#define PATCHLEVEL 0
  325. END_OF_FILE_patchlevel.h
  326.     size="`wc -c < patchlevel.h`"
  327.     if test 71 -ne "$size" ; then
  328.     echo "patchlevel.h: extraction error - got $size chars"
  329.     fi
  330. fi
  331. if test -f man.c -a "$1" != "-c" ; then
  332.     echo "man.c: file exists - will not be overwritten"
  333. else
  334.     echo "x - man.c (file 4 of 11, 5994 chars)"
  335.     sed -e 's/^X//' << 'END_OF_FILE_man.c' > man.c
  336. X/*
  337. X * @(#) man.c 1.1 88/12/30 20:42:48
  338. X *
  339. X * Mon Dec 26 17:10:06 CST 1988 - C. Rosenthal (chip@vector.UUCP)
  340. X *    Original composition.
  341. X *
  342. X * Copyright 1988, Chip Rosenthal.
  343. X * Permission granted to use, modify, and distribute the files in this
  344. X * package as described in the accompanying "README" file.
  345. X */
  346. X
  347. X#include <stdio.h>
  348. X#include "man.h"
  349. X#include "patchlevel.h"
  350. X
  351. XSCCSID("@(#) man.c 1.1 88/12/30 20:42:48");
  352. Xstatic char Copyright[] = "@(#) Copyright 1988, Chip Rosenthal";
  353. X
  354. X#define USAGE "usage: %s [-abcfwU] [-T term] [section] command\n"
  355. X
  356. X/*
  357. X * List of directories to search in the order to search.
  358. X */
  359. Xstruct base_dir_entry Base_dir_list[] = {
  360. X/*
  361. X *    basedir           xenixish
  362. X */
  363. X    { "/usr/man/local",    FALSE    },    /* my local man pages    */
  364. X    { "/usr/man",    TRUE    },    /* XENIX man pages    */
  365. X/***{ "/usr/man",    FALSE    },    /* BSD man pages    */
  366. X/***{ "/usr/man/l_man",    FALSE    },    /* SYSV local        */
  367. X/***{ "/usr/man/u_man",    FALSE    },    /* SYSV user        */
  368. X/***{ "/usr/man/a_man",    FALSE    },    /* SYSV administrative    */
  369. X/***{ "/usr/man/p_man",    FALSE    },    /* SYSV programmers    */
  370. X    { NULL,        0    },
  371. X};
  372. X
  373. X/*
  374. X * List of sections for UNIX-style man pages in search order.
  375. X */
  376. Xchar *Unix_section_list[] = {
  377. X    "1", "2", "3", "4", "5", "6", "7", "8", "l", "n", "p", NULL
  378. X};
  379. X
  380. X/*
  381. X * List of sections for XENIX-style man pages in search order.
  382. X */
  383. Xchar *Xenix_section_list[] = {
  384. X    "C", "CP", "CT", "S", "M", "F", "HW", "DOS", "UCB", "LOCAL", NULL
  385. X};
  386. X
  387. X/*
  388. X * List of suffixes which indicate file compression, and how to "cat" them.
  389. X * A "%s" in the "catcmt" is replaced with the file name.
  390. X */
  391. Xstruct zsuffix_entry Compress_list[] = {
  392. X/*
  393. X *    suffix    catcmd
  394. X */
  395. X    { ".Z",    "zcat %s"    },    /* a "compressed" file    */
  396. X    { ".z",    "pcat %s"    },    /* a "packed" file    */
  397. X    { "",    "cat %s"    },    /* a normal file    */
  398. X    { NULL,    NULL        }
  399. X};
  400. X
  401. X/*
  402. X * List of terminals which aren't run through col.
  403. X */
  404. Xchar *No_col_list[] = {
  405. X    "300", "300s", "450", "37", "4000a", "382", "4014", "tek", "1620", "X", NULL
  406. X};
  407. X
  408. X/*
  409. X * Execution options - selected through command line arguments.
  410. X */
  411. Xint Do_update = FALSE;        /* format and save manpage if out of date?    */
  412. Xint Do_format = FALSE;        /* format even if not required?              */
  413. Xint Do_first_only = TRUE;    /* show first manpage or all manpages found?  */
  414. Xint Do_squeeze = TRUE;        /* squeeze out multiple blank lines?          */
  415. Xint Do_col = FALSE;        /* run output through col(1)?              */
  416. Xint Do_names_only = FALSE;    /* show pathnames rather display manpages?    */
  417. Xint Debug = FALSE;        /* debug mode                      */
  418. Xchar *Term = DEFAULT_TERM;    /* terminal type for formatter output          */
  419. X
  420. Xmain(argc,argv)
  421. Xint argc;
  422. Xchar *argv[];
  423. X{
  424. X    char *command, *section, *basedir, **sect_p;
  425. X    int found_flag, xenixish,  i, d;
  426. X    struct fileinfo cat_info, man_info;
  427. X    extern int optind;
  428. X    extern char *optarg;
  429. X
  430. X    found_flag = FALSE;
  431. X
  432. X    /*
  433. X     * Process the command line options.
  434. X     */
  435. X    while ( (i=getopt(argc,argv,"abcfwUT:D")) != EOF ) {
  436. X    switch ( i ) {
  437. X    case 'a':            /* display all entries */
  438. X        Do_first_only = FALSE;
  439. X        break;
  440. X    case 'b':            /* keep blank lines */
  441. X        Do_squeeze = FALSE;
  442. X        break;
  443. X    case 'c':            /* run through col */
  444. X        Do_col = TRUE;
  445. X        break;
  446. X    case 'f':            /* force format */
  447. X        Do_format = TRUE;
  448. X        break;
  449. X    case 'w':            /* which names? */
  450. X        Do_names_only = TRUE;
  451. X        Do_first_only = FALSE;
  452. X        break;
  453. X    case 'U':            /* perform update */
  454. X        Do_update = TRUE;
  455. X        Do_first_only = FALSE;
  456. X        Do_squeeze = FALSE;
  457. X        break;
  458. X    case 'T':            /* output terminal type */
  459. X        Term = optarg;
  460. X        break;
  461. X    case 'D':            /* debug output */
  462. X        Debug = TRUE;
  463. X        break;
  464. X    default:
  465. X        fprintf(stderr,USAGE,argv[0]);
  466. X        (void) exit(1);
  467. X    }
  468. X    }
  469. X
  470. X    /*
  471. X     * Get the entry name.
  472. X     */
  473. X    switch ( argc-optind ) {
  474. X    case 1:                /* man [options] command */
  475. X    command = argv[optind];
  476. X    section = NULL;
  477. X    break;
  478. X    case 2:                /* man [options] section command */
  479. X    command = argv[optind+1];
  480. X    Xenix_section_list[0] = Unix_section_list[0] = section = argv[optind];
  481. X    Xenix_section_list[1] = Unix_section_list[1] = NULL;
  482. X    break;
  483. X    default:
  484. X    fprintf(stderr,USAGE,argv[0]);
  485. X    (void) exit(1);
  486. X    }
  487. X
  488. X
  489. X    /*
  490. X     * Go through each base directory.
  491. X     */
  492. X    for ( d = 0 ; (basedir=Base_dir_list[d].basedir) != NULL ; ++d ) {
  493. X
  494. X    xenixish = Base_dir_list[d].xenixish;
  495. X    Dprintf(stderr,">do_index() - checking %s-style dir '%s'\n",
  496. X        ( xenixish ? "xenix" : "unix" ), basedir);
  497. X
  498. X    /*
  499. X     * Go through each possible manual section in this directory.
  500. X     */
  501. X    for (
  502. X        sect_p = ( xenixish ? Xenix_section_list : Unix_section_list ) ;
  503. X        *sect_p != NULL ;
  504. X        ++sect_p
  505. X    ) {
  506. X
  507. X        cat_info.basedir = basedir;
  508. X        cat_info.source = FALSE;
  509. X        cat_info.xenixish = xenixish;
  510. X        cat_info.section = *sect_p;
  511. X        cat_info.entry = command;
  512. X        (void) do_lookup(&cat_info);
  513. X
  514. X        man_info.basedir = basedir;
  515. X        man_info.source = TRUE;
  516. X        man_info.xenixish = xenixish;
  517. X        man_info.section = *sect_p;
  518. X        man_info.entry = command;
  519. X        (void) do_lookup(&man_info);
  520. X
  521. X        if ( cat_info.mtime != 0 || man_info.mtime != 0 ) {
  522. X        (void) do_manpage(&man_info,&cat_info);
  523. X        found_flag = TRUE;
  524. X        if ( Do_first_only )
  525. X            (void) exit(0);
  526. X        }
  527. X
  528. X    }
  529. X
  530. X    }
  531. X
  532. X    /*
  533. X     * See if this command appears in the index under a different name.
  534. X     */
  535. X#ifdef INDEX_FILE
  536. X    if ( !found_flag && !Do_update )
  537. X    found_flag = do_index(command,section);
  538. X#endif
  539. X
  540. X    if ( !found_flag ) {
  541. X    fprintf(stderr,
  542. X        ( section == NULL ? "%s: %s '%s'.\n" : "%s: %s '%s(%s)'.\n" ),
  543. X        argv[0], "No manual entry found for", command, section );
  544. X    (void) exit(1);
  545. X    }
  546. X
  547. X    (void) exit(0);
  548. X    /*NOTREACHED*/
  549. X}
  550. X
  551. X
  552. X/*
  553. X * manpath() - Generate full pathname to a manpage from a description.
  554. X *
  555. X * Returns:  Pointer to static data which will be overwritten next call.
  556. X */
  557. Xchar *manpath(f)
  558. Xstruct fileinfo *f;
  559. X{
  560. X    static char path[BUFLEN];
  561. X    sprintf(path,"%s/%s%s%s/%s.%s%s",
  562. X    f->basedir,
  563. X    ( f->source ? "man" : "cat" ), ( f->xenixish ? "." : "" ), f->section,
  564. X    f->entry, f->suffix, f->zsuffix
  565. X    );
  566. X    return path;
  567. X}
  568. X
  569. END_OF_FILE_man.c
  570.     size="`wc -c < man.c`"
  571.     if test 5994 -ne "$size" ; then
  572.     echo "man.c: extraction error - got $size chars"
  573.     fi
  574. fi
  575. if test -f lookup.c -a "$1" != "-c" ; then
  576.     echo "lookup.c: file exists - will not be overwritten"
  577. else
  578.     echo "x - lookup.c (file 5 of 11, 3504 chars)"
  579.     sed -e 's/^X//' << 'END_OF_FILE_lookup.c' > lookup.c
  580. X/*
  581. X * @(#) lookup.c 1.1 88/12/30 20:42:42
  582. X *
  583. X * Mon Dec 26 17:10:06 CST 1988 - C. Rosenthal (chip@vector.UUCP)
  584. X *    Original composition.
  585. X *
  586. X * Copyright 1988, Chip Rosenthal.
  587. X * Permission granted to use, modify, and distribute the files in this
  588. X * package as described in the accompanying "README" file.
  589. X */
  590. X
  591. X#include <stdio.h>
  592. X#include <sys/types.h>
  593. X#include <sys/stat.h>
  594. X#include <sys/ndir.h>
  595. X#include "man.h"
  596. X
  597. XSCCSID("@(#) lookup.c 1.1 88/12/30 20:42:42");
  598. X
  599. Xstatic char *Sstrdup();
  600. X
  601. X/*
  602. X * do_lookup() - Search for a manual page.
  603. X *
  604. X * Returns:  TRUE if a man page was found here.
  605. X *
  606. X * This procedure determines whether a manual page exists, and if so
  607. X * returns information on this man page.  A single "struct fileinfo" is
  608. X * used to pass information into and back from this procedure.  Prior to
  609. X * calling "do_lookup()", the following items must be defined:
  610. X *
  611. X *    basedir, source, xenixish, section, and entry
  612. X *
  613. X * Upon return, if a manual page was found, the following items will
  614. X * be filled in:
  615. X *
  616. X *    suffix, zsuffix, mtime, catcmd
  617. X *
  618. X * If a manual page was not found, then "mtime" will be zero.
  619. X */
  620. Xint do_lookup(f)
  621. Xstruct fileinfo *f;    /* Structure to store results in.        */
  622. X{
  623. X    int i;
  624. X    char *path, *c;
  625. X    struct stat sbuf;
  626. X    DIR *dirp;
  627. X    struct direct *dinfo;
  628. X    static char buf[BUFLEN];
  629. X    extern char *strchr(), *strcat(), *strcpy();
  630. X
  631. X    /*
  632. X     * Initialize the items this procedure fills in.
  633. X     */
  634. X    f->suffix = "";
  635. X    f->zsuffix = "";
  636. X    f->mtime = 0;
  637. X    f->catcmd = "";
  638. X
  639. X    /*
  640. X     * Open the directory where this manpage would be.
  641. X     */
  642. X    (void) sprintf(buf,"%s/%s%s%s",
  643. X    f->basedir,
  644. X    ( f->source ? "man" : "cat" ), ( f->xenixish ? "." : "" ), f->section
  645. X    );
  646. X    if ( (dirp=opendir(buf)) == (DIR *) NULL )
  647. X    return FALSE;
  648. X
  649. X    /*
  650. X     * Create a file pattern to search the directory against.
  651. X     */
  652. X    (void) strcat(strcpy(buf,f->entry),".");
  653. X    i = strlen(buf);
  654. X
  655. X    /*
  656. X     * Go through each entry in the directory looking for the file pattern.
  657. X     */
  658. X    do {
  659. X    if ( (dinfo=readdir(dirp)) == (struct direct *) NULL ) {
  660. X        (void) closedir(dirp);
  661. X        return FALSE;
  662. X    }
  663. X    } while ( strncmp(buf,dinfo->d_name,i) != 0 );
  664. X    (void) closedir(dirp);
  665. X
  666. X    /*
  667. X     * Pull off the manpage suffix and the compression zsuffix.  We will
  668. X     * be malloc'ing a small amount of space here which won't be returned
  669. X     * until exiting.  But it's small enough to not worry about.
  670. X     */
  671. X    f->suffix = Sstrdup(dinfo->d_name+i);
  672. X    if ( (c=strchr(f->suffix,'.')) != NULL ) {
  673. X    f->zsuffix = Sstrdup(c);
  674. X    *c = '\0';
  675. X    }
  676. X
  677. X    /*
  678. X     * We now have full pathname information on the manpage.
  679. X     * Stat it so we can get the modification time.
  680. X     */
  681. X    path = manpath(f);
  682. X    Dprintf(stderr,">do_lookup() - found file '%s'\n",path);
  683. X    if ( stat(path,&sbuf) != 0 ) {
  684. X    perror(path);
  685. X    return FALSE;
  686. X    }
  687. X
  688. X    /*
  689. X     * Verify that this is a valid zsuffix.
  690. X     */
  691. X    for ( i = 0 ; Compress_list[i].suffix != NULL ; ++i ) {
  692. X    if ( strcmp(f->zsuffix,Compress_list[i].suffix) == 0 )
  693. X        break;
  694. X    }
  695. X    if ( Compress_list[i].suffix == NULL ) {
  696. X    fprintf(stderr,"%s: unknown suffix '%s' - file ignored\n",
  697. X        path, f->zsuffix);
  698. X    return FALSE;
  699. X    }
  700. X    f->catcmd = Compress_list[i].catcmd;
  701. X
  702. X    f->mtime = sbuf.st_mtime;
  703. X    return TRUE;
  704. X}
  705. X
  706. X
  707. Xstatic char *Sstrdup(s)
  708. Xchar *s;
  709. X{
  710. X    char *p;
  711. X    extern char *malloc(), *strcpy();
  712. X    if ( (p=malloc((unsigned)strlen(s)+1)) == NULL ) {
  713. X    fputs("malloc: out of space\n",stderr);
  714. X    exit(2);
  715. X    }
  716. X    return strcpy(p,s);
  717. X}
  718. END_OF_FILE_lookup.c
  719.     size="`wc -c < lookup.c`"
  720.     if test 3504 -ne "$size" ; then
  721.     echo "lookup.c: extraction error - got $size chars"
  722.     fi
  723. fi
  724. if test -f index.c -a "$1" != "-c" ; then
  725.     echo "index.c: file exists - will not be overwritten"
  726. else
  727.     echo "x - index.c (file 6 of 11, 3868 chars)"
  728.     sed -e 's/^X//' << 'END_OF_FILE_index.c' > index.c
  729. X/*
  730. X * @(#) index.c 1.1 88/12/30 20:42:36
  731. X *
  732. X * Mon Dec 26 17:10:06 CST 1988 - C. Rosenthal (chip@vector.UUCP)
  733. X *    Original composition.
  734. X *
  735. X * Copyright 1988, Chip Rosenthal.
  736. X * Permission granted to use, modify, and distribute the files in this
  737. X * package as described in the accompanying "README" file.
  738. X */
  739. X
  740. X#include <stdio.h>
  741. X#include <ctype.h>
  742. X#include "man.h"
  743. X
  744. XSCCSID("@(#) index.c 1.1 88/12/30 20:42:36");
  745. X
  746. X#ifdef INDEX_FILE /*{*/
  747. X
  748. X/*
  749. X * do_index() - Go through the index file for a reference for this command.
  750. X *
  751. X * Returns:  TRUE if one or more man pages were found here.
  752. X *
  753. X * The index file is useful for indicating when the manpage for the command
  754. X * is not the name of the manpage.  For example, the manpage for "strcpy"
  755. X * is "string".  The format of the index file is:
  756. X *
  757. X *    <command>    <manpage>    <section>
  758. X *
  759. X * Comments beginning with "#" are stripped.  All manpages found which meet
  760. X * the criteria passed to this procedure are passed to "do_manpage()" for
  761. X * processing.
  762. X */
  763. Xint do_index(command,section)
  764. Xchar *command;    /* name of the command to look for    */
  765. Xchar *section;    /* section to look in, or NULL for any    */
  766. X{
  767. X    FILE *fp;
  768. X    char *field1, *field2, *field3, *basedir, *c;
  769. X    struct fileinfo cat_info, man_info;
  770. X    int found_flag, xenixish, lineno, d;
  771. X    static char buf[BUFLEN];
  772. X    extern char *strchr();
  773. X
  774. X    Dprintf(stderr,">do_index() - consulting '%s' index\n",INDEX_FILE);
  775. X
  776. X    /*
  777. X     * Open the index file.
  778. X     */
  779. X    if ( (fp=fopen(INDEX_FILE,"r")) == (FILE *) NULL ) {
  780. X    perror(INDEX_FILE);
  781. X    return FALSE;
  782. X    }
  783. X
  784. X    /*
  785. X     * Go through each line of the index file.
  786. X     */
  787. X    found_flag = FALSE;
  788. X    for ( lineno = 1 ; fgets(buf,sizeof(buf),fp) != NULL ; ++lineno ) {
  789. X
  790. X    /*
  791. X     * Strip comments and trailing space.  Ignore empty lines.
  792. X     */
  793. X    if ( (c=strchr(buf,'#')) != NULL )
  794. X        *c = '\0';
  795. X    for ( c = buf+strlen(buf)-1 ; isspace(*c) && c >= buf ; --c ) ;
  796. X    *(c+1) = '\0';
  797. X    if ( *buf == '\0' )
  798. X        continue;
  799. X
  800. X    /*
  801. X     * Field 1 is the command name.
  802. X     */
  803. X    for ( field1 = buf ; isspace(*field1) ; ++field1 ) ;
  804. X    for ( c = field1 ; *c != '\0' && !isspace(*c) ; ++c ) ;
  805. X    if ( *field1 == '\0' || *c == '\0' ) {
  806. X        fprintf(stderr, "%s(%d): bad format\n", INDEX_FILE, lineno);
  807. X        continue;
  808. X    }
  809. X    *c = '\0';
  810. X    if ( strcmp(field1,command) != 0 )
  811. X        continue;
  812. X
  813. X    /*
  814. X     * Field 2 is the entry name.
  815. X     */
  816. X    for ( field2 = c+1 ; isspace(*field2) ; ++field2 ) ;
  817. X    for ( c = field2 ; *c != '\0' && !isspace(*c) ; ++c ) ;
  818. X    if ( *field2 == '\0' || *c == '\0' ) {
  819. X        fprintf(stderr, "%s(%d): bad format\n", INDEX_FILE, lineno);
  820. X        continue;
  821. X    }
  822. X    *c = '\0';
  823. X
  824. X    /*
  825. X     * Field 3 is the entry section.
  826. X     */
  827. X    for ( field3 = c+1 ; isspace(*field3) ; ++field3 ) ;
  828. X    for ( c = field3 ; *c != '\0' && !isspace(*c) ; ++c ) ;
  829. X    if ( *field3 == '\0' || *c != '\0' ) {
  830. X        fprintf(stderr, "%s(%d): bad format\n", INDEX_FILE, lineno);
  831. X        continue;
  832. X    }
  833. X    if ( section != NULL && strcmp(field3,section) != 0 )
  834. X        continue;
  835. X
  836. X    /*
  837. X     * Go through each base directory.
  838. X     */
  839. X    for ( d = 0 ; (basedir=Base_dir_list[d].basedir) != NULL ; ++d ) {
  840. X
  841. X        xenixish = Base_dir_list[d].xenixish;
  842. X        Dprintf(stderr,">do_index() - checking %s-style dir '%s'\n",
  843. X        ( xenixish ? "xenix" : "unix" ), basedir);
  844. X
  845. X        man_info.basedir = basedir;
  846. X        man_info.source = TRUE;
  847. X        man_info.xenixish = xenixish;
  848. X        man_info.section = field3;
  849. X        man_info.entry = field2;
  850. X        (void) do_lookup(&man_info);
  851. X
  852. X        cat_info.basedir = basedir;
  853. X        cat_info.source = FALSE;
  854. X        cat_info.xenixish = xenixish;
  855. X        cat_info.section = field3;
  856. X        cat_info.entry = field2;
  857. X        (void) do_lookup(&cat_info);
  858. X
  859. X        if ( man_info.mtime != 0 || cat_info.mtime == 0 ) {
  860. X        found_flag = TRUE;
  861. X        (void) do_manpage(&man_info,&cat_info);
  862. X        if ( Do_first_only ) {
  863. X            (void) fclose(fp);
  864. X            return TRUE;
  865. X        }
  866. X        }
  867. X
  868. X    }
  869. X
  870. X    }
  871. X
  872. X    (void) fclose(fp);
  873. X    return found_flag;
  874. X}
  875. X
  876. X#endif /*}INDEX_FILE*/
  877. X
  878. END_OF_FILE_index.c
  879.     size="`wc -c < index.c`"
  880.     if test 3868 -ne "$size" ; then
  881.     echo "index.c: extraction error - got $size chars"
  882.     fi
  883. fi
  884. if test -f manpage.c -a "$1" != "-c" ; then
  885.     echo "manpage.c: file exists - will not be overwritten"
  886. else
  887.     echo "x - manpage.c (file 7 of 11, 4938 chars)"
  888.     sed -e 's/^X//' << 'END_OF_FILE_manpage.c' > manpage.c
  889. X/*
  890. X * @(#) manpage.c 1.1 88/12/30 20:43:05
  891. X *
  892. X * Mon Dec 26 17:10:06 CST 1988 - C. Rosenthal (chip@vector.UUCP)
  893. X *    Original composition.
  894. X *
  895. X * Copyright 1988, Chip Rosenthal.
  896. X * Permission granted to use, modify, and distribute the files in this
  897. X * package as described in the accompanying "README" file.
  898. X */
  899. X
  900. X#include <stdio.h>
  901. X#include <sys/signal.h>
  902. X#include "man.h"
  903. X
  904. XSCCSID("@(#) manpage.c 1.1 88/12/30 20:43:05");
  905. X
  906. X/* 
  907. X * do_manpage() - Process a manual page.
  908. X *
  909. X * Returns:  0 if processing was successful.
  910. X *
  911. X * This procedure does whatever processing is required:  either display
  912. X * a manpage, print the pathname to the file (Do_names_only), or update
  913. X * the formatted version (Do_update).  A command pipeline is build up
  914. X * depending upon the global configuration settings, and then a shell
  915. X * is forked to process it.
  916. X */
  917. Xint do_manpage(man_info,cat_info)
  918. Xstruct fileinfo *man_info, *cat_info;
  919. X{
  920. X    int pid, status, i;
  921. X    char *path, *savepath, *c;
  922. X    struct fileinfo *finfo;
  923. X    int (*saveintr)();
  924. X    static char cmdbuf[LBUFLEN], buf[BUFLEN];
  925. X    extern char *getenv(), *strcat(), *strcpy(), *memcpy();
  926. X
  927. X    /*
  928. X     * The command to process the manpage will be built up in "cmdbuf".
  929. X     */
  930. X    *cmdbuf = '\0';
  931. X
  932. X    /*
  933. X     * Select the manpage to use.  The more recent file will be used
  934. X     * unless we are forcing a reformat.
  935. X     */
  936. X    finfo = (
  937. X    Do_format || man_info->mtime > cat_info->mtime ? man_info : cat_info
  938. X    );
  939. X
  940. X    /*
  941. X     * If we are doing updates and there is nothing to update then return.
  942. X     */
  943. X    if ( Do_update && finfo != man_info )
  944. X    return 0;
  945. X
  946. X    /*
  947. X     * If there isn't a manpage here then return.  This could happen, for
  948. X     * example, if "Do_format" was specified and there was a formatted man
  949. X     * page but not a source man page.
  950. X     */
  951. X    if ( finfo->mtime == 0 )
  952. X    return 0;
  953. X
  954. X    /*
  955. X     * Generate the path to the selected manpage.
  956. X     */
  957. X    path = manpath(finfo);
  958. X    Dprintf(stderr,">do_manpage() - processing '%s'\n",path);
  959. X
  960. X    /*
  961. X     * If we are only showing pathnames then show the selected file and return.
  962. X     */
  963. X    if ( Do_names_only ) {
  964. X    puts(path);
  965. X    return 0;
  966. X    }
  967. X
  968. X    /*
  969. X     * Generate the command to uncompress/output the file.
  970. X     */
  971. X    (void) sprintf(buf,finfo->catcmd,path);
  972. X    (void) strcat(cmdbuf,buf);
  973. X
  974. X    /*
  975. X     * Generate the command to format the file.
  976. X     */
  977. X    if ( finfo->source ) {
  978. X    fprintf(stderr,"Formatting %s(%s) . . .\n",finfo->entry,finfo->section);
  979. X    (void) sprintf(buf, FORMAT_CMD, Term);
  980. X    (void) strcat(cmdbuf,"|");
  981. X    (void) strcat(cmdbuf,buf);
  982. X    for ( Do_col = TRUE, i = 0 ; No_col_list[i] != NULL ; ++i ) {
  983. X        if ( strcmp(No_col_list[i],Term) == 0 ) {
  984. X        Do_col = FALSE;
  985. X        break;
  986. X        }
  987. X    }
  988. X    }
  989. X
  990. X    /*
  991. X     * Generate the command to filter the file.
  992. X     */
  993. X    if ( Do_col ) {
  994. X    (void) strcat(cmdbuf,"|");
  995. X    (void) strcat(cmdbuf,COL_CMD);
  996. X    }
  997. X
  998. X    /*
  999. X     * Generate the command to squeeze multiple spaces.
  1000. X     */
  1001. X    if ( Do_squeeze ) {
  1002. X    (void) strcat(cmdbuf,"|");
  1003. X    (void) strcat(cmdbuf,SQUEEZE_CMD);
  1004. X    }
  1005. X
  1006. X    /*
  1007. X     * Generate the command to page the output.
  1008. X     */
  1009. X    if ( isatty(fileno(stdout)) && !Do_update ) {
  1010. X    c = getenv("PAGER");
  1011. X    (void) strcat(cmdbuf,"|");
  1012. X    (void) strcat(cmdbuf, ( c != NULL ? c : PAGE_CMD) );
  1013. X    }
  1014. X
  1015. X    /*
  1016. X     * Generate the command to save the output to a file.
  1017. X     */
  1018. X    if ( Do_update ) {
  1019. X
  1020. X    /*
  1021. X     * Zap old file.
  1022. X     */
  1023. X    if ( cat_info->mtime > 0 && unlink(savepath=manpath(cat_info)) != 0 ) {
  1024. X        perror(savepath);
  1025. X        return -1;
  1026. X    }
  1027. X
  1028. X    /*
  1029. X     * Figure out what to call the new file.
  1030. X     */
  1031. X    (void) memcpy(cat_info,man_info,sizeof(struct fileinfo));
  1032. X    cat_info->source = FALSE;
  1033. X    cat_info->zsuffix = "";
  1034. X    savepath = manpath(cat_info);
  1035. X
  1036. X    /*
  1037. X     * Tack on command to redirect output to the save file.
  1038. X     */
  1039. X    (void) strcat(cmdbuf,">");
  1040. X    (void) strcat(cmdbuf,savepath);
  1041. X
  1042. X    /*
  1043. X     * Tack on command to compress the save file.
  1044. X     */
  1045. X    (void) sprintf(buf,COMPRESS_CMD,savepath);
  1046. X    (void) strcat(cmdbuf,";");
  1047. X    (void) strcat(cmdbuf,buf);
  1048. X
  1049. X    }
  1050. X
  1051. X
  1052. X    /*
  1053. X     * Go execute the command.
  1054. X     */
  1055. X    Dprintf(stderr,">do_manpage() - executing '%s'\n",cmdbuf);
  1056. X    saveintr = signal(SIGINT,SIG_IGN);
  1057. X    switch ( pid = fork() ) {
  1058. X    case -1:            /* fork error */
  1059. X    perror("fork");
  1060. X    (void) exit(1);
  1061. X    case 0:            /* child */
  1062. X    (void) signal(SIGINT,saveintr);
  1063. X    (void) execl("/bin/sh", "sh", "-c", cmdbuf, NULL);
  1064. X    fprintf(stderr,"exec /bin/sh failed\n");
  1065. X    (void) exit(1);
  1066. X    default:            /* parent */
  1067. X    break;
  1068. X    }
  1069. X
  1070. X    /*
  1071. X     * Wait for command to complete and check returned status.
  1072. X     */
  1073. X    while ( wait(&status) != pid ) ;
  1074. X    Dprintf(stderr,">do_manpage() - exit status 0x%04X\n",status);
  1075. X    (void) signal(SIGINT,saveintr);
  1076. X    if ( status == 0177 )
  1077. X    fprintf(stderr,"command stopped\n");
  1078. X    else if ( (status&0377) != 0 )
  1079. X    fprintf(stderr,"command interrupted - signal %d\n", (status&0377) );
  1080. X    else if ( (status>>8) != 0 )
  1081. X    fprintf(stderr,"command failed - exit status %d\n", (status>>8));
  1082. X
  1083. X    return status;
  1084. X}
  1085. X
  1086. END_OF_FILE_manpage.c
  1087.     size="`wc -c < manpage.c`"
  1088.     if test 4938 -ne "$size" ; then
  1089.     echo "manpage.c: extraction error - got $size chars"
  1090.     fi
  1091. fi
  1092. if test -f man.man -a "$1" != "-c" ; then
  1093.     echo "man.man: file exists - will not be overwritten"
  1094. else
  1095.     echo "x - man.man (file 8 of 11, 5651 chars)"
  1096.     sed -e 's/^X//' << 'END_OF_FILE_man.man' > man.man
  1097. X''' @(#) man.man 1.1 88/12/30 20:43:00
  1098. X'''
  1099. X''' Mon Dec 26 17:10:06 CST 1988 - C. Rosenthal (chip@vector.UUCP)
  1100. X'''    Original composition.
  1101. X'''
  1102. X''' Copyright 1988, Chip Rosenthal.
  1103. X''' Permission granted to use, modify, and distribute the files in this
  1104. X''' package as described in the accompanying "README" file.
  1105. X'''
  1106. X.TH MAN 1L
  1107. X.SH NAME
  1108. Xman - Display manual entries.
  1109. X.SH SYNTAX
  1110. X.B man
  1111. X[
  1112. X.B \-abcfwU
  1113. X] [
  1114. X.B \-T
  1115. Xterm ] [ section ] command
  1116. X.sp
  1117. X.B catman
  1118. X[ options ]
  1119. X.SH DESCRIPTION
  1120. X.I Man
  1121. Xlocates and displays the manual entry for
  1122. X.IR command .
  1123. XIf a
  1124. X.I section
  1125. Xis specified, the search is restricted to that
  1126. Xsection of the manual.
  1127. X.PP
  1128. XScreen output will be displayed through a pager.  The "PAGER" environment
  1129. Xvalue will override the default pager selection.  Manual pages may be
  1130. Xstored as either
  1131. X.I nroff
  1132. Xsources or pre-formatted files.
  1133. X.PP
  1134. XOptions are:
  1135. X.IP "\fB\-a\fR"
  1136. XDisplay all entries.  If a command has several entries,
  1137. Xnormally only the first entry found is displayed.  When
  1138. X.B \-a
  1139. Xis specified, all entries are displayed.
  1140. X.IP "\fB\-b\fR"
  1141. XKeep blank lines.  Normally multiple blank lines are squeezed out of the
  1142. Xmanual page when displayed to the screen.  The
  1143. X.B \-b
  1144. Xoption requests that these blank lines be retained.  This option is implied
  1145. Xwhen the output is redirected.
  1146. X.IP "\fB\-c\fR"
  1147. XFilter output through
  1148. X.IR col(1) .
  1149. XNormally,
  1150. X.I man
  1151. Xfilters output through
  1152. X.I col(1)
  1153. Xonly when formatting manual pages, unless the target terminal (c.f. the
  1154. X.B \-T
  1155. Xoption) is contained within an internal list of devices which don't require
  1156. Xit.  This option forces the output to be filtered by
  1157. X.IR col(1) ,
  1158. Xeven if you are reviewing a pre-formatted manual page or formatting a
  1159. Xmanual page for a terminal type in this list.
  1160. X.IP "\fB\-f\fR"
  1161. XForce formatting.  When this option is specified,
  1162. X.I man
  1163. Xignores the presence of any pre-formatted manual pages.
  1164. X.IP "\fB\-w\fR"
  1165. XWhich files?  When this option is specified, the pathnames of the manual
  1166. Xpage files will be displayed rather than the manual pages themselves.
  1167. XThis option implies the
  1168. X.B \-a
  1169. Xoption.  The
  1170. X.B \-f
  1171. Xoption may be specified to display only unformatted source files pathnames.
  1172. X.IP "\fB\-T\fR term"
  1173. XTerminal type.  Specifies the target device for
  1174. X.I nroff(1)
  1175. Xformatting.  The name of the default device is built into the
  1176. X.I man
  1177. Xprogram, usually "lp".  This information is used when formatting manual
  1178. Xpage sources -- it has no effect when reviewing formatted manual pages.
  1179. XAs initially configured,
  1180. X.I col(1)
  1181. Xwill not be invoked when formatting for the following devices:  300, 300s,
  1182. X450, 37, 4000a, 382, 4014, tek, 1620, and X.
  1183. X.IP "\fB\-U\fR"
  1184. XUpdate mode.  In this mode manual pages are not displayed, but rather the
  1185. Xformatted versions are updated if required.
  1186. X.I Man
  1187. Xwill compare a manual page source file to its formatted version, and
  1188. Xif the formatted version is missing or out of date one will be created.
  1189. XThe formatted output will be run through the
  1190. X.I col(1)
  1191. Xand
  1192. X.I compress(1L)
  1193. Xcommands.
  1194. XIf
  1195. X.B \-f
  1196. Xhas been specified, the update will always occur.  If
  1197. X.B \-w
  1198. Xhas been specified, then the update will be suppressed, and the pathname
  1199. Xof the source file will be displayed instead.
  1200. XThis option implies
  1201. Xthe
  1202. X.B \-a
  1203. Xand
  1204. X.B \-s
  1205. Xoptions, and is intended for use by the
  1206. X.I catman(1L)
  1207. Xcommand.
  1208. X.PP
  1209. X.I Man
  1210. Xsupports file packing (".z" file suffix) and compression (".Z" file suffix)
  1211. Xto save space.  When a manual page requires formatting, it is run through
  1212. Xthe
  1213. X.I tbl
  1214. Xand
  1215. X.I eqn
  1216. Xpre-processors as well as the
  1217. X.I nroff
  1218. Xformatter.
  1219. X.PP
  1220. XThere are several conventions for organizing manual pages, and
  1221. X.I man
  1222. Xmay be configured locally as appropriate.  For example, the
  1223. X.I ls(1)
  1224. Xmanual page could appear in any of the following ways:
  1225. X.RS
  1226. X.nf
  1227. X.sp
  1228. X.ta 10 35
  1229. X.I "system    source    formatted"
  1230. XSystem V    /usr/man/u_man/man1/ls.1    /usr/man/u_man/cat1/ls.1
  1231. XBSD    /usr/man/man1/ls.1    /usr/man/cat1/ls.1
  1232. XXENIX    /usr/man/man.C/ls.C    /usr/man/cat.C/ls.C
  1233. X.fi
  1234. X.RE
  1235. X.PP
  1236. XWhen a manual page isn't found by scanning the manual directories, a
  1237. Xcross-reference index may be consulted.  The format of the index is:
  1238. X.RS
  1239. X.sp
  1240. X<command> <manpage> <section>
  1241. X.RE
  1242. X.PP
  1243. XFor example, the following entry would correctly locate the manual page for
  1244. X.IR strcpy :
  1245. X.RS
  1246. X.sp
  1247. Xstrcpy string 3
  1248. X.sp
  1249. X.RE
  1250. XText beginning with a "#" pound sign is ignored as a comment.
  1251. X.PP
  1252. XThe
  1253. X.I catman
  1254. Xcommand scans manual directories looking for manual pages to format.
  1255. XIt also notifies you when the manual page source is missing for a formatted
  1256. Xmanual page.
  1257. X.I Catman
  1258. Xuses the
  1259. X.B \-U
  1260. Xoption of
  1261. X.I man
  1262. Xto perform the update.  Any command line options specified are passed along to
  1263. X.IR man .
  1264. XFor example, use "catman \-w" to display the manual pages which require
  1265. Xupdate without actually performing the update.  The list of directories
  1266. Xscanned is contained within the
  1267. X.I catman
  1268. Xscript.
  1269. X.I
  1270. X.SH FILES
  1271. X.ta 20 30
  1272. X.nf
  1273. X/usr/man/...    manual directories
  1274. X  .../man\fIsection\fR/*    unformatted source (UNIX naming)
  1275. X  .../man.\fIsection\fR/*    unformatted source (XENIX naming)
  1276. X  .../cat\fIsection\fR/*    formatted text (UNIX naming)
  1277. X  .../cat.\fIsection\fR/*    formatted text (XENIX naming)
  1278. X/usr/man/index    cross-reference index
  1279. Xtbl,eqn,nroff    to format manual pages
  1280. Xcol    to filter output
  1281. Xzcat,pcat    to examine compressed entries
  1282. Xcompress    to compress updated entries
  1283. Xless,$PAGER    output pager
  1284. X.fi
  1285. X.SH SEE ALSO
  1286. Xnroff(1), col(1), man(7)
  1287. X.SH BUGS
  1288. XProblems will occur if the command name plus the man page suffix exceed
  1289. Xthe allowable file name length.
  1290. X.PP
  1291. X.I Man
  1292. Xdoes not particularly care about filename suffixes -- you can call it
  1293. X"pathalias.1" or "pathalias.1L".  However, if you call it both,
  1294. X.I man
  1295. Xwill ignore all but one of them.
  1296. X.PP
  1297. XAlternate description:  R'sTFM.
  1298. X.SH AUTHOR
  1299. XChip Rosenthal (chip@vector.uucp)
  1300. END_OF_FILE_man.man
  1301.     size="`wc -c < man.man`"
  1302.     if test 5651 -ne "$size" ; then
  1303.     echo "man.man: extraction error - got $size chars"
  1304.     fi
  1305. fi
  1306. if test -f catman -a "$1" != "-c" ; then
  1307.     echo "catman: file exists - will not be overwritten"
  1308. else
  1309.     echo "x - catman (file 9 of 11, 852 chars)"
  1310.     sed -e 's/^X//' << 'END_OF_FILE_catman' > catman
  1311. X: '@(#) catman 1.1 88/12/30 20:42:29'
  1312. X#
  1313. X# catman - search for and format manual pages
  1314. X#
  1315. X# Mon Dec 26 17:10:06 CST 1988 - C. Rosenthal (chip@vector.UUCP)
  1316. X#    Original composition.
  1317. X
  1318. X
  1319. X# list of directories in which to look for man pages
  1320. XDIRLIST="/usr/man/local"
  1321. X
  1322. Xecho "$0: checking for man pages which need to be formatted . . ." 1>&2
  1323. Xfor dir in $DIRLIST ; do
  1324. X    cd $dir
  1325. X    for d in man* ; do
  1326. X    ls $d | \
  1327. X        sed -e "s!\(.*\)\.\(.*\)\.*[zZ]*!man -U $* \2 \1!" | \
  1328. X        sh -$-
  1329. X    done
  1330. Xdone
  1331. X
  1332. Xecho "$0: checking for man pages with missing source . . ." 1>&2
  1333. Xfor dir in $DIRLIST ; do
  1334. X    cd $dir
  1335. X    for d in cat* ; do
  1336. X    m=`echo "$d" | sed -e 's/^cat/man/'`
  1337. X    ls $d |                                \
  1338. X        sed                                \
  1339. X        -e 's!\.*[zZ]$!!'                    \
  1340. X        -e "s!.*!$dir/$m/&!"                    \
  1341. X        -e 's!.*!test \! -f & \&\& echo "&: file not found"!' |    \
  1342. X        sh -$-
  1343. X    done
  1344. Xdone
  1345. X
  1346. Xecho "$0: done"
  1347. Xexit 0
  1348. END_OF_FILE_catman
  1349.     size="`wc -c < catman`"
  1350.     if test 852 -ne "$size" ; then
  1351.     echo "catman: extraction error - got $size chars"
  1352.     fi
  1353. fi
  1354. if test -f Install -a "$1" != "-c" ; then
  1355.     echo "Install: file exists - will not be overwritten"
  1356. else
  1357.     echo "x - Install (file 10 of 11, 84 chars)"
  1358.     sed -e 's/^X//' << 'END_OF_FILE_Install' > Install
  1359. X# @(#) Install 1.1 88/12/30 20:42:15
  1360. X$B/man        man
  1361. X$B/catman    catman
  1362. X$M1/man.1    man.man
  1363. END_OF_FILE_Install
  1364.     size="`wc -c < Install`"
  1365.     if test 84 -ne "$size" ; then
  1366.     echo "Install: extraction error - got $size chars"
  1367.     fi
  1368. fi
  1369. if test -f Makefile -a "$1" != "-c" ; then
  1370.     echo "Makefile: file exists - will not be overwritten"
  1371. else
  1372.     echo "x - Makefile (file 11 of 11, 1539 chars)"
  1373.     sed -e 's/^X//' << 'END_OF_FILE_Makefile' > Makefile
  1374. X
  1375. X# @(#) Makefile 1.1 88/12/30 20:42:20
  1376. X# Makefile for "man" (generated by makemake version 1.00.02)
  1377. X# Created by bin@vector on Fri Dec 30 20:40:10 CST 1988
  1378. X
  1379. XSHELL = /bin/sh
  1380. XCC = cc
  1381. XDEFS = 
  1382. XLIBS = -lx
  1383. XDEBUG = 
  1384. XCOPTS = -O
  1385. XLOPTS = 
  1386. XLINTFLAGS = -DLINT
  1387. XSHAR1 = README man.h patchlevel.h
  1388. XSHAR2 = man.man catman Install Makefile
  1389. X
  1390. XCMD = man
  1391. X
  1392. XSRCS = man.c lookup.c index.c manpage.c
  1393. X
  1394. XOBJS = man.o lookup.o index.o manpage.o
  1395. X
  1396. X# Any edits below this line will be lost if "makemake" is rerun!
  1397. X
  1398. XCFLAGS = $(COPTS) $(DEFS) $(DEBUG)
  1399. XLFLAGS = $(LOPTS) $(DEBUG)
  1400. X
  1401. Xall:        $(CMD)
  1402. Xinstall:    all        ; inst Install
  1403. Xclean:                ; rm -f $(CMD) $(OBJS) a.out core $(CMD).lint
  1404. Xclobber:    clean        ; inst -u Install
  1405. Xlint:        $(CMD).lint
  1406. X
  1407. X$(CMD):        $(OBJS)
  1408. X        $(CC) $(LFLAGS) -o $@ $(OBJS) $(LIBS)
  1409. X
  1410. X$(CMD).lint:    $(CMD)
  1411. X        lint $(LINTFLAGS) $(DEFS) $(SRCS) $(LIBS) > $@
  1412. X
  1413. Xman.o: /usr/include/stdio.h man.c man.h patchlevel.h
  1414. Xlookup.o: /usr/include/stdio.h /usr/include/sys/ndir.h \
  1415. X        /usr/include/sys/stat.h /usr/include/sys/types.h lookup.c \
  1416. X        man.h
  1417. Xindex.o: /usr/include/ctype.h /usr/include/stdio.h index.c man.h
  1418. Xmanpage.o: /usr/include/stdio.h /usr/include/sys/signal.h man.h manpage.c
  1419. X
  1420. Xshar:        ;
  1421. X        shar $(SHAR1) $(SRCS) $(SHAR2) > $(CMD).shar
  1422. X
  1423. X
  1424. Xmake:        ;
  1425. X        makemake -i -v1.00.02 \
  1426. X            -DSHELL='$(SHELL)' \
  1427. X            -DCC='$(CC)' \
  1428. X            -DDEFS='$(DEFS)' \
  1429. X            -DLIBS='$(LIBS)' \
  1430. X            -DDEBUG='$(DEBUG)' \
  1431. X            -DCOPTS='$(COPTS)' \
  1432. X            -DLOPTS='$(LOPTS)' \
  1433. X            -DLINTFLAGS='$(LINTFLAGS)' \
  1434. X            -DSHAR1='$(SHAR1)' \
  1435. X            -DSHAR2='$(SHAR2)' \
  1436. X            $(CMD) $(SRCS)
  1437. END_OF_FILE_Makefile
  1438.     size="`wc -c < Makefile`"
  1439.     if test 1539 -ne "$size" ; then
  1440.     echo "Makefile: extraction error - got $size chars"
  1441.     fi
  1442. fi
  1443. echo "done - 11 files extracted"
  1444. exit 0
  1445. --- cut here -----------------------------------------------------------------
  1446. -- 
  1447. Chip Rosenthal     chip@vector.UUCP    |      Choke me in the shallow water
  1448. Dallas Semiconductor   214-450-5337    |         before I get too deep.
  1449.