Fri, 16 Sep 2011 10:36:45 +0200
some minor fixes + makefile now injects revisionnumber into cline.h
Makefile | file | annotate | diff | comparison | revisions | |
cline.c | file | annotate | diff | comparison | revisions | |
cline.h | file | annotate | diff | comparison | revisions | |
scanner.c | file | annotate | diff | comparison | revisions |
--- a/Makefile Fri Sep 16 09:59:20 2011 +0200 +++ b/Makefile Fri Sep 16 10:36:45 2011 +0200 @@ -1,10 +1,19 @@ CC = gcc BUILDDIR = build/ OBJ = $(shell ls | grep \.c | sed 's/^\([^.]*\)\.c/${BUILDDIR:/=\/}\1.o/g' | tr '\n' ' ') -BIN = ${BUILDDIR}/cline +BIN = ${BUILDDIR}cline + +all: addrnum ${OBJ} remrnum + ${CC} -o ${BIN} ${OBJ} -all: ${OBJ} - ${CC} -o ${BIN} ${OBJ} +addrnum: + rm build/cline.o + mv cline.h cline.src + cat cline.src | sed "s/VERSION.*/VERSION=\"$(shell hg identify -i)\";/g" > cline.h + +remrnum: + rm cline.h + mv cline.src cline.h ${BUILDDIR}%.o: %.c mkdir -p ${BUILDDIR}
--- a/cline.c Fri Sep 16 09:59:20 2011 +0200 +++ b/cline.c Fri Sep 16 10:36:45 2011 +0200 @@ -11,7 +11,6 @@ #include "arguments.h" void printHelpText() { - // Help text const char* helpText = "\nUsage:" "\n cline [-hrm][-s suffix][<directory>]" @@ -26,6 +25,7 @@ "\n -S <suffixes> - count any file except those with these suffixes" "\n (separated by commas)" "\n -r, -R - includes subdirectories" + "\n -v, --version - print out version information" "\n\n" "The default call without any options is:" "\n cline ./\n" @@ -36,6 +36,12 @@ printf(helpText); } +int exit_with_version(settings_t* settings) { + printf("cline - Version: %s", VERSION); + destroy_settings_t(settings); + return 0; +} + int exit_with_help(settings_t* settings, int code) { printHelpText(); destroy_settings_t(settings); @@ -54,40 +60,27 @@ // Get arguments char* directory = "./"; char* suffix = " "; - bool showHelp = false; int checked = 0; for (int t = 1 ; t < argc ; t++) { - int argflags = checkArgument(argv[t], "hsSrRm"); + int argflags = checkArgument(argv[t], "hsSrRmv"); - // s - if ((argflags & 2) > 0) { + // s, S + if ((argflags & 6) > 0) { if (registerArgument(&checked, 6)) { return exit_with_help(settings, 1); } - settings->includeSuffixes = true; + settings->includeSuffixes = (argflags & 2) > 0; t++; if (t >= argc) { return exit_with_help(settings, 1); } suffix = argv[t]; } - // S - if ((argflags & 4) > 0) { - if (registerArgument(&checked, 6)) { - return exit_with_help(settings, 1); - } - settings->includeSuffixes = false; - t++; - if (t >= argc) { - return exit_with_help(settings, 1); - } - suffix = argv[t]; - } // h if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { - return exit_with_help(settings, 1); + return exit_with_help(settings, 0); } // r, R if ((argflags & 24) > 0) { @@ -103,6 +96,10 @@ } settings->matchesOnly = true; } + // v + if ((argflags & 64) > 0 || strcmp(argv[t], "--version") == 0) { + return exit_with_version(settings); + } // Path if (argflags == 0) { if (registerArgument(&checked, 1024)) {
--- a/cline.h Fri Sep 16 09:59:20 2011 +0200 +++ b/cline.h Fri Sep 16 10:36:45 2011 +0200 @@ -8,6 +8,8 @@ #ifndef CLINE_H_ #define CLINE_H_ +const char* VERSION=""; // will be replaced by makefile + #include "stdinc.h" #include "settings.h" @@ -16,6 +18,7 @@ #endif void printHelpText(); +int exit_with_version(settings_t*); int exit_with_help(settings_t*, int); #ifdef _cplusplus
--- a/scanner.c Fri Sep 16 09:59:20 2011 +0200 +++ b/scanner.c Fri Sep 16 10:36:45 2011 +0200 @@ -27,15 +27,16 @@ entryname[spaces] = 0; strcat(entryname, entry->d_name); + char filename[(1+strlen(currdir)+strlen(entry->d_name))]; + strcpy(filename, currdir); + strncat(filename, &settings->fileSeparator, 1); + strcat(filename, entry->d_name); + // Check for subdirectory - char subdirname[(1+strlen(currdir)+strlen(entry->d_name))]; - strcpy(subdirname, currdir); - strncat(subdirname, &settings->fileSeparator, 1); - strcat(subdirname, entry->d_name); - if ((subdir = opendir(subdirname)) != NULL) { + if ((subdir = opendir(filename)) != NULL) { printf("%-60s\n", entryname); if (settings->recursive) { - lineSum += scanDirectory(subdir, spaces+1, subdirname, settings); + lineSum += scanDirectory(subdir, spaces+1, filename, settings); } closedir(subdir); continue; @@ -43,10 +44,10 @@ // Count lines lines = 0; - char filename[(1+strlen(currdir)+strlen(entry->d_name))]; + /* char filename[(1+strlen(currdir)+strlen(entry->d_name))]; strcpy(filename, currdir); strncat(filename, &settings->fileSeparator, 1); - strcat(filename, entry->d_name); + strcat(filename, entry->d_name); */ if (testSuffix(filename, settings)) { FILE *file = fopen(filename, "r"); if (file == NULL) {