From a0c0e854cc5792cef05fd838c2da70668ca6cf53 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 21 Nov 2010 20:55:25 -0300 Subject: [PATCH] qpkg: option -d to enable debugging at run time, and some cleanup - prereq.c: added section titles - prereq.c (debug), qpkg.h, qpkg.c: made variable "debug" global and moved it to qpkg.c - qpkg.c (usage, main): new option -d to enable debugging --- qpkg/prereq.c | 13 ++++++++++++- qpkg/qpkg.c | 11 +++++++++-- qpkg/qpkg.h | 2 ++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/qpkg/prereq.c b/qpkg/prereq.c index b5962e6..b9e50e2 100644 --- a/qpkg/prereq.c +++ b/qpkg/prereq.c @@ -39,7 +39,9 @@ static struct pkg **installs = NULL; static int n_best; /* undefined if best == NULL */ static int n_install = 0; static int install_max = 0; -static int debug = 0; + + +/* ----- Version comparison ------------------------------------------------ */ static int epoch(const char **s, const struct id *id) @@ -100,6 +102,9 @@ static int comp_versions(const struct id *va, const struct id *vb) } +/* ----- List of packages considered for installation ---------------------- */ + + static void done(void) { int size; @@ -139,6 +144,9 @@ static void backtrack(void) } +/* ----- Check dependencies and conflicts ---------------------------------- */ + + static int satisfies(const struct pkg *pkg, const struct ref *ref) { int cmp; @@ -171,6 +179,9 @@ static int conflicts(const struct pkg *pkg, const struct list *conf) } +/* ----- Recurse through lists and layers of dependencies ------------------ */ + + static void print_debug(const struct pkg *pkg, const struct stack *top, int level) { diff --git a/qpkg/qpkg.c b/qpkg/qpkg.c index 0c331dc..76d6834 100644 --- a/qpkg/qpkg.c +++ b/qpkg/qpkg.c @@ -26,6 +26,8 @@ struct tree *packages = NULL; struct tree *versions = NULL; +int debug = 0; + static void list_all_packages(void) { @@ -115,8 +117,9 @@ static void find_prereq(const char *name, const char *version) static void usage(const char *name) { fprintf(stderr, -"usage: %s [pkg-list ...] list [pkg]\n" -" %s [pkg-list ...] prereq pkg [version]\n" +"usage: %s options [pkg-list ...] list [pkg]\n" +" %s options [pkg-list ...] prereq pkg [version]\n\n" +" -d enable debugging output\n" , name, name); exit(1); } @@ -133,6 +136,10 @@ int main(int argc, char **argv) usage(*argv); for (arg = 1; arg != argc; arg++) { + if (!strcmp(argv[arg], "-d")) { + debug = 1; + continue; + } if (*argv[arg] == '-') usage(*argv); if (!strcmp(argv[arg], "list")) { diff --git a/qpkg/qpkg.h b/qpkg/qpkg.h index 62147c8..96e862e 100644 --- a/qpkg/qpkg.h +++ b/qpkg/qpkg.h @@ -52,4 +52,6 @@ struct pkg { struct tree *packages; struct tree *versions; +int debug; + #endif /* !QPKG_H */