Tue, 02 Oct 2012 10:49:25 +0200
added multi-directory support
fixed parser bug in directory parser locking argument number 1024
fixed freed memory access on settings structure
10 | 1 | /* |
2 | * cline.c | |
3 | * | |
4 | * Created on: 23.05.2011 | |
20
43725438ac50
Changed author comments + added signatures for upcomming bfile heuristics
Mike Becker <universe@uap-core.de>
parents:
19
diff
changeset
|
5 | * Author: Mike |
10 | 6 | */ |
6
be923400164c
encapsulated suffix list in type suffix_list_t
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
7 | |
10 | 8 | #include "cline.h" |
9 | #include "scanner.h" | |
10 | #include "settings.h" | |
12
902cb8d2053c
removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents:
11
diff
changeset
|
11 | #include "arguments.h" |
16
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
12 | #include "stream.h" |
27
95a958e3de88
added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
13 | #include "regex_parser.h" |
0 | 14 | |
12
902cb8d2053c
removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents:
11
diff
changeset
|
15 | void printHelpText() { |
0 | 16 | const char* helpText = |
1 | 17 | "\nUsage:" |
33
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
18 | "\n cline [Options] [Directories...]" |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
19 | "\n cline [Options] [Directories...]" |
0 | 20 | "\n\nCounts the line terminator characters (\\n) within all" |
33
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
21 | " files in the specified\ndirectories." |
0 | 22 | "\n\nOptions:" |
21
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
23 | "\n -b <level> - binary file heuristics level (default medium)" |
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
24 | "\n One of: ignore low medium high" |
28 | 25 | "\n -E <pattern> - Excludes any line matching the <pattern>" |
27
95a958e3de88
added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
26 | "\n -e <start> <end> - Excludes lines between <start> and <end>" |
28 | 27 | "\n You may use these options multiple times" |
0 | 28 | "\n -h, --help - this help text" |
1 | 29 | "\n -m - print information about matching files only" |
30 | "\n -s <suffixes> - only count files with these suffixes (separated" | |
0 | 31 | "\n by commas)" |
1 | 32 | "\n -S <suffixes> - count any file except those with these suffixes" |
0 | 33 | "\n (separated by commas)" |
1 | 34 | "\n -r, -R - includes subdirectories" |
14
ee9333c91dda
some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents:
12
diff
changeset
|
35 | "\n -v, --version - print out version information" |
16
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
36 | "\n -V - turn verbose output off, print the result only" |
31
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
37 | "\n\nShortcuts:" |
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
38 | "\n --exclude-cstyle-comments" |
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
39 | "\n = -E \"\\s*//\" -e \"\\s*/\\*\" \"\\*/\\s*\"" |
0 | 40 | "\n\n" |
1 | 41 | "The default call without any options is:" |
28 | 42 | "\n cline ./\n\n" |
7
1b55f3fa52c9
Fixed helpText and removed extra variables for default values
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
43 | "So each file in the working directory is counted. If you want to count C" |
1b55f3fa52c9
Fixed helpText and removed extra variables for default values
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
44 | "\nsource code in your working directory and its subdirectories, type:" |
27
95a958e3de88
added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
45 | "\n cline -rs .c\n" |
28 | 46 | "\nIf you want to exclude comment lines, you may use the -e/-E option." |
27
95a958e3de88
added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
47 | "\nAfter a line matches the regex pattern <start> any following line is" |
28 | 48 | "\nnot counted unless a line matches the <end> pattern. A line is still " |
49 | "\ncounted when it does not start or end with the respective patterns." | |
50 | "\nPlease note, that cline does not remove whitespace characters as this" | |
51 | "\nmight not be reasonable in some cases." | |
31
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
52 | "\n\nExample (C without comments):" |
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
53 | "\n cline -s .c,.h --exclude-cstyle-comments"; |
1 | 54 | |
12
902cb8d2053c
removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents:
11
diff
changeset
|
55 | printf(helpText); |
1 | 56 | } |
57 | ||
14
ee9333c91dda
some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents:
12
diff
changeset
|
58 | int exit_with_version(settings_t* settings) { |
32
51d6e45a7592
changed version output slightly
Mike Becker <universe@uap-core.de>
parents:
31
diff
changeset
|
59 | printf("cline - Revision: %s\n", VERSION); |
14
ee9333c91dda
some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents:
12
diff
changeset
|
60 | destroy_settings_t(settings); |
ee9333c91dda
some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents:
12
diff
changeset
|
61 | return 0; |
ee9333c91dda
some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents:
12
diff
changeset
|
62 | } |
ee9333c91dda
some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents:
12
diff
changeset
|
63 | |
12
902cb8d2053c
removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents:
11
diff
changeset
|
64 | int exit_with_help(settings_t* settings, int code) { |
902cb8d2053c
removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents:
11
diff
changeset
|
65 | printHelpText(); |
8
28319b20968c
encapsulated common operations
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
66 | destroy_settings_t(settings); |
28319b20968c
encapsulated common operations
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
67 | return code; |
28319b20968c
encapsulated common operations
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
68 | } |
28319b20968c
encapsulated common operations
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
69 | |
1 | 70 | int main(int argc, char** argv) { |
0 | 71 | |
22
4508da679ffb
completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
72 | /* Settings */ |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
73 | settings_t *settings = new_settings_t(); |
5
9393eff3d2f9
Fixed memory leak when exiting the programm ahead of time
Mike Becker <universe@uap-core.de>
parents:
4
diff
changeset
|
74 | if (settings == NULL) { |
9393eff3d2f9
Fixed memory leak when exiting the programm ahead of time
Mike Becker <universe@uap-core.de>
parents:
4
diff
changeset
|
75 | fprintf(stderr, "Memory allocation failed.\n"); |
9393eff3d2f9
Fixed memory leak when exiting the programm ahead of time
Mike Becker <universe@uap-core.de>
parents:
4
diff
changeset
|
76 | return 1; |
9393eff3d2f9
Fixed memory leak when exiting the programm ahead of time
Mike Becker <universe@uap-core.de>
parents:
4
diff
changeset
|
77 | } |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
78 | |
22
4508da679ffb
completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
79 | /* Get arguments */ |
33
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
80 | string_list_t *directories = new_string_list_t(); |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
81 | if (directories == NULL) { |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
82 | fprintf(stderr, "Memory allocation failed.\n"); |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
83 | return 1; |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
84 | } |
30
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
85 | char* includeSuffix = NULL; |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
86 | char* excludeSuffix = NULL; |
8
28319b20968c
encapsulated common operations
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
87 | int checked = 0; |
0 | 88 | |
1 | 89 | for (int t = 1 ; t < argc ; t++) { |
90 | ||
28 | 91 | int argflags = checkArgument(argv[t], "hsSrRmvVbeE"); |
30
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
92 | int paropt = 0; |
1 | 93 | |
30
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
94 | /* s */ |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
95 | if ((argflags & 2) > 0) { |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
96 | if (!checkParamOpt(&paropt) || registerArgument(&checked, 2)) { |
12
902cb8d2053c
removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents:
11
diff
changeset
|
97 | return exit_with_help(settings, 1); |
0 | 98 | } |
1 | 99 | t++; |
100 | if (t >= argc) { | |
12
902cb8d2053c
removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents:
11
diff
changeset
|
101 | return exit_with_help(settings, 1); |
1 | 102 | } |
30
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
103 | includeSuffix = argv[t]; |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
104 | } |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
105 | /* S */ |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
106 | if ((argflags & 4) > 0) { |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
107 | if (!checkParamOpt(&paropt) || registerArgument(&checked, 4)) { |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
108 | return exit_with_help(settings, 1); |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
109 | } |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
110 | t++; |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
111 | if (t >= argc) { |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
112 | return exit_with_help(settings, 1); |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
113 | } |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
114 | excludeSuffix = argv[t]; |
0 | 115 | } |
22
4508da679ffb
completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
116 | /* h */ |
1 | 117 | if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { |
14
ee9333c91dda
some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents:
12
diff
changeset
|
118 | return exit_with_help(settings, 0); |
0 | 119 | } |
22
4508da679ffb
completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
120 | /* r, R */ |
1 | 121 | if ((argflags & 24) > 0) { |
8
28319b20968c
encapsulated common operations
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
122 | if (registerArgument(&checked, 24)) { |
12
902cb8d2053c
removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents:
11
diff
changeset
|
123 | return exit_with_help(settings, 1); |
0 | 124 | } |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
125 | settings->recursive = true; |
0 | 126 | } |
22
4508da679ffb
completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
127 | /* m */ |
1 | 128 | if ((argflags & 32) > 0) { |
8
28319b20968c
encapsulated common operations
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
129 | if (registerArgument(&checked, 32)) { |
12
902cb8d2053c
removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents:
11
diff
changeset
|
130 | return exit_with_help(settings, 1); |
0 | 131 | } |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
132 | settings->matchesOnly = true; |
0 | 133 | } |
22
4508da679ffb
completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
134 | /* v */ |
14
ee9333c91dda
some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents:
12
diff
changeset
|
135 | if ((argflags & 64) > 0 || strcmp(argv[t], "--version") == 0) { |
ee9333c91dda
some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents:
12
diff
changeset
|
136 | return exit_with_version(settings); |
ee9333c91dda
some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents:
12
diff
changeset
|
137 | } |
22
4508da679ffb
completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
138 | /* V */ |
16
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
139 | if ((argflags & 128) > 0) { |
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
140 | if (registerArgument(&checked, 128)) { |
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
141 | return exit_with_help(settings, 1); |
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
142 | } |
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
143 | settings->verbose = false; |
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
144 | } |
22
4508da679ffb
completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
145 | /* b */ |
21
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
146 | if ((argflags & 256) > 0) { |
30
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
147 | if (!checkParamOpt(&paropt) || registerArgument(&checked, 256)) { |
21
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
148 | return exit_with_help(settings, 1); |
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
149 | } |
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
150 | t++; |
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
151 | if (t >= argc) { |
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
152 | return exit_with_help(settings, 1); |
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
153 | } |
24
3963e8800a12
replaced stricmp with strcasecmp to stay standard compliant
Mike Becker <universe@uap-core.de>
parents:
23
diff
changeset
|
154 | if (strcasecmp(argv[t], "ignore") == 0) { |
21
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
155 | settings->bfileHeuristics->level = BFILE_IGNORE; |
24
3963e8800a12
replaced stricmp with strcasecmp to stay standard compliant
Mike Becker <universe@uap-core.de>
parents:
23
diff
changeset
|
156 | } else if (strcasecmp(argv[t], "low") == 0) { |
21
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
157 | settings->bfileHeuristics->level = BFILE_LOW_ACCURACY; |
24
3963e8800a12
replaced stricmp with strcasecmp to stay standard compliant
Mike Becker <universe@uap-core.de>
parents:
23
diff
changeset
|
158 | } else if (strcasecmp(argv[t], "medium") == 0) { |
21
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
159 | settings->bfileHeuristics->level = BFILE_MEDIUM_ACCURACY; |
24
3963e8800a12
replaced stricmp with strcasecmp to stay standard compliant
Mike Becker <universe@uap-core.de>
parents:
23
diff
changeset
|
160 | } else if (strcasecmp(argv[t], "high") == 0) { |
21
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
161 | settings->bfileHeuristics->level = BFILE_HIGH_ACCURACY; |
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
162 | } else { |
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
163 | return exit_with_help(settings, 1); |
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
164 | } |
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
165 | } |
28 | 166 | /* e */ |
27
95a958e3de88
added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
167 | if ((argflags & 512) > 0) { |
30
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
168 | if (!checkParamOpt(&paropt) || t + 2 >= argc) { |
27
95a958e3de88
added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
169 | return exit_with_help(settings, 1); |
95a958e3de88
added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
170 | } |
95a958e3de88
added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
171 | t++; add_string(settings->regex->pattern_list, argv[t]); |
95a958e3de88
added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
172 | t++; add_string(settings->regex->pattern_list, argv[t]); |
95a958e3de88
added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents:
26
diff
changeset
|
173 | } |
28 | 174 | /* E */ |
175 | if ((argflags & 1024) > 0) { | |
176 | t++; | |
30
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
177 | if (!checkParamOpt(&paropt) || t >= argc) { |
28 | 178 | return exit_with_help(settings, 1); |
179 | } | |
180 | add_string(settings->regex->pattern_list, argv[t]); | |
181 | add_string(settings->regex->pattern_list, "$"); | |
182 | } | |
1 | 183 | if (argflags == 0) { |
31
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
184 | /* SHORTCUTS */ |
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
185 | /* exclude-cstyle-comments */ |
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
186 | if (strcmp(argv[t], "--exclude-cstyle-comments") == 0) { |
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
187 | add_string(settings->regex->pattern_list, "\\s*//"); |
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
188 | add_string(settings->regex->pattern_list, "$"); |
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
189 | add_string(settings->regex->pattern_list, "\\s*/\\*"); |
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
190 | add_string(settings->regex->pattern_list, "\\*/\\s*"); |
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
191 | } |
27c3c1c6b768
added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
192 | /* Path */ |
33
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
193 | else { |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
194 | add_string(directories, argv[t]); |
0 | 195 | } |
196 | } | |
197 | } | |
198 | ||
22
4508da679ffb
completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
199 | /* Configure output */ |
16
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
200 | if (!settings->verbose) { |
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
201 | close_stdout(); |
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
202 | } |
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
203 | |
22
4508da679ffb
completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
204 | /* Find tokens */ |
30
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
205 | parseCSL(includeSuffix, settings->includeSuffixes); |
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
206 | parseCSL(excludeSuffix, settings->excludeSuffixes); |
0 | 207 | |
33
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
208 | /* Scan directories */ |
28 | 209 | if (regex_compile_all(settings->regex)) { |
33
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
210 | int lines = 0; |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
211 | if (directories->count == 0) { |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
212 | add_string(directories, "."); |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
213 | } |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
214 | for (int t = 0 ; t < directories->count ; t++) { |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
215 | if (t > 0) { |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
216 | for (int u = 0 ; u < 79 ; u++) { |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
217 | printf("-"); |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
218 | } |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
219 | printf("\n"); |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
220 | } |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
221 | lines += scanDirectory((scanner_t){directories->items[t], 0}, settings); |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
222 | } |
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
223 | destroy_string_list_t(directories); |
0 | 224 | |
28 | 225 | /* Print double line and line count */ |
226 | for (int t = 0 ; t < 79 ; t++) { | |
227 | printf("="); | |
228 | } | |
229 | printf("\n%73d lines\n", lines); | |
0 | 230 | |
28 | 231 | if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) { |
232 | printf("\nSome files contain too long lines.\n" | |
233 | "The regex parser currently supports a maximum line length of %d." | |
234 | "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); | |
235 | } | |
25
802c5382f499
Added line buffer (and warning message - there is no regexp parser, though)
Mike Becker <universe@uap-core.de>
parents:
23
diff
changeset
|
236 | |
28 | 237 | if (!settings->verbose) { |
238 | reopen_stdout(); | |
239 | printf("%d", lines); | |
240 | } | |
33
1a2d7298bc82
added multi-directory support
Mike Becker <universe@uap-core.de>
parents:
32
diff
changeset
|
241 | destroy_settings_t(settings); |
16
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
242 | } |
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
243 | |
bc9a0fefd892
fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents:
14
diff
changeset
|
244 | fflush(stdout); |
28 | 245 | fflush(stderr); |
0 | 246 | return 0; |
247 | } |