# 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
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;
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)$/) {
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';
}
}
elsif ($arg =~ /^([A-Za-z0-9_\-\.]+)=(.*)$/) { # predefined setting
$cfg{$1} = $2;
+ print_verbose(0, 1, "$1: $2");
}
else { # file
if ($file_type eq 'i') {
($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});
}
}
(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";
}
}
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";
$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")
}
}