From 28453bcca770f897a6c36706148e105fb7e476ca Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 28 Nov 2024 13:39:10 +0100 Subject: include: add functions to implement --hyperlink * add xgethosturi() to allocate file://hostname * add hyperlinkwanted_or_err() to parse --hyperlink={never,always,auto} Signed-off-by: Karel Zak --- lib/strutils.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/strutils.c') diff --git a/lib/strutils.c b/lib/strutils.c index e3a059145a..2b54bcce51 100644 --- a/lib/strutils.c +++ b/lib/strutils.c @@ -524,6 +524,20 @@ time_t strtotime_or_err(const char *str, const char *errmesg) return (time_t) user_input; } +bool hyperlinkwanted_or_err(const char *mode, const char *errmesg) +{ + if (mode && strcmp(mode, "never") == 0) + return false; + + if (mode && strcmp(mode, "always") == 0) + return true; + + if (!mode || strcmp(mode, "auto") == 0) + return isatty(STDOUT_FILENO) ? true : false; + + errx(EXIT_FAILURE, "%s: '%s'", errmesg, mode); +} + /* * Converts stat->st_mode to ls(1)-like mode string. The size of "str" must * be 11 bytes. -- cgit 1.2.3-korg