Skip to content

Commit

Permalink
Migrate preprocessor-based debug statements to our logging module
Browse files Browse the repository at this point in the history
  • Loading branch information
tsjensen committed Sep 22, 2024
1 parent 1d3ee1f commit ff0506c
Show file tree
Hide file tree
Showing 18 changed files with 442 additions and 597 deletions.
5 changes: 0 additions & 5 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
],
"defines": [
"_DEBUG",
"DEBUG",
"REGEXP_DEBUG",
"PARSER_DEBUG",
"LEXER_DEBUG",
"DISCOVERY_DEBUG",
"UNICODE",
"_UNICODE"
],
Expand Down
30 changes: 15 additions & 15 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,24 @@ parser.c parser.h: parser.y lex.yy.h | check_dir
lex.yy.c lex.yy.h: lexer.l | check_dir
$(LEX) --header-file=lex.yy.h $<

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
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
bxstring.o: bxstring.c bxstring.h tools.h unicode.h config.h | check_dir
cmdline.o: cmdline.c cmdline.h boxes.h discovery.h query.h tools.h config.h | check_dir
detect.o: detect.c detect.h boxes.h bxstring.h shape.h tools.h config.h | check_dir
discovery.o: discovery.c discovery.h boxes.h tools.h unicode.h config.h | check_dir
generate.o: generate.c generate.h boxes.h shape.h tools.h unicode.h config.h | check_dir
input.o: input.c boxes.h input.h regulex.h tools.h unicode.h config.h | check_dir
lex.yy.o: lex.yy.c parser.h boxes.h parsing.h tools.h shape.h unicode.h config.h | check_dir
cmdline.o: cmdline.c cmdline.h boxes.h discovery.h logging.h query.h tools.h config.h | check_dir
detect.o: detect.c detect.h boxes.h bxstring.h logging.h shape.h tools.h config.h | check_dir
discovery.o: discovery.c discovery.h boxes.h logging.h tools.h unicode.h config.h | check_dir
generate.o: generate.c generate.h boxes.h logging.h shape.h tools.h unicode.h config.h | check_dir
input.o: input.c boxes.h input.h logging.h regulex.h tools.h unicode.h config.h | check_dir
lex.yy.o: lex.yy.c parser.h boxes.h logging.h parsing.h tools.h shape.h unicode.h config.h | check_dir
list.o: list.c list.h boxes.h bxstring.h parsing.h query.h shape.h tools.h unicode.h config.h | check_dir
logging.o: logging.c logging.h tools.h config.h | check_dir
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
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
parsing.o: parsing.c parsing.h bxstring.h parser.h lex.yy.h boxes.h tools.h config.h | check_dir
query.o: query.c query.h boxes.h list.h tools.h config.h | check_dir
regulex.o: regulex.c regulex.h boxes.h tools.h unicode.h config.h | check_dir
remove.o: remove.c remove.h boxes.h detect.h shape.h tools.h unicode.h config.h | check_dir
shape.o: shape.c shape.h boxes.h bxstring.h tools.h config.h | check_dir
tools.o: tools.c tools.h boxes.h regulex.h shape.h unicode.h config.h | check_dir
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
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
parsing.o: parsing.c parsing.h bxstring.h parser.h lex.yy.h boxes.h logging.h tools.h config.h | check_dir
query.o: query.c query.h boxes.h list.h logging.h tools.h config.h | check_dir
regulex.o: regulex.c regulex.h boxes.h logging.h tools.h unicode.h config.h | check_dir
remove.o: remove.c remove.h boxes.h detect.h logging.h shape.h tools.h unicode.h config.h | check_dir
shape.o: shape.c shape.h boxes.h bxstring.h logging.h tools.h config.h | check_dir
tools.o: tools.c tools.h boxes.h logging.h regulex.h shape.h unicode.h config.h | check_dir
unicode.o: unicode.c unicode.h boxes.h tools.h config.h | check_dir


Expand Down
50 changes: 21 additions & 29 deletions src/boxes.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "generate.h"
#include "input.h"
#include "list.h"
#include "logging.h"
#include "parsing.h"
#include "query.h"
#include "remove.h"
Expand Down Expand Up @@ -156,7 +157,7 @@ static int build_design(design_t **adesigns, const char *cld)

default:
fprintf(stderr, "%s: internal error\n", PROJECT);
return 1; /* never happens ;-) */
return 1;
}
c->name = i;

