functions.c

changeset 10
ecf787666f44
parent 8
28319b20968c
child 11
06cbd0ec003d
--- a/functions.c	Mon May 30 08:45:08 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,117 +0,0 @@
-#include "cline.h"
-#include "functions.h"
-
-int checkArgument(const char* arg, const char* expected) {
-  int len = strlen(expected);
-  int ret = 0;
-
-  if (arg[0] == '-') {
-    if (arg[1] != '-') {
-      for (int t = 0 ; t < len ; t++) {
-        ret |= (strchr(arg, expected[t]) > 0) << t;
-      }
-    }
-  }  
-
-  return ret;
-}
-
-bool registerArgument(int* reg, int mask) {
-  bool ret = (*reg & mask) > 0;
-  *reg |= mask;
-  return ret;
-}
-
-bool testSuffix(char* filename, settings_t* settings) {
-  bool ret = false;
-  int tokenlen, fnamelen = strlen(filename);
-  for (int t = 0 ; t < settings->suffixList->count ; t++) {
-    tokenlen = strlen(settings->suffixList->items[t]);
-    if (fnamelen >= tokenlen && tokenlen > 0) {
-      if (strncmp(filename+fnamelen-tokenlen,
-                  settings->suffixList->items[t], tokenlen) == 0) {
-        ret = true;
-        break;
-      }
-    }
-  }
-  return ret ^ !settings->includeSuffixes;
-}
-
-int scanDirectory(DIR *dir, const int spaces,
-                  char* currdir, settings_t* settings) {
-  DIR *subdir;
-  char* subdirname;
-  struct dirent *entry;
-  int lines, digits, a;
-  int lineSum = 0;
-
-  while ((entry = readdir(dir)) != NULL) {
-    if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
-      // Print occurence
-      char entryname[strlen(entry->d_name)+spaces];
-      for (int t = 0 ; t < spaces ; t++) {
-        entryname[t]=' ';
-      }
-      entryname[spaces] = 0;
-      strcat(entryname, entry->d_name);
-  
-      // Check for subdirectory
-      char subdirname[(1+strlen(currdir)+strlen(entry->d_name))];
-      strcpy(subdirname, currdir);
-      strncat(subdirname, &settings->fileSeparator, 1);
-      strcat(subdirname, entry->d_name);
-      if ((subdir = opendir(subdirname)) != NULL) {
-        printf("%-60s\n", entryname);
-        if (settings->recursive) {
-          lineSum += scanDirectory(subdir, spaces+1, subdirname, settings);
-        }
-        closedir(subdir);
-        continue;
-      }
-
-      // Count lines
-      lines = 0;
-      char filename[(1+strlen(currdir)+strlen(entry->d_name))];
-      strcpy(filename, currdir);
-      strncat(filename, &settings->fileSeparator, 1);
-      strcat(filename, entry->d_name);
-      if (testSuffix(filename, settings)) {
-        FILE *file = fopen(filename, "r");
-        if (file == NULL) {
-          perror("  File acces failed");
-          continue;
-        }
-
-        do {
-          a = fgetc(file);
-
-          if (a == 10) {
-            lines++;
-          }
-        } while (a != EOF);
-        fclose(file);
-
-        // Print line count
-        #ifdef _WIN32
-          printf("%-60s%13d lines\n", entryname, lines);
-        #else
-          printf("%-60s%14d lines\n", entryname, lines);
-        #endif /* _WIN32 */
-
-        lineSum += lines;
-      }
-      else {
-        if (!settings->matchesOnly) {
-          // Print hint
-          #ifdef _WIN32
-            printf("%-60s%19s\n", entryname, "no match");
-          #else
-            printf("%-60s%20s\n", entryname, "no match");
-          #endif /* _WIN32 */
-        }
-      }
-    }
-  }
-  return lineSum;
-}

mercurial