Skip to content

Commit e07ea2a

Browse files
committed
logg
1 parent 496ebb7 commit e07ea2a

File tree

1 file changed

+42
-56
lines changed

1 file changed

+42
-56
lines changed

src/parsecode.c

Lines changed: 42 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <unistr.h>
2828

2929
#include "discovery.h"
30+
#include "logging.h"
3031
#include "parsecode.h"
3132
#include "parsing.h"
3233
#include "query.h"
@@ -57,9 +58,7 @@ static int check_sizes(pass_to_bison *bison_args)
5758
{
5859
int i, j, k;
5960

60-
#ifdef PARSER_DEBUG
61-
fprintf(stderr, " Parser: check_sizes()\n");
62-
#endif
61+
log_debug(__FILE__, PARSER, " Parser: check_sizes()\n");
6362

6463
for (i = 0; i < NUM_SIDES; ++i) {
6564
if (i == 0 || i == 2) {
@@ -125,9 +124,7 @@ static int corner_check(pass_to_bison *bison_args)
125124
{
126125
int c;
127126

128-
#ifdef PARSER_DEBUG
129-
fprintf(stderr, " Parser: corner_check()\n");
130-
#endif
127+
log_debug(__FILE__, PARSER, " Parser: corner_check()\n");
131128

132129
for (c = 0; c < NUM_CORNERS; ++c) {
133130
if (curdes.shape[corners[c]].elastic) {
@@ -145,9 +142,7 @@ static shape_t non_existent_elastics(pass_to_bison *bison_args)
145142
{
146143
shape_t i;
147144

148-
#ifdef PARSER_DEBUG
149-
fprintf(stderr, " Parser: non_existent_elastics()\n");
150-
#endif
145+
log_debug(__FILE__, PARSER, " Parser: non_existent_elastics()\n");
151146

152147
for (i = 0; i < NUM_SHAPES; ++i) {
153148
if (curdes.shape[i].elastic && isempty(curdes.shape + i)) {
@@ -164,9 +159,7 @@ static int insufficient_elasticity(pass_to_bison *bison_args)
164159
{
165160
int i, j, ef;
166161

167-
#ifdef PARSER_DEBUG
168-
fprintf(stderr, " Parser: insufficient_elasticity()\n");
169-
#endif
162+
log_debug(__FILE__, PARSER, " Parser: insufficient_elasticity()\n");
170163

171164
for (i = 0; i < NUM_SIDES; ++i) {
172165
for (j = 1, ef = 0; j < 4; ++j) {
@@ -188,9 +181,7 @@ static int adjoining_elastics(pass_to_bison *bison_args)
188181
{
189182
int i, j, ef;
190183

191-
#ifdef PARSER_DEBUG
192-
fprintf(stderr, " Parser: adjoining_elastics()\n");
193-
#endif
184+
log_debug(__FILE__, PARSER, " Parser: adjoining_elastics()\n");
194185

195186
for (i = 0; i < NUM_SIDES; ++i) {
196187
ef = 0;
@@ -593,11 +584,9 @@ int action_finalize_shapes(pass_to_bison *bison_args)
593584
curdes.maxshapeheight = curdes.shape[i].height;
594585
}
595586
}
596-
#ifdef PARSER_DEBUG
597-
fprintf(stderr, " Parser: Minimum box dimensions: width %d height %d\n",
587+
log_debug(__FILE__, PARSER, " Parser: Minimum box dimensions: width %d height %d\n",
598588
(int) curdes.minwidth, (int) curdes.minheight);
599-
fprintf(stderr, " Parser: Maximum shape height: %d\n", (int) curdes.maxshapeheight);
600-
#endif
589+
log_debug(__FILE__, PARSER, " Parser: Maximum shape height: %d\n", (int) curdes.maxshapeheight);
601590

602591
/*
603592
* Set name of each shape
@@ -631,9 +620,7 @@ int action_start_parsing_design(pass_to_bison *bison_args, char *design_name)
631620

632621
if (!design_needed(bison_args)) {
633622
bison_args->speeding = 1;
634-
#ifdef PARSER_DEBUG
635-
fprintf(stderr, " Parser: Skipping to next design (lexer doesn't know!)\n");
636-
#endif
623+
log_debug(__FILE__, PARSER, " Parser: Skipping to next design (lexer doesn't know!)\n");
637624
return RC_ERROR; /* trigger the parser's `error` rule, which will skip to the next design */
638625
}
639626
return RC_SUCCESS;
@@ -643,9 +630,12 @@ int action_start_parsing_design(pass_to_bison *bison_args, char *design_name)
643630

644631
int action_parent_config(pass_to_bison *bison_args, bxstr_t *filepath)
645632
{
646-
#ifdef PARSER_DEBUG
647-
fprintf(stderr, " Parser: parent config file specified: [%s]\n", bxs_to_output(filepath));
648-
#endif
633+
if (is_debug_logging(PARSER)) {
634+
char *out_filepath = bxs_to_output(filepath);
635+
log_debug(__FILE__, PARSER, " Parser: parent config file specified: [%s]\n", out_filepath);
636+
BFREE(out_filepath);
637+
}
638+
649639
if (bxs_is_empty(filepath)) {
650640
bison_args->skipping = 1;
651641
yyerror(bison_args, "parent reference is empty");
@@ -674,9 +664,11 @@ int action_parent_config(pass_to_bison *bison_args, bxstr_t *filepath)
674664
fclose(f);
675665
}
676666
}
677-
#ifdef PARSER_DEBUG
678-
fprintf(stderr, " Parser: parent config file path resolved: [%s]\n", bxs_to_output(filepath));
679-
#endif
667+
if (is_debug_logging(PARSER)) {
668+
char *out_filepath = bxs_to_output(filepath);
669+
log_debug(__FILE__, PARSER, " Parser: parent config file path resolved: [%s]\n", out_filepath);
670+
BFREE(out_filepath);
671+
}
680672

681673
int is_new = !array_contains_bxs(bison_args->parent_configs, bison_args->num_parent_configs, filepath);
682674
if (is_new) {
@@ -685,10 +677,10 @@ int action_parent_config(pass_to_bison *bison_args, bxstr_t *filepath)
685677
bison_args->parent_configs[bison_args->num_parent_configs] = filepath;
686678
++(bison_args->num_parent_configs);
687679
}
688-
else {
689-
#ifdef PARSER_DEBUG
690-
fprintf(stderr, " Parser: duplicate parent / cycle: [%s]\n", bxs_to_output(filepath));
691-
#endif
680+
else if (is_debug_logging(PARSER)) {
681+
char *out_filepath = bxs_to_output(filepath);
682+
log_debug(__FILE__, PARSER, " Parser: duplicate parent / cycle: [%s]\n", out_filepath);
683+
BFREE(out_filepath);
692684
}
693685
return RC_SUCCESS;
694686
}
@@ -699,9 +691,7 @@ int action_add_design(pass_to_bison *bison_args, char *design_primary_name, char
699691
{
700692
design_t *tmp;
701693

702-
#ifdef PARSER_DEBUG
703-
fprintf(stderr, "--------- ADDING DESIGN \"%s\".\n", design_primary_name);
704-
#endif
694+
log_debug(__FILE__, PARSER, "--------- ADDING DESIGN \"%s\".\n", design_primary_name);
705695

706696
if (strcasecmp(design_primary_name, name_at_end)) {
707697
yyerror(bison_args, "box design name differs at BOX and END");
@@ -747,9 +737,11 @@ int action_add_design(pass_to_bison *bison_args, char *design_primary_name, char
747737

748738
int action_record_keyword(pass_to_bison *bison_args, char *keyword, bxstr_t *value)
749739
{
750-
#ifdef PARSER_DEBUG
751-
fprintf(stderr, " Parser: entry rule fulfilled [%s = %s]\n", keyword, bxs_to_output(value));
752-
#endif
740+
if (is_debug_logging(PARSER)) {
741+
char *out_value = bxs_to_output(value);
742+
log_debug(__FILE__, PARSER, " Parser: entry rule fulfilled [%s = %s]\n", keyword, out_value);
743+
BFREE(out_value);
744+
}
753745

754746
size_t error_pos = 0;
755747
if (!bxs_valid_in_kv_string(value, &error_pos)) {
@@ -856,9 +848,7 @@ int action_add_alias(pass_to_bison *bison_args, char *alias_name)
856848
return RC_ERROR;
857849
}
858850
if (alias_exists_in_child_configs(bison_args, alias_name)) {
859-
#ifdef PARSER_DEBUG
860-
fprintf(stderr, " Parser: alias already used by child config, dropping: %s\n", alias_name);
861-
#endif
851+
log_debug(__FILE__, PARSER, " Parser: alias already used by child config, dropping: %s\n", alias_name);
862852
}
863853
else {
864854
size_t num_aliases = array_count0(curdes.aliases);
@@ -906,9 +896,7 @@ static uint32_t *find_first_nonblank_line(bxstr_t *sample)
906896

907897
int action_sample_block(pass_to_bison *bison_args, bxstr_t *sample)
908898
{
909-
#ifdef PARSER_DEBUG
910-
fprintf(stderr, " Parser: SAMPLE block rule satisfied\n");
911-
#endif
899+
log_debug(__FILE__, PARSER, " Parser: SAMPLE block rule satisfied\n");
912900

913901
if (curdes.sample) {
914902
yyerror(bison_args, "duplicate SAMPLE block");
@@ -944,12 +932,14 @@ int action_add_regex_rule(pass_to_bison *bison_args, char *type, reprule_t **rul
944932
{
945933
size_t n = *rule_list_len;
946934

947-
UNUSED(type); /* used only in PARSER_DEBUG mode */
948-
#ifdef PARSER_DEBUG
949-
fprintf(stderr, "Adding %s rule: \"%s\" with \"%s\" (%c)\n",
950-
strcmp(type, "rep") == 0 ? "replacement" : "reversion",
951-
bxs_to_output(search), bxs_to_output(replace), mode);
952-
#endif
935+
if (is_debug_logging(PARSER)) {
936+
char *out_search = bxs_to_output(search);
937+
char *out_replace = bxs_to_output(replace);
938+
log_debug(__FILE__, PARSER, "Adding %s rule: \"%s\" with \"%s\" (%c)\n",
939+
strcmp(type, "rep") == 0 ? "replacement" : "reversion", out_search, out_replace, mode);
940+
BFREE(out_replace);
941+
BFREE(out_search);
942+
}
953943

954944
*rule_list = (reprule_t *) realloc(*rule_list, (n + 1) * sizeof(reprule_t));
955945
if (*rule_list == NULL) {
@@ -975,9 +965,7 @@ int action_first_shape_line(pass_to_bison *bison_args, bxstr_t *line, sentry_t *
975965
{
976966
sentry_t rval = SENTRY_INITIALIZER;
977967

978-
#ifdef PARSER_DEBUG
979-
fprintf(stderr, "Initializing a shape entry with first line\n");
980-
#endif
968+
log_debug(__FILE__, PARSER, "Initializing a shape entry with first line\n");
981969

982970
size_t error_pos = 0;
983971
if (!bxs_valid_in_shape(line, &error_pos)) {
@@ -1018,9 +1006,7 @@ int action_first_shape_line(pass_to_bison *bison_args, bxstr_t *line, sentry_t *
10181006

10191007
int action_add_shape_line(pass_to_bison *bison_args, sentry_t *shape, bxstr_t *line)
10201008
{
1021-
#ifdef PARSER_DEBUG
1022-
fprintf(stderr, "Extending a shape entry\n");
1023-
#endif
1009+
log_debug(__FILE__, PARSER, "Extending a shape entry\n");
10241010

10251011
size_t slen = line->num_columns;
10261012
if (slen != shape->width) {

0 commit comments

Comments
 (0)