From: Sascha Wildner Date: Mon, 22 Apr 2019 15:27:08 +0000 (+0200) Subject: Remove the old GNU man, makewhatis and manpath.config.5 manual page. X-Git-Tag: v5.7.0~273 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/6abef2da672b2112acf2502b255dfe45aaceef67 Remove the old GNU man, makewhatis and manpath.config.5 manual page. --- diff --git a/gnu/usr.bin/man/COPYING b/gnu/usr.bin/man/COPYING deleted file mode 100644 index a43ea2126f..0000000000 --- a/gnu/usr.bin/man/COPYING +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 675 Mass Ave, Cambridge, MA 02139, USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - Appendix: How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) 19yy - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) 19yy name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/gnu/usr.bin/man/Makefile b/gnu/usr.bin/man/Makefile deleted file mode 100644 index 15771ab3f8..0000000000 --- a/gnu/usr.bin/man/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# Master Makefile for man, manpath, apropos, whatis, and makewhatis -# -# You may distribute under the terms of the GNU General Public -# License as specified in the README file that comes with the man 1.0 -# distribution. -# - -SUBDIR = lib man manpath apropos - -.include diff --git a/gnu/usr.bin/man/Makefile.inc b/gnu/usr.bin/man/Makefile.inc deleted file mode 100644 index 7e3477b891..0000000000 --- a/gnu/usr.bin/man/Makefile.inc +++ /dev/null @@ -1,38 +0,0 @@ -# $FreeBSD: src/gnu/usr.bin/man/Makefile.inc,v 1.17.2.2 2001/02/23 09:39:21 ru Exp $ -# -# Set a bunch of things to hardcoded paths so that we don't accidently -# pick up a user's own version of some utility and hose ourselves. -# -libdir= /etc -bindir= ${BINDIR} -pager= more -s -manpath_config_file= /etc/manpath.config -troff= /usr/bin/groff -S -man -# -Tascii or localized encoding added automatically -nroff= /usr/bin/groff -S -Wall -mtty-char -man -apropos= /usr/bin/apropos -whatis= /usr/bin/whatis -eqn= /usr/bin/eqn -# -Tascii or localized encoding added automatically -neqn= /usr/bin/eqn -tbl= /usr/bin/tbl -col= /usr/bin/col -vgrind= /usr/bin/vgrind -refer= /usr/bin/refer -grap= # no grap -pic= /usr/bin/pic -zcat= /usr/bin/zcat -q -compress= /usr/bin/gzip -c -compext= .gz - -.if exists(${.OBJDIR}/../lib) -LIBDESTDIR= ${.OBJDIR}/../lib -.else -LIBDESTDIR= ${.CURDIR}/../lib -.endif - -LIBMAN= ${LIBDESTDIR}/libman.a - -WARNS?= 6 - -.include "../Makefile.inc" diff --git a/gnu/usr.bin/man/README b/gnu/usr.bin/man/README deleted file mode 100644 index 9c5a9e47b9..0000000000 --- a/gnu/usr.bin/man/README +++ /dev/null @@ -1,134 +0,0 @@ -README file for man(1). - -This is a replacement for Un*x man(1), apropos(1), whatis(1), and -manpath(1). It has all kinds of neat features that other versions of -man don't, including support for multiple man page directory trees, -preformatted man pages, and troff. It is provided without any -warranty whatever. I hope you find it useful. - -This program is not a GNU product but it is distributed under the -terms of the GNU copyleft which is described in the file COPYING. - -There is a solution written in perl which is probably superior in -every way, but, like me, you may prefer this one anyway. -:-) - -If you compile with support for preformatted man pages, man(1) will -try to update the preformatted page if the man page source is newer. - -If you compile with support for troff, you can say things like -`man -t foo | psdit > foo.ps' and have fabulous printed documentation -as well. - -I have resisted the temptation to handle all the bizarre ways various -vendors have of organizing man pages. This version of man assumes -that directory trees have the structure: - - .../man - /manSect - /foo.Sect* - ... - /catSect - /foo.Sect* - ... - -where Sect is some number or string and should be listed in the set of -sections to be searched. It is not necessary to have both the cat* -and man* subdirectories, but you must have at least one. :-) - - -INSTALLATION - -1. Run configure. This will grope around your system a bit and then - ask you a number of questions. It will create a Makefile from the - file Makefile.in, and a config.h file from config.h.in. You may - have to do some fine tuning to get things to work exactly right on - your system. If you do, I'd like to know what changes you had to - make to get things working. - -2. Edit the manpath.config file. This determines the system-wide - mappings for bin directories and man page directories. - -3. Do a `make all', try it out, and then if you're happy with that, do - a `make install'. You don't need to be root to use this set of - programs. - -4. Install the whatis database(s) by running makewhatis. If you want - to keep things absolutely current, you'll need to run this whenever - you add new man pages. You might want to add an entry in your - crontab. - -BUGS - -If you find one of these, please tell me about it. If you have a fix, -that's even better. If not, I can't guarantee that I'll fix it, but I -would like to know about them. - -John Eaton -jwe@che.utexas.edu -Department of Chemical Engineering -The University of Texas at Austin -Austin, Texas 78712 - - -CHANGES - -Partial list of changes since version 1.0: - -Installation made easier (this was the intent anyway) with the -introduction of a configure script. - -Commands like `man 3f intro' handled properly when the name of the -file we want is something like .../man3/intro.3f. - -Man can now run set uid to a special user so formatted man pages don't -have to be world writable. - -Man now works with compressed (.Z) frozen (.F) and yabba (.Y) cat -files. Frozen files are compressed files using freeze/melt, some -combination of LZW and tree coding. Sources for it came out on -comp.sources.misc or alt.sources or ... a few months ago. Yabba files -are compressed using yabba/unyabba, a data compression scheme posted -to alt.sources by Dan Bernstein. - -Man now uses a more reasonable default for the search order: -1, n, l, 6, 8, 2, 3, 4, 5, 7, p, o - -Man now allows for user-definable section search order via -S or -MANSECT. - -Glob.c can work even if you don't have alloca, and works properly on -Suns with the Sun C compiler. - -There is now a way to automatically to run preprocessors like the Sun -man program. The first line of the man page indicates which -preprocessors should be run: - - If the first line is a string of the form: - - '\" X - - where X is separated from the `"' by a single SPACE and - consists of any combination of characters in the following - list, man pipes its input to troff(1) or nroff(1) through - the corresponding preprocessors. - - e eqn(1), or neqn for nroff - g grap(1) - p pic(1) - r refer(1) - t tbl(1), and col(1V) for nroff - v vgrind(1) - -Preprocessors may also be set on the command line with -p or from the -environment with MANROFFSEQ. - -The tbl preprocessor is run by default. - -Manpath now stat()'s the directories in MANPATH to avoid including -directories that don't exist. - -The output of apropos and whatis are now piped through PAGER. - -There is a new option to show where you would find a man page -(-w option) and in what order (-w with -a). diff --git a/gnu/usr.bin/man/TODO b/gnu/usr.bin/man/TODO deleted file mode 100644 index cd2d7e6014..0000000000 --- a/gnu/usr.bin/man/TODO +++ /dev/null @@ -1,123 +0,0 @@ -Things that would be nice but aren't really necessary: - -0. Update the documentation. - -XX Come up with an easier way to install this thing. There are now - lots of options and dependent flags to set. Should I worry too - much about this? - -XX Properly handle commands like `man 3f intro' when the name of the - file we want is something like .../man3/intro.3f. The way this is - done right now seems sort of kludgey but it mostly works. See - man.c for details. - -2. Malloc everything instead of having fixed limits... Or at least - check the limits everywhere. If you're paranoid about this, make - the limits big (famous last words: really, there aren't that many - things that could go wrong :-). - -3. Try to do a little better job of memory management. There are a - lot of little temporary strings that are malloc'd and never freed. - This is probably ok for a standalone program but not so good if - you wanted to call man() from another program. - -XX Come up with a clear view of the cat directory file permissions - problem. What's a good solution, other than having man run setuid - to some special user? (Make directories writable by all, cat - files 666.) - -XX Allow a compile time option that makes man run setuid to some - other user that owns all the cat pages, so that they don't have to - be world writable. - -XX Allow man to deal with compressed (.Z) frozen (.F) and yabba (.Y) - cat files. Frozen files are compressed files using freeze/melt, - some combination of LZW and tree coding. Sources for it came out - on comp.sources.misc or alt.sources or ... a few months ago. - Yabba files are compressed using yabba/unyabba, a data compression - scheme posted to alt.sources by Dan Bernstein. - -XX Choose a more reasonable default for the search order. Perhaps - this: 1, n, l, 6, 8, 2, 3, 4, 5, 7, p, o - -XX Fix glob.c so it doesn't need alloca, and/or fix it so that it can - work on a Sun: - - #ifdef __GNUC__ - #define alloca __builtin_alloca - #else /* !__GNUC__ */ - #ifdef sparc - #include - #endif /* sparc */ - #endif /* __GNUC__ */ - -XX Add some way to automatically to run preprocessors. The Sun man - program has a convention that the first line of the man page can - indicate which preprocessors should be run. Here's an excerpt from - its man page: - - Preprocessing Manual Pages - If the first line is a string of the form: - - '\" X - - where X is separated from the `"' by a single SPACE and - consists of any combination of characters in the following - list, man pipes its input to troff(1) or nroff(1) through - the corresponding preprocessors. - - e eqn(1), or neqn for nroff - r refer(1) - t tbl(1), and col(1V) for nroff - v vgrind(1) - - If eqn or neqn is invoked, it will automatically read the - file /usr/pub/eqnchar (see eqnchar(7)). - -XX Have manpath stat() the directories in MANPATH to avoid including - directories that don't exist. Some versions of man and whatis - complain when the directories (like /usr/new/man) don't exist. - -XX Pipe the output of apropos and whatis through a pager. - -XX I've been using your man(1) package for a while now and I ran into - a problem with the X man pages that use tbl commands. Is it - possible to configure your man(1) package to use a general command - string. For example, a user could set an environment variable: - - setenv ROFFLINE 'pic $* | tbl | nroff -man' - -13. Fix makewhatis so that it can handle stuff like this (from the - Motif 1.1 man pages): - - .TH XmRowColumn 3X "" "" "" "" - .SH NAME - .mc | - \fBXmRowColumn \(em the RowColumn widget class.\fP - .mc - .iX "XmRowColumn" - .iX "widget class" "RowColumn" - .sp 1 - .SH SYNOPSIS - -14. Consider changing the format of the awk command's printf to use - "%s" instead of the standard 20.20s to accomodate the extra long - file names used by Motif. Maybe there's a better way to handle - this? - -XX. Add ability to run man on a local file - -16. Handle per-tree tmac macros - -XX Allow user-definable section search order via -S or $MANSECT. - Thus programmers can get stty(3) before stty(1). - -XX Show all the places you would find a man page (-w option) and in - what order. - -19. Support for multi-char sections like man1m/*.1m or manavs/*.avs - (can I have a section that doesn't start with a numeral?) - -20. Implement man -K for regexp apropos - -21. An option to grep through all the man pages in $MANPATH diff --git a/gnu/usr.bin/man/apropos/Makefile b/gnu/usr.bin/man/apropos/Makefile deleted file mode 100644 index 97e06ff75c..0000000000 --- a/gnu/usr.bin/man/apropos/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# $FreeBSD: src/gnu/usr.bin/man/apropos/Makefile,v 1.15.2.1 2001/04/25 14:04:13 ru Exp $ - -SCRIPTS=apropos.sh -MAN= apropos.1 - -LINKS= ${BINDIR}/apropos ${BINDIR}/whatis -MLINKS= apropos.1 whatis.1 - -.include diff --git a/gnu/usr.bin/man/apropos/apropos.1 b/gnu/usr.bin/man/apropos/apropos.1 deleted file mode 100644 index aa79506b83..0000000000 --- a/gnu/usr.bin/man/apropos/apropos.1 +++ /dev/null @@ -1,47 +0,0 @@ -.\" Man page for apropos an whatis -.\" -.\" Copyright (c) 1990, 1991, John W. Eaton. -.\" -.\" You may distribute under the terms of the GNU General Public -.\" License as specified in the README file that comes with the man 1.0 -.\" distribution. -.\" -.\" John W. Eaton -.\" jwe@che.utexas.edu -.\" Department of Chemical Engineering -.\" The University of Texas at Austin -.\" Austin, Texas 78712 -.\" -.\" $FreeBSD: src/gnu/usr.bin/man/apropos/apropos.man,v 1.6.2.3 2002/08/11 11:18:51 ru Exp $ -.Dd January 15, 1991 -.Dt APROPOS 1 -.Os -.Sh NAME -.Nm apropos , -.Nm whatis -.Nd search the whatis database -.Sh SYNOPSIS -.Nm apropos -.Ar keyword ... -.Nm whatis -.Ar keyword ... -.Sh DESCRIPTION -.Nm -searches a set of database files containing short descriptions -of system commands for keywords and displays the result on the -standard output. -.Nm whatis -displays only complete word matches. -.Pp -.Ar keyword -really is an extended regular expression, please read -.Xr grep 1 -manual page for more information about its format. -.Sh DIAGNOSTICS -The -.Nm -utility exits 0 on success, and 1 if no keyword matched. -.Sh SEE ALSO -.Xr grep 1 , -.Xr man 1 , -.Xr makewhatis 8 diff --git a/gnu/usr.bin/man/apropos/apropos.sh b/gnu/usr.bin/man/apropos/apropos.sh deleted file mode 100644 index b32ac3792b..0000000000 --- a/gnu/usr.bin/man/apropos/apropos.sh +++ /dev/null @@ -1,111 +0,0 @@ -#!/bin/sh -# -# apropos -- search the whatis database for keywords. -# -# Copyright (c) February 1996 Wolfram Schneider . Berlin. -# Copyright (c) 1990, 1991, John W. Eaton. -# -# You may distribute under the terms of the GNU General Public -# License as specified in the README file that comes with the man -# distribution. -# -# John W. Eaton -# jwe@che.utexas.edu -# Department of Chemical Engineering -# The University of Texas at Austin -# Austin, Texas 78712 -# -# $FreeBSD: src/gnu/usr.bin/man/apropos/apropos.sh,v 1.12.2.2 2002/08/11 11:20:54 ru Exp $ - - -PATH=/bin:/usr/bin:$PATH -db=whatis # name of whatis data base -grepopt='' - -# man -k complain if exit_nomatch=1 and no keyword matched -: ${exit_nomatch=0} -exit_error=2 - -# argument test -case $# in 0) - echo "usage: `basename $0` keyword ..." >&2 - exit $exit_error - ;; -esac - -case "$0" in - *whatis) grepopt='-w';; # run as whatis(1) - *) grepopt='';; # otherwise run as apropos(1) -esac - -# test manpath -manpath=`/usr/bin/manpath -q | tr : '\040'` -case X"$manpath" in X) - echo "`basename $0`: manpath is null, use \"/usr/share/man\"" >&2 - manpath=/usr/share/man - ;; -esac - - -# reset $PAGER if $PAGER is empty -case X"$PAGER" in X) - PAGER="more -s" - ;; -esac - -man_locales=`/usr/bin/manpath -qL` - -# search for existing */whatis databases -mandir='' -for d in $manpath -do - if [ -f "$d/$db" -a -r "$d/$db" ] - then - mandir="$mandir $d/$db" - fi - - # Check for localized manpage subdirectories - if [ X"$man_locales" != X ]; then - for l in $man_locales - do - if [ -f "$d/$l/$db" -a -r "$d/$l/$db" ]; - then - mandir="$mandir $d/$l/$db" - fi - done - fi -done - -case X"$mandir" in X) - echo "`basename $0`: no whatis databases in $manpath" >&2 - exit $exit_error -esac - - -for manpage -do - if grep -Ehi $grepopt -- "$manpage" $mandir; then : - else - echo "$manpage: nothing appropriate" - fi -done | - -( # start $PAGER only if we find a manual page - while read line - do - case $line in - # collect error(s) - *": nothing appropriate") line2="$line2$line\n";; - # matched line or EOF - *) break;; - esac - done - - # nothing found, exit - if [ -z "$line" -a ! -z "$line2" ]; then - printf -- "$line2" - exit $exit_nomatch - else - ( printf -- "$line2"; echo "$line"; cat ) | $PAGER - fi -) diff --git a/gnu/usr.bin/man/lib/Makefile b/gnu/usr.bin/man/lib/Makefile deleted file mode 100644 index c001fee689..0000000000 --- a/gnu/usr.bin/man/lib/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# $FreeBSD: src/gnu/usr.bin/man/lib/Makefile,v 1.11.6.1 2002/07/19 18:46:24 ru Exp $ - -LIB= man -INTERNALLIB= true - -SRCS= gripes.c util.c - -# Kludge to create config.h for other modules. The library itself doesn't -# depend on config.h. -SRCS+= config.h - -.include diff --git a/gnu/usr.bin/man/lib/config.h b/gnu/usr.bin/man/lib/config.h deleted file mode 100644 index 5c21bff9ad..0000000000 --- a/gnu/usr.bin/man/lib/config.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - * config.h - * - * If you haven't read the README file, now might be a good time. - * - * Sorry it's so long, but there are lots of things you might want to - * customize for your site. - * - * Copyright (c) 1990, 1991, John W. Eaton. - * - * You may distribute under the terms of the GNU General Public - * License as specified in the file COPYING that comes with the man - * distribution. - * - * John W. Eaton - * jwe@che.utexas.edu - * Department of Chemical Engineering - * The University of Texas at Austin - * Austin, Texas 78712 - */ - -/* - * This should be at least the size of the longest path. - */ -#ifndef MAXPATHLEN -#define MAXPATHLEN 1024 -#endif - -/* - * This is the maximum number of directories expected in the manpath. - */ -#ifndef MAXDIRS -#define MAXDIRS 64 -#endif - -/* - * It's probably best to define absolute paths to all of these. If - * you don't, you'll be depending on the user's path to be correct - * when system () is called. This can result in weird behavior that's - * hard to track down, especially after you forget how this program - * works... If you don't have some of these programs, simply define - * them to be empty strings (i.e. ""). As a minimum, you must have - * nroff installed. - */ -#ifndef APROPOS -#define APROPOS "/usr/bin/apropos" -#endif - -#ifndef WHATIS -#define WHATIS "/usr/bin/whatis" -#endif - -#ifndef PAGER -#define PAGER "more -s" -#endif - -#ifndef TROFF -#define TROFF "/usr/bin/groff -S -man" -#endif - -#ifndef NROFF -#define NROFF "/usr/bin/groff -S -Wall -mtty-char -man" -#endif - -#ifndef EQN -#define EQN "/usr/bin/eqn" -#endif - -#ifndef NEQN -#define NEQN "/usr/bin/eqn" -#endif - -#ifndef TBL -#define TBL "/usr/bin/tbl" -#endif - -#ifndef COL -#define COL "/usr/bin/col" -#endif - -#ifndef VGRIND -#define VGRIND "/usr/bin/vgrind" -#endif - -#ifndef REFER -#define REFER "/usr/bin/refer" -#endif - -#ifndef GRAP -#define GRAP "" -#endif - -#ifndef PIC -#define PIC "/usr/bin/pic" -#endif - -/* - * Define the absolute path to the configuration file. - */ -#ifndef MAN_MAIN - static char config_file[] = "/etc/manpath.config" ; -#endif - -/* - * Define the uncompression program(s) to use for those preformatted - * pages that end in the given character. If you add extras here, you - * may need to change man.c. [I have no idea what FCAT and YCAT files - * are! - I will leave them in for now.. -jkh] - */ -/* .F files */ -#define FCAT "" -/* .Y files */ -#define YCAT "" -/* .Z files */ -#define ZCAT "/usr/bin/zcat -q" - -/* - * This is the standard program to use on this system for compressing - * pages once they have been formatted, and the character to tack on - * to the end of those files. The program listed is expected to read - * from the standard input and write compressed output to the standard - * output. These won't actually be used unless compression is enabled. - */ -#define COMPRESSOR "/usr/bin/gzip -c" -#define COMPRESS_EXT ".gz" - -/* - * Define the standard manual sections. For example, if your man - * directory tree has subdirectories man1, man2, man3, mann, - * and man3foo, std_sections[] would have "1", "2", "3", "n", and - * "3foo". Directories are searched in the order they appear. Having - * extras isn't fatal, it just slows things down a bit. - * - * Note that this is just for directories to search. If you have - * files like .../man3/foobar.3Xtc, you don't need to have "3Xtc" in - * the list below -- this is handled separately, so that `man 3Xtc foobar', - * `man 3 foobar', and `man foobar' should find the file .../man3/foo.3Xtc, - * (assuming, of course, that there isn't a .../man1/foo.1 or somesuch - * that we would find first). - * - * Note that this list should be in the order that you want the - * directories to be searched. Is there a standard for this? What is - * the normal order? If anyone knows, please tell me! - */ -#ifndef MANPATH_MAIN - static const char *std_sections[] = - { - "1", "1aout", "8", "2", "3", "n", "4", "5", "6", "7", "9", "l", NULL - }; -#endif - -/* - * Not all systems define these in stat.h. - */ -#ifndef S_IRUSR -#define S_IRUSR 00400 /* read permission: owner */ -#endif -#ifndef S_IWUSR -#define S_IWUSR 00200 /* write permission: owner */ -#endif -#ifndef S_IRGRP -#define S_IRGRP 00040 /* read permission: group */ -#endif -#ifndef S_IWGRP -#define S_IWGRP 00020 /* write permission: group */ -#endif -#ifndef S_IROTH -#define S_IROTH 00004 /* read permission: other */ -#endif -#ifndef S_IWOTH -#define S_IWOTH 00002 /* write permission: other */ -#endif - -/* - * This is the mode used for formatted pages that we create. If you - * are using the setgid option, you should use 664. If you are not, - * you should use 666 and make the cat* directories mode 777. - */ -#ifndef CATMODE -#define CATMODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH -#endif diff --git a/gnu/usr.bin/man/lib/gripes.c b/gnu/usr.bin/man/lib/gripes.c deleted file mode 100644 index b7fae02fca..0000000000 --- a/gnu/usr.bin/man/lib/gripes.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * gripes.c - * - * Copyright (c) 1990, 1991, John W. Eaton. - * - * You may distribute under the terms of the GNU General Public - * License as specified in the file COPYING that comes with the man - * distribution. - * - * John W. Eaton - * jwe@che.utexas.edu - * Department of Chemical Engineering - * The University of Texas at Austin - * Austin, Texas 78712 - */ - -#include -#include -#include "gripes.h" - -extern char *prognam; - -void -gripe_no_name (char *section) -{ - if (section) - fprintf (stderr, "What manual page do you want from section %s?\n", - section); - else - fprintf (stderr, "What manual page do you want?\n"); - - fflush (stderr); -} - -void -gripe_reading_man_file (char *name) -{ - fprintf (stderr, "Read access denied for file %s\n", name); - - fflush (stderr); -} - -void -gripe_converting_name (char *name, int to_cat) -{ - if (to_cat) - fprintf (stderr, "Error converting %s to cat name\n", name); - else - fprintf (stderr, "Error converting %s to man name\n", name); - - fflush (stderr); - - exit (1); -} - -void -gripe_system_command (int status) -{ - fprintf (stderr, "Error executing formatting or display command.\n"); - fprintf (stderr, "system command exited with status %d\n", status); - - fflush (stderr); -} - -void -gripe_not_found (char *name, char *section) -{ - if (section) - fprintf (stderr, "No entry for %s in section %s of the manual\n", - name, section); - else - fprintf (stderr, "No manual entry for %s\n", name); - - fflush (stderr); -} - -void -gripe_incompatible (const char *s) -{ - fprintf (stderr, "%s: incompatible options %s\n", prognam, s); - - fflush (stderr); - - exit (1); -} - -void -gripe_getting_mp_config (char *file) -{ - fprintf (stderr, "%s: unable to find the file %s\n", prognam, file); - - fflush (stderr); - - exit (1); -} - -void -gripe_reading_mp_config (char *file) -{ - fprintf (stderr, "%s: unable to make sense of the file %s\n", prognam, file); - - fflush (stderr); - - exit (1); -} - -void -gripe_invalid_section (char *section) -{ - fprintf (stderr, "%s: invalid section (%s) selected\n", prognam, section); - - fflush (stderr); - - exit (1); -} - -void -gripe_manpath (void) -{ - fprintf (stderr, "%s: manpath is null\n", prognam); - - fflush (stderr); - - exit (1); -} - -void -gripe_alloc (int bytes, const char *object) -{ - fprintf (stderr, "%s: can't malloc %d bytes for %s\n", - prognam, bytes, object); - - fflush (stderr); - - exit (1); -} - -void -gripe_roff_command_from_file (char *file) -{ - fprintf (stderr, "Error parsing *roff command from file %s\n", file); - - fflush (stderr); -} - -void -gripe_roff_command_from_env (void) -{ - fprintf (stderr, "Error parsing MANROFFSEQ. Using system defaults.\n"); - - fflush (stderr); -} - -void -gripe_roff_command_from_command_line (void) -{ - fprintf (stderr, "Error parsing *roff command from command line.\n"); - - fflush (stderr); -} diff --git a/gnu/usr.bin/man/lib/gripes.h b/gnu/usr.bin/man/lib/gripes.h deleted file mode 100644 index 54a948f662..0000000000 --- a/gnu/usr.bin/man/lib/gripes.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * gripes.h - * - * Copyright (c) 1990, 1991, John W. Eaton. - * - * You may distribute under the terms of the GNU General Public - * License as specified in the file COPYING that comes with the man - * distribution. - * - * John W. Eaton - * jwe@che.utexas.edu - * Department of Chemical Engineering - * The University of Texas at Austin - * Austin, Texas 78712 - */ - -extern void gripe_no_name (char *); -extern void gripe_converting_name (char *, int); -extern void gripe_system_command (int); -extern void gripe_reading_man_file (char *); -extern void gripe_not_found (char *, char *); -extern void gripe_invalid_section (char *); -extern void gripe_manpath (void); -extern void gripe_alloc (int, const char *); -extern void gripe_incompatible (const char *); -extern void gripe_getting_mp_config (char *); -extern void gripe_reading_mp_config (char *); -extern void gripe_roff_command_from_file (char *); -extern void gripe_roff_command_from_env (void); -extern void gripe_roff_command_from_command_line (void); diff --git a/gnu/usr.bin/man/lib/util.c b/gnu/usr.bin/man/lib/util.c deleted file mode 100644 index 121e642301..0000000000 --- a/gnu/usr.bin/man/lib/util.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * util.c - * - * Copyright (c) 1990, 1991, John W. Eaton. - * - * You may distribute under the terms of the GNU General Public - * License as specified in the file COPYING that comes with the man - * distribution. - * - * John W. Eaton - * jwe@che.utexas.edu - * Department of Chemical Engineering - * The University of Texas at Austin - * Austin, Texas 78712 - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "gripes.h" -#include "util.h" - -extern int debug; - -/* - * Extract last element of a name like /foo/bar/baz. - */ -char * -mkprogname (char *s) -{ - char *t; - - t = strrchr (s, '/'); - if (t == (char *)NULL) - t = s; - else - t++; - - return strdup (t); -} - -void -downcase (unsigned char *s) -{ - unsigned char c; - while ((c = *s) != '\0') - { - if (isalpha (c)) - *s = tolower (c); - s++; - } -} - -/* - * Is file a newer than file b? - * - * case: - * - * a newer than b returns 1 - * a older than b returns 0 - * stat on a fails returns -1 - * stat on b fails returns -2 - * stat on a and b fails returns -3 - */ -int -is_newer (char *fa, char *fb) -{ - struct stat fa_sb; - struct stat fb_sb; - int fa_stat; - int fb_stat; - int status = 0; - - fa_stat = stat (fa, &fa_sb); - if (fa_stat != 0) - status = 1; - - fb_stat = stat (fb, &fb_sb); - if (fb_stat != 0) - status |= 2; - - if (status != 0) - return -status; - - return (fa_sb.st_mtime > fb_sb.st_mtime); -} - -/* - * Is path a directory? - */ -int -is_directory (char *path) -{ - struct stat sb; - int status; - - status = stat (path, &sb); - - if (status != 0) - return -1; - - return ((sb.st_mode & S_IFDIR) == S_IFDIR); - -} - -/* - * Attempt a system () call. Return 1 for success and 0 for failure - * (handy for counting successes :-). - */ -int -do_system_command (char *command) -{ - int status = 0; - - /* - * If we're debugging, don't really execute the command -- you never - * know what might be in that mangled string :-O. - */ - if (debug) - fprintf (stderr, "\ntrying command: %s\n", command); - else - status = system (command); - - /* check return value from system() function first */ - if (status == -1) { - fprintf(stderr, - "wait() for exit status of shell failed in function system()\n"); - return 0; - } else if (status == 127 || status == (127 << 8)) { - fprintf(stderr, "execution of the shell failed in function system()\n"); - return 0; - } - - if (WIFSIGNALED(status)) - return -1; - else if (WEXITSTATUS(status)) { - gripe_system_command (status); - return 0; - } - else - return 1; -} diff --git a/gnu/usr.bin/man/lib/util.h b/gnu/usr.bin/man/lib/util.h deleted file mode 100644 index 23a7004c3a..0000000000 --- a/gnu/usr.bin/man/lib/util.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * util.h - * - * Copyright (c) 2010, Sascha Wildner - * - * You may distribute under the terms of the GNU General Public - * License as specified in the file COPYING that comes with the man - * distribution. - */ - -extern int do_system_command(char *); -extern void downcase(unsigned char *); -extern int is_directory(char *); -extern int is_newer(char *, char *); -extern char *mkprogname(char *); diff --git a/gnu/usr.bin/man/man/Makefile b/gnu/usr.bin/man/man/Makefile deleted file mode 100644 index cdb8c260ff..0000000000 --- a/gnu/usr.bin/man/man/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# $FreeBSD: src/gnu/usr.bin/man/man/Makefile,v 1.27.2.4 2002/07/17 13:25:17 ru Exp $ -# - -PROG= man -SRCS= man.c manpath.c glob.c -BINOWN= man -BINMODE=4555 -.if !defined(NOFSCHG) -INSTALLFLAGS= -fschg -.endif - -CFLAGS+= -I${LIBDESTDIR} -DPADD= ${LIBMAN} -LDADD= ${LIBMAN} - -DPADD+= ${LIBZ} -LDADD+= -lz - -CFLAGS+= -I${.CURDIR}/../lib -CFLAGS+= -DCATMODE=0644 - -.PATH: ${.CURDIR}/../manpath - -.include diff --git a/gnu/usr.bin/man/man/glob.c b/gnu/usr.bin/man/man/glob.c deleted file mode 100644 index c11952e492..0000000000 --- a/gnu/usr.bin/man/man/glob.c +++ /dev/null @@ -1,598 +0,0 @@ -/* File-name wildcard pattern matching for GNU. - Copyright (C) 1985, 1988, 1989, 1990, 1991 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 1, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* To whomever it may concern: I have never seen the code which most - Unix programs use to perform this function. I wrote this from scratch - based on specifications for the pattern matching. --RMS. */ - -#ifdef SHELL -#include "config.h" -#endif /* SHELL */ - -#include -#include -#include -#include - -#define direct dirent -#define D_NAMLEN(d) strlen((d)->d_name) -#define REAL_DIR_ENTRY(dp) (dp->d_ino != 0) - -#define bcopy(s, d, n) memcpy ((d), (s), (n)) -#define index strchr -#define rindex strrchr - -#ifndef alloca -#define alloca __builtin_alloca -#endif - -int glob_pattern_p (char *); -int glob_match (char *, char *, int); -char **glob_vector (char *, const char *); -char **glob_filename (char *); - -/* Nonzero if '*' and '?' do not match an initial '.' for glob_filename. */ -int noglob_dot_filenames = 1; - -static int glob_match_after_star (char *, char *); - -static int -collate_range_cmp (int a, int b) -{ - int r; - static char s[2][2]; - - if ((unsigned char)a == (unsigned char)b) - return 0; - s[0][0] = a; - s[1][0] = b; - if ((r = strcoll(s[0], s[1])) == 0) - r = (unsigned char)a - (unsigned char)b; - return r; -} - -/* Return nonzero if PATTERN has any special globbing chars in it. */ - -int -glob_pattern_p (char *pattern) -{ - char *p = pattern; - char c; - int open = 0; - - while ((c = *p++) != '\0') - switch (c) - { - case '?': - case '*': - return 1; - - case '[': /* Only accept an open brace if there is a close */ - open++; /* brace to match it. Bracket expressions must be */ - continue; /* complete, according to Posix.2 */ - case ']': - if (open) - return 1; - continue; - - case '\\': - if (*p++ == '\0') - return 0; - } - - return 0; -} - - -/* Match the pattern PATTERN against the string TEXT; - return 1 if it matches, 0 otherwise. - - A match means the entire string TEXT is used up in matching. - - In the pattern string, `*' matches any sequence of characters, - `?' matches any character, [SET] matches any character in the specified set, - [!SET] matches any character not in the specified set. - - A set is composed of characters or ranges; a range looks like - character hyphen character (as in 0-9 or A-Z). - [0-9a-zA-Z_] is the set of characters allowed in C identifiers. - Any other character in the pattern must be matched exactly. - - To suppress the special syntactic significance of any of `[]*?!-\', - and match the character exactly, precede it with a `\'. - - If DOT_SPECIAL is nonzero, - `*' and `?' do not match `.' at the beginning of TEXT. */ - -int -glob_match (char *pattern, char *text, int dot_special) -{ - char *p = pattern, *t = text; - char c; - - while ((c = *p++) != '\0') - switch (c) - { - case '?': - if (*t == '\0' || (dot_special && t == text && *t == '.')) - return 0; - else - ++t; - break; - - case '\\': - if (*p++ != *t++) - return 0; - break; - - case '*': - if (dot_special && t == text && *t == '.') - return 0; - return glob_match_after_star (p, t); - - case '[': - { - char c1 = *t++; - int invert; - char *cp1 = p; - - if (c1 == '\0') - return 0; - - invert = (*p == '!'); - - if (invert) - p++; - - c = *p++; - while (1) - { - char cstart = c, cend = c; - - if (c == '\\') - { - cstart = *p++; - cend = cstart; - } - - if (cstart == '\0') - { - /* Missing ']'. */ - if (c1 != '[') - return 0; - /* matched a single bracket */ - p = cp1; - goto breakbracket; - } - - c = *p++; - - if (c == '-') - { - cend = *p++; - if (cend == '\\') - cend = *p++; - if (cend == '\0') - return 0; - c = *p++; - } - if ( collate_range_cmp (c1, cstart) >= 0 - && collate_range_cmp (c1, cend) <= 0 - ) - goto match; - if (c == ']') - break; - } - if (!invert) - return 0; - break; - - match: - /* Skip the rest of the [...] construct that already matched. */ - while (c != ']') - { - if (c == '\0') - return 0; - c = *p++; - if (c == '\0') - return 0; - if (c == '\\') - p++; - } - if (invert) - return 0; - breakbracket: - break; - } - - default: - if (c != *t++) - return 0; - } - - return *t == '\0'; -} - -/* Like glob_match, but match PATTERN against any final segment of TEXT. */ - -static int -glob_match_after_star (char *pattern, char *text) -{ - char *p = pattern, *t = text; - char c, c1; - - while ((c = *p++) == '?' || c == '*') - if (c == '?' && *t++ == '\0') - return 0; - - if (c == '\0') - return 1; - - if (c == '\\') - c1 = *p; - else - c1 = c; - - --p; - while (1) - { - if ((c == '[' || *t == c1) && glob_match (p, t, 0)) - return 1; - if (*t++ == '\0') - return 0; - } -} - -/* Return a vector of names of files in directory DIR - whose names match glob pattern PAT. - The names are not in any particular order. - Wildcards at the beginning of PAT do not match an initial period - if noglob_dot_filenames is nonzero. - - The vector is terminated by an element that is a null pointer. - - To free the space allocated, first free the vector's elements, - then free the vector. - - Return NULL if cannot get enough memory to hold the pointer - and the names. - - Return -1 if cannot access directory DIR. - Look in errno for more information. */ - -char ** -glob_vector (char *pat, const char *dir) -{ - struct globval - { - struct globval *next; - char *name; - }; - - DIR *d; - struct direct *dp; - struct globval *lastlink; - struct globval *nextlink; - char *nextname; - unsigned int count; - int lose; - char **name_vector; - unsigned int i; - - d = opendir (dir); - if (d == NULL) - return (char **) -1; - - lastlink = NULL; - count = 0; - lose = 0; - - /* Scan the directory, finding all names that match. - For each name that matches, allocate a struct globval - on the stack and store the name in it. - Chain those structs together; lastlink is the front of the chain. */ - while (1) - { -#if defined (SHELL) - /* Make globbing interruptible in the bash shell. */ - extern int interrupt_state; - - if (interrupt_state) - { - closedir (d); - lose = 1; - goto lost; - } -#endif /* SHELL */ - - dp = readdir (d); - if (dp == NULL) - break; - if (REAL_DIR_ENTRY (dp) - && glob_match (pat, dp->d_name, noglob_dot_filenames)) - { - nextlink = (struct globval *) alloca (sizeof (struct globval)); - nextlink->next = lastlink; - i = D_NAMLEN (dp) + 1; - nextname = (char *) malloc (i); - if (nextname == NULL) - { - lose = 1; - break; - } - lastlink = nextlink; - nextlink->name = nextname; - bcopy (dp->d_name, nextname, i); - count++; - } - } - closedir (d); - - if (!lose) - { - name_vector = (char **) malloc ((count + 1) * sizeof (char *)); - lose |= name_vector == NULL; - } - - /* Have we run out of memory? */ -#ifdef SHELL - lost: -#endif - if (lose) - { - /* Here free the strings we have got. */ - while (lastlink) - { - free (lastlink->name); - lastlink = lastlink->next; - } - return NULL; - } - - /* Copy the name pointers from the linked list into the vector. */ - for (i = 0; i < count; ++i) - { - name_vector[i] = lastlink->name; - lastlink = lastlink->next; - } - - name_vector[count] = NULL; - return name_vector; -} - -/* Return a new array, replacing ARRAY, which is the concatenation - of each string in ARRAY to DIR. - Return NULL if out of memory. */ - -static char ** -glob_dir_to_array (char *dir, char **array) -{ - unsigned int i, l; - int add_slash = 0; - char **result; - - l = strlen (dir); - if (l == 0) - return array; - - if (dir[l - 1] != '/') - add_slash++; - - for (i = 0; array[i] != NULL; i++) - ; - - result = (char **) malloc ((i + 1) * sizeof (char *)); - if (result == NULL) - return NULL; - - for (i = 0; array[i] != NULL; i++) - { - result[i] = (char *) malloc (1 + l + add_slash + strlen (array[i])); - if (result[i] == NULL) - return NULL; - strcpy (result[i], dir); - if (add_slash) - result[i][l] = '/'; - strcpy (result[i] + l + add_slash, array[i]); - } - result[i] = NULL; - - /* Free the input array. */ - for (i = 0; array[i] != NULL; i++) - free (array[i]); - free ((char *) array); - return result; -} - -/* Do globbing on PATHNAME. Return an array of pathnames that match, - marking the end of the array with a null-pointer as an element. - If no pathnames match, then the array is empty (first element is null). - If there isn't enough memory, then return NULL. - If a file system error occurs, return -1; `errno' has the error code. - - Wildcards at the beginning of PAT, or following a slash, - do not match an initial period if noglob_dot_filenames is nonzero. */ - -char ** -glob_filename (char *pathname) -{ - char **result; - unsigned int result_size; - char *directory_name, *filename; - unsigned int directory_len; - - result = (char **) malloc (sizeof (char *)); - result_size = 1; - if (result == NULL) - return NULL; - - result[0] = NULL; - - /* Find the filename. */ - filename = rindex (pathname, '/'); - if (filename == NULL) - { - filename = pathname; - directory_name = NULL; - directory_len = 0; - } - else - { - directory_len = (filename - pathname) + 1; - directory_name = (char *) alloca (directory_len + 1); - bcopy (pathname, directory_name, directory_len); - directory_name[directory_len] = '\0'; - ++filename; - } - - /* If directory_name contains globbing characters, then we - have to expand the previous levels. Just recurse. */ - if (glob_pattern_p (directory_name)) - { - char **directories; - unsigned int i; - - if (directory_name[directory_len - 1] == '/') - directory_name[directory_len - 1] = '\0'; - - directories = glob_filename (directory_name); - if (directories == NULL) - goto memory_error; - else if (directories == (char **) -1) - return (char **) -1; - else if (*directories == NULL) - { - free ((char *) directories); - return (char **) -1; - } - - /* We have successfully globbed the preceding directory name. - For each name in DIRECTORIES, call glob_vector on it and - FILENAME. Concatenate the results together. */ - for (i = 0; directories[i] != NULL; i++) - { - char **temp_results = glob_vector (filename, directories[i]); - if (temp_results == NULL) - goto memory_error; - else if (temp_results == (char **) -1) - /* This filename is probably not a directory. Ignore it. */ - ; - else - { - char **array = glob_dir_to_array (directories[i], temp_results); - unsigned int l; - - l = 0; - while (array[l] != NULL) - ++l; - - result = (char **) realloc (result, - (result_size + l) * sizeof (char *)); - if (result == NULL) - goto memory_error; - - for (l = 0; array[l] != NULL; ++l) - result[result_size++ - 1] = array[l]; - result[result_size - 1] = NULL; - free ((char *) array); - } - } - /* Free the directories. */ - for (i = 0; directories[i] != NULL; i++) - free (directories[i]); - free ((char *) directories); - - return result; - } - - /* If there is only a directory name, return it. */ - if (*filename == '\0') - { - result = (char **) realloc ((char *) result, 2 * sizeof (char *)); - if (result != NULL) - { - result[0] = (char *) malloc (directory_len + 1); - if (result[0] == NULL) - { - goto memory_error; - } - bcopy (directory_name, result[0], directory_len + 1); - result[1] = NULL; - } - return result; - } - else - { - /* Otherwise, just return what glob_vector - returns appended to the directory name. */ - char **temp_results = glob_vector (filename, - (directory_len == 0 - ? "." : directory_name)); - - if (temp_results == NULL || temp_results == (char **) -1) - { - return temp_results; - } - - temp_results = glob_dir_to_array (directory_name, temp_results); - return temp_results; - } - - /* We get to memory error if the program has run out of memory, or - if this is the shell, and we have been interrupted. */ - memory_error: - if (result != NULL) - { - unsigned int i; - for (i = 0; result[i] != NULL; ++i) - free (result[i]); - free ((char *) result); - } -#if defined (SHELL) - { - extern int interrupt_state; - - if (interrupt_state) - throw_to_top_level (); - } -#endif /* SHELL */ - return NULL; -} - -#ifdef TEST - -int -main (int argc, char **argv) -{ - char **value; - int i, optind; - - for (optind = 1; optind < argc; optind++) - { - value = glob_filename (argv[optind]); - if (value == NULL) - puts ("virtual memory exhausted"); - else if (value == (char **) -1) - perror (argv[optind]); - else - for (i = 0; value[i] != NULL; i++) - puts (value[i]); - } - exit (0); -} - -#endif /* TEST */ diff --git a/gnu/usr.bin/man/man/man.1 b/gnu/usr.bin/man/man/man.1 deleted file mode 100644 index 5537031e8e..0000000000 --- a/gnu/usr.bin/man/man/man.1 +++ /dev/null @@ -1,277 +0,0 @@ -.\" Man page for man -.\" -.\" Copyright (c) 1990, 1991, John W. Eaton. -.\" -.\" You may distribute under the terms of the GNU General Public -.\" License as specified in the README file that comes with the man 1.0 -.\" distribution. -.\" -.\" John W. Eaton -.\" jwe@che.utexas.edu -.\" Department of Chemical Engineering -.\" The University of Texas at Austin -.\" Austin, Texas 78712 -.\" -.\" $FreeBSD: src/gnu/usr.bin/man/man/man.man,v 1.10.2.8 2002/06/25 00:02:55 eric Exp $ -.\" -.Dd April 1, 2018 -.Dt MAN 1 -.Os -.Sh NAME -.Nm man -.Nd format and display the on-line manual pages -.Sh SYNOPSIS -.Nm -.Op Fl 1adfhkotw -.Op Fl m Ar machine -.Op Fl p Ar string -.Op Fl M Ar path -.Op Fl P Ar pager -.Op Fl S Ar list -.Op Ar section -.Ar name ... -.Sh DESCRIPTION -.Nm Man -formats and displays the on-line manual pages. -This version knows about the -.Ev MANPATH -and -.Ev PAGER -environment variables, so you can have -your own set(s) of personal man pages and choose whatever program you -like to display the formatted pages. -If -.Ar section -is specified, -.Nm -only looks in that section of the manual. -You may also specify the order to search the sections for entries and -which preprocessors to run on the source files via command line options -or environment variables. -If enabled by the system administrator, formatted man pages will also -be compressed with the -.Nm /usr/bin/gzip -c -command to save space. -If -.Ar name -contains a -.Sq / , -.Nm -treats it as a file name. -.Pp -The options are as follows: -.Bl -tag -width Fl -.It Fl 1 -By default, -.Nm -will display all the manual pages -that match -.Ar name , -not just the first. -Using this option forces -.Nm -to exit after displaying the first manual page it -finds. -.It Fl M Ar path -Specify an alternate manpath. -By default, -.Nm -uses -.Xr manpath 1 -(which is built into the -.Nm -binary) -to determine the path to search. -This option overrides the -.Ev MANPATH -environment variable. -.It Fl P Ar pager -Specify which pager to use. -By default, -.Nm -uses -.Nm more -s . -This option overrides the -.Ev PAGER -environment variable. -.It Fl S Ar list -List is a colon separated list of manual sections to search. -The default is -.Dq 1:8:2:3:4:5:6:7:9 . -This option overrides the -.Ev MANSECT -environment variable. -.It Fl a -Display all the manual pages -that match -.Ar name , -not just the first. -This is the default behavior. -.It Fl d -Don't actually display the man pages, but do print gobs of debugging -information. -.It Fl f -Equivalent to -.Nm whatis . -.It Fl h -Print a help message and exit. -.It Fl k -Equivalent to -.Nm apropos . -.It Fl m Ar machine -As some manual pages are intended only for specific architectures, -.Nm -searches any subdirectories, -with the same name as the current architecture, -in every directory which it searches. -Machine specific areas are checked before general areas. -The current machine type may be overridden using this option -or by setting the environment variable -.Ev MACHINE -to the name of a specific architecture. -This option overrides the -.Ev MACHINE -environment variable. -.It Fl o -Look for original, non-localized manpages only. -.Pp -By default, -.Nm -searches for a localized manpage -in a set of locale subdirectories of each -.Xr manpath 1 -component. -.Pp -Locale name is taken from the first of three environment variables -with a nonempty value: -.Ev LC_ALL , LC_CTYPE , -or -.Ev LANG , -in the specified order. -.Pp -If the value could not be determined, or is not a valid locale name, -then only non-localized manpage will be looked up. -.Pp -Otherwise, -.Nm -will search in the following subdirectories, in the order of precedence: -.Pp -.Bl -item -offset indent -compact -.Sm off -.It -.Pa _ . -.It -.Pa . -.It -.Pa en . -.Sm on -.El -.Pp -For example, for -.Dq de_DE.ISO8859-1 -locale, -.Nm -will search in the following subdirectories of the -.Pa /usr/share/man -manpath component: -.Pp -.Bl -item -offset indent -compact -.It -.Pa /usr/share/man/de_DE.ISO8859-1 -.It -.Pa /usr/share/man/de.ISO8859-1 -.It -.Pa /usr/share/man/en.ISO8859-1 -.El -.Pp -Finally, -if the search of localized manpage fails, -it will be looked up in the default -.Pa /usr/share/man -directory. -.It Fl p Ar string -Specify the sequence of preprocessors to run before nroff or troff. -Not all installations will have a full set of preprocessors. -Some of the preprocessors and the letters used to designate them are: -eqn (e), grap (g), pic (p), tbl (t), vgrind (v), refer (r). -This option overrides the -.Ev MANROFFSEQ -environment variable. -.It Fl t -Use -.Nm /usr/bin/groff -S -man -to format the manual page, passing the output to stdout. -The output from -.Nm /usr/bin/groff -S -man -may need to be passed through some filter or another before being -printed. -.It Fl w -Don't actually display the man pages, but do print the location(s) of -the files that would be formatted or displayed. -.El -.Sh ENVIRONMENT -.Bl -tag -width MANROFFSEQ -.It Ev LC_ALL , LC_CTYPE , LANG -These variables specify the preferred language for manual pages. -(See the -.Fl o -option above.) -.It Ev MACHINE -If -.Ev MACHINE -is set, its value is used to override the current machine type -when searching machine specific subdirectories. -.It Ev MANPATH -If -.Ev MANPATH -is set, its value is used as the path to search for manual pages. -.It Ev MANROFFSEQ -If -.Ev MANROFFSEQ -is set, its value is used to determine the set of preprocessors run -before running -.Xr nroff 1 -or -.Xr troff 1 . -By default, pages are passed through the table preprocessor before -.Xr nroff 1 . -.It Ev MANSECT -If -.Ev MANSECT -is set, its value is used to determine which manual sections to search. -.It Ev PAGER -If -.Ev PAGER -is set, its value is used as the name of the program to use to display -the man page. -By default, -.Nm more -s -is used. -.El -.Sh EXAMPLES -.Pp -Normally, to look at the relevant manpage information for getopt, -one would use: -.Pp -.Dl man getopt -.Pp -However, when referring to a specific section of the manual, -such as -.Xr getopt 3 , -one would use: -.Pp -.Dl man 3 getopt -.Sh SEE ALSO -.Xr apropos 1 , -.Xr groff 1 , -.Xr manpath 1 , -.Xr more 1 , -.Xr whatis 1 , -.Xr man 7 , -.Xr mdoc 7 -.Sh BUGS -The -.Fl t -option only works if the -.Xr troff 1 Ns -like -program is installed. diff --git a/gnu/usr.bin/man/man/man.c b/gnu/usr.bin/man/man/man.c deleted file mode 100644 index c2316ec088..0000000000 --- a/gnu/usr.bin/man/man/man.c +++ /dev/null @@ -1,1594 +0,0 @@ -/* - * man.c - * - * Copyright (c) 1990, 1991, John W. Eaton. - * - * You may distribute under the terms of the GNU General Public - * License as specified in the file COPYING that comes with the man - * distribution. - * - * John W. Eaton - * jwe@che.utexas.edu - * Department of Chemical Engineering - * The University of Texas at Austin - * Austin, Texas 78712 - * - * $FreeBSD: src/gnu/usr.bin/man/man/man.c,v 1.37.2.10 2003/02/14 15:38:51 ru Exp $ - */ - -#define MAN_MAIN - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "config.h" -#include "gripes.h" -#include "util.h" -#include "version.h" - -extern char **glob_filename (char *); -extern char *manpath (int); - -char *is_section (char *); -char **get_section_list (void); -void man_getopt (int, char **); -void do_apropos (char *); -void do_whatis (char *); -int man (char *); -void usage (void); -char **add_dir_to_mpath_list (char **, char *); -char *convert_name (char *, int); -char **glob_for_file (char *, char *, char *, char *, int); -char **make_name (char *, char *, char *, char *, int); -const char *get_expander (char *); -int display_cat_file (char *); -char *ultimate_source (char *, char *); -void add_directive (int *, const char *, char *, char *, int); -int parse_roff_directive (const char *, char *, char *, int); -char *make_roff_command (char *); -void cleantmp(int); -void set_sigs(void); -void restore_sigs(void); -int make_cat_file (char *, char *, char *, int); -int format_and_display (char *, char *, char *); -int try_section (char *, char *, char *, char *, int); - -char *prognam; -static char *pager; -static const char *machine; -static char *manp; -static char *manpathlist[MAXDIRS]; -static char *shortsec; -static char *longsec; -static char *colon_sep_section_list; -static char **section_list; -static char *roff_directive; -static int apropos; -static int whatis; -static int findall = 1; -static int print_where; - -static char *locale, *locale_codeset; -static const char *locale_nroff, *locale_opts; -static char locale_terr[3], locale_lang[3]; -static char *man_locale; -static int use_man_locale; -static int use_original; -struct ltable { - const char *lcode; - const char *nroff; -}; -static struct ltable ltable[] = { - {"KOI8-R", "koi8-r"}, - {"ISO8859-1", "latin1"}, - {"ISO8859-15", "latin1"}, - {NULL, NULL} -}; - -static int troff = 0; - -int debug; - -static char args[] = "1M:P:S:adfhkm:op:tw?"; - -uid_t ruid; -uid_t euid; -gid_t rgid; -gid_t egid; - -int -main (int argc, char **argv) -{ - int status = 0; - char *nextarg; - char *tmp; - - prognam = mkprogname (argv[0]); - longsec = NULL; - - unsetenv("IFS"); - (void) setlocale(LC_ALL, ""); - man_getopt (argc, argv); - - if (optind == argc) - gripe_no_name ((char *)NULL); - - section_list = get_section_list (); - - if (optind == argc - 1) - { - tmp = is_section (argv[optind]); - - if (tmp != NULL) - gripe_no_name (tmp); - } - - ruid = getuid(); - rgid = getgid(); - euid = geteuid(); - egid = getegid(); - setreuid(-1, ruid); - setregid(-1, rgid); - - while (optind < argc) - { - nextarg = argv[optind++]; - - /* - * See if this argument is a valid section name. If not, - * is_section returns NULL. - */ - tmp = is_section (nextarg); - - if (tmp != NULL) - { - shortsec = tmp; - - if (debug) - fprintf (stderr, "\nsection: %s\n", shortsec); - - continue; - } - - if (apropos) { - do_apropos (nextarg); - status = (status ? 0 : 1); /* reverts status, see below */ - } - else if (whatis) { - do_whatis (nextarg); - status = (status ? 0 : 1); /* reverts status, see below */ - } - else - { - status = man (nextarg); - - if (status == 0) - gripe_not_found (nextarg, longsec); - } - } - return (status==0); /* status==1 --> exit(0), - status==0 --> exit(1) */ -} - -void -usage (void) -{ - static char usage_string[1024] = "%s, version %s\n\n"; - - static char s1[] = - "usage: %s [-adfhkotw] [section] [-M path] [-P pager] [-S list]\n\ - [-m machine] [-p string] name ...\n\n"; - -static char s2[] = " a : find all matching entries\n\ - d : print gobs of debugging information\n\ - f : same as whatis(1)\n\ - h : print this help message\n\ - k : same as apropos(1)\n"; - - static char s3[] = " o : use original, non-localized manpages\n"; - - static char s4[] = " t : use troff to format pages for printing\n"; - - static char s5[] = " w : print location of man page(s) that would be displayed\n\n\ - M path : set search path for manual pages to `path'\n\ - P pager : use program `pager' to display pages\n\ - S list : colon separated section list\n\ - m machine : search for alternate architecture man pages\n"; - - static char s6[] = " p string : string tells which preprocessors to run\n\ - e - [n]eqn(1) p - pic(1) t - tbl(1)\n\ - g - grap(1) r - refer(1) v - vgrind(1)\n"; - - strcat (usage_string, s1); - strcat (usage_string, s2); - strcat (usage_string, s3); - - strcat (usage_string, s4); - - strcat (usage_string, s5); - - strcat (usage_string, s6); - - fprintf (stderr, usage_string, prognam, version, prognam); - exit(1); -} - -char ** -add_dir_to_mpath_list (char **mp, char *p) -{ - int status; - - status = is_directory (p); - - if (status < 0 && debug) - { - fprintf (stderr, "Warning: couldn't stat file %s!\n", p); - } - else if (status == 0 && debug) - { - fprintf (stderr, "Warning: %s isn't a directory!\n", p); - } - else if (status == 1) - { - if (debug) - fprintf (stderr, "adding %s to manpathlist\n", p); - - *mp++ = strdup (p); - } - return mp; -} - -/* - * Get options from the command line and user environment. - */ -void -man_getopt (int argc, char **argv) -{ - int c; - char *p; - char *end; - char **mp; - - while ((c = getopt (argc, argv, args)) != -1) - { - switch (c) - { - case '1': - findall = 0; - break; - case 'M': - manp = strdup (optarg); - break; - case 'P': - pager = strdup (optarg); - if (setenv("PAGER", pager, 1) != 0) - (void)fprintf(stderr, "setenv PAGER=%s\n", pager); - break; - case 'S': - colon_sep_section_list = strdup (optarg); - break; - case 'a': - break; /* default, do nothing */ - case 'd': - debug++; - break; - case 'f': - if (troff) - gripe_incompatible ("-f and -t"); - if (apropos) - gripe_incompatible ("-f and -k"); - if (print_where) - gripe_incompatible ("-f and -w"); - whatis++; - break; - case 'k': - if (troff) - gripe_incompatible ("-k and -t"); - if (whatis) - gripe_incompatible ("-k and -f"); - if (print_where) - gripe_incompatible ("-k and -w"); - apropos++; - break; - case 'm': - machine = optarg; - break; - case 'o': - use_original++; - break; - case 'p': - roff_directive = strdup (optarg); - break; - case 't': - if (apropos) - gripe_incompatible ("-t and -k"); - if (whatis) - gripe_incompatible ("-t and -f"); - if (print_where) - gripe_incompatible ("-t and -w"); - troff++; - break; - case 'w': - if (apropos) - gripe_incompatible ("-w and -k"); - if (whatis) - gripe_incompatible ("-w and -f"); - if (troff) - gripe_incompatible ("-w and -t"); - print_where++; - break; - case 'h': - case '?': - default: - usage(); - break; - } - } - - /* "" intentionally used to catch error */ - if ((locale = setlocale(LC_CTYPE, "")) != NULL) - locale_codeset = nl_langinfo(CODESET); - if (!use_original && locale != NULL && *locale_codeset != '\0' && - strcmp(locale_codeset, "US-ASCII") != 0 - ) { - char *tmp, *short_locale; - struct ltable *pltable; - size_t locale_len; - - *locale_lang = '\0'; - *locale_terr = '\0'; - - if ((short_locale = strdup(locale)) == NULL) { - perror ("ctype locale strdup"); - exit (1); - } - if ((tmp = strchr(short_locale, '.')) != NULL) - *tmp = '\0'; - - locale_len = strlen(short_locale); - tmp = strchr(short_locale, '_'); - if (locale_len == 5 && tmp == short_locale + 2) { - /* assume position 3 and 4 are not "_"; don't check */ - strncpy(locale_terr, short_locale + 3, 2); - locale_terr[2] = '\0'; - strncpy(locale_lang, short_locale, 2); - locale_lang[2] = '\0'; - } else if (locale_len == 10 && tmp == short_locale + 2 && - short_locale[7] == '_') { - /* assume positions 3-6 and 8-9 are not "_" */ - strncpy(locale_terr, short_locale + 8, 2); - locale_terr[2] = '\0'; - strncpy(locale_lang, short_locale, 2); - locale_lang[2] = '\0'; - } else { - errno = EINVAL; - perror ("ctype locale format"); - locale = NULL; - } - - free(short_locale); - - if (locale != NULL) { - for (pltable = ltable; pltable->lcode != NULL; pltable++) { - if (strcmp(pltable->lcode, locale_codeset) == 0) { - locale_nroff = pltable->nroff; - break; - } - } - asprintf(&man_locale, "%s.%s", locale_lang, locale_codeset); - } - } else { - if (locale == NULL) { - errno = EINVAL; - perror ("ctype locale"); - } else { - locale = NULL; - if (*locale_codeset == '\0') { - errno = EINVAL; - perror ("ctype codeset"); - } - } - } - - if (pager == NULL || *pager == '\0') - if ((pager = getenv ("PAGER")) == NULL || *pager == '\0') - pager = strdup (PAGER); - - if (debug) - fprintf (stderr, "\nusing %s as pager\n", pager); - - if (machine == NULL && (machine = getenv ("MACHINE")) == NULL) - machine = MACHINE; - - if (debug) - fprintf (stderr, "\nusing %s architecture\n", machine); - - if (manp == NULL) - { - if ((manp = manpath (0)) == NULL) - gripe_manpath (); - - if (debug) - fprintf (stderr, - "\nsearch path for pages determined by manpath is\n%s\n\n", - manp); - } - - /* - * Expand the manpath into a list for easier handling. - */ - mp = manpathlist; - for (p = manp; ; p = end+1) - { - if (mp == manpathlist + MAXDIRS - 1) { - fprintf (stderr, "Warning: too many directories in manpath, truncated!\n"); - break; - } - if ((end = strchr (p, ':')) != NULL) - *end = '\0'; - - mp = add_dir_to_mpath_list (mp, p); - if (end == NULL) - break; - - *end = ':'; - } - *mp = NULL; -} - -/* - * Check to see if the argument is a valid section number. If the - * first character of name is a numeral, or the name matches one of - * the sections listed in section_list, we'll assume that it's a section. - * The list of sections in config.h simply allows us to specify oddly - * named directories like .../man3f. Yuk. - */ -char * -is_section (char *name) -{ - char **vs; - char *temp, *end, *loc; - char **plist; - int x; - - for (vs = section_list; *vs != NULL; vs++) - if ((strcmp (*vs, name) == 0) - || (isdigit ((unsigned char)name[0]) && strlen(name) == 1)) - return (longsec = strdup (name)); - - plist = manpathlist; - if (isdigit ((unsigned char)name[0])) - { - while (*plist != NULL) - { - asprintf(&temp, "%s/man%c/*", *plist, name[0]); - plist++; - - x = 0; - vs = glob_filename (temp); - if (vs == (char **)-1) - { - free (temp); - return NULL; - } - for ( ; *vs != NULL; vs++) - { - end = strrchr (*vs, '/'); - if ((loc = strstr (end, name)) != NULL && loc - end > 2 - && *(loc-1) == '.' - && (*(loc+strlen(name)) == '\0' || *(loc+strlen(name)) == '.')) - { - x = 1; - break; - } - } - free (temp); - if (x == 1) - { - asprintf(&temp, "%c", name[0]); - longsec = strdup (name); - return (temp); - } - } - } - return NULL; -} - -/* - * Handle the apropos option. Cheat by using another program. - */ -void -do_apropos (char *name) -{ - int len; - char *command; - - len = strlen (APROPOS) + strlen (name) + 4; - - if ((command = (char *) malloc(len)) == NULL) - gripe_alloc (len, "command"); - - sprintf (command, "%s \"%s\"", APROPOS, name); - - (void) do_system_command (command); - - free (command); -} - -/* - * Handle the whatis option. Cheat by using another program. - */ -void -do_whatis (char *name) -{ - int len; - char *command; - - len = strlen (WHATIS) + strlen (name) + 4; - - if ((command = (char *) malloc(len)) == NULL) - gripe_alloc (len, "command"); - - sprintf (command, "%s \"%s\"", WHATIS, name); - - (void) do_system_command (command); - - free (command); -} - -/* - * Change a name of the form ...man/man1/name.1 to ...man/cat1/name.1 - * or a name of the form ...man/cat1/name.1 to ...man/man1/name.1 - */ -char * -convert_name (char *name, int to_cat) -{ - char *to_name; - char *t1; - char *t2 = NULL; - - if (to_cat) - { - int olen = strlen(name); - int cextlen = strlen(COMPRESS_EXT); - int len = olen + cextlen; - - to_name = malloc (len+1); - if (to_name == NULL) - gripe_alloc (len+1, "to_name"); - strcpy (to_name, name); - olen -= cextlen; - /* Avoid tacking it on twice */ - if (olen >= 1 && strcmp(name + olen, COMPRESS_EXT) != 0) - strcat (to_name, COMPRESS_EXT); - } - else - to_name = strdup (name); - - t1 = strrchr (to_name, '/'); - if (t1 != NULL) - { - *t1 = '\0'; - t2 = strrchr (to_name, '/'); - *t1 = '/'; - - /* Skip architecture part (if present). */ - if (t2 != NULL && (t1 - t2 < 5 || *(t2 + 1) != 'm' || *(t2 + 3) != 'n')) - { - t1 = t2; - *t1 = '\0'; - t2 = strrchr (to_name, '/'); - *t1 = '/'; - } - } - - if (t2 == NULL) - gripe_converting_name (name, to_cat); - - if (to_cat) - { - *(++t2) = 'c'; - *(t2+2) = 't'; - } - else - { - *(++t2) = 'm'; - *(t2+2) = 'n'; - } - - if (debug) - fprintf (stderr, "to_name in convert_name () is: %s\n", to_name); - - return to_name; -} - -/* - * Try to find the man page corresponding to the given name. The - * reason we do this with globbing is because some systems have man - * page directories named man3 which contain files with names like - * XtPopup.3Xt. Rather than requiring that this program know about - * all those possible names, we simply try to match things like - * .../man[sect]/name[sect]*. This is *much* easier. - * - * Note that globbing is only done when the section is unspecified. - */ -char ** -glob_for_file (char *path, char *section, char *_longsec, char *name, int cat) -{ - char pathname[FILENAME_MAX]; - char **gf; - - if (_longsec == NULL) - _longsec = section; - - if (cat) - snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.%s*", path, section, - name, _longsec); - else - snprintf (pathname, sizeof(pathname), "%s/man%s/%s.%s*", path, section, - name, _longsec); - - if (debug) - fprintf (stderr, "globbing %s\n", pathname); - - gf = glob_filename (pathname); - - if ((gf == (char **) -1 || *gf == NULL) && isdigit ((unsigned char)*section) - && strlen (_longsec) == 1) - { - if (cat) - snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.%c*", path, section, name, *section); - else - snprintf (pathname, sizeof(pathname), "%s/man%s/%s.%c*", path, section, name, *section); - - gf = glob_filename (pathname); - } - if ((gf == (char **) -1 || *gf == NULL) && isdigit ((unsigned char)*section) - && strlen (_longsec) == 1) - { - if (cat) - snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.0*", path, section, name); - else - snprintf (pathname, sizeof(pathname), "%s/man%s/%s.0*", path, section, name); - if (debug) - fprintf (stderr, "globbing %s\n", pathname); - gf = glob_filename (pathname); - } - return gf; -} - -/* - * Return an un-globbed name in the same form as if we were doing - * globbing. - */ -char ** -make_name (char *path, char *section, char *_longsec, char *name, int cat) -{ - int i = 0; - static char *names[3]; - char buf[FILENAME_MAX]; - - if (cat) - snprintf (buf, sizeof(buf), "%s/cat%s/%s.%s", path, section, name, _longsec); - else - snprintf (buf, sizeof(buf), "%s/man%s/%s.%s", path, section, name, _longsec); - - if (access (buf, R_OK) == 0) - names[i++] = strdup (buf); - - /* - * If we're given a section that looks like `3f', we may want to try - * file names like .../man3/foo.3f as well. This seems a bit - * kludgey to me, but what the hey... - */ - if (section[1] != '\0') - { - if (cat) - snprintf (buf, sizeof(buf), "%s/cat%c/%s.%s", path, section[0], name, section); - else - snprintf (buf, sizeof(buf), "%s/man%c/%s.%s", path, section[0], name, section); - - if (access (buf, R_OK) == 0) - names[i++] = strdup (buf); - } - - names[i] = NULL; - - return &names[0]; -} - -const char * -get_expander (char *file) -{ - char *end = file + (strlen (file) - 1); - - while (end > file && end[-1] != '.') - --end; - if (end == file) - return NULL; -#ifdef FCAT - if (*end == 'F') - return FCAT; -#endif /* FCAT */ -#ifdef YCAT - if (*end == 'Y') - return YCAT; -#endif /* YCAT */ -#ifdef ZCAT - if (*end == 'Z' || !strcmp(end, "gz")) - return ZCAT; -#endif /* ZCAT */ - return NULL; -} - -/* - * Simply display the preformatted page. - */ -int -display_cat_file (char *file) -{ - int found; - char command[FILENAME_MAX]; - - found = 0; - - if (access (file, R_OK) == 0) - { - const char *expander = get_expander (file); - - if (expander != NULL) - snprintf (command, sizeof(command), "%s %s | %s", expander, file, pager); - else - snprintf (command, sizeof(command), "%s %s", pager, file); - - found = do_system_command (command); - } - return found; -} - -/* - * Try to find the ultimate source file. If the first line of the - * current file is not of the form - * - * .so man3/printf.3s - * - * the input file name is returned. - */ -char * -ultimate_source (char *name, char *path) -{ - static char buf[BUFSIZ]; - static char ult[FILENAME_MAX]; - - FILE *fp; - char *beg; - char *end; - - strncpy (ult, name, sizeof(ult)-1); - ult[sizeof(ult)-1] = '\0'; - strncpy (buf, name, sizeof(buf)-1); - ult[sizeof(buf)-1] = '\0'; - - next: - - if ((fp = fopen (ult, "r")) == NULL) - return ult; - - end = fgets (buf, BUFSIZ, fp); - fclose(fp); - - if (!end || strlen (buf) < 5) - return ult; - - beg = buf; - if (*beg++ == '.' && *beg++ == 's' && *beg++ == 'o') - { - while ((*beg == ' ' || *beg == '\t') && *beg != '\0') - beg++; - - end = beg; - while (*end != ' ' && *end != '\t' && *end != '\n' && *end != '\0') - end++; - - *end = '\0'; - - snprintf(ult, sizeof(ult), "%s/%s", path, beg); - snprintf(buf, sizeof(buf), "%s", ult); - - goto next; - } - - if (debug) - fprintf (stderr, "found ultimate source file %s\n", ult); - - return ult; -} - -void -add_directive (int *first, const char *d, char *file, char *buf, int bufsize) -{ - if (strcmp (d, "") != 0) - { - if (*first) - { - *first = 0; - snprintf(buf, bufsize, "%s %s", d, file); - } - else - { - strncat (buf, " | ", bufsize-strlen(buf)-1); - strncat (buf, d, bufsize-strlen(buf)-1); - } - } -} - -int -parse_roff_directive (const char *cp, char *file, char *buf, int bufsize) -{ - char c; - const char *exp; - int first = 1; - int preproc_found = 0; - int use_col = 0; - - if ((exp = get_expander(file)) != NULL) - add_directive (&first, exp, file, buf, bufsize); - - while ((c = *cp++) != '\0') - { - switch (c) - { - case 'e': - - if (debug) - fprintf (stderr, "found eqn(1) directive\n"); - - preproc_found++; - if (troff) - add_directive (&first, EQN, file, buf, bufsize); - else { - char lbuf[FILENAME_MAX]; - - snprintf(lbuf, sizeof(lbuf), "%s -T%s", NEQN, - locale_opts == NULL ? "ascii" : locale_opts); - add_directive (&first, lbuf, file, buf, bufsize); - } - - break; - - case 'g': - - if (debug) - fprintf (stderr, "found grap(1) directive\n"); - - preproc_found++; - add_directive (&first, GRAP, file, buf, bufsize); - - break; - - case 'p': - - if (debug) - fprintf (stderr, "found pic(1) directive\n"); - - preproc_found++; - add_directive (&first, PIC, file, buf, bufsize); - - break; - - case 't': - - if (debug) - fprintf (stderr, "found tbl(1) directive\n"); - - preproc_found++; - use_col++; - add_directive (&first, TBL, file, buf, bufsize); - break; - - case 'v': - - if (debug) - fprintf (stderr, "found vgrind(1) directive\n"); - - add_directive (&first, VGRIND, file, buf, bufsize); - break; - - case 'r': - - if (debug) - fprintf (stderr, "found refer(1) directive\n"); - - add_directive (&first, REFER, file, buf, bufsize); - break; - - case ' ': - case '\t': - case '\n': - - goto done; - - default: - - return -1; - } - } - - done: - - if (troff) - add_directive (&first, TROFF, file, buf, bufsize); - else - { - char lbuf[FILENAME_MAX]; - - snprintf(lbuf, sizeof(lbuf), "%s -T%s%s%s", NROFF, - locale_opts == NULL ? "ascii" : locale_opts, - use_man_locale ? " -dlocale=" : "", - use_man_locale ? man_locale : ""); - add_directive (&first, lbuf, file, buf, bufsize); - } - if (use_col && !troff) - add_directive (&first, COL, file, buf, bufsize); - - if (preproc_found) - return 0; - else - return 1; -} - -char * -make_roff_command (char *file) -{ - gzFile fp; - char line [BUFSIZ]; - static char buf [BUFSIZ]; - int status; - char *cp; - - if (roff_directive != NULL) - { - if (debug) - fprintf (stderr, "parsing directive from command line\n"); - - status = parse_roff_directive (roff_directive, file, buf, sizeof(buf)); - - if (status == 0) - return buf; - - if (status == -1) - gripe_roff_command_from_command_line (); - } - - if ((fp = gzopen (file, "r")) != NULL) - { - cp = line; - gzgets (fp, line, BUFSIZ); - gzclose(fp); - if (*cp++ == '\'' && *cp++ == '\\' && *cp++ == '"' && *cp++ == ' ') - { - if (debug) - fprintf (stderr, "parsing directive from file\n"); - - status = parse_roff_directive (cp, file, buf, sizeof(buf)); - - if (status == 0) - return buf; - - if (status == -1) - gripe_roff_command_from_file (file); - } - } - else - { - /* - * Is there really any point in continuing to look for - * preprocessor options if we can't even read the man page source? - */ - gripe_reading_man_file (file); - return NULL; - } - - if ((cp = getenv ("MANROFFSEQ")) != NULL) - { - if (debug) - fprintf (stderr, "parsing directive from environment\n"); - - status = parse_roff_directive (cp, file, buf, sizeof(buf)); - - if (status == 0) - return buf; - - if (status == -1) - gripe_roff_command_from_env (); - } - - if (debug) - fprintf (stderr, "using default preprocessor sequence\n"); - - status = parse_roff_directive ("t", file, buf, sizeof(buf)); - if (status >= 0) - return buf; - else /* can't happen */ - return NULL; -} - -sig_t ohup, oint, oquit, oterm; -static char temp[FILENAME_MAX]; - -void -cleantmp(int signo __unused) -{ - unlink(temp); - exit(1); -} - -void -set_sigs(void) -{ - ohup = signal(SIGHUP, cleantmp); - oint = signal(SIGINT, cleantmp); - oquit = signal(SIGQUIT, cleantmp); - oterm = signal(SIGTERM, cleantmp); -} - -void -restore_sigs(void) -{ - signal(SIGHUP, ohup); - signal(SIGINT, oint); - signal(SIGQUIT, oquit); - signal(SIGTERM, oterm); -} - -/* - * Try to format the man page and create a new formatted file. Return - * 1 for success and 0 for failure. - */ -int -make_cat_file (char *path, char *man_file, char *cat_file, int manid) -{ - int s, f; - FILE *fp, *pp; - char *roff_command; - char command[FILENAME_MAX]; - - roff_command = make_roff_command (man_file); - if (roff_command == NULL) - return 0; - - snprintf(temp, sizeof(temp), "%s.tmpXXXXXX", cat_file); - if ((f = mkstemp(temp)) >= 0 && (fp = fdopen(f, "w")) != NULL) - { - set_sigs(); - - if (fchmod (f, CATMODE) < 0) { - perror("fchmod"); - unlink(temp); - restore_sigs(); - fclose(fp); - return 0; - } else if (debug) - fprintf (stderr, "mode of %s is now %o\n", temp, CATMODE); - - snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path, - roff_command, COMPRESSOR); - fprintf (stderr, "Formatting page, please wait..."); - fflush(stderr); - - if (debug) - fprintf (stderr, "\ntrying command: %s\n", command); - else { - if (manid) { - setreuid(-1, ruid); - setregid(-1, rgid); - } - if ((pp = popen(command, "r")) == NULL) { - s = errno; - fprintf(stderr, "Failed.\n"); - errno = s; - perror("popen"); - if (manid) { - setreuid(-1, euid); - setregid(-1, egid); - } - unlink(temp); - restore_sigs(); - fclose(fp); - return 0; - } - if (manid) { - setreuid(-1, euid); - setregid(-1, egid); - } - - f = 0; - while ((s = getc(pp)) != EOF) { - putc(s, fp); f++; - } - - if (!f || ((s = pclose(pp)) == -1)) { - s = errno; - fprintf(stderr, "Failed.\n"); - errno = s; - perror("pclose"); - unlink(temp); - restore_sigs(); - fclose(fp); - return 0; - } - - if (s != 0) { - fprintf(stderr, "Failed.\n"); - gripe_system_command(s); - unlink(temp); - restore_sigs(); - fclose(fp); - return 0; - } - } - - if (debug) - unlink(temp); - else if (rename(temp, cat_file) == -1) { - s = errno; - fprintf(stderr, - "\nHmm! Can't seem to rename %s to %s, check permissions on man dir!\n", - temp, cat_file); - errno = s; - perror("rename"); - unlink(temp); - restore_sigs(); - fclose(fp); - return 0; - } - restore_sigs(); - - if (fclose(fp)) { - s = errno; - if (!debug) - unlink(cat_file); - fprintf(stderr, "Failed.\n"); - errno = s; - perror("fclose"); - return 0; - } - - if (debug) { - fprintf(stderr, "No output, debug mode.\n"); - return 0; - } - - fprintf(stderr, "Done.\n"); - - return 1; - } - else - { - if (f >= 0) { - s = errno; - unlink(temp); - errno = s; - } - if (debug) { - s = errno; - fprintf (stderr, "Couldn't open %s for writing.\n", temp); - errno = s; - } - if (f >= 0) { - perror("fdopen"); - close(f); - } - - return 0; - } -} - -/* - * Try to format the man page source and save it, then display it. If - * that's not possible, try to format the man page source and display - * it directly. - * - * Note that we've already been handed the name of the ultimate source - * file at this point. - */ -int -format_and_display (char *path, char *man_file, char *cat_file) -{ - int status; - int found; - char *roff_command; - char command[FILENAME_MAX]; - - found = 0; - - if (access (man_file, R_OK) != 0) - return 0; - - if (troff) - { - roff_command = make_roff_command (man_file); - if (roff_command == NULL) - return 0; - else - snprintf (command, sizeof(command), "(cd %s ; %s)", path, roff_command); - - found = do_system_command (command); - } - else - { - if (cat_file == NULL) - goto format_and_display; - - status = is_newer (man_file, cat_file); - if (debug) - fprintf (stderr, "status from is_newer() = %d\n", status); - - if (status == 1 || status == -2) - { - /* - * Cat file is out of date. Try to format and save it. - */ - if (print_where) - { - printf ("%s\n", man_file); - found++; - } - else - { - - setreuid(-1, euid); - setregid(-1, egid); - found = make_cat_file (path, man_file, cat_file, 1); - setreuid(-1, ruid); - setregid(-1, rgid); - - if (!found) - { - /* Try again as real user - see note below. - By running with - effective group (user) ID == real group (user) ID - except for the call above, I believe the problems - of reading private man pages is avoided. */ - found = make_cat_file (path, man_file, cat_file, 0); - } - if (found) - { - /* - * Creating the cat file worked. Now just display it. - */ - (void) display_cat_file (cat_file); - } - else - { - /* - * Couldn't create cat file. Just format it and - * display it through the pager. - */ -format_and_display: - roff_command = make_roff_command (man_file); - if (roff_command == NULL) - return 0; - else - snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path, - roff_command, pager); - - found = do_system_command (command); - } - } - } - else if (access (cat_file, R_OK) == 0) - { - /* - * Formatting not necessary. Cat file is newer than source - * file, or source file is not present but cat file is. - */ - if (print_where) - { - printf ("%s (source: %s)\n", cat_file, man_file); - found++; - } - else - { - found = display_cat_file (cat_file); - } - } - } - return found; -} - -/* - * See if the preformatted man page or the source exists in the given - * section. - */ -int -try_section (char *path, char *section, char *_longsec, char *name, int glob) -{ - int found = 0; - int to_cat; - int cat; - char **names; - char **np; - static int arch_search; - char buf[FILENAME_MAX]; - - if (!arch_search) - { - snprintf(buf, sizeof(buf), "%s/man%s/%s", path, section, machine); - if (is_directory (buf) == 1) - { - snprintf(buf, sizeof(buf), "%s/%s", machine, name); - arch_search++; - found = try_section (path, section, _longsec, buf, glob); - arch_search--; - if (found && !findall) /* only do this architecture... */ - return found; - } - } - - if (debug) - { - if (glob) - fprintf (stderr, "trying section %s with globbing\n", section); - else - fprintf (stderr, "trying section %s without globbing\n", section); - } - -#ifndef NROFF_MISSING - /* - * Look for man page source files. - */ - cat = 0; - if (glob) - names = glob_for_file (path, section, _longsec, name, cat); - else - names = make_name (path, section, _longsec, name, cat); - - if (names == (char **) -1 || *names == NULL) - /* - * No files match. See if there's a preformatted page around that - * we can display. - */ -#endif /* NROFF_MISSING */ - { - if (!troff) - { - cat = 1; - if (glob) - names = glob_for_file (path, section, _longsec, name, cat); - else - names = make_name (path, section, _longsec, name, cat); - - if (names != (char **) -1 && *names != NULL) - { - for (np = names; *np != NULL; np++) - { - if (print_where) - { - printf ("%s\n", *np); - found++; - } - else - { - found += display_cat_file (*np); - } - } - } - } - } -#ifndef NROFF_MISSING - else - { - for (np = names; *np != NULL; np++) - { - char *cat_file = NULL; - char *man_file; - - man_file = ultimate_source (*np, path); - - if (!troff) - { - to_cat = 1; - - cat_file = convert_name (man_file, to_cat); - - if (debug) - fprintf (stderr, "will try to write %s if needed\n", cat_file); - } - - found += format_and_display (path, man_file, cat_file); - } - } -#endif /* NROFF_MISSING */ - return found; -} - -/* - * Search for manual pages. - * - * If preformatted manual pages are supported, look for the formatted - * file first, then the man page source file. If they both exist and - * the man page source file is newer, or only the source file exists, - * try to reformat it and write the results in the cat directory. If - * it is not possible to write the cat file, simply format and display - * the man file. - * - * If preformatted pages are not supported, or the troff option is - * being used, only look for the man page source file. - * - */ -int -man (char *name) -{ - int found; - int glob; - char **mp; - char **sp; - int l_found; - char buf[PATH_MAX]; - - found = 0; - - fflush (stdout); - if (strchr(name, '/')) /* Treat name as file name if it's a path */ - { - struct stat st; - - if (debug) - fprintf(stderr, "Trying as file name\n"); - - /* - * We need to pass an absolute file name to format_and_display, - * or it will run into problems later. - */ - realpath(name, buf); - - if (stat(buf, &st) == 0) - found += format_and_display(dirname(buf), buf, NULL); - } - else if (shortsec != NULL) - { - for (mp = manpathlist; *mp != NULL; mp++) - { - if (debug) - fprintf (stderr, "\nsearching in %s\n", *mp); - - glob = 1; - - l_found = 0; - if (locale != NULL) { - locale_opts = locale_nroff; - use_man_locale = 1; - if (*locale_lang != '\0' && *locale_terr != '\0') { - snprintf(buf, sizeof(buf), "%s/%s_%s.%s", *mp, - locale_lang, locale_terr, locale_codeset); - if (is_directory (buf) == 1) - l_found = try_section (buf, shortsec, longsec, name, glob); - } - if (!l_found) { - if (*locale_lang != '\0') { - snprintf(buf, sizeof(buf), "%s/%s.%s", *mp, - locale_lang, locale_codeset); - if (is_directory (buf) == 1) - l_found = try_section (buf, shortsec, longsec, name, glob); - } - use_man_locale = 0; - if (!l_found && strcmp(locale_lang, "en") != 0) { - snprintf(buf, sizeof(buf), "%s/en.%s", *mp, - locale_codeset); - if (is_directory (buf) == 1) - l_found = try_section (buf, shortsec, longsec, name, glob); - } - } - locale_opts = NULL; - use_man_locale = 0; - } - if (!l_found) { - found += try_section (*mp, shortsec, longsec, name, glob); - } else - found += l_found; - - if (found && !findall) /* i.e. only do this section... */ - return found; - } - } - else - { - for (sp = section_list; *sp != NULL; sp++) - { - for (mp = manpathlist; *mp != NULL; mp++) - { - if (debug) - fprintf (stderr, "\nsearching in %s\n", *mp); - - glob = 1; - - l_found = 0; - if (locale != NULL) { - locale_opts = locale_nroff; - use_man_locale = 1; - if (*locale_lang != '\0' && *locale_terr != '\0') { - snprintf(buf, sizeof(buf), "%s/%s_%s.%s", *mp, - locale_lang, locale_terr, locale_codeset); - if (is_directory (buf) == 1) - l_found = try_section (buf, *sp, longsec, name, glob); - } - if (!l_found) { - if (*locale_lang != '\0') { - snprintf(buf, sizeof(buf), "%s/%s.%s", *mp, - locale_lang, locale_codeset); - if (is_directory (buf) == 1) - l_found = try_section (buf, *sp, longsec, name, glob); - } - use_man_locale = 0; - if (!l_found && strcmp(locale_lang, "en") != 0) { - snprintf(buf, sizeof(buf), "%s/en.%s", *mp, - locale_codeset); - if (is_directory (buf) == 1) - l_found = try_section (buf, *sp, longsec, name, glob); - } - } - locale_opts = NULL; - use_man_locale = 0; - } - if (!l_found) { - found += try_section (*mp, *sp, longsec, name, glob); - } else - found += l_found; - - if (found && !findall) /* i.e. only do this section... */ - return found; - } - } - } - return found; -} - -char ** -get_section_list (void) -{ - int i; - char *p; - char *end; -#define TMP_SECTION_LIST_SIZE 100 - static char *tmp_section_list[TMP_SECTION_LIST_SIZE]; - - if (colon_sep_section_list == NULL) - { - if ((p = getenv ("MANSECT")) == NULL) - { - return __DECONST(char **, std_sections); - } - else - { - colon_sep_section_list = strdup (p); - } - } - - i = 0; - for (p = colon_sep_section_list; i < TMP_SECTION_LIST_SIZE ; p = end+1) - { - if ((end = strchr (p, ':')) != NULL) - *end = '\0'; - - tmp_section_list[i++] = strdup (p); - - if (end == NULL) - break; - } - - tmp_section_list [i] = NULL; - return tmp_section_list; -} diff --git a/gnu/usr.bin/man/man/ndir.h b/gnu/usr.bin/man/man/ndir.h deleted file mode 100644 index 140f330cbc..0000000000 --- a/gnu/usr.bin/man/man/ndir.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - -- definitions for 4.2BSD-compatible directory access - - last edit: 09-Jul-1983 D A Gwyn -*/ - -#define DIRBLKSIZ 512 /* size of directory block */ -#define MAXNAMLEN 15 /* maximum filename length */ - /* NOTE: MAXNAMLEN must be one less than a multiple of 4 */ - -struct direct /* data from readdir() */ - { - long d_ino; /* inode number of entry */ - unsigned short d_reclen; /* length of this record */ - unsigned short d_namlen; /* length of string in d_name */ - char d_name[MAXNAMLEN+1]; /* name of file */ - }; - -typedef struct - { - int dd_fd; /* file descriptor */ - int dd_loc; /* offset in block */ - int dd_size; /* amount of valid data */ - char dd_buf[DIRBLKSIZ]; /* directory block */ - } DIR; /* stream data from opendir() */ - -extern DIR *opendir(); -extern struct direct *readdir(); -extern long telldir(); -extern void seekdir(); -extern void closedir(); - -#define rewinddir( dirp ) seekdir( dirp, 0L ) diff --git a/gnu/usr.bin/man/man/version.h b/gnu/usr.bin/man/man/version.h deleted file mode 100644 index 2ec5c22c3e..0000000000 --- a/gnu/usr.bin/man/man/version.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * version.h - * - * Copyright (c) 1990, 1991, John W. Eaton. - * - * You may distribute under the terms of the GNU General Public - * License as specified in the file COPYING that comes with the man - * distribution. - * - * John W. Eaton - * jwe@che.utexas.edu - * Department of Chemical Engineering - * The University of Texas at Austin - * Austin, Texas 78712 - */ - -static char version[] = "1.1"; diff --git a/gnu/usr.bin/man/manpath/Makefile b/gnu/usr.bin/man/manpath/Makefile deleted file mode 100644 index 2a12f9cdb5..0000000000 --- a/gnu/usr.bin/man/manpath/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $FreeBSD: src/gnu/usr.bin/man/manpath/Makefile,v 1.22.2.3 2002/02/01 09:00:02 ru Exp $ - -PROG= manpath - -DPADD= ${LIBMAN} -LDADD= ${LIBMAN} - -CFLAGS+= -DMAIN -DDO_UNCOMPRESS -CFLAGS+= -I${.CURDIR}/../lib -I${.OBJDIR}/../lib - -.include diff --git a/gnu/usr.bin/man/manpath/manpath.1 b/gnu/usr.bin/man/manpath/manpath.1 deleted file mode 100644 index 558e90033c..0000000000 --- a/gnu/usr.bin/man/manpath/manpath.1 +++ /dev/null @@ -1,98 +0,0 @@ -.\" Man page for manpath -.\" -.\" Copyright (c) 1990, 1991, John W. Eaton. -.\" -.\" You may distribute under the terms of the GNU General Public -.\" License as specified in the README file that comes with the man 1.0 -.\" distribution. -.\" -.\" John W. Eaton -.\" jwe@che.utexas.edu -.\" Department of Chemical Engineering -.\" The University of Texas at Austin -.\" Austin, Texas 78712 -.\" -.\" $FreeBSD: src/gnu/usr.bin/man/manpath/manpath.man,v 1.6.2.3 2001/10/04 13:02:24 ru Exp $ -.Dd August 16, 1999 -.Dt MANPATH 1 -.Os -.Sh NAME -.Nm manpath -.Nd determine user's search path for man pages -.Sh SYNOPSIS -.Nm -.Op Fl dLq -.Sh DESCRIPTION -.Nm Manpath -tries to determine the user's manpath from a set of system -defaults and the user's -.Ev PATH , -echoing the result to the standard output. -Warnings and errors are written to the standard error. -If a directory in the user's path is not listed in the -.Pa /etc/manpath.config -file, -.Nm -looks for the subdirectories -.Pa man -or -.Pa MAN . -If they exist, they are added to the search path. -If they do not exist, but the directory ends in -.Pa /bin , -.Nm -replaces -.Pa /bin -with -.Pa /man -and checks if that directory exists. -If it exists, it is added to the search path. -.Pp -.Nm Manpath -is used by -.Xr man 1 -to determine the search path, so users normally don't need to set the -.Ev MANPATH -environment variable directly. -.Pp -The options are as follows: -.Bl -tag -width Fl -.It Fl d -Output additional debug information. -.It Fl L -Output man locales list (if exist). -.It Fl q -Operate quietly. -Only echo the final result. -.El -.Sh ENVIRONMENT -.Bl -tag -width MANLOCALES -compact -.It Ev MANPATH -If -.Ev MANPATH -is set, -.Nm -echoes its value on the standard output and issues a warning on the -standard error. -.It Ev MANLOCALES -If -.Ev MANLOCALES -is set and -.Fl L -option is set, -.Nm -echoes its value on the standard output and issues a warning on the -standard error. -.El -.Sh FILES -.Bl -tag -width /etc/manpath.config -compact -.It Pa /etc/manpath.config -System configuration file. -.El -.Sh SEE ALSO -.Xr apropos 1 , -.Xr man 1 , -.Xr whatis 1 , -.Xr manpath.config 5 -.Sh BUGS -None known. diff --git a/gnu/usr.bin/man/manpath/manpath.c b/gnu/usr.bin/man/manpath/manpath.c deleted file mode 100644 index b5001e6181..0000000000 --- a/gnu/usr.bin/man/manpath/manpath.c +++ /dev/null @@ -1,578 +0,0 @@ -/* - * manpath.c - * - * Copyright (c) 1990, 1991, John W. Eaton. - * - * You may distribute under the terms of the GNU General Public - * License as specified in the file COPYING that comes with the man - * distribution. - * - * John W. Eaton - * jwe@che.utexas.edu - * Department of Chemical Engineering - * The University of Texas at Austin - * Austin, Texas 78712 - * - * $FreeBSD: src/gnu/usr.bin/man/manpath/manpath.c,v 1.11.2.2 2003/02/15 05:33:06 kris Exp $ - */ - -#define MANPATH_MAIN - -#include -#include -#include -#include -#include -#include -#include "config.h" -#include "manpath.h" -#include "gripes.h" -#include "util.h" - -#ifndef MAIN -extern int debug; -#endif - -int get_dirlist (void); -char *def_path (int); -char *get_manpath (int, char *); -void add_dir_to_list (char **, char *, int); -char *has_subdirs (char *); -const char *manpath (int); -void usage (void); - -#ifdef MAIN - -char *prognam; -int debug; -int locale; -char *man_locales; - -/* - * Examine user's PATH and print a reasonable MANPATH. - */ -int -main(int argc, char **argv) -{ - int c; - int quiet; - const char *mp; - - quiet = 1; - - prognam = mkprogname (argv[0]); - - while ((c = getopt (argc, argv, "dhLq?")) != -1) - { - switch (c) - { - case 'd': - debug++; - break; - case 'L': - locale++; - break; - case 'q': - quiet = 0; - break; - case '?': - case 'h': - default: - usage(); - break; - } - } - - mp = manpath (quiet); - - fprintf (stdout, "%s\n", mp); - fflush (stdout); - - return 0; -} - -void -usage (void) -{ - fprintf (stderr, "usage: %s [-dLq]\n", prognam); - exit (1); -} -#endif /* MAIN */ - -/* - * If the environment variable MANPATH is set, return it. - * If the environment variable PATH is set and has a nonzero length, - * try to determine the corresponding manpath, otherwise, return the - * default manpath. - * - * The manpath.config file is used to map system wide /bin directories - * to top level man page directories. - * - * For directories which are in the user's path but not in the - * manpath.config file, see if there is a subdirectory `man' or `MAN'. - * If so, add that directory to the path. Example: user has - * $HOME/bin in his path and the directory $HOME/bin/man exists -- the - * directory $HOME/bin/man will be added to the manpath. - * - * Also search for a `man' directory next to the directory on the path. - * Example: $HOME/bin will look for $HOME/man - */ -const char * -manpath (int perrs) -{ - int len; - char *manpathlist; - char *path; - - if (get_dirlist ()) - gripe_reading_mp_config (config_file); - -#ifdef MAIN - if (locale) - { - if ((manpathlist = getenv ("MANLOCALES")) != NULL) - /* - * This must be it. - */ - { - if (perrs) - fprintf (stderr, "(Warning: MANLOCALES environment variable set)\n"); - return strdup (manpathlist); - } - return (man_locales ? man_locales : ""); - } -#endif /* MAIN */ - - if ((manpathlist = getenv ("MANPATH")) != NULL) - /* - * This must be it. - */ - { - if (perrs) - fprintf (stderr, "(Warning: MANPATH environment variable set)\n"); - return strdup (manpathlist); - } - else if ((path = getenv ("PATH")) == NULL) - /* - * Things aren't going to work well, but hey... - */ - { - if (perrs) - fprintf (stderr, "Warning: path not set\n"); - return def_path (perrs); - } - else - { - if ((len = strlen (path)) == 0) - /* - * Things aren't going to work well here either... - */ - { - if (perrs) - fprintf (stderr, "Warning: path set but has zero length\n"); - return def_path (perrs); - } - return get_manpath (perrs, path); - } -} - -/* - * Get the list of bin directories and the corresponding man - * directories from the manpath.config file. - * - * This is ugly. - */ -int -get_dirlist (void) -{ - int i; - char *bp; - char *p; - char buf[BUFSIZ]; - DIRLIST *dlp = list; - FILE *config; - - if ((config = fopen (config_file, "r")) == NULL) - gripe_getting_mp_config (config_file); - - while ((bp = fgets (buf, BUFSIZ, config)) != NULL) - { - while (*bp && (*bp == ' ' || *bp == '\t')) - bp++; - - if (*bp == '#' || *bp == '\n') - continue; - - if (!strncmp ("MANDATORY_MANPATH", bp, 17) || - !strncmp ("OPTIONAL_MANPATH", bp, 16)) - { - if ((p = strchr (bp, ' ')) == NULL && - (p = strchr (bp, '\t')) == NULL) { - fclose(config); - return -1; - } - - dlp->type = *bp == 'M'? MANPATH_MANDATORY: MANPATH_OPTIONAL; - - bp = p; - - while (*bp && *bp != '\n' && (*bp == ' ' || *bp == '\t')) - bp++; - - i = 0; - while (*bp && *bp != '\n' && *bp != ' ' && *bp != '\t') - dlp->mandir[i++] = *bp++; - dlp->mandir[i] = '\0'; - - if (debug) - fprintf (stderr, "found %s man directory %s\n", - dlp->type == MANPATH_MANDATORY? "mandatory": "optional", - dlp->mandir); - } - else if (!strncmp ("MANPATH_MAP", bp, 11)) - { - if ((p = strchr (bp, ' ')) == NULL && - (p = strchr (bp, '\t')) == NULL) { - fclose(config); - return -1; - } - - bp = p; - - dlp->type = MANPATH_MAP; - - while (*bp && *bp != '\n' && (*bp == ' ' || *bp == '\t')) - bp++; - - i = 0; - while (*bp && *bp != '\n' && *bp != ' ' && *bp != '\t') - dlp->bin[i++] = *bp++; - dlp->bin[i] = '\0'; - - while (*bp && *bp != '\n' && (*bp == ' ' || *bp == '\t')) - bp++; - - i = 0; - while (*bp && *bp != '\n' && *bp != ' ' && *bp != '\t') - dlp->mandir[i++] = *bp++; - dlp->mandir[i] = '\0'; - - if (debug) - fprintf (stderr, "found manpath map %s --> %s\n", - dlp->bin, dlp->mandir); - } - else if (!strncmp ("MANLOCALES", bp, 10)) - { - if ((p = strchr (bp, ' ')) == NULL && - (p = strchr (bp, '\t')) == NULL) { - fclose(config); - return -1; - } - - bp = p; - - while (*bp && *bp != '\n' && (*bp == ' ' || *bp == '\t')) - bp++; - - for (p = bp; *p && *p != '\n'; p++) - ; - do { - *p-- = '\0'; - } while (p >= bp && (*p == ' ' || *p == '\t')); - -#ifdef MAIN - if (man_locales != NULL) - free (man_locales); - - if ((man_locales = strdup (bp)) == NULL) { - fclose(config); - return -1; - } -#endif /* MAIN */ - - if (debug) - fprintf (stderr, "found man locales: %s\n", bp); - } - else - { - gripe_reading_mp_config (config_file); - } - dlp++; - } - - fclose(config); - dlp->bin[0] = '\0'; - dlp->mandir[0] = '\0'; - dlp->type = MANPATH_NONE; - - return 0; -} - -/* - * Construct the default manpath. This picks up mandatory - * and optional (if they exist) manpaths only. - */ -char * -def_path (int perrs) -{ - int len; - char *manpathlist, *p; - DIRLIST *dlp; - - len = 0; - dlp = list; - while (dlp->type != MANPATH_NONE) { - if (dlp->type == MANPATH_MANDATORY || dlp->type == MANPATH_OPTIONAL) - len += strlen (dlp->mandir) + 1; - dlp++; - } - - manpathlist = (char *) malloc (len); - if (manpathlist == NULL) - gripe_alloc (len, "manpathlist"); - - *manpathlist = '\0'; - - dlp = list; - p = manpathlist; - while (dlp->type != MANPATH_NONE) { - if (dlp->type == MANPATH_MANDATORY || dlp->type == MANPATH_OPTIONAL) { - int status; - char *path = dlp->mandir; - - status = is_directory(path); - - if (status < 0 && perrs && dlp->type == MANPATH_MANDATORY) - { - fprintf (stderr, "Warning: couldn't stat file %s!\n", path); - } - else if (status == 0 && perrs) - { - fprintf (stderr, "Warning: %s isn't a directory!\n", path); - } - else if (status == 1) - { - len = strlen (path); - memcpy (p, path, len); - p += len; - *p++ = ':'; - } - } - dlp++; - } - - p[-1] = '\0'; - - return manpathlist; -} - -/* - * For each directory in the user's path, see if it is one of the - * directories listed in the manpath.config file. If so, and it is - * not already in the manpath, add it. If the directory is not listed - * in the manpath.config file, see if there is a subdirectory `man' or - * `MAN'. If so, and it is not already in the manpath, add it. - * Example: user has $HOME/bin in his path and the directory - * $HOME/bin/man exists -- the directory $HOME/bin/man will be added - * to the manpath. - */ -char * -get_manpath (int perrs, char *path) -{ - int len; - char *tmppath; - char *t; - char *p; - char **lp; - char *end; - char *manpathlist; - DIRLIST *dlp; - int fnd = 0; - - tmppath = strdup (path); - - for (p = tmppath; ; p = end+1) - { - if ((end = strchr(p, ':')) != NULL) - *end = '\0'; - - if (debug) - fprintf (stderr, "\npath directory %s ", p); - - if (*p != '/') - { - if (debug) - fprintf (stderr, "is not an absolute pathname\n"); - - goto found; /* skip. */ - } - - /* - * The directory we're working on is in the config file. - * If we haven't added it to the list yet, do. - */ - for (dlp = list; dlp->mandir[0] != '\0'; dlp++) - if (dlp->bin[0] != '\0' && !strcmp (p, dlp->bin)) - { - if (debug && !fnd) - fprintf (stderr, "is in the config file\n"); - - add_dir_to_list (tmplist, dlp->mandir, perrs); - fnd++; - } - if (fnd) - { - fnd = 0; - goto found; - } - - /* - * The directory we're working on isn't in the config file. See - * if it has man or MAN subdirectories. If so, and it hasn't - * been added to the list, do. - */ - if (debug) - fprintf (stderr, "is not in the config file\n"); - - t = has_subdirs (p); - if (t != NULL) - { - if (debug) - fprintf (stderr, "but it does have a man or MAN subdirectory\n"); - - add_dir_to_list (tmplist, t, perrs); - free (t); - } - else - { - if (debug) - fprintf (stderr, "and doesn't have man or MAN subdirectories\n"); - } - - found: - - if (!end) - break; - } - - if (debug) - fprintf (stderr, "\nadding mandatory man directories\n\n"); - - dlp = list; - while (dlp->type != MANPATH_NONE) { - if (dlp->type == MANPATH_MANDATORY || dlp->type == MANPATH_OPTIONAL) - add_dir_to_list (tmplist, dlp->mandir, - dlp->type == MANPATH_MANDATORY? perrs: 0); - dlp++; - } - - len = 0; - lp = tmplist; - while (*lp != NULL) - { - len += strlen (*lp) + 1; - lp++; - } - - if (!len) - return strdup(""); - - manpathlist = (char *) malloc (len); - if (manpathlist == NULL) - gripe_alloc (len, "manpathlist"); - - *manpathlist = '\0'; - - lp = tmplist; - p = manpathlist; - while (*lp != NULL) - { - len = strlen (*lp); - memcpy (p, *lp, len); - p += len; - *p++ = ':'; - lp++; - } - - p[-1] = '\0'; - - return manpathlist; -} - -/* - * Add a directory to the manpath list if it isn't already there. - */ -void -add_dir_to_list (char **lp, char *dir, int perrs) -{ - int status; - - while (*lp != NULL) - { - if (!strcmp (*lp, dir)) - { - if (debug) - fprintf (stderr, "%s is already in the manpath\n", dir); - return; - } - lp++; - } - /* - * Not found -- add it. - */ - status = is_directory(dir); - - if (status < 0 && perrs) - { - fprintf (stderr, "Warning: couldn't stat file %s!\n", dir); - } - else if (status == 0 && perrs) - { - fprintf (stderr, "Warning: %s isn't a directory!\n", dir); - } - else if (status == 1) - { - if (debug) - fprintf (stderr, "adding %s to manpath\n", dir); - - *lp = strdup (dir); - } -} - -/* - * Check to see if the current directory has man or MAN - * subdirectories. - */ -char * -has_subdirs (char *p) -{ - int len; - char *t; - - len = strlen (p); - - t = (char *) malloc ((unsigned) len + 5); - if (t == NULL) - gripe_alloc (len+5, "p\n"); - - memcpy (t, p, len); - strcpy (t + len, "/man"); - - if (is_directory (t) == 1) - return t; - - strcpy (t + len, "/MAN"); - - if (is_directory (t) == 1) - return t; - - /* If the path ends in `bin' then replace with `man' and see if that works. */ - if (len > 3 && strncmp(t+len-4, "/bin", 4) == 0) { - strcpy(t+len-4, "/man"); - - if (is_directory(t) == 1) - return t; - } - - return NULL; -} diff --git a/gnu/usr.bin/man/manpath/manpath.config b/gnu/usr.bin/man/manpath/manpath.config deleted file mode 100644 index e099a7b4ea..0000000000 --- a/gnu/usr.bin/man/manpath/manpath.config +++ /dev/null @@ -1,32 +0,0 @@ -# $FreeBSD: src/gnu/usr.bin/man/manpath/manpath.config,v 1.15.2.1 2003/02/14 22:38:14 nectar Exp $ -# -# This file is read by manpath(1) to configure the mandatory manpath, -# optional manpath and to map each path element to a manpath element. -# The format is: -# -# MANDATORY_MANPATH manpath_element -# OPTIONAL_MANPATH manpath_element -# MANPATH_MAP path_element manpath_element -# MANLOCALES locale1 locale2 ... -# -# every automatically generated MANPATH includes these fields -# -MANDATORY_MANPATH /usr/share/man -# -# check if the directory exists and if it does, add it to MANPATH -# -OPTIONAL_MANPATH /usr/local/man -OPTIONAL_MANPATH /usr/pkg/man -OPTIONAL_MANPATH /raven/share/man -# -# set up PATH to MANPATH mapping -# -MANPATH_MAP /bin /usr/share/man -MANPATH_MAP /usr/bin /usr/share/man -MANPATH_MAP /usr/local/bin /usr/local/man -MANPATH_MAP /usr/local/bin /usr/local/share/man -MANPATH_MAP /raven/bin /raven/share/man -# -# set man locales, if needed -# -#MANLOCALES ru_RU.KOI8-R diff --git a/gnu/usr.bin/man/manpath/manpath.h b/gnu/usr.bin/man/manpath/manpath.h deleted file mode 100644 index ab6eb0ef6a..0000000000 --- a/gnu/usr.bin/man/manpath/manpath.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * manpath.h - * - * Copyright (c) 1990, 1991, John W. Eaton. - * - * You may distribute under the terms of the GNU General Public - * License as specified in the file COPYING that comes with the man - * distribution. - * - * John W. Eaton - * jwe@che.utexas.edu - * Department of Chemical Engineering - * The University of Texas at Austin - * Austin, Texas 78712 - */ - -typedef struct -{ - char mandir[MAXPATHLEN]; - char bin[MAXPATHLEN]; - int type; -} DIRLIST; - -/* manpath types */ -#define MANPATH_NONE 0 -#define MANPATH_MANDATORY 1 /* manpath is mandatory */ -#define MANPATH_OPTIONAL 2 /* manpath is optional */ -#define MANPATH_MAP 3 /* maps path to manpath */ - -DIRLIST list[MAXDIRS]; - -char *tmplist[MAXDIRS]; diff --git a/share/man/man5/manpath.config.5 b/share/man/man5/manpath.config.5 deleted file mode 100644 index 9de25df4a8..0000000000 --- a/share/man/man5/manpath.config.5 +++ /dev/null @@ -1,79 +0,0 @@ -.\" -.\" Copyright (c) 2007 -.\" The DragonFly Project. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in -.\" the documentation and/or other materials provided with the -.\" distribution. -.\" 3. Neither the name of The DragonFly Project nor the names of its -.\" contributors may be used to endorse or promote products derived -.\" from this software without specific, prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, -.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd April 25, 2007 -.Dt MANPATH.CONFIG 5 -.Os -.Sh NAME -.Nm manpath.config -.Nd manual page search path configuration file -.Sh SYNOPSIS -.Pa /etc/manpath.config -.Sh DESCRIPTION -The -.Nm -file configures the manual page search path used by the man utilities. -The environment variable -.Ev MANPATH -(if set) overrides this information. -.Pp -Empty lines or lines beginning with a -.Dq # -are ignored. -The following keywords are recognized: -.Bl -tag -width XXXXXX -.It Li MANDATORY_MANPATH Ar manpath_element -Each specified -.Ar manpath_element -will be added to the search path. -.It Li OPTIONAL_MANPATH Ar manpath_element -Each specified -.Ar manpath_element -will be added to the search path if it exists. -.It Li MANPATH_MAP Ar path_element Ar manpath_element -Each specified -.Ar manpath_element -will be added to the search path if -.Ar path_element -is in -.Ev PATH . -.\".It MANLOCALES Ar locale1 Ar locale2 Ar ... -.El -.Sh FILES -.Bl -tag -width ".Pa /etc/manpath.config" -compact -.It Pa /etc/manpath.config -Configuration file for setting up the manual page search path. -.El -.Sh SEE ALSO -.Xr manpath 1 -.Sh AUTHORS -This manual page was written by -.An Sascha Wildner . diff --git a/usr.sbin/makewhatis/Makefile b/usr.sbin/makewhatis/Makefile deleted file mode 100644 index 847d8416f0..0000000000 --- a/usr.sbin/makewhatis/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# $FreeBSD: src/usr.bin/makewhatis/Makefile,v 1.3 2002/11/18 10:11:22 ru Exp $ -# $DragonFly: src/usr.sbin/makewhatis/Makefile,v 1.2 2005/01/16 04:59:53 cpressey Exp $ - -PROG= makewhatis -DPADD= ${LIBZ} -LDADD= -lz -MAN= makewhatis.8 - -.include diff --git a/usr.sbin/makewhatis/makewhatis.8 b/usr.sbin/makewhatis/makewhatis.8 deleted file mode 100644 index 20c3e21cca..0000000000 --- a/usr.sbin/makewhatis/makewhatis.8 +++ /dev/null @@ -1,135 +0,0 @@ -.\" Copyright (c) 2002 John Rochester -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD: src/usr.bin/makewhatis/makewhatis.1,v 1.3 2002/05/18 15:39:56 ru Exp $ -.\" -.Dd December 8, 2013 -.Dt MAKEWHATIS 8 -.Os -.Sh NAME -.Nm makewhatis -.Nd create whatis database -.Sh SYNOPSIS -.Nm -.Op Fl a -.Op Fl i Ar column -.Op Fl n Ar name -.Op Fl o Ar file -.Op Fl v -.Op Fl L -.Op Ar directories ... -.Sh DESCRIPTION -The -.Nm -utility collects the names and short descriptions from all the unformatted -man pages in the -.Ar directories -and puts them into a file used by the -.Xr whatis 1 -and -.Xr apropos 1 -commands. -Directories may be separated by colons instead of spaces. -If no -.Ar directories -are specified, the contents of the -.Ev MANPATH -environment variable will be used, or if that is not set, the default directory -.Pa /usr/share/man -will be processed. -.Pp -The options are as follows: -.Bl -tag -width ".Fl i Ar column" -.It Fl a -Appends to the output file(s) instead of replacing them. -The output -will be sorted with duplicate lines removed, but may have obsolete -entries. -.It Fl i Ar column -Indents the description by -.Ar column -characters. -The default value is 24. -.It Fl n Ar name -Uses -.Ar name -instead of -.Pa whatis . -.It Fl o Ar file -Outputs all lines to the -.Ar file -instead of -.Pa */man/whatis . -.It Fl v -Makes -.Nm -more verbose about what it is doing. -.It Fl L -Process only localized subdirectories corresponding to the locale specified -in the standard environment variables. -.El -.Sh ENVIRONMENT -.Bl -tag -width ".Ev MANPATH" -.It Ev LC_ALL , LC_CTYPE , LANG -These variables control what subdirectories will be processed if the -.Fl L -option is used. -.It Ev MACHINE -If set, its value is used to override the current -machine type when searching machine specific subdirectories. -.It Ev MANPATH -Determines the set of directories to be processed if none are given on -the command line. -.El -.Sh FILES -.Bl -tag -width ".Pa /usr/share/man" -compact -.It Pa /usr/share/man -Default directory to process if the -.Ev MANPATH -environment variable is not set. -.It Pa */man/whatis -The default output file. -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr apropos 1 , -.Xr whatis 1 -.Sh HISTORY -The -.Nm -command appeared in -.Fx 2.1 . -.Sh AUTHORS -.An -nosplit -The -.Nm -program was originally written in Perl and was contributed by -.An Wolfram Schneider . -The current version of -.Nm -was rewritten in C by -.An John Rochester -with additional contributions by -.An Franco Fichtner Aq Mt franco@lastsummer.de . diff --git a/usr.sbin/makewhatis/makewhatis.c b/usr.sbin/makewhatis/makewhatis.c deleted file mode 100644 index 261613eafa..0000000000 --- a/usr.sbin/makewhatis/makewhatis.c +++ /dev/null @@ -1,1134 +0,0 @@ -/*- - * Copyright (c) 2002 John Rochester - * Copyright (c) 2013-2014 Franco Fichtner - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: src/usr.bin/makewhatis/makewhatis.c,v 1.9 2002/09/04 23:29:04 dwmalone Exp $ - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DEFAULT_MANPATH "/usr/share/man" -#define LINE_ALLOC 4096 - -static char blank[] = ""; - -/* - * Information collected about each man page alias. - */ -struct page_alias { - RB_ENTRY(page_alias) entry; - char *filename; - char *name; - char *suffix; - int gzipped; -}; - -/* - * Information collected about each unique man page. - */ -struct page_info { - RB_HEAD(page_alias_tree, page_alias) head; - RB_ENTRY(page_info) entry; - ino_t inode; -}; - -static RB_HEAD(page_info_tree, page_info) page_head = RB_INITIALIZER(&page_head); - -/* - * Sorts page info by inode number. - */ -static int -infosort(const struct page_info *a, const struct page_info *b) -{ - return (memcmp(&a->inode, &b->inode, sizeof(a->inode))); -} - -RB_PROTOTYPE(page_info_tree, page_info, entry, infosort); -RB_GENERATE(page_info_tree, page_info, entry, infosort); - -/* - * Sorts page alias first by suffix, then name. - */ -static int -aliassort(const struct page_alias *a, const struct page_alias *b) -{ - int ret = strcmp(a->suffix, b->suffix); - if (ret) { - return (ret); - } - - return (strcmp(a->name, b->name)); -} - -RB_PROTOTYPE(page_alias_tree, page_alias, entry, aliassort); -RB_GENERATE(page_alias_tree, page_alias, entry, aliassort); - -/* - * An entry kept for each visited directory. - */ -struct visited_dir { - dev_t device; - ino_t inode; - SLIST_ENTRY(visited_dir) next; -}; - -/* - * an expanding string - */ -struct sbuf { - char * content; /* the start of the buffer */ - char * end; /* just past the end of the content */ - char * last; /* the last allocated character */ -}; - -/* - * Removes the last amount characters from the sbuf. - */ -#define sbuf_retract(sbuf, amount) \ - ((sbuf)->end -= (amount)) -/* - * Returns the length of the sbuf content. - */ -#define sbuf_length(sbuf) \ - ((sbuf)->end - (sbuf)->content) - -typedef char *edited_copy(char *from, char *to, int length); - -static int append; /* -a flag: append to existing whatis */ -static int verbose; /* -v flag: be verbose with warnings */ -static int indent = 24; /* -i option: description indentation */ -static const char *whatis_name="whatis";/* -n option: the name */ -static char *common_output; /* -o option: the single output file */ -static char *locale; /* user's locale if -L is used */ -static char *lang_locale; /* short form of locale */ -static const char *machine; - -static int exit_code; /* exit code to use when finished */ -static SLIST_HEAD(, visited_dir) visited_dirs = - SLIST_HEAD_INITIALIZER(visited_dirs); - -/* - * While the whatis line is being formed, it is stored in whatis_proto. - * When finished, it is reformatted into whatis_final and then appended - * to whatis_lines. - */ -static struct sbuf *whatis_proto; -static struct sbuf *whatis_final; -static StringList *whatis_lines; /* collected output lines */ - -static char tmp_file[MAXPATHLEN]; /* path of temporary file, if any */ - -/* A set of possible names for the NAME man page section */ -static const char *name_section_titles[] = { - "NAME", "Name", "NAMN", "BEZEICHNUNG", "\xcc\xbe\xbe\xce", - "\xee\xe1\xfa\xf7\xe1\xee\xe9\xe5", NULL -}; - -/* A subset of the mdoc(7) commands to ignore */ -static char mdoc_commands[] = "ArDvErEvFlLiNmPa"; - -/* - * Frees a struct page_info and its content. - */ -static void -free_page_info(struct page_info *info) -{ - struct page_alias *alias; - - while ((alias = RB_ROOT(&info->head))) { - RB_REMOVE(page_alias_tree, &info->head, alias); - free(alias->filename); - free(alias->suffix); - free(alias->name); - free(alias); - } - - free(info); -} - -/* - * Allocates and fills in a new struct page_alias given the - * full file name of the man page and its dirent. - * If the file is not a man page, nothing is added. - */ -static void -new_page_alias(struct page_info *info, char *filename, struct dirent *dirent) -{ - int basename_length; - struct page_alias *alias; - char *suffix; - int gzipped; - - basename_length = strlen(dirent->d_name); - suffix = &dirent->d_name[basename_length]; - gzipped = basename_length >= 4 && - strcmp(&dirent->d_name[basename_length - 3], ".gz") == 0; - if (gzipped) { - suffix -= 3; - *suffix = '\0'; - } - for (;;) { - if (--suffix == dirent->d_name || !isalnum(*suffix)) { - if (*suffix == '.') - break; - if (verbose) - warnx("%s: invalid man page name", - filename); - return; - } - } - - *suffix++ = '\0'; - - alias = malloc(sizeof(*alias)); - if (alias == NULL) { - err(1, "malloc"); - } - - alias->name = strdup(dirent->d_name); - alias->filename = strdup(filename); - alias->suffix = strdup(suffix); - alias->gzipped = gzipped; - - if (!alias->name || !alias->filename || !alias->suffix) { - err(1, "strdup"); - } - - RB_INSERT(page_alias_tree, &info->head, alias); -} - -/* - * Reset an sbuf's length to 0. - */ -static void -sbuf_clear(struct sbuf *sbuf) -{ - sbuf->end = sbuf->content; -} - -/* - * Allocate a new sbuf. - */ -static struct sbuf * -new_sbuf(void) -{ - struct sbuf *sbuf = (struct sbuf *) malloc(sizeof(struct sbuf)); - sbuf->content = malloc(LINE_ALLOC); - sbuf->last = sbuf->content + LINE_ALLOC - 1; - sbuf_clear(sbuf); - return(sbuf); -} - -/* - * Ensure that there is enough room in the sbuf for nchars more characters. - */ -static void -sbuf_need(struct sbuf *sbuf, int nchars) -{ - char *new_content; - size_t size, cntsize; - - /* double the size of the allocation until the buffer is big enough */ - while (sbuf->end + nchars > sbuf->last) { - size = sbuf->last + 1 - sbuf->content; - size *= 2; - cntsize = sbuf->end - sbuf->content; - - new_content = malloc(size); - memcpy(new_content, sbuf->content, cntsize); - free(sbuf->content); - sbuf->content = new_content; - sbuf->end = new_content + cntsize; - sbuf->last = new_content + size - 1; - } -} - -/* - * Appends a string of a given length to the sbuf. - */ -static void -sbuf_append(struct sbuf *sbuf, const char *text, int length) -{ - if (length > 0) { - sbuf_need(sbuf, length); - memcpy(sbuf->end, text, length); - sbuf->end += length; - } -} - -/* - * Appends a null-terminated string to the sbuf. - */ -static void -sbuf_append_str(struct sbuf *sbuf, char *text) -{ - sbuf_append(sbuf, text, strlen(text)); -} - -/* - * Appends an edited null-terminated string to the sbuf. - */ -static void -sbuf_append_edited(struct sbuf *sbuf, char *text, edited_copy copy) -{ - int length = strlen(text); - if (length > 0) { - sbuf_need(sbuf, length); - sbuf->end = copy(text, sbuf->end, length); - } -} - -/* - * Strips any of a set of chars from the end of the sbuf. - */ -static void -sbuf_strip(struct sbuf *sbuf, const char *set) -{ - while (sbuf->end > sbuf->content && strchr(set, sbuf->end[-1]) != NULL) - sbuf->end--; -} - -/* - * Returns the null-terminated string built by the sbuf. - */ -static char * -sbuf_content(struct sbuf *sbuf) -{ - *sbuf->end = '\0'; - return(sbuf->content); -} - -static void -trap_signal(int sig __unused) -{ - if (tmp_file[0] != '\0') - unlink(tmp_file); - exit(1); -} - -/* - * Attempts to open an output file. Returns NULL if unsuccessful. - */ -static FILE * -open_output(char *name) -{ - FILE *output; - - whatis_lines = sl_init(); - if (append) { - char line[LINE_ALLOC]; - - output = fopen(name, "r"); - if (output == NULL) { - warn("%s", name); - exit_code = 1; - return(NULL); - } - while (fgets(line, sizeof line, output) != NULL) { - line[strlen(line) - 1] = '\0'; - sl_add(whatis_lines, strdup(line)); - } - } - if (common_output == NULL) { - snprintf(tmp_file, sizeof tmp_file, "%s.tmp", name); - name = tmp_file; - } - output = fopen(name, "w"); - if (output == NULL) { - warn("%s", name); - exit_code = 1; - return(NULL); - } - return(output); -} - -static int -linesort(const void *a, const void *b) -{ - return(strcmp((*(const char * const *)a), (*(const char * const *)b))); -} - -/* - * Writes the unique sorted lines to the output file. - */ -static void -finish_output(FILE *output, char *name) -{ - size_t i; - char *prev = NULL; - - qsort(whatis_lines->sl_str, whatis_lines->sl_cur, sizeof(char *), - linesort); - for (i = 0; i < whatis_lines->sl_cur; i++) { - char *line = whatis_lines->sl_str[i]; - if (i > 0 && strcmp(line, prev) == 0) - continue; - prev = line; - fputs(line, output); - putc('\n', output); - } - fclose(output); - sl_free(whatis_lines, 1); - if (common_output == NULL) { - rename(tmp_file, name); - unlink(tmp_file); - } -} - -static FILE * -open_whatis(char *mandir) -{ - char filename[MAXPATHLEN]; - - snprintf(filename, sizeof filename, "%s/%s", mandir, whatis_name); - return(open_output(filename)); -} - -static void -finish_whatis(FILE *output, char *mandir) -{ - char filename[MAXPATHLEN]; - - snprintf(filename, sizeof filename, "%s/%s", mandir, whatis_name); - finish_output(output, filename); -} - -/* - * Tests to see if the given directory has already been visited. - */ -static int -already_visited(char *dir) -{ - struct stat st; - struct visited_dir *visit; - - if (stat(dir, &st) < 0) { - warn("%s", dir); - exit_code = 1; - return(1); - } - SLIST_FOREACH(visit, &visited_dirs, next) { - if (visit->inode == st.st_ino && - visit->device == st.st_dev) { - warnx("already visited %s", dir); - return(1); - } - } - visit = (struct visited_dir *) malloc(sizeof(struct visited_dir)); - visit->device = st.st_dev; - visit->inode = st.st_ino; - SLIST_INSERT_HEAD(&visited_dirs, visit, next); - return(0); -} - -/* - * Removes trailing spaces from a string, returning a pointer to just - * beyond the new last character. - */ -static char * -trim_rhs(char *str) -{ - char *rhs = &str[strlen(str)]; - while (--rhs > str && isspace(*rhs)) - ; - *++rhs = '\0'; - return(rhs); -} - -/* - * Returns a pointer to the next non-space character in the string. - */ -static char * -skip_spaces(char *s) -{ - while (*s != '\0' && isspace(*s)) - s++; - return(s); -} - -/* - * Returns whether the string contains only digits. - */ -static int -only_digits(char *line) -{ - if (!isdigit(*line++)) - return(0); - while (isdigit(*line)) - line++; - return(*line == '\0'); -} - -/* - * Returns whether the line is of one of the forms: - * .Sh NAME - * .Sh "NAME" - * etc. - * assuming that section_start is ".Sh". - */ -static int -name_section_line(char *line, const char *section_start) -{ - char *rhs; - const char **title; - - if (strncmp(line, section_start, 3) != 0) - return(0); - line = skip_spaces(line + 3); - rhs = trim_rhs(line); - if (*line == '"') { - line++; - if (*--rhs == '"') - *rhs = '\0'; - } - for (title = name_section_titles; *title != NULL; title++) - if (strcmp(*title, line) == 0) - return(1); - return(0); -} - -/* - * Copies characters while removing the most common nroff/troff - * markup: - * \(em, \(mi, \s[+-N], \& - * \fF, \f(fo, \f[font] - * \*s, \*(st, \*[stringvar] - */ -static char * -de_nroff_copy(char *from, char *to, int fromlen) -{ - char *from_end = &from[fromlen]; - while (from < from_end) { - switch (*from) { - case '\\': - switch (*++from) { - case '(': - if (strncmp(&from[1], "em", 2) == 0 || - strncmp(&from[1], "mi", 2) == 0) { - from += 3; - continue; - } - break; - case 's': - if (*++from == '-') - from++; - while (isdigit(*from)) - from++; - continue; - case 'f': - case '*': - if (*++from == '(') - from += 3; - else if (*from == '[') { - while (*++from != ']' && from < from_end) - ; - from++; - } else - from++; - continue; - case '&': - from++; - continue; - } - break; - } - *to++ = *from++; - } - return(to); -} - -/* - * Appends a string with the nroff formatting removed. - */ -static void -add_nroff(char *text) -{ - sbuf_append_edited(whatis_proto, text, de_nroff_copy); -} - -/* - * Appends "name(suffix), " to whatis_final. - */ -static void -add_whatis_name(char *name, char *suffix) -{ - if (*name != '\0') { - sbuf_append_str(whatis_final, name); - sbuf_append(whatis_final, "(", 1); - sbuf_append_str(whatis_final, suffix); - sbuf_append(whatis_final, "), ", 3); - } -} - -/* - * Processes an old-style man(7) line. This ignores commands with only - * a single number argument. - */ -static void -process_man_line(char *line) -{ - if (*line == '.') { - while (isalpha(*++line)) - ; - line = skip_spaces(line); - if (only_digits(line)) - return; - } else - line = skip_spaces(line); - if (*line != '\0') { - add_nroff(line); - sbuf_append(whatis_proto, " ", 1); - } -} - -struct mdoc_text { - const char *mdoc; - const char *text; -}; - -static int -process_mdoc_macro(char *line) -{ - static const struct mdoc_text list[] = { - { ".At", "AT&T UNIX" }, - { ".Bsx", "BSD/OS" }, - { ".Bx", "BSD" }, - { ".Dx", "DragonFly" }, - { ".Fx", "FreeBSD" }, - { ".Nx", "NetBSD" }, - { ".Ox", "OpenBSD" }, - { ".Ux", "UNIX" }, - }; - unsigned int i; - - for (i = 0; i < NELEM(list); ++i) { - if (!strcmp(line, list[i].mdoc)) { - sbuf_append(whatis_proto, list[i].text, - strlen(list[i].text)); - sbuf_append(whatis_proto, " ", 1); - return (1); - } - } - - return (0); -} - -/* - * Processes a new-style mdoc(7) line. - */ -static void -process_mdoc_line(char *line) -{ - int xref; - int arg = 0; - char *line_end = &line[strlen(line)]; - int orig_length = sbuf_length(whatis_proto); - char *next; - - if (*line == '\0') - return; - if (line[0] != '.' || !isupper(line[1]) || !islower(line[2])) { - add_nroff(skip_spaces(line)); - sbuf_append(whatis_proto, " ", 1); - return; - } - if (process_mdoc_macro(line)) { - return; - } - xref = strncmp(line, ".Xr", 3) == 0; - line += 3; - while ((line = skip_spaces(line)) < line_end) { - if (*line == '"') { - next = ++line; - for (;;) { - next = strchr(next, '"'); - if (next == NULL) - break; - memmove(next, next + 1, strlen(next)); - line_end--; - if (*next != '"') - break; - next++; - } - } else - next = strpbrk(line, " \t"); - if (next != NULL) - *next++ = '\0'; - else - next = line_end; - if (isupper(*line) && islower(line[1]) && line[2] == '\0') { - if (strcmp(line, "Ns") == 0) { - arg = 0; - line = next; - continue; - } - if (strstr(mdoc_commands, line) != NULL) { - line = next; - continue; - } - } - if (arg > 0 && strchr(",.:;?!)]", *line) == 0) { - if (xref) { - sbuf_append(whatis_proto, "(", 1); - add_nroff(line); - sbuf_append(whatis_proto, ")", 1); - xref = 0; - line = blank; - } else - sbuf_append(whatis_proto, " ", 1); - } - add_nroff(line); - arg++; - line = next; - } - if (sbuf_length(whatis_proto) > orig_length) - sbuf_append(whatis_proto, " ", 1); -} - -enum { STATE_UNKNOWN, STATE_MANSTYLE, STATE_MDOCNAME, STATE_MDOCDESC }; - -/* - * Processes a man page source into a single whatis line and adds it - * to whatis_lines. - */ -static void -process_page(struct page_info *info) -{ - gzFile in; - char buffer[4096]; - char *line; - char *descr; - int state = STATE_UNKNOWN; - struct page_alias *alias; - - /* - * Only read the page once for each inode. It's - * safe to assume that page->list is set. - */ - alias = RB_MIN(page_alias_tree, &info->head); - - if (verbose) { - fprintf(stderr, "\treading %s\n", alias->filename); - } - - sbuf_clear(whatis_proto); - if ((in = gzopen(alias->filename, "r")) == NULL) { - warn("%s", alias->filename); - exit_code = 1; - return; - } - while (gzgets(in, buffer, sizeof buffer) != NULL) { - line = buffer; - if (strncmp(line, ".\\\"", 3) == 0) /* ignore comments */ - continue; - switch (state) { - /* - * haven't reached the NAME section yet. - */ - case STATE_UNKNOWN: - if (name_section_line(line, ".SH")) - state = STATE_MANSTYLE; - else if (name_section_line(line, ".Sh")) - state = STATE_MDOCNAME; - continue; - /* - * Inside an old-style .SH NAME section. - */ - case STATE_MANSTYLE: - if (strncmp(line, ".SH", 3) == 0) - break; - if (strncmp(line, ".SS", 3) == 0) - break; - trim_rhs(line); - if (strcmp(line, ".") == 0) - continue; - if (strncmp(line, ".IX", 3) == 0) { - line += 3; - line = skip_spaces(line); - } - process_man_line(line); - continue; - /* - * Inside a new-style .Sh NAME section (the .Nm part). - */ - case STATE_MDOCNAME: - trim_rhs(line); - if (strncmp(line, ".Nm", 3) == 0) { - process_mdoc_line(line); - continue; - } else { - if (strcmp(line, ".") == 0) - continue; - sbuf_append(whatis_proto, "- ", 2); - state = STATE_MDOCDESC; - } - /* fall through */ - /* - * Inside a new-style .Sh NAME section (after the .Nm-s). - */ - case STATE_MDOCDESC: - if (strncmp(line, ".Sh", 3) == 0) - break; - trim_rhs(line); - if (strcmp(line, ".") == 0) - continue; - process_mdoc_line(line); - continue; - } - break; - } - gzclose(in); - sbuf_strip(whatis_proto, " \t.-"); - line = sbuf_content(whatis_proto); - /* - * line now contains the appropriate data, but without - * the proper indentation or the section appended to each name. - */ - descr = strstr(line, " - "); - if (descr == NULL) { - descr = strchr(line, ' '); - if (descr == NULL) { - if (verbose) - fprintf(stderr, - "\tignoring junk description \"%s\"\n", - line); - return; - } - *descr++ = '\0'; - } else { - *descr = '\0'; - descr += 3; - } - sbuf_clear(whatis_final); - RB_FOREACH(alias, page_alias_tree, &info->head) { - /* - * This won't append names stored in `line'. - * The reason for that is that we cannot be sure - * which section they belong to unless we have - * a real alias (via MLINKS) in this list. - */ - add_whatis_name(alias->name, alias->suffix); - } - if (verbose) { - char *arg, *text = line; - StringList *names; - - names = sl_init(); - - /* - * See if there are names in the manual that - * are not in the alias list provided by the - * MLINKS. We may want to add those as well. - */ - RB_FOREACH(alias, page_alias_tree, &info->head) - sl_add(names, alias->name); - - for (;;) { - arg = text; - text = strchr(text, ','); - if (text != NULL) - *text++ = '\0'; - if (!sl_find(names, arg)) { - fprintf(stderr, "\tpage alias \"%s\" " - "may be missing\n", arg); - } - if (text == NULL) - break; - if (*text == ' ') - text++; - } - - sl_free(names, 0); - } - sbuf_retract(whatis_final, 2); /* remove last ", " */ - while (sbuf_length(whatis_final) < indent) - sbuf_append(whatis_final, " ", 1); - sbuf_append(whatis_final, " - ", 3); - sbuf_append_str(whatis_final, skip_spaces(descr)); - sl_add(whatis_lines, strdup(sbuf_content(whatis_final))); -} - -/* - * Processes a single man section. - */ -static void -process_section(char *section_dir) -{ - struct dirent **entries; - struct page_info *info; - int nentries; - int i; - - if (verbose) - fprintf(stderr, " %s\n", section_dir); - - /* - * scan the man section directory for pages - */ - nentries = scandir(section_dir, &entries, NULL, alphasort); - if (nentries < 0) { - warn("%s", section_dir); - exit_code = 1; - return; - } - - /* - * collect information about man pages - */ - for (i = 0; i < nentries; i++) { - struct page_info ref; - char *filename; - struct stat st; - - if (asprintf(&filename, "%s/%s", section_dir, - entries[i]->d_name) < 0) { - err(1, "malloc"); - } - - if (stat(filename, &st) < 0) { - warn("%s", filename); - goto process_section_next; - } - - if (!S_ISREG(st.st_mode)) { - if (verbose && !S_ISDIR(st.st_mode)) - warnx("%s: not a regular file", filename); - goto process_section_next; - } - - ref.inode = st.st_ino; - - info = RB_FIND(page_info_tree, &page_head, &ref); - if (info == NULL) { - info = malloc(sizeof(*info)); - if (info == NULL) { - err(1, "malloc"); - } - - bzero(info, sizeof(*info)); - info->inode = st.st_ino; - RB_INIT(&info->head); - - RB_INSERT(page_info_tree, &page_head, info); - } - - new_page_alias(info, filename, entries[i]); - -process_section_next: - - free(entries[i]); - free(filename); - } - free(entries); -} - -/* - * Returns whether the directory entry is a man page section. - */ -static int -select_sections(const struct dirent *entry) -{ - const char *p = &entry->d_name[3]; - - if (strncmp(entry->d_name, "man", 3) != 0) - return(0); - while (*p != '\0') { - if (!isalnum(*p++)) - return(0); - } - return(1); -} - -/* - * Processes a single top-level man directory by finding all the - * sub-directories named man* and processing each one in turn. - */ -static void -process_mandir(char *dir_name) -{ - struct dirent **entries; - struct page_info *info; - int nsections; - FILE *fp = NULL; - int i; - struct stat st; - - if (already_visited(dir_name)) - return; - if (verbose) - fprintf(stderr, "man directory %s\n", dir_name); - nsections = scandir(dir_name, &entries, select_sections, alphasort); - if (nsections < 0) { - warn("%s", dir_name); - exit_code = 1; - return; - } - if (common_output == NULL && (fp = open_whatis(dir_name)) == NULL) - return; - for (i = 0; i < nsections; i++) { - char section_dir[MAXPATHLEN]; - snprintf(section_dir, sizeof section_dir, "%s/%s", dir_name, - entries[i]->d_name); - process_section(section_dir); - snprintf(section_dir, sizeof section_dir, "%s/%s/%s", dir_name, - entries[i]->d_name, machine); - if (stat(section_dir, &st) == 0 && S_ISDIR(st.st_mode)) - process_section(section_dir); - free(entries[i]); - } - free(entries); - - /* - * process and free all pages - */ - while ((info = RB_ROOT(&page_head))) { - RB_REMOVE(page_info_tree, &page_head, info); - process_page(info); - free_page_info(info); - } - - if (common_output == NULL) - finish_whatis(fp, dir_name); -} - -/* - * Processes one argument, which may be a colon-separated list of - * directories. - */ -static void -process_argument(const char *arg) -{ - char *dir; - char *mandir; - char *parg; - - parg = strdup(arg); - if (parg == NULL) - err(1, "out of memory"); - while ((dir = strsep(&parg, ":")) != NULL) { - if (locale != NULL) { - asprintf(&mandir, "%s/%s", dir, locale); - process_mandir(mandir); - free(mandir); - if (lang_locale != NULL) { - asprintf(&mandir, "%s/%s", dir, lang_locale); - process_mandir(mandir); - free(mandir); - } - } else { - process_mandir(dir); - } - } - free(parg); -} - - -int -main(int argc, char **argv) -{ - int opt; - FILE *fp = NULL; - - while ((opt = getopt(argc, argv, "ai:n:o:vL")) != -1) { - switch (opt) { - case 'a': - append++; - break; - case 'i': - indent = atoi(optarg); - break; - case 'n': - whatis_name = optarg; - break; - case 'o': - common_output = optarg; - break; - case 'v': - verbose++; - break; - case 'L': - locale = getenv("LC_ALL"); - if (locale == NULL) - locale = getenv("LC_CTYPE"); - if (locale == NULL) - locale = getenv("LANG"); - if (locale != NULL) { - char *sep = strchr(locale, '_'); - if (sep != NULL && isupper(sep[1]) && - isupper(sep[2])) { - asprintf(&lang_locale, "%.*s%s", - (int)(sep - locale), - locale, &sep[3]); - } - } - break; - default: - fprintf(stderr, "usage: %s [-a] [-i indent] [-n name] [-o output_file] [-v] [-L] [directories...]\n", argv[0]); - exit(1); - } - } - - signal(SIGINT, trap_signal); - signal(SIGHUP, trap_signal); - signal(SIGQUIT, trap_signal); - signal(SIGTERM, trap_signal); - SLIST_INIT(&visited_dirs); - whatis_proto = new_sbuf(); - whatis_final = new_sbuf(); - - if ((machine = getenv("MACHINE")) == NULL) - machine = MACHINE; - - if (common_output != NULL && (fp = open_output(common_output)) == NULL) - err(1, "%s", common_output); - if (optind == argc) { - const char *manpath = getenv("MANPATH"); - if (manpath == NULL) - manpath = DEFAULT_MANPATH; - process_argument(manpath); - } else { - while (optind < argc) - process_argument(argv[optind++]); - } - if (common_output != NULL) - finish_output(fp, common_output); - exit(exit_code); -}