This function helps evaluates the --annotation option argument
and determines whether annotations are enabled or not.
It is identical to the hyperlinkwanted() routine, and although
that forms some form of redundancy, it is intentionally kept
seperate for potential future changes.
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
extern time_t strtotime_or_err(const char *str, const char *errmesg);
extern bool hyperlinkwanted(const char *mode);
+extern bool annotationwanted(const char *mode);
extern int isdigit_strend(const char *str, const char **end);
#define isdigit_string(_s) isdigit_strend(_s, NULL)
errx(EXIT_FAILURE, _("invalid argument of --hyperlink: %s"), mode);
}
+bool annotationwanted(const char *mode)
+{
+ 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, _("invalid argument of --annotation: %s"), mode);
+}
+
/*
* Converts stat->st_mode to ls(1)-like mode string. The size of "str" must
* be 11 bytes.