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

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