+ assert (color_string != NULL);
+
+ if (streq (color_string, "-"))
+ {
+ if (file_string)
+ vfprintf_fail (formats[FMT_GENERIC], "hyphen cannot be used as color string");
+ else
+ vfprintf_fail (formats[FMT_GENERIC], "hyphen must be preceded by color string");
+ }
+
+ if ((ret = lstat (color_string, &sb)) == 0) /* exists */
+ /* Ensure that we don't fail if there's a file with one or more
+ color names in its path. */
+ use_conf_color = skip_path_colors (color_string, file_string, &sb, !!config->color);
+
+ /* Use color from config file. */
+ if (arg_cnt == 1
+ && (access (color_string, F_OK) != -1)
+ && use_conf_color)
+ {
+ file_string = color_string;
+ color_string = config->color;
+ }
+
+ if ((p = strchr (color_string, COLOR_SEP_CHAR)))
+ {
+ if (p == color_string)
+ vfprintf_fail (formats[FMT_STRING], "foreground color missing in string", color_string);
+ else if (p == color_string + strlen (color_string) - 1)
+ vfprintf_fail (formats[FMT_STRING], "background color missing in string", color_string);
+ else if (strchr (++p, COLOR_SEP_CHAR))
+ vfprintf_fail (formats[FMT_STRING], "one color pair allowed only for string", color_string);
+ }
+
+ gather_color_names (color_string, attr, color_names);
+
+ assert (color_names[FOREGROUND] != NULL);
+
+ if (color_names[BACKGROUND])
+ {
+ unsigned int i;
+ const unsigned int color_sets[2][2] = { { FOREGROUND, BACKGROUND }, { BACKGROUND, FOREGROUND } };
+ for (i = 0; i < 2; i++)
+ {
+ const unsigned int color1 = color_sets[i][0];
+ const unsigned int color2 = color_sets[i][1];
+ if (CHECK_COLORS_RANDOM (color1, color2))
+ vfprintf_fail (formats[FMT_RANDOM], tables[color1].desc, color_names[color1]->orig, "cannot be combined with", color_names[color2]->orig);
+ }
+ }
+
+ find_color_entries (color_names, colors);
+ assert (colors[FOREGROUND] != NULL);
+ free_color_names (color_names);
+
+ if (!colors[FOREGROUND]->code && colors[BACKGROUND] && colors[BACKGROUND]->code)
+ {
+ struct color_name color_name;
+ color_name.name = color_name.orig = "default";
+
+ find_color_entry (&color_name, FOREGROUND, colors);
+ assert (colors[FOREGROUND]->code != NULL);
+ }
+
+ process_file_arg (file_string, file, stream);
+}
+
+static void
+process_file_arg (const char *file_string, const char **file, FILE **stream)
+{
+ if (file_string)
+ {
+ if (streq (file_string, "-"))
+ *stream = stdin;
+ else
+ {
+ const char *file = file_string;
+ struct stat sb;
+ int ret;
+
+ errno = 0;
+ ret = stat (file, &sb);
+
+ if (ret == -1)
+ vfprintf_fail (formats[FMT_FILE], file, strerror (errno));
+
+ if (!VALID_FILE_TYPE (sb.st_mode))
+ vfprintf_fail (formats[FMT_TYPE], file, "unrecognized type", get_file_type (sb.st_mode));