diff options
author | John Ankarstrom <john@ankarstrom.se> | 2021-07-07 12:30:11 +0200 |
---|---|---|
committer | John Ankarstrom <john@ankarstrom.se> | 2021-07-07 12:30:11 +0200 |
commit | df3fb6926720d7025829004bd75ee899be6403ce (patch) | |
tree | 5bb405f0bd1ddcdff17e209b9b11aec2a89cf559 | |
parent | 56a7e6b5d539d3a11488f56b3806714e5a6f1641 (diff) | |
download | build-df3fb6926720d7025829004bd75ee899be6403ce.tar.gz |
Add -f (force) flag
-rw-r--r-- | build.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -32,7 +32,7 @@ main(int argc, char *argv[]) { char *b, buf[MAXBUF], *cmd[MAXCMDS], *d, *dep, *name, *tgt; FILE *fp; - int c, dflag, i, icmd, j; + int c, dflag, fflag, i, icmd, j; struct stat sb, ssb; /* allocate memory */ @@ -49,12 +49,15 @@ main(int argc, char *argv[]) /* process arguments */ name = argv[0]; - dflag = 0; - while ((c = getopt(argc, argv, "d")) != -1) + dflag = fflag = 0; + while ((c = getopt(argc, argv, "df")) != -1) switch (c) { case 'd': dflag++; break; + case 'f': + fflag = 1; + break; default: fprintf(stderr, USAGE); return 1; @@ -112,7 +115,7 @@ main(int argc, char *argv[]) continue; } - if (!*tgt) + if (fflag || !*tgt) goto build; /* compare source > target */ @@ -155,7 +158,7 @@ build: /* run commands */ buf[0] = 0; for (j = 0; j < icmd; j++) { - fprintf(stderr, "$ %s\n", cmd[j]); + fprintf(stderr, "%s: $ %s\n", argv[i], cmd[j]); strncat(buf, cmd[j], MAXBUF-1); strncat(buf, "\n", MAXBUF-1); } |