home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / minix / 5122 < prev    next >
Encoding:
Text File  |  1993-01-11  |  6.8 KB  |  305 lines

  1. Newsgroups: comp.os.minix
  2. Path: sparky!uunet!mcsun!sun4nl!star.cs.vu.nl!kjb
  3. From: kjb@cs.vu.nl (Kees J. Bot)
  4. Subject: Script to transform Andy's manual pages
  5. Message-ID: <C0p1wt.29L@cs.vu.nl>
  6. Sender: news@cs.vu.nl
  7. Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
  8. Date: Mon, 11 Jan 1993 14:36:28 GMT
  9. Lines: 294
  10.  
  11. Recently Andy released the [nt]roff source of the manual pages of the
  12. Minix commands.  Great.
  13.  
  14. I only have four problems with these pages,
  15.  
  16.   - They need a separate macro set to make them look nice in The Book,
  17.     but I want man(7) style pages.
  18.  
  19.   - Not all the macros were present.  (.HS, .MX and other simple ones.)
  20.  
  21.   - My nroff (cawf) choked on them.  :-(
  22.  
  23.   - The calendar page has 'december 25' in column 1, put \& before it.
  24.  
  25. So I wrote a simple script this weekend to transform one of Andy's pages
  26. to the man(7) form, I think it gets it 99% right.  There is also a
  27. makewhatis script that can produce the whatis(5) database.  Maybe
  28. someone has a use for it.
  29.  
  30. Take a coffee break if you run these scripts, my 486 needs one full
  31. minute to run ast2man on all the pages, makewhatis needs another minute.
  32. 16-bit Minix needs 4+2 minutes, there is nothing like a trashing cache.
  33.  
  34. Getting rid of the junk in cat[2-7] is my next problem, alas these 130
  35. pages are to useful to simply rm.
  36. --
  37.                             Kees J. Bot  (kjb@cs.vu.nl)
  38.                   Systems Programmer, Vrije Universiteit Amsterdam
  39. _._. .._ _   ._ ._.. ___ _. __.   _ .... .   _.. ___ _ _ . _..   ._.. .. _. .
  40. echo x - ast2man.sh
  41. sed '/^X/s///' > ast2man.sh << '/'
  42. X#!/bin/sh
  43. X#
  44. X# ast2man - Transform Andy's manual pages to man(7)    Author: Kees J. Bot
  45. X#
  46. X# Transformation:
  47. X#    .TH <name_of_page> 1
  48. X#    .SH NAME
  49. X#    <Arguments of .CD>
  50. X#    .SH SYNOPSIS
  51. X#    <Arguments of .SX>
  52. X#    <New definitions of .FL and .SX>
  53. X#    .SH OPTIONS
  54. X#    .FL ...
  55. X#    .SH EXAMPLES
  56. X#    .SX ...        (.SY to .SX)
  57. X#    .SH DESCRIPTION
  58. X#    <The rest of the page>
  59. X#
  60. X# Some macros and strings are substituted by:
  61. X#    \(en            \-        (Oops, don't tell Andy.)
  62. X#    \s \f                    (NAME section only.)
  63. X#    ~            <space>
  64. X#    \*(OQ  \*(CQ  \*(SQ    \&'
  65. X#    \*(M2            \s-2MINIX\s+2    (I like "Minix" better...)
  66. X#    .MX            \s-2MINIX\s+2
  67. X#    .Cx            .B "<tab>"
  68. X#    .DI            .B
  69. X#    .HS            .PP
  70. X#    .SY            \&
  71. X#    .UX            \s-2UNIX\s+2
  72. X
  73. Xcase $# in
  74. X1)    ;;
  75. X*)    echo "Usage: ast2man manual_page" >&2
  76. Xesac
  77. X
  78. X# Make a manual page.
  79. Xecho ".TH `basename $1` 1
  80. X.SH NAME" | tr '[a-z]' '[A-Z]'
  81. X
  82. X# Transform the command macro.
  83. Xsed -e '
  84. X    /^\.CD /!d
  85. X    s/\\(en/\\-/g
  86. X    s/~/ /g
  87. X    s/\\\*([OCS]Q/\\\&'\''/g
  88. X    s/\\\*(M2/MINIX/g
  89. X    s/^\.CD "*//
  90. X    s/"* *$//
  91. X    s/\\s0//g
  92. X    s/\\s[-+][0-9]//g
  93. X    s/\\f[RBIP]//g
  94. X' $1
  95. X
  96. X# The syntax.
  97. Xecho ".SH SYNOPSIS"
  98. Xsed -e '
  99. X    /^\.SX /!d
  100. X    s/\\(en/\\-/g
  101. X    s/~/ /g
  102. X    s/\\\*([OCS]Q/\\\&'\''/g
  103. X    s/\\\*(M2/\\s-2MINIX\\s+2/g
  104. X    s/^\.SX "*/\\fB/
  105. X    s/"* *$/\\fR/
  106. X    a\
  107. X.br
  108. X' $1
  109. X
  110. X# Define macros for flags and examples.
  111. Xecho '.de FL
  112. X.TP
  113. X\\fB\\$1\\fR
  114. X\\$2
  115. X..
  116. X.de EX
  117. X.TP 20
  118. X\\fB\\$1\\fR
  119. X# \\$2
  120. X..'
  121. X
  122. X# The flags.
  123. Xecho ".SH OPTIONS"
  124. Xsed -e '
  125. X    /^\.FL /!d
  126. X    s/\\(en/\\-/g
  127. X    s/~/ /g
  128. X    s/\\\*([OCS]Q/\\\&'\''/g
  129. X    s/\\\*(M2/\\s-2MINIX\\s+2/g
  130. X    s/^\.FL "\\fR(none)" *$/(none)/
  131. X' $1
  132. X
  133. X# The examples.
  134. Xecho ".SH EXAMPLES"
  135. Xsed -e '
  136. X    /^\.E[XY] /!d
  137. X    s/\\(en/\\-/g
  138. X    s/~/ /g
  139. X    s/\\\*([OCS]Q/\\\&'\''/g
  140. X    s/\\\*(M2/\\s-2MINIX\\s+2/g
  141. X    s/^\.EY /.EX /
  142. X' $1
  143. X
  144. X# Extract the body.
  145. Xecho ".SH DESCRIPTION"
  146. Xsed -e '
  147. X    /^\.CD /d
  148. X    /^\.SX /d
  149. X    /^\.FL /d
  150. X    /^\.EX /d
  151. X    /^\.EY /d
  152. X    s/\\(en/\\-/g
  153. X    s/\\\*([OCS]Q/\\\&'\''/g
  154. X    s/\\\*(M2/\\s-2MINIX\\s+2/g
  155. X    s/^\.MX */\\s-2MINIX\\s+2/
  156. X    s/^\.Cx /.B "    "/
  157. X    s/^\.DI /.B /
  158. X    s/^\.HS/.PP/
  159. X    s/^\.SY /\\\&/
  160. X    s/^\.UX */\\s-2UNIX\\s+2/
  161. X    /^$/d
  162. X    /^\.SP/d
  163. X' $1
  164. /
  165. echo x - makewhatis.sh
  166. sed '/^X/s///' > makewhatis.sh << '/'
  167. X#!/bin/sh
  168. X#
  169. X# makewhatis 1.0 - make whatis(5) database.    Author: Kees J. Bot.
  170. X#
  171. X# Make the whatis database of a man directory from the manual pages.  This
  172. X# is no trivial thing, because next to the normal man pages in the man[1-8]
  173. X# directories, we also have a weird collection of formatted pages in the
  174. X# cat[1-8] directories that have no formatted counterparts.  Add to this
  175. X# confusion different layouts in each different cat directory...
  176. X#
  177. X# Better not make a catman(8) yet.
  178. X
  179. Xcase $# in
  180. X1)    ;;
  181. X*)    echo "Usage: $0 <mandir>" >&2
  182. X    exit 1
  183. Xesac
  184. X
  185. Xcd $1 || exit
  186. X
  187. X{
  188. X    # First pass, gathering the .SH NAME lines in various forms.
  189. X
  190. X    # First the man[1-8] directories, they are as it should be.  Look
  191. X    # how simple this script could have been.
  192. X    for chap in 1 2 3 4 5 6 7 8
  193. X    do
  194. X        for page in man$chap/*.$chap
  195. X        do
  196. X            test -f "$page" || continue
  197. X
  198. X            sed -e 's/    / /g
  199. X                /^\.SH NAME/,/^\.SH /!d
  200. X                /^\.SH /d
  201. X                s/\\//' \
  202. X                -e "s/-/($chap) -/" < "$page"
  203. X        done
  204. X    done
  205. X
  206. X    # The commands in cat[168], look for "Command:", stop at a line
  207. X    # that doesn't start with a space.  Ignore pages that have an
  208. X    # unformatted page too.  (For if one does run catman(8)).
  209. X    for chap in 1 6 8
  210. X    do
  211. X        for page in cat$chap/*.$chap
  212. X        do
  213. X            test -f "$page" || continue
  214. X            test -f man$chap/`basename "$page"` && continue
  215. X
  216. X            sed -e 's/    / /g
  217. X                /^Command:/,/^[^ ]/!d
  218. X                s/^Command:/ /
  219. X                /^[^ ]/d
  220. X                s/\\//' \
  221. X                -e "s/-/($chap) -/" < "$page" | \
  222. X            tr '\012' ' '
  223. X            echo
  224. X        done
  225. X    done
  226. X
  227. X    # The system calls and libraries in cat[23], the description may be
  228. X    # found after "Name:", "NAME", "SYSTEM CALLS", or "SUBROUTINES".
  229. X    for chap in 2 3
  230. X    do
  231. X        for page in cat$chap/*.$chap
  232. X        do
  233. X            test -f "$page" || continue
  234. X            test -f man$chap/`basename "$page"` && continue
  235. X
  236. X            sed -e 's/    / /g
  237. X                /^Name:/,/^[^ ]/!d
  238. X                s/^Name:/ /
  239. X                /^[^ ]/d' \
  240. X                -e "s/-/($chap) -/" < "$page" | \
  241. X            tr '\012' ' '
  242. X            echo
  243. X
  244. X            sed -e 's/    / /g
  245. X                /^NAME/,/^[^ ]/!d
  246. X                s/^NAME/ /
  247. X                /^[^ ]/d' \
  248. X                -e "s/-/($chap) -/" < "$page" | \
  249. X            tr '\012' ' '
  250. X            echo
  251. X
  252. X            sed -e 's/    / /g
  253. X                /^SYSTEM CALLS/,/^[^ ]/!d
  254. X                s/^SYSTEM CALLS/ /
  255. X                /^[^ ]/d' \
  256. X                -e "s/-/($chap) -/" < "$page" | \
  257. X            tr '\012' ' '
  258. X            echo
  259. X
  260. X            sed -e 's/    / /g
  261. X                /^SUBROUTINES/,/^[^ ]/!d
  262. X                s/^SUBROUTINES/ /
  263. X                /^[^ ]/d' \
  264. X                -e "s/-/($chap) -/" < "$page" | \
  265. X            tr '\012' ' '
  266. X            echo
  267. X        done
  268. X    done
  269. X
  270. X    # Cat4 contains file formats, this should really be cat5.  (Cat4 is
  271. X    # for devices.)  But as cat5 contains nothing but junk, we can treat
  272. X    # the two directories the same and hope that things get cleared up
  273. X    # one day.  The whatis line can be found after "File:", but ends at
  274. X    # an empty line for a change.
  275. X    for chap in 4 5
  276. X    do
  277. X        for page in cat$chap/*.$chap
  278. X        do
  279. X            test -f "$page" || continue
  280. X            test -f man$chap/`basename "$page"` && continue
  281. X
  282. X            sed -e 's/    / /g
  283. X                /^File:/,/^ *$/!d
  284. X                s/^File:/ /' \
  285. X                -e "s/-/($chap) -/" < "$page" | \
  286. X            tr '\012' ' '
  287. X            echo
  288. X        done
  289. X    done
  290. X
  291. X    # Do not bother with cat7 yet.
  292. X} | {
  293. X    # Second pass, remove empty lines, leading and trailing spaces,
  294. X    # multiple spaces to one space, remove lines without a dash.
  295. X    sed -e 's/  */ /g
  296. X        s/^ //
  297. X        s/ $//
  298. X        /^$/d
  299. X        /-/!d'
  300. X} | {
  301. X    # Third pass, sort uniquely
  302. X    sort -u
  303. X} > whatis
  304. /
  305.