From 156a53780c7b27aeb7b4de7de56450f26c55a192 Mon Sep 17 00:00:00 2001 From: qsmodo <75080827+qsmodo@users.noreply.github.com> Date: Sun, 12 Sep 2021 15:26:07 -0300 Subject: set title based on prefix and suffix (#23) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Guilherme Rugai Freire <41879254+GRFreire@users.noreply.github.com> Co-authored-by: NRK Co-authored-by: Berke Kocaoğlu --- options.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'options.c') diff --git a/options.c b/options.c index 394220f..e89b6f1 100644 --- a/options.c +++ b/options.c @@ -18,6 +18,7 @@ #include "sxiv.h" #define _IMAGE_CONFIG +#define _TITLE_CONFIG #include "config.h" #include "version.h" @@ -31,8 +32,8 @@ const opt_t *options = (const opt_t*) &_options; void print_usage(void) { printf("usage: sxiv [-abcfhiopqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] " - "[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] [-z ZOOM] " - "FILES...\n"); + "[-g GEOMETRY] [-N NAME] [-T TITLE] [-n NUM] [-S DELAY] [-s MODE] " + "[-z ZOOM] FILES...\n"); } void print_version(void) @@ -66,13 +67,15 @@ void parse_options(int argc, char **argv) _options.hide_bar = false; _options.geometry = NULL; _options.res_name = NULL; + _options.title_prefix = TITLE_PREFIX; + _options.title_suffixmode = TITLE_SUFFIXMODE; _options.quiet = false; _options.thumb_mode = false; _options.clean_cache = false; _options.private_mode = false; - while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:opqrS:s:tvZz:")) != -1) { + while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:opqrS:s:T:tvZz:")) != -1) { switch (opt) { case '?': print_usage(); @@ -149,6 +152,16 @@ void parse_options(int argc, char **argv) error(EXIT_FAILURE, 0, "Invalid argument for option -s: %s", optarg); _options.scalemode = s - scalemodes; break; + case 'T': + if ((s = strrchr(optarg, ':')) != NULL) { + *s = '\0'; + n = strtol(++s, &end, 0); + if (*end != '\0' || n < SUFFIX_EMPTY || n > SUFFIX_FULLPATH) + error(EXIT_FAILURE, 0, "Invalid argument for option -T suffixmode: %s", s); + _options.title_suffixmode = n; + } + _options.title_prefix = optarg; + break; case 't': _options.thumb_mode = true; break; -- cgit v1.2.3