+#if DEBUG
+ log = open_file (DEBUG_FILE, "w");
+ print_tstamp (log);
+ /* We're in debugging mode, hence we can't invoke STACK_FILE()
+ prior to print_tstamp(), because both cause text to be written
+ to the same logfile which is expected to have the timestamp
+ first. */
+ STACK_FILE (log);
+#endif
+
+ attr[0] = '\0';
+
+ process_opts (argc, argv, &conf_file);
+
+#ifdef CONF_FILE_TEST
+ conf_file = to_str (CONF_FILE_TEST);
+#elif !defined(TEST)
+ if (conf_file == NULL)
+ {
+ conf_file_path (&conf_file);
+ STACK_VAR (conf_file);
+ }
+ else
+ {
+ char *s;
+ if ((s = expand_string (conf_file)))
+ {
+ free (conf_file);
+ conf_file = s;
+ }
+ STACK_VAR (conf_file);
+ errno = 0;
+ if (access (conf_file, F_OK) == -1)
+ vfprintf_fail (formats[FMT_CONF_FILE], conf_file, strerror (errno));
+ }
+#endif
+#if defined(CONF_FILE_TEST) || !defined(TEST)
+ if (access (conf_file, F_OK) != -1)
+ parse_conf (conf_file, &config);
+#endif
+#if !defined(CONF_FILE_TEST) && !defined(TEST)
+ RELEASE (conf_file);
+#endif
+ init_conf_vars (&config);
+
+ init_opts_vars ();
+
+ arg_cnt = argc - optind;
+
+ if (clean || clean_all)
+ {
+ if (clean && clean_all)
+ vfprintf_fail (formats[FMT_GENERIC], "--clean and --clean-all switch are mutually exclusive");
+ if (arg_cnt > 1)
+ vfprintf_fail ("--clean%s switch cannot be used with more than one file", clean_all ? "-all" : "");
+ {
+ unsigned int i;
+ const struct option_set {
+ const char *option;
+ enum opt_set set;
+ } options[] = {
+ { "attr", OPT_ATTR_SET },
+ { "exclude-random", OPT_EXCLUDE_RANDOM_SET },
+ { "omit-color-empty", OPT_OMIT_COLOR_EMPTY_SET },
+ };
+ for (i = 0; i < COUNT_OF (options, struct option_set); i++)
+ if (opts_set & options[i].set)
+ vfprintf_diag ("--%s switch has no meaning with --clean%s", options[i].option, clean_all ? "-all" : "");
+ }
+ }
+ else
+ {
+ if (arg_cnt == 0 || arg_cnt > 2)
+ {
+ vfprintf_diag ("%u arguments provided, expected 1-2 arguments or --clean[-all]", arg_cnt);
+ print_hint ();
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ if (clean || clean_all)
+ process_file_arg (argv[optind], &file, &stream);
+ else
+ process_args (arg_cnt, &argv[optind], &attr[0], colors, &file, &stream, &config);
+ read_print_stream (&attr[0], colors, file, stream);
+
+ free_conf (&config);
+
+ RELEASE (exclude);
+
+ exit (EXIT_SUCCESS);
+}
+
+#if DEBUG
+static void
+print_tstamp (FILE *log)
+{
+ time_t t;
+ struct tm *tm;
+ char str[128];
+ size_t written;
+
+ t = time (NULL);
+ tm = localtime (&t);
+ if (tm == NULL)
+ {
+ perror ("localtime");
+ exit (EXIT_FAILURE);
+ }
+ written = strftime (str, sizeof (str), "%Y-%m-%d %H:%M:%S %Z", tm);
+ if (written == 0)
+ vfprintf_fail (formats[FMT_GENERIC], "strftime: 0 returned");
+
+ fprintf (log, "%s\n", str);
+ while (written--)
+ fprintf (log, "=");
+ fprintf (log, "\n");
+}
+#endif
+
+#define DUP_CONFIG() \
+ *conf_file = xstrdup (optarg); \
+ break;
+
+#define PRINT_HELP_EXIT() \
+ print_help (); \
+ exit (EXIT_SUCCESS);
+
+#define PRINT_VERSION_EXIT() \
+ print_version (); \
+ exit (EXIT_SUCCESS);
+
+static void
+process_opts (int argc, char **argv, char **conf_file)
+{
+ int opt;
+ while ((opt = getopt_long (argc, argv, "c:hV", long_opts, NULL)) != -1)