Sun, 10 Nov 2024 13:09:54 +0100
add msvc support - resolves #488
10 | 1 | /* |
34
fa9bda32de17
moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents:
30
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:
54
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:
30
diff
changeset
|
4 | * |
fa9bda32de17
moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents:
30
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:
30
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:
30
diff
changeset
|
7 | * |
fa9bda32de17
moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents:
30
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:
30
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:
30
diff
changeset
|
10 | * |
fa9bda32de17
moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents:
30
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:
30
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:
30
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:
30
diff
changeset
|
14 | * |
fa9bda32de17
moved src files to src subdirectory and added licence text
Mike Becker <universe@uap-core.de>
parents:
30
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:
30
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:
30
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:
30
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:
30
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:
30
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:
30
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:
30
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:
30
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:
54
diff
changeset
|
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
10 | 25 | */ |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
26 | |
8
28319b20968c
encapsulated common operations
Mike Becker <universe@uap-core.de>
parents:
6
diff
changeset
|
27 | |
10 | 28 | #include "scanner.h" |
21
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
29 | #include "bfile_heuristics.h" |
27
95a958e3de88
added regexp_parser struct and compile function
Mike Becker <universe@uap-core.de>
parents:
25
diff
changeset
|
30 | #include "regex_parser.h" |
23
778388400f7b
encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
31 | #include <sys/stat.h> |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
32 | #include <ctype.h> |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
33 | |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
34 | typedef struct filelist filelist_t; |
23
778388400f7b
encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
35 | |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
36 | struct filelist { |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
37 | char *displayname; |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
38 | unsigned displayname_len; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
39 | char *filename; |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
40 | char *ext; |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
41 | unsigned st_mode; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
42 | filelist_t *next; |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
43 | }; |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
44 | |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
45 | static bool testSuffix(char* filename, string_list_t* list) { |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
46 | bool ret = false; |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
47 | size_t tokenlen, fnamelen = strlen(filename); |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
48 | for (size_t t = 0 ; t < list->count ; t++) { |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
49 | tokenlen = strlen(list->items[t]); |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
50 | if (fnamelen >= tokenlen && tokenlen > 0) { |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
51 | if (strncmp(filename+fnamelen-tokenlen, |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
52 | list->items[t], tokenlen) == 0) { |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
53 | ret = true; |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
54 | break; |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
55 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
56 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
57 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
58 | return ret; |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
59 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
60 | |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
61 | static void addResultPerExtension(scanresult_ext_t* result, |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
62 | char* ext, unsigned value) { |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
63 | if (!result) return; |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
64 | |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
65 | if (!ext) ext = "w/o"; |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
66 | |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
67 | for (unsigned i = 0 ; i < result->count ; i++) { |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
68 | if (strcasecmp(result->extensions[i], ext) == 0) { |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
69 | result->result[i] += value; |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
70 | return; |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
71 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
72 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
73 | |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
74 | if (result->count == result->capacity) { |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
75 | unsigned newcap = result->capacity+8; |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
76 | char** extarr = realloc(result->extensions, newcap*sizeof(char*)); |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
77 | unsigned* resultarr = realloc(result->result, newcap*sizeof(unsigned)); |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
78 | if (!extarr || !resultarr) { |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
79 | fprintf(stderr, "Memory allocation error.\n"); |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
80 | abort(); |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
81 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
82 | result->extensions = extarr; |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
83 | result->result = resultarr; |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
84 | result->capacity = newcap; |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
85 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
86 | |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
87 | result->extensions[result->count] = strdup(ext); |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
88 | result->result[result->count] = value; |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
89 | result->count++; |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
90 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
91 | |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
92 | scanresult_t* new_scanresult_t(settings_t* settings) { |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
93 | scanresult_t* result = calloc(1, sizeof(scanresult_t)); |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
94 | if (settings->individual_sums) { |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
95 | result->ext = calloc(1, sizeof(scanresult_ext_t)); |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
96 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
97 | return result; |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
98 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
99 | |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
100 | void destroy_scanresult_t(scanresult_t* result) { |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
101 | if (result->ext) { |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
102 | if (result->ext->count > 0) { |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
103 | for (unsigned i = 0 ; i < result->ext->count ; i++) { |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
104 | free(result->ext->extensions[i]); |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
105 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
106 | free(result->ext->extensions); |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
107 | free(result->ext->result); |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
108 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
109 | free(result->ext); |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
110 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
111 | free(result); |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
112 | } |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
113 | |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
114 | static filelist_t *buildFileList(scanner_t scanner, settings_t* settings) { |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
115 | |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
116 | filelist_t* list = NULL; |
23
778388400f7b
encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
117 | DIR *dirf; |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
118 | struct dirent *entry; |
23
778388400f7b
encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
119 | struct stat statbuf; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
120 | |
23
778388400f7b
encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
121 | if ((dirf = opendir(scanner.dir)) == NULL) { |
58
bb512754aaf3
fixes error message when directory access fails
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
122 | fprintf(stderr, "%s - ", scanner.dir); |
bb512754aaf3
fixes error message when directory access fails
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
123 | perror("Directory access failed"); |
23
778388400f7b
encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
124 | return 0; |
778388400f7b
encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
125 | } |
778388400f7b
encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
126 | |
778388400f7b
encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
127 | while ((entry = readdir(dirf)) != NULL) { |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
128 | if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
129 | |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
130 | /* Create new filelist entry */ |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
131 | filelist_t *newentry = (filelist_t*) malloc(sizeof(filelist_t)); |
42 | 132 | newentry->next = NULL; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
133 | |
42 | 134 | newentry->displayname_len = strlen(entry->d_name); |
135 | newentry->displayname = (char*) malloc(newentry->displayname_len+1); | |
136 | memcpy(newentry->displayname, entry->d_name, newentry->displayname_len); | |
137 | newentry->displayname[newentry->displayname_len] = 0; | |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
138 | |
42 | 139 | newentry->st_mode = 0; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
140 | |
40
5938a9b74e8e
improved printing the results and fixed bug where the filename was displayed as an empty string
Mike Becker <universe@uap-core.de>
parents:
36
diff
changeset
|
141 | /* Construct absolute pathname string */ |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
142 | size_t dirnamelen = strlen(scanner.dir); |
42 | 143 | char *filename = (char*) malloc(2+dirnamelen+newentry->displayname_len); |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
144 | memcpy(filename, scanner.dir, dirnamelen); |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
145 | filename[dirnamelen] = settings->fileSeparator; |
42 | 146 | memcpy(filename+dirnamelen+1, entry->d_name, newentry->displayname_len); |
147 | filename[1+dirnamelen+newentry->displayname_len] = 0; | |
148 | newentry->filename = filename; | |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
149 | |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
150 | /* Obtain file extension */ |
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
151 | newentry->ext = strrchr(newentry->displayname, '.'); |
14
ee9333c91dda
some minor fixes + makefile now injects revisionnumber into cline.h
Mike Becker <universe@uap-core.de>
parents:
10
diff
changeset
|
152 | |
22
4508da679ffb
completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
153 | /* Check for subdirectory */ |
23
778388400f7b
encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
154 | if (stat(filename, &statbuf) == 0) { |
42 | 155 | newentry->st_mode = statbuf.st_mode; |
23
778388400f7b
encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
156 | } else { |
778388400f7b
encapsulated scanner arguments + enabled optimizer + empty file is no bfile
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
157 | perror(" Error in stat call"); |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
158 | continue; |
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
159 | } |
42 | 160 | |
161 | if (list) { | |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
162 | /* create fake root to have a pointer on the true root */ |
42 | 163 | filelist_t root; |
164 | root.next = list; | |
165 | filelist_t *parent = &root; | |
166 | while (parent->next && | |
167 | (strcasecmp(parent->next->displayname, newentry->displayname) < 0 || | |
168 | (!S_ISDIR(newentry->st_mode) && S_ISDIR(parent->next->st_mode)) | |
169 | ) && | |
170 | (!S_ISDIR(newentry->st_mode) || S_ISDIR(parent->next->st_mode)) | |
171 | ) { | |
172 | parent = parent->next; | |
173 | } | |
174 | newentry->next = parent->next; | |
175 | parent->next = newentry; | |
176 | list = root.next; | |
177 | } else { | |
178 | list = newentry; | |
179 | } | |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
180 | } |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
181 | } |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
182 | |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
183 | closedir(dirf); |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
184 | |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
185 | return list; |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
186 | } |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
187 | |
60
69be673a4fd0
preparing changes for individual sum feature
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
188 | void scanDirectory(scanner_t scanner, settings_t* settings, |
69be673a4fd0
preparing changes for individual sum feature
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
189 | string_list_t* output, scanresult_t* result) { |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
190 | |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
191 | result->result = 0; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
192 | bool bfile; |
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:
43
diff
changeset
|
193 | char *outbuf; |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
194 | const char *result_type = settings->count_chars ? "chars" : "lines"; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
195 | |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
196 | filelist_t *filelist = buildFileList(scanner, settings); |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
197 | |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
198 | while (filelist != NULL) { |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
199 | |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
200 | /* Scan subdirectories */ |
42 | 201 | if (!S_ISREG(filelist->st_mode)) { |
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:
43
diff
changeset
|
202 | if (settings->recursive && S_ISDIR(filelist->st_mode)) { |
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:
43
diff
changeset
|
203 | string_list_t *recoutput = new_string_list_t(); |
60
69be673a4fd0
preparing changes for individual sum feature
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
204 | scanresult_t recresult; |
61
9c8d768f0244
adds option to compute individual sums
Mike Becker <universe@uap-core.de>
parents:
60
diff
changeset
|
205 | recresult.ext = result->ext; |
60
69be673a4fd0
preparing changes for individual sum feature
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
206 | scanDirectory( |
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:
43
diff
changeset
|
207 | (scanner_t) {filelist->filename, scanner.spaces+1}, |
60
69be673a4fd0
preparing changes for individual sum feature
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
208 | settings, recoutput, &recresult); |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
209 | result->result += recresult.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:
43
diff
changeset
|
210 | if (!settings->matchesOnly || recoutput->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:
43
diff
changeset
|
211 | outbuf = (char*) malloc(81); |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
212 | snprintf(outbuf, 81, "%*s/%*s%13u %s\n", |
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:
43
diff
changeset
|
213 | filelist->displayname_len+scanner.spaces, filelist->displayname, |
60
69be673a4fd0
preparing changes for individual sum feature
Mike Becker <universe@uap-core.de>
parents:
58
diff
changeset
|
214 | 60-filelist->displayname_len-scanner.spaces-1, "", |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
215 | recresult.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:
43
diff
changeset
|
216 | add_string(output, outbuf); |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
217 | for (unsigned i = 0 ; i < recoutput->count ; i++) { |
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:
43
diff
changeset
|
218 | add_string(output, recoutput->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:
43
diff
changeset
|
219 | } |
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:
43
diff
changeset
|
220 | } |
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:
43
diff
changeset
|
221 | destroy_string_list_t(recoutput); |
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:
43
diff
changeset
|
222 | } else { |
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:
43
diff
changeset
|
223 | outbuf = (char*) malloc(81); |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
224 | snprintf(outbuf, 81, "%*s\n", |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
225 | filelist->displayname_len+scanner.spaces, |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
226 | filelist->displayname); |
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:
43
diff
changeset
|
227 | add_string(output, outbuf); |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
228 | } |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
229 | } else { |
30
d642fdb6745e
allow parallel use of -s and -S
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
230 | if ((settings->includeSuffixes->count == 0 |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
231 | || testSuffix(filelist->displayname, settings->includeSuffixes)) |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
232 | && !testSuffix(filelist->displayname, settings->excludeSuffixes)) { |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
233 | |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
234 | /* Count */ |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
235 | unsigned res_value = 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
|
236 | bfile = false; |
802c5382f499
Added line buffer (and warning message - there is no regexp parser, though)
Mike Becker <universe@uap-core.de>
parents:
23
diff
changeset
|
237 | bfile_reset(settings->bfileHeuristics); |
54
76d46533b9a9
regex parser was not properly reset before each file, sometimes resulting in wrong line counts, when the previous scanned file ended with a match
Mike Becker <universe@uap-core.de>
parents:
48
diff
changeset
|
238 | regex_parser_reset(settings->regex); |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
239 | char line_buffer[MAX_LINELENGTH]; |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
240 | unsigned line_buffer_pos = 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
|
241 | |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
242 | FILE *file = fopen(filelist->filename, "r"); |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
243 | if (file == NULL) { |
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:
43
diff
changeset
|
244 | outbuf = (char*) malloc(81); |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
245 | snprintf(outbuf, 81, "%*s", |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
246 | filelist->displayname_len+scanner.spaces, |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
247 | filelist->displayname); |
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:
43
diff
changeset
|
248 | add_string(output, outbuf); |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
249 | perror(" File acces failed"); |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
250 | } else { |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
251 | int a; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
252 | do { |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
253 | a = fgetc(file); |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
254 | |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
255 | bfile = bfile_check(settings->bfileHeuristics, a); |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
256 | |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
257 | /* ignore carriage return completely */ |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
258 | if (a == 13) continue; |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
259 | |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
260 | if (a == 10 || a == EOF) { |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
261 | line_buffer[line_buffer_pos] = 0; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
262 | if (regex_parser_do(settings->regex, line_buffer) == 0) { |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
263 | /* Subtract excluded lines/chars when matching has finished */ |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
264 | if (!regex_parser_matching(settings->regex)) { |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
265 | res_value -= settings->regex->matched_counted; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
266 | } |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
267 | } |
21
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
268 | |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
269 | if (settings->count_chars) { |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
270 | for (size_t i = 0 ; i < line_buffer_pos ; i++) { |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
271 | if (!isspace(line_buffer[i])) res_value++; |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
272 | } |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
273 | } else { |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
274 | res_value++; |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
275 | } |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
276 | line_buffer_pos = 0; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
277 | } else { |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
278 | if (line_buffer_pos < MAX_LINELENGTH) { |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
279 | line_buffer[line_buffer_pos] = (char) a; |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
280 | line_buffer_pos++; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
281 | } else { |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
282 | line_buffer[line_buffer_pos - 1] = 0; |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
283 | settings->confusing_lnlen = true; |
28 | 284 | } |
285 | } | |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
286 | } while (!bfile && a != EOF); |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
287 | fclose(file); |
25
802c5382f499
Added line buffer (and warning message - there is no regexp parser, though)
Mike Becker <universe@uap-core.de>
parents:
23
diff
changeset
|
288 | |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
289 | /* Print and sum line count */ |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
290 | if (bfile) { |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
291 | if (!settings->matchesOnly) { |
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:
43
diff
changeset
|
292 | 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:
43
diff
changeset
|
293 | snprintf(outbuf, 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:
43
diff
changeset
|
294 | "%*s%*s%19s\n", filelist->displayname_len+scanner.spaces, |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
295 | filelist->displayname, |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
296 | 60-filelist->displayname_len-scanner.spaces, "", "binary"); |
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:
43
diff
changeset
|
297 | add_string(output, outbuf); |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
298 | } |
25
802c5382f499
Added line buffer (and warning message - there is no regexp parser, though)
Mike Becker <universe@uap-core.de>
parents:
23
diff
changeset
|
299 | } else { |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
300 | addResultPerExtension(result->ext, filelist->ext, res_value); |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
301 | result->result += res_value; |
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:
43
diff
changeset
|
302 | outbuf = (char*) malloc(81); |
66
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
303 | snprintf(outbuf, 81, "%*s%*s%13u %s\n", |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
304 | filelist->displayname_len+scanner.spaces, |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
305 | filelist->displayname, |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
306 | 60-filelist->displayname_len-scanner.spaces, |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
307 | "", |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
308 | res_value, |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
309 | result_type |
be2084398c37
new feature: count non-whitespace characters
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
310 | ); |
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:
43
diff
changeset
|
311 | add_string(output, outbuf); |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
312 | } |
21
91e0890464b0
implemented bfile heuristics option + TODO: implement algorithm
Mike Becker <universe@uap-core.de>
parents:
20
diff
changeset
|
313 | } |
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
|
314 | } else { |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
315 | if (!settings->matchesOnly) { |
22
4508da679ffb
completed binary file heuristics
Mike Becker <universe@uap-core.de>
parents:
21
diff
changeset
|
316 | /* Print hint */ |
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:
43
diff
changeset
|
317 | 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:
43
diff
changeset
|
318 | snprintf(outbuf, 81, "%*s%*s%19s\n", |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
319 | filelist->displayname_len+scanner.spaces, filelist->displayname, |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
320 | 60-filelist->displayname_len-scanner.spaces, "", "no match"); |
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:
43
diff
changeset
|
321 | add_string(output, outbuf); |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
322 | } |
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
323 | } |
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
324 | } |
41
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
325 | |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
326 | free(filelist->filename); |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
327 | free(filelist->displayname); |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
328 | filelist_t *freethis = filelist; |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
329 | filelist = filelist->next; |
c2e73e175341
replaced direct scanning of directories with a two-step approach (first: create filename list, second: scan)
Mike Becker <universe@uap-core.de>
parents:
40
diff
changeset
|
330 | free(freethis); |
3
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
331 | } |
510d6b198dde
Moved some functions to functions.c
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
332 | } |