cline.c

Thu, 26 Jan 2012 15:55:52 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 26 Jan 2012 15:55:52 +0100
changeset 27
95a958e3de88
parent 26
853a1181884b
child 28
72a98cbcb9f1
permissions
-rw-r--r--

added regexp_parser struct and compile function

10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
1 /*
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
2 * cline.c
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
3 *
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
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
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
6 */
6
be923400164c encapsulated suffix list in type suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
7
10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
8 #include "cline.h"
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
9 #include "scanner.h"
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents: 8
diff changeset
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
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
15 void printHelpText() {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 const char* helpText =
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
17 "\nUsage:"
27
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
18 "\n cline [Options] [Directory]"
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
19 "\n cline [Options] [Directory]"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 "\n\nCounts the line terminator characters (\\n) within all"
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 " files in the specified\ndirectory."
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
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"
27
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
25 "\n -e <start> <end> - Excludes lines between <start> and <end>"
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
26 "\n You may use this option multiple times"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 "\n -h, --help - this help text"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
28 "\n -m - print information about matching files only"
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
29 "\n -s <suffixes> - only count files with these suffixes (separated"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 "\n by commas)"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
31 "\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
32 "\n (separated by commas)"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
33 "\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
34 "\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
35 "\n -V - turn verbose output off, print the result only"
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 "\n\n"
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
37 "The default call without any options is:"
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
38 "\n cline ./\n"
7
1b55f3fa52c9 Fixed helpText and removed extra variables for default values
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
39 "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
40 "\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
41 "\n cline -rs .c\n"
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
42 "\nIf you want to exclude comment lines, you may use the -e option."
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
43 "\nAfter a line matches the regex pattern <start> any following line is"
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
44 "\nnot counted unless a line matches the <end> pattern.";
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
45
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
46 printf(helpText);
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
47 }
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
48
14
ee9333c91dda some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents: 12
diff changeset
49 int exit_with_version(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
50 printf("cline - Revision: %s", VERSION);
14
ee9333c91dda some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents: 12
diff changeset
51 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
52 return 0;
ee9333c91dda some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents: 12
diff changeset
53 }
ee9333c91dda some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents: 12
diff changeset
54
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
55 int exit_with_help(settings_t* settings, int code) {
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
56 printHelpText();
8
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
57 destroy_settings_t(settings);
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
58 return code;
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
59 }
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
60
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
61 int main(int argc, char** argv) {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
63 /* Settings */
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
64 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
65 if (settings == NULL) {
9393eff3d2f9 Fixed memory leak when exiting the programm ahead of time
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
66 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
67 return 1;
9393eff3d2f9 Fixed memory leak when exiting the programm ahead of time
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
68 }
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
69
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
70 /* Get arguments */
7
1b55f3fa52c9 Fixed helpText and removed extra variables for default values
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
71 char* directory = "./";
1b55f3fa52c9 Fixed helpText and removed extra variables for default values
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
72 char* suffix = " ";
8
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
73 int checked = 0;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
75 for (int t = 1 ; t < argc ; t++) {
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
76
27
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
77 int argflags = checkArgument(argv[t], "hsSrRmvVbe");
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
78
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
79 /* s, S */
14
ee9333c91dda some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents: 12
diff changeset
80 if ((argflags & 6) > 0) {
8
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
81 if (registerArgument(&checked, 6)) {
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
82 return exit_with_help(settings, 1);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 }
14
ee9333c91dda some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents: 12
diff changeset
84 settings->includeSuffixes = (argflags & 2) > 0;
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
85 t++;
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
86 if (t >= argc) {
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
87 return exit_with_help(settings, 1);
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
88 }
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
89 suffix = argv[t];
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 }
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
91 /* h */
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
92 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
93 return exit_with_help(settings, 0);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 }
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
95 /* r, R */
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
96 if ((argflags & 24) > 0) {
8
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
97 if (registerArgument(&checked, 24)) {
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
98 return exit_with_help(settings, 1);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 }
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
100 settings->recursive = true;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 }
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
102 /* m */
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
103 if ((argflags & 32) > 0) {
8
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
104 if (registerArgument(&checked, 32)) {
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
105 return exit_with_help(settings, 1);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 }
3
510d6b198dde Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
107 settings->matchesOnly = true;
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 }
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
109 /* v */
14
ee9333c91dda some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents: 12
diff changeset
110 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
111 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
112 }
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
113 /* 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
114 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
115 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
116 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
117 }
bc9a0fefd892 fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents: 14
diff changeset
118 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
119 }
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
120 /* b */
21
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
121 if ((argflags & 256) > 0) {
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
122 if (registerArgument(&checked, 256)) {
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
123 return exit_with_help(settings, 1);
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
124 }
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
125 t++;
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
126 if (t >= argc) {
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
127 return exit_with_help(settings, 1);
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
128 }
24
3963e8800a12 replaced stricmp with strcasecmp to stay standard compliant
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
129 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
130 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
131 } 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
132 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
133 } 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
134 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
135 } 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
136 settings->bfileHeuristics->level = BFILE_HIGH_ACCURACY;
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
137 } else {
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
138 return exit_with_help(settings, 1);
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
139 }
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
140 }
27
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
141 if ((argflags & 512) > 0) {
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
142 if (t + 2 >= argc) {
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
143 return exit_with_help(settings, 1);
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
144 }
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
145 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
146 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
147 }
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
148 /* Path */
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
149 if (argflags == 0) {
8
28319b20968c encapsulated common operations
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
150 if (registerArgument(&checked, 1024)) {
12
902cb8d2053c removed dynamic programm name
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
151 return exit_with_help(settings, 1);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 directory = argv[t];
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
157 /* 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
158 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
159 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
160 }
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
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
162 /* Find tokens */
6
be923400164c encapsulated suffix list in type suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
163 char* finder = strtok(suffix, ",");
1
34a5e235d16e cline version 2
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
164 while (finder != NULL) {
19
8bac9fd0629d generalized suffix_list to string_list
Mike Becker <universe@uap-core.de>
parents: 16
diff changeset
165 add_string(settings->suffixList, finder);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 finder = strtok(NULL, ",");
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 }
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
169 /* Scan directory */
27
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
170 regex_compile_all(settings->regex);
23
778388400f7b encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
171 int lines = scanDirectory((scanner_t){directory, 0}, settings);
7
1b55f3fa52c9 Fixed helpText and removed extra variables for default values
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
172 destroy_settings_t(settings);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173
22
4508da679ffb completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
174 /* Print double line and line count */
21
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
175 for (int t = 0 ; t < 79 ; t++) {
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 printf("=");
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 }
21
91e0890464b0 implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents: 20
diff changeset
178 printf("\n%73d lines\n", lines);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179
27
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
180 if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) {
25
802c5382f499 Added line buffer (and warning message - there is no regexp parser, though)
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
181 printf("\nSome files contain too long lines.\n"
27
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
182 "The regex parser currently supports a maximum line length of %d."
95a958e3de88 added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents: 26
diff changeset
183 "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH);
25
802c5382f499 Added line buffer (and warning message - there is no regexp parser, though)
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
184 }
802c5382f499 Added line buffer (and warning message - there is no regexp parser, though)
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
185
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
186 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
187 reopen_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
188 printf("%d", lines);
bc9a0fefd892 fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents: 14
diff changeset
189 }
bc9a0fefd892 fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents: 14
diff changeset
190
bc9a0fefd892 fixed makefile to run safely on compile errors + added -V option to cline
Mike Becker <universe@uap-core.de>
parents: 14
diff changeset
191 fflush(stdout);
0
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
192 return 0;
518bfd1cc1e8 cline project init
Mike Becker <universe@uap-core.de>
parents:
diff changeset
193 }

mercurial