Advertisement
Guest User

Untitled

a guest
Jun 17th, 2017
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.15 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/share/man /usr/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 /var/cache/man /usr/share/man/preformat /usr/man/preformat /usr/share/man /usr/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=`mktemp -d /tmp/makewhatisXXXXXX`
  84. if [ $? -ne 0 ]; then
  85. echo "$0: Can't create temp file, exiting..."
  86. exit 1
  87. fi
  88. chmod 0700 $TMPFILEDIR
  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 }' /etc/man.config`
  108. if [ x"$sections" = x ]; then
  109. sections="1:1p:8:2:3:3p:3pm: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 || use_xzcat) {
  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 || use_xzcat) {
  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_xzcat = match(filename,"\\.xz");
  268. if (!use_xzcat)
  269. use_zcat = match(filename,"\\.Z$") ||
  270. match(filename,"\\.z$") || match(filename,"\\.gz$");
  271. if (!use_zcat)
  272. use_bzcat = match(filename,"\\.bz2");
  273. if(!use_bzcat)
  274. use_lzcat = match(filename,"\\.lzma");
  275. if (use_zcat || use_bzcat || use_lzcat ) {
  276. filename_no_gz = substr(filename, 0, RSTART - 1);
  277. } else {
  278. filename_no_gz = filename;
  279. }
  280. match(filename_no_gz, "/[^/]+$");
  281. progname = substr(filename, RSTART + 1, RLENGTH - 1);
  282. if (match(progname, "\\." section "[A-Za-z]+")) {
  283. actual_section = substr(progname, RSTART + 1, RLENGTH - 1);
  284. } else {
  285. actual_section = section;
  286. }
  287. sub(/\..*/, "", progname);
  288. if (use_zcat || use_bzcat || use_lzcat || use_xzcat) {
  289. if (use_xzcat) {
  290. pipe_cmd = "xzcat \"" filename "\"";
  291. } else if (use_zcat) {
  292. pipe_cmd = "zcat \"" filename "\"";
  293. } else if (use_bzcat) {
  294. pipe_cmd = "bzcat \"" filename "\"";
  295. } else {
  296. pipe_cmd = "lzcat \"" filename "\"";
  297. }
  298. # try to avoid suspicious stuff
  299. if (filename ~ /[;&|`$(]/) {
  300. print "ignored strange file name " filename " in " curdir > "/dev/stderr";
  301. return;
  302. }
  303. }
  304.  
  305. while (!done && readline() > 0) {
  306. gsub(/.\b/, "");
  307. if (($1 ~ /^\.[Ss][Hh]/ &&
  308. ($2 ~ /[Nn][Aa][Mm][Ee]/ ||
  309. $2 ~ /^JMÉNO/ || $2 ~ /^NAVN/ || $2 ~ /^NUME/ ||
  310. $2 ~ /^BEZEICHNUNG/ || $2 ~ /^NOMBRE/ ||
  311. $2 ~ /^NIMI/ || $2 ~ /^NOM/ || $2 ~ /^IME/ ||
  312. $2 ~ /^N[ÉE]V/ || $2 ~ /^NAMA/ || $2 ~ /^̾Á°/ ||
  313. $2 ~ /^̾¾Î/ || $2 ~ /^À̸§/ || $2 ~ /^NAZWA/ ||
  314. $2 ~ /^îáú÷áîéå/ || $2 ~ /^Ãû³Æ/ || $2 ~ /^¦WºÙ/ ||
  315. $2 ~ /^NOME/ || $2 ~ /^NAAM/ || $2 ~ /^ÈÌÅ/)) ||
  316. (pages == "cat" && $1 ~ /^NAME/)) {
  317. if (!insh) {
  318. insh = 1;
  319. } else {
  320. done = 1;
  321. }
  322. } else if (insh) {
  323. if ($1 ~ /^\.[Ss][HhYS]/ ||
  324. (pages == "cat" &&
  325. ($1 ~ /^S[yYeE]/ || $1 ~ /^DESCRIPTION/ ||
  326. $1 ~ /^COMMAND/ || $1 ~ /^OVERVIEW/ ||
  327. $1 ~ /^STRUCTURES/ || $1 ~ /^INTRODUCTION/ ||
  328. $0 ~ /^[^ ]/))) {
  329. # end insh for Synopsis, Syntax, but also for
  330. # DESCRIPTION (e.g., XFree86.1x),
  331. # COMMAND (e.g., xspread.1)
  332. # OVERVIEW (e.g., TclCommandWriting.3)
  333. # STRUCTURES (e.g., XEvent.3x)
  334. # INTRODUCTION (e.g., TclX.n)
  335. # and anything at all that begins in Column 1, so
  336. # is probably a section header.
  337. done = 1;
  338. } else {
  339. if ($0 ~ progname"-") { # Fix old cat pages
  340. sub(progname"-", progname" - ");
  341. }
  342. if ($0 ~ /[^ \\]-$/) {
  343. sub(/-$/, ""); # Handle Hyphenations
  344. nextjoin = 1;
  345. } else if ($0 ~ /\\c$/) {
  346. sub(/\\c$/, ""); # Handle Continuations
  347. nextjoin = 1;
  348. } else
  349. nextjoin = 0;
  350.  
  351. sub(/^.[IB] /, ""); # Kill bold and italics
  352. sub(/^.BI /, ""); #
  353. sub(/^.SM /, ""); # Kill small
  354. sub(/^.Nm /, ""); # Kill bold
  355. sub(/^.Tn /, ""); # Kill normal
  356. sub(/^.Li /, ""); # Kill .Li
  357. sub(/^.Dq /, ""); # Kill .Dq
  358. sub(/^.Nd */, "- "); # Convert .Nd to dash
  359. sub(/\\\".*/, ""); # Trim pending comments
  360. sub(/ *$/, ""); # Trim pending spaces
  361. sub(/^\.$/, ""); # Kill blank comments
  362. sub(/^'"'"'.*/, ""); # Kill comment/troff lines
  363. sub(/^.in .*/, ""); # Kill various macros
  364. sub(/^.ti .*/, "");
  365. sub(/^.ta .*/, "");
  366. sub(/^.Vb .*/, "");
  367. sub(/^.[PLTH]P$/, ""); # .PP/.LP/.TP/.HP
  368. sub(/^.Pp$/, "");
  369. sub(/^.[iI]X .*$/, "");
  370. sub(/^.nolinks$/, "");
  371. sub(/^.B$/, "");
  372. sub(/^.nf$/, "");
  373.  
  374. if (($1 ~ /^\.../ || $1 == "") &&
  375. (entire_line ~ / - / || entire_line ~ / \\- /)) {
  376. # Assume that this ends the description of one line
  377. # Sometimes there are several descriptions in one page,
  378. # as in outb(2).
  379. handle_entire_line();
  380. entire_line = "";
  381. thisjoin = 1;
  382. } else {
  383. if (thisjoin) {
  384. entire_line = entire_line $0;
  385. } else {
  386. entire_line = entire_line " " $0;
  387. }
  388. thisjoin = nextjoin;
  389. }
  390. }
  391. }
  392. }
  393. handle_entire_line();
  394. closeline();
  395. }
  396.  
  397. function handle_entire_line() {
  398. x = entire_line; # Keep it short
  399.  
  400. gsub(/\015/, "", x); # Kill DOS remains
  401. gsub(/ /, " ", x); # Translate tabs to spaces
  402. gsub(/ +/, " ", x); # Collapse spaces
  403. gsub(/ *, */, ", ", x); # Fix comma spacings
  404. sub(/^ /, "", x); # Kill initial spaces
  405. sub(/ $/, "", x); # Kill trailing spaces
  406. sub(/__+/, "_", x); # Collapse underscores
  407.  
  408. gsub(/\\f\(../, "", x); # Kill font changes
  409. gsub(/\\f[PRIB0123]/, "", x); # Kill font changes
  410. gsub(/\\s[-+0-9]*/, "", x); # Kill size changes
  411. gsub(/\\&/, "", x); # Kill \&
  412. gsub(/\\\|/, "", x); # Kill \|
  413. gsub(/\\\((ru|ul)/, "_", x); # Translate
  414. gsub(/\\\((mi|hy|em)/, "-", x); # Translate
  415. gsub(/\\\*\(../, "", x); # Kill troff strings
  416. gsub(/\\/, "", x); # Kill all backslashes
  417. gsub(/"/, "", x); # Kill quotes (from .Nd "foo bar")
  418. sub(/<h1 align=center>/, "", x);# Yuk! HTML cruft
  419. gsub(/\000.*/, "X", x); # Binary cruft in LAPACK pages
  420. gsub(/ +/, " ", x); # Collapse spaces (again)
  421. sub(/^ /, "", x); # Kill initial spaces (again)
  422. sub(/ $/, "", x); # Kill trailing spaces (again)
  423. sub(/\.$/, "", x); # Kill trailing period
  424.  
  425. if (!match(x, / - /))
  426. return;
  427.  
  428. after_dash = substr(x, RSTART);
  429. head = substr(x, 1, RSTART-1) ", ";
  430. while (match(head, /, /)) {
  431. prog = substr(head, 1, RSTART-1);
  432. head = substr(head, RSTART+2);
  433. if (prog != progname)
  434. prog = prog " [" progname "]";
  435. printf "%-*s (%s) %s\n", 20, prog, actual_section, after_dash;
  436. }
  437. }
  438.  
  439. { # Main action - process each filename read in.
  440. filename = $0;
  441. do_one();
  442. }
  443. ' pages=$pages section=$section verbose=$verbose curdir=$curdir
  444. cd ..
  445. fi
  446. done > $TMPFILE
  447.  
  448. cd "$here"
  449.  
  450. if [ -f ${mandir1}/whatis ]
  451. then
  452. cat ${mandir1}/whatis >> $TMPFILE
  453. fi
  454. tr -s '\n' < $TMPFILE | sort -u > ${mandir1}/whatis
  455.  
  456. chmod 644 ${mandir1}/whatis
  457. rm $TMPFILE
  458. fi
  459. done
  460. done
  461.  
  462. # remove tempdir
  463. rm -rf $TMPFILEDIR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement