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

4c79b5
#!/bin/bash
4c79b5
#
993f6a
# texinfo_updateNodes.sh -- This function updates chapter's nodes
4c79b5
# definition using the chapter's menu as reference.
4c79b5
#
3b0984
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
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
993f6a
function texinfo_updateNodes {
4c79b5
66b6ae
    # Retrive nodes' entries from chapter-menu.texinfo file.
9fa13b
    local NODES=$(cat $MANUAL_CHAPTER_DIR/chapter-menu.${MANUAL_EXTENSION} \
4c79b5
        | sed -r 's!^\* !!' | sed -r 's!:{1,2}.*$!!g' \
4c79b5
        | egrep -v '^@(end )?menu$' | sed -r 's! !:!g' | sort | uniq)
4c79b5
4c79b5
    # Re-build node structure based on menu information.
4c79b5
    for NODE in $NODES;do
4c79b5
fa17ed
        NODE=$(echo "${NODE}" | sed -r 's!:! !g')
420e77
        SECT=$(echo "${NODE}" | cut -d' ' -f2- | sed -r 's! !/!g')
9fa13b
        INCL=$(echo "${NODE}" | sed -r 's! !/!g').${MANUAL_EXTENSION}
420e77
        CIND=$(echo "${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.
7d58ac
        if [[ ! -f ${MANUAL_BASEDIR}/$INCL ]] \
7d58ac
            && [[ $(cli_getRepoStatus ${MANUAL_BASEDIR}/$INCL) != 'D' ]];then
858566
0f80c1
            # Define absolute path to section templates assignment
0f80c1
            # file. This is the file that hold the relation between
0f80c1
            # section template files and repository paths when
0f80c1
            # documentation entries are created.
0f80c1
            local CONFFILE="${MANUAL_TEMPLATE}/${MANUAL_NAME}.conf" 
0f80c1
0f80c1
            # Verify existence of configuration file.
0f80c1
            cli_checkFiles $CONFFILE
0f80c1
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=''
0f80c1
            local CONFLINES=$(cat ${CONFFILE} \
108ddd
                | egrep -v '^#' \
0f80c1
                | egrep -v '^[[:space:]]*$' \
0f80c1
                | sed -r 's![[:space:]]*!!g')
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 \
0f80c1
                    | gawk 'BEGIN{FS = "="}; { print $1 }' \
0f80c1
                    | sed -r 's![[:space:]]*!!g')
858566
0f80c1
                CONFRHS=$(echo $CONFLINE \
0f80c1
                    | gawk 'BEGIN{FS = "="}; { print $2 }' \
0f80c1
                    | sed -r 's![[:space:]]*!!g' | sed -r 's!^"(.+)"$!\1!')
7d58ac
0f80c1
                if [[ ${MANUAL_BASEDIR}/${INCL} =~ $CONFRHS ]];then
0f80c1
                    TEMPLATE="${MANUAL_TEMPLATE}/${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.
0f80c1
            svn cp ${TEMPLATE} ${MANUAL_BASEDIR}/$INCL --quiet
0f80c1
0f80c1
            # Expand common translation markers in documentation entry.
858566
            cli_replaceTMarkers "${MANUAL_BASEDIR}/$INCL"
858566
0f80c1
            # Expand `Goals' subsection translation markers in
0f80c1
            # documentation entry.
12d58f
            sed -i -r "s!=SECT=!${SECT}!g" "${MANUAL_BASEDIR}/$INCL"
0f80c1
0f80c1
            # Expand `See also' subsection translation markers in
0f80c1
            # documentation entry.
448d34
            ${MANUAL_BACKEND}_makeSeeAlso "${MANUAL_BASEDIR}/$INCL" "$NODE"
858566
4c79b5
        fi
0f80c1
0f80c1
        # Verify existence of chapter-nodes template files. If no
0f80c1
        # chapter-nodes template is found, stop script execution with
0f80c1
        # an error message. We cannot continue without it.
9fa13b
        cli_checkFiles ${MANUAL_TEMPLATE}/${MANUAL_CHAPTER_NAME}/chapter-nodes.${MANUAL_EXTENSION}
0f80c1
0f80c1
        # Output node information chapter-nodes template file using
0f80c1
        # the current texinfo menu information.
9fa13b
        cat ${MANUAL_TEMPLATE}/${MANUAL_CHAPTER_NAME}/chapter-nodes.${MANUAL_EXTENSION} \
0f80c1
            | sed -r -e "s!=NODE=!${NODE}!g" -e "s!=SECT=!${SECT}!g" \
0f80c1
                     -e "s!=CIND=!${CIND}!g" -e "s!=INCL=!${INCL}!g"
0f80c1
0f80c1
    # Dump node definitions into document structure.
9fa13b
    done > $MANUAL_CHAPTER_DIR/chapter-nodes.${MANUAL_EXTENSION}
4c79b5
4c79b5
}