src/cline.c

Fri, 29 Sep 2023 20:07:20 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 29 Sep 2023 20:07:20 +0200
changeset 69
186e41b332d9
parent 66
be2084398c37
permissions
-rw-r--r--

add new dist target

10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
1 /*
34
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
57
68018eac46c3 adds simple tiny test suite and updates license headers
Mike Becker <universe@uap-core.de>
parents: 50
diff changeset
3 * Copyright 2018 Mike Becker. All rights reserved.
34
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
4 *
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
5 * Redistribution and use in source and binary forms, with or without
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
6 * modification, are permitted provided that the following conditions are met:
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
7 *
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
9 * notice, this list of conditions and the following disclaimer.
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
10 *
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
11 * 2. Redistributions in binary form must reproduce the above copyright
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
12 * notice, this list of conditions and the following disclaimer in the
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
13 * documentation and/or other materials provided with the distribution.
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
14 *
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
57
68018eac46c3 adds simple tiny test suite and updates license headers
Mike Becker <universe@uap-core.de>
parents: 50
diff changeset
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
25 */
6
be923400164c encapsulated suffix list in type suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
26
10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
27 #include "cline.h"
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
28 #include "scanner.h"
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
29 #include "settings.h"
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
30 #include "arguments.h"
27
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
31 #include "regex_parser.h"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
33 void printHelpText() {
34
fa9bda32de17 moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
34 printf(
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
35 "\nUsage:"
33
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
36 "\n cline [Options] [Directories...]"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 "\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
38 " files in the specified\ndirectories."
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 "\n\nOptions:"
21
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
40 "\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
41 "\n One of: ignore low medium high"
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
42 "\n -c - Count non-whitespace characters instead of lines"
28
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
43 "\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
44 "\n -e <start> <end> - Excludes lines between <start> and <end>"
28
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
45 "\n You may use these options multiple times"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 "\n -h, --help - this help text"
61
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
47 "\n -i - print out individual sums per file extension"
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
48 "\n (cannot be used together with -V)"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
49 "\n -m - print information about matching files only"
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
50 "\n -s <suffixes> - only count files with these suffixes (separated"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 "\n by commas)"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
52 "\n -S <suffixes> - count any file except those with these suffixes"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 "\n (separated by commas)"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
54 "\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
55 "\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
56 "\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
57 "\n\nShortcuts:"
57
68018eac46c3 adds simple tiny test suite and updates license headers
Mike Becker <universe@uap-core.de>
parents: 50
diff changeset
58 "\n --exclude-cstyle-comments : -E '\\s*//' -e '\\s*/\\*' '\\*/\\s*'"
68018eac46c3 adds simple tiny test suite and updates license headers
Mike Becker <universe@uap-core.de>
parents: 50
diff changeset
59 "\n --exclude-blank-lines : -E '^\\s*$'"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 "\n\n"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
61 "The default call without any options is:"
28
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
62 "\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
63 "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
64 "\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
65 "\n cline -rs .c\n"
28
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
66 "\nIf you want to exclude comment lines, you may use the -e/-E option."
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
67 "\nAfter a line matches the regex pattern <start>, this and any following"
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
68 "\nline is not counted unless a line matches the <end> pattern. A line is"
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
69 "\nstill counted when it does not start or end with the respective pattern."
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
70 "\nPlease note, that cline does not trim the lines before matching against"
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
71 "\nthe pattern."
31
27c3c1c6b768 added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
72 "\n\nExample (C without comments):"
36
a7ff583e153f updated copyright year + added make install + removed project files
Mike Becker <universe@uap-core.de>
parents: 35
diff changeset
73 "\n cline -s .c,.h --exclude-cstyle-comments"
a7ff583e153f updated copyright year + added make install + removed project files
Mike Becker <universe@uap-core.de>
parents: 35
diff changeset
74 "\n");
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
75 }
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
76
14
ee9333c91dda some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents: 12
diff changeset
77 int exit_with_version(settings_t* settings) {
48
0d2c13c24fd0 adds remaining autoconf files
Mike Becker <universe@uap-core.de>
parents: 44
diff changeset
78 printf("cline - Version: " VERSION "\n");
14
ee9333c91dda some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents: 12
diff changeset
79 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
80 return 0;
ee9333c91dda some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents: 12
diff changeset
81 }
ee9333c91dda some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents: 12
diff changeset
82
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
83 int exit_with_help(settings_t* settings, int code) {
50
63477d92411d fixes headers missing in dist package
Mike Becker <universe@uap-core.de>
parents: 48
diff changeset
84 printf("cline - Version: " VERSION "\n");
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
85 printHelpText();
8
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
86 destroy_settings_t(settings);
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
87 return code;
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
88 }
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
89
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
90 int main(int argc, char** argv) {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
92 /* Settings */
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
93 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
94 if (settings == NULL) {
9393eff3d2f9 Fixed memory leak when exiting the programm ahead of time
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
95 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
96 return 1;
9393eff3d2f9 Fixed memory leak when exiting the programm ahead of time
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
97 }
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
98
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
99 /* Get arguments */
33
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
100 string_list_t *directories = new_string_list_t();
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
101 if (directories == NULL) {
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
102 fprintf(stderr, "Memory allocation failed.\n");
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
103 return 1;
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
104 }
30
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
105 char* includeSuffix = NULL;
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
106 char* excludeSuffix = NULL;
8
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
107 int checked = 0;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
109 for (int t = 1 ; t < argc ; t++) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
110
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
111 int argflags = checkArgument(argv[t], "hsSrRmvVbeEic");
30
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
112 int paropt = 0;
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
113
59
c5409c8be36f reorders processing of arguments (help text first)
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
114 /* h */
c5409c8be36f reorders processing of arguments (help text first)
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
115 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) {
c5409c8be36f reorders processing of arguments (help text first)
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
116 return exit_with_help(settings, 0);
c5409c8be36f reorders processing of arguments (help text first)
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
117 }
30
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
118 /* s */
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
119 if ((argflags & 2) > 0) {
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
120 if (!checkParamOpt(&paropt) || registerArgument(&checked, 2)) {
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
121 return exit_with_help(settings, 1);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 }
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
123 t++;
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
124 if (t >= argc) {
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
125 return exit_with_help(settings, 1);
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
126 }
30
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
127 includeSuffix = argv[t];
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
128 }
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
129 /* S */
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
130 if ((argflags & 4) > 0) {
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
131 if (!checkParamOpt(&paropt) || registerArgument(&checked, 4)) {
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
132 return exit_with_help(settings, 1);
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
133 }
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
134 t++;
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
135 if (t >= argc) {
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
136 return exit_with_help(settings, 1);
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
137 }
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
138 excludeSuffix = argv[t];
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 }
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
140 /* r, R */
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
141 if ((argflags & 24) > 0) {
8
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
142 if (registerArgument(&checked, 24)) {
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
143 return exit_with_help(settings, 1);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 }
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
145 settings->recursive = true;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 }
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
147 /* m */
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
148 if ((argflags & 32) > 0) {
8
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
149 if (registerArgument(&checked, 32)) {
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
150 return exit_with_help(settings, 1);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 }
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
152 settings->matchesOnly = true;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 }
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
154 /* v */
14
ee9333c91dda some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents: 12
diff changeset
155 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
156 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
157 }
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
158 /* 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
159 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
160 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
161 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
162 }
bc9a0fefd892 fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents: 14
diff changeset
163 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
164 }
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
165 /* b */
21
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
166 if ((argflags & 256) > 0) {
30
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
167 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
168 return exit_with_help(settings, 1);
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
169 }
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
170 t++;
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
171 if (t >= argc) {
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
172 return exit_with_help(settings, 1);
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
173 }
24
3963e8800a12 replaced stricmp with strcasecmp to stay standard compliant
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
174 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
175 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
176 } 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
177 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
178 } 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
179 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
180 } 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
181 settings->bfileHeuristics->level = BFILE_HIGH_ACCURACY;
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
182 } else {
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
183 return exit_with_help(settings, 1);
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
184 }
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
185 }
28
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
186 /* e */
27
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
187 if ((argflags & 512) > 0) {
30
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
188 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
189 return exit_with_help(settings, 1);
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
190 }
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
191 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
192 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
193 }
28
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
194 /* E */
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
195 if ((argflags & 1024) > 0) {
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
196 t++;
30
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
197 if (!checkParamOpt(&paropt) || t >= argc) {
28
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
198 return exit_with_help(settings, 1);
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
199 }
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
200 add_string(settings->regex->pattern_list, argv[t]);
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
201 add_string(settings->regex->pattern_list, "$");
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
202 }
61
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
203 /* i */
60
69be673a4fd0 preparing changes for individual sum feature
Mike Becker <universe@uap-core.de>
parents: 59
diff changeset
204 if ((argflags & 2048) > 0) {
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
205 /* cannot be used together with -V */
61
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
206 if (registerArgument(&checked, 128)) {
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
207 return exit_with_help(settings, 1);
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
208 }
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
209 settings->individual_sums = true;
60
69be673a4fd0 preparing changes for individual sum feature
Mike Becker <universe@uap-core.de>
parents: 59
diff changeset
210 }
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
211 if ((argflags & 4096) > 0) {
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
212 if (registerArgument(&checked, 4096)) {
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
213 return exit_with_help(settings, 1);
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
214 }
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
215 settings->count_chars = true;
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
216 settings->regex->count_chars = true;
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
217 }
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
218 if (argflags == 0) {
31
27c3c1c6b768 added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
219 /* SHORTCUTS */
27c3c1c6b768 added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
220 if (strcmp(argv[t], "--exclude-cstyle-comments") == 0) {
27c3c1c6b768 added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
221 add_string(settings->regex->pattern_list, "\\s*//");
27c3c1c6b768 added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
222 add_string(settings->regex->pattern_list, "$");
27c3c1c6b768 added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
223 add_string(settings->regex->pattern_list, "\\s*/\\*");
27c3c1c6b768 added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
224 add_string(settings->regex->pattern_list, "\\*/\\s*");
57
68018eac46c3 adds simple tiny test suite and updates license headers
Mike Becker <universe@uap-core.de>
parents: 50
diff changeset
225 } else if (strcmp(argv[t], "--exclude-blank-lines") == 0) {
68018eac46c3 adds simple tiny test suite and updates license headers
Mike Becker <universe@uap-core.de>
parents: 50
diff changeset
226 add_string(settings->regex->pattern_list, "^\\s*$");
68018eac46c3 adds simple tiny test suite and updates license headers
Mike Becker <universe@uap-core.de>
parents: 50
diff changeset
227 add_string(settings->regex->pattern_list, "$");
31
27c3c1c6b768 added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
228 }
27c3c1c6b768 added --exclude-cstyle-comments shortcut
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
229 /* Path */
33
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
230 else {
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
231 add_string(directories, argv[t]);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
232 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
235
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
236 /* Find tokens */
30
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
237 parseCSL(includeSuffix, settings->includeSuffixes);
d642fdb6745e allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
238 parseCSL(excludeSuffix, settings->excludeSuffixes);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239
33
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
240 /* Scan directories */
28
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
241 if (regex_compile_all(settings->regex)) {
61
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
242 scanresult_t* result = new_scanresult_t(settings);
44
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
243 /* Don't waste memory when only the total sum is needed */
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
244 string_list_t *output = settings->verbose ? new_string_list_t() : NULL;
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
245 char *outbuf;
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
246 const char* result_type = settings->count_chars ? "chars" : "lines";
44
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
247
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
248 unsigned total = 0;
33
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
249 if (directories->count == 0) {
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
250 add_string(directories, ".");
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
251 }
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
252 for (unsigned t = 0 ; t < directories->count ; t++) {
60
69be673a4fd0 preparing changes for individual sum feature
Mike Becker <universe@uap-core.de>
parents: 59
diff changeset
253 scanDirectory((scanner_t){directories->items[t], 0}, settings,
61
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
254 output, result);
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
255 total += result->result;
44
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
256 if (directories->count > 1 ) {
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
257 outbuf = (char*) malloc(81);
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
258 memset(outbuf, '-', 79);
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
259 outbuf[79] = '\n';
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
260 outbuf[80] = 0;
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
261 add_string(output, outbuf);
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
262 outbuf = (char*) malloc(81);
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
263 snprintf(outbuf, 81, "%-63s%10u %s\n", directories->items[t],
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
264 result->result, result_type);
44
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
265 add_string(output, outbuf);
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
266 outbuf = (char*) malloc(81);
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
267 memset(outbuf, '-', 79);
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
268 outbuf[79] = '\n';
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
269 outbuf[80] = 0;
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
270 add_string(output, outbuf);
33
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
271 }
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
272 }
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
273 destroy_string_list_t(directories);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
274
44
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
275 /* Print result */
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
276 if (settings->verbose) {
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
277 for (int i = 0 ; i < output->count ; i++) {
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
278 printf("%s", output->items[i]);
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
279 free(output->items[i]);
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
280 }
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
281
61
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
282 if (result->ext) {
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
283 if (result->ext->count > 0) {
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
284 for (unsigned t = 0 ; t < 79 ; t++) {
61
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
285 printf("=");
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
286 }
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
287 printf("\nIndividual sums:\n");
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
288 for (unsigned t = 0 ; t < result->ext->count ; t++) {
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
289 printf(" %-62s%10u %s\n",
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
290 result->ext->extensions[t],
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
291 result->ext->result[t],
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
292 result_type);
61
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
293 }
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
294 }
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
295 }
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
296
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
297 for (unsigned t = 0 ; t < 79 ; t++) {
44
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
298 printf("=");
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
299 }
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
300 printf("\n%73d %s\n", total, result_type);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
301
44
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
302 if (settings->confusing_lnlen &&
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
303 settings->regex->pattern_list->count > 0) {
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
304
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
305 printf("\nSome files contain too long lines.\n"
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
306 "The parser currently supports a maximum line length of %u."
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
307 "\nThe result might be wrong.\n", MAX_LINELENGTH);
44
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
308 }
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
309 } else {
66
be2084398c37 new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents: 62
diff changeset
310 printf("%u", total);
28
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
311 }
61
9c8d768f0244 adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents: 60
diff changeset
312 destroy_scanresult_t(result);
44
9574a181ec26 line sum per directory now displayed + directories without matching files are no longer displayed when -m is used + new buffering strategy replaces stream hack when -V is used
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
313 destroy_string_list_t(output);
33
1a2d7298bc82 added multi-directory support
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
314 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
315 }
bc9a0fefd892 fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents: 14
diff changeset
316
bc9a0fefd892 fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents: 14
diff changeset
317 fflush(stdout);
28
72a98cbcb9f1 added regex parser
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
318 fflush(stderr);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
319 return 0;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
320 }

mercurial