Blame Scripts/Bash/centos-art/Functions/Manual/manual_getEntry.sh

4c79b5
#!/bin/bash
4c79b5
#
4de5d4
# manual_getEntry.sh -- This function builds a documentation entry based
638bf8
# on a location specified. Location specification can be both action
638bf8
# value (ACTIONVAL) variable or a value passed as first positional
638bf8
# parameter.
4c79b5
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
4c79b5
# 
7cd8e9
# This program is free software; you can redistribute it and/or
7cd8e9
# modify it under the terms of the GNU General Public License as
7cd8e9
# published by the Free Software Foundation; either version 2 of the
7cd8e9
# License, or (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# 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
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
4de5d4
function manual_getEntry {
4c79b5
4c79b5
    # Define variables as local to avoid conflicts outside.
4c79b5
    local ENTRY=''
638bf8
    local LOCATION=''
638bf8
638bf8
    # Redefine location in order to make this function reusable not
638bf8
    # just for action value variable but whatever value passed as
638bf8
    # first possitional argument.
638bf8
    if [[ "$1" != '' ]];then
638bf8
        LOCATION="$1"
638bf8
    else
638bf8
        LOCATION="$ACTIONVAL"
638bf8
    fi
4c79b5
5285d6
    # Define relative path of entry, from trunk directory on.
5285d6
    ENTRY=$(echo $LOCATION | sed -r "s!^${HOME}/artwork/!!")
4c79b5
5285d6
    # Verify the entry relative path to find out which documentation
5285d6
    # manual we are acting on. As convenction, whatever documentation
5285d6
    # entry you provide outside trunk/Manuals/ directory structure is
5285d6
    # considered as you are documenting the repository directory
5285d6
    # structure. Otherwise, if an entry inside trunk/Manuals/ is
5285d6
    # provided, the directory structure provided is used as default
5285d6
    # documentation manual for actions like `--create' and `--update'
5285d6
    # to take place on. Other options like `--edit', `--delete' and
5285d6
    # `--read' cannot be applied to paths provided is inside
5285d6
    # trunk/Manuals/ such actions made manually.
5285d6
    if [[ ${ENTRY} =~ '^trunk/Manuals/.+$' ]];then
5285d6
        ENTRY=$(echo ${ENTRY} | sed 's!trunk/Manuals/!!')
5285d6
    else
ba877a
        ENTRY=$(dirname Filesystem/${ENTRY})/$(basename $LOCATION).texi
5285d6
    fi
4c79b5
5285d6
    # Re-define entry to set absolute path to manuals base directory
5285d6
    # structure.
5285d6
    ENTRY=${MANUAL_BASEDIR}/${ENTRY}
4c79b5
5285d6
    # Re-define documentation entry to handle chapter entries. Chapter
5285d6
    # entries are handled inside the chapter it refers to, not outside
5285d6
    # it. To store chapter-specific information, the special file
5285d6
    # chapter-intro.texi is used inside the chapter.  
4c79b5
    # TODO: automate the verification, in order to accept any other
4c79b5
    # structure in the first level.
5285d6
    if [[ ${ENTRY} =~ "(trunk|branches|tags)\.texi$" ]];then
5285d6
        ENTRY=$(echo ${ENTRY} \
5285d6
            | sed -r "s/(trunk|branches|tags)\.texi$/\1\/chapter-intro.texi/")
4c79b5
    fi
4c79b5
4c79b5
    # Output entry's absolute path.
5285d6
    echo ${ENTRY}
4c79b5
4c79b5
}