Advertisement
Guest User

Untitled

a guest
Jan 5th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.80 KB | None | 0 0
  1. #!/bin/sh
  2. # Generated automatically from makewhatis.in by the
  3. # configure script.
  4. #
  5. #!/bin/sh
  6. # makewhatis: create the whatis database
  7. # Created: Sun Jun 14 10:49:37 1992
  8. # Revised: Sat Jan 8 14:12:37 1994 by faith@cs.unc.edu
  9. # Revised: Sat Mar 23 17:56:18 1996 by micheal@actrix.gen.nz
  10. # Copyright 1992, 1993, 1994 Rickard E. Faith (faith@cs.unc.edu)
  11. # May be freely distributed and modified as long as copyright is retained.
  12. #
  13. # Wed Dec 23 13:27:50 1992: Rik Faith (faith@cs.unc.edu) applied changes
  14. # based on Mitchum DSouza (mitchum.dsouza@mrc-apu.cam.ac.uk) cat patches.
  15. # Also, cleaned up code and make it work with NET-2 doc pages.
  16. #
  17. # makewhatis-1.4: aeb 940802, 941007, 950417
  18. # Fixed so that the -c option works correctly for the cat pages
  19. # on my machine. Fix for -u by Nan Zou (nan@ksu.ksu.edu).
  20. # Many minor changes.
  21. # The -s option is undocumented, and may well disappear again.
  22. #
  23. # Sat Mar 23 1996: Michael Hamilton (michael@actrix.gen.nz).
  24. # I changed the script to invoke gawk only once for each directory tree.
  25. # This speeds things up considerably (from 30 minutes down to 1.5 minutes
  26. # on my 486DX66).
  27. # 960401 - aeb: slight adaptation to work correctly with cat pages.
  28. # 960510 - added fixes by brennan@raven.ca.boeing.com, author of mawk.
  29. # 971012 - replaced "test -z" - it doesnt work on SunOS 4.1.3_U1.
  30. # 980710 - be more careful with TMPFILE.
  31. # 000323 - do not change PATH, better treatment of catpages - Bryan Henderson.
  32. # 011117 - avoid suspicious filenames.
  33. # 030310 - find files only; fix LAPACK cruft; no /usr/man default;
  34. # use /dev/stderr instead of /dev/tty; handle files with strange names;
  35. # add support for chinese, hungarian, indonesian, japanese, korean,
  36. # polish, russian (Thierry Vignaud).
  37. #
  38. # makewhatis 1.6: Federico Lucifredi
  39. # 060608 - Corrected traps.
  40. # 060719 - section choosing behavior to match man's (Mike frysinger).
  41. #
  42. # Note for Slackware users: "makewhatis -v -w -c" will work.
  43. #
  44. # makewhatis flc 060719 (from man-1.6g)
  45.  
  46. program=`basename $0`
  47.  
  48. # In case both /usr/man and /usr/share/man exist, the former is local
  49. # and should be first.
  50. # It is a bug to add /var/cache/man to DEFCATPATH.
  51. dm=
  52. for d in /usr/man /usr/share/man /usr/X11R6/man /usr/local/man
  53. do
  54. if [ -d $d ]; then
  55. if [ x$dm = x ]; then dm=$d; else dm=$dm:$d; fi
  56. fi
  57. done
  58. DEFMANPATH=$dm
  59. dc=
  60. for d in /usr/man/preformat /usr/man /usr/share/man/preformat /usr/share/man
  61. do
  62. if [ -d $d ]; then
  63. if [ x$dc = x ]; then dc=$d; else dc=$dc:$d; fi
  64. fi
  65. done
  66. DEFCATPATH=$dc
  67.  
  68. # In case /usr is read-only, make /usr/foo/whatis (etc) a symlink to
  69. # something like /var/cache/man/foo-whatis.
  70. # Some distributions make a single big /var/cache/man/whatis file,
  71. # but that leads to problems and bugs.
  72.  
  73. # AWK=/usr/bin/gawk
  74. AWK=/bin/awk
  75.  
  76. # Find a place for our temporary files. If security is not a concern, use
  77. # TMPFILE=/tmp/whatis$$; TMPFILEDIR=none
  78. # Of course makewhatis should only have the required permissions
  79. # (for reading and writing directories like /usr/man).
  80. # We try here to be careful (and avoid preconstructed symlinks)
  81. # in case makewhatis is run as root, by creating a subdirectory of /tmp.
  82.  
  83. TMPFILEDIR=/tmp/whatis.tmp.dir.$$
  84. rm -rf $TMPFILEDIR
  85. if ! mkdir -m 0700 $TMPFILEDIR; then
  86. echo Could not create $TMPFILEDIR
  87. exit 1;
  88. fi
  89. TMPFILE=$TMPFILEDIR/w
  90.  
  91. # make sure TMPFILEDIR is deleted if program is killed or terminates
  92. # (just delete this line if your shell doesnt know about trap)
  93. trap "rm -rf $TMPFILEDIR" 0
  94. trap "rm -rf $TMPFILEDIR; exit 255" 1 2 3 15
  95.  
  96. # default find arg: no directories, no empty files
  97. findarg0="-type f -size +0"
  98.  
  99. topath=manpath
  100.  
  101. defmanpath=$DEFMANPATH
  102. defcatpath=
  103.  
  104. if [ -n "$MANSECT" ]; then
  105. sections=$MANSECT
  106. else
  107. sections=`$AWK '($1 == "MANSECT") { print $2 }' /usr/lib64/man.conf`
  108. if [ x"$sections" = x ]; then
  109. sections="1:1p:8:2:3:3p:4:5:6:7:9:0p:tcl:n:l:p:o"
  110. fi
  111. fi
  112. sections=`echo $sections | sed -e 's/:/ /g'`
  113.  
  114. for name in "$@"
  115. do
  116. if [ -n "$setsections" ]; then
  117. setsections=
  118. sections=$name
  119. continue
  120. fi
  121. case $name in
  122. --version|-V)
  123. echo "$program from man-1.6g"
  124. exit 0;;
  125. -c) topath=catpath
  126. defmanpath=
  127. defcatpath=$DEFCATPATH
  128. continue;;
  129. -s) setsections=1
  130. continue;;
  131. -u) findarg="-ctime 0"
  132. update=1
  133. continue;;
  134. -v) verbose=1
  135. continue;;
  136. -w) manpath=`man --path`
  137. catpath=$manpath
  138. continue;;
  139. -*) echo "Usage: makewhatis [-s sections] [-u] [-v] [-w] [manpath] [-c [catpath]]"
  140. echo " This will build the whatis database for the man pages"
  141. echo " found in manpath and the cat pages found in catpath."
  142. echo " -s: sections (default: $sections)"
  143. echo " -u: update database with new pages"
  144. echo " -v: verbose"
  145. echo " -w: use manpath obtained from \`man --path\`"
  146. echo " [manpath]: man directories (default: $DEFMANPATH)"
  147. echo " [catpath]: cat directories (default: the first existing"
  148. echo " directory in $DEFCATPATH)"
  149. exit;;
  150. *) if [ -d $name ]
  151. then
  152. eval $topath="\$$topath":$name
  153. else
  154. echo "No such directory $name"
  155. exit
  156. fi;;
  157. esac
  158. done
  159.  
  160. manpath=`echo ${manpath-$defmanpath} | tr : ' '`
  161. if [ x"$catpath" = x ]; then
  162. for d in `echo $defcatpath | tr : ' '`
  163. do
  164. if [ -d $d ]; then catpath=$d; break; fi
  165. done
  166. fi
  167. catpath=`echo ${catpath} | tr : ' '`
  168.  
  169. # first truncate all the whatis files that will be created new,
  170. # then only update - we might visit the same directory twice
  171. if [ x$update = x ]; then
  172. for pages in man cat
  173. do
  174. eval path="\$$pages"path
  175. for mandir in $path
  176. do
  177. cp /dev/null $mandir/whatis
  178. done
  179. done
  180. fi
  181.  
  182. for pages in man cat
  183. do
  184. export pages
  185. eval path="\$$pages"path
  186. for mandir in $path
  187. do
  188. if [ x$verbose != x ]; then
  189. echo "about to enter $mandir" > /dev/stderr
  190. fi
  191.  
  192. # kludge for Slackware's /usr/man/preformat
  193. if [ $mandir = /usr/man/preformat ]
  194. then
  195. mandir1=/usr/man
  196. else
  197. mandir1=$mandir
  198. fi
  199.  
  200. # if $mandir is on a readonly partition, and the whatis file
  201. # is not a symlink, then let's skip trying to update it
  202. if [ ! -L ${mandir1}/whatis ]
  203. then
  204. if [ -e ${mandir1}/whatis ] && [ ! -w ${mandir1}/whatis ]
  205. then
  206. if [ x$verbose != x ]; then
  207. echo skipping $mandir - whatis file is readonly > /dev/stderr
  208. fi
  209. continue
  210. elif [ ! -e ${mandir1}/whatis ] && [ ! -w ${mandir1} ]
  211. then
  212. if [ x$verbose != x ]; then
  213. echo skipping $mandir - directory is readonly > /dev/stderr
  214. fi
  215. continue
  216. fi
  217. fi
  218.  
  219. if [ -s ${mandir}/whatis -a $pages = man -a x$update = x ]; then
  220. if [ x$verbose != x ]; then
  221. echo skipping $mandir - we did it already > /dev/stderr
  222. fi
  223. else
  224. here=`pwd`
  225. cd $mandir
  226. for i in $sections
  227. do
  228. if [ -d ${pages}$i ]
  229. then
  230. cd ${pages}$i
  231. section=$i
  232. curdir=$mandir/${pages}$i
  233. export section verbose curdir
  234. find $mandir/${pages}$i/. -name '*' $findarg0 $findarg -print | $AWK '
  235.  
  236. function readline() {
  237. if (use_zcat || use_bzcat || use_lzcat) {
  238. result = (pipe_cmd | getline);
  239. if (result < 0) {
  240. print "Pipe error: " pipe_cmd " " ERRNO > "/dev/stderr";
  241. }
  242. } else {
  243. result = (getline < filename);
  244. if (result < 0) {
  245. print "Read file error: " filename " " ERRNO > "/dev/stderr";
  246. }
  247. }
  248. return result;
  249. }
  250.  
  251. function closeline() {
  252. if (use_zcat || use_bzcat || use_lzcat) {
  253. return close(pipe_cmd);
  254. } else {
  255. return close(filename);
  256. }
  257. }
  258.  
  259. function do_one() {
  260. insh = 0; thisjoin = 1; done = 0;
  261. entire_line = "";
  262.  
  263. if (verbose) {
  264. print "adding " filename > "/dev/stderr"
  265. }
  266.  
  267. use_zcat = match(filename,"\\.Z$") ||
  268. match(filename,"\\.z$") || match(filename,"\\.gz$");
  269. if (!use_zcat)
  270. use_bzcat = match(filename,"\\.bz2");
  271. if(!use_bzcat)
  272. use_lzcat = match(filename,"\\.lzma");
  273. if (use_zcat || use_bzcat || use_lzcat ) {
  274. filename_no_gz = substr(filename, 0, RSTART - 1);
  275. } else {
  276. filename_no_gz = filename;
  277. }
  278. match(filename_no_gz, "/[^/]+$");
  279. progname = substr(filename, RSTART + 1, RLENGTH - 1);
  280. if (match(progname, "\\." section "[A-Za-z]+")) {
  281. actual_section = substr(progname, RSTART + 1, RLENGTH - 1);
  282. } else {
  283. actual_section = section;
  284. }
  285. sub(/\..*/, "", progname);
  286. if (use_zcat || use_bzcat || use_lzcat) {
  287. if (use_zcat) {
  288. pipe_cmd = "zcat '\''" filename "'\''";
  289. } else if (use_bzcat) {
  290. pipe_cmd = "bzcat \"" filename "\"";
  291. } else {
  292. pipe_cmd = "lzcat \"" filename "\"";
  293. }
  294. # try to avoid suspicious stuff
  295. }
  296.  
  297. while (!done && readline() > 0) {
  298. gsub(/.\b/, "");
  299. if (($1 ~ /^\.[Ss][Hh]/ &&
  300. ($2 ~ /[Nn][Aa][Mm][Ee]/ ||
  301. $2 ~ /^JMЙNO/ || $2 ~ /^NAVN/ || $2 ~ /^NUME/ ||
  302. $2 ~ /^BEZEICHNUNG/ || $2 ~ /^NOMBRE/ ||
  303. $2 ~ /^NIMI/ || $2 ~ /^NOM/ || $2 ~ /^IME/ ||
  304. $2 ~ /^N[ЙE]V/ || $2 ~ /^NAMA/ || $2 ~ /^МѕБ°/ ||
  305. $2 ~ /^МѕѕО/ || $2 ~ /^АМё§/ || $2 ~ /^NAZWA/ ||
  306. $2 ~ /^объчбойе/ || $2 ~ /^ГыіЖ/ || $2 ~ /^¦WєЩ/ ||
  307. $2 ~ /^NOME/ || $2 ~ /^NAAM/ || $2 ~ /^ИМЕ/)) ||
  308. (pages == "cat" && $1 ~ /^NAME/)) {
  309. if (!insh) {
  310. insh = 1;
  311. } else {
  312. done = 1;
  313. }
  314. } else if (insh) {
  315. if ($1 ~ /^\.[Ss][HhYS]/ ||
  316. (pages == "cat" &&
  317. ($1 ~ /^S[yYeE]/ || $1 ~ /^DESCRIPTION/ ||
  318. $1 ~ /^COMMAND/ || $1 ~ /^OVERVIEW/ ||
  319. $1 ~ /^STRUCTURES/ || $1 ~ /^INTRODUCTION/ ||
  320. $0 ~ /^[^ ]/))) {
  321. # end insh for Synopsis, Syntax, but also for
  322. # DESCRIPTION (e.g., XFree86.1x),
  323. # COMMAND (e.g., xspread.1)
  324. # OVERVIEW (e.g., TclCommandWriting.3)
  325. # STRUCTURES (e.g., XEvent.3x)
  326. # INTRODUCTION (e.g., TclX.n)
  327. # and anything at all that begins in Column 1, so
  328. # is probably a section header.
  329. done = 1;
  330. } else {
  331. if ($0 ~ progname"-") { # Fix old cat pages
  332. sub(progname"-", progname" - ");
  333. }
  334. if ($0 ~ /[^ \\]-$/) {
  335. sub(/-$/, ""); # Handle Hyphenations
  336. nextjoin = 1;
  337. } else if ($0 ~ /\\c$/) {
  338. sub(/\\c$/, ""); # Handle Continuations
  339. nextjoin = 1;
  340. } else
  341. nextjoin = 0;
  342.  
  343. sub(/^.[IB] /, ""); # Kill bold and italics
  344. sub(/^.BI /, ""); #
  345. sub(/^.SM /, ""); # Kill small
  346. sub(/^.Nm /, ""); # Kill bold
  347. sub(/^.Tn /, ""); # Kill normal
  348. sub(/^.Li /, ""); # Kill .Li
  349. sub(/^.Dq /, ""); # Kill .Dq
  350. sub(/^.Nd */, "- "); # Convert .Nd to dash
  351. sub(/\\\".*/, ""); # Trim pending comments
  352. sub(/ *$/, ""); # Trim pending spaces
  353. sub(/^\.$/, ""); # Kill blank comments
  354. sub(/^'"'"'.*/, ""); # Kill comment/troff lines
  355. sub(/^.in .*/, ""); # Kill various macros
  356. sub(/^.ti .*/, "");
  357. sub(/^.ta .*/, "");
  358. sub(/^.Vb .*/, "");
  359. sub(/^.[PLTH]P$/, ""); # .PP/.LP/.TP/.HP
  360. sub(/^.Pp$/, "");
  361. sub(/^.[iI]X .*$/, "");
  362. sub(/^.nolinks$/, "");
  363. sub(/^.B$/, "");
  364. sub(/^.nf$/, "");
  365.  
  366. if (($1 ~ /^\.../ || $1 == "") &&
  367. (entire_line ~ / - / || entire_line ~ / \\- /)) {
  368. # Assume that this ends the description of one line
  369. # Sometimes there are several descriptions in one page,
  370. # as in outb(2).
  371. handle_entire_line();
  372. entire_line = "";
  373. thisjoin = 1;
  374. } else {
  375. if (thisjoin) {
  376. entire_line = entire_line $0;
  377. } else {
  378. entire_line = entire_line " " $0;
  379. }
  380. thisjoin = nextjoin;
  381. }
  382. }
  383. }
  384. }
  385. handle_entire_line();
  386. closeline();
  387. }
  388.  
  389. function handle_entire_line() {
  390. x = entire_line; # Keep it short
  391.  
  392. gsub(/\015/, "", x); # Kill DOS remains
  393. gsub(/ /, " ", x); # Translate tabs to spaces
  394. gsub(/ +/, " ", x); # Collapse spaces
  395. gsub(/ *, */, ", ", x); # Fix comma spacings
  396. sub(/^ /, "", x); # Kill initial spaces
  397. sub(/ $/, "", x); # Kill trailing spaces
  398. sub(/__+/, "_", x); # Collapse underscores
  399.  
  400. gsub(/\\f\(../, "", x); # Kill font changes
  401. gsub(/\\f[PRIB0123]/, "", x); # Kill font changes
  402. gsub(/\\s[-+0-9]*/, "", x); # Kill size changes
  403. gsub(/\\&/, "", x); # Kill \&
  404. gsub(/\\\|/, "", x); # Kill \|
  405. gsub(/\\\((ru|ul)/, "_", x); # Translate
  406. gsub(/\\\((mi|hy|em)/, "-", x); # Translate
  407. gsub(/\\\*\(../, "", x); # Kill troff strings
  408. gsub(/\\/, "", x); # Kill all backslashes
  409. gsub(/"/, "", x); # Kill quotes (from .Nd "foo bar")
  410. sub(/<h1 align=center>/, "", x);# Yuk! HTML cruft
  411. gsub(/\000.*/, "X", x); # Binary cruft in LAPACK pages
  412. gsub(/ +/, " ", x); # Collapse spaces (again)
  413. sub(/^ /, "", x); # Kill initial spaces (again)
  414. sub(/ $/, "", x); # Kill trailing spaces (again)
  415. sub(/\.$/, "", x); # Kill trailing period
  416.  
  417. if (!match(x, / - /))
  418. return;
  419.  
  420. after_dash = substr(x, RSTART);
  421. head = substr(x, 1, RSTART-1) ", ";
  422. while (match(head, /, /)) {
  423. prog = substr(head, 1, RSTART-1);
  424. head = substr(head, RSTART+2);
  425. if (prog != progname)
  426. prog = prog " [" progname "]";
  427. printf "%-*s (%s) %s\n", 20, prog, actual_section, after_dash;
  428. }
  429. }
  430.  
  431. { # Main action - process each filename read in.
  432. filename = $0;
  433. do_one();
  434. }
  435. ' pages=$pages section=$section verbose=$verbose curdir=$curdir
  436. cd ..
  437. fi
  438. done > $TMPFILE
  439.  
  440. cd "$here"
  441.  
  442. if [ -f ${mandir1}/whatis ]
  443. then
  444. cat ${mandir1}/whatis >> $TMPFILE
  445. fi
  446. tr -s '\n' < $TMPFILE | sort -u > ${mandir1}/whatis
  447.  
  448. chmod 644 ${mandir1}/whatis
  449. rm $TMPFILE
  450. fi
  451. done
  452. done
  453.  
  454. # remove tempdir
  455. rm -rf $TMPFILEDIR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement