26
26
27
27
#include "boxes.h"
28
28
#include "input.h"
29
+ #include "logging.h"
29
30
#include "regulex.h"
30
31
#include "tools.h"
31
32
#include "unicode.h"
@@ -45,9 +46,7 @@ static int has_linebreak(const uint32_t *s, const int len)
45
46
if (s != NULL && len > 0 ) {
46
47
ucs4_t the_last = s [len - 1 ];
47
48
result = u32_cmp (& char_cr , & the_last , 1 ) == 0 || u32_cmp (& char_newline , & the_last , 1 ) == 0 ;
48
- #if defined(DEBUG )
49
- fprintf (stderr , "has_linebreak: (%#010x) %d\n" , (int ) the_last , result );
50
- #endif
49
+ log_debug (__FILE__ , MAIN , "has_linebreak: (%#010x) %d\n" , (int ) the_last , result );
51
50
}
52
51
return result ;
53
52
}
@@ -66,7 +65,7 @@ static int get_indent(const line_t *lines, const size_t lines_size)
66
65
int nonblank = 0 ; /* true if one non-blank line found */
67
66
68
67
if (lines == NULL ) {
69
- fprintf (stderr , "%s: internal error\n" , PROJECT );
68
+ bx_fprintf (stderr , "%s: internal error\n" , PROJECT );
70
69
return -1 ;
71
70
}
72
71
if (lines_size == 0 ) {
@@ -112,16 +111,14 @@ int apply_substitutions(input_t *result, const int mode)
112
111
rules = opt .design -> revrules ;
113
112
}
114
113
else {
115
- fprintf (stderr , "%s: internal error\n" , PROJECT );
114
+ bx_fprintf (stderr , "%s: internal error\n" , PROJECT );
116
115
return 2 ;
117
116
}
118
117
119
118
/*
120
119
* Compile regular expressions
121
120
*/
122
- #ifdef REGEXP_DEBUG
123
- fprintf (stderr , "Compiling %d %s rule patterns\n" , (int ) num_rules , mode ? "reversion" : "replacement" );
124
- #endif
121
+ log_debug (__FILE__ , REGEXP , "Compiling %d %s rule patterns\n" , (int ) num_rules , mode ? "reversion" : "replacement" );
125
122
errno = 0 ;
126
123
opt .design -> current_rule = rules ;
127
124
for (j = 0 ; j < num_rules ; ++ j , ++ (opt .design -> current_rule )) {
@@ -141,21 +138,21 @@ int apply_substitutions(input_t *result, const int mode)
141
138
for (k = 0 ; k < result -> num_lines ; ++ k ) {
142
139
opt .design -> current_rule = rules ;
143
140
for (j = 0 ; j < num_rules ; ++ j , ++ (opt .design -> current_rule )) {
144
- #ifdef REGEXP_DEBUG
141
+ if ( is_debug_logging ( REGEXP )) {
145
142
char * outtext = bxs_to_output (result -> lines [k ].text );
146
143
char * outrepstr = bxs_to_output (rules [j ].repstr );
147
- fprintf ( stderr , "regex_replace(0x%p, \"%s\", \"%s\", %d, \'%c\') == " , rules [j ].prog , outrepstr ,
148
- outtext , (int ) result -> lines [k ].text -> num_chars , rules [j ].mode );
144
+ log_debug ( __FILE__ , REGEXP , "regex_replace(0x%p, \"%s\", \"%s\", %d, \'%c\') == " , rules [j ].prog ,
145
+ outrepstr , outtext , (int ) result -> lines [k ].text -> num_chars , rules [j ].mode );
149
146
BFREE (outtext );
150
147
BFREE (outrepstr );
151
- #endif
148
+ }
152
149
uint32_t * newtext = u32_regex_replace (rules [j ].prog , rules [j ].repstr -> memory , result -> lines [k ].text -> memory ,
153
150
result -> lines [k ].text -> num_chars , rules [j ].mode == 'g' );
154
- #ifdef REGEXP_DEBUG
151
+ if ( is_debug_logging ( REGEXP )) {
155
152
char * outnewtext = newtext ? u32_strconv_to_output (newtext ) : strdup ("NULL" );
156
- fprintf ( stderr , "\"%s\"\n" , outnewtext );
153
+ log_debug_cont ( REGEXP , "\"%s\"\n" , outnewtext );
157
154
BFREE (outnewtext );
158
- #endif
155
+ }
159
156
if (newtext == NULL ) {
160
157
return 1 ;
161
158
}
@@ -165,12 +162,12 @@ int apply_substitutions(input_t *result, const int mode)
165
162
166
163
analyze_line_ascii (result , result -> lines + k ); /* update maxline value */
167
164
168
- #ifdef REGEXP_DEBUG
165
+ if ( is_debug_logging ( REGEXP )) {
169
166
char * outtext2 = bxs_to_output (result -> lines [k ].text );
170
- fprintf ( stderr , "result->lines[%d] == {%d, \"%s\"}\n" , ( int ) k , ( int ) result -> lines [ k ]. text -> num_chars ,
171
- outtext2 );
167
+ log_debug ( __FILE__ , REGEXP , "result->lines[%d] == {%d, \"%s\"}\n" ,
168
+ ( int ) k , ( int ) result -> lines [ k ]. text -> num_chars , outtext2 );
172
169
BFREE (outtext2 );
173
- #endif
170
+ }
174
171
}
175
172
opt .design -> current_rule = NULL ;
176
173
}
@@ -321,15 +318,15 @@ int analyze_input(input_t *result)
321
318
bxs_free (result -> lines [i ].text );
322
319
result -> lines [i ].text = unindented ;
323
320
}
324
- #ifdef DEBUG
321
+ if ( is_debug_logging ( MAIN )) {
325
322
char * outtext = bxs_to_output (result -> lines [i ].text );
326
- fprintf ( stderr , "%2d: text = \"%s\" (%d chars, %d visible, %d invisible, %d columns)\n"
327
- " ascii = \"%s\"\n" , (int ) i , outtext ,
323
+ log_debug ( __FILE__ , MAIN , "%2d: text = \"%s\" (%d chars, %d visible, %d invisible, %d columns)\n" ,
324
+ (int ) i , outtext ,
328
325
(int ) result -> lines [i ].text -> num_chars , (int ) result -> lines [i ].text -> num_chars_visible ,
329
- (int ) result -> lines [i ].text -> num_chars_invisible , (int ) result -> lines [i ].text -> num_columns ,
330
- result -> lines [i ].text -> ascii );
326
+ (int ) result -> lines [i ].text -> num_chars_invisible , (int ) result -> lines [i ].text -> num_columns );
327
+ log_debug ( __FILE__ , MAIN , " ascii = \"%s\"\n" , result -> lines [i ].text -> ascii );
331
328
BFREE (outtext );
332
- #endif
329
+ }
333
330
}
334
331
result -> maxline -= result -> indent ;
335
332
}
0 commit comments