Expand All @@ -180,9 +181,8 @@ static int build_design(design_t **adesigns, const char *cld)
*/
static void handle_command_line(int argc, char *argv[])
{
#ifdef DEBUG
fprintf (stderr, "Processing Command Line ...\n");
#endif
log_debug(__FILE__, MAIN, "Processing Command Line ...\n");

opt_t *parsed_opts = process_commandline(argc, argv);
if (parsed_opts == NULL) {
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -269,9 +269,8 @@ static void apply_expected_size()
*/
static void handle_input()
{
#ifdef DEBUG
fprintf (stderr, "Reading all input ...\n");
#endif
log_debug(__FILE__, MAIN, "Reading all input ...\n");

input_t *raw_input = NULL;
if (opt.mend != 0) {
raw_input = read_all_input();
Expand All @@ -287,10 +286,10 @@ static void handle_input()
BFREE(raw_input);
}

#ifdef DEBUG
fprintf(stderr, "Effective encoding: %s\n", encoding);
if (is_debug_logging(MAIN)) {
log_debug(__FILE__, MAIN, "Effective encoding: %s\n", encoding);
print_input_lines(NULL);
#endif
}
if (input.num_lines == 0) {
exit(EXIT_SUCCESS);
}
Expand Down Expand Up @@ -362,9 +361,8 @@ static void adjust_size_and_padding()
*/
static void handle_generate_box()
{
#ifdef DEBUG
fprintf (stderr, "Generating Box ...\n");
#endif
log_debug(__FILE__, MAIN, "Generating Box ...\n");

sentry_t *thebox = (sentry_t *) calloc(NUM_SIDES, sizeof(sentry_t));
if (thebox == NULL) {
perror(PROJECT);
Expand All @@ -384,9 +382,8 @@ static void handle_generate_box()
*/
static void handle_remove_box()
{
#ifdef DEBUG
fprintf (stderr, "Removing Box ...\n");
#endif
log_debug(__FILE__, MAIN, "Removing Box ...\n");

if (opt.killblank == -1) {
if (empty_side(opt.design->shape, BTOP) && empty_side(opt.design->shape, BBOT)) {
opt.killblank = 0;
Expand Down Expand Up @@ -425,15 +422,16 @@ static int terminal_has_colors()
result = 1;
}
#endif
#if defined(DEBUG)

if (is_debug_logging(MAIN)) {
#ifdef __MINGW32__
int num_colors = 1;
#else
int num_colors = result ? tigetnum("colors") : 0;
#endif
fprintf(stderr, "Terminal \"%s\" %s colors (number of colors = %d).\n", termtype != NULL ? termtype : "(null)",
result ? "has" : "does NOT have", num_colors);
#endif
log_debug(__FILE__, MAIN, "Terminal \"%s\" %s colors (number of colors = %d).\n",
termtype != NULL ? termtype : "(null)", result ? "has" : "does NOT have", num_colors);
}
return result;
}

Expand All @@ -449,9 +447,7 @@ static int check_color_support(int opt_color)
result = terminal_has_colors();
}

#if defined(DEBUG)
fprintf(stderr, "%s: Color support %sabled\n", PROJECT, result ? "\x1b[92mEN\x1b[0m" : "DIS");
#endif
log_debug(__FILE__, MAIN, "Color support %sabled\n", result ? "\x1b[92mEN\x1b[0m" : "DIS");
return result;
}

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

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

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

/* Store system character encoding */
encoding = check_encoding(opt.encoding, locale_charset());
#ifdef DEBUG
fprintf (stderr, "Character Encoding = %s\n", encoding);
#endif
log_debug(__FILE__, MAIN, "Character Encoding = %s\n", encoding);

color_output_enabled = check_color_support(opt.color);

Expand Down
6 changes: 0 additions & 6 deletions src/boxes.in.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
#ifndef BOXES_H
#define BOXES_H

/* #define DEBUG 1 */
/* #define REGEXP_DEBUG 1 */
/* #define PARSER_DEBUG 1 */
/* #define LEXER_DEBUG 1 */
/* #define DISCOVERY_DEBUG 1 */

#include <stdio.h>
#include <unitypes.h>

Expand Down
11 changes: 5 additions & 6 deletions src/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,14 +689,13 @@ static void print_debug_info(opt_t *result)

opt_t *process_commandline(int argc, char *argv[])
{
#ifdef DEBUG
fprintf(stderr, "argc = %d\n", argc);
fprintf(stderr, "argv = [");
if (is_debug_logging(MAIN)) {
log_debug(__FILE__, MAIN, "argc = %d\n", argc);
log_debug(__FILE__, MAIN, "argv = [");
for(int i=0; i<=argc; i++) {
fprintf(stderr, "%s%s", argv[i], i < argc ? ", " : "");
log_debug_cont(MAIN, "%s%s", argv[i], i < argc ? ", " : "]\n");
}
fprintf(stderr, "]\n");
#endif
}

opt_t *result = create_new_opt();

Expand Down
Loading

0 comments on commit ff0506c

Please sign in to comment.