📄 update-info
字号:
#!/bin/sh# update-info -- update dir file from all extant info pages.# # This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2, or (at your option)# any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, you can either send email to this# program's maintainer or write to: The Free Software Foundation,# Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.# # Author: rhawes@dmapub.dma.org. Please report bugs to him.# # run this program to install update-info# ###SECTION 0### install script# These constants set the version numbers for both files:PROGRAM_VERSION="1.4"PACKAGE_VERSION="4.0"# ENVIRONMENTif test -z "$TMPDIR"; then TMPDIR="/usr/tmp"fiTMP_SED="$TMPDIR/uss$$.info"TMP_F_ADD_SECTION="$TMPDIR/ufa$$.info"TMP_F_DELETE_INVALID="$TMPDIR/ufd$$.info"TMP_F_INSERT_MISSING="$TMPDIR/ufi$$.info"TMP_FILES="$TMP_SED $TMP_F_ADD_SECTION $TMP_F_DELETE_INVALID\ $TMP_F_INSERT_MISSING"trap 'rm -f $TMP_FILES' 0# file boundariesUPDATE_INFO="/^# _file: 'update-info'_/"UPDATE_INFO_F="/^# _file: 'update-info.f'_/"# @F_ADD_SECTION@echo 'Item_Num=`expr "$Item_Num" + "1"`echo "$1">>"$TMP_SECTIONS"if test "$Item_Status"; then Item_Status=`echo "${Item_Status}X"`else Item_Status="X"fi '>$TMP_F_ADD_SECTION# @F_INSERT_MISSING@echo 'if test -z "$Create_Node"; then rm -f ${Info_Node}.old cp $Info_Node ${Info_Node}.old echo "$BACKUP_MSG"fiecho "/$MENU_BEGIN/+,$ dr $TMP_MENUwq"|ed -s $Info_Node>/dev/null'>$TMP_F_INSERT_MISSING# @F_DELETE_INVALID@echo 'rm -f ${Info_Node}.oldcp $Info_Node ${Info_Node}.oldecho "$BACKUP_MSG"echo "/$MENU_BEGIN/+,$ dwq"|ed -s $Info_Node>/dev/nullsed -f "$TMP_SED" "$TMP_MENU">>"$Info_Node"'>$TMP_F_DELETE_INVALIDcat<<Sed_Script_EOF>$TMP_SEDs/@UPDATE_INFO_VERSION@/$PROGRAM_VERSION/gs/@TEXINFO_VERSION@/$PACKAGE_VERSION/gs/@SET_ITEM@/Item_Status=\`echo "\$Item_Status"|sed -e "\${1}s%^.*%\${2}%"\`//@F_ADD_SECTION@/r $TMP_F_ADD_SECTION/@F_ADD_SECTION@/d/@F_DELETE_INVALID@/r $TMP_F_DELETE_INVALID/@F_DELETE_INVALID@/d/@F_INSERT_MISSING@/r $TMP_F_INSERT_MISSING/@F_INSERT_MISSING@/dSed_Script_EOFsed -e "1,${UPDATE_INFO}d" -e "$UPDATE_INFO_F,\$d" -f $TMP_SED $0>update-infosed -e "1,${UPDATE_INFO_F}d" -f $TMP_SED $0>update-info.fchmod +x update-info update-info.fecho "installed update-info, and update-info.f into `pwd`"rm -f $TMP_FILESexit# _file: 'update-info'_#!/bin/sh#update-info (GNU texinfo @TEXINFO_VERSION@) @UPDATE_INFO_VERSION@#Copyright (C) 1997 Free Software Foundation, Inc.#update-info comes with NO WARRANTY, to the extent permitted by law.#You may redistribute copies of update-info#under the terms of the GNU General Public License.#For more information about these matters, see the files named COPYING."#Author: Richard L. Hawes# ###SECTION 1### Constantsset -h 2>/dev/null# ENVIRONMENTif test -z "$TMPDIR"; then TMPDIR="/usr/tmp"fiif test -z "$LINES"; then LINES=24fiif test -z "$COLUMNS"; then COLUMNS=80fiif test -z "$EDITOR"; then EDITOR=vifiif test -z "$LINENO"; then LINENO="0"fi# constants redefined by update-info.fPROMPT1="(y=yes, Y=yes to all, n=no, N=No to all):"FUNCTIONS=""#ARGUMENTS="$*"DISPLAY_NUM=`expr "$LINES" - 4`CONTROL_D="{Ctrl-D}"DIR_SECTION="^INFO-DIR-SECTION"ENTRY_END="^END-INFO-DIR-ENTRY"ENTRY_START="^START-INFO-DIR-ENTRY"MENU_BEGIN='^\*\([ ]\)\{1,\}Menu:'MENU_ITEM='^\* ([^ ]).*:([ ])+\('SECTION_TITLE="^[A-Za-z0-9]"MENU_FILTER1='s/^\*\([ ]\)\{1,\}/* /'MENU_FILTER2='s/\([ ]\)\{1,\}$//g'TMP_ITEM="${TMPDIR}/ui${$}.info"TMP_LIST="${TMPDIR}/ul${$}.info"TMP_MENU="${TMPDIR}/um${$}.info"TMP_SECTIONS="${TMPDIR}/us${$}.info" # used only in Detect_MissingTMP_SED="$TMP_SECTIONS" # used only in Detect_Invalid routinesTMP_FILE1="${TMPDIR}/ux${$}.info"TMP_FILE2="${TMPDIR}/uy${$}.info"TMP_COUNT="$TMP_FILE2"TMP_FILE_LIST="$TMP_LIST $TMP_MENU $TMP_SECTIONS $TMP_FILE1 $TMP_FILE2\ $TMP_ITEM"TRY_HELP_MSG="Try --help for more information"if zcat --version 2>/dev/null>/dev/null; then CAT_COMMAND="zcat -f"else echo "$0:$LINENO: GNU zcat not found">&2 CAT_COMMAND="cat"fi# ###SECTION 100### main program#variables set by optionsCreate_Node=""Debug=":"Interactive=""Load_Functions="y"Mode=""#Inserts="0"Inserts_Total="0"Invalid="0"Invalid_Total="0"Changed=""while test "$*" do case "$1" in -c) Create_Node="y";; -ci|-ic) Create_Node="y"; Interactive="y";; -cif|-cfi|-ifc|-icf|-fci|-fic) Create_Node="y" Interactive="y"; Load_Functions="";; --debug) set -eux; Debug="set>&2";; -d|--delete) Mode="Detect_Invalid";; -f) Load_Functions="";; -i|--interactive) Interactive="y";; -fi|-if) Load_Functions=""; Interactive="y";; -id|-di) Mode="Detect_Invalid"; Interactive="y";; +i|+d|+f);; --version)cat<<VersionEOFupdate-info (GNU texinfo @TEXINFO_VERSION@) @UPDATE_INFO_VERSION@Copyright (C) 1997 Free Software Foundation, Inc.update-info comes with NO WARRANTY, to the extent permitted by law.You may redistribute copies of update-infounder the terms of the GNU General Public License.For more information about these matters, see the files named COPYING.Author: Richard L. HawesVersionEOF exit;; --help)cat<<HelpEndOfFileUsage: update-info [OPTION]... INFO_PATH/INFO_DIR_FILEIt detects and inserts missing menu items into the info node file.Options:-c create a new info node --debug print debug information to standard error path-d, --delete delete invalid menu items (ignore missing menu items)-f do not load functions (file update-info.f) --help print this help message and exit-i, --interactive interactive mode prompts before inserting or removing menu items --version print current version and exitBackup of the info node has a '.old' suffix added. This is a shell script.Files: update-info.f -- contains functions (optional).Environment Variables: COLUMNS, EDITOR, LINES, TMPDIREmail bug reports to bug-texinfo@gnu.org.HelpEndOfFile exit;; [-+]*) echo "$0:$LINENO: \"$1\" is not a valid option">&2 echo "$TRY_HELP_MSG">&2 exit 2;; *) break;; esac shift doneif test "$#" -lt "1"; then echo "$0:$LINENO: Too few parameters">&2 echo "$TRY_HELP_MSG">&2 exit 2elif test "$#" -gt "1"; then echo "$0:$LINENO: Too many parameters">&2 echo "$TRY_HELP_MSG">&2 exit 2fiInfo_Path="$1"Info_Node=`basename "$Info_Path"`if echo "$Info_Node"|grep ".*dir$">/dev/null; then :else echo "$0:$LINENO: $Info_Node is not a valid info node name">&2 exit 2fiInfo_Pathname=`dirname "$Info_Path"`cd "$Info_Pathname"||exitBACKUP_MSG="Backed up $Info_Node to ${Info_Node}.old."HANGUP_MSG="Hang up on \"update-info $ARGUMENTS\""INSERT_MSG="menu item(s) were inserted (not counting duplicates)."INSERT_MSG2="total menu item(s) were inserted into `pwd`/$Info_Node"DELETE_MSG="invalid menu item(s) were removed (not counting duplicates)."DELETE_MSG2="total invalid menu item(s) were removed from `pwd`/$Info_Node"if test "$Create_Node"; then if test "$Mode"; then echo "$0:$LINENO: ERROR: Illogical option combination: -d -c">&2 echo "$TRY_HELP_MSG">&2 exit 2 fi if test -f "$Info_Node"; then rm -f ${Info_Node}.old mv "$Info_Node" "${Info_Node}.old" echo "$BACKUP_MSG" fi echo "Creating new Info Node: `pwd`/$Info_Node"cat>$Info_Node<<NodeEndOfFile||exitThis is the file .../info/dir, which contains the topmost node of theInfo hierarchy. The first time you invoke Info you start offlooking at that node, which is (dir)Top.File: dir Node: Top This is the top of the INFO tree This (the Directory node) gives a menu of major topics. Typing "d" returns here, "q" exits, "?" lists all INFO commands, "h" gives a primer for first-timers, "mTexinfo<Return>" visits Texinfo topic, etc. Or click mouse button 2 on a menu item or cross reference to select it. --- PLEASE ADD DOCUMENTATION TO THIS TREE. (See INFO topic first.) ---* Menu: The list of major topics begins on the next line.NodeEndOfFileelse if test ! -f "$Info_Node"; then echo "$0:$LINENO: $Info_Node is irregular or nonexistant">&2 exit 2 elif test ! -r "$Info_Node"; then echo "$0:$LINENO: $Info_Node is not readable">&2 exit 2 elif test ! -w "$Info_Node"; then echo "$0:$LINENO: $Info_Node is not writeable">&2 exit 2 fifiif test "$Load_Functions" -a "$Interactive" -a -z "$Mode"; then if FUNCTIONS_VERSION=`( update-info.f )`; then if test `echo "$FUNCTIONS_VERSION"\ |cut -d' ' -f5` = "@UPDATE_INFO_VERSION@"; then echo "Loading functions..." . update-info.f else echo "$0:$LINENO: wrong version of update-info.f">&2 echo "(functions were not loaded)">&2 fi else echo "(functions were not loaded)">&2 fifitrap ' eval "$Debug"; rm -f $TMP_FILE_LIST; exit ' 0if test "$Interactive"; then if test ! -t "1"; then echo "$0:$LINENO: Cannot run in interactive mode "\ "standard out is redirected">&2 exit 2 fi trap ' ' 2 3else trap ' rm -f $TMP_FILE_LIST echo "$0:$LINENO: received INT signal. All edits are canceled.">&2 exit ' 2 trap ' rm -f $TMP_FILE_LIST echo "$0:$LINENO: received QUIT signal. All edits are canceled.">&2 exit ' 3fiif test -z "$Mode"; then trap ' if test "$Changed"; then { echo $HANGUP_MSG @F_INSERT_MISSING@ Inserts_Total=`wc -c<"$TMP_COUNT"` echo $Inserts_Total $INSERT_MSG2 }|mail "$LOGNAME" fi rm -f $TMP_FILE_LIST exit ' 1else trap ' if test "$Changed"; then { echo $HANGUP_MSG @F_DELETE_INVALID@ Invalid_Total=`wc -l<"$TMP_SED"` echo $Invalid_Total $DELETE_MSG2 }|mail $LOGNAME fi rm -f $TMP_FILE_LIST exit ' 1fised -e "1,/$MENU_BEGIN/d" -e "$MENU_FILTER1" -e "$MENU_FILTER2"<$Info_Node\|tee $TMP_MENU\|sed -n -e '/\* /{s/).*$//gs/\.gz$//s/\.info$//s/^.*(//p}'|sort -u>$TMP_FILE1ls -F|sed -e '/\/$/d' -e '/[-.][0-9]/d'\ -e '/:$/d' -e '/^$/d' -e "/^${Info_Node}~\$/d"\ -e "/^${Info_Node}\$/d" -e "/^${Info_Node}.old\$/d"\ -e 's/\.gz$//' -e 's/\.info$//'|sort>$TMP_FILE2if test -z "$Mode"; then #Detect Missing comm -13 $TMP_FILE1 $TMP_FILE2>$TMP_LIST cat</dev/null>$TMP_COUNT #get sections, initialize variables sed -n -e "/$SECTION_TITLE/p" "$TMP_MENU">"$TMP_SECTIONS" Item_Num=`wc -l<"$TMP_SECTIONS"|tr -d ' '` Item_Status=`echo\ |awk "BEGIN{for(i=1;i<=${Item_Num};i++)printf(\"_\n\")}"` Item_Dir="$Item_Num" for Info_Name in `cat $TMP_LIST` do if test -r "$Info_Name"; then Info_File="$Info_Name" elif test -r "${Info_Name}.info"; then Info_File="${Info_Name}.info" elif test -r "${Info_Name}.gz"; then Info_File="${Info_Name}.gz" elif test -r "${Info_Name}.info.gz"; then Info_File="${Info_Name}.info.gz" else echo "$0:$LINENO: can't find info file for ${Info_Name}?">&2 fi #generate menu item echo|tr -d '\012'>$TMP_FILE1 eval $CAT_COMMAND "$Info_File"\ |sed -n -e "/$DIR_SECTION/w $TMP_FILE1"\ -e "/$ENTRY_START/,/$ENTRY_END/{ $MENU_FILTER1 p }"|awk "BEGIN{Mode=0} /^$/{if(Mode==1)exit} /^([ ])+([^ ])+/{if(Mode==1)print} /^[^ ]/{if(Mode==1)exit} /${MENU_ITEM}${Info_Name}\)\./{if(Mode==0){Mode++ print} else exit}">"$TMP_ITEM" if test ! -s "$TMP_ITEM"; then echo "* $Info_Name: ($Info_Name).">"$TMP_ITEM" fi Item_Status=`echo "$Item_Status"|sed -e '1,$s/^./_/'` if test -s "$TMP_FILE1"; then Item_Section=`sed -e "s/$DIR_SECTION[ ]*//"\ <$TMP_FILE1` else Item_Section=`echo "Miscellaneous"` fi Size=`echo "$Item_Section"|wc -l|tr -d ' '` # initialize variables, check for new sections Num1=1 while test "$Num1" -le "$Size" do Item=`echo "$Item_Section"|sed -n -e "${Num1}p"` if Num=`grep -in "^$Item$" "$TMP_SECTIONS"`; then Num=`echo "$Num"|sed -e 's/:.*$//g'` ##F#Set_Item set "$Num" "X" @SET_ITEM@ else set "$Item" @F_ADD_SECTION@ fi Num1=`expr "$Num1" + "1"` done if test "$Interactive"; then echo "$Item_Section" cat "$TMP_ITEM" echo "add menu item for $Info_File? " while true do
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -