Blame Scripts/Functions/Help/help_restoreCrossReferences.sh

f8fb31
#!/bin/bash
f8fb31
#
0211a4
# help_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
0211a4
# help_deleteCrossReferences function. The
0211a4
# help_restoreCrossReferences function relays in the removed message
0211a4
# format produced by help_deleteCrossReferences function, in order
e9dba2
# to return them back into the link format. 
f8fb31
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
f8fb31
# 
f8fb31
# This program is free software; you can redistribute it and/or
f8fb31
# modify it under the terms of the GNU General Public License as
f8fb31
# published by the Free Software Foundation; either version 2 of the
f8fb31
# License, or (at your option) any later version.
f8fb31
# 
f8fb31
# This program is distributed in the hope that it will be useful, but
f8fb31
# 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
f8fb31
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
f8fb31
# USA.
f8fb31
# 
f8fb31
# ----------------------------------------------------------------------
f8fb31
# $Id$
f8fb31
# ----------------------------------------------------------------------
f8fb31
0211a4
function help_restoreCrossReferences {
f8fb31
f8fb31
    local -a PATTERN
f8fb31
    local -a REPLACE
2924ec
    local LOCATION=''
f8fb31
2924ec
    # Define entry location. Verify first argument to make this
2924ec
    # function reusable. If no value is passed as first argument use
2924ec
    # entry global information value as default value instead.
2924ec
    if [[ "$1" != '' ]];then
2924ec
        LOCATION="$1"
2924ec
    else
2924ec
        LOCATION="$ENTRY"
2924ec
    fi
2924ec
2924ec
    # Build the node string using entry location.
2924ec
    local NODE=$(echo "$LOCATION" \
5285d6
        | cut -d / -f8- \
f8fb31
        | tr '/' ' ' \
1e404b
        | sed -r \
1e404b
            -e "s/(chapter-intro\.texi|\.texi)$//" \
1e404b
            -e 's! !( |\\n)!g')
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.
f8fb31
    REPLACE[0]='@\1{\2}'
f8fb31
    REPLACE[1]='\1'
f8fb31
1e404b
    # Define list of entries to process.
759d18
    local ENTRIES=$(cli_getFilesList "${MANUAL_BASEDIR}" '.*\.texi')
1e404b
1e404b
    # Set action preamble.
467208
    cli_printActionPreamble "$ENTRIES" '' ''
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'.
1e404b
    sed -r -i ":a;N;s!${PATTERN[0]}!${REPLACE[0]}!g;ba" ${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.
1e404b
    sed -r -i "s!${PATTERN[1]}!${REPLACE[1]}!" ${ENTRIES}
f8fb31
f8fb31
}