1.1 --- a/functions.c Mon May 30 08:45:08 2011 +0200 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,117 +0,0 @@ 1.4 -#include "cline.h" 1.5 -#include "functions.h" 1.6 - 1.7 -int checkArgument(const char* arg, const char* expected) { 1.8 - int len = strlen(expected); 1.9 - int ret = 0; 1.10 - 1.11 - if (arg[0] == '-') { 1.12 - if (arg[1] != '-') { 1.13 - for (int t = 0 ; t < len ; t++) { 1.14 - ret |= (strchr(arg, expected[t]) > 0) << t; 1.15 - } 1.16 - } 1.17 - } 1.18 - 1.19 - return ret; 1.20 -} 1.21 - 1.22 -bool registerArgument(int* reg, int mask) { 1.23 - bool ret = (*reg & mask) > 0; 1.24 - *reg |= mask; 1.25 - return ret; 1.26 -} 1.27 - 1.28 -bool testSuffix(char* filename, settings_t* settings) { 1.29 - bool ret = false; 1.30 - int tokenlen, fnamelen = strlen(filename); 1.31 - for (int t = 0 ; t < settings->suffixList->count ; t++) { 1.32 - tokenlen = strlen(settings->suffixList->items[t]); 1.33 - if (fnamelen >= tokenlen && tokenlen > 0) { 1.34 - if (strncmp(filename+fnamelen-tokenlen, 1.35 - settings->suffixList->items[t], tokenlen) == 0) { 1.36 - ret = true; 1.37 - break; 1.38 - } 1.39 - } 1.40 - } 1.41 - return ret ^ !settings->includeSuffixes; 1.42 -} 1.43 - 1.44 -int scanDirectory(DIR *dir, const int spaces, 1.45 - char* currdir, settings_t* settings) { 1.46 - DIR *subdir; 1.47 - char* subdirname; 1.48 - struct dirent *entry; 1.49 - int lines, digits, a; 1.50 - int lineSum = 0; 1.51 - 1.52 - while ((entry = readdir(dir)) != NULL) { 1.53 - if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { 1.54 - // Print occurence 1.55 - char entryname[strlen(entry->d_name)+spaces]; 1.56 - for (int t = 0 ; t < spaces ; t++) { 1.57 - entryname[t]=' '; 1.58 - } 1.59 - entryname[spaces] = 0; 1.60 - strcat(entryname, entry->d_name); 1.61 - 1.62 - // Check for subdirectory 1.63 - char subdirname[(1+strlen(currdir)+strlen(entry->d_name))]; 1.64 - strcpy(subdirname, currdir); 1.65 - strncat(subdirname, &settings->fileSeparator, 1); 1.66 - strcat(subdirname, entry->d_name); 1.67 - if ((subdir = opendir(subdirname)) != NULL) { 1.68 - printf("%-60s\n", entryname); 1.69 - if (settings->recursive) { 1.70 - lineSum += scanDirectory(subdir, spaces+1, subdirname, settings); 1.71 - } 1.72 - closedir(subdir); 1.73 - continue; 1.74 - } 1.75 - 1.76 - // Count lines 1.77 - lines = 0; 1.78 - char filename[(1+strlen(currdir)+strlen(entry->d_name))]; 1.79 - strcpy(filename, currdir); 1.80 - strncat(filename, &settings->fileSeparator, 1); 1.81 - strcat(filename, entry->d_name); 1.82 - if (testSuffix(filename, settings)) { 1.83 - FILE *file = fopen(filename, "r"); 1.84 - if (file == NULL) { 1.85 - perror(" File acces failed"); 1.86 - continue; 1.87 - } 1.88 - 1.89 - do { 1.90 - a = fgetc(file); 1.91 - 1.92 - if (a == 10) { 1.93 - lines++; 1.94 - } 1.95 - } while (a != EOF); 1.96 - fclose(file); 1.97 - 1.98 - // Print line count 1.99 - #ifdef _WIN32 1.100 - printf("%-60s%13d lines\n", entryname, lines); 1.101 - #else 1.102 - printf("%-60s%14d lines\n", entryname, lines); 1.103 - #endif /* _WIN32 */ 1.104 - 1.105 - lineSum += lines; 1.106 - } 1.107 - else { 1.108 - if (!settings->matchesOnly) { 1.109 - // Print hint 1.110 - #ifdef _WIN32 1.111 - printf("%-60s%19s\n", entryname, "no match"); 1.112 - #else 1.113 - printf("%-60s%20s\n", entryname, "no match"); 1.114 - #endif /* _WIN32 */ 1.115 - } 1.116 - } 1.117 - } 1.118 - } 1.119 - return lineSum; 1.120 -}