refactored sources

Thu, 15 Sep 2011 13:29:06 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 15 Sep 2011 13:29:06 +0200
changeset 10
ecf787666f44
parent 8
28319b20968c
child 11
06cbd0ec003d

refactored sources

.cproject file | annotate | diff | comparison | revisions
.hgignore file | annotate | diff | comparison | revisions
.project file | annotate | diff | comparison | revisions
Makefile file | annotate | diff | comparison | revisions
arguments.c file | annotate | diff | comparison | revisions
arguments.h file | annotate | diff | comparison | revisions
cline.c file | annotate | diff | comparison | revisions
cline.h file | annotate | diff | comparison | revisions
functions.c file | annotate | diff | comparison | revisions
functions.h file | annotate | diff | comparison | revisions
scanner.c file | annotate | diff | comparison | revisions
scanner.h file | annotate | diff | comparison | revisions
settings.c file | annotate | diff | comparison | revisions
settings.h file | annotate | diff | comparison | revisions
stdinc.h file | annotate | diff | comparison | revisions
suffix_fnc.c file | annotate | diff | comparison | revisions
suffix_fnc.h file | annotate | diff | comparison | revisions
suffix_list.c file | annotate | diff | comparison | revisions
suffix_list.h file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.cproject	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?>
+
+<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+	<storageModule moduleId="org.eclipse.cdt.core.settings">
+		<cconfiguration id="cdt.managedbuild.toolchain.gnu.mingw.base.1677102573">
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.mingw.base.1677102573" moduleId="org.eclipse.cdt.core.settings" name="Default">
+				<externalSettings/>
+				<extensions>
+					<extension id="org.eclipse.cdt.core.PE" point="org.eclipse.cdt.core.BinaryParser"/>
+					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+				</extensions>
+			</storageModule>
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+				<configuration artifactName="cline" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.mingw.base.1677102573" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
+					<folderInfo id="cdt.managedbuild.toolchain.gnu.mingw.base.1677102573.925482417" name="/" resourcePath="">
+						<toolChain id="cdt.managedbuild.toolchain.gnu.mingw.base.1515980604" name="cdt.managedbuild.toolchain.gnu.mingw.base" superClass="cdt.managedbuild.toolchain.gnu.mingw.base">
+							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.PE" id="cdt.managedbuild.target.gnu.platform.mingw.base.572787976" name="Debug Platform" osList="win32" superClass="cdt.managedbuild.target.gnu.platform.mingw.base"/>
+							<builder id="cdt.managedbuild.target.gnu.builder.base.349472496" managedBuildOn="false" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+							<tool id="cdt.managedbuild.tool.gnu.assembler.mingw.base.1362600845" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.mingw.base">
+								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.902665459" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.archiver.mingw.base.1854197304" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.mingw.base"/>
+							<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.587980711" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base">
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1604468143" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.base.40840995" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.base">
+								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1426829237" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
+							</tool>
+							<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.base.1769052188" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.base"/>
+							<tool id="cdt.managedbuild.tool.gnu.cpp.linker.mingw.base.1937061838" name="MinGW C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.mingw.base">
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.683685806" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
+									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
+									<additionalInput kind="additionalinput" paths="$(LIBS)"/>
+								</inputType>
+							</tool>
+						</toolChain>
+					</folderInfo>
+				</configuration>
+			</storageModule>
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+		</cconfiguration>
+	</storageModule>
+	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+		<project id="cline.null.1826762082" name="cline"/>
+	</storageModule>
+	<storageModule moduleId="refreshScope" versionNumber="1">
+		<resource resourceType="PROJECT" workspacePath="/cline"/>
+	</storageModule>
+	<storageModule moduleId="scannerConfiguration">
+		<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+		<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1677102573;cdt.managedbuild.toolchain.gnu.mingw.base.1677102573.925482417;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.587980711;cdt.managedbuild.tool.gnu.cpp.compiler.input.1604468143">
+			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
+		</scannerConfigBuildInfo>
+		<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1677102573;cdt.managedbuild.toolchain.gnu.mingw.base.1677102573.925482417;cdt.managedbuild.tool.gnu.c.compiler.mingw.base.40840995;cdt.managedbuild.tool.gnu.c.compiler.input.1426829237">
+			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
+		</scannerConfigBuildInfo>
+	</storageModule>
+</cproject>
--- a/.hgignore	Mon May 30 08:45:08 2011 +0200
+++ b/.hgignore	Thu Sep 15 13:29:06 2011 +0200
@@ -1,5 +1,3 @@
 syntax: regexp
