Fortran · 3954 bytes Raw Blame History
1 module ferp_options
2 !> FERP options - holds all command-line configuration
3 use ferp_kinds, only: max_path_len, max_pattern_len
4 implicit none
5 private
6
7 public :: grep_options
8 public :: PATTERN_BRE, PATTERN_ERE, PATTERN_FIXED, PATTERN_PERL
9 public :: COLOR_NEVER, COLOR_AUTO, COLOR_ALWAYS
10 public :: DIR_READ, DIR_SKIP, DIR_RECURSE
11 public :: DEV_READ, DEV_SKIP
12 public :: MAX_GLOBS
13
14 !> Pattern type constants
15 integer, parameter :: PATTERN_BRE = 1
16 integer, parameter :: PATTERN_ERE = 2
17 integer, parameter :: PATTERN_FIXED = 3
18 integer, parameter :: PATTERN_PERL = 4
19
20 !> Color mode constants
21 integer, parameter :: COLOR_NEVER = 0
22 integer, parameter :: COLOR_AUTO = 1
23 integer, parameter :: COLOR_ALWAYS = 2
24
25 !> Directory action constants
26 integer, parameter :: DIR_READ = 0
27 integer, parameter :: DIR_SKIP = 1
28 integer, parameter :: DIR_RECURSE = 2
29
30 !> Device action constants
31 integer, parameter :: DEV_READ = 0
32 integer, parameter :: DEV_SKIP = 1
33
34 !> Max glob patterns
35 integer, parameter :: MAX_GLOBS = 64
36
37 type :: grep_options
38 !> Pattern type selection
39 integer :: pattern_type = PATTERN_BRE
40
41 !> Matching control
42 logical :: ignore_case = .false. ! -i, --ignore-case
43 logical :: invert_match = .false. ! -v, --invert-match
44 logical :: word_regexp = .false. ! -w, --word-regexp
45 logical :: line_regexp = .false. ! -x, --line-regexp
46
47 !> Output control
48 logical :: count_only = .false. ! -c, --count
49 logical :: files_with_matches = .false. ! -l, --files-with-matches
50 logical :: files_without_match = .false. ! -L, --files-without-match
51 logical :: only_matching = .false. ! -o, --only-matching
52 logical :: quiet = .false. ! -q, --quiet, --silent
53 logical :: no_messages = .false. ! -s, --no-messages
54
55 !> Line prefix control
56 logical :: show_line_number = .false. ! -n, --line-number
57 logical :: show_byte_offset = .false. ! -b, --byte-offset
58 logical :: show_filename = .false. ! -H, --with-filename
59 logical :: hide_filename = .false. ! -h, --no-filename
60 logical :: null_after_filename = .false. ! -Z, --null
61 logical :: initial_tab = .false. ! -T, --initial-tab
62
63 !> Context control
64 integer :: before_context = 0 ! -B, --before-context
65 integer :: after_context = 0 ! -A, --after-context
66 character(len=8) :: group_separator = '--'
67 logical :: no_group_separator = .false.
68
69 !> File selection
70 logical :: recursive = .false. ! -r, --recursive
71 logical :: dereference_recursive = .false. ! -R, --dereference-recursive
72 character(len=max_path_len) :: include_globs(MAX_GLOBS) = ''
73 integer :: num_include_globs = 0
74 character(len=max_path_len) :: exclude_globs(MAX_GLOBS) = ''
75 integer :: num_exclude_globs = 0
76 character(len=max_path_len) :: exclude_dirs(MAX_GLOBS) = ''
77 integer :: num_exclude_dirs = 0
78 character(len=max_path_len) :: exclude_from_file = ''
79 character(len=max_path_len) :: include_from_file = ''
80
81 !> Binary file handling
82 logical :: text_mode = .false. ! -a, --text
83 logical :: ignore_binary = .false. ! -I
84
85 !> Misc
86 integer :: color_mode = COLOR_AUTO ! --color
87 integer :: max_count = 0 ! -m, --max-count (0 = unlimited)
88 character(len=max_path_len) :: label = '(standard input)'
89 logical :: line_buffered = .false. ! --line-buffered
90 logical :: null_data = .false. ! -z, --null-data
91 integer :: dir_action = DIR_READ ! -d, --directories
92 integer :: dev_action = DEV_READ ! -D, --devices
93
94 !> Internal state
95 logical :: multiple_files = .false. ! Auto-set when >1 file
96 logical :: reading_stdin = .false. ! Auto-set when reading stdin
97 integer :: line_number_width = 1 ! Width for -T padding (set per file)
98 end type grep_options
99
100 end module ferp_options
101