summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2018-01-24 19:19:30 +0300
committerIvan Maidanski <ivmai@mail.ru>2018-01-24 19:19:30 +0300
commitb5cab5aacd263577af3502ecf068612591d27704 (patch)
treee4ec1cbf15af540d98a1000f75bf4f026b104141 /tools
parentef879a9d20aac4d841196fc68fce12a50020d9d9 (diff)
downloadbdwgc-b5cab5aacd263577af3502ecf068612591d27704.tar.gz
Run command passed to if_not_there directly from Makefile.direct
Issue #199 (bdwgc). if_not_there tool is modified to accept a single argument (file name). * Makefile.direct (base_lib, cords, test_cpp, c++, mach_dep.o, mark_rts.o, cord/cordtest, cord/de, gctest): Replace "if_not_there <file> <command>" with "if_not_there <file> || <command>". * Makefile.direct (c++): Add dependency on $(UTILS). * Makefile.direct (gctest): Remove double spaces. * tools/if_not_there.c: Update header comment. * tools/if_not_there.c (main): Allow both 2 and 3 command-line arguments; return 2 if the file does not exist and argc is 2; update the printed usage message.
Diffstat (limited to 'tools')
-rw-r--r--tools/if_not_there.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/tools/if_not_there.c b/tools/if_not_there.c
index 190a5821..10f5d14a 100644
--- a/tools/if_not_there.c
+++ b/tools/if_not_there.c
@@ -1,4 +1,6 @@
-/* Conditionally execute a command based if the file argv[1] doesn't exist */
+/* Conditionally execute the command argv[2] based if the file argv[1] */
+/* does not exist. If the command is omitted (and the file does not */
+/* exist) then just exit with a non-zero code. */
# include "private/gc_priv.h"
# include <stdio.h>
@@ -16,7 +18,8 @@ int main(int argc, char **argv)
#endif /* __DJGPP__ */
char *fname;
- if (argc < 3) goto Usage;
+ if (argc < 2 || argc > 3)
+ goto Usage;
fname = TRUSTED_STRING(argv[1]);
f = fopen(fname, "rb");
@@ -37,10 +40,13 @@ int main(int argc, char **argv)
#endif
printf("^^^^Starting command^^^^\n");
fflush(stdout);
+ if (argc == 2)
+ return(2); /* the file does not exist but no command is given */
+
execvp(TRUSTED_STRING(argv[2]), (void *)(argv + 2));
exit(1);
Usage:
- fprintf(stderr, "Usage: %s file_name command\n", argv[0]);
+ fprintf(stderr, "Usage: %s file_name [command]\n", argv[0]);
return(1);
}