dag

Djmoch's Auto Generator
git clone git://git.danielmoch.com/dag.git
Log | Files | Refs | README | LICENSE

commit 487c6ff5a388696a35d1561ced33e9622ce60053
parent 26c02c827de83b4505cbd26acc95f2695fd68d0c
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Sun, 18 Sep 2022 06:44:00 -0400

More verbose messaging

Diffstat:
Mdag.c | 4++--
Mdagfile.c | 64+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mdagfile.h | 2+-
Mdagindex.c | 3+++
4 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/dag.c b/dag.c @@ -57,7 +57,7 @@ main(int argc, char **argv) usage(ERR_NONE); break; case 'v': - verbose = 1; + verbose += 1; break; case 'V': printf("%s %s\n", argv0, VERSION); @@ -90,7 +90,7 @@ main(int argc, char **argv) debug_dagfile(dagfile); } - retval = process_dagfile(dagfile); + retval = process_dagfile(dagfile, verbose); free_dagfile(dagfile); diff --git a/dagfile.c b/dagfile.c @@ -28,8 +28,10 @@ static struct source *src; static struct extension *ext; static struct suffix *sfx; +static int verbose = 0; + int -process_dagfile(struct dagfile *df) +process_dagfile(struct dagfile *df, int verb) { FTSENT *entry = NULL; FTS *src_tree; @@ -39,6 +41,12 @@ process_dagfile(struct dagfile *df) ext = NULL; sfx = NULL; + verbose = verb; + + if (verbose >= 2) { + printf("process_dagfile\n"); + } + while (src != NULL && path[0] != NULL) { src_tree = fts_open(path, FTS_LOGICAL, NULL); if (src_tree == NULL) { @@ -113,6 +121,10 @@ process_source(char *file) int found = 0; ext = src->extensions; + if (verbose >= 2) { + printf("process_source(%s)\n", file); + } + while (ext != NULL) { if (strend(file, ext->value)) { process_extension(file); @@ -132,6 +144,10 @@ process_extension(char *file) { sfx = ext->suffixes; + if (verbose >= 2) { + printf("process_extension(%s, %s)\n", file, ext->value); + } + while (sfx != NULL) { process_suffix(file); sfx = sfx->next; @@ -144,6 +160,10 @@ process_suffix(char *file) char *target = make_outpath(file); struct requirement *r = sfx->requirements; + if (verbose >= 2) { + printf("process_suffix(%s, %s)\n", file, sfx->value); + } + int old = outdated(target, 1, file); while (r != NULL) { old |= outdated(target, 1, r->path); @@ -151,6 +171,9 @@ process_suffix(char *file) } if (old) { + if (verbose) { + printf("%s outdated, applying filters\n", file); + } struct filter *f = sfx->filters; while (f != NULL) { char *cmd = fmt_filter(f->cmd, file, target); @@ -160,6 +183,9 @@ process_suffix(char *file) f = f->next; } } + else if (verbose) { + printf("%s up to date\n", file); + } free(target); } @@ -169,6 +195,9 @@ copy_file(char *file) char *target = make_outpath(file); if (outdated(target, 1, file)) { + if (verbose) { + printf("%s outdated, applying filters\n", file); + } char fmt[] = "cp %s %s"; char *cmd; @@ -181,7 +210,9 @@ copy_file(char *file) system(cmd); free(cmd); } - + else if (verbose) { + printf("%s up to date\n", file); + } free(target); } @@ -196,7 +227,13 @@ make_outpath(const char *file) } strcpy(target, file); + if (verbose >= 2) { + printf("make_outpath: target = %s\n", target); + } strnswp(target, src->path, tgt->path, len); + if (verbose >= 2) { + printf("make_outpath: target = %s\n", target); + } /* * TODO: find a better way to determine if the suffix needs @@ -209,12 +246,24 @@ make_outpath(const char *file) err(errno, "malloc failed"); } strcpy(tmp, target); + if (verbose >= 2) { + printf("make_outpath: tmp = %s\n", target); + } strnswp(tmp, ext->value, sfx->value, len); + if (verbose >= 2) { + printf("make_outpath: tmp = %s\n", target); + } free(target); target = tmp; + if (verbose >= 2) { + printf("make_outpath: target = %s\n", target); + } } dag_mkdir(dirname(target)); + if (verbose >= 2) { + printf("make_outpath(%s) = %s\n", file, target); + } return target; } @@ -224,10 +273,19 @@ outdated(char *dest, int nsrc, ...) va_list ap; struct stat d_sb, s_sb; int rv = 1; + int r; - if (stat(dest, &d_sb) != 0) { + if ((r = stat(dest, &d_sb)) != 0) { + if (verbose) { + printf("stat(%s): %d\n", dest, r); + } return rv; } + else { + if (verbose) { + printf("stat(%s): %d\n", dest, r); + } + } va_start(ap, nsrc); for (int i=0; i<nsrc; i++) { diff --git a/dagfile.h b/dagfile.h @@ -38,7 +38,7 @@ struct dagfile { struct target *target; }; -int process_dagfile(struct dagfile *df); +int process_dagfile(struct dagfile *df, int verbose); void free_dagfile(struct dagfile *df); struct dagfile *parse_dagfile(FILE *path); void debug_dagfile(struct dagfile *df); diff --git a/dagindex.c b/dagindex.c @@ -91,6 +91,9 @@ populate_time(char *time_str) char *ep; if (time_str) { + if (verbose >= 2) { + fprintf(stderr, "time_str: %s\n", time_str); + } time = strtoll(time_str, &ep, 10); if (time_str[0] != '\0' && *ep == '\0') { return time;