Blame Scripts/Functions/Prepare/prepare_getLinkName.sh

8888b3
#!/bin/bash
8888b3
#
8888b3
# prepare_getLinkName.sh -- This function standardizes link name
8888b3
# construction. For the construction sake, two arguments are required,
8888b3
# one to now the file's base directory, and another holding the file's
8888b3
# absolute path. With this information, the base directory is removed
8888b3
# from file's absolute path and the remaining path is transformed into
8888b3
# a file name where each slash is converted into minus sign. 
8888b3
# 
8888b3
# For example, if the following information is provided:
8888b3
#
8888b3
# ARG1: /home/centos/artwork/trunk/Identity/Brushes
8888b3
# ARG2: /home/centos/artwork/trunk/Identity/Brushes/Corporate/symbol.gbr
8888b3
#
8888b3
# the result will be: `corporate-symbol.gbr'.
8888b3
#
2fe9b7
# Copyright (C) 2009, 2010, 2011 The CentOS Project
8888b3
#
8888b3
# This program is free software; you can redistribute it and/or modify
8888b3
# it under the terms of the GNU General Public License as published by
8888b3
# the Free Software Foundation; either version 2 of the License, or (at
8888b3
# your option) any later version.
8888b3
#
8888b3
# This program is distributed in the hope that it will be useful, but
8888b3
# WITHOUT ANY WARRANTY; without even the implied warranty of
8888b3
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
8888b3
# General Public License for more details.
8888b3
#
8888b3
# You should have received a copy of the GNU General Public License
8888b3
# along with this program; if not, write to the Free Software
8888b3
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
8888b3
#
8888b3
# ----------------------------------------------------------------------
8888b3
# $Id$
8888b3
# ----------------------------------------------------------------------
8888b3
8888b3
function prepare_getLinkName {
8888b3
8888b3
    local LINK_BASEDIR=''
8888b3
    local LINK_ABSPATH=''
8888b3
    local LINK_CHARSEP=''
8888b3
8888b3
    # Define absolute path to link's base directory.
8888b3
    LINK_BASEDIR="$1"
8888b3
8888b3
    # Define absolute path to link's file.
8888b3
    LINK_ABSPATH="$2"
8888b3
8888b3
    # Define character used as word separator on file name.
8888b3
    LINK_CHARSEP='-'
8888b3
8888b3
    # Output link name.
8888b3
    echo "$LINK_ABSPATH" | sed -r "s!^${LINK_BASEDIR}/!!" \
8888b3
        | tr '[:upper:]' '[:lower:]' | sed -r "s!/!${LINK_CHARSEP}!g"
8888b3
8888b3
}