Blame Scripts/Functions/Help/Backends/Texinfo/texinfo_deleteCrossReferences.sh

f8fb31
#!/bin/bash
f8fb31
#
1afa3c
# texinfo_deleteCrossReferences.sh -- This function looks inside
e9dba2
# texinfo source files, from section level on, and removes all cross
e9dba2
# referece definitions related to a documentation entry. Use this
1afa3c
# function in coordination with texinfo_deleteEntry function, in order
e9dba2
# to keep cross reference information, inside the documentation
e9dba2
# manual, syncronized.
f8fb31
#
2d3646
# 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
1afa3c
function texinfo_deleteCrossReferences {
f8fb31
f8fb31
    local -a PATTERN
f8fb31
    local -a REPLACE
f2c0f9
    local LOCATION=''
f8fb31
f2c0f9
    # Define entry location. Verify first argument to make this
f2c0f9
    # function reusable. If no value is passed as first argument use
f2c0f9
    # entry global information value as default value instead.
f2c0f9
    if [[ "$1" != '' ]];then
f2c0f9
        LOCATION="$1"
f2c0f9
    else
f2c0f9
        LOCATION="$ENTRY"
f2c0f9
    fi
f2c0f9
f2c0f9
    # Build the node string using entry location.
f2c0f9
    local NODE=$(echo "$LOCATION" \
6fa673
        | cut -d / -f8- \
f8fb31
        | tr '/' ' ' \
54ea1a
        | sed -r \
54ea1a
            -e "s/(chapter-intro\.texi|\.texi)$//" \
54ea1a
            -e 's! !( |\\n)!g')
f8fb31
f8fb31
    # Define regular expression patterns for texinfo cross reference
f8fb31
    # commands.
f8fb31
    PATTERN[0]="@(pxref|xref|ref)\{(${NODE})\}"
f8fb31
    PATTERN[1]="^(\* ${NODE}:(.*)?:(.*)?)$"
f8fb31
f8fb31
    # Define replacement string for missing entries. It is convenient
f8fb31
    # to keep missing entries in documentation for documentation team
f8fb31
    # to know. Removing the missing cross reference may intorudce
f8fb31
    # confussion. Imagine that! you are spending lots of hours in an
f8fb31
    # article and suddenly one of your cross refereces disappears with
f8fb31
    # no visible reason, with the next working copy update you
f8fb31
    # perform. That's frustrating. Instead, when centos-art.sh script
f8fb31
    # finds a missing cross reference it removes the link and remark
f8fb31
    # the issue for you to act on it.
f8fb31
    REPLACE[0]='--- @strong{'`gettext "Removed"`'}(\1:\2) ---'
f8fb31
    REPLACE[1]='@comment --- '`gettext "Removed"`'(\1) ---'
f8fb31
54ea1a
    # Define list of entries to process.
da9312
    local ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR} --pattern='.*\.texi')
54ea1a
54ea1a
    # Update node-related cross references. The node-related cross
54ea1a
    # reference definition, long ones specially, could require more
54ea1a
    # than one line to be set. By default, GNU sed does not matches 
54ea1a
    # newline characters in the pattern space, so we need to make use
54ea1a
    # of `label' feature and the `N' command in order to build a
54ea1a
    # pattern space that includes the newline character in it. Here we
54ea1a
    # use the `a' letter to name the label we use, followed by N
f2c0f9
    # command to add a newline to the pattern space, the s command to
f2c0f9
    # make the pattern replacement using the `g' flag to make it
f2c0f9
    # global and finaly the command `b' to branch label named `a'.
54ea1a
    sed -r -i ":a;N;s!${PATTERN[0]}!${REPLACE[0]}!g;ba" ${ENTRIES}
54ea1a
54ea1a
    # Update menu-related cross references. Menu-related cross
54ea1a
    # references hardly appear in more than one line, so there is no
54ea1a
    # need to complicate the replacement command.
54ea1a
    sed -r -i "s!${PATTERN[1]}!${REPLACE[1]}!" ${ENTRIES}
f8fb31
f8fb31
}