src/scanner.c

changeset 82
44b3332dfe03
parent 79
e4592d0292e7
equal deleted inserted replaced
81:54515e5d60f5 82:44b3332dfe03
199 199
200 /* Scan subdirectories */ 200 /* Scan subdirectories */
201 if (!S_ISREG(filelist->st_mode)) { 201 if (!S_ISREG(filelist->st_mode)) {
202 if (S_ISDIR(filelist->st_mode)) { 202 if (S_ISDIR(filelist->st_mode)) {
203 if (settings->recursive) { 203 if (settings->recursive) {
204 string_list_t *recoutput = new_string_list_t(); 204 string_list_t *recoutput = settings->verbose ? new_string_list_t() : NULL;
205 scanresult_t recresult; 205 scanresult_t recresult;
206 recresult.ext = result->ext; 206 recresult.ext = result->ext;
207 scanDirectory( 207 scanDirectory(
208 (scanner_t) {filelist->filename, scanner.spaces+1}, 208 (scanner_t) {filelist->filename, scanner.spaces+1},
209 settings, recoutput, &recresult); 209 settings, recoutput, &recresult);
210 result->result += recresult.result; 210 result->result += recresult.result;
211 if (!settings->matchesOnly || recresult.result > 0) { 211 if (settings->verbose && (!settings->matchesOnly || recresult.result > 0)) {
212 outbuf = (char*) malloc(81); 212 outbuf = (char*) malloc(81);
213 snprintf(outbuf, 81, "%*s/%*s%13u %s\n", 213 snprintf(outbuf, 81, "%*s/%*s%13u %s\n",
214 filelist->displayname_len+scanner.spaces, filelist->displayname, 214 filelist->displayname_len+scanner.spaces, filelist->displayname,
215 60-filelist->displayname_len-scanner.spaces-1, "", 215 60-filelist->displayname_len-scanner.spaces-1, "",
216 recresult.result, result_type); 216 recresult.result, result_type);
219 add_string(output, recoutput->items[i]); 219 add_string(output, recoutput->items[i]);
220 } 220 }
221 } 221 }
222 destroy_string_list_t(recoutput); 222 destroy_string_list_t(recoutput);
223 } 223 }
224 } else if (!settings->matchesOnly) { 224 } else if (!settings->matchesOnly && settings->verbose) {
225 outbuf = (char*) malloc(81); 225 outbuf = (char*) malloc(81);
226 snprintf(outbuf, 81, "%*s\n", 226 snprintf(outbuf, 81, "%*s\n",
227 filelist->displayname_len+scanner.spaces, 227 filelist->displayname_len+scanner.spaces,
228 filelist->displayname); 228 filelist->displayname);
229 add_string(output, outbuf); 229 add_string(output, outbuf);
241 char line_buffer[MAX_LINELENGTH + 1]; 241 char line_buffer[MAX_LINELENGTH + 1];
242 unsigned line_buffer_pos = 0; 242 unsigned line_buffer_pos = 0;
243 243
244 FILE *file = fopen(filelist->filename, "r"); 244 FILE *file = fopen(filelist->filename, "r");
245 if (file == NULL) { 245 if (file == NULL) {
246 outbuf = (char*) malloc(81); 246 fprintf(stderr, "Error: %s", filelist->displayname);
247 snprintf(outbuf, 81, "%*s",
248 filelist->displayname_len+scanner.spaces,
249 filelist->displayname);
250 add_string(output, outbuf);
251 perror(" File acces failed"); 247 perror(" File acces failed");
252 } else { 248 } else {
253 int a; 249 int a;
254 do { 250 do {
255 a = fgetc(file); 251 a = fgetc(file);
288 } while (!bfile && a != EOF); 284 } while (!bfile && a != EOF);
289 fclose(file); 285 fclose(file);
290 286
291 /* Print and sum line count */ 287 /* Print and sum line count */
292 if (bfile) { 288 if (bfile) {
293 if (!settings->matchesOnly && !settings->dirsOnly) { 289 if (!settings->matchesOnly && !settings->dirsOnly && settings->verbose) {
294 outbuf = (char*) malloc(81); 290 outbuf = (char*) malloc(81);
295 snprintf(outbuf, 81, 291 snprintf(outbuf, 81,
296 "%*s%*s%19s\n", filelist->displayname_len+scanner.spaces, 292 "%*s%*s%19s\n", filelist->displayname_len+scanner.spaces,
297 filelist->displayname, 293 filelist->displayname,
298 60-filelist->displayname_len-scanner.spaces, "", "binary"); 294 60-filelist->displayname_len-scanner.spaces, "", "binary");
299 add_string(output, outbuf); 295 add_string(output, outbuf);
300 } 296 }
301 } else { 297 } else {
302 addResultPerExtension(result->ext, filelist->ext, res_value); 298 addResultPerExtension(result->ext, filelist->ext, res_value);
303 result->result += res_value; 299 result->result += res_value;
304 if (!settings->dirsOnly) { 300 if (!settings->dirsOnly && settings->verbose) {
305 outbuf = (char*) malloc(81); 301 outbuf = (char*) malloc(81);
306 snprintf(outbuf, 81, "%*s%*s%13u %s\n", 302 snprintf(outbuf, 81, "%*s%*s%13u %s\n",
307 filelist->displayname_len+scanner.spaces, 303 filelist->displayname_len+scanner.spaces,
308 filelist->displayname, 304 filelist->displayname,
309 60-filelist->displayname_len-scanner.spaces, 305 60-filelist->displayname_len-scanner.spaces,
314 add_string(output, outbuf); 310 add_string(output, outbuf);
315 } 311 }
316 } 312 }
317 } 313 }
318 } else { 314 } else {
319 if (!settings->matchesOnly && !settings->dirsOnly) { 315 if (!settings->matchesOnly && !settings->dirsOnly && settings->verbose) {
320 /* Print hint */ 316 /* Print hint */
321 outbuf = (char*) malloc(81); 317 outbuf = (char*) malloc(81);
322 snprintf(outbuf, 81, "%*s%*s%19s\n", 318 snprintf(outbuf, 81, "%*s%*s%19s\n",
323 filelist->displayname_len+scanner.spaces, filelist->displayname, 319 filelist->displayname_len+scanner.spaces, filelist->displayname,
324 60-filelist->displayname_len-scanner.spaces, "", "no match"); 320 60-filelist->displayname_len-scanner.spaces, "", "no match");

mercurial