+#if DEBUG
+ log = open_file (DEBUG_FILE, "w");
+ print_tstamp (log);
+#endif
+
+ attr[0] = '\0';
+
+#ifdef CONF_FILE_TEST
+ conf_file = to_str (CONF_FILE_TEST);
+#elif !defined(TEST)
+ uid = getuid ();
+ errno = 0;
+ if ((passwd = getpwuid (uid)) == NULL)
+ {
+ if (errno == 0)
+ vfprintf_diag ("password file entry for uid %lu not found", (unsigned long)uid);
+ else
+ perror ("getpwuid");
+ exit (EXIT_FAILURE);
+ }
+ size = strlen (passwd->pw_dir) + 1 + strlen (CONF_FILE) + 1;
+ conf_file = xmalloc (size);
+ snprintf (conf_file, size, "%s/%s", passwd->pw_dir, CONF_FILE);
+#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)
+ free (conf_file);
+#endif
+ init_conf_vars (&config);
+
+ process_opts (argc, argv);
+
+ 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)
+ {
+ const char *const format = "%s %s";
+ const char *const message = "switch cannot be used with more than one file";
+ if (clean)
+ vfprintf_fail (format, "--clean", message);
+ else if (clean_all)
+ vfprintf_fail (format, "--clean-all", message);
+ }
+ }
+ else
+ {
+ if (arg_cnt == 0 || arg_cnt > 2)
+ {
+ vfprintf_diag ("%u arguments provided, expected 1-2 arguments or clean option", 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_VAR (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 PRINT_HELP_EXIT() \
+ print_help (); \
+ exit (EXIT_SUCCESS);
+
+#define PRINT_VERSION_EXIT() \
+ print_version (); \
+ exit (EXIT_SUCCESS);
+
+extern char *optarg;
+
+static void
+process_opts (int argc, char **argv)
+{
+ int opt;
+ while ((opt = getopt_long (argc, argv, "hV", long_opts, NULL)) != -1)