From f94f3269da7980d07d42de00434913bbb210b111 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sat, 6 Aug 2022 18:38:35 +0100 Subject: [PATCH] getopt: make logo_size_max configurable with -q --- src/pbsplash.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/pbsplash.c b/src/pbsplash.c index 1c2ed42..573ea66 100644 --- a/src/pbsplash.c +++ b/src/pbsplash.c @@ -51,13 +51,14 @@ int usage() fprintf(stderr, "pbsplash: postmarketOS bootsplash generator\n"); fprintf(stderr, "-------------------------------------------\n"); fprintf(stderr, "pbsplash [-v] [-h] [-f font] [-s splash image] [-m message]\n"); - fprintf(stderr, " [-p font size] [-d]\n\n"); + fprintf(stderr, " [-p font size] [-q max logo size] [-d]\n\n"); fprintf(stderr, " -v enable verbose logging\n"); fprintf(stderr, " -h show this help\n"); fprintf(stderr, " -f path to SVG font file (default: %s)\n", DEFAULT_FONT_PATH); fprintf(stderr, " -s path to splash image to display\n"); fprintf(stderr, " -m message to show under the splash image\n"); fprintf(stderr, " -p font size in pt (default: %d)\n", FONT_SIZE_PT); + fprintf(stderr, " -q max logo size in mm (default: %d)\n", LOGO_SIZE_MAX_MM); fprintf(stderr, " -d custom DPI (for testing)\n"); // clang-format on @@ -212,6 +213,7 @@ int main(int argc, char **argv) NSVGimage *font = NULL; struct sigaction action; float font_size = FONT_SIZE_PT; + float logo_size_max = LOGO_SIZE_MAX_MM; int optflag; long dpi = 0; @@ -223,7 +225,7 @@ int main(int argc, char **argv) sigaction(SIGTERM, &action, NULL); sigaction(SIGINT, &action, NULL); - while ((optflag = getopt(argc, argv, "hvf:s:m:p:d:")) != -1) { + while ((optflag = getopt(argc, argv, "hvf:s:m:p:q:d:")) != -1) { char *end = NULL; switch (optflag) { case 'h': @@ -248,6 +250,14 @@ int main(int argc, char **argv) return usage(); } break; + case 'q': + logo_size_max = strtof(optarg, &end); + if (end == optarg) { + fprintf(stderr, "Invalid max logo size: %s\n", + optarg); + return usage(); + } + break; case 'd': dpi = strtol(optarg, &end, 10); if (end == optarg) { @@ -300,12 +310,12 @@ int main(int argc, char **argv) float logo_size_px = (float)(screenWidth < screenHeight ? screenWidth : screenHeight) * 0.75f; if (w_mm > 0 && h_mm > 0) { if (w_mm < h_mm) { - if (w_mm > (float)LOGO_SIZE_MAX_MM * 1.2f) - logo_size_px = (float)LOGO_SIZE_MAX_MM * + if (w_mm > logo_size_max * 1.2f) + logo_size_px = logo_size_max * pixels_per_milli; } else { - if (h_mm > (float)LOGO_SIZE_MAX_MM * 1.2f) - logo_size_px = (float)LOGO_SIZE_MAX_MM * + if (h_mm > logo_size_max * 1.2f) + logo_size_px = logo_size_max * pixels_per_milli; } }