Blame Scripts/Bash/Functions/Render/Svg/svg_checkColorFormats.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# svg_checkColorFormats.sh -- This function verifies formats of colors
878a2b
# (i.e., the way color information is specified).
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function svg_checkColorFormats {
878a2b
878a2b
    # Define short options.
878a2b
    local ARGSS=''
878a2b
878a2b
    # Define long options.
878a2b
    local ARGSL='format:'
878a2b
878a2b
    # Initialize pattern used for color sanitation.
878a2b
    local PATTERN='^#[0-9a-f]{6}$'
878a2b
7103a2
    # Initialize arguments with an empty value and set it as local
7103a2
    # variable to this function scope. Doing this is very important to
7103a2
    # avoid any clash with higher execution environments.
7103a2
    local ARGUMENTS=''
7103a2
7103a2
    # Prepare ARGUMENTS variable for getopt.
878a2b
    cli_parseArgumentsReDef "$@"
878a2b
7103a2
    # Redefine ARGUMENTS using getopt(1) command parser.
878a2b
    cli_parseArguments
878a2b
878a2b
    # Redefine positional parameters using ARGUMENTS variable.
878a2b
    eval set -- "$ARGUMENTS"
878a2b
878a2b
    # Look for options passed through positional parameters.
878a2b
    while true;do
878a2b
878a2b
        case "$1" in
878a2b
878a2b
            --format )
878a2b
878a2b
                case "$2" in
878a2b
878a2b
                    rrggbb|*)
878a2b
                        PATTERN='^#[0-9a-f]{6}$'
878a2b
                        ;;
878a2b
878a2b
                esac
878a2b
                shift 2
878a2b
                ;;
878a2b
878a2b
            -- )
878a2b
                shift 1
878a2b
                break
878a2b
                ;;
878a2b
        esac
878a2b
    done
878a2b
878a2b
    # Define the location we want to apply verifications to.
878a2b
    local COLOR=''
878a2b
    local COLORS="$@"
878a2b
878a2b
    # Loop through colors and perform format verification as specified
878a2b
    # by pattern.
878a2b
    for COLOR in $COLORS;do
878a2b
878a2b
        if [[ ! $COLOR =~ $PATTERN ]];then
878a2b
            cli_printMessage "`eval_gettext "The \\\"\\\$COLOR\\\" string is not a valid color code."`" --as-error-line
878a2b
        fi
878a2b
878a2b
    done
878a2b
878a2b
}