fix-info-dir 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. #!/bin/sh
  2. #fix-info-dir (GNU texinfo)
  3. VERSION=1.1
  4. #Copyright (C) 1998, 2003 Free Software Foundation, Inc.
  5. #fix-info-dir comes with NO WARRANTY, to the extent permitted by law.
  6. #You may redistribute copies of fix-info-dir
  7. #under the terms of the GNU General Public License.
  8. #For more information about these matters, see the files named COPYING."
  9. #fix-info-dir was derived from update-info and gen-dir-node
  10. # The skeleton file contains info topic names in the
  11. # order they should appear in the output. There are three special
  12. # lines that alter the behavior: a line consisting of just "--" causes
  13. # the next line to be echoed verbatim to the output. A line
  14. # containing just "%%" causes all the remaining filenames (wildcards
  15. # allowed) in the rest of the file to be ignored. A line containing
  16. # just "!!" exits the script when reached (unless preceded by a line
  17. # containing just "--").
  18. #Author: Richard L. Hawes, rhawes@dmapub.dma.org.
  19. # ###SECTION 1### Constants
  20. set -h 2>/dev/null
  21. # ENVIRONMENT
  22. if test -z "$TMPDIR"; then
  23. TMPDIR="/usr/tmp"
  24. fi
  25. if test -z "$LINENO"; then
  26. LINENO="0"
  27. fi
  28. MENU_BEGIN='^\*\([ ]\)\{1,\}Menu:'
  29. MENU_ITEM='^\* ([^ ]).*:([ ])+\('
  30. MENU_FILTER1='s/^\*\([ ]\)\{1,\}/* /'
  31. MENU_FILTER2='s/\([ ]\)\{1,\}$//g'
  32. TMP_FILE1="${TMPDIR}/fx${$}.info"
  33. TMP_FILE2="${TMPDIR}/fy${$}.info"
  34. TMP_FILE_LIST="$TMP_FILE1 $TMP_FILE2"
  35. TRY_HELP_MSG="Try --help for more information"
  36. # ###SECTION 100### main program
  37. #variables set by options
  38. CREATE_NODE=""
  39. DEBUG=":"
  40. MODE=""
  41. #
  42. Total="0"
  43. Changed=""
  44. while test "$*"; do
  45. case "$1" in
  46. -c|--create) CREATE_NODE="y";;
  47. --debug) set -eux; DEBUG="set>&2";;
  48. -d|--delete) MODE="Detect_Invalid";;
  49. +d);;
  50. --version)
  51. cat<<VersionEOF
  52. fix-info-dir (GNU Texinfo) $VERSION
  53. Copyright (C) 1998 Free Software Foundation, Inc.
  54. fix-info-dir comes with NO WARRANTY, to the extent permitted by law.
  55. You may redistribute copies of fix-info-dir
  56. under the terms of the GNU General Public License.
  57. For more information about these matters, see the files named COPYING.
  58. Author: Richard L. Hawes
  59. VersionEOF
  60. exit;;
  61. --help)
  62. cat<<HelpEndOfFile
  63. Usage: fix-info-dir [OPTION]... [INFO_DIR/[DIR_FILE]] [SKELETON]
  64. It detects and inserts missing menu items into the info dir file.
  65. The info dir must be the current directory.
  66. Options:
  67. -c, --create create a new info node
  68. -d, --delete delete invalid menu items (ignore missing menu items)
  69. --debug print debug information to standard error path
  70. --help print this help message and exit
  71. --version print current version and exit
  72. Backup of the info node has a '.old' suffix added. This is a shell script.
  73. Environment Variables: TMPDIR
  74. Email bug reports to bug-texinfo@gnu.org.
  75. HelpEndOfFile
  76. exit;;
  77. [-+]*) echo "$0:$LINENO: \"$1\" is not a valid option">&2
  78. echo "$TRY_HELP_MSG">&2
  79. exit 2;;
  80. *) break;;
  81. esac
  82. shift
  83. done
  84. ORIGINAL_DIR=`pwd`
  85. if test "$#" -gt "0"; then
  86. INFO_DIR="$1"
  87. shift
  88. else
  89. INFO_DIR=$DEFAULT_INFO_DIR
  90. fi
  91. if test ! -d "${INFO_DIR}"; then
  92. DIR_FILE=`basename ${INFO_DIR}`;
  93. INFO_DIR=`dirname ${INFO_DIR}`;
  94. else
  95. DIR_FILE="dir"
  96. fi
  97. cd "$INFO_DIR"||exit
  98. if test "$CREATE_NODE"; then
  99. if test "$#" -gt "0"; then
  100. if test `expr $1 : /` = '1'; then
  101. SKELETON="$1"
  102. else
  103. SKELETON="$ORIGINAL_DIR/$1"
  104. fi
  105. if test ! -r "$SKELETON" && test -f "$SKELETON"; then
  106. echo "$0:$LINENO: $SKELETON is not readable">&2
  107. exit 2
  108. fi
  109. shift
  110. else
  111. SKELETON=/dev/null
  112. fi
  113. else
  114. if test ! -f "$DIR_FILE"; then
  115. echo "$0:$LINENO: $DIR_FILE is irregular or nonexistant">&2
  116. exit 2
  117. elif test ! -r "$DIR_FILE"; then
  118. echo "$0:$LINENO: $DIR_FILE is not readable">&2
  119. exit 2
  120. elif test ! -w "$DIR_FILE"; then
  121. echo "$0:$LINENO: $DIR_FILE is not writeable">&2
  122. exit 2
  123. fi
  124. fi
  125. if test "$#" -gt "0"; then
  126. echo "$0:$LINENO: Too many parameters">&2
  127. echo "$TRY_HELP_MSG">&2
  128. exit 2
  129. fi
  130. if test -f "$DIR_FILE"; then
  131. cp "$DIR_FILE" "$DIR_FILE.old"
  132. echo "Backed up $DIR_FILE to $DIR_FILE.old."
  133. fi
  134. if test "$CREATE_NODE"; then
  135. if test "$MODE"; then
  136. echo "$0:$LINENO: ERROR: Illogical option combination: -d -c">&2
  137. echo "$TRY_HELP_MSG">&2
  138. exit 2
  139. fi
  140. echo "Creating new Info Node: `pwd`/$DIR_FILE"
  141. Changed="y"
  142. {
  143. ### output the dir header
  144. echo "-*- Text -*-"
  145. echo "This file was generated automatically by $0."
  146. echo "This version was generated on `date`"
  147. echo "by `whoami`@`hostname` for `pwd`"
  148. cat<<DIR_FILE_END_OF_FILE
  149. This is the file .../info/$DIR_FILE, which contains the topmost node of the
  150. Info hierarchy. The first time you invoke Info you start off
  151. looking at that node, which is ($DIR_FILE)Top.
  152. 
  153. File: $DIR_FILE Node: Top This is the top of the INFO tree
  154. This (the Directory node) gives a menu of major topics.
  155. Typing "q" exits, "?" lists all Info commands, "d" returns here,
  156. "h" gives a primer for first-timers,
  157. "mEmacs<Return>" visits the Emacs topic, etc.
  158. In Emacs, you can click mouse button 2 on a menu item or cross reference
  159. to select it.
  160. * Menu: The list of major topics begins on the next line.
  161. DIR_FILE_END_OF_FILE
  162. ### go through the list of files in the skeleton. If an info file
  163. ### exists, grab the ENTRY information from it. If an entry exists
  164. ### use it, otherwise create a minimal $DIR_FILE entry.
  165. # Read one line from the file. This is so that we can echo lines with
  166. # whitespace and quoted characters in them.
  167. while read fileline; do
  168. # flag fancy features
  169. if test ! -z "$echoline"; then # echo line
  170. echo "$fileline"
  171. echoline=""
  172. continue
  173. elif test "${fileline}" = "--"; then
  174. # echo the next line
  175. echoline="1"
  176. continue
  177. elif test "${fileline}" = "%%"; then
  178. # skip remaining files listed in skeleton file
  179. skip="1"
  180. continue
  181. elif test "${fileline}" = "!!"; then
  182. # quit now
  183. break
  184. fi
  185. # handle files if they exist
  186. for file in $fileline""; do
  187. fname=
  188. if test -z "$file"; then
  189. break
  190. fi
  191. # Find the file to operate upon.
  192. if test -r "$file"; then
  193. fname="$file"
  194. elif test -r "${file}.info"; then
  195. fname="${file}.info"
  196. elif test -r "${file}.gz"; then
  197. fname="${file}.gz"
  198. elif test -r "${file}.info.gz"; then
  199. fname="${file}.info.gz"
  200. else
  201. echo "$0:$LINENO: can't find info file for ${file}?">&2
  202. continue
  203. fi
  204. # if we found something and aren't skipping, do the entry
  205. if test "$skip"; then
  206. continue
  207. fi
  208. infoname=`echo $file|sed -e 's/.info$//'`
  209. entry=`zcat -f $fname|\
  210. sed -e '1,/START-INFO-DIR-ENTRY/d'\
  211. -e '/END-INFO-DIR-ENTRY/,$d'`
  212. if [ ! -z "${entry}" ]; then
  213. echo "${entry}"
  214. else
  215. echo "* ${infoname}: (${infoname})."
  216. fi
  217. Total=`expr "$Total" + "1"`
  218. done
  219. done
  220. }>$DIR_FILE<$SKELETON
  221. fi
  222. trap ' eval "$DEBUG"; rm -f $TMP_FILE_LIST; exit ' 0
  223. trap ' rm -f $TMP_FILE_LIST
  224. exit ' 1
  225. trap ' rm -f $TMP_FILE_LIST
  226. echo "$0:$LINENO: received INT signal.">&2
  227. exit ' 2
  228. trap ' rm -f $TMP_FILE_LIST
  229. echo "$0:$LINENO: received QUIT signal.">&2
  230. exit ' 3
  231. sed -e "1,/$MENU_BEGIN/d" -e "$MENU_FILTER1" -e "$MENU_FILTER2"<$DIR_FILE\
  232. |sed -n -e '/\* /{
  233. s/).*$//g
  234. s/\.gz$//
  235. s/\.info$//
  236. s/^.*(//p
  237. }'|sort -u>$TMP_FILE1
  238. ls -F|sed -e '/\/$/d' -e '/[-.][0-9]/d'\
  239. -e "/^$DIR_FILE\$/d" -e "/^$DIR_FILE.old\$/d"\
  240. -e 's/[*@]$//' -e 's/\.gz$//' -e 's/\.info$//'|sort>$TMP_FILE2
  241. if test -z "$MODE"; then
  242. #Detect Missing
  243. DONE_MSG="total menu item(s) were inserted into `pwd`/$DIR_FILE"
  244. for Info_Name in `comm -13 $TMP_FILE1 $TMP_FILE2`; do
  245. if test -r "$Info_Name"; then
  246. Info_File="$Info_Name"
  247. elif test -r "${Info_Name}.info"; then
  248. Info_File="${Info_Name}.info"
  249. elif test -r "${Info_Name}.gz"; then
  250. Info_File="${Info_Name}.gz"
  251. elif test -r "${Info_Name}.info.gz"; then
  252. Info_File="${Info_Name}.info.gz"
  253. else
  254. echo "$0:$LINENO: can't find info file for ${Info_Name}?">&2
  255. continue
  256. fi
  257. Changed="y"
  258. if install-info $Info_File $DIR_FILE; then
  259. Total=`expr "$Total" + "1"`
  260. fi
  261. done
  262. else
  263. # Detect Invalid
  264. DONE_MSG="total invalid menu item(s) were removed from `pwd`/$DIR_FILE"
  265. for Info_Name in `comm -23 $TMP_FILE1 $TMP_FILE2`; do
  266. Changed="y"
  267. if install-info --remove $Info_Name $DIR_FILE; then
  268. Total=`expr "$Total" + "1"`
  269. fi
  270. done
  271. fi
  272. # print summary
  273. if test "$Changed"; then
  274. echo "$Total $DONE_MSG"
  275. else
  276. echo "Nothing to do"
  277. fi
  278. rm -f $TMP_FILE_LIST
  279. eval "$DEBUG"
  280. exit 0