home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.minix
- Path: sparky!uunet!mcsun!sun4nl!star.cs.vu.nl!kjb
- From: kjb@cs.vu.nl (Kees J. Bot)
- Subject: Script to transform Andy's manual pages
- Message-ID: <C0p1wt.29L@cs.vu.nl>
- Sender: news@cs.vu.nl
- Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
- Date: Mon, 11 Jan 1993 14:36:28 GMT
- Lines: 294
-
- Recently Andy released the [nt]roff source of the manual pages of the
- Minix commands. Great.
-
- I only have four problems with these pages,
-
- - They need a separate macro set to make them look nice in The Book,
- but I want man(7) style pages.
-
- - Not all the macros were present. (.HS, .MX and other simple ones.)
-
- - My nroff (cawf) choked on them. :-(
-
- - The calendar page has 'december 25' in column 1, put \& before it.
-
- So I wrote a simple script this weekend to transform one of Andy's pages
- to the man(7) form, I think it gets it 99% right. There is also a
- makewhatis script that can produce the whatis(5) database. Maybe
- someone has a use for it.
-
- Take a coffee break if you run these scripts, my 486 needs one full
- minute to run ast2man on all the pages, makewhatis needs another minute.
- 16-bit Minix needs 4+2 minutes, there is nothing like a trashing cache.
-
- Getting rid of the junk in cat[2-7] is my next problem, alas these 130
- pages are to useful to simply rm.
- --
- Kees J. Bot (kjb@cs.vu.nl)
- Systems Programmer, Vrije Universiteit Amsterdam
- _._. .._ _ ._ ._.. ___ _. __. _ .... . _.. ___ _ _ . _.. ._.. .. _. .
- echo x - ast2man.sh
- sed '/^X/s///' > ast2man.sh << '/'
- X#!/bin/sh
- X#
- X# ast2man - Transform Andy's manual pages to man(7) Author: Kees J. Bot
- X#
- X# Transformation:
- X# .TH <name_of_page> 1
- X# .SH NAME
- X# <Arguments of .CD>
- X# .SH SYNOPSIS
- X# <Arguments of .SX>
- X# <New definitions of .FL and .SX>
- X# .SH OPTIONS
- X# .FL ...
- X# .SH EXAMPLES
- X# .SX ... (.SY to .SX)
- X# .SH DESCRIPTION
- X# <The rest of the page>
- X#
- X# Some macros and strings are substituted by:
- X# \(en \- (Oops, don't tell Andy.)
- X# \s \f (NAME section only.)
- X# ~ <space>
- X# \*(OQ \*(CQ \*(SQ \&'
- X# \*(M2 \s-2MINIX\s+2 (I like "Minix" better...)
- X# .MX \s-2MINIX\s+2
- X# .Cx .B "<tab>"
- X# .DI .B
- X# .HS .PP
- X# .SY \&
- X# .UX \s-2UNIX\s+2
- X
- Xcase $# in
- X1) ;;
- X*) echo "Usage: ast2man manual_page" >&2
- Xesac
- X
- X# Make a manual page.
- Xecho ".TH `basename $1` 1
- X.SH NAME" | tr '[a-z]' '[A-Z]'
- X
- X# Transform the command macro.
- Xsed -e '
- X /^\.CD /!d
- X s/\\(en/\\-/g
- X s/~/ /g
- X s/\\\*([OCS]Q/\\\&'\''/g
- X s/\\\*(M2/MINIX/g
- X s/^\.CD "*//
- X s/"* *$//
- X s/\\s0//g
- X s/\\s[-+][0-9]//g
- X s/\\f[RBIP]//g
- X' $1
- X
- X# The syntax.
- Xecho ".SH SYNOPSIS"
- Xsed -e '
- X /^\.SX /!d
- X s/\\(en/\\-/g
- X s/~/ /g
- X s/\\\*([OCS]Q/\\\&'\''/g
- X s/\\\*(M2/\\s-2MINIX\\s+2/g
- X s/^\.SX "*/\\fB/
- X s/"* *$/\\fR/
- X a\
- X.br
- X' $1
- X
- X# Define macros for flags and examples.
- Xecho '.de FL
- X.TP
- X\\fB\\$1\\fR
- X\\$2
- X..
- X.de EX
- X.TP 20
- X\\fB\\$1\\fR
- X# \\$2
- X..'
- X
- X# The flags.
- Xecho ".SH OPTIONS"
- Xsed -e '
- X /^\.FL /!d
- X s/\\(en/\\-/g
- X s/~/ /g
- X s/\\\*([OCS]Q/\\\&'\''/g
- X s/\\\*(M2/\\s-2MINIX\\s+2/g
- X s/^\.FL "\\fR(none)" *$/(none)/
- X' $1
- X
- X# The examples.
- Xecho ".SH EXAMPLES"
- Xsed -e '
- X /^\.E[XY] /!d
- X s/\\(en/\\-/g
- X s/~/ /g
- X s/\\\*([OCS]Q/\\\&'\''/g
- X s/\\\*(M2/\\s-2MINIX\\s+2/g
- X s/^\.EY /.EX /
- X' $1
- X
- X# Extract the body.
- Xecho ".SH DESCRIPTION"
- Xsed -e '
- X /^\.CD /d
- X /^\.SX /d
- X /^\.FL /d
- X /^\.EX /d
- X /^\.EY /d
- X s/\\(en/\\-/g
- X s/\\\*([OCS]Q/\\\&'\''/g
- X s/\\\*(M2/\\s-2MINIX\\s+2/g
- X s/^\.MX */\\s-2MINIX\\s+2/
- X s/^\.Cx /.B " "/
- X s/^\.DI /.B /
- X s/^\.HS/.PP/
- X s/^\.SY /\\\&/
- X s/^\.UX */\\s-2UNIX\\s+2/
- X /^$/d
- X /^\.SP/d
- X' $1
- /
- echo x - makewhatis.sh
- sed '/^X/s///' > makewhatis.sh << '/'
- X#!/bin/sh
- X#
- X# makewhatis 1.0 - make whatis(5) database. Author: Kees J. Bot.
- X#
- X# Make the whatis database of a man directory from the manual pages. This
- X# is no trivial thing, because next to the normal man pages in the man[1-8]
- X# directories, we also have a weird collection of formatted pages in the
- X# cat[1-8] directories that have no formatted counterparts. Add to this
- X# confusion different layouts in each different cat directory...
- X#
- X# Better not make a catman(8) yet.
- X
- Xcase $# in
- X1) ;;
- X*) echo "Usage: $0 <mandir>" >&2
- X exit 1
- Xesac
- X
- Xcd $1 || exit
- X
- X{
- X # First pass, gathering the .SH NAME lines in various forms.
- X
- X # First the man[1-8] directories, they are as it should be. Look
- X # how simple this script could have been.
- X for chap in 1 2 3 4 5 6 7 8
- X do
- X for page in man$chap/*.$chap
- X do
- X test -f "$page" || continue
- X
- X sed -e 's/ / /g
- X /^\.SH NAME/,/^\.SH /!d
- X /^\.SH /d
- X s/\\//' \
- X -e "s/-/($chap) -/" < "$page"
- X done
- X done
- X
- X # The commands in cat[168], look for "Command:", stop at a line
- X # that doesn't start with a space. Ignore pages that have an
- X # unformatted page too. (For if one does run catman(8)).
- X for chap in 1 6 8
- X do
- X for page in cat$chap/*.$chap
- X do
- X test -f "$page" || continue
- X test -f man$chap/`basename "$page"` && continue
- X
- X sed -e 's/ / /g
- X /^Command:/,/^[^ ]/!d
- X s/^Command:/ /
- X /^[^ ]/d
- X s/\\//' \
- X -e "s/-/($chap) -/" < "$page" | \
- X tr '\012' ' '
- X echo
- X done
- X done
- X
- X # The system calls and libraries in cat[23], the description may be
- X # found after "Name:", "NAME", "SYSTEM CALLS", or "SUBROUTINES".
- X for chap in 2 3
- X do
- X for page in cat$chap/*.$chap
- X do
- X test -f "$page" || continue
- X test -f man$chap/`basename "$page"` && continue
- X
- X sed -e 's/ / /g
- X /^Name:/,/^[^ ]/!d
- X s/^Name:/ /
- X /^[^ ]/d' \
- X -e "s/-/($chap) -/" < "$page" | \
- X tr '\012' ' '
- X echo
- X
- X sed -e 's/ / /g
- X /^NAME/,/^[^ ]/!d
- X s/^NAME/ /
- X /^[^ ]/d' \
- X -e "s/-/($chap) -/" < "$page" | \
- X tr '\012' ' '
- X echo
- X
- X sed -e 's/ / /g
- X /^SYSTEM CALLS/,/^[^ ]/!d
- X s/^SYSTEM CALLS/ /
- X /^[^ ]/d' \
- X -e "s/-/($chap) -/" < "$page" | \
- X tr '\012' ' '
- X echo
- X
- X sed -e 's/ / /g
- X /^SUBROUTINES/,/^[^ ]/!d
- X s/^SUBROUTINES/ /
- X /^[^ ]/d' \
- X -e "s/-/($chap) -/" < "$page" | \
- X tr '\012' ' '
- X echo
- X done
- X done
- X
- X # Cat4 contains file formats, this should really be cat5. (Cat4 is
- X # for devices.) But as cat5 contains nothing but junk, we can treat
- X # the two directories the same and hope that things get cleared up
- X # one day. The whatis line can be found after "File:", but ends at
- X # an empty line for a change.
- X for chap in 4 5
- X do
- X for page in cat$chap/*.$chap
- X do
- X test -f "$page" || continue
- X test -f man$chap/`basename "$page"` && continue
- X
- X sed -e 's/ / /g
- X /^File:/,/^ *$/!d
- X s/^File:/ /' \
- X -e "s/-/($chap) -/" < "$page" | \
- X tr '\012' ' '
- X echo
- X done
- X done
- X
- X # Do not bother with cat7 yet.
- X} | {
- X # Second pass, remove empty lines, leading and trailing spaces,
- X # multiple spaces to one space, remove lines without a dash.
- X sed -e 's/ */ /g
- X s/^ //
- X s/ $//
- X /^$/d
- X /-/!d'
- X} | {
- X # Third pass, sort uniquely
- X sort -u
- X} > whatis
- /
-