diff options
author | Roy Marples <roy@marples.name> | 2008-03-16 17:00:56 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2008-03-16 17:00:56 +0000 |
commit | cb9da6a262b60255cd037f20b4cde3ab2c8a1e6a (patch) | |
tree | c5c57d5adedf009fdb02b53677e2cdf940bdb47c /src/libeinfo/libeinfo.c | |
parent | 40e12f6ba026af9c24d5c3d8e36512719ed5faee (diff) |
Remove null terminated char ** lists in favour of RC_STRINGLIST, using TAILQ from queue(3). Refactor code style around the BSD KNF.
Diffstat (limited to 'src/libeinfo/libeinfo.c')
-rw-r--r-- | src/libeinfo/libeinfo.c | 650 |
1 files changed, 326 insertions, 324 deletions
diff --git a/src/libeinfo/libeinfo.c b/src/libeinfo/libeinfo.c index ee5b8a68..41969964 100644 --- a/src/libeinfo/libeinfo.c +++ b/src/libeinfo/libeinfo.c @@ -34,6 +34,7 @@ const char libeinfo_copyright[] = "Copyright (c) 2007-2008 Roy Marples"; #include <sys/types.h> #include <sys/ioctl.h> #include <sys/stat.h> + #include <errno.h> #include <fcntl.h> #include <inttypes.h> @@ -52,6 +53,7 @@ const char libeinfo_copyright[] = "Copyright (c) 2007-2008 Roy Marples"; #include "einfo.h" #include "hidden-visibility.h" + hidden_proto(ecolor) hidden_proto(ebegin) hidden_proto(ebeginv) @@ -107,10 +109,10 @@ hidden_proto(ewendv) #define ME "\033[m" #define UP "\033[A" -#define _GET_CAP(_d, _c) strlcpy (_d, tgoto (_c, 0, 0), sizeof (_d)); +#define _GET_CAP(_d, _c) strlcpy(_d, tgoto(_c, 0, 0), sizeof(_d)); #define _ASSIGN_CAP(_v) { \ _v = p; \ - p += strlcpy (p, tmp, sizeof (ebuffer) - (p - ebuffer)) + 1; \ + p += strlcpy(p, tmp, sizeof(ebuffer) - (p - ebuffer)) + 1; \ } /* A pointer to a string to prefix to einfo/ewarn/eerror messages */ @@ -119,7 +121,7 @@ static const char *_eprefix = NULL; /* Buffers and structures to hold the final colours */ static char ebuffer[100]; struct ecolor { - einfo_color_t color; + ECOLOR color; int def; const char *name; }; @@ -197,7 +199,7 @@ static const char *const color_terms[] = { /* strlcat and strlcpy are nice, shame glibc does not define them */ #ifdef __GLIBC__ # 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; const char *s = src; @@ -210,7 +212,7 @@ static size_t strlcat (char *dst, const char *src, size_t size) src_n = size - dst_n; if (src_n == 0) - return (dst_n + strlen (src)); + return dst_n + strlen(src); while (*s != '\0') { if (src_n != 1) { @@ -221,10 +223,10 @@ static size_t strlcat (char *dst, const char *src, size_t size) } *d = '\0'; - 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; size_t n = size; @@ -241,72 +243,72 @@ static size_t strlcpy (char *dst, const char *src, size_t size) while (*src++); } - return (src - s - 1); + return src - s - 1; } # endif #endif -static bool yesno (const char *value) +static bool yesno(const char *value) { if (! value) { errno = ENOENT; - return (false); + return false; } - if (strcasecmp (value, "yes") == 0 || - strcasecmp (value, "y") == 0 || - strcasecmp (value, "true") == 0 || - strcasecmp (value, "on") == 0 || - strcasecmp (value, "1") == 0) - return (true); - - if (strcasecmp (value, "no") != 0 && - strcasecmp (value, "n") != 0 && - strcasecmp (value, "false") != 0 && - strcasecmp (value, "off") != 0 && - strcasecmp (value, "0") != 0) + if (strcasecmp(value, "yes") == 0 || + strcasecmp(value, "y") == 0 || + strcasecmp(value, "true") == 0 || + strcasecmp(value, "on") == 0 || + strcasecmp(value, "1") == 0) + return true; + + if (strcasecmp(value, "no") != 0 && + strcasecmp(value, "n") != 0 && + strcasecmp(value, "false") != 0 && + strcasecmp(value, "off") != 0 && + strcasecmp(value, "0") != 0) errno = EINVAL; - return (false); + return false; } -static bool noyes (const char *value) +static bool noyes(const char *value) { int serrno = errno; bool retval; errno = 0; - retval = yesno (value); + retval = yesno(value); if (errno == 0) { retval = ! retval; errno = serrno; } - return (retval); + return retval; } -static bool is_quiet() +static bool is_quiet(void) { - return (yesno (getenv ("EINFO_QUIET"))); + return yesno(getenv("EINFO_QUIET")); } -static bool is_verbose() +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 */ #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]; - snprintf (buf, sizeof (buf), cap, b, a); - return (buf); + snprintf(buf, sizeof(buf), cap, b, a); + return buf; } #endif -static bool colour_terminal (FILE * __EINFO_RESTRICT f) +static bool colour_terminal(FILE * __EINFO_RESTRICT f) { static int in_colour = -1; char *e; @@ -321,50 +323,50 @@ static bool colour_terminal (FILE * __EINFO_RESTRICT f) char *p; unsigned int i = 0; - if (f && ! isatty (fileno (f))) - return (false); + if (f && ! isatty(fileno(f))) + return false; - if (noyes (getenv ("EINFO_COLOR"))) - return (false); + if (noyes(getenv("EINFO_COLOR"))) + return false; if (in_colour == 0) - return (false); + return false; if (in_colour == 1) - return (true); + return true; term_is_cons25 = false; if (! term) { - term = getenv ("TERM"); + term = getenv("TERM"); if (! term) - return (false); + return false; } - if (strcmp (term, "cons25") == 0) + if (strcmp(term, "cons25") == 0) term_is_cons25 = true; #ifdef HAVE_TERMCAP /* Check termcap to see if we can do colour or not */ - if (tgetent (termcapbuf, term) == 1) { + if (tgetent(termcapbuf, term) == 1) { char *bp = tcapbuf; - _af = tgetstr ("AF", &bp); - _ce = tgetstr ("ce", &bp); - _ch = tgetstr ("ch", &bp); + _af = tgetstr("AF", &bp); + _ce = tgetstr("ce", &bp); + _ch = tgetstr("ch", &bp); /* Our ch use also works with RI .... for now */ if (! _ch) - _ch = tgetstr ("RI", &bp); - _md = tgetstr ("md", &bp); - _me = tgetstr ("me", &bp); - _up = tgetstr ("up", &bp); + _ch = tgetstr("RI", &bp); + _md = tgetstr("md", &bp); + _me = tgetstr("me", &bp); + _up = tgetstr("up", &bp); } /* Cheat here as vanilla BSD has the whole termcap info in /usr * which is not available to us when we boot */ - if (term_is_cons25 || strcmp (term, "wsvt25") == 0) { + if (term_is_cons25 || strcmp(term, "wsvt25") == 0) { #else while (color_terms[i]) { - if (strcmp (color_terms[i], term) == 0) { + if (strcmp(color_terms[i], term) == 0) { in_colour = 1; } i++; @@ -372,7 +374,7 @@ static bool colour_terminal (FILE * __EINFO_RESTRICT f) if (in_colour != 1) { in_colour = 0; - return (false); + return false; } #endif if (! _af) @@ -392,7 +394,7 @@ static bool colour_terminal (FILE * __EINFO_RESTRICT f) if (! _af || ! _ce || ! _me || !_md || ! _up) { in_colour = 0; - return (false); + return false; } /* Many termcap databases don't have ch or RI even though they @@ -403,7 +405,7 @@ static bool colour_terminal (FILE * __EINFO_RESTRICT f) /* Now setup our colours */ 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'; if (ecolors[i].name) { @@ -414,370 +416,370 @@ static bool colour_terminal (FILE * __EINFO_RESTRICT f) * We use a :col;bold: format like 2;1: for bold green * and 1;0: for a normal red */ if ((e = getenv("EINFO_COLOR"))) { - char *ee = strstr (e, ecolors[i].name); + char *ee = strstr(e, ecolors[i].name); if (ee) - ee += strlen (ecolors[i].name); + ee += strlen(ecolors[i].name); if (ee && *ee == '=') { - char *d = strdup (ee + 1); + char *d = strdup(ee + 1); if (d) { - char *end = strchr (d, ':'); + char *end = strchr(d, ':'); if (end) *end = '\0'; c = atoi(d); - end = strchr (d, ';'); + end = strchr(d, ';'); if (end && *++end == '0') bold = _me; - free (d); + free(d); } } } - strlcpy (tmp, tgoto (bold, 0, 0), sizeof (tmp)); - strlcat (tmp, tgoto (_af, 0, c & 0x07), sizeof (tmp)); + strlcpy(tmp, tgoto(bold, 0, 0), sizeof(tmp)); + strlcat(tmp, tgoto(_af, 0, c & 0x07), sizeof(tmp)); } else - _GET_CAP (tmp, _me); + _GET_CAP(tmp, _me); if (tmp[0]) - _ASSIGN_CAP (ecolors_str[i]) + _ASSIGN_CAP(ecolors_str[i]) else ecolors_str[i] = &nullstr; } - _GET_CAP (tmp, _ce) - _ASSIGN_CAP (flush) - _GET_CAP (tmp, _up); - _ASSIGN_CAP (up); - strlcpy (tmp, _ch, sizeof (tmp)); - _ASSIGN_CAP (goto_column); + _GET_CAP(tmp, _ce); + _ASSIGN_CAP(flush); + _GET_CAP(tmp, _up); + _ASSIGN_CAP(up); + strlcpy(tmp, _ch, sizeof(tmp)); + _ASSIGN_CAP(goto_column); in_colour = 1; - 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; - char *env = getenv ("COLUMNS"); + char *env = getenv("COLUMNS"); char *p; int i; if (env) { - i = strtoimax (env, &p, 10); + i = strtoimax(env, &p, 10); if (! *p) - return (i); + return i; } - if (ioctl (fileno (stream), TIOCGWINSZ, &ws) == 0) - return (ws.ws_col); + if (ioctl(fileno(stream), TIOCGWINSZ, &ws) == 0) + return ws.ws_col; - return (DEFAULT_COLS); + return DEFAULT_COLS; } -void eprefix (const char *__EINFO_RESTRICT prefix) +void eprefix(const char *__EINFO_RESTRICT prefix) { _eprefix = prefix; } 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; if (fmt && e) { - closelog (); - openlog (e, LOG_PID, LOG_DAEMON); - va_copy (apc, ap); - vsyslog (level, fmt, apc); - va_end (apc); - closelog (); + closelog(); + openlog(e, LOG_PID, LOG_DAEMON); + va_copy(apc, ap); + vsyslog(level, fmt, apc); + va_end(apc); + closelog(); } } -void elog (int level, const char *__EINFO_RESTRICT fmt, ...) +void elog(int level, const char *__EINFO_RESTRICT fmt, ...) { va_list ap; - va_start (ap, fmt); - elogv (level, fmt, ap); - va_end (ap); + va_start(ap, fmt); + elogv(level, fmt, ap); + va_end(ap); } 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; char indent[INDENT_MAX]; if (env) { errno = 0; - amount = strtoimax (env, NULL, 0); + amount = strtoimax(env, NULL, 0); if (errno != 0 || amount < 0) amount = 0; else if (amount > INDENT_MAX) amount = INDENT_MAX; if (amount > 0) - memset (indent, ' ', (size_t) amount); + memset(indent, ' ', (size_t) amount); } /* Terminate it */ - memset (indent + amount, 0, 1); - return (fprintf (stream, "%s", indent)); + memset(indent + amount, 0, 1); + return fprintf(stream, "%s", indent); } -static const char *_ecolor (FILE * __EINFO_RESTRICT f, einfo_color_t color) +static const char *_ecolor(FILE * __EINFO_RESTRICT f, ECOLOR color) { unsigned int i; - if (! colour_terminal (f)) - return (""); + if (! colour_terminal(f)) + 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) - return (ecolors_str[i]); + return ecolors_str[i]; } - return (""); + return ""; } hidden_def(ecolor) -const char *ecolor (einfo_color_t color) +const char *ecolor(ECOLOR color) { FILE *f = stdout; /* Try and guess a valid tty */ - if (! isatty (fileno (f))) { + if (! isatty(fileno(f))) { f = stderr; - if (! isatty (fileno (f))) { + if (! isatty(fileno(f))) { f = stdin; - if (! isatty (fileno (f))) + if (! isatty(fileno(f))) f = NULL; } } - return (_ecolor (f, color)); + return _ecolor(f, color); } #define LASTCMD(_cmd) { \ - unsetenv ("EINFO_LASTCMD"); \ - setenv ("EINFO_LASTCMD", _cmd, 1); \ + unsetenv("EINFO_LASTCMD"); \ + setenv("EINFO_LASTCMD", _cmd, 1); \ } #define EINFOVN(_file, _color) \ { \ - char *_e = getenv ("EINFO_LASTCMD"); \ - if (_e && ! colour_terminal (_file) && strcmp (_e, "ewarn") != 0 && \ + char *_e = getenv("EINFO_LASTCMD"); \ + if (_e && ! colour_terminal(_file) && strcmp(_e, "ewarn") != 0 && \ _e[strlen (_e) - 1] == 'n') \ - fprintf (_file, "\n"); \ + fprintf(_file, "\n"); \ if (_eprefix) \ - fprintf (_file, "%s%s%s|", _ecolor (_file, _color), _eprefix, _ecolor (_file, ECOLOR_NORMAL)); \ - fprintf (_file, " %s*%s ", _ecolor (_file, _color), _ecolor (_file, ECOLOR_NORMAL)); \ - retval += _eindent (_file); \ + fprintf(_file, "%s%s%s|", _ecolor(_file, _color), _eprefix, _ecolor(_file, ECOLOR_NORMAL)); \ + fprintf(_file, " %s*%s ", _ecolor(_file, _color), _ecolor(_file, ECOLOR_NORMAL)); \ + retval += _eindent(_file); \ { \ va_list _ap; \ - va_copy (_ap, ap); \ - retval += vfprintf (_file, fmt, _ap) + 3; \ - va_end (_ap); \ + va_copy(_ap, ap); \ + retval += vfprintf(_file, fmt, _ap) + 3; \ + va_end(_ap); \ } \ - if (colour_terminal (_file)) \ - fprintf (_file, "%s", flush); \ + if (colour_terminal(_file)) \ + fprintf(_file, "%s", flush); \ } -static int _einfovn (const char *__EINFO_RESTRICT fmt, va_list ap) +static int _einfovn(const char *__EINFO_RESTRICT fmt, va_list ap) { int retval = 0; - EINFOVN (stdout, ECOLOR_GOOD); - return (retval); + EINFOVN(stdout, ECOLOR_GOOD); + return retval; } -static int _ewarnvn (const char *__EINFO_RESTRICT fmt, va_list ap) +static int _ewarnvn(const char *__EINFO_RESTRICT fmt, va_list ap) { int retval = 0; - EINFOVN (stderr, ECOLOR_WARN); - return (retval); + EINFOVN(stderr, ECOLOR_WARN); + return retval; } -static int _eerrorvn (const char *__EINFO_RESTRICT fmt, va_list ap) +static int _eerrorvn(const char *__EINFO_RESTRICT fmt, va_list ap) { int retval = 0; - EINFOVN (stderr, ECOLOR_BAD); - return (retval); + EINFOVN(stderr, ECOLOR_BAD); + return retval; } -int einfon (const char *__EINFO_RESTRICT fmt, ...) +int einfon(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; - if (! fmt || is_quiet ()) - return (0); + if (! fmt || is_quiet()) + return 0; - va_start (ap, fmt); - retval = _einfovn (fmt, ap); - va_end (ap); + va_start(ap, fmt); + retval = _einfovn(fmt, ap); + va_end(ap); - LASTCMD ("einfon"); + LASTCMD("einfon"); - return (retval); + return retval; } hidden_def(einfon) -int ewarnn (const char *__EINFO_RESTRICT fmt, ...) +int ewarnn(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; - if (! fmt || is_quiet ()) - return (0); + if (! fmt || is_quiet()) + return 0; - va_start (ap, fmt); - retval = _ewarnvn (fmt, ap); - va_end (ap); + va_start(ap, fmt); + retval = _ewarnvn(fmt, ap); + va_end(ap); - LASTCMD ("ewarnn"); + LASTCMD("ewarnn"); - return (retval); + return retval; } hidden_def(ewarnn) -int eerrorn (const char *__EINFO_RESTRICT fmt, ...) +int eerrorn(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; - va_start (ap, fmt); - retval = _eerrorvn (fmt, ap); - va_end (ap); + va_start(ap, fmt); + retval = _eerrorvn(fmt, ap); + va_end(ap); - LASTCMD ("errorn"); + LASTCMD("errorn"); - return (retval); + return retval; } hidden_def(eerrorn) -int einfo (const char *__EINFO_RESTRICT fmt, ...) +int einfo(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; if (! fmt || is_quiet()) - return (0); + return 0; - va_start (ap, fmt); - retval = _einfovn (fmt, ap); - retval += printf ("\n"); - va_end (ap); + va_start(ap, fmt); + retval = _einfovn(fmt, ap); + retval += printf("\n"); + va_end(ap); - LASTCMD ("einfo"); + LASTCMD("einfo"); - return (retval); + return retval; } hidden_def(einfo) -int ewarn (const char *__EINFO_RESTRICT fmt, ...) +int ewarn(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; - if (! fmt || is_quiet ()) - return (0); + if (! fmt || is_quiet()) + return 0; - va_start (ap, fmt); - elogv (LOG_WARNING, fmt, ap); - retval = _ewarnvn (fmt, ap); - retval += fprintf (stderr, "\n"); - va_end (ap); + va_start(ap, fmt); + elogv(LOG_WARNING, fmt, ap); + retval = _ewarnvn(fmt, ap); + retval += fprintf(stderr, "\n"); + va_end(ap); - LASTCMD ("ewarn"); + LASTCMD("ewarn"); - return (retval); + return retval; } hidden_def(ewarn) -void ewarnx (const char *__EINFO_RESTRICT fmt, ...) +void ewarnx(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; - if (fmt && ! is_quiet ()) { - va_start (ap, fmt); - elogv (LOG_WARNING, fmt, ap); - retval = _ewarnvn (fmt, ap); - va_end (ap); - retval += fprintf (stderr, "\n"); + if (fmt && ! is_quiet()) { + va_start(ap, fmt); + elogv(LOG_WARNING, fmt, ap); + retval = _ewarnvn(fmt, ap); + va_end(ap); + retval += fprintf(stderr, "\n"); } - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } hidden_def(ewarnx) -int eerror (const char *__EINFO_RESTRICT fmt, ...) +int eerror(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; if (! fmt) - return (0); + return 0; - va_start (ap, fmt); - elogv (LOG_ERR, fmt, ap); - retval = _eerrorvn (fmt, ap); - va_end (ap); - retval += fprintf (stderr, "\n"); + va_start(ap, fmt); + elogv(LOG_ERR, fmt, ap); + retval = _eerrorvn(fmt, ap); + va_end(ap); + retval += fprintf(stderr, "\n"); - LASTCMD ("eerror"); + LASTCMD("eerror"); - return (retval); + return retval; } hidden_def(eerror) -void eerrorx (const char *__EINFO_RESTRICT fmt, ...) +void eerrorx(const char *__EINFO_RESTRICT fmt, ...) { va_list ap; if (fmt) { - va_start (ap, fmt); - elogv (LOG_ERR, fmt, ap); - _eerrorvn (fmt, ap); - va_end (ap); - fprintf (stderr, "\n"); + va_start(ap, fmt); + elogv(LOG_ERR, fmt, ap); + _eerrorvn(fmt, ap); + va_end(ap); + fprintf(stderr, "\n"); } - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } hidden_def(eerrorx) -int ebegin (const char *__EINFO_RESTRICT fmt, ...) +int ebegin(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; - if (! fmt || is_quiet ()) - return (0); + if (! fmt || is_quiet()) + return 0; - va_start (ap, fmt); - retval = _einfovn (fmt, ap); - va_end (ap); - retval += printf (" ..."); - if (colour_terminal (stdout)) - retval += printf ("\n"); + va_start(ap, fmt); + retval = _einfovn(fmt, ap); + va_end(ap); + retval += printf(" ..."); + if (colour_terminal(stdout)) + retval += printf("\n"); - LASTCMD ("ebegin"); + LASTCMD("ebegin"); - return (retval); + return retval; } hidden_def(ebegin) -static void _eend (FILE * __EINFO_RESTRICT fp, int col, einfo_color_t color, - const char *msg) +static void _eend(FILE * __EINFO_RESTRICT fp, int col, ECOLOR color, + const char *msg) { int i; int cols; @@ -785,13 +787,13 @@ static void _eend (FILE * __EINFO_RESTRICT fp, int col, einfo_color_t color, if (! msg) 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 * do not align properly at all. */ if (! term) { - term = getenv ("TERM"); - if (term && strcmp (term, "cons25") == 0) + term = getenv("TERM"); + if (term && strcmp(term, "cons25") == 0) term_is_cons25 = true; else term_is_cons25 = false; @@ -799,19 +801,19 @@ static void _eend (FILE * __EINFO_RESTRICT fp, int col, einfo_color_t color, if (term_is_cons25) cols--; - if (cols > 0 && colour_terminal (fp)) { - fprintf (fp, "%s%s %s[%s%s%s]%s\n", up, tgoto (goto_column, 0, cols), - ecolor (ECOLOR_BRACKET), ecolor (color), msg, - ecolor (ECOLOR_BRACKET), ecolor (ECOLOR_NORMAL)); + if (cols > 0 && colour_terminal(fp)) { + fprintf(fp, "%s%s %s[%s%s%s]%s\n", up, tgoto(goto_column, 0, cols), + ecolor(ECOLOR_BRACKET), ecolor(color), msg, + ecolor(ECOLOR_BRACKET), ecolor(ECOLOR_NORMAL)); } else { if (col > 0) for (i = 0; i < cols - col; i++) - fprintf (fp, " "); - fprintf (fp, " [%s]\n", msg); + fprintf(fp, " "); + fprintf(fp, " [%s]\n", msg); } } -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; FILE *fp = stdout; @@ -819,70 +821,70 @@ static int _do_eend (const char *cmd, int retval, const char *__EINFO_RESTRICT f if (fmt && *fmt != '\0' && retval != 0) { fp = stderr; - va_copy (apc, ap); - if (strcmp (cmd, "ewend") == 0) - col = _ewarnvn (fmt, apc); + va_copy(apc, ap); + if (strcmp(cmd, "ewend") == 0) + col = _ewarnvn(fmt, apc); else - col = _eerrorvn (fmt, apc); - col += fprintf (fp, "\n"); - va_end (apc); + col = _eerrorvn(fmt, apc); + col += fprintf(fp, "\n"); + va_end(apc); } - _eend (fp, col, - retval == 0 ? ECOLOR_GOOD : ECOLOR_BAD, - retval == 0 ? OK : NOT_OK); - return (retval); + _eend(fp, col, + retval == 0 ? ECOLOR_GOOD : ECOLOR_BAD, + retval == 0 ? OK : NOT_OK); + return retval; } -int eend (int retval, const char *__EINFO_RESTRICT fmt, ...) +int eend(int retval, const char *__EINFO_RESTRICT fmt, ...) { va_list ap; - if (is_quiet ()) - return (retval); + if (is_quiet()) + return retval; - va_start (ap, fmt); - _do_eend ("eend", retval, fmt, ap); - va_end (ap); + va_start(ap, fmt); + _do_eend("eend", retval, fmt, ap); + va_end(ap); - LASTCMD ("eend"); + LASTCMD("eend"); - return (retval); + return retval; } hidden_def(eend) -int ewend (int retval, const char *__EINFO_RESTRICT fmt, ...) +int ewend(int retval, const char *__EINFO_RESTRICT fmt, ...) { va_list ap; - if (is_quiet ()) - return (retval); + if (is_quiet()) + return retval; - va_start (ap, fmt); - _do_eend ("ewend", retval, fmt, ap); - va_end (ap); + va_start(ap, fmt); + _do_eend("ewend", retval, fmt, ap); + va_end(ap); - LASTCMD ("ewend"); + LASTCMD("ewend"); - return (retval); + return retval; } hidden_def(ewend) -void ebracket (int col, einfo_color_t 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) -void eindent (void) +void eindent(void) { - char *env = getenv ("EINFO_INDENT"); + char *env = getenv("EINFO_INDENT"); int amount = 0; char num[10]; if (env) { errno = 0; - amount = strtoimax (env, NULL, 0); + amount = strtoimax(env, NULL, 0); if (errno != 0) amount = 0; } @@ -891,14 +893,14 @@ void eindent (void) if (amount > INDENT_MAX) amount = INDENT_MAX; - snprintf (num, 10, "%08d", amount); - setenv ("EINFO_INDENT", num, 1); + snprintf(num, 10, "%08d", amount); + setenv("EINFO_INDENT", num, 1); } hidden_def(eindent) -void eoutdent (void) +void eoutdent(void) { - char *env = getenv ("EINFO_INDENT"); + char *env = getenv("EINFO_INDENT"); int amount = 0; char num[10]; int serrno = errno; @@ -907,161 +909,161 @@ void eoutdent (void) return; errno = 0; - amount = strtoimax (env, NULL, 0); + amount = strtoimax(env, NULL, 0); if (errno != 0) amount = 0; else amount -= INDENT_WIDTH; if (amount <= 0) - unsetenv ("EINFO_INDENT"); + unsetenv("EINFO_INDENT"); else { - snprintf (num, 10, "%08d", amount); - setenv ("EINFO_INDENT", num, 1); + snprintf(num, 10, "%08d", amount); + setenv("EINFO_INDENT", num, 1); } errno = serrno; } hidden_def(eoutdent) -int einfovn (const char *__EINFO_RESTRICT fmt, ...) +int einfovn(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; - if (! fmt || ! is_verbose ()) - return (0); + if (! fmt || ! is_verbose()) + return 0; - va_start (ap, fmt); - retval = _einfovn (fmt, ap); - va_end (ap); + va_start(ap, fmt); + retval = _einfovn(fmt, ap); + va_end(ap); - LASTCMD ("einfovn"); + LASTCMD("einfovn"); - return (retval); + return retval; } hidden_def(einfovn) -int ewarnvn (const char *__EINFO_RESTRICT fmt, ...) +int ewarnvn(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; - if (! fmt || ! is_verbose ()) - return (0); + if (! fmt || ! is_verbose()) + return 0; - va_start (ap, fmt); - retval = _ewarnvn (fmt, ap); - va_end (ap); + va_start(ap, fmt); + retval = _ewarnvn(fmt, ap); + va_end(ap); - LASTCMD ("ewarnvn"); + LASTCMD("ewarnvn"); - return (retval); + return retval; } hidden_def(ewarnvn) -int einfov (const char *__EINFO_RESTRICT fmt, ...) +int einfov(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; - if (! fmt || ! is_verbose ()) - return (0); + if (! fmt || ! is_verbose()) + return 0; - va_start (ap, fmt); - retval = _einfovn (fmt, ap); - retval += printf ("\n"); - va_end (ap); + va_start(ap, fmt); + retval = _einfovn(fmt, ap); + retval += printf("\n"); + va_end(ap); - LASTCMD ("einfov"); + LASTCMD("einfov"); - return (retval); + return retval; } hidden_def(einfov) -int ewarnv (const char *__EINFO_RESTRICT fmt, ...) +int ewarnv(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; - if (! fmt || ! is_verbose ()) - return (0); + if (! fmt || ! is_verbose()) + return 0; - va_start (ap, fmt); - retval = _ewarnvn (fmt, ap); - retval += printf ("\n"); - va_end (ap); + va_start(ap, fmt); + retval = _ewarnvn(fmt, ap); + retval += printf("\n"); + va_end(ap); - LASTCMD ("ewarnv"); + LASTCMD("ewarnv"); - return (retval); + return retval; } hidden_def(ewarnv) -int ebeginv (const char *__EINFO_RESTRICT fmt, ...) +int ebeginv(const char *__EINFO_RESTRICT fmt, ...) { int retval; va_list ap; - if (! fmt || ! is_verbose ()) - return (0); + if (! fmt || ! is_verbose()) + return 0; - va_start (ap, fmt); - retval = _einfovn (fmt, ap); - retval += printf (" ..."); - if (colour_terminal (stdout)) - retval += printf ("\n"); - va_end (ap); + va_start(ap, fmt); + retval = _einfovn(fmt, ap); + retval += printf(" ..."); + if (colour_terminal(stdout)) + retval += printf("\n"); + va_end(ap); - LASTCMD ("ebeginv"); + LASTCMD("ebeginv"); - return (retval); + return retval; } hidden_def(ebeginv) -int eendv (int retval, const char *__EINFO_RESTRICT fmt, ...) +int eendv(int retval, const char *__EINFO_RESTRICT fmt, ...) { va_list ap; - if (! is_verbose ()) - return (0); + if (! is_verbose()) + return 0; - va_start (ap, fmt); - _do_eend ("eendv", retval, fmt, ap); - va_end (ap); + va_start(ap, fmt); + _do_eend("eendv", retval, fmt, ap); + va_end(ap); - LASTCMD ("eendv"); + LASTCMD("eendv"); - return (retval); + return retval; } hidden_def(eendv) -int ewendv (int retval, const char *__EINFO_RESTRICT fmt, ...) +int ewendv(int retval, const char *__EINFO_RESTRICT fmt, ...) { va_list ap; - if (! is_verbose ()) - return (0); + if (! is_verbose()) + return 0; - va_start (ap, fmt); - _do_eend ("ewendv", retval, fmt, ap); - va_end (ap); + va_start(ap, fmt); + _do_eend("ewendv", retval, fmt, ap); + va_end(ap); - LASTCMD ("ewendv"); + LASTCMD("ewendv"); - return (retval); + return retval; } hidden_def(ewendv) -void eindentv (void) +void eindentv(void) { - if (is_verbose ()) + if (is_verbose()) eindent (); } hidden_def(eindentv) -void eoutdentv (void) +void eoutdentv(void) { - if (is_verbose ()) - eoutdent (); + if (is_verbose()) + eoutdent(); } hidden_def(eoutdentv) |