+ gather_color_names (color_string, bold, color_names);
+
+ assert (color_names[FOREGROUND]);
+
+ 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);
+ 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);
+ }
+
+ 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));
+
+ *stream = open_file (file, "r");
+ }
+ *file = file_string;
+ }
+ else
+ {
+ *stream = stdin;
+ *file = "stdin";
+ }
+
+ assert (*stream);
+ assert (*file);
+}
+
+static void
+gather_color_names (const char *color_string, bool *bold, struct color_name **color_names)
+{
+ unsigned int index;
+ char *color, *p, *str;
+