Blame Scripts/centos-art/Functions/Help/help.sh

4c79b5
#!/bin/bash
4c79b5
#
522184
# help.sh -- This function initializes the interface used by
522184
# centos-art.sh script to perform documentation tasks through
522184
# different documentation backends.
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
2fe9b7
# the Free Software Foundation; either version 2 of the License, or (at
2fe9b7
# 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
    
0211a4
function help {
2bd980
edaa9d
    # Initialize action name with an empty value.
c145a8
    local ACTIONNAM=''
c145a8
771ff2
    # Initialize search option (`--search'). This option is used to
771ff2
    # look for documentation inside documentation backends.
6150a1
    local FLAG_SEARCH=""
1b527b
6150a1
    # Initialize manual's language.
6150a1
    local MANUAL_L10N=$(cli_getCurrentLocale)
771ff2
5e989a
    # Initialize manuals's top-level directory. This is the place
5e989a
    # where the manual will be stored in. To provide flexibility, the
5e989a
    # current directory where the `centos-art.sh' script was called
5e989a
    # from is used as manual's top-level directory.  Notice that this
5e989a
    # relaxation is required because we need to create/maintain
5e989a
    # manuals both under `trunk/Manuals/' and `branches/Manuals/'
5e989a
    # directories.
5e989a
    local MANUAL_TLDIR=${PWD}
5e989a
5e989a
    # Verify manual's top-level directory. To prevent messing the
5e989a
    # things up, we need to restrict the possible locations
d256a8
    # where documentation manuals can be created in the working copy.
5e989a
    # When manual's top-level location is other but the ones
5e989a
    # permitted, use `trunk/Manuals' directory structure as default
5e989a
    # location to store documentation manuals.
358fb0
    if [[ ! $MANUAL_TLDIR =~ "^${CLI_WRKCOPY}/(trunk/Manuals|branches/Manuals/[[:alnum:]-]+)$" ]];then
358fb0
        MANUAL_TLDIR="${CLI_WRKCOPY}/trunk/Manuals"
5e989a
    fi
5e989a
d256a8
    # Initialize documentation entries arrays. Arrays defined here
d256a8
    # contain all the information needed to process documentation
e0c375
    # entries (e.g., manual, part, chapter and section).
edaa9d
    local -a MANUAL_SLFN
edaa9d
    local -a MANUAL_DIRN
e0c375
    local -a MANUAL_PART
e0c375
    local -a MANUAL_CHAP
e0c375
    local -a MANUAL_SECT
edaa9d
d256a8
    # Initialize documentation entries counter.
edaa9d
    local MANUAL_DOCENTRY_COUNT=0
edaa9d
    local MANUAL_DOCENTRY_ID=0
771ff2
0c5b48
    # Interpret option arguments passed through the command-line.
ef43e2
    help_getOptions
116f45
edaa9d
    # Redefine arrays related to documentation entries using
edaa9d
    # non-option arguments passed through the command-line. At this
edaa9d
    # point all options have been removed from ARGUMENTS and
edaa9d
    # non-option arguments remain. Evaluate ARGUMENTS to retrive the
edaa9d
    # information related documentation entries from there.
ef43e2
    help_getEntries
6150a1
edaa9d
    # Execute backend-specific documentation tasks for each
edaa9d
    # documentation entry specified in the command-line, individually.
edaa9d
    # Notice that we've stored all documentation entries passed as
edaa9d
    # non-option arguments in array variables in order to process them
edaa9d
    # now, one by one.  This is particularily useful when we need to
edaa9d
    # reach items in the array beyond the current iteration cycle. For
edaa9d
    # example, when we perform actions that require source and target
edaa9d
    # locations (e.g., copying and renaming): we use the current value
edaa9d
    # as source location and the second value in the array as target
edaa9d
    # location; both defined from the first iteration cycle.
edaa9d
    while [[ $MANUAL_DOCENTRY_ID -lt $MANUAL_DOCENTRY_COUNT ]];do
edaa9d
edaa9d
        # Define name used by manual's main definition file.
edaa9d
        MANUAL_NAME=${MANUAL_SLFN[${MANUAL_DOCENTRY_ID}]}
edaa9d
5e989a
        # Define absolute path to directory holding language-specific
5e989a
        # directories.
5e989a
        MANUAL_BASEDIR="${MANUAL_TLDIR}/${MANUAL_DIRN[${MANUAL_DOCENTRY_ID}]}"
5e989a
5e989a
        # Define absolute path to directory holding language-specific
5e989a
        # texinfo source files.
5e989a
        MANUAL_BASEDIR_L10N="${MANUAL_BASEDIR}/${MANUAL_L10N}"
5e989a
115094
        # Define absolute path to changed directories inside the
115094
        # manual. For example, when a section entry is edited, copied
115094
        # or renamed inside  the same manual there is only one
e9a725
        # aboslute path to look for changes, the one holding the
e9a725
        # section entry.  However, when an entire manual is renamed,
e9a725
        # there might be two different locations to look changes for,
e9a725
        # the source location deleted and the target location added.
115094
        MANUAL_CHANGED_DIRS="${MANUAL_BASEDIR_L10N}"
115094
5e989a
        # Define absolute path to base file. This is the main file
5e989a
        # name (without extension) we use as reference to build output
5e989a
        # files in different formats (.info, .pdf, .xml, etc.).
5e989a
        MANUAL_BASEFILE="${MANUAL_BASEDIR_L10N}/${MANUAL_NAME}"
edaa9d
e9a725
        # Define manual's part name.
e0c375
        MANUAL_PART_NAME=${MANUAL_PART[${MANUAL_DOCENTRY_ID}]}
e0c375
e9a725
        # Define absolute path to manual's part directory.
e0c375
        MANUAL_PART_DIR="${MANUAL_BASEDIR_L10N}/${MANUAL_PART_NAME}"
e0c375
e9a725
        # Define manual's chapter name.
e0c375
        MANUAL_CHAPTER_NAME=${MANUAL_CHAP[${MANUAL_DOCENTRY_ID}]}
edaa9d
22d055
        # Define absolute path to chapter's directory. This is the
e0c375
        # place where chapter-specific files are stored in. Be sure no
e0c375
        # extra slash be present in the value (e.g., when the part
e0c375
        # name isn't provided).
e0c375
        MANUAL_CHAPTER_DIR="$(echo ${MANUAL_PART_DIR}/${MANUAL_CHAPTER_NAME} \
e0c375
            | sed -r 's!/{2,}!/!g' )"
