[go: up one dir, main page]

File: nag.cc

package info (click to toggle)
debtags 1.10.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 992 kB
  • sloc: cpp: 1,247; python: 960; sh: 112; makefile: 74
file content (85 lines) | stat: -rw-r--r-- 1,609 bytes parent folder | download | duplicates (2)
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
#include "nag.h"

#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>	// isatty

#include <cstdlib>

static bool op_verbose = false;
static bool op_debug = false;
static bool op_stdout_isatty = false;

namespace nag {
void init(bool verbose, bool debug)
{
    if (debug) verbose=true;

    op_verbose = verbose;
    op_debug = debug;
    op_stdout_isatty = isatty(1);
}
bool is_verbose() throw() { return op_verbose; }
bool is_debug() throw() { return op_debug; }
}

void fatal_error(const char* fmt, ...) throw() ATTR_PRINTF(1, 2)
{
    fprintf(stderr, "debtags: ");
    va_list ap;
    va_start(ap, fmt);
    vfprintf(stderr, fmt, ap);
    va_end(ap);
    fprintf(stderr, "\n");
    exit(1);
}

void error(const char* fmt, ...) throw() ATTR_PRINTF(1, 2)
{
    va_list ap;
    va_start(ap, fmt);
    vfprintf(stderr, fmt, ap);
    va_end(ap);
}

void warning(const char* fmt, ...) throw() ATTR_PRINTF(1, 2)
{
    va_list ap;
    va_start(ap, fmt);
    vfprintf(stderr, fmt, ap);
    va_end(ap);
}

void verbose(const char* fmt, ...) throw() ATTR_PRINTF(1, 2)
{
    if (op_verbose)
    {
        va_list ap;
        va_start(ap, fmt);
        vfprintf(stderr, fmt, ap);
        va_end(ap);
    }
}

void debug(const char* fmt, ...) throw() ATTR_PRINTF(1, 2)
{
    if (op_debug)
    {
        va_list ap;
        va_start(ap, fmt);
        vfprintf(stderr, fmt, ap);
        va_end(ap);
    }
}

void feedback(const char* fmt, ...) throw() ATTR_PRINTF(1, 2)
{
    if (op_stdout_isatty)
    {
        va_list ap;
        va_start(ap, fmt);
        vfprintf(stdout, fmt, ap);
        va_end(ap);
    }
}