Blame Scripts/centos-art/Functions/Help/Texinfo/texinfo_getEntryTitle.sh

d286ed
#!/bin/bash
d286ed
#
d286ed
# texinfo_getEntryTitle.sh -- This function standardizes the way entry
d286ed
# titles for chapters and sections are printed out.
d286ed
#
2fe9b7
# Copyright (C) 2009, 2010, 2011 The CentOS Project
d286ed
#
d286ed
# This program is free software; you can redistribute it and/or modify
d286ed
# it under the terms of the GNU General Public License as published by
d286ed
# the Free Software Foundation; either version 2 of the License, or (at
d286ed
# your option) any later version.
d286ed
#
d286ed
# This program is distributed in the hope that it will be useful, but
d286ed
# WITHOUT ANY WARRANTY; without even the implied warranty of
d286ed
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
d286ed
# General Public License for more details.
d286ed
#
d286ed
# You should have received a copy of the GNU General Public License
d286ed
# along with this program; if not, write to the Free Software
d286ed
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
d286ed
#
d286ed
# ----------------------------------------------------------------------
d286ed
# $Id$
d286ed
# ----------------------------------------------------------------------
d286ed
d286ed
function texinfo_getEntryTitle {
d286ed
d286ed
    # Initialize phrase we want to transform based on style provided.
d286ed
    local PHRASE="$1"
d286ed
b7d7e3
    # Define section style. Through this property you can customize
b7d7e3
    # the section title in predefined ways.  By default, section
b7d7e3
    # titles are printed with each word capitalized (`cap-each-word').
b7d7e3
    # Other values to this option are `cap-first-only' (to capitalize
b7d7e3
    # just the first word in the title) or `directory' to transform
b7d7e3
    # each word to a directory path.
b7d7e3
    local MANUAL_SECTION_STYLE=$(cli_getConfigValue "${MANUAL_CONFIG_FILE}" "main" "manual_section_style")
b7d7e3
    if [[ ! $MANUAL_SECTION_STYLE =~ '^(cap-each-word|cap-first-only|directory)$' ]];then
b7d7e3
        MANUAL_SECTION_STYLE='cap-each-word'
b7d7e3
    fi
d286ed
b7d7e3
    # Verify section style provided and transform the phrase value in
b7d7e3
    # accordance with it.
b7d7e3
    case $MANUAL_SECTION_STYLE in
d286ed
b7d7e3
        'cap-first-only' )
d286ed
b7d7e3
            # In the entire phrase provided, capitalize the first word
b7d7e3
            # only.
b7d7e3
            PHRASE=$(echo "${PHRASE}" | tr '[:upper:]' '[:lower:]' \
b7d7e3
                | sed -r 's!^([[:alpha:]])!\u\1!')
b7d7e3
            ;;
d286ed
b7d7e3
        'directory' )
d286ed
b7d7e3
            # In the entire phrase provided, concatenate all words
b7d7e3
            # with slash (/) character and remark the fact it is a
b7d7e3
            # directory.
b7d7e3
            PHRASE=$(echo "${PHRASE}" | sed -r \
b7d7e3
                -e 's/(Trunk|Branches|Tags)/\l\1/' \
b7d7e3
                -e 's/ /\//g' \
b7d7e3
                -e 's/\/([[:alpha:]])/\/\u\1/g')
d286ed
b7d7e3
            PHRASE="@file{$PHRASE}"
b7d7e3
            ;;
d286ed
b7d7e3
        'cap-each-word' | * )
b7d7e3
b7d7e3
            # In the entire phrase provided, capitalize all words.
b7d7e3
            PHRASE=$(echo "${PHRASE}" | tr '[:upper:]' '[:lower:]' \
b7d7e3
                | sed -r 's!\<([[:alpha:]]+)\>!\u\1!g')
b7d7e3
            ;;
b7d7e3
b7d7e3
    esac
d286ed
d286ed
    # Output transformed phrase.
d286ed
    echo "$PHRASE"
d286ed
d286ed
}