22d055
edaa9d
        # Define section name.
e0c375
        MANUAL_SECTION_NAME=${MANUAL_SECT[${MANUAL_DOCENTRY_ID}]}
edaa9d
22d055
        # Define absolute path to manual's configuration file.  This
22d055
        # is the file that controls the way template files are applied
22d055
        # to documentation entries once they have been created as well
22d055
        # as the style and order used for printing sections. 
22d055
        MANUAL_CONFIG_FILE="${MANUAL_BASEFILE}.conf" 
22d055
22d055
        # Define documentation backend. This information defines the
22d055
        # kind of source files we work with inside the documentation
22d055
        # manual as well as the kind of actions required by them to
22d055
        # perform actions related to document management (e.g.,
22d055
        # creation, edition, deletion, copying, renaming, etc.).
22d055
        if [[ -f ${MANUAL_CONFIG_FILE} ]];then
22d055
22d055
            # Retrive documentation backend from configuration file.
22d055
            MANUAL_BACKEND=$(cli_getConfigValue \
22d055
                "${MANUAL_CONFIG_FILE}" "main" "manual_backend")
22d055
e9a725
            # Verify documentation backend. This is required in order
e9a725
            # to prevent malformed values from being used. Be sure
e9a725
            # only supported documentation backends can be provided as
e9a725
            # value to `manual_backend' option inside configuration
e9a725
            # files.
22d055
            if [[ ! $MANUAL_BACKEND =~ '^(texinfo)$' ]];then
22d055
                cli_printMessage "`gettext "The documentation backend provided isn't supported."`" --as-error-line
22d055
            fi 
22d055
22d055
        else
22d055
22d055
            # When the current documentation manual is being created
