Blame Scripts/Bash/Functions/Help/Texinfo/texinfo_restoreCrossReferences.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# texinfo_restoreCrossReferences.sh -- This function looks inside
878a2b
# texinfo source files, from section level on, and restores any cross
878a2b
# reference related to a documentation entry. This function is used in
878a2b
# those cases where documentation entries are created/recreated to
878a2b
# documentation structure. It is a verification that looks for
878a2b
# matching documentation entries previously defined as removed by
878a2b
# texinfo_deleteCrossReferences function. The
878a2b
# texinfo_restoreCrossReferences function relays in the removed
878a2b
# message format produced by texinfo_deleteCrossReferences
878a2b
# function, in order to return them back into the link format. 
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function texinfo_restoreCrossReferences {
878a2b
878a2b
    local -a PATTERN
878a2b
    local -a REPLACE
878a2b
878a2b
    # Define documentation entry.
878a2b
    local MANUAL_ENTRY="$1"
878a2b
878a2b
    # Verify documentation entry. If documentation entry is empty,
878a2b
    # stop script execution with an error message.
878a2b
    if [[ $MANUAL_ENTRY == '' ]];then
878a2b
        cli_printMessage "`gettext "The first positional parameter cannot be empty."`" --as-error-line
878a2b
    fi
878a2b
878a2b
    # Build the node string using entry location.
878a2b
    local NODE="$(texinfo_getEntryNode "$MANUAL_ENTRY")"
878a2b
878a2b
    # Define regular expression patterns to match removed message
878a2b
    # format produced by message_removeCrossReferences function.
878a2b
    PATTERN[0]="--- @strong\{`gettext "Removed"`\}\((pxref|xref|ref):(${NODE})\) ---"
878a2b
    PATTERN[1]="^@comment --- `gettext "Removed"`\((\* ${NODE}:(.*)?:(.*)?)\) ---$"
878a2b
878a2b
    # Define replacement string to turn removed message back to cross
878a2b
    # reference link.
878a2b
    REPLACE[0]='\@\1{\2}'
878a2b
    REPLACE[1]='\1'
878a2b
878a2b
    # Define list of entries to process.
878a2b
    local MANUAL_ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR_L10N} \
22d9b5
        --pattern="^.+\.${MANUAL_EXTENSION}$")
123ee8
   
878a2b
    # Update node-related cross references. The node-related cross
878a2b
    # reference definition, long ones specially, could require more
878a2b
    # than one line to be set. By default, GNU sed does not matches 
878a2b
    # newline characters in the pattern space, so we need to make use
878a2b
    # of `label' feature and the `N' command in order to build a
878a2b
    # pattern space that includes the newline character in it. Here we
878a2b
    # use the `a' letter to name the label we use, followed by N
878a2b
    # command to add a newline to the pattern space, the s command to
878a2b
    # make the pattern replacement using the `g' flag to make it
123ee8
    # global and finally the command `b' to branch label named `a'.
878a2b
    sed -r -i ":a;N;s!${PATTERN[0]}!${REPLACE[0]}!g;ba" ${MANUAL_ENTRIES}
878a2b
878a2b
    # Update menu-related cross references. Menu-related cross
878a2b
    # references hardly appear in more than one line, so there is no
878a2b
    # need to complicate the replacement command.
878a2b
    sed -r -i "s!${PATTERN[1]}!${REPLACE[1]}!" ${MANUAL_ENTRIES}
878a2b
878a2b
}