aboutsummaryrefslogtreecommitdiff
path: root/src/einfo.h
blob: 9c9bc7a3f45039005d586d9668ba5f1b3a833a95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * @file einfo.h
 * @brief Describes how to interface with the einfo library
 *
 * Copyright 2007 Gentoo Foundation
 * Released under the GPLv2
 */

#ifndef __EINFO_H__
#define __EINFO_H__

#ifdef __GNUC__
# define __EINFO_PRINTF  __attribute__ ((__format__ (__printf__, 1, 2)))
# define __EINFO_XPRINTF __attribute__ ((__noreturn__, __format__ (__printf__, 1, 2)))
# define __EEND_PRINTF   __attribute__ ((__format__ (__printf__, 2, 3)))
#else
# define __EINFO_PRINTF
# define __EINFO_XPRINTF
# define __EEND_PRINTF
#endif

#include <sys/types.h>
#include <stdbool.h>

/*! @brief Color types to use */
typedef enum
{
	ecolor_good,
	ecolor_warn,
	ecolor_bad,
	ecolor_hilite,
	ecolor_bracket,
	ecolor_normal
} einfo_color_t;

/*! @brief Returns the ASCII code for the color */
const char *ecolor (einfo_color_t);

/*! @brief Writes to syslog. */
void elog (int __level, const char *__fmt, ...) __EEND_PRINTF;

/*!
 * @brief Display informational messages.
 *
 * The einfo family of functions display messages in a consistent manner
 * across Gentoo applications. Basically they prefix the message with
 * " * ". If the terminal can handle color then we color the * based on
 * the command used. Otherwise we are identical to the printf function.
 *
 * - einfo  - green
 * - ewarn  - yellow
 * - eerror - red
 *
 * The n suffix denotes that no new line should be printed.
 * The v suffix means only print if RC_VERBOSE is yes.
 */
/*@{*/
int einfon (const char *__fmt, ...) __EINFO_PRINTF;
int ewarnn (const char *__fmt, ...) __EINFO_PRINTF;
int eerrorn (const char *__fmt, ...) __EINFO_PRINTF;
int einfo (const char *__fmt, ...) __EINFO_PRINTF;
int ewarn (const char *__fmt, ...) __EINFO_PRINTF;
void ewarnx (const char *__fmt, ...) __EINFO_XPRINTF;
int eerror (const char *__fmt, ...) __EINFO_PRINTF;
void eerrorx (const char *__fmt, ...) __EINFO_XPRINTF;

int einfovn (const char *__fmt, ...) __EINFO_PRINTF;
int ewarnvn (const char *__fmt, ...) __EINFO_PRINTF;
int ebeginvn (const char *__fmt, ...) __EINFO_PRINTF;
int eendvn (int __retval, const char *__fmt, ...) __EEND_PRINTF;
int ewendvn (int __retval, const char *__fmt, ...) __EEND_PRINTF;
int einfov (const char *__fmt, ...) __EINFO_PRINTF;
int ewarnv (const char *__fmt, ...) __EINFO_PRINTF;
/*@}*/

/*! @ingroup ebegin
 * @brief Display informational messages that may take some time.
 *
 * Similar to einfo, but we add ... to the end of the message */
/*@{*/
int ebeginv (const char *__fmt, ...) __EINFO_PRINTF;
int ebegin (const char *__fmt, ...) __EINFO_PRINTF;
/*@}*/

/*! @ingroup eend
 * @brief End an ebegin.
 *
 * If you ebegin, you should eend also.
 * eend places [ ok ] or [ !! ] at the end of the terminal line depending on
 * retval (0 or ok, anything else for !!)
 *
 * ebracket allows you to specifiy the position, color and message */
/*@{*/
int eend (int __retval, const char *__fmt, ...) __EEND_PRINTF;
int ewend (int __retval, const char *__fmt, ...) __EEND_PRINTF;
void ebracket (int __col, einfo_color_t __color, const char *__msg);

int eendv (int __retval, const char *__fmt, ...) __EEND_PRINTF;
int ewendv (int __retval, const char *__fmt, ...) __EEND_PRINTF;
/*@}*/

/*! @ingroup eindent
 * @brief Indents the einfo lines.
 *
 * For each indent you should outdent when done */
/*@{*/
void eindent (void);
void eoutdent (void);
void eindentv (void);
void eoutdentv (void);

/*! @brief Prefix each einfo line with something */
void eprefix (const char *__prefix);

#endif