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

ascii-boxes / boxes / 25991660202

17 May 2026 01:04PM UTC coverage: 82.822%. Remained the same
25991660202

push

github

tsjensen
Fix a Heisenbug in u32_insert_space_at() in unicode.c

2776 of 3695 branches covered (75.13%)

Branch coverage included in aggregate %.

5 of 7 new or added lines in 1 file covered. (71.43%)

297 existing lines in 19 files now uncovered.

4345 of 4903 relevant lines covered (88.62%)

98937.49 hits per line

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

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

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

21
#include "config.h"
22

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

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

30

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

33
static int debug_logging_active = 0;
34

35
static int *areas_active = NULL;
36

37

38

39
static char *shorten_module(const char *module)
11,819✔
40
{
41
    if (module == NULL) {
11,819✔
42
        return strdup("NULL");
1✔
43
    }
44

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

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

65

66

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

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

81

82

83
static int is_area_active(log_area_t log_area)
13,139✔
84
{
85
    if (debug_logging_active && areas_active != NULL && log_area != RESERVED && log_area < NUM_LOG_AREAS + 2) {
13,139!
86
        if (log_area == ALL) {
13,137✔
87
            for (size_t i = 0; i < NUM_LOG_AREAS; i++) {
8✔
88
                if (!areas_active[i]) {
7✔
89
                    return 0;
1✔
90
                }
91
            }
92
            return 1;
1✔
93
        }
94
        return areas_active[log_area - 2];
13,135✔
95
    }
96
    return 0;
2✔
97
}
98

99

100

101
int is_debug_logging(log_area_t log_area)
1,805,076✔
102
{
103
    return (debug_logging_active && is_area_active(log_area)) ? 1 : 0;
1,805,076✔
104
}
105

106

107

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

120

121

122
void log_debug(const char *module, log_area_t log_area, const char *format, ...)
1,676,663✔
123
{
124
    if (is_debug_logging(log_area)) {
1,676,663✔
125
        char *msg = (char *) malloc(1024);
11,819✔
126
        va_list va;
127
        va_start(va, format);
11,819✔
128
        vsprintf(msg, format, va);
11,819✔
129
        va_end(va);
11,819✔
130

131
        char *short_module = shorten_module(module);
11,819✔
132
        bx_fprintf(stderr, "[%-9s] %s", short_module, msg);
11,819✔
133
        BFREE(short_module);
11,819!
134
        BFREE(msg);
11,819!
135
    }
136
}
1,676,663✔
137

138

139

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

149
        bx_fprintf(stderr, "%s", msg);
681✔
150
        BFREE(msg);
681!
151
    }
152
}
1,034✔
153

154

155
/* 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