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

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