Blame Automation/Modules/centos-art.sh-help/Texinfo/texinfo_makeSeeAlso.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# texinfo_makeSeeAlso.sh -- This function creates a list of links with
Alain Reguera Delgado 8f60cb
# section entries one level ahead from the current section entry being
Alain Reguera Delgado 8f60cb
# processed. Desition of what of these texinfo definitions to use is
Alain Reguera Delgado 8f60cb
# set inside the section entry itself, through the following
Alain Reguera Delgado 8f60cb
# construction:
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# @c -- <[centos-art(SeeAlso,TYPE)
Alain Reguera Delgado 8f60cb
# @c -- ]>
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# In this construction, the TYPE variable can be either `itemize',
Alain Reguera Delgado 8f60cb
# `enumerate' or `menu'.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function texinfo_makeSeeAlso {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Initialize variables.
Alain Reguera Delgado 8f60cb
    local CHILD_ENTRIES=''
Alain Reguera Delgado 8f60cb
    local CHILD_ENTRY=''
Alain Reguera Delgado 8f60cb
    local ENTRY_PATTERN=''
Alain Reguera Delgado 8f60cb
    local LIST_DEF=''
Alain Reguera Delgado 8f60cb
    local LIST_ENTRIES=''
Alain Reguera Delgado 8f60cb
    local LIST_TYPE=''
Alain Reguera Delgado 8f60cb
    local LIST_TYPE_PATTERN=''
Alain Reguera Delgado 8f60cb
    local MANUAL_ENTRY=''
Alain Reguera Delgado 8f60cb
    local TMARK=''
Alain Reguera Delgado 8f60cb
    local TMARK_PATTERN=''
Alain Reguera Delgado 8f60cb
    local TMARKS=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define absolute path to section entry.
Alain Reguera Delgado 8f60cb
    MANUAL_ENTRY="$1"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify section entry. When section entries are deleted, there is
Alain Reguera Delgado 8f60cb
    # no menu definition to set.
Alain Reguera Delgado 8f60cb
    if [[ ! -f $MANUAL_ENTRY ]];then
Alain Reguera Delgado 8f60cb
        return
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define `SeeAlso' translation marker regular expression pattern.
Alain Reguera Delgado 8f60cb
    TMARK_PATTERN="^@c -- <\[${CLI_NAME}\(SeeAlso(,(itemize|enumerate|menu))?\)$"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Retrieve `SeeAlso' translation marker definition lines. Be sure
Alain Reguera Delgado 8f60cb
    # to retrieve unique definitions only. If the same definition is
Alain Reguera Delgado 8f60cb
    # present more than once, it will be expanded in one pass. There's
Alain Reguera Delgado 8f60cb
    # no need to go through different passes in order to expand
Alain Reguera Delgado 8f60cb
    # repeated translation marker definition.
Alain Reguera Delgado 8f60cb
    TMARKS=$(egrep "${TMARK_PATTERN}" $MANUAL_ENTRY | sort | uniq)
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Remove spaces from translation marker definition lines in order
Alain Reguera Delgado 8f60cb
    # to process them correctly. Otherwise the definition line would
Alain Reguera Delgado 8f60cb
    # be broken on each space character and then that wouldn't be the
Alain Reguera Delgado 8f60cb
    # definition line we initially conceived.
Alain Reguera Delgado 8f60cb
    TMARKS=$(echo "$TMARKS" | sed -r 's/ /\\040/g')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define pattern used to build list of child sections. A child
Alain Reguera Delgado 8f60cb
    # section shares the same path information of its parent without
Alain Reguera Delgado 8f60cb
    # file extension. For example, if you have the `identity',
Alain Reguera Delgado 8f60cb
    # `identity-images' and `identity-images-themes' section entries,
Alain Reguera Delgado 8f60cb
    # `identity-images' is a child entry of `identity' likewise
Alain Reguera Delgado 8f60cb
    # `identity-images-themes' is a child entry of `identity-images'.
Alain Reguera Delgado 8f60cb
    ENTRY_PATTERN=$(echo "$MANUAL_ENTRY" | sed -r "s/\.${MANUAL_EXTENSION}$//")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define list of child entries we'll use as reference to build the
Alain Reguera Delgado 8f60cb
    # menu nodes. Reverse the output here to produce the correct value
Alain Reguera Delgado 8f60cb
    # based on menu nodes definition set further.
