home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / gnuish / futil14.arc / fileutil.pl < prev    next >
Perl Script  |  1990-09-19  |  26KB  |  851 lines

  1. #! c:/bin/perl.exe
  2. # fileutils.pl - crude nroff -> texinfo conversion
  3. # Copyright (C) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  4.  
  5. # $Header: e:/gnu/fileutil/RCS/fileutil.pl 1.4.0.1 90/09/19 13:26:15 tho Exp $
  6. #
  7.  
  8. $, = ' ';        # set output field separator
  9. $\ = "\n";        # set output record separator
  10.  
  11. eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;
  12.             # process any FOO=bar switches
  13.  
  14. print <<'!END!OF!INTRO!';
  15. \input texinfo                    @c -*-texinfo-*-
  16. @setfilename fileutils.info
  17. @settitle The GNU file utilities (MS-DOS Version)
  18.  
  19. @comment Don't bother about some overfull boxes from the manpages.
  20. @iftex
  21. @finalout
  22. @end iftex
  23.  
  24. @ifinfo
  25. This file documents the MS-DOS port of the GNU file utilities.
  26.  
  27. Copyright @copyright{} 1990 Thorsten Ohl, <td12@@ddagsi3.bitnet>
  28.  
  29. Permission is granted to make and distribute verbatim copies of
  30. this manual provided the copyright notice and this permission notice
  31. are preserved on all copies.
  32.  
  33. @ignore
  34. Permission is granted to process this file through TeX and print the
  35. results, provided the printed document carries copying permission
  36. notice identical to this one except for the removal of this paragraph
  37. (this paragraph not being relevant to the printed manual).
  38.  
  39. @end ignore
  40. Permission is granted to copy and distribute modified versions of this
  41. manual under the conditions for verbatim copying, provided also that
  42. the section entitled ``GNU General Public License'' is included exactly as in
  43. the original, and provided that the entire resulting derived work is
  44. distributed under the terms of a permission notice identical to this
  45. one.
  46.  
  47. Permission is granted to copy and distribute translations of this
  48. manual into another language, under the above conditions for modified
  49. versions, except that the text of the translations of the section
  50. entitled ``GNU General Public License'' must be approved for accuracy by the
  51. Foundation.
  52. @end ifinfo
  53.  
  54.  
  55. @comment --------------------------------------------------------------
  56.  
  57. @node Top,,,(Dir)
  58.  
  59. @menu
  60. * Copying::        Legal matters.
  61. * Introduction::    Generalilties.
  62. * Installation::    How to make the GNU fileutilities.
  63. * MS-DOS::        How the MS-DOS version differs.
  64. * Manpages::        Short description of the commands.
  65. * Program Index::    A guide to key material.
  66. @end menu
  67.  
  68. @node Copying, Introduction, Top, Top
  69. @unnumbered GNU GENERAL PUBLIC LICENSE
  70. @center Version 1, February 1989
  71.  
  72. @display
  73. Copyright @copyright{} 1989 Free Software Foundation, Inc.
  74. 675 Mass Ave, Cambridge, MA 02139, USA
  75.  
  76. Everyone is permitted to copy and distribute verbatim copies
  77. of this license document, but changing it is not allowed.
  78. @end display
  79.  
  80. @unnumberedsec Preamble
  81.  
  82.   The license agreements of most software companies try to keep users
  83. at the mercy of those companies.  By contrast, our General Public
  84. License is intended to guarantee your freedom to share and change free
  85. software---to make sure the software is free for all its users.  The
  86. General Public License applies to the Free Software Foundation's
  87. software and to any other program whose authors commit to using it.
  88. You can use it for your programs, too.
  89.  
  90.   When we speak of free software, we are referring to freedom, not
  91. price.  Specifically, the General Public License is designed to make
  92. sure that you have the freedom to give away or sell copies of free
  93. software, that you receive source code or can get it if you want it,
  94. that you can change the software or use pieces of it in new free
  95. programs; and that you know you can do these things.
  96.  
  97.   To protect your rights, we need to make restrictions that forbid
  98. anyone to deny you these rights or to ask you to surrender the rights.
  99. These restrictions translate to certain responsibilities for you if you
  100. distribute copies of the software, or if you modify it.
  101.  
  102.   For example, if you distribute copies of a such a program, whether
  103. gratis or for a fee, you must give the recipients all the rights that
  104. you have.  You must make sure that they, too, receive or can get the
  105. source code.  And you must tell them their rights.
  106.  
  107.   We protect your rights with two steps: (1) copyright the software, and
  108. (2) offer you this license which gives you legal permission to copy,
  109. distribute and/or modify the software.
  110.  
  111.   Also, for each author's protection and ours, we want to make certain
  112. that everyone understands that there is no warranty for this free
  113. software.  If the software is modified by someone else and passed on, we
  114. want its recipients to know that what they have is not the original, so
  115. that any problems introduced by others will not reflect on the original
  116. authors' reputations.
  117.  
  118.   The precise terms and conditions for copying, distribution and
  119. modification follow.
  120.  
  121. @iftex
  122. @unnumberedsec TERMS AND CONDITIONS
  123. @end iftex
  124. @ifinfo
  125. @center TERMS AND CONDITIONS
  126. @end ifinfo
  127.  
  128. @enumerate
  129. @item
  130. This License Agreement applies to any program or other work which
  131. contains a notice placed by the copyright holder saying it may be
  132. distributed under the terms of this General Public License.  The
  133. ``Program'', below, refers to any such program or work, and a ``work based
  134. on the Program'' means either the Program or any work containing the
  135. Program or a portion of it, either verbatim or with modifications.  Each
  136. licensee is addressed as ``you''.
  137.  
  138. @item
  139. You may copy and distribute verbatim copies of the Program's source
  140. code as you receive it, in any medium, provided that you conspicuously and
  141. appropriately publish on each copy an appropriate copyright notice and
  142. disclaimer of warranty; keep intact all the notices that refer to this
  143. General Public License and to the absence of any warranty; and give any
  144. other recipients of the Program a copy of this General Public License
  145. along with the Program.  You may charge a fee for the physical act of
  146. transferring a copy.
  147.  
  148. @item
  149. You may modify your copy or copies of the Program or any portion of
  150. it, and copy and distribute such modifications under the terms of Paragraph
  151. 1 above, provided that you also do the following:
  152.  
  153. @itemize @bullet
  154. @item
  155. cause the modified files to carry prominent notices stating that
  156. you changed the files and the date of any change; and
  157.  
  158. @item
  159. cause the whole of any work that you distribute or publish, that
  160. in whole or in part contains the Program or any part thereof, either
  161. with or without modifications, to be licensed at no charge to all
  162. third parties under the terms of this General Public License (except
  163. that you may choose to grant warranty protection to some or all
  164. third parties, at your option).
  165.  
  166. @item
  167. If the modified program normally reads commands interactively when
  168. run, you must cause it, when started running for such interactive use
  169. in the simplest and most usual way, to print or display an
  170. announcement including an appropriate copyright notice and a notice
  171. that there is no warranty (or else, saying that you provide a
  172. warranty) and that users may redistribute the program under these
  173. conditions, and telling the user how to view a copy of this General
  174. Public License.
  175.  
  176. @item
  177. You may charge a fee for the physical act of transferring a
  178. copy, and you may at your option offer warranty protection in
  179. exchange for a fee.
  180. @end itemize
  181.  
  182. Mere aggregation of another independent work with the Program (or its
  183. derivative) on a volume of a storage or distribution medium does not bring
  184. the other work under the scope of these terms.
  185.  
  186. @item
  187. You may copy and distribute the Program (or a portion or derivative of
  188. it, under Paragraph 2) in object code or executable form under the terms of
  189. Paragraphs 1 and 2 above provided that you also do one of the following:
  190.  
  191. @itemize @bullet
  192. @item
  193. accompany it with the complete corresponding machine-readable
  194. source code, which must be distributed under the terms of
  195. Paragraphs 1 and 2 above; or,
  196.  
  197. @item
  198. accompany it with a written offer, valid for at least three
  199. years, to give any third party free (except for a nominal charge
  200. for the cost of distribution) a complete machine-readable copy of the
  201. corresponding source code, to be distributed under the terms of
  202. Paragraphs 1 and 2 above; or,
  203.  
  204. @item
  205. accompany it with the information you received as to where the
  206. corresponding source code may be obtained.  (This alternative is
  207. allowed only for noncommercial distribution and only if you
  208. received the program in object code or executable form alone.)
  209. @end itemize
  210.  
  211. Source code for a work means the preferred form of the work for making
  212. modifications to it.  For an executable file, complete source code means
  213. all the source code for all modules it contains; but, as a special
  214. exception, it need not include source code for modules which are standard
  215. libraries that accompany the operating system on which the executable
  216. file runs, or for standard header files or definitions files that
  217. accompany that operating system.
  218.  
  219. @item
  220. You may not copy, modify, sublicense, distribute or transfer the
  221. Program except as expressly provided under this General Public License.
  222. Any attempt otherwise to copy, modify, sublicense, distribute or transfer
  223. the Program is void, and will automatically terminate your rights to use
  224. the Program under this License.  However, parties who have received
  225. copies, or rights to use copies, from you under this General Public
  226. License will not have their licenses terminated so long as such parties
  227. remain in full compliance.
  228.  
  229. @item
  230. By copying, distributing or modifying the Program (or any work based
  231. on the Program) you indicate your acceptance of this license to do so,
  232. and all its terms and conditions.
  233.  
  234. @item
  235. Each time you redistribute the Program (or any work based on the
  236. Program), the recipient automatically receives a license from the original
  237. licensor to copy, distribute or modify the Program subject to these
  238. terms and conditions.  You may not impose any further restrictions on the
  239. recipients' exercise of the rights granted herein.
  240.  
  241. @item
  242. The Free Software Foundation may publish revised and/or new versions
  243. of the General Public License from time to time.  Such new versions will
  244. be similar in spirit to the present version, but may differ in detail to
  245. address new problems or concerns.
  246.  
  247. Each version is given a distinguishing version number.  If the Program
  248. specifies a version number of the license which applies to it and ``any
  249. later version'', you have the option of following the terms and conditions
  250. either of that version or of any later version published by the Free
  251. Software Foundation.  If the Program does not specify a version number of
  252. the license, you may choose any version ever published by the Free Software
  253. Foundation.
  254.  
  255. @item
  256. If you wish to incorporate parts of the Program into other free
  257. programs whose distribution conditions are different, write to the author
  258. to ask for permission.  For software which is copyrighted by the Free
  259. Software Foundation, write to the Free Software Foundation; we sometimes
  260. make exceptions for this.  Our decision will be guided by the two goals
  261. of preserving the free status of all derivatives of our free software and
  262. of promoting the sharing and reuse of software generally.
  263.  
  264. @iftex
  265. @heading NO WARRANTY
  266. @end iftex
  267. @ifinfo
  268. @center NO WARRANTY
  269. @end ifinfo
  270.  
  271. @item
  272. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  273. FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  274. OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  275. PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  276. OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  277. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  278. TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  279. PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  280. REPAIR OR CORRECTION.
  281.  
  282. @item
  283. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
  284. ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  285. REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  286. INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
  287. ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
  288. LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
  289. SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
  290. WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
  291. ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  292. @end enumerate
  293.  
  294. @iftex
  295. @heading END OF TERMS AND CONDITIONS
  296. @end iftex
  297. @ifinfo
  298. @center END OF TERMS AND CONDITIONS
  299. @end ifinfo
  300.  
  301. @page
  302. @unnumberedsec Appendix: How to Apply These Terms to Your New Programs
  303.  
  304.   If you develop a new program, and you want it to be of the greatest
  305. possible use to humanity, the best way to achieve this is to make it
  306. free software which everyone can redistribute and change under these
  307. terms.
  308.  
  309.   To do so, attach the following notices to the program.  It is safest to
  310. attach them to the start of each source file to most effectively convey
  311. the exclusion of warranty; and each file should have at least the
  312. ``copyright'' line and a pointer to where the full notice is found.
  313.  
  314. @smallexample
  315. @var{one line to give the program's name and a brief idea of what it does.}
  316. Copyright (C) 19@var{yy}  @var{name of author}
  317.  
  318. This program is free software; you can redistribute it and/or modify
  319. it under the terms of the GNU General Public License as published by
  320. the Free Software Foundation; either version 1, or (at your option)
  321. any later version.
  322.  
  323. This program is distributed in the hope that it will be useful,
  324. but WITHOUT ANY WARRANTY; without even the implied warranty of
  325. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  326. GNU General Public License for more details.
  327.  
  328. You should have received a copy of the GNU General Public License
  329. along with this program; if not, write to the Free Software
  330. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  331. @end smallexample
  332.  
  333. Also add information on how to contact you by electronic and paper mail.
  334.  
  335. If the program is interactive, make it output a short notice like this
  336. when it starts in an interactive mode:
  337.  
  338. @smallexample
  339. Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
  340. Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  341. This is free software, and you are welcome to redistribute it
  342. under certain conditions; type `show c' for details.
  343. @end smallexample
  344.  
  345. The hypothetical commands `show w' and `show c' should show the
  346. appropriate parts of the General Public License.  Of course, the
  347. commands you use may be called something other than `show w' and `show
  348. c'; they could even be mouse-clicks or menu items---whatever suits your
  349. program.
  350.  
  351. You should also get your employer (if you work as a programmer) or your
  352. school, if any, to sign a ``copyright disclaimer'' for the program, if
  353. necessary.  Here a sample; alter the names:
  354.  
  355. @example
  356. Yoyodyne, Inc., hereby disclaims all copyright interest in the
  357. program `Gnomovision' (a program to direct compilers to make passes
  358. at assemblers) written by James Hacker.
  359.  
  360. @var{signature of Ty Coon}, 1 April 1989
  361. Ty Coon, President of Vice
  362. @end example
  363.  
  364. That's all there is to it!
  365.  
  366.  
  367. @comment --------------------------------------------------------------
  368.  
  369. @node Introduction, Installation, Copying, Top
  370. @chapter General introduction to the GNU file utilities
  371.  
  372. Please send bug reports
  373. (preferably with fixes (@strong{context} @code{diff}'s!) to
  374.  
  375. @display
  376.       Thorsten Ohl
  377.       <td12@@ddagsi3.bitnet>
  378. @end display
  379.  
  380. I can make no promises to fix it immediately, but I might want to!
  381.  
  382.  
  383. @comment --------------------------------------------------------------
  384.  
  385. @node Installation, MS-DOS, Introduction, Top
  386. @chapter How to install the @code{GNUish MS-DOS} file utilities
  387.  
  388. @enumerate
  389. @item
  390. Edit the following variables in the makefile
  391.  
  392. @table @code
  393.  
  394. @item CFLAGS, LDFLAGS
  395. These are for the Microsoft C compiler Version 6.0, edit them for your
  396. system:
  397.  
  398. @table @code
  399. @item -AS
  400. Small memory model
  401.  
  402. @item -W4
  403. Full warnings!
  404.  
  405. @item -Ox
  406. Optimization.
  407.  
  408. @item -Za
  409. @item -DSTDC_HEADERS
  410. ANSI C.
  411.  
  412. @item -DUSG
  413. Microsoft's C looks more like System V than BSD.
  414.  
  415. @item -DVPRINTF
  416. The runtime library has @code{vprintf()}.
  417.  
  418. @item -DUTIMES_MISSING
  419. The runtime library misses @code{utimes()}.
  420.  
  421. @item -DFCHMOD_MISSING
  422. The runtime library misses @code{fchmod()}.
  423.  
  424. @item -DINT_16_BITS
  425. 32-bit @code{MS-DOS}?
  426.  
  427. @item -DBLKSIZE=0x4000
  428. Use large blocksizes for @emph{fast} copying.
  429.  
  430. @item -DSMART_SHELL
  431. Recognize the @code{GNUish MS-DOS} argument passing convention.
  432.  
  433. @item /e
  434. Pack the executable.
  435.  
  436. @item /st:0x8000
  437. Large stack.
  438.  
  439. @item /noe
  440. If duplicate symbols in object files and libraries, use the one from the
  441. object file.
  442. @end table
  443. @end table
  444.  
  445. @item
  446. Say @code{make}.
  447. @end enumerate
  448.  
  449. That's all.
  450.  
  451.  
  452. @comment --------------------------------------------------------------
  453.  
  454. @node MS-DOS, Manpages, Installation, Top
  455. @chapter How the @code{MS-DOS} version differs
  456.  
  457. All programs have additional options @samp{+version} and @samp{+copying}
  458. for echoing the revision and a short copyleft notice respectively to
  459. @file{stderr}.  This is mainly useful for identifying executables if
  460. you do not yet have the sources.
  461.  
  462. @section Individual programs
  463.  
  464. @itemize
  465. @item
  466. @pindex cp
  467. @pindex mv
  468. GNU @code{cp} and @code{mv} can generate backup files with GNU
  469. @code{emacs} style numbered backup suffixes (i.e. @file{foo.c} becomes
  470. @file{foo.c.~1~}). Of course this is almost always impossible under
  471. @code{MS-DOS}.  We have changed this convention to strip a part of the
  472. original filename. The following examples should make the principle
  473. clear:
  474. @example
  475. @file{foo} goes to @file{foo.~1~}
  476. @file{foo.c} goes to @file{foo.c~1}
  477. @file{foo.tex} goes to @file{foo.t~1}
  478. @end example
  479. This is not entirely foolproof (cf. @file{foo.txt} and @file{foo.tex}), and
  480. is furthermore restructed to at most 9 generations of backup files.  But
  481. here @code{MS-DOS}' limits are too restrictive to provide more.
  482.  
  483. @item
  484. @pindex cp
  485. GNU @code{cp} remembers all files it copies. This is primarily intended
  486. for avoiding duplicate copying of linked files, but has the nice side
  487. effect that by
  488. @example
  489. cp *.c foo.*
  490. @end example
  491. the file @file{foo.c} (if it exists) will not be copied twice.
  492.  
  493. Since @code{MS-DOS} has no inodes, this hashing doesn't work and has been
  494. disabled. Future versions might provide either of the following:
  495. @itemize
  496. @item
  497. Hashing based on filenames (no links!)
  498.  
  499. @item
  500. An improved @file{ndir} library, which uses the starting cluster of a
  501. file as an inode number.
  502.  
  503. @display
  504. Suggestions for fast and @strong{portable} access to the @code{MS-DOS}
  505. directory are very much appreciated.
  506. @end display
  507.  
  508. @end itemize
  509.  
  510. @item
  511. @pindex cat
  512. @pindex head
  513. @pindex tail
  514. @code{cat}, @code{head} and @code{tail} have the new option:
  515. @table @code
  516. @item -B, +binary
  517. Process the inputfiles and stdout in binary mode.  The has the effect of
  518. switching of the @key{LF} @key{CR}@key{LF} conversions and allows reading
  519. past a @ctrl{^Z}.
  520. @end table
  521.  
  522. @item
  523. @pindex dd
  524. @code{dd} has the follwing new options:
  525. @table @code
  526. @item im=@{text,binary@}
  527. Process the inputfile in binary mode.
  528.  
  529. @item om=@{text,binary@}
  530. Process the outputfile in binary mode.
  531. @end table
  532.  
  533.  
  534. @item
  535. @pindex ln
  536. @pindex cp
  537. There is no @code{ln}, since we can't link files under @code{MS-DOS}.
  538. If one @emph{needs} to, one can use @code{cp}.  But this wastes disk
  539. space, of course.
  540.  
  541. @item
  542. @pindex mkfifo
  543. There is no @code{mkfifo}, again for obvious reasons.
  544.  
  545. @item
  546. @pindex install
  547. There is no @code{install}.  I have no burning need for one, but for
  548. completeness' sake, there might be one in the future.
  549.  
  550. @item
  551. @pindex du
  552. There is also no @code{du}.  This one I really miss, but it might be hard
  553. to gather the information under @code{MS-DOS} - without going into too much
  554. device dependent details.
  555. @end itemize
  556.  
  557.  
  558. @comment --------------------------------------------------------------
  559.  
  560. @node Manpages, Program Index, MS-DOS, Top
  561. @chapter Manpages
  562.  
  563. These "manpages" have been translated automatically by a @code{perl}
  564. script from the @code{nroff} sources, as supplied with the GNU distribution.
  565.  
  566. Thus they apply to the GNU version of these programs.  For @code{MS-DOS}
  567. specific changes, additions, and omissions, @pxref{MS-DOS}
  568.  
  569.  
  570. !END!OF!INTRO!
  571.  
  572. # O.k. now perl's work starts.
  573.  
  574. # This array will be used to determine the `next' fiels of a node.
  575. @commands = ();
  576.  
  577. # Use all section 1 manpages in the `man' subdirectory.
  578. @manpages = split (/[ \t\n]+/,<$MANDIR/*.1>);
  579.  
  580. # First pass: generate the menu.
  581. print '@menu';
  582.  
  583. file: while ($manfile = shift @manpages)
  584.   {
  585.     chop;
  586.     open (cur_file, $manfile) || die "can't open  $manfile.";
  587.  
  588.     while (<cur_file>)
  589.       {
  590.     # Take the menu entry from the `NAME' section.
  591.  
  592.     if (/^\.SH[ \t]+NAME/)
  593.       {
  594.         # Get the next line.
  595.         $_ = <cur_file>;
  596.         &preprocess;
  597.  
  598.         ($name, $desc) = split ('[ \t]*-[ \t]*', $_, 2);
  599.         $name =~ s/[ \t]*,[ \t]*/ - /g;
  600.  
  601.         # Print out a menu entry
  602.         printf "* %-22s%s\n", $name . "::", $desc;
  603.  
  604.         # Save the name
  605.         push (@commands, $name);
  606.  
  607.         next file;
  608.       }
  609.       }
  610.  
  611.     die "Command has no name: $manfile.";    # oops...
  612.   }
  613.  
  614. print '@end menu';
  615.  
  616. # Second pass: process the complete manpages.
  617. shift (@commands);
  618. $last = "";
  619.  
  620. # No open tables, etc. yet.
  621. @pending = ();
  622.  
  623. @manpages = split (/[ \t\n]+/,<$MANDIR/*.1>);
  624.  
  625. file: while ($manfile = shift @manpages)
  626.   {
  627.     chop;
  628.     open (cur_file, $manfile) || die "can't open  $manfile";
  629.  
  630.     # Close all open tables.
  631.     &pop_pending;
  632.  
  633.   line: while (<cur_file>)
  634.       {
  635.     &preprocess;
  636.  
  637.     if (/^\./)
  638.       {
  639.         # We have found a command, interpret it.
  640.  
  641.         ($cmd, $arg) = split (/[ \t]+/, $_, 2);
  642.  
  643.         if ($cmd eq '.TH')
  644.           {
  645.         # ignore the header section.
  646.  
  647.         next line;
  648.           }
  649.         elsif ($cmd eq '.SH')
  650.           {
  651.         # A new section starts here
  652.  
  653.         # Close all open tables.
  654.         &pop_pending;
  655.  
  656.         if ($arg eq 'NAME')
  657.           {
  658.             # The name section gives us the information
  659.             # for the @node.
  660.  
  661.             $_ = <cur_file>;
  662.             &preprocess;
  663.  
  664.             ($name, $desc) = split ('[ \t]*-[ \t]*', $_, 2);
  665.             $name =~ s/[ \t]*,[ \t]*/ - /g;
  666.  
  667.             print '';
  668.             print '';
  669.             printf "@node %s, %s, %s, Manpages\n",
  670.                $name, shift (@commands), $last;
  671.             print '@section ' . $name;
  672.             print '@pindex ' . $name;
  673.             print '';
  674.             print '@unnumberedsubsec NAME';
  675.             print '@display';
  676.             print $_;
  677.             print '@end display';
  678.             print '';
  679.  
  680.             # Remember the name for the `last' field 
  681.             # of the next node
  682.             $last = $name;
  683.  
  684.             next line;
  685.           }
  686.         elsif ($arg eq 'SYNOPSIS')
  687.           {
  688.             # `display' the `SYNOPSIS'
  689.  
  690.             print '';
  691.             print '@unnumberedsubsec SYNOPSIS';
  692.             print '@display';
  693.  
  694.             push (@pending, '@end display');
  695.           }
  696.         elsif ($arg eq 'DESCRIPTION')
  697.           {
  698.             print '';
  699.             print '@unnumberedsubsec DESCRIPTION';
  700.             print '';
  701.           }
  702.         else
  703.           {
  704.             die "unknown section: $_.";
  705.           }
  706.           }
  707.         elsif ($cmd eq '.SS')
  708.           {
  709.         &pop_pending;
  710.  
  711.         if ($arg eq 'OPTIONS')
  712.           {
  713.             print '';
  714.             print '@unnumberedsubsec OPTIONS';
  715.             print '';
  716.           }
  717.         else
  718.           {
  719.             die "unknown section: $_.";
  720.           }
  721.           }
  722.         elsif ($cmd eq '.TP')
  723.           {
  724.         # This is usually for a table entry.
  725.  
  726.         print '';
  727.  
  728.         if (! $intable)
  729.           {
  730.             # We're not yet in a @table, open it.
  731.  
  732.             $intable = 1;
  733.             print '@table @code';
  734.             push (@pending, "@end table");
  735.           }
  736.  
  737.         # Get rid of the next lines' formatting commands.
  738.         $_ = <cur_file>;
  739.         &preprocess;
  740.  
  741.         if (/^\.[BI]R?/)
  742.           {
  743.             ($junk, $_) = split ('[ \t]+', $_, 2);
  744.           }
  745.  
  746.          print '@item ' . $_;
  747.           }
  748.         elsif ($cmd eq '.PP')
  749.           {
  750.         # New paragraph
  751.  
  752.         print '';
  753.           }
  754.         elsif ($cmd eq '.br')
  755.           {
  756.         # Break the line
  757.  
  758.         print '';
  759.           }
  760.         elsif ($cmd eq '.RS')
  761.           {
  762.         # This should start another level of `@table'
  763.  
  764.         print '@table @asis';
  765.           }
  766.         elsif ($cmd eq '.RE')
  767.           {
  768.         # This should end another level of `@table'
  769.  
  770.         print '@end table';
  771.           }
  772.         elsif ($cmd eq '.B')
  773.           {
  774.         # Assume that boldface is like `@code'
  775.  
  776.         printf "@code{%s} ", $arg;
  777.           }
  778.         elsif ($cmd eq '.BR')
  779.           {
  780.         printf "@code{%s}%s ", split (/[ \t]+/, $arg, 2);
  781.           }
  782.         elsif ($cmd eq '.I')
  783.           {
  784.         # Assume that italics are like `@samp'
  785.  
  786.         printf "@samp{%s} ", $arg;
  787.           }
  788.         elsif ($cmd eq '.IR')
  789.           {
  790.         printf "@samp{%s}%s ", split (/[ \t]+/, $arg, 2);
  791.           }
  792.         else
  793.           {
  794.         die "unknown command: $_.";
  795.           }
  796.       }
  797.     else
  798.       {
  799.         # Plain line, print it.
  800.  
  801.         print;
  802.       }
  803.       }
  804.   }
  805.  
  806. # Close all pending `@table's.
  807. &pop_pending;
  808.  
  809. print '
  810.  
  811. @comment --------------------------------------------------------------
  812.  
  813. @node Program Index, , Manpages, Top
  814. @appendix Program Index
  815.  
  816. @printindex pg
  817.  
  818. @contents
  819. @bye
  820. ';
  821.  
  822. # Trivial subroutines:
  823.  
  824. # handle special characters.
  825. sub preprocess
  826. {
  827.   chop;
  828.   s/\\-/-/g;
  829.   s/@/@@/g;
  830.   s/{/@{/g;
  831.   s/}/@}/g;
  832. }
  833.  
  834. # Close all pending `@table's.
  835. sub pop_pending
  836. {
  837.   while ($tmp = pop (@pending))
  838.     {
  839.       print $tmp;
  840.     }
  841.   $intable = 0;
  842. }
  843.  
  844. #
  845. # Local Variables:
  846. # mode:texinfo
  847. # ChangeLog:ChangeLog
  848. # compile-command:make
  849. # End:
  850.  
  851.