+skip_path_colors (const char *color_string, const char *file_string, const struct stat *sb)
+{
+ bool have_file;
+ unsigned int c;
+ const char *color = color_string;
+ const mode_t mode = sb->st_mode;
+
+ for (c = 1; c <= 2 && *color; c++)
+ {
+ bool matched = false;
+ unsigned int i;
+ for (i = 0; i < tables[GENERIC].count; i++)
+ {
+ const struct color *entry = &tables[GENERIC].entries[i];
+ if (has_color_name (color, 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
+ break;
+ }
+
+ have_file = (*color != '\0');
+
+ if (have_file)
+ {
+ const char *file_existing = color_string;
+ if (file_string)
+ vfprintf_fail (formats[FMT_QUOTE], get_file_type (mode), file_existing, "cannot be used as color string");
+ else
+ {
+ if (VALID_FILE_TYPE (mode))
+ vfprintf_fail (formats[FMT_QUOTE], get_file_type (mode), file_existing, "must be preceded by color string");
+ else
+ vfprintf_fail (formats[FMT_QUOTE], get_file_type (mode), file_existing, "is not a valid file type");
+ }
+ }
+}
+
+static void
+gather_color_names (const char *color_string, char *attr, struct color_name **color_names)
+{
+ unsigned int index;
+ char *color, *p, *str;
+
+ str = xstrdup (color_string);
+ STACK_VAR (str);
+
+ for (index = 0, color = str; *color; index++, color = p)
+ {
+ char *ch, *sep;
+
+ p = NULL;
+ if ((sep = strchr (color, COLOR_SEP_CHAR)))
+ {
+ *sep = '\0';
+ p = sep + 1;
+ }
+ else
+ p = color + strlen (color);
+ assert (p != NULL);
+
+ for (ch = color; *ch; ch++)
+ if (!isalpha (*ch))
+ vfprintf_fail (formats[FMT_COLOR], tables[index].desc, color, "cannot be made of non-alphabetic characters");
+
+ for (ch = color + 1; *ch; ch++)
+ if (!islower (*ch))
+ vfprintf_fail (formats[FMT_COLOR], tables[index].desc, color, "cannot be in mixed lower/upper case");
+
+ if (streq (color, "None"))
+ vfprintf_fail (formats[FMT_COLOR], tables[index].desc, color, "cannot be bold");
+
+ if (isupper (*color))
+ {
+ switch (index)
+ {
+ case FOREGROUND:
+ snprintf (attr + strlen (attr), 3, "1;");
+ break;
+ case BACKGROUND:
+ vfprintf_fail (formats[FMT_COLOR], tables[BACKGROUND].desc, color, "cannot be bold");
+ default: /* never reached */
+ ABORT_TRACE ();
+ }
+ }
+
+ color_names[index] = xcalloc (1, sizeof (struct color_name));
+ STACK_VAR (color_names[index]);
+
+ color_names[index]->orig = xstrdup (color);
+ STACK_VAR (color_names[index]->orig);
+
+ for (ch = color; *ch; ch++)
+ *ch = tolower (*ch);
+
+ color_names[index]->name = xstrdup (color);
+ STACK_VAR (color_names[index]->name);
+ }
+
+ RELEASE_VAR (str);
+}
+
+static void
+read_print_stream (const char *attr, const struct color **colors, const char *file, FILE *stream)