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
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.cproject	Thu Sep 15 13:29:06 2011 +0200
     1.3 @@ -0,0 +1,63 @@
     1.4 +<?xml version="1.0" encoding="UTF-8" standalone="no"?>
     1.5 +<?fileVersion 4.0.0?>
     1.6 +
     1.7 +<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
     1.8 +	<storageModule moduleId="org.eclipse.cdt.core.settings">
     1.9 +		<cconfiguration id="cdt.managedbuild.toolchain.gnu.mingw.base.1677102573">
    1.10 +			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.mingw.base.1677102573" moduleId="org.eclipse.cdt.core.settings" name="Default">
    1.11 +				<externalSettings/>
    1.12 +				<extensions>
    1.13 +					<extension id="org.eclipse.cdt.core.PE" point="org.eclipse.cdt.core.BinaryParser"/>
    1.14 +					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
    1.15 +					<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
    1.16 +					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
    1.17 +					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
    1.18 +					<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
    1.19 +				</extensions>
    1.20 +			</storageModule>
    1.21 +			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
    1.22 +				<configuration artifactName="cline" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.mingw.base.1677102573" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
    1.23 +					<folderInfo id="cdt.managedbuild.toolchain.gnu.mingw.base.1677102573.925482417" name="/" resourcePath="">
    1.24 +						<toolChain id="cdt.managedbuild.toolchain.gnu.mingw.base.1515980604" name="cdt.managedbuild.toolchain.gnu.mingw.base" superClass="cdt.managedbuild.toolchain.gnu.mingw.base">
    1.25 +							<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"/>
    1.26 +							<builder id="cdt.managedbuild.target.gnu.builder.base.349472496" managedBuildOn="false" superClass="cdt.managedbuild.target.gnu.builder.base"/>
    1.27 +							<tool id="cdt.managedbuild.tool.gnu.assembler.mingw.base.1362600845" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.mingw.base">
    1.28 +								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.902665459" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
    1.29 +							</tool>
    1.30 +							<tool id="cdt.managedbuild.tool.gnu.archiver.mingw.base.1854197304" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.mingw.base"/>
    1.31 +							<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.587980711" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base">
    1.32 +								<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1604468143" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
    1.33 +							</tool>
    1.34 +							<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.base.40840995" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.base">
    1.35 +								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1426829237" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
    1.36 +							</tool>
    1.37 +							<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.base.1769052188" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.base"/>
    1.38 +							<tool id="cdt.managedbuild.tool.gnu.cpp.linker.mingw.base.1937061838" name="MinGW C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.mingw.base">
    1.39 +								<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.683685806" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
    1.40 +									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
    1.41 +									<additionalInput kind="additionalinput" paths="$(LIBS)"/>
    1.42 +								</inputType>
    1.43 +							</tool>
    1.44 +						</toolChain>
    1.45 +					</folderInfo>
    1.46 +				</configuration>
    1.47 +			</storageModule>
    1.48 +			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
    1.49 +		</cconfiguration>
    1.50 +	</storageModule>
    1.51 +	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
    1.52 +		<project id="cline.null.1826762082" name="cline"/>
    1.53 +	</storageModule>
    1.54 +	<storageModule moduleId="refreshScope" versionNumber="1">
    1.55 +		<resource resourceType="PROJECT" workspacePath="/cline"/>
    1.56 +	</storageModule>
    1.57 +	<storageModule moduleId="scannerConfiguration">
    1.58 +		<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
    1.59 +		<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">
    1.60 +			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
    1.61 +		</scannerConfigBuildInfo>
    1.62 +		<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">
    1.63 +			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
    1.64 +		</scannerConfigBuildInfo>
    1.65 +	</storageModule>
    1.66 +</cproject>
     2.1 --- a/.hgignore	Mon May 30 08:45:08 2011 +0200
     2.2 +++ b/.hgignore	Thu Sep 15 13:29:06 2011 +0200
     2.3 @@ -1,5 +1,3 @@
     2.4  syntax: regexp
     2.5 -^[^.]*\.o$
     2.6 -^[^.]*\.exe$
     2.7 -^cline$
     2.8 +^build/.*$
     2.9  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/.project	Thu Sep 15 13:29:06 2011 +0200
     3.3 @@ -0,0 +1,78 @@
     3.4 +<?xml version="1.0" encoding="UTF-8"?>
     3.5 +<projectDescription>
     3.6 +	<name>cline</name>
     3.7 +	<comment></comment>
     3.8 +	<projects>
     3.9 +	</projects>
    3.10 +	<buildSpec>
    3.11 +		<buildCommand>
    3.12 +			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
    3.13 +			<triggers>clean,full,incremental,</triggers>
    3.14 +			<arguments>
    3.15 +				<dictionary>
    3.16 +					<key>?name?</key>
    3.17 +					<value></value>
    3.18 +				</dictionary>
    3.19 +				<dictionary>
    3.20 +					<key>org.eclipse.cdt.make.core.append_environment</key>
    3.21 +					<value>true</value>
    3.22 +				</dictionary>
    3.23 +				<dictionary>
    3.24 +					<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
    3.25 +					<value>all</value>
    3.26 +				</dictionary>
    3.27 +				<dictionary>
    3.28 +					<key>org.eclipse.cdt.make.core.buildArguments</key>
    3.29 +					<value></value>
    3.30 +				</dictionary>
    3.31 +				<dictionary>
    3.32 +					<key>org.eclipse.cdt.make.core.buildCommand</key>
    3.33 +					<value>make</value>
    3.34 +				</dictionary>
    3.35 +				<dictionary>
    3.36 +					<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
    3.37 +					<value>clean</value>
    3.38 +				</dictionary>
    3.39 +				<dictionary>
    3.40 +					<key>org.eclipse.cdt.make.core.contents</key>
    3.41 +					<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
    3.42 +				</dictionary>
    3.43 +				<dictionary>
    3.44 +					<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
    3.45 +					<value>false</value>
    3.46 +				</dictionary>
    3.47 +				<dictionary>
    3.48 +					<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
    3.49 +					<value>true</value>
    3.50 +				</dictionary>
    3.51 +				<dictionary>
    3.52 +					<key>org.eclipse.cdt.make.core.enableFullBuild</key>
    3.53 +					<value>true</value>
    3.54 +				</dictionary>
    3.55 +				<dictionary>
    3.56 +					<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
    3.57 +					<value>all</value>
    3.58 +				</dictionary>
    3.59 +				<dictionary>
    3.60 +					<key>org.eclipse.cdt.make.core.stopOnError</key>
    3.61 +					<value>true</value>
    3.62 +				</dictionary>
    3.63 +				<dictionary>
    3.64 +					<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
    3.65 +					<value>true</value>
    3.66 +				</dictionary>
    3.67 +			</arguments>
    3.68 +		</buildCommand>
    3.69 +		<buildCommand>
    3.70 +			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
    3.71 +			<arguments>
    3.72 +			</arguments>
    3.73 +		</buildCommand>
    3.74 +	</buildSpec>
    3.75 +	<natures>
    3.76 +		<nature>org.eclipse.cdt.core.cnature</nature>
    3.77 +		<nature>org.eclipse.cdt.core.ccnature</nature>
    3.78 +		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
    3.79 +		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
    3.80 +	</natures>
    3.81 +</projectDescription>
     4.1 --- a/Makefile	Mon May 30 08:45:08 2011 +0200
     4.2 +++ b/Makefile	Thu Sep 15 13:29:06 2011 +0200
     4.3 @@ -1,11 +1,14 @@
     4.4  CC = gcc
     4.5 -OBJ = cline.o functions.o
     4.6 +BUILDDIR = build
     4.7 +OBJ = ${BUILDDIR}/cline.o ${BUILDDIR}/scanner.o ${BUILDDIR}/settings.o ${BUILDDIR}/suffix_fnc.o ${BUILDDIR}/suffix_list.o ${BUILDDIR}/arguments.o
     4.8 +BIN = ${BUILDDIR}/cline
     4.9  
    4.10 -cline: ${OBJ}
    4.11 -	${CC} -o cline ${OBJ}
    4.12 +all: ${OBJ}
    4.13 +	${CC} -o ${BIN} ${OBJ}
    4.14  
    4.15 -%.o: %.c
    4.16 -	${CC} -c -std=c99 $<
    4.17 +${BUILDDIR}/%.o: %.c
    4.18 +	mkdir -p ${BUILDDIR}
    4.19 +	${CC} -c -std=c99 -o ${BUILDDIR}/$*.o $<
    4.20  
    4.21  clean:
    4.22 -	rm *.o
    4.23 +	rm build/*
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/arguments.c	Thu Sep 15 13:29:06 2011 +0200
     5.3 @@ -0,0 +1,29 @@
     5.4 +/*
     5.5 + * arguments.c
     5.6 + *
     5.7 + *  Created on: 15.09.2011
     5.8 + *      Author: beckermi
     5.9 + */
    5.10 +
    5.11 +#include "arguments.h"
    5.12 +
    5.13 +int checkArgument(const char* arg, const char* expected) {
    5.14 +  int len = strlen(expected);
    5.15 +  int ret = 0;
    5.16 +
    5.17 +  if (arg[0] == '-') {
    5.18 +    if (arg[1] != '-') {
    5.19 +      for (int t = 0 ; t < len ; t++) {
    5.20 +        ret |= (strchr(arg, expected[t]) > 0) << t;
    5.21 +      }
    5.22 +    }
    5.23 +  }
    5.24 +
    5.25 +  return ret;
    5.26 +}
    5.27 +
    5.28 +bool registerArgument(int* reg, int mask) {
    5.29 +  bool ret = (*reg & mask) > 0;
    5.30 +  *reg |= mask;
    5.31 +  return ret;
    5.32 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/arguments.h	Thu Sep 15 13:29:06 2011 +0200
     6.3 @@ -0,0 +1,24 @@
     6.4 +/*
     6.5 + * arguments.h
     6.6 + *
     6.7 + *  Created on: 15.09.2011
     6.8 + *      Author: beckermi
     6.9 + */
    6.10 +
    6.11 +#ifndef ARGUMENTS_H_
    6.12 +#define ARGUMENTS_H_
    6.13 +
    6.14 +#include "stdinc.h"
    6.15 +
    6.16 +#ifdef _cplusplus
    6.17 +extern "C" {
    6.18 +#endif
    6.19 +
    6.20 +int checkArgument(const char*, const char*);
    6.21 +bool registerArgument(int*, int);
    6.22 +
    6.23 +#ifdef _cplusplus
    6.24 +}
    6.25 +#endif
    6.26 +
    6.27 +#endif /* ARGUMENTS_H_ */
     7.1 --- a/cline.c	Mon May 30 08:45:08 2011 +0200
     7.2 +++ b/cline.c	Thu Sep 15 13:29:06 2011 +0200
     7.3 @@ -1,50 +1,13 @@
     7.4 +/*
     7.5 + * cline.c
     7.6 + *
     7.7 + *  Created on: 23.05.2011
     7.8 + *      Author: beckermi
     7.9 + */
    7.10 +
    7.11  #include "cline.h"
    7.12 -#include "functions.h"
    7.13 -
    7.14 -suffix_list_t* new_suffix_list_t() {
    7.15 -  suffix_list_t* suffixList = malloc(sizeof(suffix_list_t*));
    7.16 -  suffixList->count = 0;
    7.17 -  suffixList->items = NULL;
    7.18 -}
    7.19 -
    7.20 -void destroy_suffix_list_t(suffix_list_t* list) {
    7.21 -  while (--list->count >= 0) {
    7.22 -    free(list->items[list->count]);
    7.23 -  }
    7.24 -  free(list);
    7.25 -}
    7.26 -
    7.27 -void add_suffix(suffix_list_t* list, char* item) {
    7.28 -  char** reallocated_list =
    7.29 -    realloc(list->items, sizeof(char**) * list->count + 1);
    7.30 -  if (reallocated_list != NULL) {
    7.31 -    list->items = reallocated_list;
    7.32 -    list->items[list->count] = item;
    7.33 -    list->count++;
    7.34 -  }
    7.35 -}
    7.36 -
    7.37 -settings_t* new_settings_t() {
    7.38 -  settings_t *settings = malloc(sizeof(settings_t*));
    7.39 -  if (settings != NULL) {
    7.40 -  #ifdef _WIN32
    7.41 -    settings->fileSeparator      = '\\';
    7.42 -  #else
    7.43 -    settings->fileSeparator      = '/';
    7.44 -  #endif /* _WIN32 */
    7.45 -    settings->recursive          = false;
    7.46 -    settings->includeSuffixes    = false;
    7.47 -    settings->matchesOnly        = false;
    7.48 -    settings->suffixList         = new_suffix_list_t();
    7.49 -  }
    7.50 -  
    7.51 -  return settings;
    7.52 -}
    7.53 -
    7.54 -void destroy_settings_t(settings_t* settings) {
    7.55 -  destroy_suffix_list_t(settings->suffixList);
    7.56 -  free(settings);
    7.57 -}
    7.58 +#include "scanner.h"
    7.59 +#include "settings.h"
    7.60  
    7.61  void printHelpText(const char* prgName) {
    7.62    // Help text
    7.63 @@ -132,10 +95,7 @@
    7.64      }
    7.65      // h
    7.66      if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) {
    7.67 -      if (registerArgument(&checked, 1)) {
    7.68 -        return exit_with_help(prgName, settings, 1);
    7.69 -      }
    7.70 -      showHelp = true;
    7.71 +      return exit_with_help(prgName, settings, 1);
    7.72      }
    7.73      // r, R
    7.74      if ((argflags & 24) > 0) {
    7.75 @@ -160,11 +120,6 @@
    7.76      }
    7.77    }
    7.78  
    7.79 -  // Show help and quit
    7.80 -  if (showHelp) {
    7.81 -    return exit_with_help(prgName, settings, 0);
    7.82 -  }
    7.83 -
    7.84    // Find tokens
    7.85    char* finder = strtok(suffix, ",");
    7.86    while (finder != NULL) {
     8.1 --- a/cline.h	Mon May 30 08:45:08 2011 +0200
     8.2 +++ b/cline.h	Thu Sep 15 13:29:06 2011 +0200
     8.3 @@ -1,39 +1,25 @@
     8.4 -#ifndef _CLINE_H
     8.5 -#define _CLINE_H
     8.6 +/*
     8.7 + * cline.h
     8.8 + *
     8.9 + *  Created on: 23.05.2011
    8.10 + *      Author: beckermi
    8.11 + */
    8.12  
    8.13 -#include <stdio.h>
    8.14 -#include <string.h>
    8.15 -#include <stdbool.h>
    8.16 -#include <stdlib.h>
    8.17 -#include <dirent.h>
    8.18 +#ifndef CLINE_H_
    8.19 +#define CLINE_H_
    8.20  
    8.21 -
    8.22 -typedef struct _suffix_list {
    8.23 -  int count;
    8.24 -  char** items;
    8.25 -} suffix_list_t;
    8.26 -
    8.27 -typedef struct _settings {
    8.28 -  char fileSeparator;
    8.29 -  suffix_list_t* suffixList;
    8.30 -  bool recursive;
    8.31 -  bool includeSuffixes;
    8.32 -  bool matchesOnly;
    8.33 -} settings_t;
    8.34 +#include "stdinc.h"
    8.35 +#include "settings.h"
    8.36  
    8.37  #ifdef _cplusplus
    8.38  extern "C" {
    8.39  #endif
    8.40 -settings_t* new_settings_t();
    8.41 -void destroy_settings_t(settings_t*);
    8.42 -suffix_list_t* new_suffix_list_t();
    8.43 -void destroy_suffix_list_t(suffix_list_t*);
    8.44 -void add_suffix(suffix_list_t*, char*);
    8.45  
    8.46  void printHelpText(const char*);
    8.47  int exit_with_help(char*, settings_t*, int);
    8.48 +
    8.49  #ifdef _cplusplus
    8.50  }
    8.51  #endif
    8.52  
    8.53 -#endif /* _CLINE_H */
    8.54 +#endif /* CLINE_H_ */
     9.1 --- a/functions.c	Mon May 30 08:45:08 2011 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,117 +0,0 @@
     9.4 -#include "cline.h"
     9.5 -#include "functions.h"
     9.6 -
     9.7 -int checkArgument(const char* arg, const char* expected) {
     9.8 -  int len = strlen(expected);
     9.9 -  int ret = 0;
    9.10 -
    9.11 -  if (arg[0] == '-') {
    9.12 -    if (arg[1] != '-') {
    9.13 -      for (int t = 0 ; t < len ; t++) {
    9.14 -        ret |= (strchr(arg, expected[t]) > 0) << t;
    9.15 -      }
    9.16 -    }
    9.17 -  }  
    9.18 -
    9.19 -  return ret;
    9.20 -}
    9.21 -
    9.22 -bool registerArgument(int* reg, int mask) {
    9.23 -  bool ret = (*reg & mask) > 0;
    9.24 -  *reg |= mask;
    9.25 -  return ret;
    9.26 -}
    9.27 -
    9.28 -bool testSuffix(char* filename, settings_t* settings) {
    9.29 -  bool ret = false;
    9.30 -  int tokenlen, fnamelen = strlen(filename);
    9.31 -  for (int t = 0 ; t < settings->suffixList->count ; t++) {
    9.32 -    tokenlen = strlen(settings->suffixList->items[t]);
    9.33 -    if (fnamelen >= tokenlen && tokenlen > 0) {
    9.34 -      if (strncmp(filename+fnamelen-tokenlen,
    9.35 -                  settings->suffixList->items[t], tokenlen) == 0) {
    9.36 -        ret = true;
    9.37 -        break;
    9.38 -      }
    9.39 -    }
    9.40 -  }
    9.41 -  return ret ^ !settings->includeSuffixes;
    9.42 -}
    9.43 -
    9.44 -int scanDirectory(DIR *dir, const int spaces,
    9.45 -                  char* currdir, settings_t* settings) {
    9.46 -  DIR *subdir;
    9.47 -  char* subdirname;
    9.48 -  struct dirent *entry;
    9.49 -  int lines, digits, a;
    9.50 -  int lineSum = 0;
    9.51 -
    9.52 -  while ((entry = readdir(dir)) != NULL) {
    9.53 -    if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
    9.54 -      // Print occurence
    9.55 -      char entryname[strlen(entry->d_name)+spaces];
    9.56 -      for (int t = 0 ; t < spaces ; t++) {
    9.57 -        entryname[t]=' ';
    9.58 -      }
    9.59 -      entryname[spaces] = 0;
    9.60 -      strcat(entryname, entry->d_name);
    9.61 -  
    9.62 -      // Check for subdirectory
    9.63 -      char subdirname[(1+strlen(currdir)+strlen(entry->d_name))];
    9.64 -      strcpy(subdirname, currdir);
    9.65 -      strncat(subdirname, &settings->fileSeparator, 1);
    9.66 -      strcat(subdirname, entry->d_name);
    9.67 -      if ((subdir = opendir(subdirname)) != NULL) {
    9.68 -        printf("%-60s\n", entryname);
    9.69 -        if (settings->recursive) {
    9.70 -          lineSum += scanDirectory(subdir, spaces+1, subdirname, settings);
    9.71 -        }
    9.72 -        closedir(subdir);
    9.73 -        continue;
    9.74 -      }
    9.75 -
    9.76 -      // Count lines
    9.77 -      lines = 0;
    9.78 -      char filename[(1+strlen(currdir)+strlen(entry->d_name))];
    9.79 -      strcpy(filename, currdir);
    9.80 -      strncat(filename, &settings->fileSeparator, 1);
    9.81 -      strcat(filename, entry->d_name);
    9.82 -      if (testSuffix(filename, settings)) {
    9.83 -        FILE *file = fopen(filename, "r");
    9.84 -        if (file == NULL) {
    9.85 -          perror("  File acces failed");
    9.86 -          continue;
    9.87 -        }
    9.88 -
    9.89 -        do {
    9.90 -          a = fgetc(file);
    9.91 -
    9.92 -          if (a == 10) {
    9.93 -            lines++;
    9.94 -          }
    9.95 -        } while (a != EOF);
    9.96 -        fclose(file);
    9.97 -
    9.98 -        // Print line count
    9.99 -        #ifdef _WIN32
   9.100 -          printf("%-60s%13d lines\n", entryname, lines);
   9.101 -        #else
   9.102 -          printf("%-60s%14d lines\n", entryname, lines);
   9.103 -        #endif /* _WIN32 */
   9.104 -
   9.105 -        lineSum += lines;
   9.106 -      }
   9.107 -      else {
   9.108 -        if (!settings->matchesOnly) {
   9.109 -          // Print hint
   9.110 -          #ifdef _WIN32
   9.111 -            printf("%-60s%19s\n", entryname, "no match");
   9.112 -          #else
   9.113 -            printf("%-60s%20s\n", entryname, "no match");
   9.114 -          #endif /* _WIN32 */
   9.115 -        }
   9.116 -      }
   9.117 -    }
   9.118 -  }
   9.119 -  return lineSum;
   9.120 -}
    10.1 --- a/functions.h	Mon May 30 08:45:08 2011 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,18 +0,0 @@
    10.4 -#ifndef _CLINE_FUNCTIONS_H
    10.5 -#define _CLINE_FUNCTIONS_H
    10.6 -
    10.7 -#ifdef _cplusplus
    10.8 -extern "C" {
    10.9 -#endif
   10.10 -
   10.11 -int checkArgument(const char*, const char*);
   10.12 -bool registerArgument(int*, int);
   10.13 -bool testSuffix(char* filename, settings_t* settings);
   10.14 -int scanDirectory(DIR *dir, const int spaces,
   10.15 -                  char* currdir, settings_t* settings);
   10.16 -
   10.17 -#ifdef _cplusplus
   10.18 -}
   10.19 -#endif 
   10.20 -                  
   10.21 -#endif /* _CLINE_FUNCTIONS_H */
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/scanner.c	Thu Sep 15 13:29:06 2011 +0200
    11.3 @@ -0,0 +1,88 @@
    11.4 +/*
    11.5 + * functions.c
    11.6 + *
    11.7 + *  Created on: 23.05.2011
    11.8 + *      Author: beckermi
    11.9 + */
   11.10 +
   11.11 +
   11.12 +#include "scanner.h"
   11.13 +#include "suffix_fnc.h"
   11.14 +
   11.15 +int scanDirectory(DIR *dir, const int spaces,
   11.16 +                  char* currdir, settings_t* settings) {
   11.17 +  DIR *subdir;
   11.18 +  char* subdirname;
   11.19 +  struct dirent *entry;
   11.20 +  int lines, digits, a;
   11.21 +  int lineSum = 0;
   11.22 +
   11.23 +  while ((entry = readdir(dir)) != NULL) {
   11.24 +    if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
   11.25 +      // Print occurence
   11.26 +      char entryname[strlen(entry->d_name)+spaces];
   11.27 +      for (int t = 0 ; t < spaces ; t++) {
   11.28 +        entryname[t]=' ';
   11.29 +      }
   11.30 +      entryname[spaces] = 0;
   11.31 +      strcat(entryname, entry->d_name);
   11.32 +  
   11.33 +      // Check for subdirectory
   11.34 +      char subdirname[(1+strlen(currdir)+strlen(entry->d_name))];
   11.35 +      strcpy(subdirname, currdir);
   11.36 +      strncat(subdirname, &settings->fileSeparator, 1);
   11.37 +      strcat(subdirname, entry->d_name);
   11.38 +      if ((subdir = opendir(subdirname)) != NULL) {
   11.39 +        printf("%-60s\n", entryname);
   11.40 +        if (settings->recursive) {
   11.41 +          lineSum += scanDirectory(subdir, spaces+1, subdirname, settings);
   11.42 +        }
   11.43 +        closedir(subdir);
   11.44 +        continue;
   11.45 +      }
   11.46 +
   11.47 +      // Count lines
   11.48 +      lines = 0;
   11.49 +      char filename[(1+strlen(currdir)+strlen(entry->d_name))];
   11.50 +      strcpy(filename, currdir);
   11.51 +      strncat(filename, &settings->fileSeparator, 1);
   11.52 +      strcat(filename, entry->d_name);
   11.53 +      if (testSuffix(filename, settings)) {
   11.54 +        FILE *file = fopen(filename, "r");
   11.55 +        if (file == NULL) {
   11.56 +          perror("  File acces failed");
   11.57 +          continue;
   11.58 +        }
   11.59 +
   11.60 +        do {
   11.61 +          a = fgetc(file);
   11.62 +
   11.63 +          if (a == 10) {
   11.64 +            lines++;
   11.65 +          }
   11.66 +        } while (a != EOF);
   11.67 +        fclose(file);
   11.68 +
   11.69 +        // Print line count
   11.70 +        #ifdef _WIN32
   11.71 +          printf("%-60s%13d lines\n", entryname, lines);
   11.72 +        #else
   11.73 +          printf("%-60s%14d lines\n", entryname, lines);
   11.74 +        #endif /* _WIN32 */
   11.75 +
   11.76 +        lineSum += lines;
   11.77 +      }
   11.78 +      else {
   11.79 +        if (!settings->matchesOnly) {
   11.80 +          // Print hint
   11.81 +          #ifdef _WIN32
   11.82 +            printf("%-60s%19s\n", entryname, "no match");
   11.83 +          #else
   11.84 +            printf("%-60s%20s\n", entryname, "no match");
   11.85 +          #endif /* _WIN32 */
   11.86 +        }
   11.87 +      }
   11.88 +    }
   11.89 +  }
   11.90 +  return lineSum;
   11.91 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/scanner.h	Thu Sep 15 13:29:06 2011 +0200
    12.3 @@ -0,0 +1,25 @@
    12.4 +/*
    12.5 + * functions.h
    12.6 + *
    12.7 + *  Created on: 23.05.2011
    12.8 + *      Author: beckermi
    12.9 + */
   12.10 +
   12.11 +#ifndef SCANNER_H_
   12.12 +#define SCANNER_H_
   12.13 +
   12.14 +#include "stdinc.h"
   12.15 +#include "settings.h"
   12.16 +
   12.17 +#ifdef _cplusplus
   12.18 +extern "C" {
   12.19 +#endif
   12.20 +
   12.21 +int scanDirectory(DIR *dir, const int spaces,
   12.22 +                  char* currdir, settings_t* settings);
   12.23 +
   12.24 +#ifdef _cplusplus
   12.25 +}
   12.26 +#endif 
   12.27 +                  
   12.28 +#endif /* SCANNER_H_ */
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/settings.c	Thu Sep 15 13:29:06 2011 +0200
    13.3 @@ -0,0 +1,30 @@
    13.4 +/*
    13.5 + * settings.c
    13.6 + *
    13.7 + *  Created on: 15.09.2011
    13.8 + *      Author: beckermi
    13.9 + */
   13.10 +
   13.11 +#include "settings.h"
   13.12 +
   13.13 +settings_t* new_settings_t() {
   13.14 +  settings_t *settings = malloc(sizeof(settings_t*));
   13.15 +  if (settings != NULL) {
   13.16 +  #ifdef _WIN32
   13.17 +    settings->fileSeparator      = '\\';
   13.18 +  #else
   13.19 +    settings->fileSeparator      = '/';
   13.20 +  #endif /* _WIN32 */
   13.21 +    settings->recursive          = false;
   13.22 +    settings->includeSuffixes    = false;
   13.23 +    settings->matchesOnly        = false;
   13.24 +    settings->suffixList         = new_suffix_list_t();
   13.25 +  }
   13.26 +
   13.27 +  return settings;
   13.28 +}
   13.29 +
   13.30 +void destroy_settings_t(settings_t* settings) {
   13.31 +  destroy_suffix_list_t(settings->suffixList);
   13.32 +  free(settings);
   13.33 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/settings.h	Thu Sep 15 13:29:06 2011 +0200
    14.3 @@ -0,0 +1,33 @@
    14.4 +/*
    14.5 + * settings.h
    14.6 + *
    14.7 + *  Created on: 15.09.2011
    14.8 + *      Author: beckermi
    14.9 + */
   14.10 +
   14.11 +#ifndef SETTINGS_H_
   14.12 +#define SETTINGS_H_
   14.13 +
   14.14 +#include "stdinc.h"
   14.15 +#include "suffix_list.h"
   14.16 +
   14.17 +typedef struct _settings {
   14.18 +  char fileSeparator;
   14.19 +  suffix_list_t* suffixList;
   14.20 +  bool recursive;
   14.21 +  bool includeSuffixes;
   14.22 +  bool matchesOnly;
   14.23 +} settings_t;
   14.24 +
   14.25 +#ifdef _cplusplus
   14.26 +extern "C" {
   14.27 +#endif
   14.28 +
   14.29 +settings_t* new_settings_t();
   14.30 +void destroy_settings_t(settings_t*);
   14.31 +
   14.32 +#ifdef _cplusplus
   14.33 +}
   14.34 +#endif
   14.35 +
   14.36 +#endif /* SETTINGS_H_ */
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/stdinc.h	Thu Sep 15 13:29:06 2011 +0200
    15.3 @@ -0,0 +1,17 @@
    15.4 +/*
    15.5 + * stdinc.h
    15.6 + *
    15.7 + *  Created on: 15.09.2011
    15.8 + *      Author: beckermi
    15.9 + */
   15.10 +
   15.11 +#ifndef STDINC_H_
   15.12 +#define STDINC_H_
   15.13 +
   15.14 +#include <stdio.h>
   15.15 +#include <string.h>
   15.16 +#include <stdbool.h>
   15.17 +#include <stdlib.h>
   15.18 +#include <dirent.h>
   15.19 +
   15.20 +#endif /* STDINC_H_ */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/suffix_fnc.c	Thu Sep 15 13:29:06 2011 +0200
    16.3 @@ -0,0 +1,25 @@
    16.4 +/*
    16.5 + * suffix_fnc.c
    16.6 + *
    16.7 + *  Created on: 15.09.2011
    16.8 + *      Author: beckermi
    16.9 + */
   16.10 +
   16.11 +#include "suffix_fnc.h"
   16.12 +
   16.13 +bool testSuffix(char* filename, settings_t* settings) {
   16.14 +  bool ret = false;
   16.15 +  int tokenlen, fnamelen = strlen(filename);
   16.16 +  for (int t = 0 ; t < settings->suffixList->count ; t++) {
   16.17 +    tokenlen = strlen(settings->suffixList->items[t]);
   16.18 +    if (fnamelen >= tokenlen && tokenlen > 0) {
   16.19 +      if (strncmp(filename+fnamelen-tokenlen,
   16.20 +                  settings->suffixList->items[t], tokenlen) == 0) {
   16.21 +        ret = true;
   16.22 +        break;
   16.23 +      }
   16.24 +    }
   16.25 +  }
   16.26 +  return ret ^ !settings->includeSuffixes;
   16.27 +}
   16.28 +
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/suffix_fnc.h	Thu Sep 15 13:29:06 2011 +0200
    17.3 @@ -0,0 +1,16 @@
    17.4 +/*
    17.5 + * suffix_fnc.h
    17.6 + *
    17.7 + *  Created on: 15.09.2011
    17.8 + *      Author: beckermi
    17.9 + */
   17.10 +
   17.11 +#ifndef SUFFIX_FNC_H_
   17.12 +#define SUFFIX_FNC_H_
   17.13 +
   17.14 +#include "stdinc.h"
   17.15 +#include "settings.h"
   17.16 +
   17.17 +bool testSuffix(char*, settings_t*);
   17.18 +
   17.19 +#endif /* SUFFIX_FNC_H_ */
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/suffix_list.c	Thu Sep 15 13:29:06 2011 +0200
    18.3 @@ -0,0 +1,34 @@
    18.4 +/*
    18.5 + * suffix_list.c
    18.6 + *
    18.7 + *  Created on: 15.09.2011
    18.8 + *      Author: beckermi
    18.9 + */
   18.10 +
   18.11 +#include "suffix_list.h"
   18.12 +
   18.13 +suffix_list_t* new_suffix_list_t() {
   18.14 +  suffix_list_t* suffixList = malloc(sizeof(suffix_list_t*));
   18.15 +  suffixList->count = 0;
   18.16 +  suffixList->items = NULL;
   18.17 +
   18.18 +  return suffixList;
   18.19 +}
   18.20 +
   18.21 +void destroy_suffix_list_t(suffix_list_t* list) {
   18.22 +  while (--list->count >= 0) {
   18.23 +    free(list->items[list->count]);
   18.24 +  }
   18.25 +  free(list);
   18.26 +}
   18.27 +
   18.28 +void add_suffix(suffix_list_t* list, char* item) {
   18.29 +  char** reallocated_list =
   18.30 +    realloc(list->items, sizeof(char**) * list->count + 1);
   18.31 +  if (reallocated_list != NULL) {
   18.32 +    list->items = reallocated_list;
   18.33 +    list->items[list->count] = item;
   18.34 +    list->count++;
   18.35 +  }
   18.36 +}
   18.37 +
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/suffix_list.h	Thu Sep 15 13:29:06 2011 +0200
    19.3 @@ -0,0 +1,30 @@
    19.4 +/*
    19.5 + * suffix_list.h
    19.6 + *
    19.7 + *  Created on: 15.09.2011
    19.8 + *      Author: beckermi
    19.9 + */
   19.10 +
   19.11 +#ifndef SUFFIX_LIST_H_
   19.12 +#define SUFFIX_LIST_H_
   19.13 +
   19.14 +#include "stdinc.h"
   19.15 +
   19.16 +typedef struct _suffix_list {
   19.17 +  int count;
   19.18 +  char** items;
   19.19 +} suffix_list_t;
   19.20 +
   19.21 +#ifdef _cplusplus
   19.22 +extern "C" {
   19.23 +#endif
   19.24 +
   19.25 +suffix_list_t* new_suffix_list_t();
   19.26 +void destroy_suffix_list_t(suffix_list_t*);
   19.27 +void add_suffix(suffix_list_t*, char*);
   19.28 +
   19.29 +#ifdef _cplusplus
   19.30 +}
   19.31 +#endif
   19.32 +
   19.33 +#endif /* SUFFIX_LIST_H_ */

mercurial