From: b Date: Thu, 22 Feb 2024 21:49:20 +0000 (+0000) Subject: improvement related to debug output X-Git-Tag: v1.2.5 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=fc9affec336a16cde93b2675a836bdd01d1c2210;p=botm%2Fconfig improvement related to debug output --- diff --git a/configure.1.pl b/configure.1.pl index 62fdc80..aec27da 100755 --- a/configure.1.pl +++ b/configure.1.pl @@ -87,6 +87,8 @@ # available for applying in files (starting with '_') # * --v, --vv - will print information about processed files and patterns # to standard error. Number of 'v's is the verbose level. +# * --do, --debug_stdout - all debug information will go to standard output +# * --de, --debug_stderr - all debug information will go to standard error # * --i, --in, --input - all further file paths are for input files # * --o, --out, --output - all further file paths are for output files # * -- - all further file paths are for configuration files @@ -440,6 +442,7 @@ my $encoding_file = ''; my $encoding_configfile = ''; my $encoding_stdin; my $encoding_stdout; +my $debug_out = \*STDERR; $cfg{REPLACE_LINE()} = DEFAULT_REPLACE_LINE; $cfg{REPLACE_KEYWORD()} = DEFAULT_REPLACE_KEYWORD; @@ -448,9 +451,12 @@ $cfg{PATH_SEPARATOR()} = DEFAULT_PATH_SEPARATOR; decode_argv(); foreach my $arg (@ARGV) { - if ($arg =~ /^--(.*)$/) { # option - $arg = $1; - if ($arg =~ /^d(ebug)?$/) { + if ($arg =~ /^(--?)(.*)$/) { # option + $arg = $2; + if (($1 eq '-') and (length($arg)>1)) { + # invalid for now + } + elsif ($arg =~ /^d(ebug)?$/) { $debug_enabled = 1; } elsif ($arg =~ /^(da)|(debug[_\-]?all)$/) { @@ -467,6 +473,12 @@ foreach my $arg (@ARGV) { elsif ($arg =~ /^v+$/) { $verbose += length($&); } + elsif ($arg =~ /^(do)|(debug[_\-]?stdout)$/) { + $debug_out = \*STDOUT; + } + elsif ($arg =~ /^(de)|(debug[_\-]?stderr)$/) { + $debug_out = \*STDERR; + } elsif ($arg =~ /^i(n(put)?)?$/) { $file_type = 'i'; } @@ -488,6 +500,7 @@ foreach my $arg (@ARGV) { } elsif ($arg =~ /^([A-Za-z0-9_\-\.]+)=(.*)$/) { # predefined setting $cfg{$1} = $2; + print_verbose(0, 1, "$1: $2"); } else { # file if ($file_type eq 'i') { @@ -542,13 +555,13 @@ foreach my $key (keys %cfg) { ($key =~ /^[0-9]+$/) ) { if ($list_all) { - print STDERR format_cfg($key, $cfg{$key}); + print $debug_out format_cfg($key, $cfg{$key}); } delete %cfg{$key}; next; } if ($list or $list_all) { - print STDERR format_cfg($key, $cfg{$key}); + print $debug_out format_cfg($key, $cfg{$key}); } } @@ -644,14 +657,14 @@ sub print_debug { (my $depth, my $text) = @_; if ($debug_enabled) { # $debug_text .= (' 'x$depth).$text."\n"; - print STDERR (' 'x$depth).$text."\n"; + print $debug_out (' 'x$depth).$text."\n"; } } sub print_verbose { (my $depth, my $level, my $text) = @_; if ($level < $verbose) { - print STDERR (' 'x($depth + $level)).$text."\n"; + print $debug_out (' 'x($depth + $level)).$text."\n"; } } @@ -1044,7 +1057,7 @@ sub parse_value { sub parse_file { (my $path, my $encoding, my $depth, my %cfg) = @_; - print_verbose($depth, 0, "config file $path"); + print_verbose($depth, 0, "$path"); if ($depth >= MAX_DEPTH) { print STDERR "Too deep.\n"; @@ -1161,7 +1174,7 @@ sub parse_file { $value = parse_value($value, $depth+1, %cfg); } $cfg{$name} .= $value; - print_verbose($depth, 1, "pattern $name=$value"); + print_verbose($depth, 1, "$name: $value"); print_debug($depth, "ADD $name=$value") } }