-#define MERGE_PRINT_LINE(part_line, line, flags, check_eof) do { \
- char *current_line, *merged_line = NULL; \
- if (part_line) \
- { \
- merged_line = str_concat (part_line, line); \
- free_null (part_line); \
- } \
- current_line = merged_line ? merged_line : (char *)line; \
- if (!check_eof || *current_line != '\0') \
- print_line (bold, colors, current_line, flags); \
- free (merged_line); \
-} while (false)
+static void
+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[FOREGROUND].count; i++)
+ {
+ const struct color *entry = &tables[FOREGROUND].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_exists = color_string;
+ if (file_string)
+ vfprintf_fail (formats[FMT_QUOTE], get_file_type (mode), file_exists, "cannot be used as color string");
+ else
+ {
+ if (VALID_FILE_TYPE (mode))
+ vfprintf_fail (formats[FMT_QUOTE], get_file_type (mode), file_exists, "must be preceeded by color string");
+ else
+ vfprintf_fail (formats[FMT_QUOTE], get_file_type (mode), file_exists, "is not a valid file type");
+ }
+ }
+}
+
+static void
+gather_color_names (const char *color_string, bool *bold, 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);
+
+ 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:
+ *bold = true;
+ 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));
+
+ color_names[index]->orig = xstrdup (color);
+
+ for (ch = color; *ch; ch++)
+ *ch = tolower (*ch);
+
+ color_names[index]->name = xstrdup (color);
+ }
+
+ RELEASE_VAR (str);
+}