src/scanner.c

changeset 60
69be673a4fd0
parent 58
bb512754aaf3
child 61
9c8d768f0244
equal deleted inserted replaced
59:c5409c8be36f 60:69be673a4fd0
110 closedir(dirf); 110 closedir(dirf);
111 111
112 return list; 112 return list;
113 } 113 }
114 114
115 int scanDirectory(scanner_t scanner, settings_t* settings, 115 void scanDirectory(scanner_t scanner, settings_t* settings,
116 string_list_t* output) { 116 string_list_t* output, scanresult_t* result) {
117 117
118 int lines, a; 118 result->directory = 0;
119 int lineSum = 0; 119 int a;
120 bool bfile; 120 bool bfile;
121 char *outbuf; 121 char *outbuf;
122 122
123 filelist_t *filelist = buildFileList(scanner, settings, NULL); 123 filelist_t *filelist = buildFileList(scanner, settings, NULL);
124 124
126 126
127 /* Scan subdirectories */ 127 /* Scan subdirectories */
128 if (!S_ISREG(filelist->st_mode)) { 128 if (!S_ISREG(filelist->st_mode)) {
129 if (settings->recursive && S_ISDIR(filelist->st_mode)) { 129 if (settings->recursive && S_ISDIR(filelist->st_mode)) {
130 string_list_t *recoutput = new_string_list_t(); 130 string_list_t *recoutput = new_string_list_t();
131 lines = scanDirectory( 131 scanresult_t recresult;
132 scanDirectory(
132 (scanner_t) {filelist->filename, scanner.spaces+1}, 133 (scanner_t) {filelist->filename, scanner.spaces+1},
133 settings, recoutput); 134 settings, recoutput, &recresult);
134 lineSum += lines; 135 result->directory += recresult.directory;
135 if (!settings->matchesOnly || recoutput->count > 0) { 136 if (!settings->matchesOnly || recoutput->count > 0) {
136 outbuf = (char*) malloc(81); 137 outbuf = (char*) malloc(81);
137 snprintf(outbuf, 81, "%*s/%*s%13d lines\n", 138 snprintf(outbuf, 81, "%*s/%*s%13d lines\n",
138 filelist->displayname_len+scanner.spaces, filelist->displayname, 139 filelist->displayname_len+scanner.spaces, filelist->displayname,
139 60-filelist->displayname_len-scanner.spaces-1, "", lines); 140 60-filelist->displayname_len-scanner.spaces-1, "",
141 recresult.directory);
140 add_string(output, outbuf); 142 add_string(output, outbuf);
141 for (int i = 0 ; i < recoutput->count ; i++) { 143 for (int i = 0 ; i < recoutput->count ; i++) {
142 add_string(output, recoutput->items[i]); 144 add_string(output, recoutput->items[i]);
143 } 145 }
144 } 146 }
153 if ((settings->includeSuffixes->count == 0 155 if ((settings->includeSuffixes->count == 0
154 || testSuffix(filelist->displayname, settings->includeSuffixes)) 156 || testSuffix(filelist->displayname, settings->includeSuffixes))
155 && !testSuffix(filelist->displayname, settings->excludeSuffixes)) { 157 && !testSuffix(filelist->displayname, settings->excludeSuffixes)) {
156 158
157 /* Count lines */ 159 /* Count lines */
158 lines = 0; 160 int lines = 0;
159 bfile = false; 161 bfile = false;
160 bfile_reset(settings->bfileHeuristics); 162 bfile_reset(settings->bfileHeuristics);
161 regex_parser_reset(settings->regex); 163 regex_parser_reset(settings->regex);
162 char line_buffer[REGEX_MAX_LINELENGTH]; 164 char line_buffer[REGEX_MAX_LINELENGTH];
163 int line_buffer_offset = 0; 165 int line_buffer_offset = 0;
207 filelist->displayname, 209 filelist->displayname,
208 60-filelist->displayname_len-scanner.spaces, "", "binary"); 210 60-filelist->displayname_len-scanner.spaces, "", "binary");
209 add_string(output, outbuf); 211 add_string(output, outbuf);
210 } 212 }
211 } else { 213 } else {
212 lineSum += lines; 214 result->directory += lines;
213 outbuf = (char*) malloc(81); 215 outbuf = (char*) malloc(81);
214 snprintf(outbuf, 81, "%*s%*s%13d lines\n", 216 snprintf(outbuf, 81, "%*s%*s%13d lines\n",
215 filelist->displayname_len+scanner.spaces, filelist->displayname, 217 filelist->displayname_len+scanner.spaces, filelist->displayname,
216 60-filelist->displayname_len-scanner.spaces, "", lines); 218 60-filelist->displayname_len-scanner.spaces, "", lines);
217 add_string(output, outbuf); 219 add_string(output, outbuf);
233 free(filelist->displayname); 235 free(filelist->displayname);
234 filelist_t *freethis = filelist; 236 filelist_t *freethis = filelist;
235 filelist = filelist->next; 237 filelist = filelist->next;
236 free(freethis); 238 free(freethis);
237 } 239 }
238
239 return lineSum;
240 } 240 }

mercurial