-^[^.]*\.o$
-^[^.]*\.exe$
-^cline$
+^build/.*$
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.project	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>cline</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+			<triggers>clean,full,incremental,</triggers>
+			<arguments>
+				<dictionary>
+					<key>?name?</key>
+					<value></value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.append_environment</key>
+					<value>true</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
+					<value>all</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.buildArguments</key>
+					<value></value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.buildCommand</key>
+					<value>make</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
+					<value>clean</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.contents</key>
+					<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
+					<value>false</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
+					<value>true</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.enableFullBuild</key>
+					<value>true</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
+					<value>all</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.stopOnError</key>
+					<value>true</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
+					<value>true</value>
+				</dictionary>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.cdt.core.cnature</nature>
+		<nature>org.eclipse.cdt.core.ccnature</nature>
+		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+	</natures>
+</projectDescription>
--- a/Makefile	Mon May 30 08:45:08 2011 +0200
+++ b/Makefile	Thu Sep 15 13:29:06 2011 +0200
@@ -1,11 +1,14 @@
 CC = gcc
-OBJ = cline.o functions.o
+BUILDDIR = build
+OBJ = ${BUILDDIR}/cline.o ${BUILDDIR}/scanner.o ${BUILDDIR}/settings.o ${BUILDDIR}/suffix_fnc.o ${BUILDDIR}/suffix_list.o ${BUILDDIR}/arguments.o
+BIN = ${BUILDDIR}/cline
 
-cline: ${OBJ}
-	${CC} -o cline ${OBJ}
+all: ${OBJ}
+	${CC} -o ${BIN} ${OBJ}
 
-%.o: %.c
-	${CC} -c -std=c99 $<
+${BUILDDIR}/%.o: %.c
+	mkdir -p ${BUILDDIR}
+	${CC} -c -std=c99 -o ${BUILDDIR}/$*.o $<
 
 clean:
-	rm *.o
+	rm build/*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/arguments.c	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,29 @@
+/*
+ * arguments.c
+ *
+ *  Created on: 15.09.2011
+ *      Author: beckermi
+ */
+
+#include "arguments.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;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/arguments.h	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,24 @@
+/*
+ * arguments.h
+ *
+ *  Created on: 15.09.2011
+ *      Author: beckermi
+ */
+
+#ifndef ARGUMENTS_H_
+#define ARGUMENTS_H_
+
+#include "stdinc.h"
+
+#ifdef _cplusplus
+extern "C" {
+#endif
+
+int checkArgument(const char*, const char*);
+bool registerArgument(int*, int);
+
+#ifdef _cplusplus
+}
+#endif
+
+#endif /* ARGUMENTS_H_ */
--- a/cline.c	Mon May 30 08:45:08 2011 +0200
+++ b/cline.c	Thu Sep 15 13:29:06 2011 +0200
@@ -1,50 +1,13 @@
-#include "cline.h"
-#include "functions.h"
-
-suffix_list_t* new_suffix_list_t() {
-  suffix_list_t* suffixList = malloc(sizeof(suffix_list_t*));
-  suffixList->count = 0;
-  suffixList->items = NULL;
-}
-
-void destroy_suffix_list_t(suffix_list_t* list) {
-  while (--list->count >= 0) {
-    free(list->items[list->count]);
-  }
-  free(list);
-}
+/*
+ * cline.c
+ *
+ *  Created on: 23.05.2011
+ *      Author: beckermi
+ */
 
