# HG changeset patch # User Mike Becker # Date 1316162205 -7200 # Node ID ee9333c91dda2d125f83e6af8a36d18ea8e6c4e7 # Parent 51b1ba3776b1ee584b2dd26d8da283d8f83828d6 some minor fixes + makefile now injects revisionnumber into cline.h diff -r 51b1ba3776b1 -r ee9333c91dda Makefile --- a/Makefile Fri Sep 16 09:59:20 2011 +0200 +++ b/Makefile Fri Sep 16 10:36:45 2011 +0200 @@ -1,11 +1,20 @@ 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: ${OBJ} +all: addrnum ${OBJ} remrnum ${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} ${CC} -c -std=c99 -o ${BUILDDIR}$*.o $< diff -r 51b1ba3776b1 -r ee9333c91dda cline.c --- 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][]" @@ -26,6 +25,7 @@ "\n -S - 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)) { diff -r 51b1ba3776b1 -r ee9333c91dda cline.h --- 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 diff -r 51b1ba3776b1 -r ee9333c91dda scanner.c --- 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) {