27
27
#include <unistr.h>
28
28
29
29
#include "discovery.h"
30
+ #include "logging.h"
30
31
#include "parsecode.h"
31
32
#include "parsing.h"
32
33
#include "query.h"
@@ -57,9 +58,7 @@ static int check_sizes(pass_to_bison *bison_args)
57
58
{
58
59
int i , j , k ;
59
60
60
- #ifdef PARSER_DEBUG
61
- fprintf (stderr , " Parser: check_sizes()\n" );
62
- #endif
61
+ log_debug (__FILE__ , PARSER , " Parser: check_sizes()\n" );
63
62
64
63
for (i = 0 ; i < NUM_SIDES ; ++ i ) {
65
64
if (i == 0 || i == 2 ) {
@@ -125,9 +124,7 @@ static int corner_check(pass_to_bison *bison_args)
125
124
{
126
125
int c ;
127
126
128
- #ifdef PARSER_DEBUG
129
- fprintf (stderr , " Parser: corner_check()\n" );
130
- #endif
127
+ log_debug (__FILE__ , PARSER , " Parser: corner_check()\n" );
131
128
132
129
for (c = 0 ; c < NUM_CORNERS ; ++ c ) {
133
130
if (curdes .shape [corners [c ]].elastic ) {
@@ -145,9 +142,7 @@ static shape_t non_existent_elastics(pass_to_bison *bison_args)
145
142
{
146
143
shape_t i ;
147
144
148
- #ifdef PARSER_DEBUG
149
- fprintf (stderr , " Parser: non_existent_elastics()\n" );
150
- #endif
145
+ log_debug (__FILE__ , PARSER , " Parser: non_existent_elastics()\n" );
151
146
152
147
for (i = 0 ; i < NUM_SHAPES ; ++ i ) {
153
148
if (curdes .shape [i ].elastic && isempty (curdes .shape + i )) {
@@ -164,9 +159,7 @@ static int insufficient_elasticity(pass_to_bison *bison_args)
164
159
{
165
160
int i , j , ef ;
166
161
167
- #ifdef PARSER_DEBUG
168
- fprintf (stderr , " Parser: insufficient_elasticity()\n" );
169
- #endif
162
+ log_debug (__FILE__ , PARSER , " Parser: insufficient_elasticity()\n" );
170
163
171
164
for (i = 0 ; i < NUM_SIDES ; ++ i ) {
172
165
for (j = 1 , ef = 0 ; j < 4 ; ++ j ) {
@@ -188,9 +181,7 @@ static int adjoining_elastics(pass_to_bison *bison_args)
188
181
{
189
182
int i , j , ef ;
190
183
191
- #ifdef PARSER_DEBUG
192
- fprintf (stderr , " Parser: adjoining_elastics()\n" );
193
- #endif
184
+ log_debug (__FILE__ , PARSER , " Parser: adjoining_elastics()\n" );
194
185
195
186
for (i = 0 ; i < NUM_SIDES ; ++ i ) {
196
187
ef = 0 ;
@@ -593,11 +584,9 @@ int action_finalize_shapes(pass_to_bison *bison_args)
593
584
curdes .maxshapeheight = curdes .shape [i ].height ;
594
585
}
595
586
}
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" ,
598
588
(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 );
601
590
602
591
/*
603
592
* Set name of each shape
@@ -631,9 +620,7 @@ int action_start_parsing_design(pass_to_bison *bison_args, char *design_name)
631
620
632
621
if (!design_needed (bison_args )) {
633
622
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" );
637
624
return RC_ERROR ; /* trigger the parser's `error` rule, which will skip to the next design */
638
625
}
639
626
return RC_SUCCESS ;
@@ -643,9 +630,12 @@ int action_start_parsing_design(pass_to_bison *bison_args, char *design_name)
643
630
644
631
int action_parent_config (pass_to_bison * bison_args , bxstr_t * filepath )
645
632
{
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
+
649
639
if (bxs_is_empty (filepath )) {
650
640
bison_args -> skipping = 1 ;
651
641
yyerror (bison_args , "parent reference is empty" );
@@ -674,9 +664,11 @@ int action_parent_config(pass_to_bison *bison_args, bxstr_t *filepath)
674
664
fclose (f );
675
665
}
676
666
}
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
+ }
680
672
681
673
int is_new = !array_contains_bxs (bison_args -> parent_configs , bison_args -> num_parent_configs , filepath );
682
674
if (is_new ) {
@@ -685,10 +677,10 @@ int action_parent_config(pass_to_bison *bison_args, bxstr_t *filepath)
685
677
bison_args -> parent_configs [bison_args -> num_parent_configs ] = filepath ;
686
678
++ (bison_args -> num_parent_configs );
687
679
}
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 );
692
684
}
693
685
return RC_SUCCESS ;
694
686
}
@@ -699,9 +691,7 @@ int action_add_design(pass_to_bison *bison_args, char *design_primary_name, char
699
691
{
700
692
design_t * tmp ;
701
693
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 );
705
695
706
696
if (strcasecmp (design_primary_name , name_at_end )) {
707
697
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
747
737
748
738
int action_record_keyword (pass_to_bison * bison_args , char * keyword , bxstr_t * value )
749
739
{
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
+ }
753
745
754
746
size_t error_pos = 0 ;
755
747
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)
856
848
return RC_ERROR ;
857
849
}
858
850
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 );
862
852
}
863
853
else {
864
854
size_t num_aliases = array_count0 (curdes .aliases );
@@ -906,9 +896,7 @@ static uint32_t *find_first_nonblank_line(bxstr_t *sample)
906
896
907
897
int action_sample_block (pass_to_bison * bison_args , bxstr_t * sample )
908
898
{
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" );
912
900
913
901
if (curdes .sample ) {
914
902
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
944
932
{
945
933
size_t n = * rule_list_len ;
946
934
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
+ }
953
943
954
944
* rule_list = (reprule_t * ) realloc (* rule_list , (n + 1 ) * sizeof (reprule_t ));
955
945
if (* rule_list == NULL ) {
@@ -975,9 +965,7 @@ int action_first_shape_line(pass_to_bison *bison_args, bxstr_t *line, sentry_t *
975
965
{
976
966
sentry_t rval = SENTRY_INITIALIZER ;
977
967
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" );
981
969
982
970
size_t error_pos = 0 ;
983
971
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 *
1018
1006
1019
1007
int action_add_shape_line (pass_to_bison * bison_args , sentry_t * shape , bxstr_t * line )
1020
1008
{
1021
- #ifdef PARSER_DEBUG
1022
- fprintf (stderr , "Extending a shape entry\n" );
1023
- #endif
1009
+ log_debug (__FILE__ , PARSER , "Extending a shape entry\n" );
1024
1010
1025
1011
size_t slen = line -> num_columns ;
1026
1012
if (slen != shape -> width ) {
0 commit comments