| 176 /* Create new filelist entry */ |
176 /* Create new filelist entry */ |
| 177 struct filelist *newentry = malloc(sizeof(struct filelist)); |
177 struct filelist *newentry = malloc(sizeof(struct filelist)); |
| 178 newentry->next = NULL; |
178 newentry->next = NULL; |
| 179 |
179 |
| 180 newentry->displayname_len = strlen(entry->d_name); |
180 newentry->displayname_len = strlen(entry->d_name); |
| 181 newentry->displayname = (char*) malloc(newentry->displayname_len+1); |
181 newentry->displayname = malloc(newentry->displayname_len+1); |
| 182 memcpy(newentry->displayname, entry->d_name, newentry->displayname_len); |
182 memcpy(newentry->displayname, entry->d_name, newentry->displayname_len); |
| 183 newentry->displayname[newentry->displayname_len] = 0; |
183 newentry->displayname[newentry->displayname_len] = 0; |
| 184 |
184 |
| 185 newentry->st_mode = 0; |
185 newentry->st_mode = 0; |
| 186 |
186 |
| 187 /* Construct full pathname string */ |
187 /* Construct full pathname string */ |
| 188 size_t dirnamelen = strlen(scanner.dir); |
188 size_t dirnamelen = strlen(scanner.dir); |
| 189 char *filename = (char*) malloc(2+dirnamelen+newentry->displayname_len); |
189 char *filename = malloc(2+dirnamelen+newentry->displayname_len); |
| 190 memcpy(filename, scanner.dir, dirnamelen); |
190 memcpy(filename, scanner.dir, dirnamelen); |
| 191 if (filename[dirnamelen - 1] != settings->fileSeparator) { |
191 if (filename[dirnamelen - 1] != settings->fileSeparator) { |
| 192 filename[dirnamelen++] = settings->fileSeparator; |
192 filename[dirnamelen++] = settings->fileSeparator; |
| 193 } |
193 } |
| 194 memcpy(filename+dirnamelen, entry->d_name, newentry->displayname_len); |
194 memcpy(filename+dirnamelen, entry->d_name, newentry->displayname_len); |
| 296 scanDirectory( |
296 scanDirectory( |
| 297 (scanner) {filelist->filename, scnr.spaces+1}, |
297 (scanner) {filelist->filename, scnr.spaces+1}, |
| 298 settings, recoutput, &recresult); |
298 settings, recoutput, &recresult); |
| 299 result->result += recresult.result; |
299 result->result += recresult.result; |
| 300 if (settings->verbose && (!settings->matchesOnly || recresult.result > 0)) { |
300 if (settings->verbose && (!settings->matchesOnly || recresult.result > 0)) { |
| 301 outbuf = (char*) malloc(81); |
301 outbuf = malloc(81); |
| 302 snprintf(outbuf, 81, "%*s/%*s%13u %s\n", |
302 snprintf(outbuf, 81, "%*s/%*s%13u %s\n", |
| 303 filelist->displayname_len+scnr.spaces, filelist->displayname, |
303 filelist->displayname_len+scnr.spaces, filelist->displayname, |
| 304 60-filelist->displayname_len-scnr.spaces-1, "", |
304 60-filelist->displayname_len-scnr.spaces-1, "", |
| 305 recresult.result, result_type); |
305 recresult.result, result_type); |
| 306 add_string(output, outbuf); |
306 add_string(output, outbuf); |
| 310 } |
310 } |
| 311 destroy_string_list(recoutput); |
311 destroy_string_list(recoutput); |
| 312 } |
312 } |
| 313 } |
313 } |
| 314 } else if (!settings->matchesOnly && settings->verbose) { |
314 } else if (!settings->matchesOnly && settings->verbose) { |
| 315 outbuf = (char*) malloc(81); |
315 outbuf = malloc(81); |
| 316 snprintf(outbuf, 81, "%*s\n", |
316 snprintf(outbuf, 81, "%*s\n", |
| 317 filelist->displayname_len+scnr.spaces, |
317 filelist->displayname_len+scnr.spaces, |
| 318 filelist->displayname); |
318 filelist->displayname); |
| 319 add_string(output, outbuf); |
319 add_string(output, outbuf); |
| 320 } |
320 } |
| 375 fclose(file); |
375 fclose(file); |
| 376 |
376 |
| 377 /* Print and sum line count */ |
377 /* Print and sum line count */ |
| 378 if (bfile) { |
378 if (bfile) { |
| 379 if (!settings->matchesOnly && !settings->dirsOnly && settings->verbose) { |
379 if (!settings->matchesOnly && !settings->dirsOnly && settings->verbose) { |
| 380 outbuf = (char*) malloc(81); |
380 outbuf = malloc(81); |
| 381 snprintf(outbuf, 81, |
381 snprintf(outbuf, 81, |
| 382 "%*s%*s%19s\n", filelist->displayname_len+scnr.spaces, |
382 "%*s%*s%19s\n", filelist->displayname_len+scnr.spaces, |
| 383 filelist->displayname, |
383 filelist->displayname, |
| 384 60-filelist->displayname_len-scnr.spaces, "", "binary"); |
384 60-filelist->displayname_len-scnr.spaces, "", "binary"); |
| 385 add_string(output, outbuf); |
385 add_string(output, outbuf); |
| 386 } |
386 } |
| 387 } else { |
387 } else { |
| 388 addResultPerExtension(result->ext, filelist->ext, res_value); |
388 addResultPerExtension(result->ext, filelist->ext, res_value); |
| 389 result->result += res_value; |
389 result->result += res_value; |
| 390 if (!settings->dirsOnly && settings->verbose) { |
390 if (!settings->dirsOnly && settings->verbose) { |
| 391 outbuf = (char*) malloc(81); |
391 outbuf = malloc(81); |
| 392 snprintf(outbuf, 81, "%*s%*s%13u %s\n", |
392 snprintf(outbuf, 81, "%*s%*s%13u %s\n", |
| 393 filelist->displayname_len+scnr.spaces, |
393 filelist->displayname_len+scnr.spaces, |
| 394 filelist->displayname, |
394 filelist->displayname, |
| 395 60-filelist->displayname_len-scnr.spaces, |
395 60-filelist->displayname_len-scnr.spaces, |
| 396 "", |
396 "", |
| 402 } |
402 } |
| 403 } |
403 } |
| 404 } else { |
404 } else { |
| 405 if (!settings->matchesOnly && !settings->dirsOnly && settings->verbose) { |
405 if (!settings->matchesOnly && !settings->dirsOnly && settings->verbose) { |
| 406 /* Print hint */ |
406 /* Print hint */ |
| 407 outbuf = (char*) malloc(81); |
407 outbuf = malloc(81); |
| 408 snprintf(outbuf, 81, "%*s%*s%19s\n", |
408 snprintf(outbuf, 81, "%*s%*s%19s\n", |
| 409 filelist->displayname_len+scnr.spaces, filelist->displayname, |
409 filelist->displayname_len+scnr.spaces, filelist->displayname, |
| 410 60-filelist->displayname_len-scnr.spaces, "", "no match"); |
410 60-filelist->displayname_len-scnr.spaces, "", "no match"); |
| 411 add_string(output, outbuf); |
411 add_string(output, outbuf); |
| 412 } |
412 } |