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

878a2b
#!/bin/bash
878a2b
#
878a2b
# texinfo_createStructure.sh -- This function creates the
878a2b
# documentation structure of a manual using the current language as
878a2b
# reference.
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_createStructure {
878a2b
878a2b
    # Verify manual main definition file. If it already exist, assume
878a2b
    # it was correctly created in the past. Otherwise try to create
878a2b
    # it. Don't use the manual base directory here, it would prevent
878a2b
    # documentation manuals from being created on different languages.
878a2b
    if [[ -f ${MANUAL_BASEFILE}.${MANUAL_EXTENSION} ]];then
878a2b
        return
878a2b
    else
a319f0
        cli_printMessage "`eval_gettext "The following documentation manual doesn't exist:"`" --as-stdout-line
878a2b
        cli_printMessage "${MANUAL_BASEFILE}.texinfo" --as-response-line
a319f0
        cli_printMessage "`gettext "Do you want to create it now?"`" --as-yesornorequest-line
878a2b
    fi
878a2b
878a2b
    # Initialize manual's information (e.g., title, subtitle, abstract).
878a2b
    local MANUAL_TITLE=''
878a2b
    local MANUAL_SUBTITLE=''
878a2b
    local MANUAL_ABSTRACT=''
878a2b
878a2b
    # Create manual's top-level directory using subversion. This is
878a2b
    # the place where all texinfo documentation manuals is stored in.
878a2b
    if [[ ! -d ${MANUAL_BASEDIR} ]];then
878a2b
        svn mkdir ${MANUAL_BASEDIR} --quiet
878a2b
    fi
878a2b
878a2b
    # Create manual's base directory. This is the place where
878a2b
    # language-specific documentation source files are stored in.
878a2b
    svn mkdir ${MANUAL_BASEDIR_L10N} --quiet
878a2b
878a2b
    # Retrive manual's information from standard input.
878a2b
    cli_printMessage "`gettext "Manual Title"`" --as-request-line
878a2b
    read MANUAL_TITLE
878a2b
    cli_printMessage "`gettext "Manual Subtitle"`" --as-request-line
878a2b
    read MANUAL_SUBTITLE
878a2b
    cli_printMessage "`gettext "Manual Abstract"`" --as-request-line
878a2b
    read MANUAL_ABSTRACT
878a2b
878a2b
    # Print action message.
878a2b
    cli_printMessage "-" --as-separator-line
878a2b
    cli_printMessage "`gettext "Creating manual structure in texinfo format."`" --as-response-line
878a2b
878a2b
    # Verify manual's information. The title information must be
878a2b
    # non-empty value.
878a2b
    if [[ $MANUAL_TITLE == '' ]];then
878a2b
        cli_printMessage "`gettext "The manual title cannot be empty."`" --as-error-line
878a2b
    fi
878a2b
878a2b
    # Define file names required to build the manual.
878a2b
    local FILE=''
878a2b
    local FILES=$(cli_getFilesList "${MANUAL_TEMPLATE_L10N}" \
878a2b
        --maxdepth='1' \
878a2b
        --pattern="manual((-menu|-nodes|-index)?\.${MANUAL_EXTENSION}|\.conf)")
878a2b
878a2b
    # Verify manual base file. The manual base file is where the
24ece8
    # documentation manual is defined in the format format. Assuming
878a2b
    # no file exists (e.g., a new language-specific manual is being
878a2b
    # created), use texinfo templates for it.
878a2b
    for FILE in $FILES;do
878a2b
        if [[ ! -f ${MANUAL_BASEDIR_L10N}/$(basename ${FILE}) ]];then
878a2b
878a2b
            # Be sure the file is inside the working copy and under
878a2b
            # version control. 
957ee6
            ${CLI_NAME} svn --is-versioned ${FILE}
957ee6
            if [[ $? -ne 0 ]];then
957ee6
                cli_printMessage "${FILE} `gettext "is not under version control."`" --as-error-line
957ee6
            fi
878a2b
878a2b
            # Define target file.
878a2b
            local DST=${MANUAL_BASEDIR_L10N}/$(basename ${FILE} \
878a2b
                | sed -r "s!manual!${MANUAL_NAME}!")
878a2b
878a2b
            # Copy using subversion to register this action.
878a2b
            svn cp ${FILE} ${DST} --quiet
878a2b
878a2b
            # Expand common translation markers inside target file.
878a2b
            cli_expandTMarkers ${DST}
878a2b
878a2b
            # Expand specific translation markers inside target file.
878a2b
            sed -r -i -e "s!=MANUAL_NAME=!${MANUAL_NAME}!g" \
878a2b
                -e "s!=MANUAL_TITLE=!${MANUAL_TITLE}!g" \
878a2b
                -e "s!=MANUAL_SUBTITLE=!${MANUAL_SUBTITLE}!g" \
878a2b
                -e "s!=MANUAL_ABSTRACT=!${MANUAL_ABSTRACT}!g" $DST
878a2b
878a2b
        fi
878a2b
    done
878a2b
878a2b
    # Initialize chapter structure inside the manual.
878a2b
    texinfo_createStructureChapters
878a2b
878a2b
    # Redefine absolute path to changed directory.
878a2b
    MANUAL_CHANGED_DIRS=${MANUAL_BASEDIR}
878a2b
878a2b
}