# HG changeset patch # User Mike Becker # Date 1316524768 -7200 # Node ID bc9a0fefd892172bf8ab334366bbdf5d90e2f6a9 # Parent 9a262e046ab840598340aeee34f8d0407cb7f5ee fixed makefile to run safely on compile errors + added -V option to cline diff -r 9a262e046ab8 -r bc9a0fefd892 .cproject --- a/.cproject Mon Sep 19 08:11:08 2011 +0200 +++ b/.cproject Tue Sep 20 15:19:28 2011 +0200 @@ -20,7 +20,7 @@ - + diff -r 9a262e046ab8 -r bc9a0fefd892 Makefile --- a/Makefile Mon Sep 19 08:11:08 2011 +0200 +++ b/Makefile Tue Sep 20 15:19:28 2011 +0200 @@ -1,23 +1,32 @@ CC = gcc BUILDDIR = build/ -OBJ = $(shell ls | grep \.c | sed 's/^\([^.]*\)\.c/${BUILDDIR:/=\/}\1.o/g' | tr '\n' ' ') +OBJ = $(shell ls | grep '\.c' | sed 's/^\([^.]*\)\.c$$/${BUILDDIR:/=\/}\1.o/g' | tr '\n' ' ') BIN = ${BUILDDIR}cline -all: addrnum ${OBJ} remrnum +.PHONY: setup run-compile teardown + +all: setup run-compile teardown + + +run-compile: + -${MAKE} compile + +compile: ${OBJ} ${CC} -o ${BIN} ${OBJ} -addrnum: - rm build/cline.o +setup: + mkdir -p ${BUILDDIR} + rm -f build/cline.o mv cline.h cline.src - cat cline.src | sed "s/VERSION.*/VERSION=\"$(shell hg identify -i)\";/g" > cline.h + cat cline.src | sed "s/VERSION.*/VERSION=\"$(shell hg identify -n) ($(shell hg identify -i))\";/g" > cline.h -remrnum: - rm cline.h +teardown: + rm -f cline.h mv cline.src cline.h ${BUILDDIR}%.o: %.c - mkdir -p ${BUILDDIR} ${CC} -c -std=c99 -o ${BUILDDIR}$*.o $< clean: - rm build/* + rm -f build/* + \ No newline at end of file diff -r 9a262e046ab8 -r bc9a0fefd892 cline.c --- a/cline.c Mon Sep 19 08:11:08 2011 +0200 +++ b/cline.c Tue Sep 20 15:19:28 2011 +0200 @@ -9,6 +9,7 @@ #include "scanner.h" #include "settings.h" #include "arguments.h" +#include "stream.h" void printHelpText() { const char* helpText = @@ -26,6 +27,7 @@ "\n (separated by commas)" "\n -r, -R - includes subdirectories" "\n -v, --version - print out version information" + "\n -V - turn verbose output off, print the result only" "\n\n" "The default call without any options is:" "\n cline ./\n" @@ -37,7 +39,7 @@ } int exit_with_version(settings_t* settings) { - printf("cline - Version: %s", VERSION); + printf("cline - Revision: %s", VERSION); destroy_settings_t(settings); return 0; } @@ -64,7 +66,7 @@ for (int t = 1 ; t < argc ; t++) { - int argflags = checkArgument(argv[t], "hsSrRmv"); + int argflags = checkArgument(argv[t], "hsSrRmvV"); // s, S if ((argflags & 6) > 0) { @@ -100,6 +102,13 @@ if ((argflags & 64) > 0 || strcmp(argv[t], "--version") == 0) { return exit_with_version(settings); } + // V + if ((argflags & 128) > 0) { + if (registerArgument(&checked, 128)) { + return exit_with_help(settings, 1); + } + settings->verbose = false; + } // Path if (argflags == 0) { if (registerArgument(&checked, 1024)) { @@ -109,6 +118,11 @@ } } + // Configure output + if (!settings->verbose) { + close_stdout(); + } + // Find tokens char* finder = strtok(suffix, ","); while (finder != NULL) { @@ -130,20 +144,26 @@ destroy_settings_t(settings); // Print double line and line count - #ifdef _WIN32 +#ifdef _WIN32 const int columns = 79; - #else +#else const int columns = 80; - #endif /* _WIN32 */ +#endif /* _WIN32 */ for (int t = 0 ; t < columns ; t++) { printf("="); } - #ifdef _WIN32 +#ifdef _WIN32 printf("\n%73d lines\n", lines); - #else +#else printf("\n%74d lines\n", lines); - #endif /* _WIN32 */ +#endif /* _WIN32 */ + if (!settings->verbose) { + reopen_stdout(); + printf("%d", lines); + } + + fflush(stdout); return 0; } diff -r 9a262e046ab8 -r bc9a0fefd892 scanner.c --- a/scanner.c Mon Sep 19 08:11:08 2011 +0200 +++ b/scanner.c Tue Sep 20 15:19:28 2011 +0200 @@ -44,10 +44,6 @@ // Count lines lines = 0; - /* char filename[(1+strlen(currdir)+strlen(entry->d_name))]; - strcpy(filename, currdir); - strncat(filename, &settings->fileSeparator, 1); - strcat(filename, entry->d_name); */ if (testSuffix(filename, settings)) { FILE *file = fopen(filename, "r"); if (file == NULL) { @@ -72,8 +68,7 @@ #endif /* _WIN32 */ lineSum += lines; - } - else { + } else { if (!settings->matchesOnly) { // Print hint #ifdef _WIN32 diff -r 9a262e046ab8 -r bc9a0fefd892 settings.c --- a/settings.c Mon Sep 19 08:11:08 2011 +0200 +++ b/settings.c Tue Sep 20 15:19:28 2011 +0200 @@ -19,6 +19,7 @@ settings->includeSuffixes = false; settings->matchesOnly = false; settings->suffixList = new_suffix_list_t(); + settings->verbose = true; } return settings; diff -r 9a262e046ab8 -r bc9a0fefd892 settings.h --- a/settings.h Mon Sep 19 08:11:08 2011 +0200 +++ b/settings.h Tue Sep 20 15:19:28 2011 +0200 @@ -17,6 +17,7 @@ bool recursive; bool includeSuffixes; bool matchesOnly; + bool verbose; } settings_t; #ifdef _cplusplus diff -r 9a262e046ab8 -r bc9a0fefd892 stream.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stream.c Tue Sep 20 15:19:28 2011 +0200 @@ -0,0 +1,25 @@ +/* + * stream.c + * + * Created on: 20.09.2011 + * Author: beckermi + */ + +#include "stream.h" + +void close_stdout() { +#ifdef _WIN32 + _STREAM_STDOUT = dup(STDOUT_FILENO); +#endif + freopen("/dev/null", "w", stdout); +} + +void reopen_stdout() { +#ifdef _WIN32 + close(STDOUT_FILENO); + fdopen(dup(_STREAM_STDOUT), "wa"); + close(_STREAM_STDOUT); +#else + freopen("/dev/stdout", "w", stdout); +#endif +} diff -r 9a262e046ab8 -r bc9a0fefd892 stream.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stream.h Tue Sep 20 15:19:28 2011 +0200 @@ -0,0 +1,28 @@ +/* + * stream.h + * + * Created on: 20.09.2011 + * Author: beckermi + */ + +#ifndef STREAM_H_ +#define STREAM_H_ + +#include "stdinc.h" + +#ifdef _WIN32 +int _STREAM_STDOUT; +#endif + +#ifdef _cplusplus +extern "C" { +#endif + +void close_stdout(); +void reopen_stdout(); + +#ifdef _cplusplus +extern "C" } +#endif + +#endif /* STREAM_H_ */