Blame Scripts/Bash/Functions/Manual/manual_getEntry.sh

4c79b5
#!/bin/bash
4c79b5
#
4de5d4
# manual_getEntry.sh -- This function builds a documentation entry based
48d577
# on action value (ACTIONVAL) variable.
4c79b5
#
7cd8e9
# Copyright (C) 2009, 2010 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 DIR=''
4c79b5
    local FILE=''
4c79b5
    local ENTRY=''
4c79b5
4c79b5
    # Build directory for documenation entry.
d8a742
    DIR=$(echo $ACTIONVAL | sed -r 's!^/home/centos/artwork/!!')
4c79b5
    DIR=$(dirname $DIR)
4c79b5
    DIR=${MANUALS_DIR[2]}/$DIR
4c79b5
4c79b5
    # Build file for documentation entry.
d8a742
    FILE=$(basename $ACTIONVAL).texi
4c79b5
4c79b5
    # Combine both directory (DIR) and file (FILE) to build entry's
4c79b5
    # absolute path. When the entry's absolute path is built for the
4c79b5
    # current location, the string "." is returned by dirname and used
4c79b5
    # as current directory to store the .texi file.  This is not
4c79b5
    # desirable because we are using absolute path already and the "."
4c79b5
    # string adds another level in the path (e.g.,
4c79b5
    # /home/centos/artwork/trunk/Manuals/Texinfo/en/./trunk/chapter.texi).
4c79b5
    # This extra level in the path confuses the script when it tries
4c79b5
    # to find out where the chapter's directory is. In the example
4c79b5
    # above, the chapter's directory is "trunk/" not "./". So, remove
4c79b5
    # the string './' from entry's absolute path in order to build the
4c79b5
    # entry's absolute path correctly.
4c79b5
    ENTRY=$(echo $DIR/$FILE | sed -r 's!\./!!')
4c79b5
4c79b5
    # Re-define documentation entry if it is the chapter entry.
4c79b5
    # TODO: automate the verification, in order to accept any other
4c79b5
    # structure in the first level.
4c79b5
    if [[ $ENTRY =~ "(trunk|branches|tags)\.texi$" ]];then
4c79b5
        ENTRY=$(echo $ENTRY \
4c79b5
            | sed -r "s/(trunk|branches|tags)\.texi$/\1\/${MANUALS_FILE[7]}/")
4c79b5
    fi
4c79b5
4c79b5
    # Output entry's absolute path.
4c79b5
    echo $ENTRY
4c79b5
4c79b5
}