Blame Scripts/Functions/Render/render_svg_checkColorFormats.sh

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