Blame Scripts/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
edaa9d
    # Initialize the backend flag (`--backend'). This option sets the
edaa9d
    # documentation backed used to perform documentation actions.
edaa9d
    local FLAG_BACKEND='texinfo'
09b4e0
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
d256a8
    # entries (e.g., manual, chapter, section).
edaa9d
    local -a MANUAL_SLFN
edaa9d
    local -a MANUAL_DIRN
edaa9d
    local -a MANUAL_CHAN
edaa9d
    local -a MANUAL_SECN
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.
5a5b08
    ${CLI_FUNCNAME}_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.
5a5b08
    ${CLI_FUNCNAME}_getEntries
6150a1
d256a8
    # Initialize documentation backend functionalities. At this point
d256a8
    # we load all functionalities required into `centos-art.sh''s
d256a8
    # execution environment and make them available, this way, to
d256a8
    # perform backend-specific documentation tasks.
903cf1
    cli_exportFunctions "${CLI_FUNCDIR}/${CLI_FUNCDIRNAM}/$(cli_getRepoName \
edaa9d
        ${FLAG_BACKEND} -d)" "${FLAG_BACKEND}"
edaa9d
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
115094
        # aboslute path to changed directory to look for changes, the
115094
        # one holding the section entry.  However, when a manual entry
115094
        # is renamed, there are two different locations to look for
115094
        # changes, the source manual removed and the target manual
115094
        # added.
115094
        MANUAL_CHANGED_DIRS="${MANUAL_BASEDIR_L10N}"
115094
115094
        # Syncronize changes between repository and working copy. At
115094
        # this point, changes in the repository are merged in the
115094
        # working copy and changes in the working copy committed up to
115094
        # repository. Notice that, because we are processing
115094
        # non-option arguments one by one, there is no need to
115094
        # sycronize changes to the same manual time after time
115094
        # (assuming all documentation entries passed as non-option
115094
        # arguments refer the same manual directory name).
115094
        if [[ ${MANUAL_DOCENTRY_ID} -eq 0 \
115094
            || ( ( ${MANUAL_DOCENTRY_ID} -gt 0 ) && ( \
115094
            ${MANUAL_DIRN[${MANUAL_DOCENTRY_ID}]} != ${MANUAL_DIRN[((${MANUAL_DOCENTRY_ID} - 1))]} ) ) ]];then
115094
            cli_syncroRepoChanges ${MANUAL_CHANGED_DIRS}
115094
        fi
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
edaa9d
        # Define chapter name.
edaa9d
        MANUAL_CHAPTER_NAME=${MANUAL_CHAN[${MANUAL_DOCENTRY_ID}]}
edaa9d
edaa9d
        # Define section name.
edaa9d
        MANUAL_SECTION_NAME=${MANUAL_SECN[${MANUAL_DOCENTRY_ID}]}
edaa9d
edaa9d
        # Execute backend-specific documentation tasks.
edaa9d
        ${FLAG_BACKEND}
edaa9d
edaa9d
        # Increment documentation entry counter id.
edaa9d
        MANUAL_DOCENTRY_ID=$(($MANUAL_DOCENTRY_ID + 1))
edaa9d
edaa9d
    done
edaa9d
edaa9d
    # Rebuild output files to propagate recent changes.
edaa9d
    ${FLAG_BACKEND}_updateOutputFiles
23c4a7
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
}