• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ascii-boxes / boxes / 11001727581

23 Sep 2024 08:16PM UTC coverage: 82.798% (-0.3%) from 83.099%
11001727581

push

github

tsjensen
cmdline

2958 of 3811 branches covered (77.62%)

Branch coverage included in aggregate %.

0 of 22 new or added lines in 1 file covered. (0.0%)

6 existing lines in 1 file now uncovered.

4796 of 5554 relevant lines covered (86.35%)

175921.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.43
/src/logging.c
1
/*
2
 * boxes - Command line filter to draw/remove ASCII boxes around text
3
 * Copyright (c) 1999-2023 Thomas Jensen and the boxes contributors
4
 *
5
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
6
 * License, version 3, as published by the Free Software Foundation.
7
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
8
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
9
 * details.
10
 * You should have received a copy of the GNU General Public License along with this program.
11
 * If not, see <https://www.gnu.org/licenses/>.
12
 *
13
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
14
 */
15

16
/*
17
 * Simple makeshift log facility for handling debug output.
18
 */
19

20
#include "config.h"
21

22
#include <stdarg.h>
23
#include <string.h>
24

25
#include "regulex.h"
26
#include "tools.h"
27
#include "logging.h"
28

29

30
char *log_area_names[] = { "RESERVED", "ALL", "MAIN", "REGEXP", "PARSER", "LEXER", "DISCOVERY" };
31

32
static int debug_logging_active = 0;
33

34
static int *areas_active = NULL;
35

36

37

38
static char *shorten_module(const char *module)
18✔
39
{
40
    if (module == NULL) {
18✔
41
        return strdup("NULL");
2✔
42
    }
43

44
    const char *s = strrchr(module, '/');
16✔
45
    if (s == NULL) {
16✔
46
        s = strrchr(module, '\\');
10✔
47
    }
5✔
48
    if (s != NULL) {
16✔
49
        s++;
8✔
50
    }
4✔
51
    else {
52
        s = module;
8✔
53
    }
54

55
    char *e = strrchr(module, '.');
16✔
56
    if (e != NULL && e > s && *s != '\0') {
16!
57
        char *result = strdup(s);
8✔
58
        result[e-s] = '\0';
8✔
59
        return result;
8✔
60
    }
61
    return strdup(s);
8✔
62
}
9✔
63

64

65

66
void activate_debug_logging(int *log_areas)
8✔
67
{
68
    debug_logging_active = 0;
8✔
69

70
    if (areas_active != NULL) {
8✔
71
        BFREE(areas_active);
6!
72
    }
3✔
73
    areas_active = (int *) calloc(NUM_LOG_AREAS, sizeof(int));
8✔
74
    if (log_areas != NULL) {
8✔
75
        memcpy(areas_active, log_areas, NUM_LOG_AREAS * sizeof(int));
4✔
76
        debug_logging_active = 1;
4✔
77
    }
2✔
78
}
8✔
79

80

81

82
static int is_area_active(log_area_t log_area)
30✔
83
{
84
    if (debug_logging_active && areas_active != NULL && log_area != RESERVED && log_area < NUM_LOG_AREAS + 2) {
30!
85
        if (log_area == ALL) {
26✔
86
            for (size_t i = 0; i < NUM_LOG_AREAS; i++) {
16✔
87
                if (!areas_active[i]) {
14✔
88
                    return 0;
2✔
89
                }
90
            }
6✔
91
            return 1;
2✔
92
        }
93
        return areas_active[log_area - 2];
22✔
94
    }
95
    return 0;
4✔
96
}
15✔
97

98

99

100
int is_debug_logging(log_area_t log_area)
3,583,496✔
101
{
102
    return (debug_logging_active && is_area_active(log_area)) ? 1 : 0;
3,583,496✔
103
}
104

105

106

UNCOV
107
int is_debug_activated()
×
108
{
UNCOV
109
    if (debug_logging_active) {
×
UNCOV
110
        for (size_t i = 0; i < NUM_LOG_AREAS; i++) {
×
UNCOV
111
            if (areas_active[i]) {
×
UNCOV
112
                return 1;
×
113
            }
114
        }
115
    }
UNCOV
116
    return 0;
×
117
}
118

119

120

121
void log_debug(const char *module, log_area_t log_area, const char *format, ...)
3,329,824✔
122
{
123
    if (is_debug_logging(log_area)) {
3,329,824✔
124
        char *msg = (char *) malloc(1024);
18✔
125
        va_list va;
126
        va_start(va, format);
18✔
127
        vsprintf(msg, format, va);
18✔
128
        va_end(va);
18✔
129

130
        char *short_module = shorten_module(module);
18✔
131
        bx_fprintf(stderr, "[%-9s] %s", short_module, msg);
18✔
132
        BFREE(short_module);
18!
133
        BFREE(msg);
18!
134
    }
9✔
135
}
3,329,824✔
136

137

138

139
void log_debug_cont(log_area_t log_area, const char *format, ...)
708✔
140
{
141
    if (is_debug_logging(log_area)) {
708✔
142
        char *msg = (char *) malloc(1024);
2✔
143
        va_list va;
144
        va_start(va, format);
2✔
145
        vsprintf(msg, format, va);
2✔
146
        va_end(va);
2✔
147

148
        bx_fprintf(stderr, "%s", msg);
2✔
149
        BFREE(msg);
2!
150
    }
1✔
151
}
708✔
152

153

154
/* vim: set cindent sw=4: */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc