1.1 --- a/scanner.c Tue Oct 02 10:49:25 2012 +0200 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,126 +0,0 @@ 1.4 -/* 1.5 - * scanner.c 1.6 - * 1.7 - * Created on: 23.05.2011 1.8 - * Author: Mike 1.9 - */ 1.10 - 1.11 - 1.12 -#include "scanner.h" 1.13 -#include "suffix_fnc.h" 1.14 -#include "bfile_heuristics.h" 1.15 -#include "regex_parser.h" 1.16 -#include <sys/stat.h> 1.17 - 1.18 -int scanDirectory(scanner_t scanner, settings_t* settings) { 1.19 - 1.20 - DIR *dirf; 1.21 - struct dirent *entry; 1.22 - int lines, a; 1.23 - int lineSum = 0; 1.24 - bool bfile; 1.25 - struct stat statbuf; 1.26 - 1.27 - if ((dirf = opendir(scanner.dir)) == NULL) { 1.28 - printf(scanner.dir); 1.29 - perror(" Directory access failed"); 1.30 - return 0; 1.31 - } 1.32 - 1.33 - while ((entry = readdir(dirf)) != NULL) { 1.34 - if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { 1.35 - /* Construct tree view and absolute pathname strings */ 1.36 - char entryname[strlen(entry->d_name)+scanner.spaces]; 1.37 - for (int t = 0 ; t < scanner.spaces ; t++) { 1.38 - entryname[t]=' '; 1.39 - } 1.40 - entryname[scanner.spaces] = 0; 1.41 - strcat(entryname, entry->d_name); 1.42 - 1.43 - char filename[(1+strlen(scanner.dir)+strlen(entry->d_name))]; 1.44 - strcpy(filename, scanner.dir); 1.45 - strncat(filename, &settings->fileSeparator, 1); 1.46 - strcat(filename, entry->d_name); 1.47 - 1.48 - /* Check for subdirectory */ 1.49 - if (stat(filename, &statbuf) == 0) { 1.50 - if (!(statbuf.st_mode & S_IFREG)) { 1.51 - printf("%-60s\n", entryname); 1.52 - if (settings->recursive && (statbuf.st_mode & S_IFDIR)) { 1.53 - lineSum += scanDirectory( 1.54 - (scanner_t) {filename, scanner.spaces+1}, settings); 1.55 - } 1.56 - continue; 1.57 - } 1.58 - } else { 1.59 - perror(" Error in stat call"); 1.60 - continue; 1.61 - } 1.62 - 1.63 - if ((settings->includeSuffixes->count == 0 1.64 - || testSuffix(filename, settings->includeSuffixes)) 1.65 - && !testSuffix(filename, settings->excludeSuffixes)) { 1.66 - /* Count lines */ 1.67 - lines = 0; 1.68 - bfile = false; 1.69 - bfile_reset(settings->bfileHeuristics); 1.70 - char line_buffer[REGEX_MAX_LINELENGTH]; 1.71 - int line_buffer_offset = 0; 1.72 - 1.73 - FILE *file = fopen(filename, "r"); 1.74 - if (file == NULL) { 1.75 - printf(entryname); 1.76 - perror(" File acces failed"); 1.77 - continue; 1.78 - } 1.79 - 1.80 - do { 1.81 - a = fgetc(file); 1.82 - 1.83 - bfile = bfile_check(settings->bfileHeuristics, a); 1.84 - 1.85 - if (a == 10 || a == EOF) { 1.86 - line_buffer[line_buffer_offset] = 0; 1.87 - if (regex_parser_do(settings->regex, line_buffer) == 0) { 1.88 - /* Only subtract lines when matching has finished */ 1.89 - if (!regex_parser_matching(settings->regex)) { 1.90 - lines -= settings->regex->matched_lines; 1.91 - } 1.92 - } 1.93 - 1.94 - line_buffer_offset = 0; 1.95 - lines++; 1.96 - } else { 1.97 - if (line_buffer_offset < REGEX_MAX_LINELENGTH) { 1.98 - line_buffer[line_buffer_offset] = a; 1.99 - line_buffer_offset++; 1.100 - } else { 1.101 - line_buffer[line_buffer_offset-1] = 0; 1.102 - settings->confusing_lnlen = true; 1.103 - } 1.104 - } 1.105 - } while (!bfile && a != EOF); 1.106 - fclose(file); 1.107 - 1.108 - /* Print and sum line count */ 1.109 - if (bfile) { 1.110 - if (!settings->matchesOnly) { 1.111 - printf("%-60s%19s\n", entryname, "binary"); 1.112 - } 1.113 - } else { 1.114 - lineSum += lines; 1.115 - printf("%-60s%13d lines\n", entryname, lines); 1.116 - } 1.117 - } else { 1.118 - if (!settings->matchesOnly) { 1.119 - /* Print hint */ 1.120 - printf("%-60s%19s\n", entryname, "no match"); 1.121 - } 1.122 - } 1.123 - } 1.124 - } 1.125 - 1.126 - closedir(dirf); 1.127 - 1.128 - return lineSum; 1.129 -}