35
35
#include "generate.h"
36
36
#include "input.h"
37
37
#include "list.h"
38
+ #include "logging.h"
38
39
#include "parsing.h"
39
40
#include "query.h"
40
41
#include "remove.h"
@@ -156,7 +157,7 @@ static int build_design(design_t **adesigns, const char *cld)
156
157
157
158
default :
158
159
fprintf (stderr , "%s: internal error\n" , PROJECT );
159
- return 1 ; /* never happens ;-) */
160
+ return 1 ;
160
161
}
161
162
c -> name = i ;
162
163
@@ -180,9 +181,8 @@ static int build_design(design_t **adesigns, const char *cld)
180
181
*/
181
182
static void handle_command_line (int argc , char * argv [])
182
183
{
183
- #ifdef DEBUG
184
- fprintf (stderr , "Processing Command Line ...\n" );
185
- #endif
184
+ log_debug (__FILE__ , MAIN , "Processing Command Line ...\n" );
185
+
186
186
opt_t * parsed_opts = process_commandline (argc , argv );
187
187
if (parsed_opts == NULL ) {
188
188
exit (EXIT_FAILURE );
@@ -269,9 +269,8 @@ static void apply_expected_size()
269
269
*/
270
270
static void handle_input ()
271
271
{
272
- #ifdef DEBUG
273
- fprintf (stderr , "Reading all input ...\n" );
274
- #endif
272
+ log_debug (__FILE__ , MAIN , "Reading all input ...\n" );
273
+
275
274
input_t * raw_input = NULL ;
276
275
if (opt .mend != 0 ) {
277
276
raw_input = read_all_input ();
@@ -287,10 +286,10 @@ static void handle_input()
287
286
BFREE (raw_input );
288
287
}
289
288
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 );
292
291
print_input_lines (NULL );
293
- #endif
292
+ }
294
293
if (input .num_lines == 0 ) {
295
294
exit (EXIT_SUCCESS );
296
295
}
@@ -362,9 +361,8 @@ static void adjust_size_and_padding()
362
361
*/
363
362
static void handle_generate_box ()
364
363
{
365
- #ifdef DEBUG
366
- fprintf (stderr , "Generating Box ...\n" );
367
- #endif
364
+ log_debug (__FILE__ , MAIN , "Generating Box ...\n" );
365
+
368
366
sentry_t * thebox = (sentry_t * ) calloc (NUM_SIDES , sizeof (sentry_t ));
369
367
if (thebox == NULL ) {
370
368
perror (PROJECT );
@@ -384,9 +382,8 @@ static void handle_generate_box()
384
382
*/
385
383
static void handle_remove_box ()
386
384
{
387
- #ifdef DEBUG
388
- fprintf (stderr , "Removing Box ...\n" );
389
- #endif
385
+ log_debug (__FILE__ , MAIN , "Removing Box ...\n" );
386
+
390
387
if (opt .killblank == -1 ) {
391
388
if (empty_side (opt .design -> shape , BTOP ) && empty_side (opt .design -> shape , BBOT )) {
392
389
opt .killblank = 0 ;
@@ -425,15 +422,16 @@ static int terminal_has_colors()
425
422
result = 1 ;
426
423
}
427
424
#endif
428
- #if defined(DEBUG )
425
+
426
+ if (is_debug_logging (MAIN )) {
429
427
#ifdef __MINGW32__
430
428
int num_colors = 1 ;
431
429
#else
432
430
int num_colors = result ? tigetnum ("colors" ) : 0 ;
433
431
#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
+ }
437
435
return result ;
438
436
}
439
437
@@ -449,9 +447,7 @@ static int check_color_support(int opt_color)
449
447
result = terminal_has_colors ();
450
448
}
451
449
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" );
455
451
return result ;
456
452
}
457
453
@@ -485,9 +481,7 @@ int main(int argc, char *argv[])
485
481
int saved_designwidth ; /* opt.design->minwith backup, used for mending */
486
482
int saved_designheight ; /* opt.design->minheight backup, used for mending */
487
483
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 */
491
485
492
486
/* Temporarily set the system encoding, for proper output of --help text etc. */
493
487
activateSystemEncoding ();
@@ -497,9 +491,7 @@ int main(int argc, char *argv[])
497
491
498
492
/* Store system character encoding */
499
493
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 );
503
495
504
496
color_output_enabled = check_color_support (opt .color );
505
497
0 commit comments