summaryrefslogtreecommitdiffstats
path: root/cmdline.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-09-16 12:25:16 -0400
committerTavian Barnes <tavianator@tavianator.com>2017-09-16 12:25:16 -0400
commit25fab2c717ac72a69d11c7190df0563b082808b0 (patch)
tree54e5deb63c432b501f2f2b49f594cd261b649eaf /cmdline.h
parent1db02c9ee890d6b5fda25444243c40f9d2bb9906 (diff)
downloadbfs-25fab2c717ac72a69d11c7190df0563b082808b0.tar.xz
opt: Separate optimization from parsing
Diffstat (limited to 'cmdline.h')
-rw-r--r--cmdline.h123
1 files changed, 123 insertions, 0 deletions
diff --git a/cmdline.h b/cmdline.h
new file mode 100644
index 0000000..a1dadc3
--- /dev/null
+++ b/cmdline.h
@@ -0,0 +1,123 @@
+/****************************************************************************
+ * bfs *
+ * Copyright (C) 2015-2017 Tavian Barnes <tavianator@tavianator.com> *
+ * *
+ * Permission to use, copy, modify, and/or distribute this software for any *
+ * purpose with or without fee is hereby granted. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES *
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF *
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR *
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES *
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN *
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
+ ****************************************************************************/
+
+#ifndef CMDLINE_H
+#define CMDLINE_H
+
+#include "color.h"
+
+/**
+ * Various debugging flags.
+ */
+enum debug_flags {
+ /** Print cost estimates. */
+ DEBUG_COST = 1 << 0,
+ /** Print executed command details. */
+ DEBUG_EXEC = 1 << 1,
+ /** Print optimization details. */
+ DEBUG_OPT = 1 << 2,
+ /** Print rate information. */
+ DEBUG_RATES = 1 << 3,
+ /** Trace the filesystem traversal. */
+ DEBUG_SEARCH = 1 << 4,
+ /** Trace all stat() calls. */
+ DEBUG_STAT = 1 << 5,
+ /** Print the parse tree. */
+ DEBUG_TREE = 1 << 6,
+};
+
+/**
+ * A root path to explore.
+ */
+struct root {
+ /** The root path itself. */
+ const char *path;
+ /** The next path in the list. */
+ struct root *next;
+};
+
+/**
+ * The parsed command line.
+ */
+struct cmdline {
+ /** The unparsed command line arguments. */
+ char **argv;
+
+ /** The list of root paths. */
+ struct root *roots;
+
+ /** Color data. */
+ struct colors *colors;
+ /** Colored stdout. */
+ CFILE *cout;
+ /** Colored stderr. */
+ CFILE *cerr;
+
+ /** Table of mounted file systems. */
+ struct bfs_mtab *mtab;
+
+ /** -mindepth option. */
+ int mindepth;
+ /** -maxdepth option. */
+ int maxdepth;
+
+ /** bftw() flags. */
+ enum bftw_flags flags;
+
+ /** Optimization level. */
+ int optlevel;
+ /** Debugging flags. */
+ enum debug_flags debug;
+ /** Whether to only handle paths with xargs-safe characters. */
+ bool xargs_safe;
+ /** Whether to ignore deletions that race with bfs. */
+ bool ignore_races;
+
+ /** The command line expression. */
+ struct expr *expr;
+
+ /** The number of open files used by the expression tree. */
+ int nopen_files;
+};
+
+/**
+ * Optimize the parsed command line.
+ *
+ * @return 0 if successful, -1 on error.
+ */
+int optimize_cmdline(struct cmdline *cmdline);
+
+/**
+ * Parse the command line.
+ */
+struct cmdline *parse_cmdline(int argc, char *argv[]);
+
+/**
+ * Dump the parsed command line.
+ */
+void dump_cmdline(const struct cmdline *cmdline, bool verbose);
+
+/**
+ * Evaluate the command line.
+ */
+int eval_cmdline(const struct cmdline *cmdline);
+
+/**
+ * Free the parsed command line.
+ */
+void free_cmdline(struct cmdline *cmdline);
+
+#endif // CMDLINE_H