22d055
            # for first time, there's no way to get the documentation
22d055
            # backend to use in the future manual, but asking the user
22d055
            # creating it which one to use.
22d055
            cli_printMessage "`gettext "Select one of the following documentation backends:"`"
22d055
            MANUAL_BACKEND=$(cli_printMessage "texinfo" --as-selection-line)
22d055
22d055
        fi
22d055
22d055
        # Notice that, because we are processing non-option arguments
22d055
        # one by one, there is no need to sycronize changes or
22d055
        # initialize functionalities to the same manual time after
22d055
        # time (assuming all documentation entries passed as
22d055
        # non-option arguments refer the same manual directory name).
22d055
        # That would be only necessary when documentation entries
22d055
        # refer to different manual directory names that could be
22d055
        # written in different documentation backends.
22d055
        if [[ ${MANUAL_DOCENTRY_ID} -eq 0 \
22d055
            || ( ( ${MANUAL_DOCENTRY_ID} -gt 0 ) && ( \
22d055
            ${MANUAL_DIRN[${MANUAL_DOCENTRY_ID}]} != ${MANUAL_DIRN[((${MANUAL_DOCENTRY_ID} - 1))]} ) ) ]];then
22d055
22d055
            # Syncronize changes between repository and working copy.
22d055
            # At this point, changes in the repository are merged in
22d055
            # the working copy and changes in the working copy
22d055
            # committed up to repository.
154cfd
            if [[ -d ${MANUAL_CHANGED_DIRS} ]];then
154cfd
                cli_syncroRepoChanges ${MANUAL_CHANGED_DIRS}
154cfd
            fi
22d055
22d055
            # Initialize documentation backend functionalities. At
22d055
            # this point we load all functionalities required into
22d055
            # `centos-art.sh''s execution environment and make them
22d055
            # available, this way, to perform backend-specific
22d055
            # documentation tasks.
22d055
            cli_exportFunctions "${CLI_FUNCDIR}/${CLI_FUNCDIRNAM}/$(cli_getRepoName \
22d055
                ${MANUAL_BACKEND} -d)" "${MANUAL_BACKEND}"
22d055
22d055
        fi
22d055
edaa9d
        # Execute backend-specific documentation tasks.
0ca0ad
        ${MANUAL_BACKEND}
edaa9d
22d055
        # Unset the exported functions before go on with the next
22d055
        # documentation entry provided as non-option argument to
22d055
        # `centos-art.sh' script. Different documentation entries may
22d055
        # be written in different documentation backends. Each
22d055
        # documentation backend is loaded in order to perform their
22d055
        # related documentation tasks. Assuming more that one
22d055
        # documentation entry be passed as non-option argument to
22d055
        # `centos-art.sh' script and they are written in different
22d055
        # formats, we might end up loading documentation backend
22d055
        # functionalities that aren't used in the current
22d055
        # documentation entry being processed. In that sake, unset
22d055
        # documentation bakend functionalities when the next
22d055
        # documentation entry refers to a manual directory different
22d055
        # to that one being currently processed.
22d055
        if [[ ${MANUAL_DOCENTRY_ID} -gt 0 \
22d055
            && ${MANUAL_DIRN[${MANUAL_DOCENTRY_ID}]} != ${MANUAL_DIRN[((${MANUAL_DOCENTRY_ID} + 1))]} ]];then
22d055
            cli_unsetFunctions "${CLI_FUNCDIR}/${CLI_FUNCDIRNAM}/$(cli_getRepoName \
22d055
                ${MANUAL_BACKEND} -d)" "${MANUAL_BACKEND}"
22d055
        fi
22d055
edaa9d
        # Increment documentation entry counter id.
edaa9d
        MANUAL_DOCENTRY_ID=$(($MANUAL_DOCENTRY_ID + 1))
edaa9d
edaa9d
    done
edaa9d
d286ed
    # Syncronize changes between repository and working copy. At this
d286ed
    # point, changes in the repository are merged in the working copy
d286ed
    # and changes in the working copy committed up to repository.
d286ed
    cli_syncroRepoChanges ${MANUAL_CHANGED_DIRS}
c145a8
23c4a7
}