-void add_suffix(suffix_list_t* list, char* item) {
-  char** reallocated_list =
-    realloc(list->items, sizeof(char**) * list->count + 1);
-  if (reallocated_list != NULL) {
-    list->items = reallocated_list;
-    list->items[list->count] = item;
-    list->count++;
-  }
-}
-
-settings_t* new_settings_t() {
-  settings_t *settings = malloc(sizeof(settings_t*));
-  if (settings != NULL) {
-  #ifdef _WIN32
-    settings->fileSeparator      = '\\';
-  #else
-    settings->fileSeparator      = '/';
-  #endif /* _WIN32 */
-    settings->recursive          = false;
-    settings->includeSuffixes    = false;
-    settings->matchesOnly        = false;
-    settings->suffixList         = new_suffix_list_t();
-  }
-  
-  return settings;
-}
-
-void destroy_settings_t(settings_t* settings) {
-  destroy_suffix_list_t(settings->suffixList);
-  free(settings);
-}
+#include "cline.h"
+#include "scanner.h"
+#include "settings.h"
 
 void printHelpText(const char* prgName) {
   // Help text
@@ -132,10 +95,7 @@
     }
     // h
     if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) {
-      if (registerArgument(&checked, 1)) {
-        return exit_with_help(prgName, settings, 1);
-      }
-      showHelp = true;
+      return exit_with_help(prgName, settings, 1);
     }
     // r, R
     if ((argflags & 24) > 0) {
@@ -160,11 +120,6 @@
     }
   }
 
