home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / OS2 / gnuinfo.zip / util / update-info < prev   
Text File  |  1997-07-14  |  22KB  |  876 lines

  1. #!/bin/sh
  2. # update-info -- update dir file from all extant info pages.
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2, or (at your option)
  6. # any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, you can either send email to this
  15. # program's maintainer or write to: The Free Software Foundation,
  16. # Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
  17. # Author: rhawes@dmapub.dma.org.  Please report bugs to him.
  18. # run this program to install update-info
  19. # ###SECTION 0### install script
  20. # These constants set the version numbers for both files:
  21. PROGRAM_VERSION="1.4"
  22. PACKAGE_VERSION="4.0"
  23.  
  24. # ENVIRONMENT
  25. if test -z "$TMPDIR"; then
  26.     TMPDIR="/usr/tmp"
  27. fi
  28.  
  29. TMP_SED="$TMPDIR/uss$$.info"
  30. TMP_F_ADD_SECTION="$TMPDIR/ufa$$.info"
  31. TMP_F_DELETE_INVALID="$TMPDIR/ufd$$.info"
  32. TMP_F_INSERT_MISSING="$TMPDIR/ufi$$.info"
  33. TMP_FILES="$TMP_SED $TMP_F_ADD_SECTION $TMP_F_DELETE_INVALID\
  34.     $TMP_F_INSERT_MISSING"
  35.  
  36. trap 'rm -f $TMP_FILES' 0
  37.  
  38. # file boundaries
  39. UPDATE_INFO="/^# _file: 'update-info'_/"
  40. UPDATE_INFO_F="/^# _file: 'update-info.f'_/"
  41.  
  42. # @F_ADD_SECTION@
  43. echo 'Item_Num=`expr "$Item_Num" + "1"`
  44. echo "$1">>"$TMP_SECTIONS"
  45. if test "$Item_Status"; then
  46.     Item_Status=`echo "${Item_Status}
  47. X"`
  48. else
  49.     Item_Status="X"
  50. fi '>$TMP_F_ADD_SECTION
  51.  
  52. # @F_INSERT_MISSING@
  53. echo 'if test -z "$Create_Node"; then
  54.     rm -f ${Info_Node}.old
  55.     cp $Info_Node ${Info_Node}.old
  56.     echo "$BACKUP_MSG"
  57. fi
  58. echo "/$MENU_BEGIN/
  59. +,$ d
  60. r $TMP_MENU
  61. w
  62. q"|ed -s $Info_Node>/dev/null'>$TMP_F_INSERT_MISSING
  63.  
  64. # @F_DELETE_INVALID@
  65. echo '
  66. rm -f ${Info_Node}.old
  67. cp $Info_Node ${Info_Node}.old
  68. echo "$BACKUP_MSG"
  69. echo "/$MENU_BEGIN/
  70. +,$ d
  71. w
  72. q"|ed -s $Info_Node>/dev/null
  73. sed -f "$TMP_SED" "$TMP_MENU">>"$Info_Node"'>$TMP_F_DELETE_INVALID
  74.  
  75. cat<<Sed_Script_EOF>$TMP_SED
  76. s/@UPDATE_INFO_VERSION@/$PROGRAM_VERSION/g
  77. s/@TEXINFO_VERSION@/$PACKAGE_VERSION/g
  78. s/@SET_ITEM@/Item_Status=\`echo "\$Item_Status"|sed -e "\${1}s%^.*%\${2}%"\`/
  79. /@F_ADD_SECTION@/r $TMP_F_ADD_SECTION
  80. /@F_ADD_SECTION@/d
  81. /@F_DELETE_INVALID@/r $TMP_F_DELETE_INVALID
  82. /@F_DELETE_INVALID@/d
  83. /@F_INSERT_MISSING@/r $TMP_F_INSERT_MISSING
  84. /@F_INSERT_MISSING@/d
  85. Sed_Script_EOF
  86.  
  87. sed -e "1,${UPDATE_INFO}d" -e "$UPDATE_INFO_F,\$d" -f $TMP_SED $0>update-info
  88. sed -e "1,${UPDATE_INFO_F}d" -f $TMP_SED $0>update-info.f
  89. chmod +x update-info update-info.f
  90. echo "installed update-info, and update-info.f into `pwd`"
  91. rm -f $TMP_FILES
  92. exit
  93.  
  94. # _file: 'update-info'_
  95. #!/bin/sh
  96. #update-info (GNU texinfo @TEXINFO_VERSION@) @UPDATE_INFO_VERSION@
  97. #Copyright (C) 1997 Free Software Foundation, Inc.
  98. #update-info comes with NO WARRANTY, to the extent permitted by law.
  99. #You may redistribute copies of update-info
  100. #under the terms of the GNU General Public License.
  101. #For more information about these matters, see the files named COPYING."
  102. #Author: Richard L. Hawes
  103.  
  104. # ###SECTION 1### Constants
  105. set -h 2>/dev/null
  106. # ENVIRONMENT
  107. if test -z "$TMPDIR"; then
  108.     TMPDIR="/usr/tmp"
  109. fi
  110. if test -z "$LINES"; then
  111.     LINES=24
  112. fi
  113. if test -z "$COLUMNS"; then
  114.     COLUMNS=80
  115. fi
  116. if test -z "$EDITOR"; then
  117.     EDITOR=vi
  118. fi
  119. if test -z "$LINENO"; then
  120.     LINENO="0"
  121. fi
  122. # constants redefined by update-info.f
  123. PROMPT1="(y=yes, Y=yes to all, n=no, N=No to all):"
  124. FUNCTIONS=""
  125. #
  126. ARGUMENTS="$*"
  127. DISPLAY_NUM=`expr "$LINES" - 4`
  128. CONTROL_D="{Ctrl-D}"
  129. DIR_SECTION="^INFO-DIR-SECTION"
  130. ENTRY_END="^END-INFO-DIR-ENTRY"
  131. ENTRY_START="^START-INFO-DIR-ENTRY"
  132. MENU_BEGIN='^\*\([     ]\)\{1,\}Menu:'
  133. MENU_ITEM='^\* ([^     ]).*:([     ])+\('
  134. SECTION_TITLE="^[A-Za-z0-9]"
  135. MENU_FILTER1='s/^\*\([     ]\)\{1,\}/* /'
  136. MENU_FILTER2='s/\([     ]\)\{1,\}$//g'
  137. TMP_ITEM="${TMPDIR}/ui${$}.info"
  138. TMP_LIST="${TMPDIR}/ul${$}.info"
  139. TMP_MENU="${TMPDIR}/um${$}.info"
  140. TMP_SECTIONS="${TMPDIR}/us${$}.info" # used only in Detect_Missing
  141. TMP_SED="$TMP_SECTIONS" # used only in Detect_Invalid routines
  142. TMP_FILE1="${TMPDIR}/ux${$}.info"
  143. TMP_FILE2="${TMPDIR}/uy${$}.info"
  144. TMP_COUNT="$TMP_FILE2"
  145. TMP_FILE_LIST="$TMP_LIST $TMP_MENU $TMP_SECTIONS $TMP_FILE1 $TMP_FILE2\
  146.     $TMP_ITEM"
  147. TRY_HELP_MSG="Try --help for more information"
  148. if zcat --version 2>/dev/null>/dev/null; then
  149.     CAT_COMMAND="zcat -f"
  150. else
  151.     echo "$0:$LINENO: GNU zcat not found">&2
  152.     CAT_COMMAND="cat"
  153. fi
  154.  
  155. # ###SECTION 100### main program
  156. #variables set by options
  157. Create_Node=""
  158. Debug=":"
  159. Interactive=""
  160. Load_Functions="y"
  161. Mode=""
  162. #
  163. Inserts="0"
  164. Inserts_Total="0"
  165. Invalid="0"
  166. Invalid_Total="0"
  167. Changed=""
  168.  
  169. while test "$*"
  170.     do
  171.     case "$1" in
  172.         -c)             Create_Node="y";;
  173.         -ci|-ic)        Create_Node="y"; Interactive="y";;
  174.         -cif|-cfi|-ifc|-icf|-fci|-fic) Create_Node="y"
  175.                 Interactive="y"; Load_Functions="";;
  176.         --debug)    set -eux; Debug="set>&2";;
  177.         -d|--delete)    Mode="Detect_Invalid";;
  178.         -f)        Load_Functions="";;
  179.         -i|--interactive) Interactive="y";;
  180.         -fi|-if)    Load_Functions=""; Interactive="y";;
  181.         -id|-di)    Mode="Detect_Invalid"; Interactive="y";;
  182.         +i|+d|+f);;
  183.         --version)
  184. cat<<VersionEOF
  185. update-info (GNU texinfo @TEXINFO_VERSION@) @UPDATE_INFO_VERSION@
  186. Copyright (C) 1997 Free Software Foundation, Inc.
  187. update-info comes with NO WARRANTY, to the extent permitted by law.
  188. You may redistribute copies of update-info
  189. under the terms of the GNU General Public License.
  190. For more information about these matters, see the files named COPYING.
  191. Author: Richard L. Hawes
  192. VersionEOF
  193.         exit;;
  194.  
  195.         --help)
  196. cat<<HelpEndOfFile
  197. Usage:    update-info  [OPTION]... INFO_PATH/INFO_DIR_FILE
  198.  
  199. It detects and inserts missing menu items into the info node file.
  200.  
  201. Options:
  202. -c            create a new info node
  203.     --debug        print debug information to standard error path
  204. -d,    --delete    delete invalid menu items (ignore missing menu items)
  205. -f            do not load functions (file update-info.f)
  206.     --help        print this help message and exit
  207. -i,    --interactive    interactive mode prompts before inserting or removing
  208.             menu items
  209.     --version    print current version and exit
  210. Backup of the info node has a '.old' suffix added.  This is a shell script.
  211. Files: update-info.f -- contains functions (optional).
  212. Environment Variables: COLUMNS, EDITOR, LINES, TMPDIR
  213. Email bug reports to bug-texinfo@prep.ai.mit.edu.
  214. HelpEndOfFile
  215.         exit;;
  216.  
  217.         [-+]*)    echo "$0:$LINENO: \"$1\" is not a valid option">&2
  218.             echo "$TRY_HELP_MSG">&2
  219.             exit 2;;
  220.         *) break;;
  221.     esac
  222.     shift
  223.     done
  224.  
  225. if test "$#" -lt "1"; then
  226.     echo "$0:$LINENO: Too few parameters">&2
  227.     echo "$TRY_HELP_MSG">&2
  228.     exit 2
  229. elif test "$#" -gt "1"; then
  230.     echo "$0:$LINENO: Too many parameters">&2
  231.     echo "$TRY_HELP_MSG">&2
  232.     exit 2
  233. fi
  234. Info_Path="$1"
  235. Info_Node=`basename "$Info_Path"`
  236. if echo "$Info_Node"|grep ".*dir$">/dev/null; then
  237.     :
  238. else
  239.     echo "$0:$LINENO: $Info_Node is not a valid info node name">&2
  240.     exit 2
  241. fi
  242. Info_Pathname=`dirname "$Info_Path"`
  243. cd "$Info_Pathname"||exit
  244.  
  245. BACKUP_MSG="Backed up $Info_Node to ${Info_Node}.old."
  246. HANGUP_MSG="Hang up on \"update-info $ARGUMENTS\""
  247. INSERT_MSG="menu item(s) were inserted (not counting duplicates)."
  248. INSERT_MSG2="total menu item(s) were inserted into `pwd`/$Info_Node"
  249. DELETE_MSG="invalid menu item(s) were removed (not counting duplicates)."
  250. DELETE_MSG2="total invalid menu item(s) were removed from `pwd`/$Info_Node"
  251.  
  252. if test "$Create_Node"; then
  253.     if test "$Mode"; then
  254.         echo "$0:$LINENO: ERROR: Illogical option combination: -d -c">&2
  255.         echo "$TRY_HELP_MSG">&2
  256.         exit 2
  257.     fi
  258.     if test -f "$Info_Node"; then
  259.         rm -f ${Info_Node}.old
  260.         mv "$Info_Node" "${Info_Node}.old"
  261.         echo "$BACKUP_MSG"
  262.     fi
  263.     echo "Creating new Info Node: `pwd`/$Info_Node"
  264. cat>$Info_Node<<NodeEndOfFile||exit
  265.  
  266. This is the file .../info/dir, which contains the topmost node of the
  267. Info hierarchy.  The first time you invoke Info you start off
  268. looking at that node, which is (dir)Top.
  269. 
  270. File: dir    Node: Top    This is the top of the INFO tree
  271.   This (the Directory node) gives a menu of major topics.
  272.   Typing "d" returns here, "q" exits, "?" lists all INFO commands, "h"
  273.   gives a primer for first-timers, "mTexinfo<Return>" visits Texinfo topic,
  274.   etc.
  275.   Or click mouse button 2 on a menu item or cross reference to select it.
  276.   --- PLEASE ADD DOCUMENTATION TO THIS TREE. (See INFO topic first.) ---
  277.  
  278. * Menu: The list of major topics begins on the next line.
  279.  
  280. NodeEndOfFile
  281. else
  282.     if test ! -f "$Info_Node"; then
  283.         echo "$0:$LINENO: $Info_Node is irregular or nonexistant">&2
  284.         exit 2
  285.     elif test ! -r "$Info_Node"; then
  286.         echo "$0:$LINENO: $Info_Node is not readable">&2
  287.         exit 2
  288.     elif test ! -w "$Info_Node"; then
  289.         echo "$0:$LINENO: $Info_Node is not writeable">&2
  290.         exit 2
  291.     fi
  292. fi
  293.  
  294. if test "$Load_Functions" -a "$Interactive" -a -z "$Mode"; then
  295.     if FUNCTIONS_VERSION=`( update-info.f )`; then
  296.         if test `echo "$FUNCTIONS_VERSION"\
  297.         |cut -d' ' -f5` = "@UPDATE_INFO_VERSION@"; then
  298.             echo "Loading functions..."
  299.             . update-info.f
  300.         else
  301.             echo "$0:$LINENO: wrong version of update-info.f">&2
  302.             echo "(functions were not loaded)">&2
  303.         fi
  304.     else
  305.         echo "(functions were not loaded)">&2
  306.     fi
  307. fi
  308.  
  309.  
  310. trap ' eval "$Debug"; rm -f $TMP_FILE_LIST; exit ' 0
  311. if test "$Interactive"; then
  312.     if test ! -t "1"; then
  313.         echo "$0:$LINENO: Cannot run in interactive mode  "\
  314.         "standard out is redirected">&2
  315.         exit 2
  316.     fi
  317.     trap ' ' 2 3
  318. else
  319.     trap ' rm -f $TMP_FILE_LIST
  320.     echo "$0:$LINENO: received INT signal.  All edits are canceled.">&2
  321.     exit ' 2
  322.     trap ' rm -f $TMP_FILE_LIST
  323.     echo "$0:$LINENO: received QUIT signal.  All edits are canceled.">&2
  324.     exit ' 3
  325. fi
  326. if test -z "$Mode"; then
  327.     trap '
  328.     if test "$Changed"; then
  329.         {
  330.         echo $HANGUP_MSG
  331.         @F_INSERT_MISSING@
  332.         Inserts_Total=`wc -c<"$TMP_COUNT"`
  333.         echo $Inserts_Total $INSERT_MSG2
  334.         }|mail "$LOGNAME"
  335.     fi
  336.     rm -f $TMP_FILE_LIST
  337.     exit ' 1
  338. else
  339.     trap '
  340.     if test "$Changed"; then
  341.         {
  342.         echo $HANGUP_MSG
  343.         @F_DELETE_INVALID@
  344.         Invalid_Total=`wc -l<"$TMP_SED"`
  345.         echo $Invalid_Total $DELETE_MSG2
  346.         }|mail $LOGNAME
  347.     fi
  348.     rm -f $TMP_FILE_LIST
  349.     exit ' 1
  350. fi
  351.  
  352. sed -e "1,/$MENU_BEGIN/d" -e "$MENU_FILTER1" -e "$MENU_FILTER2"<$Info_Node\
  353. |tee $TMP_MENU\
  354. |sed -n -e '/\* /{
  355. s/).*$//g
  356. s/\.gz$//
  357. s/\.info$//
  358. s/^.*(//p
  359. }'|sort -u>$TMP_FILE1
  360. ls -F|sed -e '/\/$/d' -e '/[-.][0-9]/d'\
  361.     -e '/:$/d' -e '/^$/d' -e "/^${Info_Node}~\$/d"\
  362.     -e "/^${Info_Node}\$/d" -e "/^${Info_Node}.old\$/d"\
  363.     -e 's/\.gz$//' -e 's/\.info$//'|sort>$TMP_FILE2
  364.  
  365. if test -z "$Mode"; then
  366.     #Detect Missing
  367.     comm -13 $TMP_FILE1 $TMP_FILE2>$TMP_LIST
  368.     cat</dev/null>$TMP_COUNT
  369.     #get sections, initialize variables
  370.     sed -n -e "/$SECTION_TITLE/p" "$TMP_MENU">"$TMP_SECTIONS"
  371.     Item_Num=`wc -l<"$TMP_SECTIONS"|tr -d ' '`
  372.     Item_Status=`echo\
  373.     |awk "BEGIN{for(i=1;i<=${Item_Num};i++)printf(\"_\n\")}"`
  374.     Item_Dir="$Item_Num"
  375.     for Info_Name in `cat $TMP_LIST`
  376.         do
  377.         if test -r "$Info_Name"; then
  378.             Info_File="$Info_Name"
  379.         elif test -r "${Info_Name}.info"; then
  380.             Info_File="${Info_Name}.info"
  381.         elif test -r "${Info_Name}.gz"; then
  382.             Info_File="${Info_Name}.gz"
  383.         elif test -r "${Info_Name}.info.gz"; then
  384.             Info_File="${Info_Name}.info.gz"
  385.         else
  386.             echo "$0:$LINENO: can't find info file for ${Info_Name}?">&2
  387.         fi
  388.         #generate menu item
  389.         echo|tr -d '\012'>$TMP_FILE1
  390.         eval $CAT_COMMAND "$Info_File"\
  391.         |sed -n -e "/$DIR_SECTION/w $TMP_FILE1"\
  392.         -e "/$ENTRY_START/,/$ENTRY_END/{
  393.         $MENU_FILTER1
  394.         p
  395.         }"|awk "BEGIN{Mode=0}
  396.         /^$/{if(Mode==1)exit}
  397.         /^([     ])+([^     ])+/{if(Mode==1)print}
  398.         /^[^     ]/{if(Mode==1)exit}
  399.         /${MENU_ITEM}${Info_Name}\)\./{if(Mode==0){Mode++
  400.                 print}
  401.             else
  402.                 exit}">"$TMP_ITEM"
  403.         if test ! -s "$TMP_ITEM"; then
  404.             echo "* $Info_Name: ($Info_Name).">"$TMP_ITEM"
  405.         fi
  406.         Item_Status=`echo "$Item_Status"|sed -e '1,$s/^./_/'`
  407.         if test -s "$TMP_FILE1"; then
  408.             Item_Section=`sed -e "s/$DIR_SECTION[     ]*//"\
  409.             <$TMP_FILE1`
  410.         else
  411.             Item_Section=`echo "Miscellaneous"`
  412.         fi
  413.         Size=`echo "$Item_Section"|wc -l|tr -d ' '`
  414.         # initialize variables, check for new sections
  415.         Num1=1
  416.         while test "$Num1" -le "$Size"
  417.             do
  418.             Item=`echo "$Item_Section"|sed -n -e "${Num1}p"`
  419.             if Num=`grep -in "^$Item$" "$TMP_SECTIONS"`; then
  420.                 Num=`echo "$Num"|sed -e 's/:.*$//g'`
  421.                 ##F#Set_Item
  422.                 set "$Num" "X"
  423.                 @SET_ITEM@
  424.             else
  425.                 set "$Item"
  426.                 @F_ADD_SECTION@
  427.             fi
  428.             Num1=`expr "$Num1" + "1"`
  429.             done
  430.         if test "$Interactive"; then
  431.             echo "$Item_Section"
  432.             cat "$TMP_ITEM"
  433.             echo "add menu item for $Info_File? "
  434.             while true
  435.                 do
  436.                 echo "$PROMPT1"|tr -d '\012'
  437.                 read Answer
  438.                 case $Answer in
  439.                     y) break;;
  440.                     e)
  441.                     if test "$FUNCTIONS"; then
  442.                         Select_Sections
  443.                         break
  444.                     else
  445.                         echo "Can't edit.  "\
  446.                         "Functions are not loaded.">&2
  447.                     fi;;
  448.                     Y) Interactive=""; break;;
  449.                     n) continue 2;;
  450.                     N) break 2;;
  451.                     *) echo "\"$Answer\" "\
  452.                     "is an invalid response">&2;;
  453.                     esac
  454.                 done
  455.         fi
  456.         if echo "$Item_Status"|grep '^X'>/dev/null; then
  457.             # edit $TMP_MENU
  458.  
  459.             Changed="y"
  460.             (
  461.             trap ' ' 1 2 3
  462.             Tmp_Var=`echo "$Item_Status"|tr -d '\012'`
  463.             Key=`awk -F':' ' FNR==1{ print $1}' $TMP_ITEM`
  464.             # add new sections to 'dir' file
  465.             if test "$Item_Num" -gt "$Item_Dir"; then
  466.                 if test "$Item_Dir" -ne "0"; then
  467.                     sed -e "1,${Item_Dir}d" -e 'i\
  468.  
  469. ' "$TMP_SECTIONS">>"$TMP_MENU"
  470.                 else
  471.                     sed -e 'i\
  472.  
  473. ' "$TMP_SECTIONS">>"$TMP_MENU"
  474.                 fi
  475.             fi
  476.             # awk determines the insertion points for each section
  477.             awk -F":" "function Insert(Line){
  478.             if(Mode==2){
  479.                 Mode=1;if(substr(\"$Tmp_Var\",Item++,1)==\"X\")
  480.                     print Line
  481.                 }
  482.             }
  483.             BEGIN{Mode=1;Item=1}
  484.             /$SECTION_TITLE/{Insert(FNR-1);if(Mode>=1)Mode=2}
  485.             /${MENU_ITEM}.*\)\./{if(\$1>Item_Name)Insert(FNR-1)}
  486.             /^$/{Insert(FNR-1)}
  487.             END{Insert(FNR)}" Item_Name="$Key" "$TMP_MENU"\
  488.             |sort -nr|sed -e "s%\$% r $TMP_ITEM%"|sed -e '$a\
  489. w
  490. ' -e '$a\
  491. q
  492. '|ed -s "$TMP_MENU"
  493.             echo "$Item_Status"|tr -cd "X">>$TMP_COUNT
  494.             )
  495.  
  496.             Inserts=`expr "$Inserts" + "1"`
  497.             echo "$Info_File installed into section(s):"\
  498.             |tr -d '\012'
  499.             echo "$Item_Status"|awk '/X/{printf(" %d", FNR)}'
  500.             echo
  501.             Item_Dir="$Item_Num"
  502.         else
  503.             echo "$Info_File not installed (no section selected)"
  504.         fi
  505.         done
  506.     # print summary
  507.     trap ' ' 1 2 3
  508.     if test "$Changed"; then
  509.         @F_INSERT_MISSING@
  510.         Inserts_Total=`wc -c<"$TMP_COUNT"|tr -d " "`
  511.         if test "$Inserts" -ne "$Inserts_Total"; then
  512.             echo "$Inserts $INSERT_MSG"
  513.         fi
  514.         echo "$Inserts_Total $INSERT_MSG2"
  515.     fi
  516. else
  517.     # Detect Invalid
  518.     cat</dev/null>"$TMP_SED"
  519.     comm -23 $TMP_FILE1 $TMP_FILE2>$TMP_LIST
  520.     for Info_Name in `cat $TMP_LIST`
  521.         do
  522.         if test "$Interactive"; then
  523.             # display invalid menu item(s)
  524.             awk "BEGIN{Mode=1}
  525.             /^([     ])+([^     ])+/{if(Mode==2)print}
  526.             /^$/{if(Mode==2)Mode=1}
  527.             /$SECTION_TITLE/{Section=\$0}
  528.             /^[^     ]/{if(Mode==2)Mode=1}
  529.             /${MENU_ITEM}${Info_Name}\)\./{if(Mode==1){Mode++
  530.                 print Section
  531.                 print}}" $TMP_MENU
  532.             echo "delete menu item for $Info_Name? "
  533.             while true
  534.                 do
  535.                 echo\
  536.                 "(y=yes, n=no, Y=yes to all, N=No to all):"\
  537.                 |tr -d '\012'
  538.                 read Answer
  539.                 case "$Answer" in
  540.                     y) break;;
  541.                     Y) Interactive=""; break;;
  542.                     n) continue 2;;
  543.                     N) break 2;;
  544.                     *) echo "\"$Answer\" "\
  545.                     "is an invalid reponse">&2;;
  546.                     esac
  547.                 done
  548.         fi
  549.         # remove menu item from $TMP_MENU
  550.         Invalid=`expr "$Invalid" + "1"`
  551.         Changed="y"
  552.         (
  553.         trap ' ' 1 2 3
  554.         echo\
  555.         "invalid menu item for $Info_Name removed from section(s):"\
  556.         |tr -d '\012'
  557.         awk "function Delete(Last){
  558.         printf(\"%d,%dd\n\",First,Last-1)>>\"$TMP_SED\"}
  559.         BEGIN{Mode=1;Section=0}
  560.         /^$/{if(Mode==2){Delete(FNR);Mode=1}}
  561.         /$SECTION_TITLE/{Section++}
  562.         /^[^     ]/{if(Mode==2){Delete(FNR);Mode=1}}
  563.         /${MENU_ITEM}${Info_Name}\)\./{if(Mode==1){
  564.             First=FNR;printf(\" %d\",Section);Mode=2}}
  565.         END{if(Mode==2)Delete(FNR+1)}" $TMP_MENU
  566.         echo
  567.         )
  568.         done
  569.  
  570.     # display a summary
  571.     trap ' ' 1 2 3
  572.     if test "$Changed"; then
  573.         Invalid_Total=`wc -l<"$TMP_SED"|tr -d ' '`
  574.         @F_DELETE_INVALID@
  575.         if test "$Invalid" -ne "$Invalid_Total"; then
  576.             echo "$Invalid $DELETE_MSG"
  577.         fi
  578.         echo "$Invalid_Total $DELETE_MSG2"
  579.     fi
  580. fi
  581. if test -z "$Changed"; then
  582.     echo "Nothing to do"
  583. fi
  584. rm -f $TMP_FILE_LIST
  585. eval "$Debug"
  586. exit 0
  587. # _file: 'update-info.f'_
  588. #update-info.f (GNU texinfo @TEXINFO_VERSION@) @UPDATE_INFO_VERSION@
  589. #Copyright (C) 1997 Free Software Foundation, Inc.
  590. #update-info comes with NO WARRANTY, to the extent permitted by law.
  591. #You may redistribute copies of update-info
  592. #under the terms of the GNU General Public License.
  593. #For more information about these matters, see the files named COPYING."
  594. #Author: Richard L. Hawes
  595.  
  596. # update-info.f functions for update-info
  597.  
  598. # ###SECTION 1### functions used to insert missing menu items
  599.  
  600. Set_Item (){
  601. # set item status
  602. @SET_ITEM@
  603. }
  604.  
  605. Add_Section (){
  606. # add a section
  607. @F_ADD_SECTION@
  608. }
  609.  
  610. # ###SECTION 2### functions for menu selection of sections
  611.  
  612. Print (){
  613. # print a line without a linefeed
  614. echo "$*"|tr -d '\012'
  615. }
  616.  
  617. Get_Answer (){
  618. # get an answer to question
  619. _gs_Valid="$1"
  620. _gs_Prompt="$2"
  621. set -f
  622. Answer=""
  623. while test -z "$Answer"
  624.     do
  625.     Print "$_gs_Prompt"
  626.     if read Answer; then
  627.         :
  628.     else
  629.         Answer="$CONTROL_D"
  630.         echo
  631.     fi
  632.     if expr "$Answer" : "[$_gs_Valid]$">/dev/null; then
  633.         :
  634.     else
  635.         Print "\"$Answer\" is not a valid response! --">&2
  636.         Answer=""
  637.     fi
  638.     done
  639. set +f
  640. }
  641.  
  642. Do_Previous (){
  643. # go to previous screen
  644. if test "$Previous"; then
  645.     Next="$Top_Item"
  646.     Top_Item="$Previous"
  647.     if Previous=`expr "$Top_Item" - "$DISPLAY_NUM"`; then
  648.         if test "$Previous" -le "0"; then
  649.             Previous=""
  650.         fi
  651.     else
  652.         Previous=""
  653.     fi
  654. elif test "$Next"; then
  655.     Last_Page
  656. else
  657.     Print "There is no previous page. ">&2
  658. fi
  659. }
  660.  
  661. Do_Next (){
  662. # process go to next
  663. if test "$Next"; then
  664.     Previous="$Top_Item"
  665.     Top_Item="$Next"
  666.     Set_Next
  667. elif test "$Previous"; then
  668.     Top_Item="1"
  669.     Previous=""
  670.     Set_Next
  671. else
  672.     Print "There is no next page. ">&2
  673. fi
  674. }
  675.  
  676. Do_Add_Section (){
  677. # process add section command
  678. echo
  679. echo "Please enter the name of the new section:"
  680. if read Answer; then
  681.     Answer=`echo "$Answer"\
  682.     |sed -e 's/^\([     ]\)\{1,\}//g' -e "$MENU_FILTER2"`
  683.     if test "$Answer"; then
  684.         Add_Section "$Answer"
  685.         Last_Page
  686.         clear
  687.     fi
  688. else
  689.     Answer=""
  690. fi
  691. if test -z "$Answer"; then
  692.     clear
  693.     Print "no section added. "
  694. fi
  695. }
  696.  
  697. Do_Edit (){
  698. # process edit item command
  699. if test -t "2"; then
  700.     _de_Done=""
  701.     cp "$TMP_ITEM" "$TMP_FILE1"
  702.     while test -z "$_de_Done"
  703.         do
  704.         eval $EDITOR "$TMP_FILE1"
  705.         clear
  706.         _de_Done="t"
  707.         if sed -n -e "$MENU_FILTER1" -e '1p' "$TMP_FILE1"\
  708.         |egrep "${MENU_ITEM}${Info_Name}\)\.">/dev/null; then
  709.             :
  710.         else
  711.             sed -n -e '1p' "$TMP_FILE1"
  712.             echo "Pattern mismatch: `echo\
  713.             "/${MENU_ITEM}${Info_Name}\)\./"\
  714.             |tr -d "\011"`">&2
  715.             echo
  716.             _de_Done=""
  717.         fi
  718.         if sed -n -e '2,$p' "$TMP_FILE1"|grep '^[^     ]'>&2; then
  719.             echo "These lines must have leading spaces">&2
  720.             echo
  721.             _de_Done=""
  722.         fi
  723.         if test -z "$_de_Done"; then
  724.             Get_Answer "yn" "Invalid entry, cancel edits? (y or n):"
  725.             if test "y" = "$Answer"; then
  726.                 clear
  727.                 Print "Canceling edits -- invalid entry ">&2
  728.                 _de_Done="t"
  729.             fi
  730.         else
  731.             sed -e "$MENU_FILTER1" -e "$MENU_FILTER2" -e '/^$/d'\
  732.             <"$TMP_FILE1">"$TMP_ITEM"
  733.         fi
  734.         done
  735. else
  736.     Print "editor cannot run with error path redirected "
  737. fi
  738. }
  739.  
  740. Do_Number (){
  741. # process number
  742. _dn_Num="$1"
  743. if test "$_dn_Num" -ge 1 -a "$_dn_Num" -le "$Item_Num"; then
  744.     if test `echo "$Item_Status"|sed -n -e "${_dn_Num}p"` = "_"; then
  745.         Set_Item "$_dn_Num" "X"
  746.     else
  747.         Set_Item "$_dn_Num" "_"
  748.     fi
  749. else
  750.     Print "\"$_dn_Num\" is an invalid section number. ">&2
  751. fi
  752. }
  753.  
  754. Do_Help (){
  755. # process menu help
  756. echo
  757. echo "\
  758. Enter the following commands seperated
  759. by spaces and terminated by<ENTER>:
  760. # : (section number) toggle section
  761. a : add a new section
  762. e : edit item -- changes will not be
  763.   accepted if you change the
  764.   '(info_file_name).' or delete
  765.   the key parts: '*' 'Menu Name' ':'
  766. h : get this help screen
  767. n : next page
  768. p : previous page
  769. q : quit and do not put into menu
  770. s : save and put into menu"
  771. Print "Press enter to continue:"
  772. read junk
  773. clear
  774. }
  775.  
  776. Set_Next (){
  777. # determine value of Next
  778. Next=`expr "$DISPLAY_NUM" + "$Top_Item"`
  779. if test "$Next" -gt "$Item_Num"; then
  780.     Next=""
  781. fi
  782. }
  783.  
  784. Last_Page (){
  785. # go to last page of menu
  786. Top_Item=`echo|awk "BEGIN{printf(\"%d\",
  787. int((${Item_Num}-1)/${DISPLAY_NUM})*${DISPLAY_NUM}+1)}"`
  788. if test "$Top_Item" -gt "$DISPLAY_NUM"; then
  789.     Previous=`expr "$Top_Item" '-' "$DISPLAY_NUM"`
  790. else
  791.     Previous=""
  792. fi
  793. Set_Next
  794. }
  795.  
  796. Select_Sections (){
  797. # prompt user for which sections
  798. set -f
  799. Top_Item="1"
  800. Previous=""
  801. Set_Next
  802. clear
  803. echo "Default sections are selected."
  804. Done=""
  805. while test -z "$Done"
  806.     do
  807.     awk "FNR==1{printf(\"%s\n\", substr(\$0,1,${COLUMNS}))}" $TMP_ITEM
  808.     Tmp_Var=`echo "$Item_Status"|tr -d '\012'`
  809.     awk "BEGIN{Max=$Top_Item+$DISPLAY_NUM}
  810.     FNR>=$Top_Item{if(FNR>=Max)exit
  811.     printf(\"%2d:%s %s\n\",FNR,substr(\"$Tmp_Var\",FNR,1),
  812.     substr(\$0,1,${COLUMNS}-5))}" "$TMP_SECTIONS"
  813.     echo "Enter 1-${Item_Num}, add, edit, help,"
  814.     if test "$Previous" -o "$Next"; then
  815.         Print "next, previous, "
  816.     fi
  817.     Print "quit, save :"
  818.     read Command_List||Command_List="$CONTROL_D"
  819.     Command_List=`echo "$Command_List"\
  820.     |tr '\011' ' '|tr ' ' '\012'|sed -e "/^$/d"`
  821.     clear
  822.     if test -z "$Command_List"; then
  823.         Help="y"
  824.     else
  825.         Help=""
  826.     fi
  827.     while test "$Command_List"
  828.         do
  829.         Command=`echo "$Command_List"|sed -n -e '1p'`
  830.         Command_List=`echo "$Command_List"|sed -e '1d'`
  831.         case "$Command" in
  832.             [0-9]|[0-9][0-9]) Do_Number "$Command";;
  833.             n*)    Do_Next;;
  834.             p*)    Do_Previous;;
  835.             a*)    Do_Add_Section;;
  836.             e*)    Do_Edit; break;;
  837.             h*)    Help="y";;
  838.             s*)    Done="s"; break;;
  839.             q*)    Done="q"
  840.             Item_Status=`echo "$Item_Status"|sed -e '1,$s/^./_/'`
  841.             break;;
  842.             *) Print "$Command is not a valid command. ">&2
  843.             Help="y";;
  844.         esac
  845.         done
  846.     if test "$Help"; then
  847.         Do_Help
  848.     fi
  849.     echo
  850.     done
  851. set +f
  852. # if new sections added, remove unused ones
  853. if test "$Item_Num" -gt "$Item_Dir"; then
  854.     Tmp_Var=`echo "$Item_Status"|awk "FNR>$Item_Dir{
  855.     if(\\$0==\"_\")printf(\"%d\n\", FNR)}"`
  856.     if test "$Tmp_Var"; then
  857.         Tmp_Var1=`echo "$Tmp_Var"|sed -e 's/$/d/'`
  858.         sed -e "$Tmp_Var1" "$TMP_SECTIONS">$TMP_FILE1
  859.         cp $TMP_FILE1 "$TMP_SECTIONS"
  860.         Item_Status=`echo "$Item_Status"|sed -e "$Tmp_Var1"`
  861.         Tmp_Var=""
  862.         Tmp_Var1=""
  863.         Item_Num=`wc -l<"$TMP_SECTIONS"|tr -d ' '`
  864.     fi
  865. fi
  866. }
  867.  
  868. # ###SECTION 100### Constants that redefine
  869. PROMPT1="(y=yes, e=edit, Y=yes to all, n=no, N=No to all):"
  870. FUNCTIONS="y"
  871. #
  872. echo "update-info.f (GNU texinfo @TEXINFO_VERSION@) @UPDATE_INFO_VERSION@"
  873.