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 |
1.1 --- a/Makefile Fri Sep 16 09:59:20 2011 +0200 1.2 +++ b/Makefile Fri Sep 16 10:36:45 2011 +0200 1.3 @@ -1,11 +1,20 @@ 1.4 CC = gcc 1.5 BUILDDIR = build/ 1.6 OBJ = $(shell ls | grep \.c | sed 's/^\([^.]*\)\.c/${BUILDDIR:/=\/}\1.o/g' | tr '\n' ' ') 1.7 -BIN = ${BUILDDIR}/cline 1.8 +BIN = ${BUILDDIR}cline 1.9 1.10 -all: ${OBJ} 1.11 +all: addrnum ${OBJ} remrnum 1.12 ${CC} -o ${BIN} ${OBJ} 1.13 1.14 +addrnum: 1.15 + rm build/cline.o 1.16 + mv cline.h cline.src 1.17 + cat cline.src | sed "s/VERSION.*/VERSION=\"$(shell hg identify -i)\";/g" > cline.h 1.18 + 1.19 +remrnum: 1.20 + rm cline.h 1.21 + mv cline.src cline.h 1.22 + 1.23 ${BUILDDIR}%.o: %.c 1.24 mkdir -p ${BUILDDIR} 1.25 ${CC} -c -std=c99 -o ${BUILDDIR}$*.o $<
2.1 --- a/cline.c Fri Sep 16 09:59:20 2011 +0200 2.2 +++ b/cline.c Fri Sep 16 10:36:45 2011 +0200 2.3 @@ -11,7 +11,6 @@ 2.4 #include "arguments.h" 2.5 2.6 void printHelpText() { 2.7 - // Help text 2.8 const char* helpText = 2.9 "\nUsage:" 2.10 "\n cline [-hrm][-s suffix][<directory>]" 2.11 @@ -26,6 +25,7 @@ 2.12 "\n -S <suffixes> - count any file except those with these suffixes" 2.13 "\n (separated by commas)" 2.14 "\n -r, -R - includes subdirectories" 2.15 + "\n -v, --version - print out version information" 2.16 "\n\n" 2.17 "The default call without any options is:" 2.18 "\n cline ./\n" 2.19 @@ -36,6 +36,12 @@ 2.20 printf(helpText); 2.21 } 2.22 2.23 +int exit_with_version(settings_t* settings) { 2.24 + printf("cline - Version: %s", VERSION); 2.25 + destroy_settings_t(settings); 2.26 + return 0; 2.27 +} 2.28 + 2.29 int exit_with_help(settings_t* settings, int code) { 2.30 printHelpText(); 2.31 destroy_settings_t(settings); 2.32 @@ -54,40 +60,27 @@ 2.33 // Get arguments 2.34 char* directory = "./"; 2.35 char* suffix = " "; 2.36 - bool showHelp = false; 2.37 int checked = 0; 2.38 2.39 for (int t = 1 ; t < argc ; t++) { 2.40 2.41 - int argflags = checkArgument(argv[t], "hsSrRm"); 2.42 + int argflags = checkArgument(argv[t], "hsSrRmv"); 2.43 2.44 - // s 2.45 - if ((argflags & 2) > 0) { 2.46 + // s, S 2.47 + if ((argflags & 6) > 0) { 2.48 if (registerArgument(&checked, 6)) { 2.49 return exit_with_help(settings, 1); 2.50 } 2.51 - settings->includeSuffixes = true; 2.52 + settings->includeSuffixes = (argflags & 2) > 0; 2.53 t++; 2.54 if (t >= argc) { 2.55 return exit_with_help(settings, 1); 2.56 } 2.57 suffix = argv[t]; 2.58 } 2.59 - // S 2.60 - if ((argflags & 4) > 0) { 2.61 - if (registerArgument(&checked, 6)) { 2.62 - return exit_with_help(settings, 1); 2.63 - } 2.64 - settings->includeSuffixes = false; 2.65 - t++; 2.66 - if (t >= argc) { 2.67 - return exit_with_help(settings, 1); 2.68 - } 2.69 - suffix = argv[t]; 2.70 - } 2.71 // h 2.72 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { 2.73 - return exit_with_help(settings, 1); 2.74 + return exit_with_help(settings, 0); 2.75 } 2.76 // r, R 2.77 if ((argflags & 24) > 0) { 2.78 @@ -103,6 +96,10 @@ 2.79 } 2.80 settings->matchesOnly = true; 2.81 } 2.82 + // v 2.83 + if ((argflags & 64) > 0 || strcmp(argv[t], "--version") == 0) { 2.84 + return exit_with_version(settings); 2.85 + } 2.86 // Path 2.87 if (argflags == 0) { 2.88 if (registerArgument(&checked, 1024)) {
3.1 --- a/cline.h Fri Sep 16 09:59:20 2011 +0200 3.2 +++ b/cline.h Fri Sep 16 10:36:45 2011 +0200 3.3 @@ -8,6 +8,8 @@ 3.4 #ifndef CLINE_H_ 3.5 #define CLINE_H_ 3.6 3.7 +const char* VERSION=""; // will be replaced by makefile 3.8 + 3.9 #include "stdinc.h" 3.10 #include "settings.h" 3.11 3.12 @@ -16,6 +18,7 @@ 3.13 #endif 3.14 3.15 void printHelpText(); 3.16 +int exit_with_version(settings_t*); 3.17 int exit_with_help(settings_t*, int); 3.18 3.19 #ifdef _cplusplus
4.1 --- a/scanner.c Fri Sep 16 09:59:20 2011 +0200 4.2 +++ b/scanner.c Fri Sep 16 10:36:45 2011 +0200 4.3 @@ -27,15 +27,16 @@ 4.4 entryname[spaces] = 0; 4.5 strcat(entryname, entry->d_name); 4.6 4.7 + char filename[(1+strlen(currdir)+strlen(entry->d_name))]; 4.8 + strcpy(filename, currdir); 4.9 + strncat(filename, &settings->fileSeparator, 1); 4.10 + strcat(filename, entry->d_name); 4.11 + 4.12 // Check for subdirectory 4.13 - char subdirname[(1+strlen(currdir)+strlen(entry->d_name))]; 4.14 - strcpy(subdirname, currdir); 4.15 - strncat(subdirname, &settings->fileSeparator, 1); 4.16 - strcat(subdirname, entry->d_name); 4.17 - if ((subdir = opendir(subdirname)) != NULL) { 4.18 + if ((subdir = opendir(filename)) != NULL) { 4.19 printf("%-60s\n", entryname); 4.20 if (settings->recursive) { 4.21 - lineSum += scanDirectory(subdir, spaces+1, subdirname, settings); 4.22 + lineSum += scanDirectory(subdir, spaces+1, filename, settings); 4.23 } 4.24 closedir(subdir); 4.25 continue; 4.26 @@ -43,10 +44,10 @@ 4.27 4.28 // Count lines 4.29 lines = 0; 4.30 - char filename[(1+strlen(currdir)+strlen(entry->d_name))]; 4.31 + /* char filename[(1+strlen(currdir)+strlen(entry->d_name))]; 4.32 strcpy(filename, currdir); 4.33 strncat(filename, &settings->fileSeparator, 1); 4.34 - strcat(filename, entry->d_name); 4.35 + strcat(filename, entry->d_name); */ 4.36 if (testSuffix(filename, settings)) { 4.37 FILE *file = fopen(filename, "r"); 4.38 if (file == NULL) {