/[baselayout]/trunk/src/einfo.h
Gentoo

Contents of /trunk/src/einfo.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2577 - (show annotations) (download) (as text)
Wed Apr 11 12:44:47 2007 UTC (11 years, 4 months ago) by uberlord
File MIME type: text/x-chdr
File size: 3300 byte(s)
Cuddle up to LKML C style
1 /*
2 rc.h
3 Header file for external applications to get RC information.
4 Copyright 2007 Gentoo Foundation
5 Released under the GPLv2
6 */
7
8 #ifndef __EINFO_H__
9 #define __EINFO_H__
10
11 #ifdef __GNUC__
12 # define EINFO_PRINTF(_one, _two) __attribute__ ((__format__ (__printf__, _one, _two)))
13 # define EINFO_XPRINTF(_one, _two) __attribute__ ((__noreturn__, __format__ (__printf__, _one, _two)))
14 #endif
15
16 #include <sys/types.h>
17 #include <stdbool.h>
18
19 typedef enum
20 {
21 einfo_good,
22 einfo_warn,
23 einfo_bad,
24 einfo_hilite,
25 einfo_bracket,
26 einfo_normal
27 } einfo_color_t;
28
29 /* Colour codes used by the below functions. */
30 #define EINFO_GOOD "\033[32;01m"
31 #define EINFO_WARN "\033[33;01m"
32 #define EINFO_BAD "\033[31;01m"
33 #define EINFO_HILITE "\033[36;01m"
34 #define EINFO_BRACKET "\033[34;01m"
35 #define EINFO_NORMAL "\033[0m"
36
37 /* Handy macros to easily use the above in a custom manner */
38 #define PEINFO_GOOD if (colour_terminal ()) printf (EINFO_GOOD)
39 #define PEINFO_WARN if (colour_terminal ()) printf (EINFO_WARN)
40 #define PEINFO_BAD if (colour_terminal ()) printf (EINFO_BAD)
41 #define PEINFO_HILITE if (colour_terminal ()) printf (EINFO_HILITE)
42 #define PEINFO_BRACKET if (colour_terminal ()) printf (EINFO_BRACKET)
43 #define PEINFO_NORMAL if (colour_terminal ()) printf (EINFO_NORMAL)
44
45 /* We work out if the terminal supports colour or not through the use
46 of the TERM env var. We cache the reslt in a static bool, so
47 subsequent calls are very fast.
48 The n suffix means that a newline is NOT appended to the string
49 The v suffix means that we only print it when RC_VERBOSE=yes
50 NOTE We use the v suffix here so we can add veinfo for va_list
51 in the future, but veinfo is used by shell scripts as they don't
52 have the va_list concept
53 */
54 bool colour_terminal (void);
55 int einfon (const char *fmt, ...) EINFO_PRINTF (1, 2);
56 int ewarnn (const char *fmt, ...) EINFO_PRINTF (1, 2);
57 int eerrorn (const char *fmt, ...) EINFO_PRINTF (1, 2);
58 int einfo (const char *fmt, ...) EINFO_PRINTF(1, 2);
59 int ewarn (const char *fmt, ...) EINFO_PRINTF (1, 2);
60 void ewarnx (const char *fmt, ...) EINFO_XPRINTF (1,2);
61 int eerror (const char *fmt, ...) EINFO_PRINTF (1,2);
62 void eerrorx (const char *fmt, ...) EINFO_XPRINTF (1,2);
63 int ebegin (const char *fmt, ...) EINFO_PRINTF (1, 2);
64 int eend (int retval, const char *fmt, ...) EINFO_PRINTF (2, 3);
65 int ewend (int retval, const char *fmt, ...) EINFO_PRINTF (2, 3);
66 void ebracket (int col, einfo_color_t color, const char *msg);
67 void eindent (void);
68 void eoutdent (void);
69
70 int einfovn (const char *fmt, ...) EINFO_PRINTF (1, 2);
71 int ewarnvn (const char *fmt, ...) EINFO_PRINTF (1, 2);
72 int ebeginvn (const char *fmt, ...) EINFO_PRINTF (1, 2);
73 int eendvn (int retval, const char *fmt, ...) EINFO_PRINTF (2, 3);
74 int ewendvn (int retval, const char *fmt, ...) EINFO_PRINTF (2, 3);
75 int einfov (const char *fmt, ...) EINFO_PRINTF (1, 2);
76 int ewarnv (const char *fmt, ...) EINFO_PRINTF (1, 2);
77 int ebeginv (const char *fmt, ...) EINFO_PRINTF (1, 2);
78 int eendv (int retval, const char *fmt, ...) EINFO_PRINTF (2, 3);
79 int ewendv (int retval, const char *fmt, ...) EINFO_PRINTF (2, 3);
80 void eindentv (void);
81 void eoutdentv (void);
82
83 /* If RC_EBUFFER is set, then we buffer all the above commands.
84 As such, we need to flush the buffer when done. */
85 void eflush(void);
86
87 #endif

  ViewVC Help
Powered by ViewVC 1.1.20