From a9724c1b01d634e1b9922d2893b3ced397b0bdaa Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Tue, 14 Nov 2023 03:31:58 +0100 Subject: [PATCH] add verbose option to findconfig --- include/libmegapixels.h | 3 +++ src/findconfig.c | 24 +++++++++++++++++++++--- util/findconfig.c | 10 +++++++--- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/include/libmegapixels.h b/include/libmegapixels.h index 1654656..612987c 100644 --- a/include/libmegapixels.h +++ b/include/libmegapixels.h @@ -10,6 +10,9 @@ EXPORT int libmegapixels_find_config(char *configfile); +EXPORT int +libmegapixels_find_config_verbose(char *configfile, int print); + #define LIBMEGAPIXELS_CMD_LINK 1 #define LIBMEGAPIXELS_CMD_MODE 2 #define LIBMEGAPIXELS_CMD_CROP 3 diff --git a/src/findconfig.c b/src/findconfig.c index d3b318d..a55b4b8 100644 --- a/src/findconfig.c +++ b/src/findconfig.c @@ -10,30 +10,42 @@ #endif static int -find_device_by_model(char *conffile, char *model) +find_device_by_model(char *conffile, char *model, int print) { // Check config/%model.conf in the current working directory sprintf(conffile, "config/%s.conf", model); + if (print) { + printf("- %s\n", conffile); + } if (access(conffile, F_OK) != -1) { return 1; } // Check user overridden /etc/megapixels/config/%model.conf sprintf(conffile, "%s/megapixels/config/%s.conf", SYSCONFDIR, model); + if (print) { + printf("- %s\n", conffile); + } if (access(conffile, F_OK) != -1) { return 1; } // Check packaged /usr/share/megapixels/config/%model.conf sprintf(conffile, "%s/megapixels/config/%s.conf", DATADIR, model); + if (print) { + printf("- %s\n", conffile); + } if (access(conffile, F_OK) != -1) { return 1; } + if (print) { + printf("no config for '%s'\n", model); + } return 0; } int -libmegapixels_find_config(char *configfile) +libmegapixels_find_config_verbose(char *configfile, int print) { char model[512]; FILE *fp; @@ -50,10 +62,16 @@ libmegapixels_find_config(char *configfile) } *(modelptr++) = (char) c; if (c == 0) { - if (find_device_by_model(configfile, model)) { + if (find_device_by_model(configfile, model, print)) { return 1; } modelptr = model; } } +} + +int +libmegapixels_find_config(char *configfile) +{ + return libmegapixels_find_config_verbose(configfile, 0); } \ No newline at end of file diff --git a/util/findconfig.c b/util/findconfig.c index 893e7dd..b9fadcc 100644 --- a/util/findconfig.c +++ b/util/findconfig.c @@ -10,14 +10,18 @@ main(int argc, char *argv[]) int c; char configpath[PATH_MAX]; - int ret = libmegapixels_find_config(configpath); + int ret; + int verbose = 0; - while ((c = getopt(argc, argv, "c:")) != -1) { + while ((c = getopt(argc, argv, "c:v")) != -1) { switch (c) { case 'c': sprintf(configpath, "%s", optarg); ret = 1; break; + case 'v': + verbose = 1; + break; case '?': if (optopt == 'd' || optopt == 'l') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); @@ -31,7 +35,7 @@ main(int argc, char *argv[]) return 1; } } - + ret = libmegapixels_find_config_verbose(configpath, verbose); libmegapixels_devconfig *config = {0}; libmegapixels_init(&config);