Alain Reguera Delgado 8f60cb
    CHILD_ENTRIES=$(cli_getFilesList $(dirname ${MANUAL_ENTRY}) \
Alain Reguera Delgado 8f60cb
        --pattern="^${ENTRY_PATTERN}-[[:alnum:]]+\.${MANUAL_EXTENSION}$" | sort -r | uniq )
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Loop through translation marker definition lines.
Alain Reguera Delgado 8f60cb
    for TMARK in $TMARKS;do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define list type based on translation marker definition.
Alain Reguera Delgado 8f60cb
        # Remember to revert back the space character transformation
Alain Reguera Delgado 8f60cb
        # we previously did, in order for the translation marker
Alain Reguera Delgado 8f60cb
        # regular expression pattern to match.
Alain Reguera Delgado 8f60cb
        LIST_TYPE=$(echo "$TMARK" | sed -r -e 's/\\040/ /g' -e "s/${TMARK_PATTERN}/\2/")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define list type default value.  This is, the list type used
Alain Reguera Delgado 8f60cb
        # when no list type is specified in the translation marker
Alain Reguera Delgado 8f60cb
        # construction properties field.
Alain Reguera Delgado 8f60cb
        if [[ $LIST_TYPE == '' ]];then
Alain Reguera Delgado 8f60cb
            LIST_TYPE="itemize"
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define list properties (type included).
Alain Reguera Delgado 8f60cb
        LIST_PROP=$(echo "$TMARK" | sed -r -e 's/\\040/ /g' -e "s/${TMARK_PATTERN}/\1/")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define `SeeAlso' translation marker regular expression
Alain Reguera Delgado 8f60cb
        # pattern that matches the translation marker definition.
Alain Reguera Delgado 8f60cb
        # Notice that we cannot use TMARK_PATTERN here because it
Alain Reguera Delgado 8f60cb
        # includes a selection list of all possible translation
Alain Reguera Delgado 8f60cb
        # markers that can provided and here we need to precisely set
Alain Reguera Delgado 8f60cb
        # the one being currently processed, not those whose could be
Alain Reguera Delgado 8f60cb
        # processed.
Alain Reguera Delgado 8f60cb
        LIST_TYPE_PATTERN="^@c -- <\[${CLI_NAME}\(SeeAlso${LIST_PROP}\)$"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Redefine list's entry based on translation marker definition.
Alain Reguera Delgado 8f60cb
        if [[ $LIST_TYPE =~ '^menu$' ]];then
Alain Reguera Delgado 8f60cb
            for CHILD_ENTRY in $CHILD_ENTRIES;do
Alain Reguera Delgado 8f60cb
                LIST_ENTRIES="* $(texinfo_getEntryNode "$CHILD_ENTRY")::\n${LIST_ENTRIES}"
Alain Reguera Delgado 8f60cb
            done
Alain Reguera Delgado 8f60cb
        elif [[ $LIST_TYPE =~ '^(itemize|enumerate)$' ]];then 
Alain Reguera Delgado 8f60cb
            for CHILD_ENTRY in $CHILD_ENTRIES;do
Alain Reguera Delgado 8f60cb
                LIST_ENTRIES="@item @ref{$(texinfo_getEntryNode "$CHILD_ENTRY")}\n${LIST_ENTRIES}"
Alain Reguera Delgado 8f60cb
            done
Alain Reguera Delgado 8f60cb
        else
Alain Reguera Delgado 8f60cb
            # When an translation marker isn't recognize, go on with
Alain Reguera Delgado 8f60cb
            # the next one in the list.
Alain Reguera Delgado 8f60cb
            continue
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define menu using menu nodes.
Alain Reguera Delgado 8f60cb
        LIST_DEF="@c -- <[${CLI_NAME}(SeeAlso${LIST_PROP})\n@${LIST_TYPE}\n${LIST_ENTRIES}@end ${LIST_TYPE}\n@c -- ]>"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Expand list definition using translation marker and list
Alain Reguera Delgado 8f60cb
        # definition itself. Be sure that no expansion be done when
Alain Reguera Delgado 8f60cb
        # the closing tag of translation marker isn't specified.
Alain Reguera Delgado 8f60cb
        # Otherwise, there might be lost of content.
Alain Reguera Delgado 8f60cb
        sed -r -i "/${LIST_TYPE_PATTERN}/{:a;N;/\n@c -- ]>$/!ba;s/.*/${LIST_DEF}/;}" $MANUAL_ENTRY
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Clean up both list definition and list entries. Otherwise
Alain Reguera Delgado 8f60cb
        # undesired concatenations happen.
Alain Reguera Delgado 8f60cb
        LIST_DEF=''
Alain Reguera Delgado 8f60cb
        LIST_ENTRIES=''
Alain Reguera Delgado 8f60cb
        LIST_TYPE=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
 
Alain Reguera Delgado 8f60cb
}