Skip to content

Commit ff0506c

Browse files
committed
Migrate preprocessor-based debug statements to our logging module
1 parent 1d3ee1f commit ff0506c

18 files changed

+442
-597
lines changed

.vscode/c_cpp_properties.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
],
1313
"defines": [
1414
"_DEBUG",
15-
"DEBUG",
16-
"REGEXP_DEBUG",
17-
"PARSER_DEBUG",
18-
"LEXER_DEBUG",
19-
"DISCOVERY_DEBUG",
2015
"UNICODE",
2116
"_UNICODE"
2217
],

src/Makefile

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,24 @@ parser.c parser.h: parser.y lex.yy.h | check_dir
107107
lex.yy.c lex.yy.h: lexer.l | check_dir
108108
$(LEX) --header-file=lex.yy.h $<
109109

110-
boxes.o: boxes.c boxes.h cmdline.h discovery.h generate.h input.h list.h parsing.h query.h remove.h shape.h tools.h unicode.h config.h | check_dir
110+
boxes.o: boxes.c boxes.h cmdline.h discovery.h generate.h input.h list.h logging.h parsing.h query.h remove.h shape.h tools.h unicode.h config.h | check_dir
111111
bxstring.o: bxstring.c bxstring.h tools.h unicode.h config.h | check_dir
112-
cmdline.o: cmdline.c cmdline.h boxes.h discovery.h query.h tools.h config.h | check_dir
113-
detect.o: detect.c detect.h boxes.h bxstring.h shape.h tools.h config.h | check_dir
114-
discovery.o: discovery.c discovery.h boxes.h tools.h unicode.h config.h | check_dir
115-
generate.o: generate.c generate.h boxes.h shape.h tools.h unicode.h config.h | check_dir
116-
input.o: input.c boxes.h input.h regulex.h tools.h unicode.h config.h | check_dir
117-
lex.yy.o: lex.yy.c parser.h boxes.h parsing.h tools.h shape.h unicode.h config.h | check_dir
112+
cmdline.o: cmdline.c cmdline.h boxes.h discovery.h logging.h query.h tools.h config.h | check_dir
113+
detect.o: detect.c detect.h boxes.h bxstring.h logging.h shape.h tools.h config.h | check_dir
114+
discovery.o: discovery.c discovery.h boxes.h logging.h tools.h unicode.h config.h | check_dir
115+
generate.o: generate.c generate.h boxes.h logging.h shape.h tools.h unicode.h config.h | check_dir
116+
input.o: input.c boxes.h input.h logging.h regulex.h tools.h unicode.h config.h | check_dir
117+
lex.yy.o: lex.yy.c parser.h boxes.h logging.h parsing.h tools.h shape.h unicode.h config.h | check_dir
118118
list.o: list.c list.h boxes.h bxstring.h parsing.h query.h shape.h tools.h unicode.h config.h | check_dir
119119
logging.o: logging.c logging.h tools.h config.h | check_dir
120-
parsecode.o: parsecode.c parsecode.h discovery.h lex.yy.h parsing.h parser.h query.h regulex.h shape.h tools.h unicode.h config.h | check_dir
121-
parser.o: parser.c boxes.h bxstring.h lex.yy.h parsecode.h parser.h parsing.h shape.h tools.h unicode.h config.h | check_dir
122-
parsing.o: parsing.c parsing.h bxstring.h parser.h lex.yy.h boxes.h tools.h config.h | check_dir
123-
query.o: query.c query.h boxes.h list.h tools.h config.h | check_dir
124-
regulex.o: regulex.c regulex.h boxes.h tools.h unicode.h config.h | check_dir
125-
remove.o: remove.c remove.h boxes.h detect.h shape.h tools.h unicode.h config.h | check_dir
126-
shape.o: shape.c shape.h boxes.h bxstring.h tools.h config.h | check_dir
127-
tools.o: tools.c tools.h boxes.h regulex.h shape.h unicode.h config.h | check_dir
120+
parsecode.o: parsecode.c parsecode.h discovery.h lex.yy.h logging.h parsing.h parser.h query.h regulex.h shape.h tools.h unicode.h config.h | check_dir
121+
parser.o: parser.c boxes.h bxstring.h lex.yy.h logging.h parsecode.h parser.h parsing.h shape.h tools.h unicode.h config.h | check_dir
122+
parsing.o: parsing.c parsing.h bxstring.h parser.h lex.yy.h boxes.h logging.h tools.h config.h | check_dir
123+
query.o: query.c query.h boxes.h list.h logging.h tools.h config.h | check_dir
124+
regulex.o: regulex.c regulex.h boxes.h logging.h tools.h unicode.h config.h | check_dir
125+
remove.o: remove.c remove.h boxes.h detect.h logging.h shape.h tools.h unicode.h config.h | check_dir
126+
shape.o: shape.c shape.h boxes.h bxstring.h logging.h tools.h config.h | check_dir
127+
tools.o: tools.c tools.h boxes.h logging.h regulex.h shape.h unicode.h config.h | check_dir
128128
unicode.o: unicode.c unicode.h boxes.h tools.h config.h | check_dir
129129

