2007-04-05 16:48:42 +05:30
|
|
|
/*
|
|
|
|
einfo.c
|
2007-11-14 20:52:04 +05:30
|
|
|
Informational functions
|
2007-04-05 16:48:42 +05:30
|
|
|
*/
|
|
|
|
|
2007-11-14 20:52:04 +05:30
|
|
|
/*
|
|
|
|
* Copyright 2007 Roy Marples
|
|
|
|
* All rights reserved
|
|
|
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2007-12-14 19:42:38 +05:30
|
|
|
const char copyright[] = "Copyright (c) 2007 Roy Marples";
|
2007-11-19 22:11:36 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
2007-04-24 16:59:19 +05:30
|
|
|
#include <fcntl.h>
|
2007-04-05 16:48:42 +05:30
|
|
|
#include <limits.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2007-10-09 18:22:09 +05:30
|
|
|
#include <strings.h>
|
2007-04-05 16:48:42 +05:30
|
|
|
#include <syslog.h>
|
2007-12-08 08:20:35 +05:30
|
|
|
#ifdef HAVE_TERMCAP
|
|
|
|
#include <termcap.h>
|
|
|
|
#endif
|
2007-04-05 16:48:42 +05:30
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "einfo.h"
|
|
|
|
#include "rc.h"
|
|
|
|
#include "rc-misc.h"
|
|
|
|
|
2007-04-13 19:48:38 +05:30
|
|
|
#include "hidden-visibility.h"
|
2007-04-17 15:02:18 +05:30
|
|
|
hidden_proto(ecolor)
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_proto(ebegin)
|
|
|
|
hidden_proto(ebeginv)
|
|
|
|
hidden_proto(ebracket)
|
|
|
|
hidden_proto(eend)
|
|
|
|
hidden_proto(eendv)
|
|
|
|
hidden_proto(eerror)
|
|
|
|
hidden_proto(eerrorn)
|
|
|
|
hidden_proto(eerrorx)
|
|
|
|
hidden_proto(eindent)
|
|
|
|
hidden_proto(eindentv)
|
|
|
|
hidden_proto(einfo)
|
|
|
|
hidden_proto(einfon)
|
|
|
|
hidden_proto(einfov)
|
|
|
|
hidden_proto(einfovn)
|
2007-08-16 22:23:20 +05:30
|
|
|
hidden_proto(elog)
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_proto(eoutdent)
|
|
|
|
hidden_proto(eoutdentv)
|
2007-10-03 18:25:27 +05:30
|
|
|
hidden_proto(eprefix)
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_proto(ewarn)
|
|
|
|
hidden_proto(ewarnn)
|
|
|
|
hidden_proto(ewarnv)
|
|
|
|
hidden_proto(ewarnvn)
|
|
|
|
hidden_proto(ewarnx)
|
|
|
|
hidden_proto(ewend)
|
|
|
|
hidden_proto(ewendv)
|
|
|
|
|
2007-04-17 15:02:18 +05:30
|
|
|
/* Incase we cannot work out how many columns from ioctl, supply a default */
|
2007-04-05 16:48:42 +05:30
|
|
|
#define DEFAULT_COLS 80
|
|
|
|
|
2007-04-17 15:02:18 +05:30
|
|
|
#define OK "ok"
|
|
|
|
#define NOT_OK "!!"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
/* Number of spaces for an indent */
|
2007-04-05 16:48:42 +05:30
|
|
|
#define INDENT_WIDTH 2
|
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
/* How wide can the indent go? */
|
2007-04-17 15:02:18 +05:30
|
|
|
#define INDENT_MAX 40
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-17 15:02:18 +05:30
|
|
|
/* Default colours */
|
2007-12-08 08:20:35 +05:30
|
|
|
#define GOOD 2
|
|
|
|
#define WARN 3
|
|
|
|
#define BAD 1
|
|
|
|
#define HILITE 6
|
|
|
|
#define BRACKET 4
|
|
|
|
|
|
|
|
/* We fallback to these escape codes if termcap isn't available
|
|
|
|
* like say /usr isn't mounted */
|
|
|
|
#define AF "\033[3%dm"
|
|
|
|
#define CE "\033[K"
|
|
|
|
#define CH "\033[%dC"
|
|
|
|
#define MD "\033[1m"
|
|
|
|
#define ME "\033[m"
|
|
|
|
#define UP "\033[A"
|
|
|
|
|
|
|
|
/* A pointer to a string to prefix to einfo/ewarn/eerror messages */
|
|
|
|
static const char *_eprefix = NULL;
|
|
|
|
|
|
|
|
/* Buffers and structures to hold the final colours */
|
|
|
|
static char ebuffer[100];
|
|
|
|
struct ecolor {
|
|
|
|
einfo_color_t color;
|
|
|
|
int def;
|
|
|
|
const char *name;
|
|
|
|
char *str;
|
|
|
|
};
|
|
|
|
static char nullstr = '\0';
|
|
|
|
|
|
|
|
static struct ecolor ecolors[] = {
|
|
|
|
{ ECOLOR_GOOD, GOOD, "good", NULL },
|
|
|
|
{ ECOLOR_WARN, WARN, "warn", NULL },
|
|
|
|
{ ECOLOR_BAD, BAD, "bad", NULL },
|
|
|
|
{ ECOLOR_HILITE, HILITE, "hilite", NULL },
|
|
|
|
{ ECOLOR_BRACKET, BRACKET, "bracket", NULL },
|
|
|
|
{ ECOLOR_NORMAL, 0, NULL, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *flush = NULL;
|
|
|
|
static char *up = NULL;
|
|
|
|
static char *goto_column = NULL;
|
|
|
|
|
|
|
|
static const char *term = NULL;
|
|
|
|
static bool term_is_cons25 = false;
|
|
|
|
|
|
|
|
/* Termcap buffers and pointers
|
|
|
|
* Static buffers suck hard, but some termcap implementations require them */
|
|
|
|
#ifdef HAVE_TERMCAP
|
|
|
|
static char termcapbuf[2048];
|
|
|
|
static char tcapbuf[512];
|
|
|
|
#else
|
|
|
|
/* No curses support, so we hardcode a list of colour capable terms */
|
2007-04-17 15:02:18 +05:30
|
|
|
static const char *color_terms[] = {
|
2007-04-11 18:14:47 +05:30
|
|
|
"Eterm",
|
|
|
|
"ansi",
|
|
|
|
"color-xterm",
|
|
|
|
"con132x25",
|
|
|
|
"con132x30",
|
|
|
|
"con132x43",
|
|
|
|
"con132x60",
|
|
|
|
"con80x25",
|
|
|
|
"con80x28",
|
|
|
|
"con80x30",
|
|
|
|
"con80x43",
|
|
|
|
"con80x50",
|
|
|
|
"con80x60",
|
|
|
|
"cons25",
|
|
|
|
"console",
|
|
|
|
"cygwin",
|
|
|
|
"dtterm",
|
|
|
|
"gnome",
|
|
|
|
"konsole",
|
|
|
|
"kterm",
|
|
|
|
"linux",
|
|
|
|
"linux-c",
|
|
|
|
"mach-color",
|
|
|
|
"mlterm",
|
|
|
|
"putty",
|
|
|
|
"rxvt",
|
|
|
|
"rxvt-cygwin",
|
|
|
|
"rxvt-cygwin-native",
|
|
|
|
"rxvt-unicode",
|
|
|
|
"screen",
|
|
|
|
"screen-bce",
|
|
|
|
"screen-w",
|
|
|
|
"screen.linux",
|
|
|
|
"vt100",
|
|
|
|
"xterm",
|
|
|
|
"xterm-256color",
|
|
|
|
"xterm-color",
|
|
|
|
"xterm-debian",
|
|
|
|
NULL
|
2007-04-05 16:48:42 +05:30
|
|
|
};
|
2007-12-08 08:20:35 +05:30
|
|
|
#endif
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
char *d = dst;
|
|
|
|
const char *s = src;
|
|
|
|
size_t src_n = size;
|
|
|
|
size_t dst_n;
|
|
|
|
|
|
|
|
while (src_n-- != 0 && *d != '\0')
|
|
|
|
d++;
|
|
|
|
dst_n = d - dst;
|
|
|
|
src_n = size - dst_n;
|
|
|
|
|
|
|
|
if (src_n == 0)
|
|
|
|
return (dst_n + strlen (src));
|
|
|
|
|
|
|
|
while (*s != '\0') {
|
|
|
|
if (src_n != 1) {
|
|
|
|
*d++ = *s;
|
|
|
|
src_n--;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
*d = '\0';
|
2007-04-24 16:59:19 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
return (dst_n + (s - src));
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t strlcpy (char *dst, const char *src, size_t size)
|
|
|
|
{
|
|
|
|
const char *s = src;
|
|
|
|
size_t n = size;
|
|
|
|
|
|
|
|
if (n && --n)
|
|
|
|
do {
|
|
|
|
if (! (*dst++ = *src++))
|
|
|
|
break;
|
|
|
|
} while (--n);
|
|
|
|
|
|
|
|
if (! n) {
|
|
|
|
if (size)
|
|
|
|
*dst = '\0';
|
|
|
|
while (*src++);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (src - s - 1);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
#endif
|
2007-04-25 18:00:24 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
static bool yesno (const char *value)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-12-06 16:18:00 +05:30
|
|
|
if (! value) {
|
|
|
|
errno = ENOENT;
|
2007-04-11 18:14:47 +05:30
|
|
|
return (false);
|
2007-12-06 16:18:00 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
static bool noyes (const char *value)
|
|
|
|
{
|
2007-12-06 16:18:00 +05:30
|
|
|
int serrno = errno;
|
|
|
|
bool retval;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
retval = yesno (value);
|
|
|
|
if (errno == 0) {
|
|
|
|
retval = ! retval;
|
|
|
|
errno = serrno;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (retval);
|
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
static bool is_quiet()
|
|
|
|
{
|
2007-12-06 16:18:00 +05:30
|
|
|
return (yesno (getenv ("EINFO_QUIET")));
|
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
static bool is_verbose()
|
|
|
|
{
|
2007-12-06 16:18:00 +05:30
|
|
|
return (yesno (getenv ("EINFO_VERBOSE")));
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
/* 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 buf[20];
|
|
|
|
|
|
|
|
snprintf (buf, sizeof (buf), cap, b, a);
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-10-03 18:13:50 +05:30
|
|
|
static bool colour_terminal (FILE *f)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
static int in_colour = -1;
|
2007-12-08 08:20:35 +05:30
|
|
|
char *e;
|
|
|
|
int c;
|
|
|
|
const char *_af = NULL;
|
|
|
|
const char *_ce = NULL;
|
|
|
|
const char *_ch = NULL;
|
|
|
|
const char *_md = NULL;
|
|
|
|
const char *_me = NULL;
|
|
|
|
const char *_up = NULL;
|
|
|
|
char tmp[100];
|
|
|
|
char *p;
|
|
|
|
unsigned int i = 0;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-10-03 18:13:50 +05:30
|
|
|
if (f && ! isatty (fileno (f)))
|
|
|
|
return (false);
|
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (noyes (getenv ("EINFO_COLOR")))
|
2007-06-28 21:14:14 +05:30
|
|
|
return (false);
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
if (in_colour == 0)
|
|
|
|
return (false);
|
|
|
|
if (in_colour == 1)
|
|
|
|
return (true);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
term_is_cons25 = false;
|
|
|
|
|
2007-05-02 16:13:43 +05:30
|
|
|
if (! term) {
|
|
|
|
term = getenv ("TERM");
|
|
|
|
if (! term)
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp (term, "cons25") == 0)
|
|
|
|
term_is_cons25 = true;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
#ifdef HAVE_TERMCAP
|
|
|
|
/* Check termcap to see if we can do colour or not */
|
|
|
|
if (tgetent (termcapbuf, term) == 1) {
|
|
|
|
char *bp = tcapbuf;
|
|
|
|
|
|
|
|
_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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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) {
|
|
|
|
#else
|
|
|
|
while (color_terms[i]) {
|
|
|
|
if (strcmp (color_terms[i], term) == 0) {
|
|
|
|
in_colour = 1;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_colour != 1) {
|
|
|
|
in_colour = 0;
|
|
|
|
return (false);
|
2007-04-11 18:14:47 +05:30
|
|
|
}
|
2007-12-08 08:20:35 +05:30
|
|
|
#endif
|
|
|
|
if (! _af)
|
|
|
|
_af = AF;
|
|
|
|
if (! _ce)
|
|
|
|
_ce = CE;
|
|
|
|
if (! _ch)
|
|
|
|
_ch = CH;
|
|
|
|
if (! _md)
|
|
|
|
_md = MD;
|
|
|
|
if (! _me)
|
|
|
|
_me = ME;
|
|
|
|
if (! _up)
|
|
|
|
_up = UP;
|
|
|
|
#ifdef HAVE_TERMCAP
|
2007-04-11 18:14:47 +05:30
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
if (! _af || ! _ce || ! _ch || ! _me || !_md || ! _up) {
|
|
|
|
in_colour = 0;
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#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; \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now setup our colours */
|
|
|
|
p = ebuffer;
|
|
|
|
for (i = 0; i < sizeof (ecolors) / sizeof (ecolors[0]); i++) {
|
|
|
|
tmp[0] = '\0';
|
|
|
|
|
|
|
|
if (ecolors[i].name) {
|
|
|
|
const char *bold = _md;
|
|
|
|
c = ecolors[i].def;
|
|
|
|
|
|
|
|
/* See if the user wants to override the colour
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
if (ee)
|
|
|
|
ee += strlen (ecolors[i].name);
|
|
|
|
|
|
|
|
if (ee && *ee == '=') {
|
|
|
|
|
|
|
|
char *d = xstrdup (ee + 1);
|
|
|
|
char *end = strchr (d, ':');
|
|
|
|
if (end)
|
|
|
|
*end = '\0';
|
|
|
|
|
|
|
|
c = atoi(d);
|
|
|
|
|
|
|
|
end = strchr (d, ';');
|
|
|
|
if (end && *++end == '0')
|
|
|
|
bold = _me;
|
|
|
|
|
|
|
|
free (d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strlcpy (tmp, tgoto (bold, 0, 0), sizeof (tmp));
|
|
|
|
strlcat (tmp, tgoto (_af, 0, c & 0x07), sizeof (tmp));
|
|
|
|
} else
|
|
|
|
_GET_CAP (tmp, _me);
|
|
|
|
|
|
|
|
if (tmp[0])
|
|
|
|
_ASSIGN_CAP (ecolors[i].str)
|
|
|
|
else
|
|
|
|
ecolors[i].str = &nullstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
_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);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2007-09-20 17:17:04 +05:30
|
|
|
static int get_term_columns (FILE *stream)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-17 17:51:15 +05:30
|
|
|
struct winsize ws;
|
2007-10-03 17:19:08 +05:30
|
|
|
char *env = getenv ("COLUMNS");
|
|
|
|
char *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (env) {
|
|
|
|
i = strtol (env, &p, 10);
|
|
|
|
if (! *p)
|
|
|
|
return (i);
|
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-09-20 17:23:10 +05:30
|
|
|
if (ioctl (fileno (stream), TIOCGWINSZ, &ws) == 0)
|
2007-04-11 18:14:47 +05:30
|
|
|
return (ws.ws_col);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (DEFAULT_COLS);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2007-10-03 18:13:50 +05:30
|
|
|
void eprefix (const char *prefix)
|
|
|
|
{
|
2007-04-25 18:00:24 +05:30
|
|
|
_eprefix = prefix;
|
|
|
|
}
|
2007-10-03 18:25:27 +05:30
|
|
|
hidden_def(eprefix)
|
2007-04-25 18:00:24 +05:30
|
|
|
|
2007-08-16 22:23:20 +05:30
|
|
|
static void elogv (int level, const char *fmt, va_list ap)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-12-06 16:18:00 +05:30
|
|
|
char *e = getenv ("EINFO_LOG");
|
2007-04-11 18:14:47 +05:30
|
|
|
va_list apc;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
if (fmt && e) {
|
|
|
|
closelog ();
|
|
|
|
openlog (e, LOG_PID, LOG_DAEMON);
|
|
|
|
va_copy (apc, ap);
|
|
|
|
vsyslog (level, fmt, apc);
|
|
|
|
va_end (apc);
|
|
|
|
closelog ();
|
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2007-08-16 22:23:20 +05:30
|
|
|
void elog (int level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
elogv (level, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
}
|
|
|
|
hidden_def(elog)
|
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
static int _eindent (FILE *stream)
|
|
|
|
{
|
2007-12-06 16:18:00 +05:30
|
|
|
char *env = getenv ("EINFO_INDENT");
|
2007-04-11 18:14:47 +05:30
|
|
|
int amount = 0;
|
|
|
|
char indent[INDENT_MAX];
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
if (env) {
|
|
|
|
errno = 0;
|
|
|
|
amount = strtol (env, NULL, 0);
|
|
|
|
if (errno != 0 || amount < 0)
|
|
|
|
amount = 0;
|
|
|
|
else if (amount > INDENT_MAX)
|
|
|
|
amount = INDENT_MAX;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
if (amount > 0)
|
|
|
|
memset (indent, ' ', amount);
|
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
/* Terminate it */
|
|
|
|
memset (indent + amount, 0, 1);
|
|
|
|
return (fprintf (stream, "%s", indent));
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2007-10-03 18:13:50 +05:30
|
|
|
static const char *_ecolor (FILE *f, einfo_color_t color)
|
|
|
|
{
|
2007-12-08 08:20:35 +05:30
|
|
|
unsigned int i;
|
2007-04-17 15:02:18 +05:30
|
|
|
|
2007-10-03 18:13:50 +05:30
|
|
|
if (! colour_terminal (f))
|
2007-04-17 15:02:18 +05:30
|
|
|
return ("");
|
2007-12-03 21:46:08 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
for (i = 0; i < sizeof (ecolors) / sizeof (ecolors[0]); i++) {
|
|
|
|
if (ecolors[i].color == color)
|
|
|
|
return (ecolors[i].str);
|
2007-04-17 12:36:04 +05:30
|
|
|
}
|
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
return ("");
|
2007-04-17 12:36:04 +05:30
|
|
|
}
|
2007-04-17 15:02:18 +05:30
|
|
|
hidden_def(ecolor)
|
2007-04-17 12:36:04 +05:30
|
|
|
|
2007-10-03 18:13:50 +05:30
|
|
|
const char *ecolor (einfo_color_t color)
|
|
|
|
{
|
2007-12-03 21:46:08 +05:30
|
|
|
FILE *f = stdout;
|
|
|
|
|
|
|
|
/* Try and guess a valid tty */
|
|
|
|
if (! isatty (fileno (f))) {
|
|
|
|
f = stderr;
|
|
|
|
if (! isatty (fileno (f))) {
|
|
|
|
f = stdin;
|
|
|
|
if (! isatty (fileno (f)))
|
|
|
|
f = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (_ecolor (f, color));
|
2007-10-03 18:13:50 +05:30
|
|
|
}
|
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
#define LASTCMD(_cmd) \
|
|
|
|
unsetenv ("EINFO_LASTCMD"); \
|
|
|
|
setenv ("EINFO_LASTCMD", _cmd, 1);
|
|
|
|
|
2007-04-17 12:36:04 +05:30
|
|
|
#define EINFOVN(_file, _color) \
|
2007-12-08 08:20:35 +05:30
|
|
|
{ \
|
|
|
|
char *_e = getenv ("EINFO_LASTCMD"); \
|
|
|
|
if (_e && ! colour_terminal (_file) && strcmp (_e, "ewarn") != 0 && \
|
|
|
|
_e[strlen (_e) - 1] == 'n') \
|
|
|
|
fprintf (_file, "\n"); \
|
|
|
|
if (_eprefix) \
|
2007-10-03 18:13:50 +05:30
|
|
|
fprintf (_file, "%s%s%s|", _ecolor (_file, _color), _eprefix, _ecolor (_file, ECOLOR_NORMAL)); \
|
|
|
|
fprintf (_file, " %s*%s ", _ecolor (_file, _color), _ecolor (_file, ECOLOR_NORMAL)); \
|
2007-04-25 18:00:24 +05:30
|
|
|
retval += _eindent (_file); \
|
2007-04-10 16:54:58 +05:30
|
|
|
{ \
|
2007-04-11 18:14:47 +05:30
|
|
|
va_list _ap; \
|
|
|
|
va_copy (_ap, ap); \
|
|
|
|
retval += vfprintf (_file, fmt, _ap) + 3; \
|
|
|
|
va_end (_ap); \
|
2007-04-10 16:54:58 +05:30
|
|
|
} \
|
2007-10-03 18:13:50 +05:30
|
|
|
if (colour_terminal (_file)) \
|
2007-12-08 08:20:35 +05:30
|
|
|
fprintf (_file, "%s", flush); \
|
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-10 21:41:20 +05:30
|
|
|
static int _einfovn (const char *fmt, va_list ap)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval = 0;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-09-28 17:59:23 +05:30
|
|
|
EINFOVN (stdout, ECOLOR_GOOD);
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2007-04-10 21:41:20 +05:30
|
|
|
static int _ewarnvn (const char *fmt, va_list ap)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval = 0;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-09-28 17:59:23 +05:30
|
|
|
EINFOVN (stdout, ECOLOR_WARN);
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2007-04-10 21:41:20 +05:30
|
|
|
static int _eerrorvn (const char *fmt, va_list ap)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval = 0;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-09-28 17:59:23 +05:30
|
|
|
EINFOVN (stderr, ECOLOR_BAD);
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int einfon (const char *fmt, ...)
|
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (! fmt || is_quiet ())
|
2007-04-11 18:14:47 +05:30
|
|
|
return (0);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
2007-04-24 16:59:19 +05:30
|
|
|
retval = _einfovn (fmt, ap);
|
2007-04-11 18:14:47 +05:30
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("einfon");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(einfon)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
int ewarnn (const char *fmt, ...)
|
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (! fmt || is_quiet ())
|
2007-04-11 18:14:47 +05:30
|
|
|
return (0);
|
2007-04-10 16:54:58 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
2007-04-24 16:59:19 +05:30
|
|
|
retval = _ewarnvn (fmt, ap);
|
2007-04-11 18:14:47 +05:30
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("ewarnn");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(ewarnn)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
int eerrorn (const char *fmt, ...)
|
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
2007-04-24 16:59:19 +05:30
|
|
|
retval = _eerrorvn (fmt, ap);
|
2007-04-11 18:14:47 +05:30
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("errorn");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(eerrorn)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
int einfo (const char *fmt, ...)
|
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (! fmt || is_quiet())
|
2007-04-11 18:14:47 +05:30
|
|
|
return (0);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
2007-04-24 16:59:19 +05:30
|
|
|
retval = _einfovn (fmt, ap);
|
|
|
|
retval += printf ("\n");
|
2007-04-11 18:14:47 +05:30
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("einfo");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(einfo)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
int ewarn (const char *fmt, ...)
|
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (! fmt || is_quiet ())
|
2007-04-11 18:14:47 +05:30
|
|
|
return (0);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
2007-08-16 22:23:20 +05:30
|
|
|
elogv (LOG_WARNING, fmt, ap);
|
2007-04-24 16:59:19 +05:30
|
|
|
retval = _ewarnvn (fmt, ap);
|
|
|
|
retval += printf ("\n");
|
2007-04-11 18:14:47 +05:30
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("ewarn");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(ewarn)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
void ewarnx (const char *fmt, ...)
|
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (fmt && ! is_quiet ()) {
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
2007-08-16 22:23:20 +05:30
|
|
|
elogv (LOG_WARNING, fmt, ap);
|
2007-04-11 18:14:47 +05:30
|
|
|
retval = _ewarnvn (fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
retval += printf ("\n");
|
|
|
|
}
|
|
|
|
exit (EXIT_FAILURE);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(ewarnx)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
int eerror (const char *fmt, ...)
|
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
if (! fmt)
|
|
|
|
return (0);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
2007-08-16 22:23:20 +05:30
|
|
|
elogv (LOG_ERR, fmt, ap);
|
2007-04-11 18:14:47 +05:30
|
|
|
retval = _eerrorvn (fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
retval += fprintf (stderr, "\n");
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("eerror");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(eerror)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
void eerrorx (const char *fmt, ...)
|
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
if (fmt) {
|
|
|
|
va_start (ap, fmt);
|
2007-08-16 22:23:20 +05:30
|
|
|
elogv (LOG_ERR, fmt, ap);
|
2007-04-11 18:14:47 +05:30
|
|
|
_eerrorvn (fmt, ap);
|
|
|
|
va_end (ap);
|
2007-08-01 17:03:07 +05:30
|
|
|
fprintf (stderr, "\n");
|
2007-04-11 18:14:47 +05:30
|
|
|
}
|
2007-04-24 16:59:19 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
exit (EXIT_FAILURE);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(eerrorx)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
int ebegin (const char *fmt, ...)
|
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (! fmt || is_quiet ())
|
2007-04-11 18:14:47 +05:30
|
|
|
return (0);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
|
|
|
retval = _einfovn (fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
retval += printf (" ...");
|
2007-10-03 18:13:50 +05:30
|
|
|
if (colour_terminal (stdout))
|
2007-04-11 18:14:47 +05:30
|
|
|
retval += printf ("\n");
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("ebegin");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(ebegin)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-05-02 16:13:43 +05:30
|
|
|
static void _eend (FILE *fp, int col, einfo_color_t color, const char *msg)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int i;
|
|
|
|
int cols;
|
|
|
|
|
|
|
|
if (! msg)
|
|
|
|
return;
|
|
|
|
|
2007-09-20 17:17:04 +05:30
|
|
|
cols = get_term_columns (fp) - (strlen (msg) + 5);
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2007-05-02 16:13:43 +05:30
|
|
|
/* 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_is_cons25 = true;
|
|
|
|
else
|
|
|
|
term_is_cons25 = false;
|
|
|
|
}
|
|
|
|
if (term_is_cons25)
|
|
|
|
cols--;
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2007-10-03 18:13:50 +05:30
|
|
|
if (cols > 0 && colour_terminal (fp)) {
|
2007-12-08 08:20:35 +05:30
|
|
|
fprintf (fp, "%s%s %s[ %s%s %s]%s\n", up, tgoto (goto_column, 0, cols),
|
2007-09-28 17:59:23 +05:30
|
|
|
ecolor (ECOLOR_BRACKET), ecolor (color), msg,
|
|
|
|
ecolor (ECOLOR_BRACKET), ecolor (ECOLOR_NORMAL));
|
2007-04-11 18:14:47 +05:30
|
|
|
} else {
|
2007-05-02 16:13:43 +05:30
|
|
|
if (col > 0)
|
|
|
|
for (i = 0; i < cols - col; i++)
|
|
|
|
fprintf (fp, " ");
|
|
|
|
fprintf (fp, " [ %s ]\n", msg);
|
2007-04-11 18:14:47 +05:30
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static int _do_eend (const char *cmd, int retval, const char *fmt, va_list ap)
|
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int col = 0;
|
2007-05-02 16:13:43 +05:30
|
|
|
FILE *fp = stdout;
|
2007-04-11 18:14:47 +05:30
|
|
|
va_list apc;
|
|
|
|
|
|
|
|
if (fmt && retval != 0) {
|
|
|
|
va_copy (apc, ap);
|
|
|
|
if (strcmp (cmd, "ewend") == 0) {
|
|
|
|
col = _ewarnvn (fmt, apc);
|
|
|
|
fp = stdout;
|
|
|
|
} else {
|
|
|
|
col = _eerrorvn (fmt, apc);
|
|
|
|
fp = stderr;
|
|
|
|
}
|
2007-08-01 17:03:07 +05:30
|
|
|
col += fprintf (fp, "\n");
|
2007-04-11 18:14:47 +05:30
|
|
|
va_end (apc);
|
|
|
|
}
|
|
|
|
|
2007-05-02 16:13:43 +05:30
|
|
|
_eend (fp, col,
|
2007-09-28 17:59:23 +05:30
|
|
|
retval == 0 ? ECOLOR_GOOD : ECOLOR_BAD,
|
2007-04-17 15:02:18 +05:30
|
|
|
retval == 0 ? OK : NOT_OK);
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int eend (int retval, const char *fmt, ...)
|
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (is_quiet ())
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
|
|
|
_do_eend ("eend", retval, fmt, ap);
|
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("eend");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(eend)
|
2007-04-10 16:54:58 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
int ewend (int retval, const char *fmt, ...)
|
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (is_quiet ())
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
|
|
|
_do_eend ("ewend", retval, fmt, ap);
|
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("ewend");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(ewend)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
void ebracket (int col, einfo_color_t color, const char *msg)
|
|
|
|
{
|
2007-05-02 16:13:43 +05:30
|
|
|
_eend (stdout, col, color, msg);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(ebracket)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
void eindent (void)
|
|
|
|
{
|
2007-12-06 16:18:00 +05:30
|
|
|
char *env = getenv ("EINFO_INDENT");
|
2007-04-11 18:14:47 +05:30
|
|
|
int amount = 0;
|
|
|
|
char num[10];
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
if (env) {
|
|
|
|
errno = 0;
|
|
|
|
amount = strtol (env, NULL, 0);
|
|
|
|
if (errno != 0)
|
|
|
|
amount = 0;
|
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
amount += INDENT_WIDTH;
|
|
|
|
if (amount > INDENT_MAX)
|
|
|
|
amount = INDENT_MAX;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
snprintf (num, 10, "%08d", amount);
|
2007-12-06 16:18:00 +05:30
|
|
|
setenv ("EINFO_INDENT", num, 1);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(eindent)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
void eoutdent (void)
|
|
|
|
{
|
2007-12-06 16:18:00 +05:30
|
|
|
char *env = getenv ("EINFO_INDENT");
|
2007-04-11 18:14:47 +05:30
|
|
|
int amount = 0;
|
|
|
|
char num[10];
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
if (! env)
|
|
|
|
return;
|
2007-04-10 16:54:58 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
errno = 0;
|
|
|
|
amount = strtol (env, NULL, 0);
|
|
|
|
if (errno != 0)
|
|
|
|
amount = 0;
|
|
|
|
else
|
|
|
|
amount -= INDENT_WIDTH;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
if (amount <= 0)
|
2007-12-06 16:18:00 +05:30
|
|
|
unsetenv ("EINFO_EINDENT");
|
2007-04-11 18:14:47 +05:30
|
|
|
else {
|
|
|
|
snprintf (num, 10, "%08d", amount);
|
2007-12-06 16:18:00 +05:30
|
|
|
setenv ("EINFO_EINDENT", num, 1);
|
2007-04-11 18:14:47 +05:30
|
|
|
}
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(eoutdent)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-10 21:41:20 +05:30
|
|
|
int einfovn (const char *fmt, ...)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (! fmt || ! is_verbose ())
|
2007-04-11 18:14:47 +05:30
|
|
|
return (0);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
2007-04-24 16:59:19 +05:30
|
|
|
retval = _einfovn (fmt, ap);
|
2007-04-11 18:14:47 +05:30
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("einfovn");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(einfovn)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-10 21:41:20 +05:30
|
|
|
int ewarnvn (const char *fmt, ...)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (! fmt || ! is_verbose ())
|
2007-04-11 18:14:47 +05:30
|
|
|
return (0);
|
2007-04-10 16:54:58 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
2007-04-24 16:59:19 +05:30
|
|
|
retval = _ewarnvn (fmt, ap);
|
2007-04-11 18:14:47 +05:30
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("ewarnvn");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(ewarnvn)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-10 21:41:20 +05:30
|
|
|
int einfov (const char *fmt, ...)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (! fmt || ! is_verbose ())
|
2007-04-11 18:14:47 +05:30
|
|
|
return (0);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
2007-04-24 16:59:19 +05:30
|
|
|
retval = _einfovn (fmt, ap);
|
|
|
|
retval += printf ("\n");
|
2007-04-11 18:14:47 +05:30
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("einfov");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(einfov)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-10 21:41:20 +05:30
|
|
|
int ewarnv (const char *fmt, ...)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (! fmt || ! is_verbose ())
|
2007-04-11 18:14:47 +05:30
|
|
|
return (0);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
2007-04-24 16:59:19 +05:30
|
|
|
retval = _ewarnvn (fmt, ap);
|
|
|
|
retval += printf ("\n");
|
2007-04-11 18:14:47 +05:30
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("ewarnv");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(ewarnv)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-10 21:41:20 +05:30
|
|
|
int ebeginv (const char *fmt, ...)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
int retval;
|
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (! fmt || ! is_verbose ())
|
2007-04-11 18:14:47 +05:30
|
|
|
return (0);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
2007-04-24 16:59:19 +05:30
|
|
|
retval = _einfovn (fmt, ap);
|
|
|
|
retval += printf (" ...");
|
2007-10-03 18:13:50 +05:30
|
|
|
if (colour_terminal (stdout))
|
2007-04-24 16:59:19 +05:30
|
|
|
retval += printf ("\n");
|
2007-04-11 18:14:47 +05:30
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("ebeginv");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(ebeginv)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-10 21:41:20 +05:30
|
|
|
int eendv (int retval, const char *fmt, ...)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
va_list ap;
|
2007-12-06 16:18:00 +05:30
|
|
|
|
|
|
|
if (! is_verbose ())
|
|
|
|
return (0);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
|
|
|
_do_eend ("eendv", retval, fmt, ap);
|
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("eendv");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(eendv)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-10 21:41:20 +05:30
|
|
|
int ewendv (int retval, const char *fmt, ...)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
va_list ap;
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-06 16:18:00 +05:30
|
|
|
if (! is_verbose ())
|
|
|
|
return (0);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
va_start (ap, fmt);
|
|
|
|
_do_eend ("ewendv", retval, fmt, ap);
|
|
|
|
va_end (ap);
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-12-08 08:20:35 +05:30
|
|
|
LASTCMD ("ewendv");
|
|
|
|
|
2007-04-11 18:14:47 +05:30
|
|
|
return (retval);
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(ewendv)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-10 21:41:20 +05:30
|
|
|
void eindentv (void)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-12-06 16:18:00 +05:30
|
|
|
if (is_verbose ())
|
2007-04-11 18:14:47 +05:30
|
|
|
eindent ();
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(eindentv)
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-10 21:41:20 +05:30
|
|
|
void eoutdentv (void)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-12-06 16:18:00 +05:30
|
|
|
if (is_verbose ())
|
2007-04-11 18:14:47 +05:30
|
|
|
eoutdent ();
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
2007-04-13 19:48:38 +05:30
|
|
|
hidden_def(eoutdentv)
|