diff options
author | Steven Schubiger <stsc@refcnt.org> | 2013-11-16 23:19:06 +0100 |
---|---|---|
committer | Steven Schubiger <stsc@refcnt.org> | 2013-11-16 23:19:06 +0100 |
commit | 4f6ff00bd402a74d794214f3c58c19b98eafa756 (patch) | |
tree | cc48e636051992f7050b037b9a3c183cb012f8bf /colorize.c | |
parent | 1e96a9284dde2717737cb3c1d2b5f77026b30fc1 (diff) | |
download | colorize-4f6ff00bd402a74d794214f3c58c19b98eafa756.tar.gz colorize-4f6ff00bd402a74d794214f3c58c19b98eafa756.tar.bz2 |
Validate color provided to exclude-random switch
Diffstat (limited to 'colorize.c')
-rw-r--r-- | colorize.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -262,13 +262,21 @@ main (int argc, char **argv) clean_all = true; break; case OPT_EXCLUDE_RANDOM: { - char *p; + bool valid = false; + unsigned int i; exclude = xstrdup (optarg); STACK_VAR (exclude); - for (p = exclude; *p; p++) - *p = tolower (*p); - if (streq (exclude, "random")) - vfprintf_fail (formats[FMT_GENERIC], "--exclude-random switch must be provided a color"); + for (i = 1; i < tables[FOREGROUND].count - 1; i++) /* skip color none and default */ + { + const struct color *entry = &tables[FOREGROUND].entries[i]; + if (streq (exclude, entry->name)) + { + valid = true; + break; + } + } + if (!valid) + vfprintf_fail (formats[FMT_GENERIC], "--exclude-random switch must be provided a plain color"); break; } case OPT_HELP: |