#define COLOR_SEP_CHAR '/'
-#define VERSION "0.51"
+#define VERSION "0.52"
typedef unsigned short bool;
static void free_wrap (void **);
static char *strdup_wrap (const char *);
static char *str_concat (const char *, const char *);
+static bool has_color_name (const char *, const char *);
static void vfprintf_diag (const char *, ...);
static void vfprintf_fail (const char *, ...);
static void stack_var (void ***, unsigned int *, unsigned int, void *);
{ "exclude-random", required_argument, &opt_type, OPT_EXCLUDE_RANDOM },
{ "help", no_argument, &opt_type, OPT_HELP },
{ "version", no_argument, &opt_type, OPT_VERSION },
- { 0, 0, 0, 0 },
+ { NULL, 0, NULL, 0 },
};
bool bold = false;
for (i = 0; i < tables[FOREGROUND].count; i++)
{
const struct color *entry = &tables[FOREGROUND].entries[i];
- char *p;
- if ((p = strstr (color, entry->name)) && p == color)
+ if (has_color_name (color, entry->name))
{
- color = p + strlen (entry->name);
+ color += strlen (entry->name);
matched = true;
break;
}
}
+ if (!matched && has_color_name (color, "random"))
+ {
+ color += strlen ("random");
+ matched = true;
+ }
if (matched && *color == COLOR_SEP_CHAR && *(color + 1))
color++;
else
for (index = 0, color = str; *color; index++, color = p)
{
char *ch, *sep;
+
+ p = NULL;
if ((sep = strchr (color, COLOR_SEP_CHAR)))
{
*sep = '\0';
}
else
p = color + strlen (color);
+ assert (p);
for (ch = color; *ch; ch++)
if (!isalpha (*ch))
return str;
}
+static bool
+has_color_name (const char *str, const char *name)
+{
+ char *p;
+
+ assert (strlen (str));
+ assert (strlen (name));
+
+ if (!(*str == *name || *str == toupper (*name)))
+ return false;
+ else if (*(name + 1) != '\0'
+ && !((p = strstr (str + 1, name + 1)) && p == str + 1))
+ return false;
+
+ return true;
+}
+
#define DO_VFPRINTF(fmt) \
va_list ap; \
fprintf (stderr, "%s: ", program_name); \