#define COLOR_SEP_CHAR '/'
-#define VERSION "0.51"
+#define VERSION "0.52"
typedef unsigned short bool;
static void read_print_stream (bool, const struct color **, const char *, FILE *);
static void find_color_entries (struct color_name **, const struct color **);
static void find_color_entry (const struct color_name *, unsigned int, const struct color **);
-static void print_line (const struct color **, bool, const char * const, unsigned int);
+static void print_line (bool, const struct color **, const char * const, unsigned int);
static void print_clean (const char *);
static void print_free_offsets (const char *, char ***, unsigned int);
static void *malloc_wrap (size_t);
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))
} \
current_line = merged_line ? merged_line : (char *)line; \
if (!check_eof || *current_line != '\0') \
- print_line (colors, bold, current_line, flags); \
+ print_line (bold, colors, current_line, flags); \
free (merged_line); \
} while (false);
else if (*line != '\0')
{
if (!clean && !clean_all) /* efficiency */
- print_line (colors, bold, line, 0);
+ print_line (bold, colors, line, 0);
else if (!part_line)
part_line = xstrdup (line);
else
}
static void
-print_line (const struct color **colors, bool bold, const char *const line, unsigned int flags)
+print_line (bool bold, const struct color **colors, const char *const line, unsigned int flags)
{
/* --clean[-all] */
if (clean || clean_all)
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); \