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

878a2b
#!/bin/bash
878a2b
#
878a2b
# texinfo_makeSeeAlso.sh -- This function creates a list of links with
878a2b
# section entries one level ahead from the current section entry being
878a2b
# processed. Desition of what of these texinfo definitions to use is
878a2b
# set inside the section entry itself, through the following
878a2b
# construction:
878a2b
#
878a2b
# @c -- <[centos-art(SeeAlso,TYPE)
878a2b
# @c -- ]>
878a2b
#
878a2b
# In this construction, the TYPE variable can be either `itemize',
878a2b
# `enumerate' or `menu'.
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_makeSeeAlso {
878a2b
878a2b
    # Initialize variables.
878a2b
    local CHILD_ENTRIES=''
878a2b
    local CHILD_ENTRY=''
878a2b
    local ENTRY_PATTERN=''
878a2b
    local LIST_DEF=''
878a2b
    local LIST_ENTRIES=''
878a2b
    local LIST_TYPE=''
878a2b
    local LIST_TYPE_PATTERN=''
878a2b
    local MANUAL_ENTRY=''
878a2b
    local TMARK=''
878a2b
    local TMARK_PATTERN=''
878a2b
    local TMARKS=''
878a2b
878a2b
    # Define absolute path to section entry.
878a2b
    MANUAL_ENTRY="$1"
878a2b
878a2b
    # Verify section entry. When section entries are deleted, there is
878a2b
    # no menu definition to set.
878a2b
    if [[ ! -f $MANUAL_ENTRY ]];then
878a2b
        return
878a2b
    fi
878a2b
446449
    # Define `SeeAlso' translation marker regular expression pattern.
7228ae
    TMARK_PATTERN="^@c -- <\[${CLI_NAME}\(SeeAlso(,(itemize|enumerate|menu))?\)$"
878a2b
446449
    # Retrieve `SeeAlso' translation marker definition lines. Be sure
446449
    # to retrieve unique definitions only. If the same definition is
878a2b
    # present more than once, it will be expanded in one pass. There's
878a2b
    # no need to go through different passes in order to expand
878a2b
    # repeated translation marker definition.
878a2b
    TMARKS=$(egrep "${TMARK_PATTERN}" $MANUAL_ENTRY | sort | uniq)
878a2b
878a2b
    # Remove spaces from translation marker definition lines in order
878a2b
    # to process them correctly. Otherwise the definition line would
878a2b
    # be broken on each space character and then that wouldn't be the
878a2b
    # definition line we initially conceived.
878a2b
    TMARKS=$(echo "$TMARKS" | sed -r 's/ /\\040/g')
878a2b
878a2b
    # Define pattern used to build list of child sections. A child
878a2b
    # section shares the same path information of its parent with out
878a2b
    # file extension. For example, if you have the `identity',
878a2b
    # `identity-images' and `identity-images-themes' section entries,
878a2b
    # `identity-images' is a child entry of `identity' likewise
878a2b
    # `identity-images-themes' is a child entry of `identity-images'.
878a2b
    ENTRY_PATTERN=$(echo "$MANUAL_ENTRY" | sed -r "s/\.${MANUAL_EXTENSION}$//")
878a2b
878a2b
    # Define list of child entries we'll use as reference to build the
878a2b
    # menu nodes. Reverse the output here to produce the correct value
878a2b
    # based on menu nodes definition set further.
878a2b
    CHILD_ENTRIES=$(cli_getFilesList $(dirname ${MANUAL_ENTRY}) \
604e9b
        --pattern="^.+/${ENTRY_PATTERN}-[[:alnum:]]+\.${MANUAL_EXTENSION}$" | sort -r | uniq )
878a2b
878a2b
    # Loop through translation marker definition lines.
878a2b
    for TMARK in $TMARKS;do
878a2b
878a2b
        # Define list type based on translation marker definition.
878a2b
        # Remember to revert back the space character transformation
878a2b
        # we previously did, in order for the translation marker
878a2b
        # regular expression pattern to match.
878a2b
        LIST_TYPE=$(echo "$TMARK" | sed -r -e 's/\\040/ /g' -e "s/${TMARK_PATTERN}/\2/")
878a2b
878a2b
        # Define list type default value.  This is, the list type used
878a2b
        # when no list type is specified in the translation marker
878a2b
        # construction properties field.
878a2b
        if [[ $LIST_TYPE == '' ]];then
878a2b
            LIST_TYPE="itemize"
878a2b
        fi
878a2b
878a2b
        # Define list properties (type included).
878a2b
        LIST_PROP=$(echo "$TMARK" | sed -r -e 's/\\040/ /g' -e "s/${TMARK_PATTERN}/\1/")
878a2b
878a2b
        # Define `SeeAlso' transltaion marker regular expression
878a2b
        # pattern that matches the translation marker definition.
878a2b
        # Notice that we cannot use TMARK_PATTERN here because it
878a2b
        # includes a selection list of all possible translation
878a2b
        # markers that can provided and here we need to precisely set
878a2b
        # the one being currently processed, not those whose could be
878a2b
        # processed.
7228ae
        LIST_TYPE_PATTERN="^@c -- <\[${CLI_NAME}\(SeeAlso${LIST_PROP}\)$"
878a2b
878a2b
        # Redefine list's entry based on translation marker definition.
878a2b
        if [[ $LIST_TYPE =~ '^menu$' ]];then
878a2b
            for CHILD_ENTRY in $CHILD_ENTRIES;do
878a2b
                LIST_ENTRIES="* $(texinfo_getEntryNode "$CHILD_ENTRY")::\n${LIST_ENTRIES}"
878a2b
            done
878a2b
        elif [[ $LIST_TYPE =~ '^(itemize|enumerate)$' ]];then 
878a2b
            for CHILD_ENTRY in $CHILD_ENTRIES;do
878a2b
                LIST_ENTRIES="@item @ref{$(texinfo_getEntryNode "$CHILD_ENTRY")}\n${LIST_ENTRIES}"
878a2b
            done
878a2b
        else
878a2b
            # When an translation marker isn't recognize, go on with
878a2b
            # the next one in the list.
878a2b
            continue
878a2b
        fi
878a2b
878a2b
        # Define menu using menu nodes.
7228ae
        LIST_DEF="@c -- <[${CLI_NAME}(SeeAlso${LIST_PROP})\n@${LIST_TYPE}\n${LIST_ENTRIES}@end ${LIST_TYPE}\n@c -- ]>"
878a2b
878a2b
        # Expand list definition using translation marker and list
878a2b
        # definition itself. Be sure that no expansion be done when
878a2b
        # the closing tag of translation marker isn't specified.
878a2b
        # Otherwise, there might be lost of content.
878a2b
        sed -r -i "/${LIST_TYPE_PATTERN}/{:a;N;/\n@c -- ]>$/!ba;s/.*/${LIST_DEF}/;}" $MANUAL_ENTRY
878a2b
878a2b
        # Clean up both list definition and list entries. Otherwise
878a2b
        # undesired concatenations happen.
878a2b
        LIST_DEF=''
878a2b
        LIST_ENTRIES=''
878a2b
        LIST_TYPE=''
878a2b
878a2b
    done
878a2b
 
878a2b
}