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