Fri, 28 Dec 2012 15:44:28 +0100
moved src files to src subdirectory and added licence text
1.1 --- a/.hgignore Tue Oct 02 10:49:25 2012 +0200 1.2 +++ b/.hgignore Fri Dec 28 15:44:28 2012 +0100 1.3 @@ -1,3 +1,8 @@ 1.4 syntax: regexp 1.5 ^build/.*$ 1.6 1.7 +\.orig\..*$ 1.8 +\.orig$ 1.9 +\.chg\..*$ 1.10 +\.rej$ 1.11 +\.conflict\~$
2.1 --- a/Makefile Tue Oct 02 10:49:25 2012 +0200 2.2 +++ b/Makefile Fri Dec 28 15:44:28 2012 +0100 2.3 @@ -38,6 +38,10 @@ 2.4 #endif 2.5 2.6 VERSION_PREFIX=1.0. 2.7 +SRCDIR=src/ 2.8 +BUILDDIR=build/ 2.9 +OBJ = $(shell ls ${SRCDIR} | grep '\.c' | sed 's/^\([^.]*\)\.c$$/${BUILDDIR:/=\/}\1.o/g' | tr '\n' ' ') 2.10 +BIN = ${BUILDDIR}cline 2.11 2.12 include ${CONF}.mk 2.13 2.14 @@ -52,17 +56,19 @@ 2.15 compile: ${OBJ} 2.16 ${LD} -o ${BIN} ${OBJ} ${LDFLAGS} 2.17 2.18 -setup: 2.19 - mkdir -p ${BUILDDIR} 2.20 +setup: ${BUILDDIR} 2.21 rm -f ${BUILDDIR}cline.o 2.22 - mv cline.h cline.src 2.23 - cat cline.src | sed "s/VERSION.*/VERSION=\"${VERSION_PREFIX}$(shell hg identify -n) ($(shell hg identify -i))\";/g" > cline.h 2.24 + mv ${SRCDIR}cline.h ${SRCDIR}cline.src 2.25 + cat ${SRCDIR}cline.src | sed "s/VERSION.*/VERSION=\"${VERSION_PREFIX}$(shell hg identify -n) ($(shell hg identify -i))\";/g" > ${SRCDIR}cline.h 2.26 + 2.27 +${BUILDDIR}: 2.28 + mkdir ${BUILDDIR} 2.29 2.30 teardown: 2.31 - rm -f cline.h 2.32 - mv cline.src cline.h 2.33 + rm -f ${SRCDIR}cline.h 2.34 + mv ${SRCDIR}cline.src ${SRCDIR}cline.h 2.35 2.36 -${BUILDDIR}%.o: %.c 2.37 +${BUILDDIR}%.o: ${SRCDIR}%.c 2.38 ${CC} ${CFLAGS} -c -o ${BUILDDIR}$*.o $< 2.39 2.40 clean:
3.1 --- a/arguments.c Tue Oct 02 10:49:25 2012 +0200 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,45 +0,0 @@ 3.4 -/* 3.5 - * arguments.c 3.6 - * 3.7 - * Created on: 15.09.2011 3.8 - * Author: Mike 3.9 - */ 3.10 - 3.11 -#include "arguments.h" 3.12 - 3.13 -int checkArgument(const char* arg, const char* expected) { 3.14 - int len = strlen(expected); 3.15 - int ret = 0; 3.16 - 3.17 - if (arg[0] == '-') { 3.18 - if (arg[1] != '-') { 3.19 - for (int t = 0 ; t < len ; t++) { 3.20 - ret |= (strchr(arg, expected[t]) > 0) << t; 3.21 - } 3.22 - } 3.23 - } 3.24 - 3.25 - return ret; 3.26 -} 3.27 - 3.28 -bool registerArgument(int* reg, int mask) { 3.29 - bool ret = (*reg & mask) > 0; 3.30 - *reg |= mask; 3.31 - return ret; 3.32 -} 3.33 - 3.34 -bool checkParamOpt(int* paropt) { 3.35 - bool ret = *paropt == 0; 3.36 - *paropt = 1; 3.37 - return ret; 3.38 -} 3.39 - 3.40 -void parseCSL(char* csl, string_list_t* list) { 3.41 - if (csl != NULL) { 3.42 - char* finder = strtok(csl, ","); 3.43 - while (finder != NULL) { 3.44 - add_string(list, finder); 3.45 - finder = strtok(NULL, ","); 3.46 - } 3.47 - } 3.48 -}
4.1 --- a/arguments.h Tue Oct 02 10:49:25 2012 +0200 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,27 +0,0 @@ 4.4 -/* 4.5 - * arguments.h 4.6 - * 4.7 - * Created on: 15.09.2011 4.8 - * Author: Mike 4.9 - */ 4.10 - 4.11 -#ifndef ARGUMENTS_H_ 4.12 -#define ARGUMENTS_H_ 4.13 - 4.14 -#include "stdinc.h" 4.15 -#include "string_list.h" 4.16 - 4.17 -#ifdef _cplusplus 4.18 -extern "C" { 4.19 -#endif 4.20 - 4.21 -int checkArgument(const char*, const char*); 4.22 -bool checkParamOpt(int*); 4.23 -bool registerArgument(int*, int); 4.24 -void parseCSL(char*, string_list_t*); 4.25 - 4.26 -#ifdef _cplusplus 4.27 -} 4.28 -#endif 4.29 - 4.30 -#endif /* ARGUMENTS_H_ */
5.1 --- a/bfile_heuristics.c Tue Oct 02 10:49:25 2012 +0200 5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 5.3 @@ -1,57 +0,0 @@ 5.4 -/* 5.5 - * bfile_heuristics.c 5.6 - * 5.7 - * Created on: 20.10.2011 5.8 - * Author: Mike 5.9 - */ 5.10 - 5.11 -#include "bfile_heuristics.h" 5.12 -#include <ctype.h> 5.13 - 5.14 -bfile_heuristics_t *new_bfile_heuristics_t() { 5.15 - bfile_heuristics_t *ret = malloc(sizeof(bfile_heuristics_t)); 5.16 - ret->level = BFILE_MEDIUM_ACCURACY; 5.17 - bfile_reset(ret); 5.18 - return ret; 5.19 -} 5.20 - 5.21 -void destroy_bfile_heuristics_t(bfile_heuristics_t *def) { 5.22 - free(def); 5.23 -} 5.24 - 5.25 -void bfile_reset(bfile_heuristics_t *def) { 5.26 - def->bcount = 0; 5.27 - def->tcount = 0; 5.28 -} 5.29 - 5.30 -bool bfile_check(bfile_heuristics_t *def, int next_char) { 5.31 - bool ret = false; 5.32 - if (def->level != BFILE_IGNORE) { 5.33 - def->tcount++; 5.34 - if (!isprint(next_char) && !isspace(next_char)) { 5.35 - def->bcount++; 5.36 - } 5.37 - 5.38 - if (def->tcount > 1) { /* empty files are text files */ 5.39 - switch (def->level) { 5.40 - case BFILE_LOW_ACCURACY: 5.41 - if (def->tcount > 15 || next_char == EOF) { 5.42 - ret = (1.0*def->bcount)/def->tcount > 0.32; 5.43 - } 5.44 - break; 5.45 - case BFILE_HIGH_ACCURACY: 5.46 - if (def->tcount > 500 || next_char == EOF) { 5.47 - ret = (1.0*def->bcount)/def->tcount > 0.1; 5.48 - } 5.49 - break; 5.50 - default: /* BFILE_MEDIUM_ACCURACY */ 5.51 - if (def->tcount > 100 || next_char == EOF) { 5.52 - ret = (1.0*def->bcount)/def->tcount > 0.1; 5.53 - } 5.54 - break; 5.55 - } 5.56 - } 5.57 - } 5.58 - 5.59 - return ret; 5.60 -}
6.1 --- a/bfile_heuristics.h Tue Oct 02 10:49:25 2012 +0200 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,37 +0,0 @@ 6.4 -/* 6.5 - * bfile_heuristics.h 6.6 - * 6.7 - * Created on: 20.10.2011 6.8 - * Author: Mike 6.9 - */ 6.10 - 6.11 -#ifndef BFILE_HEURISTICS_H_ 6.12 -#define BFILE_HEURISTICS_H_ 6.13 - 6.14 -#include "stdinc.h" 6.15 - 6.16 -#define BFILE_IGNORE 0x00 6.17 -#define BFILE_LOW_ACCURACY 0x01 6.18 -#define BFILE_MEDIUM_ACCURACY 0x02 6.19 -#define BFILE_HIGH_ACCURACY 0x04 6.20 - 6.21 -typedef struct { 6.22 - unsigned int level; 6.23 - unsigned int bcount; /* 'binary' character count */ 6.24 - unsigned int tcount; /* total count */ 6.25 -} bfile_heuristics_t; 6.26 - 6.27 -#ifdef _cplusplus 6.28 -extern "C" { 6.29 -#endif 6.30 - 6.31 -bfile_heuristics_t *new_bfile_heuristics_t(); 6.32 -void destroy_bfile_heuristics_t(bfile_heuristics_t *def); 6.33 -void bfile_reset(bfile_heuristics_t *def); 6.34 -bool bfile_check(bfile_heuristics_t *def, int next_char); 6.35 - 6.36 -#ifdef _cplusplus 6.37 -} 6.38 -#endif 6.39 - 6.40 -#endif /* BFILE_HEURISTICS_H_ */
7.1 --- a/cline.c Tue Oct 02 10:49:25 2012 +0200 7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 7.3 @@ -1,247 +0,0 @@ 7.4 -/* 7.5 - * cline.c 7.6 - * 7.7 - * Created on: 23.05.2011 7.8 - * Author: Mike 7.9 - */ 7.10 - 7.11 -#include "cline.h" 7.12 -#include "scanner.h" 7.13 -#include "settings.h" 7.14 -#include "arguments.h" 7.15 -#include "stream.h" 7.16 -#include "regex_parser.h" 7.17 - 7.18 -void printHelpText() { 7.19 - const char* helpText = 7.20 - "\nUsage:" 7.21 - "\n cline [Options] [Directories...]" 7.22 - "\n cline [Options] [Directories...]" 7.23 - "\n\nCounts the line terminator characters (\\n) within all" 7.24 - " files in the specified\ndirectories." 7.25 - "\n\nOptions:" 7.26 - "\n -b <level> - binary file heuristics level (default medium)" 7.27 - "\n One of: ignore low medium high" 7.28 - "\n -E <pattern> - Excludes any line matching the <pattern>" 7.29 - "\n -e <start> <end> - Excludes lines between <start> and <end>" 7.30 - "\n You may use these options multiple times" 7.31 - "\n -h, --help - this help text" 7.32 - "\n -m - print information about matching files only" 7.33 - "\n -s <suffixes> - only count files with these suffixes (separated" 7.34 - "\n by commas)" 7.35 - "\n -S <suffixes> - count any file except those with these suffixes" 7.36 - "\n (separated by commas)" 7.37 - "\n -r, -R - includes subdirectories" 7.38 - "\n -v, --version - print out version information" 7.39 - "\n -V - turn verbose output off, print the result only" 7.40 - "\n\nShortcuts:" 7.41 - "\n --exclude-cstyle-comments" 7.42 - "\n = -E \"\\s*//\" -e \"\\s*/\\*\" \"\\*/\\s*\"" 7.43 - "\n\n" 7.44 - "The default call without any options is:" 7.45 - "\n cline ./\n\n" 7.46 - "So each file in the working directory is counted. If you want to count C" 7.47 - "\nsource code in your working directory and its subdirectories, type:" 7.48 - "\n cline -rs .c\n" 7.49 - "\nIf you want to exclude comment lines, you may use the -e/-E option." 7.50 - "\nAfter a line matches the regex pattern <start> any following line is" 7.51 - "\nnot counted unless a line matches the <end> pattern. A line is still " 7.52 - "\ncounted when it does not start or end with the respective patterns." 7.53 - "\nPlease note, that cline does not remove whitespace characters as this" 7.54 - "\nmight not be reasonable in some cases." 7.55 - "\n\nExample (C without comments):" 7.56 - "\n cline -s .c,.h --exclude-cstyle-comments"; 7.57 - 7.58 - printf(helpText); 7.59 -} 7.60 - 7.61 -int exit_with_version(settings_t* settings) { 7.62 - printf("cline - Revision: %s\n", VERSION); 7.63 - destroy_settings_t(settings); 7.64 - return 0; 7.65 -} 7.66 - 7.67 -int exit_with_help(settings_t* settings, int code) { 7.68 - printHelpText(); 7.69 - destroy_settings_t(settings); 7.70 - return code; 7.71 -} 7.72 - 7.73 -int main(int argc, char** argv) { 7.74 - 7.75 - /* Settings */ 7.76 - settings_t *settings = new_settings_t(); 7.77 - if (settings == NULL) { 7.78 - fprintf(stderr, "Memory allocation failed.\n"); 7.79 - return 1; 7.80 - } 7.81 - 7.82 - /* Get arguments */ 7.83 - string_list_t *directories = new_string_list_t(); 7.84 - if (directories == NULL) { 7.85 - fprintf(stderr, "Memory allocation failed.\n"); 7.86 - return 1; 7.87 - } 7.88 - char* includeSuffix = NULL; 7.89 - char* excludeSuffix = NULL; 7.90 - int checked = 0; 7.91 - 7.92 - for (int t = 1 ; t < argc ; t++) { 7.93 - 7.94 - int argflags = checkArgument(argv[t], "hsSrRmvVbeE"); 7.95 - int paropt = 0; 7.96 - 7.97 - /* s */ 7.98 - if ((argflags & 2) > 0) { 7.99 - if (!checkParamOpt(&paropt) || registerArgument(&checked, 2)) { 7.100 - return exit_with_help(settings, 1); 7.101 - } 7.102 - t++; 7.103 - if (t >= argc) { 7.104 - return exit_with_help(settings, 1); 7.105 - } 7.106 - includeSuffix = argv[t]; 7.107 - } 7.108 - /* S */ 7.109 - if ((argflags & 4) > 0) { 7.110 - if (!checkParamOpt(&paropt) || registerArgument(&checked, 4)) { 7.111 - return exit_with_help(settings, 1); 7.112 - } 7.113 - t++; 7.114 - if (t >= argc) { 7.115 - return exit_with_help(settings, 1); 7.116 - } 7.117 - excludeSuffix = argv[t]; 7.118 - } 7.119 - /* h */ 7.120 - if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { 7.121 - return exit_with_help(settings, 0); 7.122 - } 7.123 - /* r, R */ 7.124 - if ((argflags & 24) > 0) { 7.125 - if (registerArgument(&checked, 24)) { 7.126 - return exit_with_help(settings, 1); 7.127 - } 7.128 - settings->recursive = true; 7.129 - } 7.130 - /* m */ 7.131 - if ((argflags & 32) > 0) { 7.132 - if (registerArgument(&checked, 32)) { 7.133 - return exit_with_help(settings, 1); 7.134 - } 7.135 - settings->matchesOnly = true; 7.136 - } 7.137 - /* v */ 7.138 - if ((argflags & 64) > 0 || strcmp(argv[t], "--version") == 0) { 7.139 - return exit_with_version(settings); 7.140 - } 7.141 - /* V */ 7.142 - if ((argflags & 128) > 0) { 7.143 - if (registerArgument(&checked, 128)) { 7.144 - return exit_with_help(settings, 1); 7.145 - } 7.146 - settings->verbose = false; 7.147 - } 7.148 - /* b */ 7.149 - if ((argflags & 256) > 0) { 7.150 - if (!checkParamOpt(&paropt) || registerArgument(&checked, 256)) { 7.151 - return exit_with_help(settings, 1); 7.152 - } 7.153 - t++; 7.154 - if (t >= argc) { 7.155 - return exit_with_help(settings, 1); 7.156 - } 7.157 - if (strcasecmp(argv[t], "ignore") == 0) { 7.158 - settings->bfileHeuristics->level = BFILE_IGNORE; 7.159 - } else if (strcasecmp(argv[t], "low") == 0) { 7.160 - settings->bfileHeuristics->level = BFILE_LOW_ACCURACY; 7.161 - } else if (strcasecmp(argv[t], "medium") == 0) { 7.162 - settings->bfileHeuristics->level = BFILE_MEDIUM_ACCURACY; 7.163 - } else if (strcasecmp(argv[t], "high") == 0) { 7.164 - settings->bfileHeuristics->level = BFILE_HIGH_ACCURACY; 7.165 - } else { 7.166 - return exit_with_help(settings, 1); 7.167 - } 7.168 - } 7.169 - /* e */ 7.170 - if ((argflags & 512) > 0) { 7.171 - if (!checkParamOpt(&paropt) || t + 2 >= argc) { 7.172 - return exit_with_help(settings, 1); 7.173 - } 7.174 - t++; add_string(settings->regex->pattern_list, argv[t]); 7.175 - t++; add_string(settings->regex->pattern_list, argv[t]); 7.176 - } 7.177 - /* E */ 7.178 - if ((argflags & 1024) > 0) { 7.179 - t++; 7.180 - if (!checkParamOpt(&paropt) || t >= argc) { 7.181 - return exit_with_help(settings, 1); 7.182 - } 7.183 - add_string(settings->regex->pattern_list, argv[t]); 7.184 - add_string(settings->regex->pattern_list, "$"); 7.185 - } 7.186 - if (argflags == 0) { 7.187 - /* SHORTCUTS */ 7.188 - /* exclude-cstyle-comments */ 7.189 - if (strcmp(argv[t], "--exclude-cstyle-comments") == 0) { 7.190 - add_string(settings->regex->pattern_list, "\\s*//"); 7.191 - add_string(settings->regex->pattern_list, "$"); 7.192 - add_string(settings->regex->pattern_list, "\\s*/\\*"); 7.193 - add_string(settings->regex->pattern_list, "\\*/\\s*"); 7.194 - } 7.195 - /* Path */ 7.196 - else { 7.197 - add_string(directories, argv[t]); 7.198 - } 7.199 - } 7.200 - } 7.201 - 7.202 - /* Configure output */ 7.203 - if (!settings->verbose) { 7.204 - close_stdout(); 7.205 - } 7.206 - 7.207 - /* Find tokens */ 7.208 - parseCSL(includeSuffix, settings->includeSuffixes); 7.209 - parseCSL(excludeSuffix, settings->excludeSuffixes); 7.210 - 7.211 - /* Scan directories */ 7.212 - if (regex_compile_all(settings->regex)) { 7.213 - int lines = 0; 7.214 - if (directories->count == 0) { 7.215 - add_string(directories, "."); 7.216 - } 7.217 - for (int t = 0 ; t < directories->count ; t++) { 7.218 - if (t > 0) { 7.219 - for (int u = 0 ; u < 79 ; u++) { 7.220 - printf("-"); 7.221 - } 7.222 - printf("\n"); 7.223 - } 7.224 - lines += scanDirectory((scanner_t){directories->items[t], 0}, settings); 7.225 - } 7.226 - destroy_string_list_t(directories); 7.227 - 7.228 - /* Print double line and line count */ 7.229 - for (int t = 0 ; t < 79 ; t++) { 7.230 - printf("="); 7.231 - } 7.232 - printf("\n%73d lines\n", lines); 7.233 - 7.234 - if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) { 7.235 - printf("\nSome files contain too long lines.\n" 7.236 - "The regex parser currently supports a maximum line length of %d." 7.237 - "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); 7.238 - } 7.239 - 7.240 - if (!settings->verbose) { 7.241 - reopen_stdout(); 7.242 - printf("%d", lines); 7.243 - } 7.244 - destroy_settings_t(settings); 7.245 - } 7.246 - 7.247 - fflush(stdout); 7.248 - fflush(stderr); 7.249 - return 0; 7.250 -}
8.1 --- a/cline.h Tue Oct 02 10:49:25 2012 +0200 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,28 +0,0 @@ 8.4 -/* 8.5 - * cline.h 8.6 - * 8.7 - * Created on: 23.05.2011 8.8 - * Author: Mike 8.9 - */ 8.10 - 8.11 -#ifndef CLINE_H_ 8.12 -#define CLINE_H_ 8.13 - 8.14 -const char* VERSION=""; /* will be replaced by makefile */ 8.15 - 8.16 -#include "stdinc.h" 8.17 -#include "settings.h" 8.18 - 8.19 -#ifdef _cplusplus 8.20 -extern "C" { 8.21 -#endif 8.22 - 8.23 -void printHelpText(); 8.24 -int exit_with_version(settings_t*); 8.25 -int exit_with_help(settings_t*, int); 8.26 - 8.27 -#ifdef _cplusplus 8.28 -} 8.29 -#endif 8.30 - 8.31 -#endif /* CLINE_H_ */
9.1 --- a/gcc-debug.mk Tue Oct 02 10:49:25 2012 +0200 9.2 +++ b/gcc-debug.mk Fri Dec 28 15:44:28 2012 +0100 9.3 @@ -1,34 +1,31 @@ 9.4 -# 9.5 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 9.6 -# 9.7 -# Copyright 2011 Mike Becker. All rights reserved. 9.8 -# 9.9 -# Redistribution and use in source and binary forms, with or without 9.10 -# modification, are permitted provided that the following conditions are met: 9.11 -# 9.12 -# 1. Redistributions of source code must retain the above copyright 9.13 -# notice, this list of conditions and the following disclaimer. 9.14 -# 9.15 -# 2. Redistributions in binary form must reproduce the above copyright 9.16 -# notice, this list of conditions and the following disclaimer in the 9.17 -# documentation and/or other materials provided with the distribution. 9.18 -# 9.19 -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 9.20 -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 9.21 -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 9.22 -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 9.23 -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 9.24 -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 9.25 -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 9.26 -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 9.27 -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 9.28 -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 9.29 -# 9.30 - 9.31 -CC = gcc 9.32 -LD = gcc 9.33 -CFLAGS = -Wall -std=gnu99 -O0 -ggdb 9.34 -LDFLAGS = 9.35 -BUILDDIR = build/ 9.36 -OBJ = $(shell ls | grep '\.c' | sed 's/^\([^.]*\)\.c$$/${BUILDDIR:/=\/}\1.o/g' | tr '\n' ' ') 9.37 -BIN = ${BUILDDIR}cline 9.38 +# 9.39 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 9.40 +# 9.41 +# Copyright 2011 Mike Becker. All rights reserved. 9.42 +# 9.43 +# Redistribution and use in source and binary forms, with or without 9.44 +# modification, are permitted provided that the following conditions are met: 9.45 +# 9.46 +# 1. Redistributions of source code must retain the above copyright 9.47 +# notice, this list of conditions and the following disclaimer. 9.48 +# 9.49 +# 2. Redistributions in binary form must reproduce the above copyright 9.50 +# notice, this list of conditions and the following disclaimer in the 9.51 +# documentation and/or other materials provided with the distribution. 9.52 +# 9.53 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 9.54 +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 9.55 +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 9.56 +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 9.57 +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 9.58 +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 9.59 +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 9.60 +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 9.61 +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 9.62 +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 9.63 +# 9.64 + 9.65 +CC = gcc 9.66 +LD = gcc 9.67 +CFLAGS = -Wall -std=gnu99 -O0 -ggdb 9.68 +LDFLAGS =
10.1 --- a/gcc.mk Tue Oct 02 10:49:25 2012 +0200 10.2 +++ b/gcc.mk Fri Dec 28 15:44:28 2012 +0100 10.3 @@ -1,34 +1,31 @@ 10.4 -# 10.5 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 10.6 -# 10.7 -# Copyright 2011 Mike Becker. All rights reserved. 10.8 -# 10.9 -# Redistribution and use in source and binary forms, with or without 10.10 -# modification, are permitted provided that the following conditions are met: 10.11 -# 10.12 -# 1. Redistributions of source code must retain the above copyright 10.13 -# notice, this list of conditions and the following disclaimer. 10.14 -# 10.15 -# 2. Redistributions in binary form must reproduce the above copyright 10.16 -# notice, this list of conditions and the following disclaimer in the 10.17 -# documentation and/or other materials provided with the distribution. 10.18 -# 10.19 -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 10.20 -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 10.21 -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 10.22 -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 10.23 -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 10.24 -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 10.25 -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 10.26 -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 10.27 -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 10.28 -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10.29 -# 10.30 - 10.31 -CC = gcc 10.32 -LD = gcc 10.33 -CFLAGS = -Wall -std=gnu99 -O 10.34 -LDFLAGS = 10.35 -BUILDDIR = build/ 10.36 -OBJ = $(shell ls | grep '\.c' | sed 's/^\([^.]*\)\.c$$/${BUILDDIR:/=\/}\1.o/g' | tr '\n' ' ') 10.37 -BIN = ${BUILDDIR}cline 10.38 +# 10.39 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 10.40 +# 10.41 +# Copyright 2011 Mike Becker. All rights reserved. 10.42 +# 10.43 +# Redistribution and use in source and binary forms, with or without 10.44 +# modification, are permitted provided that the following conditions are met: 10.45 +# 10.46 +# 1. Redistributions of source code must retain the above copyright 10.47 +# notice, this list of conditions and the following disclaimer. 10.48 +# 10.49 +# 2. Redistributions in binary form must reproduce the above copyright 10.50 +# notice, this list of conditions and the following disclaimer in the 10.51 +# documentation and/or other materials provided with the distribution. 10.52 +# 10.53 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 10.54 +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 10.55 +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 10.56 +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 10.57 +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 10.58 +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 10.59 +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 10.60 +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 10.61 +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 10.62 +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10.63 +# 10.64 + 10.65 +CC = gcc 10.66 +LD = gcc 10.67 +CFLAGS = -Wall -std=gnu99 -O 10.68 +LDFLAGS =
11.1 --- a/mingw-debug.mk Tue Oct 02 10:49:25 2012 +0200 11.2 +++ b/mingw-debug.mk Fri Dec 28 15:44:28 2012 +0100 11.3 @@ -1,34 +1,31 @@ 11.4 -# 11.5 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 11.6 -# 11.7 -# Copyright 2011 Mike Becker. All rights reserved. 11.8 -# 11.9 -# Redistribution and use in source and binary forms, with or without 11.10 -# modification, are permitted provided that the following conditions are met: 11.11 -# 11.12 -# 1. Redistributions of source code must retain the above copyright 11.13 -# notice, this list of conditions and the following disclaimer. 11.14 -# 11.15 -# 2. Redistributions in binary form must reproduce the above copyright 11.16 -# notice, this list of conditions and the following disclaimer in the 11.17 -# documentation and/or other materials provided with the distribution. 11.18 -# 11.19 -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 11.20 -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 11.21 -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 11.22 -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 11.23 -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 11.24 -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 11.25 -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 11.26 -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 11.27 -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 11.28 -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11.29 -# 11.30 - 11.31 -CC = gcc 11.32 -LD = gcc 11.33 -CFLAGS = -Wall -std=gnu99 -O0 -g 11.34 -LDFLAGS = -static -lregex 11.35 -BUILDDIR = build/ 11.36 -OBJ = $(shell ls | grep '\.c' | sed 's/^\([^.]*\)\.c$$/${BUILDDIR:/=\/}\1.o/g' | tr '\n' ' ') 11.37 -BIN = ${BUILDDIR}cline 11.38 +# 11.39 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 11.40 +# 11.41 +# Copyright 2011 Mike Becker. All rights reserved. 11.42 +# 11.43 +# Redistribution and use in source and binary forms, with or without 11.44 +# modification, are permitted provided that the following conditions are met: 11.45 +# 11.46 +# 1. Redistributions of source code must retain the above copyright 11.47 +# notice, this list of conditions and the following disclaimer. 11.48 +# 11.49 +# 2. Redistributions in binary form must reproduce the above copyright 11.50 +# notice, this list of conditions and the following disclaimer in the 11.51 +# documentation and/or other materials provided with the distribution. 11.52 +# 11.53 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 11.54 +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 11.55 +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 11.56 +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 11.57 +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 11.58 +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 11.59 +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 11.60 +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 11.61 +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 11.62 +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11.63 +# 11.64 + 11.65 +CC = gcc 11.66 +LD = gcc 11.67 +CFLAGS = -Wall -std=gnu99 -O0 -g 11.68 +LDFLAGS = -static -lregex
12.1 --- a/mingw.mk Tue Oct 02 10:49:25 2012 +0200 12.2 +++ b/mingw.mk Fri Dec 28 15:44:28 2012 +0100 12.3 @@ -1,34 +1,31 @@ 12.4 -# 12.5 -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 12.6 -# 12.7 -# Copyright 2011 Mike Becker. All rights reserved. 12.8 -# 12.9 -# Redistribution and use in source and binary forms, with or without 12.10 -# modification, are permitted provided that the following conditions are met: 12.11 -# 12.12 -# 1. Redistributions of source code must retain the above copyright 12.13 -# notice, this list of conditions and the following disclaimer. 12.14 -# 12.15 -# 2. Redistributions in binary form must reproduce the above copyright 12.16 -# notice, this list of conditions and the following disclaimer in the 12.17 -# documentation and/or other materials provided with the distribution. 12.18 -# 12.19 -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12.20 -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 12.21 -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 12.22 -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 12.23 -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 12.24 -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 12.25 -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 12.26 -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 12.27 -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 12.28 -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12.29 -# 12.30 - 12.31 -CC = gcc 12.32 -LD = gcc 12.33 -CFLAGS = -Wall -std=gnu99 -O 12.34 -LDFLAGS = -static -lregex 12.35 -BUILDDIR = build/ 12.36 -OBJ = $(shell ls | grep '\.c' | sed 's/^\([^.]*\)\.c$$/${BUILDDIR:/=\/}\1.o/g' | tr '\n' ' ') 12.37 -BIN = ${BUILDDIR}cline 12.38 +# 12.39 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 12.40 +# 12.41 +# Copyright 2011 Mike Becker. All rights reserved. 12.42 +# 12.43 +# Redistribution and use in source and binary forms, with or without 12.44 +# modification, are permitted provided that the following conditions are met: 12.45 +# 12.46 +# 1. Redistributions of source code must retain the above copyright 12.47 +# notice, this list of conditions and the following disclaimer. 12.48 +# 12.49 +# 2. Redistributions in binary form must reproduce the above copyright 12.50 +# notice, this list of conditions and the following disclaimer in the 12.51 +# documentation and/or other materials provided with the distribution. 12.52 +# 12.53 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12.54 +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 12.55 +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 12.56 +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 12.57 +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 12.58 +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 12.59 +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 12.60 +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 12.61 +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 12.62 +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12.63 +# 12.64 + 12.65 +CC = gcc 12.66 +LD = gcc 12.67 +CFLAGS = -Wall -std=gnu99 -O 12.68 +LDFLAGS = -static -lregex
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/nbproject/Package-Default.bash Fri Dec 28 15:44:28 2012 +0100 13.3 @@ -0,0 +1,75 @@ 13.4 +#!/bin/bash -x 13.5 + 13.6 +# 13.7 +# Generated - do not edit! 13.8 +# 13.9 + 13.10 +# Macros 13.11 +TOP=`pwd` 13.12 +CND_PLATFORM=GNU-Linux-x86 13.13 +CND_CONF=Default 13.14 +CND_DISTDIR=dist 13.15 +CND_BUILDDIR=build 13.16 +NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging 13.17 +TMPDIRNAME=tmp-packaging 13.18 +OUTPUT_PATH=MissingOutputInProject 13.19 +OUTPUT_BASENAME=MissingOutputInProject 13.20 +PACKAGE_TOP_DIR=cline/ 13.21 + 13.22 +# Functions 13.23 +function checkReturnCode 13.24 +{ 13.25 + rc=$? 13.26 + if [ $rc != 0 ] 13.27 + then 13.28 + exit $rc 13.29 + fi 13.30 +} 13.31 +function makeDirectory 13.32 +# $1 directory path 13.33 +# $2 permission (optional) 13.34 +{ 13.35 + mkdir -p "$1" 13.36 + checkReturnCode 13.37 + if [ "$2" != "" ] 13.38 + then 13.39 + chmod $2 "$1" 13.40 + checkReturnCode 13.41 + fi 13.42 +} 13.43 +function copyFileToTmpDir 13.44 +# $1 from-file path 13.45 +# $2 to-file path 13.46 +# $3 permission 13.47 +{ 13.48 + cp "$1" "$2" 13.49 + checkReturnCode 13.50 + if [ "$3" != "" ] 13.51 + then 13.52 + chmod $3 "$2" 13.53 + checkReturnCode 13.54 + fi 13.55 +} 13.56 + 13.57 +# Setup 13.58 +cd "${TOP}" 13.59 +mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package 13.60 +rm -rf ${NBTMPDIR} 13.61 +mkdir -p ${NBTMPDIR} 13.62 + 13.63 +# Copy files and create directories and links 13.64 +cd "${TOP}" 13.65 +makeDirectory "${NBTMPDIR}/cline" 13.66 +copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 13.67 + 13.68 + 13.69 +# Generate tar file 13.70 +cd "${TOP}" 13.71 +rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/cline.tar 13.72 +cd ${NBTMPDIR} 13.73 +tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/cline.tar * 13.74 +checkReturnCode 13.75 + 13.76 +# Cleanup 13.77 +cd "${TOP}" 13.78 +rm -rf ${NBTMPDIR}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/nbproject/configurations.xml Fri Dec 28 15:44:28 2012 +0100 14.3 @@ -0,0 +1,57 @@ 14.4 +<?xml version="1.0" encoding="UTF-8"?> 14.5 +<configurationDescriptor version="84"> 14.6 + <logicalFolder name="root" displayName="root" projectFiles="true" kind="ROOT"> 14.7 + <df name="cline" root="."> 14.8 + <df name="build"> 14.9 + </df> 14.10 + <in>arguments.c</in> 14.11 + <in>arguments.h</in> 14.12 + <in>bfile_heuristics.c</in> 14.13 + <in>bfile_heuristics.h</in> 14.14 + <in>cline.c</in> 14.15 + <in>cline.h</in> 14.16 + <in>regex_parser.c</in> 14.17 + <in>regex_parser.h</in> 14.18 + <in>scanner.c</in> 14.19 + <in>scanner.h</in> 14.20 + <in>settings.c</in> 14.21 + <in>settings.h</in> 14.22 + <in>stdinc.h</in> 14.23 + <in>stream.c</in> 14.24 + <in>stream.h</in> 14.25 + <in>string_list.c</in> 14.26 + <in>string_list.h</in> 14.27 + <in>suffix_fnc.c</in> 14.28 + <in>suffix_fnc.h</in> 14.29 + </df> 14.30 + <logicalFolder name="ExternalFiles" 14.31 + displayName="Important Files" 14.32 + projectFiles="false" 14.33 + kind="IMPORTANT_FILES_FOLDER"> 14.34 + <itemPath>Makefile</itemPath> 14.35 + </logicalFolder> 14.36 + </logicalFolder> 14.37 + <sourceFolderFilter>^(nbproject)$</sourceFolderFilter> 14.38 + <sourceRootList> 14.39 + <Elem>.</Elem> 14.40 + </sourceRootList> 14.41 + <projectmakefile>Makefile</projectmakefile> 14.42 + <confs> 14.43 + <conf name="Default" type="0"> 14.44 + <toolsSet> 14.45 + <remote-sources-mode>LOCAL_SOURCES</remote-sources-mode> 14.46 + <compilerSet>default</compilerSet> 14.47 + </toolsSet> 14.48 + <codeAssistance> 14.49 + </codeAssistance> 14.50 + <makefileType> 14.51 + <makeTool> 14.52 + <buildCommandWorkingDir>.</buildCommandWorkingDir> 14.53 + <buildCommand>${MAKE} -f Makefile</buildCommand> 14.54 + <cleanCommand>${MAKE} -f Makefile clean</cleanCommand> 14.55 + <executablePath></executablePath> 14.56 + </makeTool> 14.57 + </makefileType> 14.58 + </conf> 14.59 + </confs> 14.60 +</configurationDescriptor>
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/nbproject/private/Default.properties Fri Dec 28 15:44:28 2012 +0100 15.3 @@ -0,0 +1,9 @@ 15.4 +/home/mike/workspace/c/cline/bfile_heuristics.c=/home/mike/workspace/c/cline#-Wall -std=gnu99 -O -c -o build/bfile_heuristics.o bfile_heuristics.c 15.5 +/home/mike/workspace/c/cline/suffix_fnc.c=/home/mike/workspace/c/cline#-Wall -std=gnu99 -O -c -o build/suffix_fnc.o suffix_fnc.c 15.6 +/home/mike/workspace/c/cline/regex_parser.c=/home/mike/workspace/c/cline#-Wall -std=gnu99 -O -c -o build/regex_parser.o regex_parser.c 15.7 +/home/mike/workspace/c/cline/stream.c=/home/mike/workspace/c/cline#-Wall -std=gnu99 -O -c -o build/stream.o stream.c 15.8 +/home/mike/workspace/c/cline/settings.c=/home/mike/workspace/c/cline#-Wall -std=gnu99 -O -c -o build/settings.o settings.c 15.9 +/home/mike/workspace/c/cline/scanner.c=/home/mike/workspace/c/cline#-Wall -std=gnu99 -O -c -o build/scanner.o scanner.c 15.10 +/home/mike/workspace/c/cline/arguments.c=/home/mike/workspace/c/cline#-Wall -std=gnu99 -O -c -o build/arguments.o arguments.c 15.11 +/home/mike/workspace/c/cline/cline.c=/home/mike/workspace/c/cline#-Wall -std=gnu99 -O -c -o build/cline.o cline.c 15.12 +/home/mike/workspace/c/cline/string_list.c=/home/mike/workspace/c/cline#-Wall -std=gnu99 -O -c -o build/string_list.o string_list.c
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/nbproject/private/configurations.xml Fri Dec 28 15:44:28 2012 +0100 16.3 @@ -0,0 +1,39 @@ 16.4 +<?xml version="1.0" encoding="UTF-8"?> 16.5 +<configurationDescriptor version="84"> 16.6 + <projectmakefile>Makefile</projectmakefile> 16.7 + <confs> 16.8 + <conf name="Default" type="0"> 16.9 + <toolsSet> 16.10 + <developmentServer>localhost</developmentServer> 16.11 + <platform>2</platform> 16.12 + </toolsSet> 16.13 + <dbx_gdbdebugger version="1"> 16.14 + <gdb_pathmaps> 16.15 + </gdb_pathmaps> 16.16 + <gdb_interceptlist> 16.17 + <gdbinterceptoptions gdb_all="false" gdb_unhandled="true" gdb_unexpected="true"/> 16.18 + </gdb_interceptlist> 16.19 + <gdb_options> 16.20 + <DebugOptions> 16.21 + </DebugOptions> 16.22 + </gdb_options> 16.23 + <gdb_buildfirst gdb_buildfirst_overriden="false" gdb_buildfirst_old="false"/> 16.24 + </dbx_gdbdebugger> 16.25 + <nativedebugger version="1"> 16.26 + <engine>gdb</engine> 16.27 + </nativedebugger> 16.28 + <runprofile version="9"> 16.29 + <runcommandpicklist> 16.30 + <runcommandpicklistitem>"${OUTPUT_PATH}"</runcommandpicklistitem> 16.31 + </runcommandpicklist> 16.32 + <runcommand>"${OUTPUT_PATH}"</runcommand> 16.33 + <rundir>.</rundir> 16.34 + <buildfirst>true</buildfirst> 16.35 + <terminal-type>0</terminal-type> 16.36 + <remove-instrumentation>0</remove-instrumentation> 16.37 + <environment> 16.38 + </environment> 16.39 + </runprofile> 16.40 + </conf> 16.41 + </confs> 16.42 +</configurationDescriptor>
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/nbproject/private/private.xml Fri Dec 28 15:44:28 2012 +0100 17.3 @@ -0,0 +1,10 @@ 17.4 +<?xml version="1.0" encoding="UTF-8"?> 17.5 +<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> 17.6 + <code-assistance-data xmlns="http://www.netbeans.org/ns/make-project-private/1"> 17.7 + <code-model-enabled>true</code-model-enabled> 17.8 + </code-assistance-data> 17.9 + <data xmlns="http://www.netbeans.org/ns/make-project-private/1"> 17.10 + <activeConfTypeElem>0</activeConfTypeElem> 17.11 + <activeConfIndexElem>0</activeConfIndexElem> 17.12 + </data> 17.13 +</project-private>
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/nbproject/project.xml Fri Dec 28 15:44:28 2012 +0100 18.3 @@ -0,0 +1,23 @@ 18.4 +<?xml version="1.0" encoding="UTF-8"?> 18.5 +<project xmlns="http://www.netbeans.org/ns/project/1"> 18.6 + <type>org.netbeans.modules.cnd.makeproject</type> 18.7 + <configuration> 18.8 + <data xmlns="http://www.netbeans.org/ns/make-project/1"> 18.9 + <name>cline</name> 18.10 + <c-extensions>c</c-extensions> 18.11 + <cpp-extensions/> 18.12 + <header-extensions>h</header-extensions> 18.13 + <sourceEncoding>UTF-8</sourceEncoding> 18.14 + <make-dep-projects/> 18.15 + <sourceRootList> 18.16 + <sourceRootElem>.</sourceRootElem> 18.17 + </sourceRootList> 18.18 + <confList> 18.19 + <confElem> 18.20 + <name>Default</name> 18.21 + <type>0</type> 18.22 + </confElem> 18.23 + </confList> 18.24 + </data> 18.25 + </configuration> 18.26 +</project>
19.1 --- a/regex_parser.c Tue Oct 02 10:49:25 2012 +0200 19.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 19.3 @@ -1,110 +0,0 @@ 19.4 -/* 19.5 - * regex_parser.c 19.6 - * 19.7 - * Created on: 26.01.2012 19.8 - * Author: Mike 19.9 - */ 19.10 - 19.11 -#include "regex_parser.h" 19.12 - 19.13 -regex_parser_t* new_regex_parser_t() { 19.14 - regex_parser_t* ret = malloc(sizeof(regex_parser_t)); 19.15 - if (ret != NULL) { 19.16 - ret->pattern_list = new_string_list_t(); 19.17 - ret->matched_lines = 0; 19.18 - ret->pattern_match = 0; 19.19 - ret->compiled_patterns = NULL; 19.20 - ret->compiled_pattern_count = 0; 19.21 - } 19.22 - return ret; 19.23 -} 19.24 - 19.25 -void regex_destcomppats(regex_parser_t* parser) { 19.26 - if (parser->compiled_patterns != NULL) { 19.27 - for (int i = 0 ; i < parser->compiled_pattern_count ; i++) { 19.28 - if (parser->compiled_patterns[i] != NULL) { 19.29 - free(parser->compiled_patterns[i]); 19.30 - } 19.31 - } 19.32 - free(parser->compiled_patterns); 19.33 - parser->compiled_patterns = NULL; 19.34 - parser->compiled_pattern_count = 0; 19.35 - } 19.36 -} 19.37 - 19.38 -void destroy_regex_parser_t(regex_parser_t* parser) { 19.39 - regex_destcomppats(parser); 19.40 - destroy_string_list_t(parser->pattern_list); 19.41 - free(parser); 19.42 -} 19.43 - 19.44 -bool regex_parser_matching(regex_parser_t* parser) { 19.45 - return parser->pattern_match > 0; 19.46 -} 19.47 - 19.48 -int regex_parser_do(regex_parser_t* parser, char* input) { 19.49 - int err = REG_NOMATCH; 19.50 - if (parser->compiled_pattern_count > 0) { 19.51 - regmatch_t match; 19.52 - 19.53 - if (regex_parser_matching(parser)) { 19.54 - parser->matched_lines++; 19.55 - 19.56 - err = regexec(parser->compiled_patterns[parser->pattern_match], 19.57 - input, 1, &match, 0); 19.58 - if (err > 0 && err != REG_NOMATCH) { 19.59 - fprintf(stderr, "Regex-Error: 0x%08x", err); 19.60 - } 19.61 - if (err == 0) { 19.62 - parser->pattern_match = 0; 19.63 - /* do not match line, if it does not end with the pattern */ 19.64 - if (match.rm_eo < strlen(input)) { 19.65 - parser->matched_lines--; 19.66 - } 19.67 - } 19.68 - } else { 19.69 - for (int i = 0 ; i < parser->compiled_pattern_count - 1 ; i += 2) { 19.70 - err = regexec(parser->compiled_patterns[i], input, 1, &match, 0); 19.71 - if (err > 0 && err != REG_NOMATCH) { 19.72 - fprintf(stderr, "Regex-Error: 0x%08x", err); 19.73 - } 19.74 - if (err == 0) { 19.75 - parser->pattern_match = i+1; 19.76 - parser->matched_lines = 0; 19.77 - /* Check, if end pattern is also in this line */ 19.78 - regex_parser_do(parser, input); 19.79 - /* do not match line, if it does not start with the pattern */ 19.80 - if (match.rm_so > 0 && parser->matched_lines > 0) { 19.81 - parser->matched_lines--; 19.82 - } 19.83 - break; 19.84 - } 19.85 - } 19.86 - } 19.87 - } 19.88 - return err; 19.89 -} 19.90 - 19.91 -bool regex_compile_all(regex_parser_t* parser) { 19.92 - bool success = true; 19.93 - size_t pcount = parser->pattern_list->count; 19.94 - if (pcount > 0) { 19.95 - regex_destcomppats(parser); 19.96 - parser->compiled_patterns = calloc(pcount, sizeof(regex_t)); 19.97 - parser->compiled_pattern_count = pcount; 19.98 - 19.99 - regex_t* re; 19.100 - for (int i = 0 ; i < pcount ; i++) { 19.101 - re = malloc(sizeof(regex_t)); 19.102 - if (regcomp(re, parser->pattern_list->items[i], REG_EXTENDED) == 0) { 19.103 - parser->compiled_patterns[i] = re; 19.104 - } else { 19.105 - fprintf(stderr, "Cannot compile pattern: %s\n", 19.106 - (parser->pattern_list->items[i])); 19.107 - parser->compiled_patterns[i] = NULL; 19.108 - success = false; 19.109 - } 19.110 - } 19.111 - } 19.112 - return success; 19.113 -}
20.1 --- a/regex_parser.h Tue Oct 02 10:49:25 2012 +0200 20.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 20.3 @@ -1,42 +0,0 @@ 20.4 -/* 20.5 - * regex_parser.h 20.6 - * 20.7 - * Created on: 26.01.2012 20.8 - * Author: Mike 20.9 - */ 20.10 - 20.11 -#ifndef REGEX_PARSER_H_ 20.12 -#define REGEX_PARSER_H_ 20.13 - 20.14 -#define REGEX_MAX_LINELENGTH 2048 20.15 - 20.16 -#include <sys/types.h> 20.17 -#include <stdbool.h> 20.18 -#include <regex.h> 20.19 -#include "string_list.h" 20.20 - 20.21 -typedef struct { 20.22 - string_list_t* pattern_list; /* even entries: start ; odd entries: end */ 20.23 - regex_t** compiled_patterns; 20.24 - size_t compiled_pattern_count; 20.25 - unsigned int pattern_match; /* save position of end pattern to match - 20.26 - NULL when a start pattern shall match first */ 20.27 - unsigned int matched_lines; 20.28 -} regex_parser_t; 20.29 - 20.30 -#ifdef _cplusplus 20.31 -extern "C" { 20.32 -#endif 20.33 - 20.34 -regex_parser_t* new_regex_parser_t(); 20.35 -void destroy_regex_parser_t(regex_parser_t*); 20.36 - 20.37 -bool regex_parser_matching(regex_parser_t*); 20.38 -bool regex_compile_all(regex_parser_t*); 20.39 -int regex_parser_do(regex_parser_t*, char*); 20.40 - 20.41 -#ifdef _cplusplus 20.42 -} 20.43 -#endif 20.44 - 20.45 -#endif /* REGEX_PARSER_H_ */
21.1 --- a/scanner.c Tue Oct 02 10:49:25 2012 +0200 21.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 21.3 @@ -1,126 +0,0 @@ 21.4 -/* 21.5 - * scanner.c 21.6 - * 21.7 - * Created on: 23.05.2011 21.8 - * Author: Mike 21.9 - */ 21.10 - 21.11 - 21.12 -#include "scanner.h" 21.13 -#include "suffix_fnc.h" 21.14 -#include "bfile_heuristics.h" 21.15 -#include "regex_parser.h" 21.16 -#include <sys/stat.h> 21.17 - 21.18 -int scanDirectory(scanner_t scanner, settings_t* settings) { 21.19 - 21.20 - DIR *dirf; 21.21 - struct dirent *entry; 21.22 - int lines, a; 21.23 - int lineSum = 0; 21.24 - bool bfile; 21.25 - struct stat statbuf; 21.26 - 21.27 - if ((dirf = opendir(scanner.dir)) == NULL) { 21.28 - printf(scanner.dir); 21.29 - perror(" Directory access failed"); 21.30 - return 0; 21.31 - } 21.32 - 21.33 - while ((entry = readdir(dirf)) != NULL) { 21.34 - if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { 21.35 - /* Construct tree view and absolute pathname strings */ 21.36 - char entryname[strlen(entry->d_name)+scanner.spaces]; 21.37 - for (int t = 0 ; t < scanner.spaces ; t++) { 21.38 - entryname[t]=' '; 21.39 - } 21.40 - entryname[scanner.spaces] = 0; 21.41 - strcat(entryname, entry->d_name); 21.42 - 21.43 - char filename[(1+strlen(scanner.dir)+strlen(entry->d_name))]; 21.44 - strcpy(filename, scanner.dir); 21.45 - strncat(filename, &settings->fileSeparator, 1); 21.46 - strcat(filename, entry->d_name); 21.47 - 21.48 - /* Check for subdirectory */ 21.49 - if (stat(filename, &statbuf) == 0) { 21.50 - if (!(statbuf.st_mode & S_IFREG)) { 21.51 - printf("%-60s\n", entryname); 21.52 - if (settings->recursive && (statbuf.st_mode & S_IFDIR)) { 21.53 - lineSum += scanDirectory( 21.54 - (scanner_t) {filename, scanner.spaces+1}, settings); 21.55 - } 21.56 - continue; 21.57 - } 21.58 - } else { 21.59 - perror(" Error in stat call"); 21.60 - continue; 21.61 - } 21.62 - 21.63 - if ((settings->includeSuffixes->count == 0 21.64 - || testSuffix(filename, settings->includeSuffixes)) 21.65 - && !testSuffix(filename, settings->excludeSuffixes)) { 21.66 - /* Count lines */ 21.67 - lines = 0; 21.68 - bfile = false; 21.69 - bfile_reset(settings->bfileHeuristics); 21.70 - char line_buffer[REGEX_MAX_LINELENGTH]; 21.71 - int line_buffer_offset = 0; 21.72 - 21.73 - FILE *file = fopen(filename, "r"); 21.74 - if (file == NULL) { 21.75 - printf(entryname); 21.76 - perror(" File acces failed"); 21.77 - continue; 21.78 - } 21.79 - 21.80 - do { 21.81 - a = fgetc(file); 21.82 - 21.83 - bfile = bfile_check(settings->bfileHeuristics, a); 21.84 - 21.85 - if (a == 10 || a == EOF) { 21.86 - line_buffer[line_buffer_offset] = 0; 21.87 - if (regex_parser_do(settings->regex, line_buffer) == 0) { 21.88 - /* Only subtract lines when matching has finished */ 21.89 - if (!regex_parser_matching(settings->regex)) { 21.90 - lines -= settings->regex->matched_lines; 21.91 - } 21.92 - } 21.93 - 21.94 - line_buffer_offset = 0; 21.95 - lines++; 21.96 - } else { 21.97 - if (line_buffer_offset < REGEX_MAX_LINELENGTH) { 21.98 - line_buffer[line_buffer_offset] = a; 21.99 - line_buffer_offset++; 21.100 - } else { 21.101 - line_buffer[line_buffer_offset-1] = 0; 21.102 - settings->confusing_lnlen = true; 21.103 - } 21.104 - } 21.105 - } while (!bfile && a != EOF); 21.106 - fclose(file); 21.107 - 21.108 - /* Print and sum line count */ 21.109 - if (bfile) { 21.110 - if (!settings->matchesOnly) { 21.111 - printf("%-60s%19s\n", entryname, "binary"); 21.112 - } 21.113 - } else { 21.114 - lineSum += lines; 21.115 - printf("%-60s%13d lines\n", entryname, lines); 21.116 - } 21.117 - } else { 21.118 - if (!settings->matchesOnly) { 21.119 - /* Print hint */ 21.120 - printf("%-60s%19s\n", entryname, "no match"); 21.121 - } 21.122 - } 21.123 - } 21.124 - } 21.125 - 21.126 - closedir(dirf); 21.127 - 21.128 - return lineSum; 21.129 -}
22.1 --- a/scanner.h Tue Oct 02 10:49:25 2012 +0200 22.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 22.3 @@ -1,29 +0,0 @@ 22.4 -/* 22.5 - * scanner.h 22.6 - * 22.7 - * Created on: 23.05.2011 22.8 - * Author: Mike 22.9 - */ 22.10 - 22.11 -#ifndef SCANNER_H_ 22.12 -#define SCANNER_H_ 22.13 - 22.14 -#include "stdinc.h" 22.15 -#include "settings.h" 22.16 - 22.17 -typedef struct { 22.18 - char *dir; 22.19 - int spaces; 22.20 -} scanner_t; 22.21 - 22.22 -#ifdef _cplusplus 22.23 -extern "C" { 22.24 -#endif 22.25 - 22.26 -int scanDirectory(scanner_t scanner, settings_t* settings); 22.27 - 22.28 -#ifdef _cplusplus 22.29 -} 22.30 -#endif 22.31 - 22.32 -#endif /* SCANNER_H_ */
23.1 --- a/settings.c Tue Oct 02 10:49:25 2012 +0200 23.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 23.3 @@ -1,37 +0,0 @@ 23.4 -/* 23.5 - * settings.c 23.6 - * 23.7 - * Created on: 15.09.2011 23.8 - * Author: Mike 23.9 - */ 23.10 - 23.11 -#include "settings.h" 23.12 - 23.13 -settings_t* new_settings_t() { 23.14 - settings_t *settings = malloc(sizeof(settings_t)); 23.15 - if (settings != NULL) { 23.16 - #ifdef _WIN32 23.17 - settings->fileSeparator = '\\'; 23.18 - #else 23.19 - settings->fileSeparator = '/'; 23.20 - #endif /* _WIN32 */ 23.21 - settings->recursive = false; 23.22 - settings->matchesOnly = false; 23.23 - settings->includeSuffixes = new_string_list_t(); 23.24 - settings->excludeSuffixes = new_string_list_t(); 23.25 - settings->verbose = true; 23.26 - settings->bfileHeuristics = new_bfile_heuristics_t(); 23.27 - settings->confusing_lnlen = false; 23.28 - settings->regex = new_regex_parser_t(); 23.29 - } 23.30 - 23.31 - return settings; 23.32 -} 23.33 - 23.34 -void destroy_settings_t(settings_t* settings) { 23.35 - destroy_regex_parser_t(settings->regex); 23.36 - destroy_string_list_t(settings->includeSuffixes); 23.37 - destroy_string_list_t(settings->excludeSuffixes); 23.38 - destroy_bfile_heuristics_t(settings->bfileHeuristics); 23.39 - free(settings); 23.40 -}
24.1 --- a/settings.h Tue Oct 02 10:49:25 2012 +0200 24.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 24.3 @@ -1,39 +0,0 @@ 24.4 -/* 24.5 - * settings.h 24.6 - * 24.7 - * Created on: 15.09.2011 24.8 - * Author: Mike 24.9 - */ 24.10 - 24.11 -#ifndef SETTINGS_H_ 24.12 -#define SETTINGS_H_ 24.13 - 24.14 -#include "stdinc.h" 24.15 -#include "string_list.h" 24.16 -#include "bfile_heuristics.h" 24.17 -#include "regex_parser.h" 24.18 - 24.19 -typedef struct _settings { 24.20 - string_list_t* includeSuffixes; 24.21 - string_list_t* excludeSuffixes; 24.22 - regex_parser_t* regex; 24.23 - bfile_heuristics_t* bfileHeuristics; 24.24 - char fileSeparator; 24.25 - bool recursive; 24.26 - bool matchesOnly; 24.27 - bool verbose; 24.28 - bool confusing_lnlen; /* this flag is set by the scanner */ 24.29 -} settings_t; 24.30 - 24.31 -#ifdef _cplusplus 24.32 -extern "C" { 24.33 -#endif 24.34 - 24.35 -settings_t* new_settings_t(); 24.36 -void destroy_settings_t(settings_t*); 24.37 - 24.38 -#ifdef _cplusplus 24.39 -} 24.40 -#endif 24.41 - 24.42 -#endif /* SETTINGS_H_ */
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/src/arguments.c Fri Dec 28 15:44:28 2012 +0100 25.3 @@ -0,0 +1,70 @@ 25.4 +/* 25.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 25.6 + * Copyright 2011 Mike Becker. All rights reserved. 25.7 + * 25.8 + * Redistribution and use in source and binary forms, with or without 25.9 + * modification, are permitted provided that the following conditions are met: 25.10 + * 25.11 + * 1. Redistributions of source code must retain the above copyright 25.12 + * notice, this list of conditions and the following disclaimer. 25.13 + * 25.14 + * 2. Redistributions in binary form must reproduce the above copyright 25.15 + * notice, this list of conditions and the following disclaimer in the 25.16 + * documentation and/or other materials provided with the distribution. 25.17 + * 25.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25.28 + * 25.29 + * 25.30 + * arguments.c 25.31 + * 25.32 + * Created on: 15.09.2011 25.33 + * Author: Mike 25.34 + */ 25.35 + 25.36 +#include "arguments.h" 25.37 + 25.38 +int checkArgument(const char* arg, const char* expected) { 25.39 + int len = strlen(expected); 25.40 + int ret = 0; 25.41 + 25.42 + if (arg[0] == '-') { 25.43 + if (arg[1] != '-') { 25.44 + for (int t = 0 ; t < len ; t++) { 25.45 + ret |= (strchr(arg, expected[t]) > 0) << t; 25.46 + } 25.47 + } 25.48 + } 25.49 + 25.50 + return ret; 25.51 +} 25.52 + 25.53 +bool registerArgument(int* reg, int mask) { 25.54 + bool ret = (*reg & mask) > 0; 25.55 + *reg |= mask; 25.56 + return ret; 25.57 +} 25.58 + 25.59 +bool checkParamOpt(int* paropt) { 25.60 + bool ret = *paropt == 0; 25.61 + *paropt = 1; 25.62 + return ret; 25.63 +} 25.64 + 25.65 +void parseCSL(char* csl, string_list_t* list) { 25.66 + if (csl != NULL) { 25.67 + char* finder = strtok(csl, ","); 25.68 + while (finder != NULL) { 25.69 + add_string(list, finder); 25.70 + finder = strtok(NULL, ","); 25.71 + } 25.72 + } 25.73 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/src/arguments.h Fri Dec 28 15:44:28 2012 +0100 26.3 @@ -0,0 +1,51 @@ 26.4 +/* 26.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 26.6 + * Copyright 2011 Mike Becker. All rights reserved. 26.7 + * 26.8 + * Redistribution and use in source and binary forms, with or without 26.9 + * modification, are permitted provided that the following conditions are met: 26.10 + * 26.11 + * 1. Redistributions of source code must retain the above copyright 26.12 + * notice, this list of conditions and the following disclaimer. 26.13 + * 26.14 + * 2. Redistributions in binary form must reproduce the above copyright 26.15 + * notice, this list of conditions and the following disclaimer in the 26.16 + * documentation and/or other materials provided with the distribution. 26.17 + * 26.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26.28 + * 26.29 + * arguments.h 26.30 + * 26.31 + * Created on: 15.09.2011 26.32 + * Author: Mike 26.33 + */ 26.34 + 26.35 +#ifndef ARGUMENTS_H_ 26.36 +#define ARGUMENTS_H_ 26.37 + 26.38 +#include "stdinc.h" 26.39 +#include "string_list.h" 26.40 + 26.41 +#ifdef _cplusplus 26.42 +extern "C" { 26.43 +#endif 26.44 + 26.45 +int checkArgument(const char*, const char*); 26.46 +bool checkParamOpt(int*); 26.47 +bool registerArgument(int*, int); 26.48 +void parseCSL(char*, string_list_t*); 26.49 + 26.50 +#ifdef _cplusplus 26.51 +} 26.52 +#endif 26.53 + 26.54 +#endif /* ARGUMENTS_H_ */
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/src/bfile_heuristics.c Fri Dec 28 15:44:28 2012 +0100 27.3 @@ -0,0 +1,81 @@ 27.4 +/* 27.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 27.6 + * Copyright 2011 Mike Becker. All rights reserved. 27.7 + * 27.8 + * Redistribution and use in source and binary forms, with or without 27.9 + * modification, are permitted provided that the following conditions are met: 27.10 + * 27.11 + * 1. Redistributions of source code must retain the above copyright 27.12 + * notice, this list of conditions and the following disclaimer. 27.13 + * 27.14 + * 2. Redistributions in binary form must reproduce the above copyright 27.15 + * notice, this list of conditions and the following disclaimer in the 27.16 + * documentation and/or other materials provided with the distribution. 27.17 + * 27.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 27.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27.28 + * 27.29 + * bfile_heuristics.c 27.30 + * 27.31 + * Created on: 20.10.2011 27.32 + * Author: Mike 27.33 + */ 27.34 + 27.35 +#include "bfile_heuristics.h" 27.36 +#include <ctype.h> 27.37 + 27.38 +bfile_heuristics_t *new_bfile_heuristics_t() { 27.39 + bfile_heuristics_t *ret = malloc(sizeof(bfile_heuristics_t)); 27.40 + ret->level = BFILE_MEDIUM_ACCURACY; 27.41 + bfile_reset(ret); 27.42 + return ret; 27.43 +} 27.44 + 27.45 +void destroy_bfile_heuristics_t(bfile_heuristics_t *def) { 27.46 + free(def); 27.47 +} 27.48 + 27.49 +void bfile_reset(bfile_heuristics_t *def) { 27.50 + def->bcount = 0; 27.51 + def->tcount = 0; 27.52 +} 27.53 + 27.54 +bool bfile_check(bfile_heuristics_t *def, int next_char) { 27.55 + bool ret = false; 27.56 + if (def->level != BFILE_IGNORE) { 27.57 + def->tcount++; 27.58 + if (!isprint(next_char) && !isspace(next_char)) { 27.59 + def->bcount++; 27.60 + } 27.61 + 27.62 + if (def->tcount > 1) { /* empty files are text files */ 27.63 + switch (def->level) { 27.64 + case BFILE_LOW_ACCURACY: 27.65 + if (def->tcount > 15 || next_char == EOF) { 27.66 + ret = (1.0*def->bcount)/def->tcount > 0.32; 27.67 + } 27.68 + break; 27.69 + case BFILE_HIGH_ACCURACY: 27.70 + if (def->tcount > 500 || next_char == EOF) { 27.71 + ret = (1.0*def->bcount)/def->tcount > 0.1; 27.72 + } 27.73 + break; 27.74 + default: /* BFILE_MEDIUM_ACCURACY */ 27.75 + if (def->tcount > 100 || next_char == EOF) { 27.76 + ret = (1.0*def->bcount)/def->tcount > 0.1; 27.77 + } 27.78 + break; 27.79 + } 27.80 + } 27.81 + } 27.82 + 27.83 + return ret; 27.84 +}
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/src/bfile_heuristics.h Fri Dec 28 15:44:28 2012 +0100 28.3 @@ -0,0 +1,61 @@ 28.4 +/* 28.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 28.6 + * Copyright 2011 Mike Becker. All rights reserved. 28.7 + * 28.8 + * Redistribution and use in source and binary forms, with or without 28.9 + * modification, are permitted provided that the following conditions are met: 28.10 + * 28.11 + * 1. Redistributions of source code must retain the above copyright 28.12 + * notice, this list of conditions and the following disclaimer. 28.13 + * 28.14 + * 2. Redistributions in binary form must reproduce the above copyright 28.15 + * notice, this list of conditions and the following disclaimer in the 28.16 + * documentation and/or other materials provided with the distribution. 28.17 + * 28.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 28.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28.28 + * 28.29 + * bfile_heuristics.h 28.30 + * 28.31 + * Created on: 20.10.2011 28.32 + * Author: Mike 28.33 + */ 28.34 + 28.35 +#ifndef BFILE_HEURISTICS_H_ 28.36 +#define BFILE_HEURISTICS_H_ 28.37 + 28.38 +#include "stdinc.h" 28.39 + 28.40 +#define BFILE_IGNORE 0x00 28.41 +#define BFILE_LOW_ACCURACY 0x01 28.42 +#define BFILE_MEDIUM_ACCURACY 0x02 28.43 +#define BFILE_HIGH_ACCURACY 0x04 28.44 + 28.45 +typedef struct { 28.46 + unsigned int level; 28.47 + unsigned int bcount; /* 'binary' character count */ 28.48 + unsigned int tcount; /* total count */ 28.49 +} bfile_heuristics_t; 28.50 + 28.51 +#ifdef _cplusplus 28.52 +extern "C" { 28.53 +#endif 28.54 + 28.55 +bfile_heuristics_t *new_bfile_heuristics_t(); 28.56 +void destroy_bfile_heuristics_t(bfile_heuristics_t *def); 28.57 +void bfile_reset(bfile_heuristics_t *def); 28.58 +bool bfile_check(bfile_heuristics_t *def, int next_char); 28.59 + 28.60 +#ifdef _cplusplus 28.61 +} 28.62 +#endif 28.63 + 28.64 +#endif /* BFILE_HEURISTICS_H_ */
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/src/cline.c Fri Dec 28 15:44:28 2012 +0100 29.3 @@ -0,0 +1,269 @@ 29.4 +/* 29.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 29.6 + * Copyright 2011 Mike Becker. All rights reserved. 29.7 + * 29.8 + * Redistribution and use in source and binary forms, with or without 29.9 + * modification, are permitted provided that the following conditions are met: 29.10 + * 29.11 + * 1. Redistributions of source code must retain the above copyright 29.12 + * notice, this list of conditions and the following disclaimer. 29.13 + * 29.14 + * 2. Redistributions in binary form must reproduce the above copyright 29.15 + * notice, this list of conditions and the following disclaimer in the 29.16 + * documentation and/or other materials provided with the distribution. 29.17 + * 29.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 29.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 29.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29.28 + * 29.29 + * cline.c 29.30 + * 29.31 + * Created on: 23.05.2011 29.32 + * Author: Mike 29.33 + */ 29.34 + 29.35 +#include "cline.h" 29.36 +#include "scanner.h" 29.37 +#include "settings.h" 29.38 +#include "arguments.h" 29.39 +#include "stream.h" 29.40 +#include "regex_parser.h" 29.41 + 29.42 +void printHelpText() { 29.43 + printf( 29.44 + "\nUsage:" 29.45 + "\n cline [Options] [Directories...]" 29.46 + "\n cline [Options] [Directories...]" 29.47 + "\n\nCounts the line terminator characters (\\n) within all" 29.48 + " files in the specified\ndirectories." 29.49 + "\n\nOptions:" 29.50 + "\n -b <level> - binary file heuristics level (default medium)" 29.51 + "\n One of: ignore low medium high" 29.52 + "\n -E <pattern> - Excludes any line matching the <pattern>" 29.53 + "\n -e <start> <end> - Excludes lines between <start> and <end>" 29.54 + "\n You may use these options multiple times" 29.55 + "\n -h, --help - this help text" 29.56 + "\n -m - print information about matching files only" 29.57 + "\n -s <suffixes> - only count files with these suffixes (separated" 29.58 + "\n by commas)" 29.59 + "\n -S <suffixes> - count any file except those with these suffixes" 29.60 + "\n (separated by commas)" 29.61 + "\n -r, -R - includes subdirectories" 29.62 + "\n -v, --version - print out version information" 29.63 + "\n -V - turn verbose output off, print the result only" 29.64 + "\n\nShortcuts:" 29.65 + "\n --exclude-cstyle-comments" 29.66 + "\n = -E \"\\s*//\" -e \"\\s*/\\*\" \"\\*/\\s*\"" 29.67 + "\n\n" 29.68 + "The default call without any options is:" 29.69 + "\n cline ./\n\n" 29.70 + "So each file in the working directory is counted. If you want to count C" 29.71 + "\nsource code in your working directory and its subdirectories, type:" 29.72 + "\n cline -rs .c\n" 29.73 + "\nIf you want to exclude comment lines, you may use the -e/-E option." 29.74 + "\nAfter a line matches the regex pattern <start> any following line is" 29.75 + "\nnot counted unless a line matches the <end> pattern. A line is still " 29.76 + "\ncounted when it does not start or end with the respective patterns." 29.77 + "\nPlease note, that cline does not remove whitespace characters as this" 29.78 + "\nmight not be reasonable in some cases." 29.79 + "\n\nExample (C without comments):" 29.80 + "\n cline -s .c,.h --exclude-cstyle-comments"); 29.81 +} 29.82 + 29.83 +int exit_with_version(settings_t* settings) { 29.84 + printf("cline - Revision: %s\n", VERSION); 29.85 + destroy_settings_t(settings); 29.86 + return 0; 29.87 +} 29.88 + 29.89 +int exit_with_help(settings_t* settings, int code) { 29.90 + printHelpText(); 29.91 + destroy_settings_t(settings); 29.92 + return code; 29.93 +} 29.94 + 29.95 +int main(int argc, char** argv) { 29.96 + 29.97 + /* Settings */ 29.98 + settings_t *settings = new_settings_t(); 29.99 + if (settings == NULL) { 29.100 + fprintf(stderr, "Memory allocation failed.\n"); 29.101 + return 1; 29.102 + } 29.103 + 29.104 + /* Get arguments */ 29.105 + string_list_t *directories = new_string_list_t(); 29.106 + if (directories == NULL) { 29.107 + fprintf(stderr, "Memory allocation failed.\n"); 29.108 + return 1; 29.109 + } 29.110 + char* includeSuffix = NULL; 29.111 + char* excludeSuffix = NULL; 29.112 + int checked = 0; 29.113 + 29.114 + for (int t = 1 ; t < argc ; t++) { 29.115 + 29.116 + int argflags = checkArgument(argv[t], "hsSrRmvVbeE"); 29.117 + int paropt = 0; 29.118 + 29.119 + /* s */ 29.120 + if ((argflags & 2) > 0) { 29.121 + if (!checkParamOpt(&paropt) || registerArgument(&checked, 2)) { 29.122 + return exit_with_help(settings, 1); 29.123 + } 29.124 + t++; 29.125 + if (t >= argc) { 29.126 + return exit_with_help(settings, 1); 29.127 + } 29.128 + includeSuffix = argv[t]; 29.129 + } 29.130 + /* S */ 29.131 + if ((argflags & 4) > 0) { 29.132 + if (!checkParamOpt(&paropt) || registerArgument(&checked, 4)) { 29.133 + return exit_with_help(settings, 1); 29.134 + } 29.135 + t++; 29.136 + if (t >= argc) { 29.137 + return exit_with_help(settings, 1); 29.138 + } 29.139 + excludeSuffix = argv[t]; 29.140 + } 29.141 + /* h */ 29.142 + if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { 29.143 + return exit_with_help(settings, 0); 29.144 + } 29.145 + /* r, R */ 29.146 + if ((argflags & 24) > 0) { 29.147 + if (registerArgument(&checked, 24)) { 29.148 + return exit_with_help(settings, 1); 29.149 + } 29.150 + settings->recursive = true; 29.151 + } 29.152 + /* m */ 29.153 + if ((argflags & 32) > 0) { 29.154 + if (registerArgument(&checked, 32)) { 29.155 + return exit_with_help(settings, 1); 29.156 + } 29.157 + settings->matchesOnly = true; 29.158 + } 29.159 + /* v */ 29.160 + if ((argflags & 64) > 0 || strcmp(argv[t], "--version") == 0) { 29.161 + return exit_with_version(settings); 29.162 + } 29.163 + /* V */ 29.164 + if ((argflags & 128) > 0) { 29.165 + if (registerArgument(&checked, 128)) { 29.166 + return exit_with_help(settings, 1); 29.167 + } 29.168 + settings->verbose = false; 29.169 + } 29.170 + /* b */ 29.171 + if ((argflags & 256) > 0) { 29.172 + if (!checkParamOpt(&paropt) || registerArgument(&checked, 256)) { 29.173 + return exit_with_help(settings, 1); 29.174 + } 29.175 + t++; 29.176 + if (t >= argc) { 29.177 + return exit_with_help(settings, 1); 29.178 + } 29.179 + if (strcasecmp(argv[t], "ignore") == 0) { 29.180 + settings->bfileHeuristics->level = BFILE_IGNORE; 29.181 + } else if (strcasecmp(argv[t], "low") == 0) { 29.182 + settings->bfileHeuristics->level = BFILE_LOW_ACCURACY; 29.183 + } else if (strcasecmp(argv[t], "medium") == 0) { 29.184 + settings->bfileHeuristics->level = BFILE_MEDIUM_ACCURACY; 29.185 + } else if (strcasecmp(argv[t], "high") == 0) { 29.186 + settings->bfileHeuristics->level = BFILE_HIGH_ACCURACY; 29.187 + } else { 29.188 + return exit_with_help(settings, 1); 29.189 + } 29.190 + } 29.191 + /* e */ 29.192 + if ((argflags & 512) > 0) { 29.193 + if (!checkParamOpt(&paropt) || t + 2 >= argc) { 29.194 + return exit_with_help(settings, 1); 29.195 + } 29.196 + t++; add_string(settings->regex->pattern_list, argv[t]); 29.197 + t++; add_string(settings->regex->pattern_list, argv[t]); 29.198 + } 29.199 + /* E */ 29.200 + if ((argflags & 1024) > 0) { 29.201 + t++; 29.202 + if (!checkParamOpt(&paropt) || t >= argc) { 29.203 + return exit_with_help(settings, 1); 29.204 + } 29.205 + add_string(settings->regex->pattern_list, argv[t]); 29.206 + add_string(settings->regex->pattern_list, "$"); 29.207 + } 29.208 + if (argflags == 0) { 29.209 + /* SHORTCUTS */ 29.210 + /* exclude-cstyle-comments */ 29.211 + if (strcmp(argv[t], "--exclude-cstyle-comments") == 0) { 29.212 + add_string(settings->regex->pattern_list, "\\s*//"); 29.213 + add_string(settings->regex->pattern_list, "$"); 29.214 + add_string(settings->regex->pattern_list, "\\s*/\\*"); 29.215 + add_string(settings->regex->pattern_list, "\\*/\\s*"); 29.216 + } 29.217 + /* Path */ 29.218 + else { 29.219 + add_string(directories, argv[t]); 29.220 + } 29.221 + } 29.222 + } 29.223 + 29.224 + /* Configure output */ 29.225 + if (!settings->verbose) { 29.226 + close_stdout(); 29.227 + } 29.228 + 29.229 + /* Find tokens */ 29.230 + parseCSL(includeSuffix, settings->includeSuffixes); 29.231 + parseCSL(excludeSuffix, settings->excludeSuffixes); 29.232 + 29.233 + /* Scan directories */ 29.234 + if (regex_compile_all(settings->regex)) { 29.235 + int lines = 0; 29.236 + if (directories->count == 0) { 29.237 + add_string(directories, "."); 29.238 + } 29.239 + for (int t = 0 ; t < directories->count ; t++) { 29.240 + if (t > 0) { 29.241 + for (int u = 0 ; u < 79 ; u++) { 29.242 + printf("-"); 29.243 + } 29.244 + printf("\n"); 29.245 + } 29.246 + lines += scanDirectory((scanner_t){directories->items[t], 0}, settings); 29.247 + } 29.248 + destroy_string_list_t(directories); 29.249 + 29.250 + /* Print double line and line count */ 29.251 + for (int t = 0 ; t < 79 ; t++) { 29.252 + printf("="); 29.253 + } 29.254 + printf("\n%73d lines\n", lines); 29.255 + 29.256 + if (settings->confusing_lnlen && settings->regex->pattern_list->count > 0) { 29.257 + printf("\nSome files contain too long lines.\n" 29.258 + "The regex parser currently supports a maximum line length of %d." 29.259 + "\nThe result might be wrong.\n", REGEX_MAX_LINELENGTH); 29.260 + } 29.261 + 29.262 + if (!settings->verbose) { 29.263 + reopen_stdout(); 29.264 + printf("%d", lines); 29.265 + } 29.266 + destroy_settings_t(settings); 29.267 + } 29.268 + 29.269 + fflush(stdout); 29.270 + fflush(stderr); 29.271 + return 0; 29.272 +}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 30.2 +++ b/src/cline.h Fri Dec 28 15:44:28 2012 +0100 30.3 @@ -0,0 +1,52 @@ 30.4 +/* 30.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 30.6 + * Copyright 2011 Mike Becker. All rights reserved. 30.7 + * 30.8 + * Redistribution and use in source and binary forms, with or without 30.9 + * modification, are permitted provided that the following conditions are met: 30.10 + * 30.11 + * 1. Redistributions of source code must retain the above copyright 30.12 + * notice, this list of conditions and the following disclaimer. 30.13 + * 30.14 + * 2. Redistributions in binary form must reproduce the above copyright 30.15 + * notice, this list of conditions and the following disclaimer in the 30.16 + * documentation and/or other materials provided with the distribution. 30.17 + * 30.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 30.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30.28 + * 30.29 + * cline.h 30.30 + * 30.31 + * Created on: 23.05.2011 30.32 + * Author: Mike 30.33 + */ 30.34 + 30.35 +#ifndef CLINE_H_ 30.36 +#define CLINE_H_ 30.37 + 30.38 +const char* VERSION=""; /* will be replaced by makefile */ 30.39 + 30.40 +#include "stdinc.h" 30.41 +#include "settings.h" 30.42 + 30.43 +#ifdef _cplusplus 30.44 +extern "C" { 30.45 +#endif 30.46 + 30.47 +void printHelpText(); 30.48 +int exit_with_version(settings_t*); 30.49 +int exit_with_help(settings_t*, int); 30.50 + 30.51 +#ifdef _cplusplus 30.52 +} 30.53 +#endif 30.54 + 30.55 +#endif /* CLINE_H_ */
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 31.2 +++ b/src/regex_parser.c Fri Dec 28 15:44:28 2012 +0100 31.3 @@ -0,0 +1,134 @@ 31.4 +/* 31.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 31.6 + * Copyright 2011 Mike Becker. All rights reserved. 31.7 + * 31.8 + * Redistribution and use in source and binary forms, with or without 31.9 + * modification, are permitted provided that the following conditions are met: 31.10 + * 31.11 + * 1. Redistributions of source code must retain the above copyright 31.12 + * notice, this list of conditions and the following disclaimer. 31.13 + * 31.14 + * 2. Redistributions in binary form must reproduce the above copyright 31.15 + * notice, this list of conditions and the following disclaimer in the 31.16 + * documentation and/or other materials provided with the distribution. 31.17 + * 31.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 31.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 31.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 31.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31.28 + * 31.29 + * regex_parser.c 31.30 + * 31.31 + * Created on: 26.01.2012 31.32 + * Author: Mike 31.33 + */ 31.34 + 31.35 +#include "regex_parser.h" 31.36 + 31.37 +regex_parser_t* new_regex_parser_t() { 31.38 + regex_parser_t* ret = malloc(sizeof(regex_parser_t)); 31.39 + if (ret != NULL) { 31.40 + ret->pattern_list = new_string_list_t(); 31.41 + ret->matched_lines = 0; 31.42 + ret->pattern_match = 0; 31.43 + ret->compiled_patterns = NULL; 31.44 + ret->compiled_pattern_count = 0; 31.45 + } 31.46 + return ret; 31.47 +} 31.48 + 31.49 +void regex_destcomppats(regex_parser_t* parser) { 31.50 + if (parser->compiled_patterns != NULL) { 31.51 + for (int i = 0 ; i < parser->compiled_pattern_count ; i++) { 31.52 + if (parser->compiled_patterns[i] != NULL) { 31.53 + free(parser->compiled_patterns[i]); 31.54 + } 31.55 + } 31.56 + free(parser->compiled_patterns); 31.57 + parser->compiled_patterns = NULL; 31.58 + parser->compiled_pattern_count = 0; 31.59 + } 31.60 +} 31.61 + 31.62 +void destroy_regex_parser_t(regex_parser_t* parser) { 31.63 + regex_destcomppats(parser); 31.64 + destroy_string_list_t(parser->pattern_list); 31.65 + free(parser); 31.66 +} 31.67 + 31.68 +bool regex_parser_matching(regex_parser_t* parser) { 31.69 + return parser->pattern_match > 0; 31.70 +} 31.71 + 31.72 +int regex_parser_do(regex_parser_t* parser, char* input) { 31.73 + int err = REG_NOMATCH; 31.74 + if (parser->compiled_pattern_count > 0) { 31.75 + regmatch_t match; 31.76 + 31.77 + if (regex_parser_matching(parser)) { 31.78 + parser->matched_lines++; 31.79 + 31.80 + err = regexec(parser->compiled_patterns[parser->pattern_match], 31.81 + input, 1, &match, 0); 31.82 + if (err > 0 && err != REG_NOMATCH) { 31.83 + fprintf(stderr, "Regex-Error: 0x%08x", err); 31.84 + } 31.85 + if (err == 0) { 31.86 + parser->pattern_match = 0; 31.87 + /* do not match line, if it does not end with the pattern */ 31.88 + if (match.rm_eo < strlen(input)) { 31.89 + parser->matched_lines--; 31.90 + } 31.91 + } 31.92 + } else { 31.93 + for (int i = 0 ; i < parser->compiled_pattern_count - 1 ; i += 2) { 31.94 + err = regexec(parser->compiled_patterns[i], input, 1, &match, 0); 31.95 + if (err > 0 && err != REG_NOMATCH) { 31.96 + fprintf(stderr, "Regex-Error: 0x%08x", err); 31.97 + } 31.98 + if (err == 0) { 31.99 + parser->pattern_match = i+1; 31.100 + parser->matched_lines = 0; 31.101 + /* Check, if end pattern is also in this line */ 31.102 + regex_parser_do(parser, input); 31.103 + /* do not match line, if it does not start with the pattern */ 31.104 + if (match.rm_so > 0 && parser->matched_lines > 0) { 31.105 + parser->matched_lines--; 31.106 + } 31.107 + break; 31.108 + } 31.109 + } 31.110 + } 31.111 + } 31.112 + return err; 31.113 +} 31.114 + 31.115 +bool regex_compile_all(regex_parser_t* parser) { 31.116 + bool success = true; 31.117 + size_t pcount = parser->pattern_list->count; 31.118 + if (pcount > 0) { 31.119 + regex_destcomppats(parser); 31.120 + parser->compiled_patterns = calloc(pcount, sizeof(regex_t)); 31.121 + parser->compiled_pattern_count = pcount; 31.122 + 31.123 + regex_t* re; 31.124 + for (int i = 0 ; i < pcount ; i++) { 31.125 + re = malloc(sizeof(regex_t)); 31.126 + if (regcomp(re, parser->pattern_list->items[i], REG_EXTENDED) == 0) { 31.127 + parser->compiled_patterns[i] = re; 31.128 + } else { 31.129 + fprintf(stderr, "Cannot compile pattern: %s\n", 31.130 + (parser->pattern_list->items[i])); 31.131 + parser->compiled_patterns[i] = NULL; 31.132 + success = false; 31.133 + } 31.134 + } 31.135 + } 31.136 + return success; 31.137 +}
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/src/regex_parser.h Fri Dec 28 15:44:28 2012 +0100 32.3 @@ -0,0 +1,66 @@ 32.4 +/* 32.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 32.6 + * Copyright 2011 Mike Becker. All rights reserved. 32.7 + * 32.8 + * Redistribution and use in source and binary forms, with or without 32.9 + * modification, are permitted provided that the following conditions are met: 32.10 + * 32.11 + * 1. Redistributions of source code must retain the above copyright 32.12 + * notice, this list of conditions and the following disclaimer. 32.13 + * 32.14 + * 2. Redistributions in binary form must reproduce the above copyright 32.15 + * notice, this list of conditions and the following disclaimer in the 32.16 + * documentation and/or other materials provided with the distribution. 32.17 + * 32.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 32.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 32.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 32.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32.28 + * 32.29 + * regex_parser.h 32.30 + * 32.31 + * Created on: 26.01.2012 32.32 + * Author: Mike 32.33 + */ 32.34 + 32.35 +#ifndef REGEX_PARSER_H_ 32.36 +#define REGEX_PARSER_H_ 32.37 + 32.38 +#define REGEX_MAX_LINELENGTH 2048 32.39 + 32.40 +#include <sys/types.h> 32.41 +#include <stdbool.h> 32.42 +#include <regex.h> 32.43 +#include "string_list.h" 32.44 + 32.45 +typedef struct { 32.46 + string_list_t* pattern_list; /* even entries: start ; odd entries: end */ 32.47 + regex_t** compiled_patterns; 32.48 + size_t compiled_pattern_count; 32.49 + unsigned int pattern_match; /* save position of end pattern to match - 32.50 + NULL when a start pattern shall match first */ 32.51 + unsigned int matched_lines; 32.52 +} regex_parser_t; 32.53 + 32.54 +#ifdef _cplusplus 32.55 +extern "C" { 32.56 +#endif 32.57 + 32.58 +regex_parser_t* new_regex_parser_t(); 32.59 +void destroy_regex_parser_t(regex_parser_t*); 32.60 + 32.61 +bool regex_parser_matching(regex_parser_t*); 32.62 +bool regex_compile_all(regex_parser_t*); 32.63 +int regex_parser_do(regex_parser_t*, char*); 32.64 + 32.65 +#ifdef _cplusplus 32.66 +} 32.67 +#endif 32.68 + 32.69 +#endif /* REGEX_PARSER_H_ */
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/src/scanner.c Fri Dec 28 15:44:28 2012 +0100 33.3 @@ -0,0 +1,150 @@ 33.4 +/* 33.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 33.6 + * Copyright 2011 Mike Becker. All rights reserved. 33.7 + * 33.8 + * Redistribution and use in source and binary forms, with or without 33.9 + * modification, are permitted provided that the following conditions are met: 33.10 + * 33.11 + * 1. Redistributions of source code must retain the above copyright 33.12 + * notice, this list of conditions and the following disclaimer. 33.13 + * 33.14 + * 2. Redistributions in binary form must reproduce the above copyright 33.15 + * notice, this list of conditions and the following disclaimer in the 33.16 + * documentation and/or other materials provided with the distribution. 33.17 + * 33.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 33.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 33.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 33.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 33.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33.28 + * 33.29 + * scanner.c 33.30 + * 33.31 + * Created on: 23.05.2011 33.32 + * Author: Mike 33.33 + */ 33.34 + 33.35 + 33.36 +#include "scanner.h" 33.37 +#include "suffix_fnc.h" 33.38 +#include "bfile_heuristics.h" 33.39 +#include "regex_parser.h" 33.40 +#include <sys/stat.h> 33.41 + 33.42 +int scanDirectory(scanner_t scanner, settings_t* settings) { 33.43 + 33.44 + DIR *dirf; 33.45 + struct dirent *entry; 33.46 + int lines, a; 33.47 + int lineSum = 0; 33.48 + bool bfile; 33.49 + struct stat statbuf; 33.50 + 33.51 + if ((dirf = opendir(scanner.dir)) == NULL) { 33.52 + printf("%s", scanner.dir); 33.53 + perror(" Directory access failed"); 33.54 + return 0; 33.55 + } 33.56 + 33.57 + while ((entry = readdir(dirf)) != NULL) { 33.58 + if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { 33.59 + /* Construct tree view and absolute pathname strings */ 33.60 + char entryname[strlen(entry->d_name)+scanner.spaces]; 33.61 + for (int t = 0 ; t < scanner.spaces ; t++) { 33.62 + entryname[t]=' '; 33.63 + } 33.64 + entryname[scanner.spaces] = 0; 33.65 + strcat(entryname, entry->d_name); 33.66 + 33.67 + char filename[(1+strlen(scanner.dir)+strlen(entry->d_name))]; 33.68 + strcpy(filename, scanner.dir); 33.69 + strncat(filename, &settings->fileSeparator, 1); 33.70 + strcat(filename, entry->d_name); 33.71 + 33.72 + /* Check for subdirectory */ 33.73 + if (stat(filename, &statbuf) == 0) { 33.74 + if (!(statbuf.st_mode & S_IFREG)) { 33.75 + printf("%-60s\n", entryname); 33.76 + if (settings->recursive && (statbuf.st_mode & S_IFDIR)) { 33.77 + lineSum += scanDirectory( 33.78 + (scanner_t) {filename, scanner.spaces+1}, settings); 33.79 + } 33.80 + continue; 33.81 + } 33.82 + } else { 33.83 + perror(" Error in stat call"); 33.84 + continue; 33.85 + } 33.86 + 33.87 + if ((settings->includeSuffixes->count == 0 33.88 + || testSuffix(filename, settings->includeSuffixes)) 33.89 + && !testSuffix(filename, settings->excludeSuffixes)) { 33.90 + /* Count lines */ 33.91 + lines = 0; 33.92 + bfile = false; 33.93 + bfile_reset(settings->bfileHeuristics); 33.94 + char line_buffer[REGEX_MAX_LINELENGTH]; 33.95 + int line_buffer_offset = 0; 33.96 + 33.97 + FILE *file = fopen(filename, "r"); 33.98 + if (file == NULL) { 33.99 + printf("%s", entryname); 33.100 + perror(" File acces failed"); 33.101 + continue; 33.102 + } 33.103 + 33.104 + do { 33.105 + a = fgetc(file); 33.106 + 33.107 + bfile = bfile_check(settings->bfileHeuristics, a); 33.108 + 33.109 + if (a == 10 || a == EOF) { 33.110 + line_buffer[line_buffer_offset] = 0; 33.111 + if (regex_parser_do(settings->regex, line_buffer) == 0) { 33.112 + /* Only subtract lines when matching has finished */ 33.113 + if (!regex_parser_matching(settings->regex)) { 33.114 + lines -= settings->regex->matched_lines; 33.115 + } 33.116 + } 33.117 + 33.118 + line_buffer_offset = 0; 33.119 + lines++; 33.120 + } else { 33.121 + if (line_buffer_offset < REGEX_MAX_LINELENGTH) { 33.122 + line_buffer[line_buffer_offset] = a; 33.123 + line_buffer_offset++; 33.124 + } else { 33.125 + line_buffer[line_buffer_offset-1] = 0; 33.126 + settings->confusing_lnlen = true; 33.127 + } 33.128 + } 33.129 + } while (!bfile && a != EOF); 33.130 + fclose(file); 33.131 + 33.132 + /* Print and sum line count */ 33.133 + if (bfile) { 33.134 + if (!settings->matchesOnly) { 33.135 + printf("%-60s%19s\n", entryname, "binary"); 33.136 + } 33.137 + } else { 33.138 + lineSum += lines; 33.139 + printf("%-60s%13d lines\n", entryname, lines); 33.140 + } 33.141 + } else { 33.142 + if (!settings->matchesOnly) { 33.143 + /* Print hint */ 33.144 + printf("%-60s%19s\n", entryname, "no match"); 33.145 + } 33.146 + } 33.147 + } 33.148 + } 33.149 + 33.150 + closedir(dirf); 33.151 + 33.152 + return lineSum; 33.153 +}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/src/scanner.h Fri Dec 28 15:44:28 2012 +0100 34.3 @@ -0,0 +1,53 @@ 34.4 +/* 34.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 34.6 + * Copyright 2011 Mike Becker. All rights reserved. 34.7 + * 34.8 + * Redistribution and use in source and binary forms, with or without 34.9 + * modification, are permitted provided that the following conditions are met: 34.10 + * 34.11 + * 1. Redistributions of source code must retain the above copyright 34.12 + * notice, this list of conditions and the following disclaimer. 34.13 + * 34.14 + * 2. Redistributions in binary form must reproduce the above copyright 34.15 + * notice, this list of conditions and the following disclaimer in the 34.16 + * documentation and/or other materials provided with the distribution. 34.17 + * 34.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 34.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 34.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 34.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 34.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 34.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 34.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34.28 + * 34.29 + * scanner.h 34.30 + * 34.31 + * Created on: 23.05.2011 34.32 + * Author: Mike 34.33 + */ 34.34 + 34.35 +#ifndef SCANNER_H_ 34.36 +#define SCANNER_H_ 34.37 + 34.38 +#include "stdinc.h" 34.39 +#include "settings.h" 34.40 + 34.41 +typedef struct { 34.42 + char *dir; 34.43 + int spaces; 34.44 +} scanner_t; 34.45 + 34.46 +#ifdef _cplusplus 34.47 +extern "C" { 34.48 +#endif 34.49 + 34.50 +int scanDirectory(scanner_t scanner, settings_t* settings); 34.51 + 34.52 +#ifdef _cplusplus 34.53 +} 34.54 +#endif 34.55 + 34.56 +#endif /* SCANNER_H_ */
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/src/settings.c Fri Dec 28 15:44:28 2012 +0100 35.3 @@ -0,0 +1,61 @@ 35.4 +/* 35.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 35.6 + * Copyright 2011 Mike Becker. All rights reserved. 35.7 + * 35.8 + * Redistribution and use in source and binary forms, with or without 35.9 + * modification, are permitted provided that the following conditions are met: 35.10 + * 35.11 + * 1. Redistributions of source code must retain the above copyright 35.12 + * notice, this list of conditions and the following disclaimer. 35.13 + * 35.14 + * 2. Redistributions in binary form must reproduce the above copyright 35.15 + * notice, this list of conditions and the following disclaimer in the 35.16 + * documentation and/or other materials provided with the distribution. 35.17 + * 35.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 35.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 35.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 35.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 35.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35.28 + * 35.29 + * settings.c 35.30 + * 35.31 + * Created on: 15.09.2011 35.32 + * Author: Mike 35.33 + */ 35.34 + 35.35 +#include "settings.h" 35.36 + 35.37 +settings_t* new_settings_t() { 35.38 + settings_t *settings = malloc(sizeof(settings_t)); 35.39 + if (settings != NULL) { 35.40 + #ifdef _WIN32 35.41 + settings->fileSeparator = '\\'; 35.42 + #else 35.43 + settings->fileSeparator = '/'; 35.44 + #endif /* _WIN32 */ 35.45 + settings->recursive = false; 35.46 + settings->matchesOnly = false; 35.47 + settings->includeSuffixes = new_string_list_t(); 35.48 + settings->excludeSuffixes = new_string_list_t(); 35.49 + settings->verbose = true; 35.50 + settings->bfileHeuristics = new_bfile_heuristics_t(); 35.51 + settings->confusing_lnlen = false; 35.52 + settings->regex = new_regex_parser_t(); 35.53 + } 35.54 + 35.55 + return settings; 35.56 +} 35.57 + 35.58 +void destroy_settings_t(settings_t* settings) { 35.59 + destroy_regex_parser_t(settings->regex); 35.60 + destroy_string_list_t(settings->includeSuffixes); 35.61 + destroy_string_list_t(settings->excludeSuffixes); 35.62 + destroy_bfile_heuristics_t(settings->bfileHeuristics); 35.63 + free(settings); 35.64 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/src/settings.h Fri Dec 28 15:44:28 2012 +0100 36.3 @@ -0,0 +1,63 @@ 36.4 +/* 36.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 36.6 + * Copyright 2011 Mike Becker. All rights reserved. 36.7 + * 36.8 + * Redistribution and use in source and binary forms, with or without 36.9 + * modification, are permitted provided that the following conditions are met: 36.10 + * 36.11 + * 1. Redistributions of source code must retain the above copyright 36.12 + * notice, this list of conditions and the following disclaimer. 36.13 + * 36.14 + * 2. Redistributions in binary form must reproduce the above copyright 36.15 + * notice, this list of conditions and the following disclaimer in the 36.16 + * documentation and/or other materials provided with the distribution. 36.17 + * 36.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 36.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 36.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 36.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 36.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 36.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36.28 + * 36.29 + * settings.h 36.30 + * 36.31 + * Created on: 15.09.2011 36.32 + * Author: Mike 36.33 + */ 36.34 + 36.35 +#ifndef SETTINGS_H_ 36.36 +#define SETTINGS_H_ 36.37 + 36.38 +#include "stdinc.h" 36.39 +#include "string_list.h" 36.40 +#include "bfile_heuristics.h" 36.41 +#include "regex_parser.h" 36.42 + 36.43 +typedef struct _settings { 36.44 + string_list_t* includeSuffixes; 36.45 + string_list_t* excludeSuffixes; 36.46 + regex_parser_t* regex; 36.47 + bfile_heuristics_t* bfileHeuristics; 36.48 + char fileSeparator; 36.49 + bool recursive; 36.50 + bool matchesOnly; 36.51 + bool verbose; 36.52 + bool confusing_lnlen; /* this flag is set by the scanner */ 36.53 +} settings_t; 36.54 + 36.55 +#ifdef _cplusplus 36.56 +extern "C" { 36.57 +#endif 36.58 + 36.59 +settings_t* new_settings_t(); 36.60 +void destroy_settings_t(settings_t*); 36.61 + 36.62 +#ifdef _cplusplus 36.63 +} 36.64 +#endif 36.65 + 36.66 +#endif /* SETTINGS_H_ */
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/src/stdinc.h Fri Dec 28 15:44:28 2012 +0100 37.3 @@ -0,0 +1,41 @@ 37.4 +/* 37.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 37.6 + * Copyright 2011 Mike Becker. All rights reserved. 37.7 + * 37.8 + * Redistribution and use in source and binary forms, with or without 37.9 + * modification, are permitted provided that the following conditions are met: 37.10 + * 37.11 + * 1. Redistributions of source code must retain the above copyright 37.12 + * notice, this list of conditions and the following disclaimer. 37.13 + * 37.14 + * 2. Redistributions in binary form must reproduce the above copyright 37.15 + * notice, this list of conditions and the following disclaimer in the 37.16 + * documentation and/or other materials provided with the distribution. 37.17 + * 37.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 37.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 37.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 37.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 37.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 37.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 37.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37.28 + * 37.29 + * stdinc.h 37.30 + * 37.31 + * Created on: 15.09.2011 37.32 + * Author: Mike 37.33 + */ 37.34 + 37.35 +#ifndef STDINC_H_ 37.36 +#define STDINC_H_ 37.37 + 37.38 +#include <stdio.h> 37.39 +#include <string.h> 37.40 +#include <stdbool.h> 37.41 +#include <stdlib.h> 37.42 +#include <dirent.h> 37.43 + 37.44 +#endif /* STDINC_H_ */
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/src/stream.c Fri Dec 28 15:44:28 2012 +0100 38.3 @@ -0,0 +1,49 @@ 38.4 +/* 38.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 38.6 + * Copyright 2011 Mike Becker. All rights reserved. 38.7 + * 38.8 + * Redistribution and use in source and binary forms, with or without 38.9 + * modification, are permitted provided that the following conditions are met: 38.10 + * 38.11 + * 1. Redistributions of source code must retain the above copyright 38.12 + * notice, this list of conditions and the following disclaimer. 38.13 + * 38.14 + * 2. Redistributions in binary form must reproduce the above copyright 38.15 + * notice, this list of conditions and the following disclaimer in the 38.16 + * documentation and/or other materials provided with the distribution. 38.17 + * 38.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 38.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 38.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 38.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 38.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 38.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 38.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38.28 + * 38.29 + * stream.c 38.30 + * 38.31 + * Created on: 20.09.2011 38.32 + * Author: Mike 38.33 + */ 38.34 + 38.35 +#include "stream.h" 38.36 + 38.37 +void close_stdout() { 38.38 +#ifdef _WIN32 38.39 + _STREAM_STDOUT = dup(STDOUT_FILENO); 38.40 +#endif 38.41 + stdout = freopen("/dev/null", "w", stdout); 38.42 +} 38.43 + 38.44 +void reopen_stdout() { 38.45 +#ifdef _WIN32 38.46 + close(STDOUT_FILENO); 38.47 + fdopen(dup(_STREAM_STDOUT), "wa"); 38.48 + close(_STREAM_STDOUT); 38.49 +#else 38.50 + stdout = freopen("/dev/stdout", "w", stdout); 38.51 +#endif 38.52 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/src/stream.h Fri Dec 28 15:44:28 2012 +0100 39.3 @@ -0,0 +1,52 @@ 39.4 +/* 39.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 39.6 + * Copyright 2011 Mike Becker. All rights reserved. 39.7 + * 39.8 + * Redistribution and use in source and binary forms, with or without 39.9 + * modification, are permitted provided that the following conditions are met: 39.10 + * 39.11 + * 1. Redistributions of source code must retain the above copyright 39.12 + * notice, this list of conditions and the following disclaimer. 39.13 + * 39.14 + * 2. Redistributions in binary form must reproduce the above copyright 39.15 + * notice, this list of conditions and the following disclaimer in the 39.16 + * documentation and/or other materials provided with the distribution. 39.17 + * 39.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 39.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 39.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 39.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 39.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 39.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 39.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 39.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39.28 + * 39.29 + * stream.h 39.30 + * 39.31 + * Created on: 20.09.2011 39.32 + * Author: Mike 39.33 + */ 39.34 + 39.35 +#ifndef STREAM_H_ 39.36 +#define STREAM_H_ 39.37 + 39.38 +#include "stdinc.h" 39.39 + 39.40 +#ifdef _WIN32 39.41 +int _STREAM_STDOUT; 39.42 +#endif 39.43 + 39.44 +#ifdef _cplusplus 39.45 +extern "C" { 39.46 +#endif 39.47 + 39.48 +void close_stdout(); 39.49 +void reopen_stdout(); 39.50 + 39.51 +#ifdef _cplusplus 39.52 +extern "C" } 39.53 +#endif 39.54 + 39.55 +#endif /* STREAM_H_ */
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/src/string_list.c Fri Dec 28 15:44:28 2012 +0100 40.3 @@ -0,0 +1,58 @@ 40.4 +/* 40.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 40.6 + * Copyright 2011 Mike Becker. All rights reserved. 40.7 + * 40.8 + * Redistribution and use in source and binary forms, with or without 40.9 + * modification, are permitted provided that the following conditions are met: 40.10 + * 40.11 + * 1. Redistributions of source code must retain the above copyright 40.12 + * notice, this list of conditions and the following disclaimer. 40.13 + * 40.14 + * 2. Redistributions in binary form must reproduce the above copyright 40.15 + * notice, this list of conditions and the following disclaimer in the 40.16 + * documentation and/or other materials provided with the distribution. 40.17 + * 40.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 40.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 40.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 40.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 40.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 40.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 40.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40.28 + * 40.29 + * string_list.c 40.30 + * 40.31 + * Created on: 15.09.2011 40.32 + * Author: Mike 40.33 + */ 40.34 + 40.35 +#include "string_list.h" 40.36 + 40.37 +string_list_t* new_string_list_t() { 40.38 + string_list_t* stringList = malloc(sizeof(string_list_t)); 40.39 + stringList->count = 0; 40.40 + stringList->items = NULL; 40.41 + 40.42 + return stringList; 40.43 +} 40.44 + 40.45 +void destroy_string_list_t(string_list_t* list) { 40.46 + if (list->items != NULL) { 40.47 + free(list->items); 40.48 + } 40.49 + free(list); 40.50 +} 40.51 + 40.52 +void add_string(string_list_t* list, char* item) { 40.53 + char** reallocated_list = 40.54 + realloc(list->items, sizeof(char*) * (list->count + 1)); 40.55 + if (reallocated_list != NULL) { 40.56 + list->items = reallocated_list; 40.57 + list->items[list->count] = item; 40.58 + list->count++; 40.59 + } 40.60 +} 40.61 +
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 41.2 +++ b/src/string_list.h Fri Dec 28 15:44:28 2012 +0100 41.3 @@ -0,0 +1,54 @@ 41.4 +/* 41.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 41.6 + * Copyright 2011 Mike Becker. All rights reserved. 41.7 + * 41.8 + * Redistribution and use in source and binary forms, with or without 41.9 + * modification, are permitted provided that the following conditions are met: 41.10 + * 41.11 + * 1. Redistributions of source code must retain the above copyright 41.12 + * notice, this list of conditions and the following disclaimer. 41.13 + * 41.14 + * 2. Redistributions in binary form must reproduce the above copyright 41.15 + * notice, this list of conditions and the following disclaimer in the 41.16 + * documentation and/or other materials provided with the distribution. 41.17 + * 41.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 41.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 41.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 41.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 41.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 41.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 41.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41.28 + * 41.29 + * string_list.h 41.30 + * 41.31 + * Created on: 15.09.2011 41.32 + * Author: Mike 41.33 + */ 41.34 + 41.35 +#ifndef STRING_LIST_H_ 41.36 +#define STRING_LIST_H_ 41.37 + 41.38 +#include "stdinc.h" 41.39 + 41.40 +typedef struct _string_list { 41.41 + size_t count; 41.42 + char** items; 41.43 +} string_list_t; 41.44 + 41.45 +#ifdef _cplusplus 41.46 +extern "C" { 41.47 +#endif 41.48 + 41.49 +string_list_t* new_string_list_t(); 41.50 +void destroy_string_list_t(string_list_t*); 41.51 +void add_string(string_list_t*, char*); 41.52 + 41.53 +#ifdef _cplusplus 41.54 +} 41.55 +#endif 41.56 + 41.57 +#endif /* STRING_LIST_H_ */
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/src/suffix_fnc.c Fri Dec 28 15:44:28 2012 +0100 42.3 @@ -0,0 +1,49 @@ 42.4 +/* 42.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 42.6 + * Copyright 2011 Mike Becker. All rights reserved. 42.7 + * 42.8 + * Redistribution and use in source and binary forms, with or without 42.9 + * modification, are permitted provided that the following conditions are met: 42.10 + * 42.11 + * 1. Redistributions of source code must retain the above copyright 42.12 + * notice, this list of conditions and the following disclaimer. 42.13 + * 42.14 + * 2. Redistributions in binary form must reproduce the above copyright 42.15 + * notice, this list of conditions and the following disclaimer in the 42.16 + * documentation and/or other materials provided with the distribution. 42.17 + * 42.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 42.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 42.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 42.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 42.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 42.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 42.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 42.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42.28 + * 42.29 + * suffix_fnc.c 42.30 + * 42.31 + * Created on: 15.09.2011 42.32 + * Author: Mike 42.33 + */ 42.34 + 42.35 +#include "suffix_fnc.h" 42.36 + 42.37 +bool testSuffix(char* filename, string_list_t* list) { 42.38 + bool ret = false; 42.39 + int tokenlen, fnamelen = strlen(filename); 42.40 + for (int t = 0 ; t < list->count ; t++) { 42.41 + tokenlen = strlen(list->items[t]); 42.42 + if (fnamelen >= tokenlen && tokenlen > 0) { 42.43 + if (strncmp(filename+fnamelen-tokenlen, 42.44 + list->items[t], tokenlen) == 0) { 42.45 + ret = true; 42.46 + break; 42.47 + } 42.48 + } 42.49 + } 42.50 + return ret; 42.51 +} 42.52 +
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/src/suffix_fnc.h Fri Dec 28 15:44:28 2012 +0100 43.3 @@ -0,0 +1,40 @@ 43.4 +/* 43.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 43.6 + * Copyright 2011 Mike Becker. All rights reserved. 43.7 + * 43.8 + * Redistribution and use in source and binary forms, with or without 43.9 + * modification, are permitted provided that the following conditions are met: 43.10 + * 43.11 + * 1. Redistributions of source code must retain the above copyright 43.12 + * notice, this list of conditions and the following disclaimer. 43.13 + * 43.14 + * 2. Redistributions in binary form must reproduce the above copyright 43.15 + * notice, this list of conditions and the following disclaimer in the 43.16 + * documentation and/or other materials provided with the distribution. 43.17 + * 43.18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 43.19 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 43.21 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 43.22 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 43.23 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 43.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 43.25 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 43.26 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43.27 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 43.28 + * 43.29 + * suffix_fnc.h 43.30 + * 43.31 + * Created on: 15.09.2011 43.32 + * Author: Mike 43.33 + */ 43.34 + 43.35 +#ifndef SUFFIX_FNC_H_ 43.36 +#define SUFFIX_FNC_H_ 43.37 + 43.38 +#include "stdinc.h" 43.39 +#include "string_list.h" 43.40 + 43.41 +bool testSuffix(char*, string_list_t*); 43.42 + 43.43 +#endif /* SUFFIX_FNC_H_ */
44.1 --- a/stdinc.h Tue Oct 02 10:49:25 2012 +0200 44.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 44.3 @@ -1,17 +0,0 @@ 44.4 -/* 44.5 - * stdinc.h 44.6 - * 44.7 - * Created on: 15.09.2011 44.8 - * Author: Mike 44.9 - */ 44.10 - 44.11 -#ifndef STDINC_H_ 44.12 -#define STDINC_H_ 44.13 - 44.14 -#include <stdio.h> 44.15 -#include <string.h> 44.16 -#include <stdbool.h> 44.17 -#include <stdlib.h> 44.18 -#include <dirent.h> 44.19 - 44.20 -#endif /* STDINC_H_ */
45.1 --- a/stream.c Tue Oct 02 10:49:25 2012 +0200 45.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 45.3 @@ -1,25 +0,0 @@ 45.4 -/* 45.5 - * stream.c 45.6 - * 45.7 - * Created on: 20.09.2011 45.8 - * Author: Mike 45.9 - */ 45.10 - 45.11 -#include "stream.h" 45.12 - 45.13 -void close_stdout() { 45.14 -#ifdef _WIN32 45.15 - _STREAM_STDOUT = dup(STDOUT_FILENO); 45.16 -#endif 45.17 - freopen("/dev/null", "w", stdout); 45.18 -} 45.19 - 45.20 -void reopen_stdout() { 45.21 -#ifdef _WIN32 45.22 - close(STDOUT_FILENO); 45.23 - fdopen(dup(_STREAM_STDOUT), "wa"); 45.24 - close(_STREAM_STDOUT); 45.25 -#else 45.26 - freopen("/dev/stdout", "w", stdout); 45.27 -#endif 45.28 -}
46.1 --- a/stream.h Tue Oct 02 10:49:25 2012 +0200 46.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 46.3 @@ -1,28 +0,0 @@ 46.4 -/* 46.5 - * stream.h 46.6 - * 46.7 - * Created on: 20.09.2011 46.8 - * Author: Mike 46.9 - */ 46.10 - 46.11 -#ifndef STREAM_H_ 46.12 -#define STREAM_H_ 46.13 - 46.14 -#include "stdinc.h" 46.15 - 46.16 -#ifdef _WIN32 46.17 -int _STREAM_STDOUT; 46.18 -#endif 46.19 - 46.20 -#ifdef _cplusplus 46.21 -extern "C" { 46.22 -#endif 46.23 - 46.24 -void close_stdout(); 46.25 -void reopen_stdout(); 46.26 - 46.27 -#ifdef _cplusplus 46.28 -extern "C" } 46.29 -#endif 46.30 - 46.31 -#endif /* STREAM_H_ */
47.1 --- a/string_list.c Tue Oct 02 10:49:25 2012 +0200 47.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 47.3 @@ -1,34 +0,0 @@ 47.4 -/* 47.5 - * string_list.c 47.6 - * 47.7 - * Created on: 15.09.2011 47.8 - * Author: Mike 47.9 - */ 47.10 - 47.11 -#include "string_list.h" 47.12 - 47.13 -string_list_t* new_string_list_t() { 47.14 - string_list_t* stringList = malloc(sizeof(string_list_t)); 47.15 - stringList->count = 0; 47.16 - stringList->items = NULL; 47.17 - 47.18 - return stringList; 47.19 -} 47.20 - 47.21 -void destroy_string_list_t(string_list_t* list) { 47.22 - if (list->items != NULL) { 47.23 - free(list->items); 47.24 - } 47.25 - free(list); 47.26 -} 47.27 - 47.28 -void add_string(string_list_t* list, char* item) { 47.29 - char** reallocated_list = 47.30 - realloc(list->items, sizeof(char*) * (list->count + 1)); 47.31 - if (reallocated_list != NULL) { 47.32 - list->items = reallocated_list; 47.33 - list->items[list->count] = item; 47.34 - list->count++; 47.35 - } 47.36 -} 47.37 -
48.1 --- a/string_list.h Tue Oct 02 10:49:25 2012 +0200 48.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 48.3 @@ -1,30 +0,0 @@ 48.4 -/* 48.5 - * string_list.h 48.6 - * 48.7 - * Created on: 15.09.2011 48.8 - * Author: Mike 48.9 - */ 48.10 - 48.11 -#ifndef STRING_LIST_H_ 48.12 -#define STRING_LIST_H_ 48.13 - 48.14 -#include "stdinc.h" 48.15 - 48.16 -typedef struct _string_list { 48.17 - size_t count; 48.18 - char** items; 48.19 -} string_list_t; 48.20 - 48.21 -#ifdef _cplusplus 48.22 -extern "C" { 48.23 -#endif 48.24 - 48.25 -string_list_t* new_string_list_t(); 48.26 -void destroy_string_list_t(string_list_t*); 48.27 -void add_string(string_list_t*, char*); 48.28 - 48.29 -#ifdef _cplusplus 48.30 -} 48.31 -#endif 48.32 - 48.33 -#endif /* STRING_LIST_H_ */
49.1 --- a/suffix_fnc.c Tue Oct 02 10:49:25 2012 +0200 49.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 49.3 @@ -1,25 +0,0 @@ 49.4 -/* 49.5 - * suffix_fnc.c 49.6 - * 49.7 - * Created on: 15.09.2011 49.8 - * Author: Mike 49.9 - */ 49.10 - 49.11 -#include "suffix_fnc.h" 49.12 - 49.13 -bool testSuffix(char* filename, string_list_t* list) { 49.14 - bool ret = false; 49.15 - int tokenlen, fnamelen = strlen(filename); 49.16 - for (int t = 0 ; t < list->count ; t++) { 49.17 - tokenlen = strlen(list->items[t]); 49.18 - if (fnamelen >= tokenlen && tokenlen > 0) { 49.19 - if (strncmp(filename+fnamelen-tokenlen, 49.20 - list->items[t], tokenlen) == 0) { 49.21 - ret = true; 49.22 - break; 49.23 - } 49.24 - } 49.25 - } 49.26 - return ret; 49.27 -} 49.28 -
50.1 --- a/suffix_fnc.h Tue Oct 02 10:49:25 2012 +0200 50.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 50.3 @@ -1,16 +0,0 @@ 50.4 -/* 50.5 - * suffix_fnc.h 50.6 - * 50.7 - * Created on: 15.09.2011 50.8 - * Author: Mike 50.9 - */ 50.10 - 50.11 -#ifndef SUFFIX_FNC_H_ 50.12 -#define SUFFIX_FNC_H_ 50.13 - 50.14 -#include "stdinc.h" 50.15 -#include "string_list.h" 50.16 - 50.17 -bool testSuffix(char*, string_list_t*); 50.18 - 50.19 -#endif /* SUFFIX_FNC_H_ */