130130

src/boxes.c

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "generate.h"
3636
#include "input.h"
3737
#include "list.h"
38+
#include "logging.h"
3839
#include "parsing.h"
3940
#include "query.h"
4041
#include "remove.h"
@@ -156,7 +157,7 @@ static int build_design(design_t **adesigns, const char *cld)
156157

157158
default:
158159
fprintf(stderr, "%s: internal error\n", PROJECT);
159-
return 1; /* never happens ;-) */
160+
return 1;
160161
}
161162
c->name = i;
162163

@@ -180,9 +181,8 @@ static int build_design(design_t **adesigns, const char *cld)
180181
*/
181182
static void handle_command_line(int argc, char *argv[])
182183
{
183-
#ifdef DEBUG
184-
fprintf (stderr, "Processing Command Line ...\n");
185-
#endif
184+
log_debug(__FILE__, MAIN, "Processing Command Line ...\n");
185+
186186
opt_t *parsed_opts = process_commandline(argc, argv);
187187
if (parsed_opts == NULL) {
188188
exit(EXIT_FAILURE);
@@ -269,9 +269,8 @@ static void apply_expected_size()
269269
*/
270270
static void handle_input()
271271
{
272-
#ifdef DEBUG
273-
fprintf (stderr, "Reading all input ...\n");
274-
#endif
272+
log_debug(__FILE__, MAIN, "Reading all input ...\n");
273+
275274
input_t *raw_input = NULL;
276275
if (opt.mend != 0) {
277276
raw_input = read_all_input();
@@ -287,10 +286,10 @@ static void handle_input()
287286
BFREE(raw_input);
288287
}
289288

290-
#ifdef DEBUG
291-
fprintf(stderr, "Effective encoding: %s\n", encoding);
289+
if (is_debug_logging(MAIN)) {
290+
log_debug(__FILE__, MAIN, "Effective encoding: %s\n", encoding);
292291
print_input_lines(NULL);
293-
#endif
292+
}
294293
if (input.num_lines == 0) {
295294
exit(EXIT_SUCCESS);
296295
}
@@ -362,9 +361,8 @@ static void adjust_size_and_padding()
362361
*/
363362
static void handle_generate_box()
364363
{
365-
#ifdef DEBUG
366-
fprintf (stderr, "Generating Box ...\n");
367-
#endif
364+
log_debug(__FILE__, MAIN, "Generating Box ...\n");
365+
368366
sentry_t *thebox = (sentry_t *) calloc(NUM_SIDES, sizeof(sentry_t));
369367
if (thebox == NULL) {
370368
perror(PROJECT);
@@ -384,9 +382,8 @@ static void handle_generate_box()
384382
*/
385383
static void handle_remove_box()
386384
{
387-
#ifdef DEBUG
388-
fprintf (stderr, "Removing Box ...\n");
389-
#endif
385+
log_debug(__FILE__, MAIN, "Removing Box ...\n");
386+
390387
if (opt.killblank == -1) {
391388
if (empty_side(opt.design->shape, BTOP) && empty_side(opt.design->shape, BBOT)) {
392389
opt.killblank = 0;
@@ -425,15 +422,16 @@ static int terminal_has_colors()
425422
result = 1;
426423
}
427424
#endif
428-
#if defined(DEBUG)
425+
426+
if (is_debug_logging(MAIN)) {
429427
#ifdef __MINGW32__
430428
int num_colors = 1;
431429
#else
432430
int num_colors = result ? tigetnum("colors") : 0;
433431
#endif
434-
fprintf(stderr, "Terminal \"%s\" %s colors (number of colors = %d).\n", termtype != NULL ? termtype : "(null)",
435-
result ? "has" : "does NOT have", num_colors);
436-
#endif
432+
log_debug(__FILE__, MAIN, "Terminal \"%s\" %s colors (number of colors = %d).\n",
433+
termtype != NULL ? termtype : "(null)", result ? "has" : "does NOT have", num_colors);
434+
}
437435
return result;
438436
}
439437

@@ -449,9 +447,7 @@ static int check_color_support(int opt_color)
449447
result = terminal_has_colors();
450448
}
451449

452-
#if defined(DEBUG)
453-
fprintf(stderr, "%s: Color support %sabled\n", PROJECT, result ? "\x1b[92mEN\x1b[0m" : "DIS");
454-
#endif
450+
log_debug(__FILE__, MAIN, "Color support %sabled\n", result ? "\x1b[92mEN\x1b[0m" : "DIS");
455451
return result;
456452
}
457453

@@ -485,9 +481,7 @@ int main(int argc, char *argv[])
485481
int saved_designwidth; /* opt.design->minwith backup, used for mending */
486482
int saved_designheight; /* opt.design->minheight backup, used for mending */
487483

488-
#ifdef DEBUG
489-
fprintf (stderr, "BOXES STARTING ...\n");
490-
#endif
484+
log_debug(__FILE__, MAIN, "BOXES STARTING ...\n"); /* TODO This line will never execute, because debug not on yet */
491485

492486
/* Temporarily set the system encoding, for proper output of --help text etc. */
493487
activateSystemEncoding();
@@ -497,9 +491,7 @@ int main(int argc, char *argv[])
497491

498492
/* Store system character encoding */
499493
encoding = check_encoding(opt.encoding, locale_charset());
500-
#ifdef DEBUG
501-
fprintf (stderr, "Character Encoding = %s\n", encoding);
502-
#endif
494+
log_debug(__FILE__, MAIN, "Character Encoding = %s\n", encoding);
503495

504496
color_output_enabled = check_color_support(opt.color);
505497

src/boxes.in.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
#ifndef BOXES_H
2121
#define BOXES_H
2222

23-
/* #define DEBUG 1 */
24-
/* #define REGEXP_DEBUG 1 */
25-
/* #define PARSER_DEBUG 1 */
26-
/* #define LEXER_DEBUG 1 */
27-
/* #define DISCOVERY_DEBUG 1 */
28-
2923
#include <stdio.h>
3024
#include <unitypes.h>
3125

src/cmdline.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -689,14 +689,13 @@ static void print_debug_info(opt_t *result)
689689

690690
opt_t *process_commandline(int argc, char *argv[])
691691
{
692-
#ifdef DEBUG
693-
fprintf(stderr, "argc = %d\n", argc);
694-
fprintf(stderr, "argv = [");
692+
if (is_debug_logging(MAIN)) {
693+
log_debug(__FILE__, MAIN, "argc = %d\n", argc);
694+
log_debug(__FILE__, MAIN, "argv = [");
695695
for(int i=0; i<=argc; i++) {
696-
fprintf(stderr, "%s%s", argv[i], i < argc ? ", " : "");
696+
log_debug_cont(MAIN, "%s%s", argv[i], i < argc ? ", " : "]\n");
697697
}
698-
fprintf(stderr, "]\n");
699-
#endif
698+
}
700699

701700
opt_t *result = create_new_opt();
702701

0 commit comments

Comments
 (0)