Update style to more BSDish and replace the big macro with a function.

This commit is contained in:
Roy Marples 2008-06-05 12:17:41 +00:00
parent dc891b0647
commit 76063daee5

View File

@ -199,7 +199,8 @@ static const char *const color_terms[] = {
/* strlcat and strlcpy are nice, shame glibc does not define them */ /* strlcat and strlcpy are nice, shame glibc does not define them */
#ifdef __GLIBC__ #ifdef __GLIBC__
# if ! defined (__UCLIBC__) && ! defined (__dietlibc__) # if ! defined (__UCLIBC__) && ! defined (__dietlibc__)
static size_t strlcat(char *dst, const char *src, size_t size) static size_t
strlcat(char *dst, const char *src, size_t size)
{ {
char *d = dst; char *d = dst;
const char *s = src; const char *s = src;
@ -226,18 +227,19 @@ static size_t strlcat(char *dst, const char *src, size_t size)
return dst_n + (s - src); return dst_n + (s - src);
} }
static size_t strlcpy(char *dst, const char *src, size_t size) static size_t
strlcpy(char *dst, const char *src, size_t size)
{ {
const char *s = src; const char *s = src;
size_t n = size; size_t n = size;
if (n && --n) if (n && --n)
do { do {
if (! (*dst++ = *src++)) if (!(*dst++ = *src++))
break; break;
} while (--n); } while (--n);
if (! n) { if (!n) {
if (size) if (size)
*dst = '\0'; *dst = '\0';
while (*src++); while (*src++);
@ -248,9 +250,10 @@ static size_t strlcpy(char *dst, const char *src, size_t size)
# endif # endif
#endif #endif
static bool yesno(const char *value) static bool
yesno(const char *value)
{ {
if (! value) { if (!value) {
errno = ENOENT; errno = ENOENT;
return false; return false;
} }
@ -272,7 +275,8 @@ static bool yesno(const char *value)
return false; return false;
} }
static bool noyes(const char *value) static bool
noyes(const char *value)
{ {
int serrno = errno; int serrno = errno;
bool retval; bool retval;
@ -280,26 +284,29 @@ static bool noyes(const char *value)
errno = 0; errno = 0;
retval = yesno(value); retval = yesno(value);
if (errno == 0) { if (errno == 0) {
retval = ! retval; retval = !retval;
errno = serrno; errno = serrno;
} }
return retval; return retval;
} }
static bool is_quiet(void) static bool
is_quiet(void)
{ {
return yesno(getenv("EINFO_QUIET")); return yesno(getenv("EINFO_QUIET"));
} }
static bool is_verbose(void) static bool
is_verbose(void)
{ {
return yesno(getenv ("EINFO_VERBOSE")); return yesno(getenv ("EINFO_VERBOSE"));
} }
/* Fake tgoto call - very crapy, but works for our needs */ /* Fake tgoto call - very crapy, but works for our needs */
#ifndef HAVE_TERMCAP #ifndef HAVE_TERMCAP
static char *tgoto(const char *cap, int a, int b) static char *
tgoto(const char *cap, int a, int b)
{ {
static char buf[20]; static char buf[20];
@ -308,22 +315,22 @@ static char *tgoto(const char *cap, int a, int b)
} }
#endif #endif
static bool colour_terminal(FILE * __EINFO_RESTRICT f) static bool
colour_terminal(FILE * __EINFO_RESTRICT f)
{ {
static int in_colour = -1; static int in_colour = -1;
char *e; char *e, *ee, *end, *d, *p;
int c; int c;
const char *_af = NULL; const char *_af = NULL, *_ce = NULL, *_ch = NULL;
const char *_ce = NULL; const char *_md = NULL, *_me = NULL, *_up = NULL;
const char *_ch = NULL; const char *bold;
const char *_md = NULL;
const char *_me = NULL;
const char *_up = NULL;
char tmp[100]; char tmp[100];
char *p;
unsigned int i = 0; unsigned int i = 0;
#ifdef HAVE_TERMCAP
char *bp;
#endif
if (f && ! isatty(fileno(f))) if (f && !isatty(fileno(f)))
return false; return false;
if (noyes(getenv("EINFO_COLOR"))) if (noyes(getenv("EINFO_COLOR")))
@ -335,26 +342,23 @@ static bool colour_terminal(FILE * __EINFO_RESTRICT f)
return true; return true;
term_is_cons25 = false; term_is_cons25 = false;
if (!term) {
if (! term) {
term = getenv("TERM"); term = getenv("TERM");
if (! term) if (!term)
return false; return false;
} }
if (strcmp(term, "cons25") == 0) if (strcmp(term, "cons25") == 0)
term_is_cons25 = true; term_is_cons25 = true;
#ifdef HAVE_TERMCAP #ifdef HAVE_TERMCAP
/* Check termcap to see if we can do colour or not */ /* Check termcap to see if we can do colour or not */
if (tgetent(termcapbuf, term) == 1) { if (tgetent(termcapbuf, term) == 1) {
char *bp = tcapbuf; bp = tcapbuf;
_af = tgetstr("AF", &bp); _af = tgetstr("AF", &bp);
_ce = tgetstr("ce", &bp); _ce = tgetstr("ce", &bp);
_ch = tgetstr("ch", &bp); _ch = tgetstr("ch", &bp);
/* Our ch use also works with RI .... for now */ /* Our ch use also works with RI .... for now */
if (! _ch) if (!_ch)
_ch = tgetstr("RI", &bp); _ch = tgetstr("RI", &bp);
_md = tgetstr("md", &bp); _md = tgetstr("md", &bp);
_me = tgetstr("me", &bp); _me = tgetstr("me", &bp);
@ -377,29 +381,29 @@ static bool colour_terminal(FILE * __EINFO_RESTRICT f)
return false; return false;
} }
#endif #endif
if (! _af) if (!_af)
_af = AF; _af = AF;
if (! _ce) if (!_ce)
_ce = CE; _ce = CE;
if (! _ch) if (!_ch)
_ch = CH; _ch = CH;
if (! _md) if (!_md)
_md = MD; _md = MD;
if (! _me) if (!_me)
_me = ME; _me = ME;
if (! _up) if (!_up)
_up = UP; _up = UP;
#ifdef HAVE_TERMCAP #ifdef HAVE_TERMCAP
} }
if (! _af || ! _ce || ! _me || !_md || ! _up) { if (!_af || !_ce || !_me || !_md || !_up) {
in_colour = 0; in_colour = 0;
return false; return false;
} }
/* Many termcap databases don't have ch or RI even though they /* Many termcap databases don't have ch or RI even though they
* do work */ * do work */
if (! _ch) if (!_ch)
_ch = CH; _ch = CH;
#endif #endif
@ -407,33 +411,28 @@ static bool colour_terminal(FILE * __EINFO_RESTRICT f)
p = ebuffer; p = ebuffer;
for (i = 0; i < sizeof(ecolors) / sizeof(ecolors[0]); i++) { for (i = 0; i < sizeof(ecolors) / sizeof(ecolors[0]); i++) {
tmp[0] = '\0'; tmp[0] = '\0';
if (ecolors[i].name) { if (ecolors[i].name) {
const char *bold = _md; bold = _md;
c = ecolors[i].def; c = ecolors[i].def;
/* See if the user wants to override the colour /* See if the user wants to override the colour
* We use a :col;bold: format like 2;1: for bold green * We use a :col;bold: format like 2;1: for bold green
* and 1;0: for a normal red */ * and 1;0: for a normal red */
if ((e = getenv("EINFO_COLOR"))) { if ((e = getenv("EINFO_COLOR"))) {
char *ee = strstr(e, ecolors[i].name); ee = strstr(e, ecolors[i].name);
if (ee) if (ee)
ee += strlen(ecolors[i].name); ee += strlen(ecolors[i].name);
if (ee && *ee == '=') { if (ee && *ee == '=') {
char *d = strdup(ee + 1); d = strdup(ee + 1);
if (d) { if (d) {
char *end = strchr(d, ':'); end = strchr(d, ':');
if (end) if (end)
*end = '\0'; *end = '\0';
c = atoi(d); c = atoi(d);
end = strchr(d, ';'); end = strchr(d, ';');
if (end && *++end == '0') if (end && *++end == '0')
bold = _me; bold = _me;
free(d); free(d);
} }
} }
@ -460,7 +459,8 @@ static bool colour_terminal(FILE * __EINFO_RESTRICT f)
return true; return true;
} }
static int get_term_columns(FILE * __EINFO_RESTRICT stream) static int
get_term_columns(FILE * __EINFO_RESTRICT stream)
{ {
struct winsize ws; struct winsize ws;
char *env = getenv("COLUMNS"); char *env = getenv("COLUMNS");
@ -469,7 +469,7 @@ static int get_term_columns(FILE * __EINFO_RESTRICT stream)
if (env) { if (env) {
i = strtoimax(env, &p, 10); i = strtoimax(env, &p, 10);
if (! *p) if (!*p)
return i; return i;
} }
@ -479,13 +479,15 @@ static int get_term_columns(FILE * __EINFO_RESTRICT stream)
return DEFAULT_COLS; return DEFAULT_COLS;
} }
void eprefix(const char *__EINFO_RESTRICT prefix) void
eprefix(const char *__EINFO_RESTRICT prefix)
{ {
_eprefix = prefix; _eprefix = prefix;
} }
hidden_def(eprefix) hidden_def(eprefix)
static void elogv(int level, const char *__EINFO_RESTRICT fmt, va_list ap) static void
elogv(int level, const char *__EINFO_RESTRICT fmt, va_list ap)
{ {
char *e = getenv("EINFO_LOG"); char *e = getenv("EINFO_LOG");
va_list apc; va_list apc;
@ -500,7 +502,8 @@ static void elogv(int level, const char *__EINFO_RESTRICT fmt, va_list ap)
} }
} }
void elog(int level, const char *__EINFO_RESTRICT fmt, ...) void
elog(int level, const char *__EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;
@ -510,7 +513,8 @@ void elog(int level, const char *__EINFO_RESTRICT fmt, ...)
} }
hidden_def(elog) hidden_def(elog)
static int _eindent(FILE * __EINFO_RESTRICT stream) static int
_eindent(FILE * __EINFO_RESTRICT stream)
{ {
char *env = getenv("EINFO_INDENT"); char *env = getenv("EINFO_INDENT");
int amount = 0; int amount = 0;
@ -525,7 +529,7 @@ static int _eindent(FILE * __EINFO_RESTRICT stream)
amount = INDENT_MAX; amount = INDENT_MAX;
if (amount > 0) if (amount > 0)
memset(indent, ' ', (size_t) amount); memset(indent, ' ', (size_t)amount);
} }
/* Terminate it */ /* Terminate it */
@ -533,32 +537,32 @@ static int _eindent(FILE * __EINFO_RESTRICT stream)
return fprintf(stream, "%s", indent); return fprintf(stream, "%s", indent);
} }
static const char *_ecolor(FILE * __EINFO_RESTRICT f, ECOLOR color) static const char *
_ecolor(FILE * __EINFO_RESTRICT f, ECOLOR color)
{ {
unsigned int i; unsigned int i;
if (! colour_terminal(f)) if (!colour_terminal(f))
return ""; return "";
for (i = 0; i < sizeof(ecolors) / sizeof(ecolors[0]); i++) { for (i = 0; i < sizeof(ecolors) / sizeof(ecolors[0]); i++)
if (ecolors[i].color == color) if (ecolors[i].color == color)
return ecolors_str[i]; return ecolors_str[i];
}
return ""; return "";
} }
hidden_def(ecolor) hidden_def(ecolor)
const char *ecolor(ECOLOR color) const char *
ecolor(ECOLOR color)
{ {
FILE *f = stdout; FILE *f = stdout;
/* Try and guess a valid tty */ /* Try and guess a valid tty */
if (! isatty(fileno(f))) { if (!isatty(fileno(f))) {
f = stderr; f = stderr;
if (! isatty(fileno(f))) { if (!isatty(fileno(f))) {
f = stdin; f = stdin;
if (! isatty(fileno(f))) if (!isatty(fileno(f)))
f = NULL; f = NULL;
} }
} }
@ -574,7 +578,7 @@ const char *ecolor(ECOLOR color)
#define EINFOVN(_file, _color) \ #define EINFOVN(_file, _color) \
{ \ { \
char *_e = getenv("EINFO_LASTCMD"); \ char *_e = getenv("EINFO_LASTCMD"); \
if (_e && ! colour_terminal(_file) && strcmp(_e, "ewarn") != 0 && \ if (_e && !colour_terminal(_file) && strcmp(_e, "ewarn") != 0 && \
_e[strlen (_e) - 1] == 'n') \ _e[strlen (_e) - 1] == 'n') \
fprintf(_file, "\n"); \ fprintf(_file, "\n"); \
if (_eprefix) \ if (_eprefix) \
@ -591,67 +595,69 @@ const char *ecolor(ECOLOR color)
fprintf(_file, "%s", flush); \ fprintf(_file, "%s", flush); \
} }
static int _einfovn(const char *__EINFO_RESTRICT fmt, va_list ap) static int
_einfo(FILE *f, ECOLOR color, const char *__EINFO_RESTRICT fmt, va_list va)
{ {
int retval = 0; int retval = 0;
char *last = getenv("EINFO_LASTCMD");
va_list ap;
EINFOVN(stdout, ECOLOR_GOOD); if (last &&
!colour_terminal(f) &&
strcmp(last, "ewarn") != 0 &&
last[strlen(last) - 1] == 'n')
fprintf(f, "\n");
if (_eprefix)
fprintf(f, "%s%s%s|", _ecolor(f, color), _eprefix, _ecolor(f, ECOLOR_NORMAL));
fprintf(f, " %s*%s ", _ecolor(f, color), _ecolor(f, ECOLOR_NORMAL));
retval += _eindent(f);
va_copy(ap, va);
retval += vfprintf(f, fmt, ap) + 3;
va_end(ap); \
if (colour_terminal(f))
fprintf(f, "%s", flush);
return retval; return retval;
} }
static int _ewarnvn(const char *__EINFO_RESTRICT fmt, va_list ap) #define _einfovn(fmt, ap) _einfo(stdout, ECOLOR_GOOD, fmt, ap)
{ #define _ewarnvn(fmt, ap) _einfo(stderr, ECOLOR_WARN, fmt, ap)
int retval = 0; #define _eerrorvn(fmt, ap) _einfo(stderr, ECOLOR_BAD, fmt, ap)
EINFOVN(stderr, ECOLOR_WARN); int
return retval; einfon(const char *__EINFO_RESTRICT fmt, ...)
}
static int _eerrorvn(const char *__EINFO_RESTRICT fmt, va_list ap)
{
int retval = 0;
EINFOVN(stderr, ECOLOR_BAD);
return retval;
}
int einfon(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
if (! fmt || is_quiet()) if (!fmt || is_quiet())
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
retval = _einfovn(fmt, ap); retval = _einfovn(fmt, ap);
va_end(ap); va_end(ap);
LASTCMD("einfon"); LASTCMD("einfon");
return retval; return retval;
} }
hidden_def(einfon) hidden_def(einfon)
int ewarnn(const char *__EINFO_RESTRICT fmt, ...) int
ewarnn(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
if (! fmt || is_quiet()) if (!fmt || is_quiet())
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
retval = _ewarnvn(fmt, ap); retval = _ewarnvn(fmt, ap);
va_end(ap); va_end(ap);
LASTCMD("ewarnn"); LASTCMD("ewarnn");
return retval; return retval;
} }
hidden_def(ewarnn) hidden_def(ewarnn)
int eerrorn(const char *__EINFO_RESTRICT fmt, ...) int
eerrorn(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -659,58 +665,53 @@ int eerrorn(const char *__EINFO_RESTRICT fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
retval = _eerrorvn(fmt, ap); retval = _eerrorvn(fmt, ap);
va_end(ap); va_end(ap);
LASTCMD("errorn"); LASTCMD("errorn");
return retval; return retval;
} }
hidden_def(eerrorn) hidden_def(eerrorn)
int einfo(const char *__EINFO_RESTRICT fmt, ...) int
einfo(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
if (! fmt || is_quiet()) if (!fmt || is_quiet())
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
retval = _einfovn(fmt, ap); retval = _einfovn(fmt, ap);
retval += printf("\n"); retval += printf("\n");
va_end(ap); va_end(ap);
LASTCMD("einfo"); LASTCMD("einfo");
return retval; return retval;
} }
hidden_def(einfo) hidden_def(einfo)
int ewarn(const char *__EINFO_RESTRICT fmt, ...) int
ewarn(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
if (! fmt || is_quiet()) if (!fmt || is_quiet())
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
elogv(LOG_WARNING, fmt, ap); elogv(LOG_WARNING, fmt, ap);
retval = _ewarnvn(fmt, ap); retval = _ewarnvn(fmt, ap);
retval += fprintf(stderr, "\n"); retval += fprintf(stderr, "\n");
va_end(ap); va_end(ap);
LASTCMD("ewarn"); LASTCMD("ewarn");
return retval; return retval;
} }
hidden_def(ewarn) hidden_def(ewarn)
void ewarnx(const char *__EINFO_RESTRICT fmt, ...) void
ewarnx(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
if (fmt && ! is_quiet()) { if (fmt && !is_quiet()) {
va_start(ap, fmt); va_start(ap, fmt);
elogv(LOG_WARNING, fmt, ap); elogv(LOG_WARNING, fmt, ap);
retval = _ewarnvn(fmt, ap); retval = _ewarnvn(fmt, ap);
@ -721,27 +722,26 @@ void ewarnx(const char *__EINFO_RESTRICT fmt, ...)
} }
hidden_def(ewarnx) hidden_def(ewarnx)
int eerror(const char *__EINFO_RESTRICT fmt, ...) int
eerror(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
if (! fmt) if (!fmt)
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
elogv(LOG_ERR, fmt, ap); elogv(LOG_ERR, fmt, ap);
retval = _eerrorvn(fmt, ap); retval = _eerrorvn(fmt, ap);
va_end(ap); va_end(ap);
retval += fprintf(stderr, "\n"); retval += fprintf(stderr, "\n");
LASTCMD("eerror"); LASTCMD("eerror");
return retval; return retval;
} }
hidden_def(eerror) hidden_def(eerror)
void eerrorx(const char *__EINFO_RESTRICT fmt, ...) void
eerrorx(const char *__EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;
@ -752,46 +752,43 @@ void eerrorx(const char *__EINFO_RESTRICT fmt, ...)
va_end(ap); va_end(ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
hidden_def(eerrorx) hidden_def(eerrorx)
int ebegin(const char *__EINFO_RESTRICT fmt, ...) int
ebegin(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
if (! fmt || is_quiet()) if (!fmt || is_quiet())
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
retval = _einfovn(fmt, ap); retval = _einfovn(fmt, ap);
va_end(ap); va_end(ap);
retval += printf(" ..."); retval += printf(" ...");
if (colour_terminal(stdout)) if (colour_terminal(stdout))
retval += printf("\n"); retval += printf("\n");
LASTCMD("ebegin"); LASTCMD("ebegin");
return retval; return retval;
} }
hidden_def(ebegin) hidden_def(ebegin)
static void _eend(FILE * __EINFO_RESTRICT fp, int col, ECOLOR color, static void
const char *msg) _eend(FILE * __EINFO_RESTRICT fp, int col, ECOLOR color, const char *msg)
{ {
int i; int i;
int cols; int cols;
if (! msg) if (!msg)
return; return;
cols = get_term_columns(fp) - (strlen(msg) + 3); cols = get_term_columns(fp) - (strlen(msg) + 3);
/* cons25 is special - we need to remove one char, otherwise things /* cons25 is special - we need to remove one char, otherwise things
* do not align properly at all. */ * do not align properly at all. */
if (! term) { if (!term) {
term = getenv("TERM"); term = getenv("TERM");
if (term && strcmp(term, "cons25") == 0) if (term && strcmp(term, "cons25") == 0)
term_is_cons25 = true; term_is_cons25 = true;
@ -816,7 +813,8 @@ static void _eend(FILE * __EINFO_RESTRICT fp, int col, ECOLOR color,
} }
} }
static int _do_eend(const char *cmd, int retval, const char *__EINFO_RESTRICT fmt, va_list ap) static int
_do_eend(const char *cmd, int retval, const char *__EINFO_RESTRICT fmt, va_list ap)
{ {
int col = 0; int col = 0;
FILE *fp = stdout; FILE *fp = stdout;
@ -832,54 +830,51 @@ static int _do_eend(const char *cmd, int retval, const char *__EINFO_RESTRICT fm
col += fprintf(fp, "\n"); col += fprintf(fp, "\n");
va_end(apc); va_end(apc);
} }
_eend(fp, col, _eend(fp, col,
retval == 0 ? ECOLOR_GOOD : ECOLOR_BAD, retval == 0 ? ECOLOR_GOOD : ECOLOR_BAD,
retval == 0 ? OK : NOT_OK); retval == 0 ? OK : NOT_OK);
return retval; return retval;
} }
int eend(int retval, const char *__EINFO_RESTRICT fmt, ...) int
eend(int retval, const char *__EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;
if (is_quiet()) if (is_quiet())
return retval; return retval;
va_start(ap, fmt); va_start(ap, fmt);
_do_eend("eend", retval, fmt, ap); _do_eend("eend", retval, fmt, ap);
va_end(ap); va_end(ap);
LASTCMD("eend"); LASTCMD("eend");
return retval; return retval;
} }
hidden_def(eend) hidden_def(eend)
int ewend(int retval, const char *__EINFO_RESTRICT fmt, ...) int
ewend(int retval, const char *__EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;
if (is_quiet()) if (is_quiet())
return retval; return retval;
va_start(ap, fmt); va_start(ap, fmt);
_do_eend("ewend", retval, fmt, ap); _do_eend("ewend", retval, fmt, ap);
va_end(ap); va_end(ap);
LASTCMD("ewend"); LASTCMD("ewend");
return retval; return retval;
} }
hidden_def(ewend) hidden_def(ewend)
void ebracket(int col, ECOLOR color, const char *msg) void
ebracket(int col, ECOLOR color, const char *msg)
{ {
_eend(stdout, col, color, msg); _eend(stdout, col, color, msg);
} }
hidden_def(ebracket) hidden_def(ebracket)
void eindent(void) void
eindent(void)
{ {
char *env = getenv("EINFO_INDENT"); char *env = getenv("EINFO_INDENT");
int amount = 0; int amount = 0;
@ -891,11 +886,9 @@ void eindent(void)
if (errno != 0) if (errno != 0)
amount = 0; amount = 0;
} }
amount += INDENT_WIDTH; amount += INDENT_WIDTH;
if (amount > INDENT_MAX) if (amount > INDENT_MAX)
amount = INDENT_MAX; amount = INDENT_MAX;
snprintf(num, 10, "%08d", amount); snprintf(num, 10, "%08d", amount);
setenv("EINFO_INDENT", num, 1); setenv("EINFO_INDENT", num, 1);
} }
@ -908,16 +901,14 @@ void eoutdent(void)
char num[10]; char num[10];
int serrno = errno; int serrno = errno;
if (! env) if (!env)
return; return;
errno = 0; errno = 0;
amount = strtoimax(env, NULL, 0); amount = strtoimax(env, NULL, 0);
if (errno != 0) if (errno != 0)
amount = 0; amount = 0;
else else
amount -= INDENT_WIDTH; amount -= INDENT_WIDTH;
if (amount <= 0) if (amount <= 0)
unsetenv("EINFO_INDENT"); unsetenv("EINFO_INDENT");
else { else {
@ -928,86 +919,79 @@ void eoutdent(void)
} }
hidden_def(eoutdent) hidden_def(eoutdent)
int einfovn(const char *__EINFO_RESTRICT fmt, ...) int
einfovn(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
if (! fmt || ! is_verbose()) if (!fmt || !is_verbose())
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
retval = _einfovn(fmt, ap); retval = _einfovn(fmt, ap);
va_end(ap); va_end(ap);
LASTCMD("einfovn"); LASTCMD("einfovn");
return retval; return retval;
} }
hidden_def(einfovn) hidden_def(einfovn)
int ewarnvn(const char *__EINFO_RESTRICT fmt, ...) int
ewarnvn(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
if (! fmt || ! is_verbose()) if (!fmt || !is_verbose())
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
retval = _ewarnvn(fmt, ap); retval = _ewarnvn(fmt, ap);
va_end(ap); va_end(ap);
LASTCMD("ewarnvn"); LASTCMD("ewarnvn");
return retval; return retval;
} }
hidden_def(ewarnvn) hidden_def(ewarnvn)
int einfov(const char *__EINFO_RESTRICT fmt, ...) int
einfov(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
if (! fmt || ! is_verbose()) if (!fmt || !is_verbose())
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
retval = _einfovn(fmt, ap); retval = _einfovn(fmt, ap);
retval += printf("\n"); retval += printf("\n");
va_end(ap); va_end(ap);
LASTCMD("einfov"); LASTCMD("einfov");
return retval; return retval;
} }
hidden_def(einfov) hidden_def(einfov)
int ewarnv(const char *__EINFO_RESTRICT fmt, ...) int
ewarnv(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
if (! fmt || ! is_verbose()) if (!fmt || !is_verbose())
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
retval = _ewarnvn(fmt, ap); retval = _ewarnvn(fmt, ap);
retval += printf("\n"); retval += printf("\n");
va_end(ap); va_end(ap);
LASTCMD("ewarnv"); LASTCMD("ewarnv");
return retval; return retval;
} }
hidden_def(ewarnv) hidden_def(ewarnv)
int ebeginv(const char *__EINFO_RESTRICT fmt, ...) int
ebeginv(const char *__EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
if (! fmt || ! is_verbose()) if (!fmt || !is_verbose())
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
@ -1016,55 +1000,51 @@ int ebeginv(const char *__EINFO_RESTRICT fmt, ...)
if (colour_terminal(stdout)) if (colour_terminal(stdout))
retval += printf("\n"); retval += printf("\n");
va_end(ap); va_end(ap);
LASTCMD("ebeginv"); LASTCMD("ebeginv");
return retval; return retval;
} }
hidden_def(ebeginv) hidden_def(ebeginv)
int eendv(int retval, const char *__EINFO_RESTRICT fmt, ...) int
eendv(int retval, const char *__EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;
if (! is_verbose()) if (!is_verbose())
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
_do_eend("eendv", retval, fmt, ap); _do_eend("eendv", retval, fmt, ap);
va_end(ap); va_end(ap);
LASTCMD("eendv"); LASTCMD("eendv");
return retval; return retval;
} }
hidden_def(eendv) hidden_def(eendv)
int ewendv(int retval, const char *__EINFO_RESTRICT fmt, ...) int
ewendv(int retval, const char *__EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;
if (! is_verbose()) if (!is_verbose())
return 0; return 0;
va_start(ap, fmt); va_start(ap, fmt);
_do_eend("ewendv", retval, fmt, ap); _do_eend("ewendv", retval, fmt, ap);
va_end(ap); va_end(ap);
LASTCMD("ewendv"); LASTCMD("ewendv");
return retval; return retval;
} }
hidden_def(ewendv) hidden_def(ewendv)
void eindentv(void) void
eindentv(void)
{ {
if (is_verbose()) if (is_verbose())
eindent (); eindent();
} }
hidden_def(eindentv) hidden_def(eindentv)
void eoutdentv(void) void
eoutdentv(void)
{ {
if (is_verbose()) if (is_verbose())
eoutdent(); eoutdent();