1 #ifndef OPTIONS_H
2 #define OPTIONS_H
3 
4 #include <getopt.h>
5 #include <sys/stat.h>
6 
7 #include <pcre.h>
8 
9 #define DEFAULT_AFTER_LEN 2
10 #define DEFAULT_BEFORE_LEN 2
11 #define DEFAULT_CONTEXT_LEN 2
12 #define DEFAULT_MAX_SEARCH_DEPTH 25
13 enum case_behavior {
14     CASE_DEFAULT, /* Changes to CASE_SMART at the end of option parsing */
15     CASE_SENSITIVE,
16     CASE_INSENSITIVE,
17     CASE_SMART,
18     CASE_SENSITIVE_RETRY_INSENSITIVE /* for future use */
19 };
20 
21 enum path_print_behavior {
22     PATH_PRINT_DEFAULT,           /* PRINT_TOP if > 1 file being searched, else PRINT_NOTHING */
23     PATH_PRINT_DEFAULT_EACH_LINE, /* PRINT_EACH_LINE if > 1 file being searched, else PRINT_NOTHING */
24     PATH_PRINT_TOP,
25     PATH_PRINT_EACH_LINE,
26     PATH_PRINT_NOTHING
27 };
28 
29 typedef struct {
30     int ackmate;
31     pcre *ackmate_dir_filter;
32     pcre_extra *ackmate_dir_filter_extra;
33     size_t after;
34     size_t before;
35     enum case_behavior casing;
36     const char *file_search_string;
37     int match_files;
38     pcre *file_search_regex;
39     pcre_extra *file_search_regex_extra;
40     int color;
41     char *color_line_number;
42     char *color_match;
43     char *color_path;
44     int color_win_ansi;
45     int column;
46     int context;
47     int follow_symlinks;
48     int invert_match;
49     int literal;
50     int literal_starts_wordchar;
51     int literal_ends_wordchar;
52     size_t max_matches_per_file;
53     int max_search_depth;
54     int mmap;
55     int multiline;
56     int one_dev;
57     int only_matching;
58     char path_sep;
59     int path_to_ignore;
60     int print_break;
61     int print_count;
62     int print_filename_only;
63     int print_path;
64     int print_all_paths;
65     int print_line_numbers;
66     int print_long_lines; /* TODO: support this in print.c */
67     int passthrough;
68     pcre *re;
69     pcre_extra *re_extra;
70     int recurse_dirs;
71     int search_all_files;
72     int skip_vcs_ignores;
73     int search_binary_files;
74     int search_zip_files;
75     int search_hidden_files;
76     int search_stream; /* true if tail -F blah | ag */
77     int stats;
78     size_t stream_line_num; /* This should totally not be in here */
79     int match_found;        /* This should totally not be in here */
80     ino_t stdout_inode;
81     char *query;
82     int query_len;
83     char *pager;
84     int paths_len;
85     int parallel;
86     int use_thread_affinity;
87     int vimgrep;
88     size_t width;
89     int word_regexp;
90     int workers;
91 } cli_options;
92 
93 /* global options. parse_options gives it sane values, everything else reads from it */
94 extern cli_options opts;
95 
96 typedef struct option option_t;
97 
98 void usage(void);
99 void print_version(void);
100 
101 void init_options(void);
102 void parse_options(int argc, char **argv, char **base_paths[], char **paths[]);
103 void cleanup_options(void);
104 
105 #endif
106