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

4c79b5
#!/bin/bash
4c79b5
#
4e0284
# texinfo_updateSectionNodes.sh -- This function updates section's
4e0284
# nodes definition files using section's menu definition file both
4e0284
# inside the same chapter.
4c79b5
#
2fe9b7
# 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
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
4e0284
function texinfo_updateSectionNodes {
4c79b5
edaa9d
    # Build list of chapter nodes using entries from chapter menu as
edaa9d
    # reference.
87235c
    local NODES=$(cat $(dirname ${MANUAL_ENTRY})/chapter-menu.${MANUAL_EXTENSION} \
4c79b5
        | sed -r 's!^\* !!' | sed -r 's!:{1,2}.*$!!g' \
edaa9d
        | egrep -v '^@(end )?menu$' | sed -r 's! !:!g')
4c79b5
edaa9d
    # Build chapter nodes based on chapter menu.
4c79b5
    for NODE in $NODES;do
4c79b5
d286ed
        local NODE=$(echo "${NODE}" | sed -r 's!:! !g')
d286ed
        local INCL=$(echo "${NODE}" | sed -r 's! !/!' | sed -r 's! !-!g' | sed -r 's!/(.+)!/\L\1!').${MANUAL_EXTENSION}
ef43e2
        local SECT=$(texinfo_getEntryTitle "$NODE")
ef43e2
        local CIND=$(texinfo_getEntryIndex "$NODE")
4c79b5
7d58ac
        # Create texinfo section file using templates, only if the
7d58ac
        # section file doesn't exist and hasn't been marked for
7d58ac
        # deletion.  Otherwise, when the files have been marked for
7d58ac
        # deletion, they will be created again from texinfo template
7d58ac
        # to working copy and that might create confusion.
5e989a
        if [[ ! -f ${MANUAL_BASEDIR_L10N}/$INCL ]] \
5e989a
            && [[ $(cli_getRepoStatus ${MANUAL_BASEDIR_L10N}/$INCL) != 'D' ]];then
858566
0f80c1
            # Retrive configuration lines from configuration file. Be
0f80c1
            # sure no line begining with `#' or space remain in the
0f80c1
            # line. Otherwise, it would be difficult to loop through
0f80c1
            # configuration lines.
0f80c1
            local CONFLINE=''
35dbd2
            local CONFLINES=$(cli_getConfigLines "${MANUAL_CONFIG_FILE}" "templates")
0f80c1
0f80c1
            # Initialize both left hand side and right hand side
0f80c1
            # configuration values.
0f80c1
            local CONFLHS=''
0f80c1
            local CONFRHS=''
0f80c1
0f80c1
            # Initialize absolute path to final texinfo template.
0f80c1
            local TEMPLATE=''
0f80c1
0f80c1
            # Define what section template to apply using
0f80c1
            # documentation entry absolute path and values provided by
0f80c1
            # configuration line. Be sure to break the loop in the
0f80c1
            # first match.
0f80c1
            for CONFLINE in $CONFLINES;do
0f80c1
0f80c1
                CONFLHS=$(echo $CONFLINE \
edaa9d
                    | gawk 'BEGIN{FS="="}; { print $1 }' \
0f80c1
                    | sed -r 's![[:space:]]*!!g')
858566
0f80c1
                CONFRHS=$(echo $CONFLINE \
edaa9d
                    | gawk 'BEGIN{FS="="}; { print $2 }' \
0f80c1
                    | sed -r 's![[:space:]]*!!g' | sed -r 's!^"(.+)"$!\1!')
7d58ac
5e989a
                if [[ ${MANUAL_BASEDIR_L10N}/${INCL} =~ $CONFRHS ]];then
6150a1
                    TEMPLATE="${MANUAL_TEMPLATE_L10N}/${CONFLHS}"
0f80c1
                    break
0f80c1
                fi
858566
0f80c1
            done
0f80c1
0f80c1
            # Verify existence of texinfo template file. If no
0f80c1
            # template is found, stop script execution with an error
0f80c1
            # message. We cannot continue without it.
0f80c1
            cli_checkFiles $TEMPLATE
0f80c1
0f80c1
            # Create documentation entry using texinfo template as
0f80c1
            # reference.
5e989a
            svn cp ${TEMPLATE} ${MANUAL_BASEDIR_L10N}/$INCL --quiet
0f80c1
4c79b5
        fi
0f80c1
edaa9d
        # Expand common translation markers in documentation entry.
5e989a
        cli_expandTMarkers "${MANUAL_BASEDIR_L10N}/$INCL"
edaa9d
edaa9d
        # Replace node, section and concept index definitions already
edaa9d
        # defined with node, section and concept index translation
574995
        # markers. Otherwise, incorrect sectioning may happen. Take
574995
        # care with index definitions, more than one index definition
574995
        # might be found in the section file but only the first
574995
        # concept index entry (i.e., `cindex') will be updated, the
574995
        # rest will remain as they are.
edaa9d
        sed -i -r \
574995
            -e '/^@node/c@node =NODE=' \
574995
            -e '/^@section/c@section =SECT=' \
574995
            -e '0,/^@cindex/c@cindex =CIND=' \
574995
            "${MANUAL_BASEDIR_L10N}/$INCL" 
edaa9d
d286ed
        # Before expading node, section and concept index, be sure
d286ed
        # that all slash characters (`/') be escaped.  Otherwise, they
d286ed
        # might be interpreted as separators and that isn't
d286ed
        # desireable in anyway. 
d286ed
        NODE=$(echo "$NODE" | sed -r 's/\//\\\//g')
d286ed
        SECT=$(echo "$SECT" | sed -r 's/\//\\\//g')
d286ed
        CIND=$(echo "$CIND" | sed -r 's/\//\\\//g')
d286ed
d286ed
        # Expand node, section and concept index translation
edaa9d
        # markers in documentation entry.
edaa9d
        sed -i -r \
d286ed
            -e "s/=NODE=/${NODE}/g" \
d286ed
            -e "s/=SECT=/${SECT}/g" \
d286ed
            -e "s/=CIND=/${CIND}/g" \
5e989a
            "${MANUAL_BASEDIR_L10N}/$INCL"
edaa9d
d286ed
        # Verify existence of chapter-nodes template file. If no
0f80c1
        # chapter-nodes template is found, stop script execution with
0f80c1
        # an error message. We cannot continue without it.
edaa9d
        cli_checkFiles ${MANUAL_TEMPLATE_L10N}/Chapters/chapter-nodes.${MANUAL_EXTENSION}
0f80c1
d286ed
        # Expand chapter node inclusion definition.
edaa9d
        cat ${MANUAL_TEMPLATE_L10N}/Chapters/chapter-nodes.${MANUAL_EXTENSION} \
edaa9d
            | sed -r "s!=INCL=!${INCL}!g"
0f80c1
d286ed
    # Dump chapter node definition into manual structure.
87235c
    done > $(dirname ${MANUAL_ENTRY})/chapter-nodes.${MANUAL_EXTENSION}
4c79b5
4c79b5
}