-  // Show help and quit
-  if (showHelp) {
-    return exit_with_help(prgName, settings, 0);
-  }
-
   // Find tokens
   char* finder = strtok(suffix, ",");
   while (finder != NULL) {
--- a/cline.h	Mon May 30 08:45:08 2011 +0200
+++ b/cline.h	Thu Sep 15 13:29:06 2011 +0200
@@ -1,39 +1,25 @@
-#ifndef _CLINE_H
-#define _CLINE_H
-
-#include <stdio.h>
-#include <string.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <dirent.h>
-
+/*
+ * cline.h
+ *
+ *  Created on: 23.05.2011
+ *      Author: beckermi
+ */
 
-typedef struct _suffix_list {
-  int count;
-  char** items;
-} suffix_list_t;
+#ifndef CLINE_H_
+#define CLINE_H_
 
-typedef struct _settings {
-  char fileSeparator;
-  suffix_list_t* suffixList;
-  bool recursive;
-  bool includeSuffixes;
-  bool matchesOnly;
-} settings_t;
+#include "stdinc.h"
+#include "settings.h"
 
 #ifdef _cplusplus
 extern "C" {
 #endif
-settings_t* new_settings_t();
-void destroy_settings_t(settings_t*);
-suffix_list_t* new_suffix_list_t();
-void destroy_suffix_list_t(suffix_list_t*);
-void add_suffix(suffix_list_t*, char*);
 
 void printHelpText(const char*);
 int exit_with_help(char*, settings_t*, int);
+
 #ifdef _cplusplus
 }
 #endif
 
-#endif /* _CLINE_H */
+#endif /* CLINE_H_ */
--- 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;
-}
--- a/functions.h	Mon May 30 08:45:08 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-#ifndef _CLINE_FUNCTIONS_H
-#define _CLINE_FUNCTIONS_H
-
-#ifdef _cplusplus
-extern "C" {
-#endif
-
-int checkArgument(const char*, const char*);
-bool registerArgument(int*, int);
-bool testSuffix(char* filename, settings_t* settings);
-int scanDirectory(DIR *dir, const int spaces,
-                  char* currdir, settings_t* settings);
-
-#ifdef _cplusplus
-}
-#endif 
-                  
-#endif /* _CLINE_FUNCTIONS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scanner.c	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,88 @@
+/*
+ * functions.c
+ *
+ *  Created on: 23.05.2011
+ *      Author: beckermi
+ */
+
+
+#include "scanner.h"
+#include "suffix_fnc.h"
+
+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;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scanner.h	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,25 @@
+/*
+ * functions.h
+ *
+ *  Created on: 23.05.2011
+ *      Author: beckermi
+ */
+
+#ifndef SCANNER_H_
+#define SCANNER_H_
+
+#include "stdinc.h"
+#include "settings.h"
+
+#ifdef _cplusplus
+extern "C" {
+#endif
+
+int scanDirectory(DIR *dir, const int spaces,
+                  char* currdir, settings_t* settings);
+
+#ifdef _cplusplus
+}
+#endif 
+                  
+#endif /* SCANNER_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/settings.c	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,30 @@
+/*
+ * settings.c
+ *
+ *  Created on: 15.09.2011
+ *      Author: beckermi
+ */
+
+#include "settings.h"
+
+settings_t* new_settings_t() {
+  settings_t *settings = malloc(sizeof(settings_t*));
+  if (settings != NULL) {
+  #ifdef _WIN32
+    settings->fileSeparator      = '\\';
+  #else
+    settings->fileSeparator      = '/';
+  #endif /* _WIN32 */
+    settings->recursive          = false;
+    settings->includeSuffixes    = false;
+    settings->matchesOnly        = false;
+    settings->suffixList         = new_suffix_list_t();
+  }
+
+  return settings;
+}
+
+void destroy_settings_t(settings_t* settings) {
+  destroy_suffix_list_t(settings->suffixList);
+  free(settings);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/settings.h	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,33 @@
+/*
+ * settings.h
+ *
+ *  Created on: 15.09.2011
+ *      Author: beckermi
+ */
+
+#ifndef SETTINGS_H_
+#define SETTINGS_H_
+
+#include "stdinc.h"
+#include "suffix_list.h"
+
+typedef struct _settings {
+  char fileSeparator;
+  suffix_list_t* suffixList;
+  bool recursive;
+  bool includeSuffixes;
+  bool matchesOnly;
+} settings_t;
+
+#ifdef _cplusplus
+extern "C" {
+#endif
+
+settings_t* new_settings_t();
+void destroy_settings_t(settings_t*);
+
+#ifdef _cplusplus
+}
+#endif
+
+#endif /* SETTINGS_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stdinc.h	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,17 @@
+/*
+ * stdinc.h
+ *
+ *  Created on: 15.09.2011
+ *      Author: beckermi
+ */
+
+#ifndef STDINC_H_
+#define STDINC_H_
+
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <dirent.h>
+
+#endif /* STDINC_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/suffix_fnc.c	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,25 @@
+/*
+ * suffix_fnc.c
+ *
+ *  Created on: 15.09.2011
+ *      Author: beckermi
+ */
+
+#include "suffix_fnc.h"
+
+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;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/suffix_fnc.h	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,16 @@
+/*
+ * suffix_fnc.h
+ *
+ *  Created on: 15.09.2011
+ *      Author: beckermi
+ */
+
+#ifndef SUFFIX_FNC_H_
+#define SUFFIX_FNC_H_
+
+#include "stdinc.h"
+#include "settings.h"
+
+bool testSuffix(char*, settings_t*);
+
+#endif /* SUFFIX_FNC_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/suffix_list.c	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,34 @@
+/*
+ * suffix_list.c
+ *
+ *  Created on: 15.09.2011
+ *      Author: beckermi
+ */
+
+#include "suffix_list.h"
+
+suffix_list_t* new_suffix_list_t() {
+  suffix_list_t* suffixList = malloc(sizeof(suffix_list_t*));
+  suffixList->count = 0;
+  suffixList->items = NULL;
+
+  return suffixList;
+}
+
+void destroy_suffix_list_t(suffix_list_t* list) {
+  while (--list->count >= 0) {
+    free(list->items[list->count]);
+  }
+  free(list);
+}
+
+void add_suffix(suffix_list_t* list, char* item) {
+  char** reallocated_list =
+    realloc(list->items, sizeof(char**) * list->count + 1);
+  if (reallocated_list != NULL) {
+    list->items = reallocated_list;
+    list->items[list->count] = item;
+    list->count++;
+  }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/suffix_list.h	Thu Sep 15 13:29:06 2011 +0200
@@ -0,0 +1,30 @@
+/*
+ * suffix_list.h
+ *
+ *  Created on: 15.09.2011
+ *      Author: beckermi
+ */
+
+#ifndef SUFFIX_LIST_H_
+#define SUFFIX_LIST_H_
+
+#include "stdinc.h"
+
+typedef struct _suffix_list {
+  int count;
+  char** items;
+} suffix_list_t;
+
+#ifdef _cplusplus
+extern "C" {
+#endif
+
+suffix_list_t* new_suffix_list_t();
+void destroy_suffix_list_t(suffix_list_t*);
+void add_suffix(suffix_list_t*, char*);
+
+#ifdef _cplusplus
+}
+#endif
+
+#endif /* SUFFIX_LIST_H_ */

mercurial