From 7fde3bca549b545ddac7c43618a04e1128e1b6cb Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: May 31 2011 02:19:38 +0000 Subject: Update texinfo_restoreCrossReferences.sh. --- diff --git a/Scripts/Functions/Help/Backends/Texinfo/texinfo_restoreCrossReferences.sh b/Scripts/Functions/Help/Backends/Texinfo/texinfo_restoreCrossReferences.sh index 98f86eb..0bd14b2 100755 --- a/Scripts/Functions/Help/Backends/Texinfo/texinfo_restoreCrossReferences.sh +++ b/Scripts/Functions/Help/Backends/Texinfo/texinfo_restoreCrossReferences.sh @@ -35,19 +35,18 @@ function texinfo_restoreCrossReferences { local -a PATTERN local -a REPLACE - local LOCATION='' - # Define entry location. Verify first argument to make this - # function reusable. If no value is passed as first argument use - # entry global information value as default value instead. - if [[ "$1" != '' ]];then - LOCATION="$1" - else - LOCATION="$MANUAL_ENTRY" + # Define documentation entry. + local MANUAL_ENTRY="$1" + + # Verify documentation entry. If documentation entry is empty, + # stop script execution with an error message. + if [[ $MANUAL_ENTRY == '' ]];then + cli_printMessage "`gettext "The first positional parameter cannot be empty."`" --as-error-line fi # Build the node string using entry location. - local NODE=$(${FLAG_BACKEND}_getNode "$LOCATION") + local NODE=$(${FLAG_BACKEND}_getNode "$MANUAL_ENTRY") # Define regular expression patterns to match removed message # format produced by message_removeCrossReferences function. @@ -60,7 +59,7 @@ function texinfo_restoreCrossReferences { REPLACE[1]='\1' # Define list of entries to process. - local ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR} --pattern=".*\.${FLAG_BACKEND}") + local MANUAL_ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR} --pattern=".*\.${FLAG_BACKEND}") # Update node-related cross references. The node-related cross # reference definition, long ones specially, could require more @@ -72,11 +71,23 @@ function texinfo_restoreCrossReferences { # command to add a newline to the pattern space, the s command to # make the pattern replacement using the `g' flag to make it # global and finaly the command `b' to branch label named `a'. - sed -r -i ":a;N;s!${PATTERN[0]}!${REPLACE[0]}!g;ba" ${ENTRIES} + # + # Inside the pattern space, the `\<' and `\>' are used to restrict + # the match pattern to a word boundary. The word boundary + # restriction applied here is required to avoid undesired + # replacements when we replace singular words with their plurals. + # For example, if we need to change the word `Manual' to its + # plular (i.e., `Manuals'), and no boundary restriction is used in + # the pattern space to do that, we might end up having words like + # `Manualsssss'. This is because this sed command might be applied + # to the same file many times; and each time it is applied a new + # `Manuals' replaces the previous `Manuals' replacement to form + # `Manualss', `Manualsss', and so on for each interaction. + sed -r -i ":a;N;s!\<${PATTERN[0]}\>!${REPLACE[0]}!g;ba" ${MANUAL_ENTRIES} # Update menu-related cross references. Menu-related cross # references hardly appear in more than one line, so there is no # need to complicate the replacement command. - sed -r -i "s!${PATTERN[1]}!${REPLACE[1]}!" ${ENTRIES} + sed -r -i "s!\<${PATTERN[1]}\>!${REPLACE[1]}!" ${MANUAL_ENTRIES} }