Permalink
Browse files

Merge branch 'master' of github.com:visionmedia/watch

  • Loading branch information...
2 parents 2410346 + 00951fb commit 2406b2593d2fbadff5739520f2469c257cf039f2 @tj committed Jun 8, 2012
Showing with 22 additions and 5 deletions.
  1. +3 −1 Makefile
  2. +2 −1 Readme.md
  3. +17 −3 src/watch.c
View
4 Makefile
@@ -2,6 +2,8 @@
CFLAGS = -std=c99 -D_POSIX_C_SOURCE=199309L -Wall -pedantic -Wno-parentheses
PREFIX ?= /usr/local
+all: watch
+
watch: src/watch.c
$(CC) $< $(CFLAGS) -o $@
@@ -14,4 +16,4 @@ uninstall:
clean:
rm -f watch
-.PHONY: clean install uninstall
+.PHONY: all clean install uninstall
View
3 Readme.md
@@ -12,8 +12,9 @@ Usage: watch [options] <cmd>
Options:
-q, --quiet only output stderr
+ -x, --halt halt on failure
-i, --interval <n> interval in seconds or ms defaulting to 1
- -V, --version output version number
+ -v, --version output version number
```
View
20 src/watch.c
@@ -38,6 +38,11 @@
static int quiet = 0;
/*
+ * Halt on failure.
+ */
+static int halt = 0;
+
+/*
* Output command usage.
*/
@@ -50,6 +55,7 @@ usage() {
" Options:\n"
"\n"
" -q, --quiet only output stderr\n"
+ " -x, --halt halt on failure\n"
" -i, --interval <n> interval in seconds or ms defaulting to 1\n"
" -v, --version output version number\n"
" -h, --help output this help information\n"
@@ -113,7 +119,7 @@ int
length(char **strs) {
int n = 0;
char *str;
- while (str = *strs++) n += strlen(str);
+ while ((str = *strs++)) n += strlen(str);
return n + 1;
}
@@ -126,7 +132,7 @@ join(char **strs, int len, char *val) {
--len;
char *buf = malloc(length(strs) + len * strlen(val));
char *str;
- while (str = *strs++) {
+ while ((str = *strs++)) {
strcat(buf, str);
if (*strs) strcat(buf, val);
}
@@ -159,7 +165,13 @@ main(int argc, const char **argv){
continue;
}
- // -V, --version
+ // -x, --halt
+ if (option("-x", "--halt", arg)) {
+ halt = 1;
+ continue;
+ }
+
+ // -v, --version
if (option("-v", "--version", arg)) {
printf("%s\n", VERSION);
exit(1);
@@ -224,6 +236,8 @@ main(int argc, const char **argv){
// exit > 0
if (WEXITSTATUS(status)) {
fprintf(stderr, "\033[90mexit: %d\33[0m\n\n", WEXITSTATUS(status));
+
+ if (halt) exit(WEXITSTATUS(status));
}
mssleep(interval);

0 comments on commit 2406b25

Please sign in to comment.