From 46717c9c1421831e4d41f03a6f25b377fc5c4826 Mon Sep 17 00:00:00 2001 From: b Date: Mon, 19 Feb 2024 22:18:01 +0000 Subject: [PATCH] more debug output possibility --- configure.1.pl | 31 +++++++++++++++++++++++++++---- install.sh | 5 +++++ makefile | 23 ++++++++++++++++++++--- makefile.1.mak | 23 ++++++++++++++++++++--- 4 files changed, 72 insertions(+), 10 deletions(-) create mode 100755 install.sh diff --git a/configure.1.pl b/configure.1.pl index 6a150cf..f9d4618 100755 --- a/configure.1.pl +++ b/configure.1.pl @@ -3,7 +3,7 @@ # configure.pl # The new BOTM configuration tool -# Copyright (C) 2022, 2023 Balthasar Szczepański +# Copyright (C) 2022, 2023, 2024 Balthasar Szczepański # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -84,6 +84,8 @@ # error # * --la, --listall, --list_all - as above but will include settings not # 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. # * --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 @@ -426,6 +428,7 @@ my $debug_all = 0; my $list = 0; my $list_all = 0; my $file_type = ''; +my $verbose = 0; $cfg{REPLACE_LINE()} = DEFAULT_REPLACE_LINE; $cfg{REPLACE_KEYWORD()} = DEFAULT_REPLACE_KEYWORD; @@ -445,17 +448,20 @@ foreach my $arg (@ARGV) { if ($arg =~ /^d(ebug)?$/) { $debug_enabled = 1; } - elsif ($arg =~ /^(da)|(debug_?all)$/) { + elsif ($arg =~ /^(da)|(debug[_\-]?all)$/) { $debug_enabled = 1; $debug_all = 1; } elsif ($arg =~ /^l(ist)?$/) { $list = 1; } - elsif ($arg =~ /^(la)|(list-?all)$/) { + elsif ($arg =~ /^(la)|(list[_\-]?all)$/) { $list = 1; $list_all = 1; } + elsif ($arg =~ /^v+$/) { + $verbose = length($&); + } elsif ($arg =~ /^i(n(put)?)?$/) { $file_type = 'i'; } @@ -587,6 +593,8 @@ sub replace_masked { my $text_after = substr($text, $ind+$len); my $mask_after = substr($mask, $ind+$len); + print_verbose(0, 1, "$to_replace -> $replacement"); + $text = $text_before.$replacement.$text_after; $mask = $mask_before.$mask_insert.$mask_after; @@ -601,6 +609,13 @@ sub print_debug { } } +sub print_verbose { + (my $depth, my $level, my $text) = @_; + if ($level < $verbose) { + print STDERR (' 'x($depth + $level)).$text."\n"; + } +} + sub unescape1ch { (my $to_escape) = @_; @@ -990,6 +1005,8 @@ sub parse_value { sub parse_file { (my $path, my $encoding, my $depth, my %cfg) = @_; + print_verbose($depth, 0, "config file $path"); + if ($depth >= MAX_DEPTH) { print STDERR "Too deep.\n"; exit 3; @@ -1105,6 +1122,7 @@ sub parse_file { $value = parse_value($value, $depth+1, %cfg); } $cfg{$name} .= $value; + print_verbose($depth, 1, "pattern $name=$value"); print_debug($depth, "ADD $name=$value") } } @@ -1116,6 +1134,8 @@ sub parse_file { sub convert_file { (my $in, my $out, my $encoding) = @_; + print_verbose(0, 0, $in.' -> '.$out); + my $ref_in = ref($in); my $ref_out = ref($out); @@ -1148,12 +1168,15 @@ sub convert_file { } } + # TODO: This is extremely inefficient. and does not scale well. Improve! my $status; LINE: while (defined(my $line = <$in>)) { $line =~ s/[\r\n]//g; foreach my $key (keys %replace_line) { if (index($line, $key) >= 0) { - print $out "$replace_line{$key}\n"; + my $replace = $replace_line{$key}; + print_verbose(0, 1, "$key -> $replace"); + print $out "$replace\n"; next LINE; } } diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..27f5a30 --- /dev/null +++ b/install.sh @@ -0,0 +1,5 @@ +#!/bin/sh +make clean +make -B TARGET=release makefile +make install +make clean diff --git a/makefile b/makefile index 7c71f4a..d8a63c1 100644 --- a/makefile +++ b/makefile @@ -1,3 +1,20 @@ +# "makefile" is automatically generated from "makefile.1.mak" +# +# Copyright (C) 2022, 2023, 2024 Balthasar Szczepański +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + DEFAULT_TARGET = debug ifndef TARGET TARGET = debug @@ -33,8 +50,8 @@ makefile: makefile.1.mak configure.1.pl $(CONFIGFILE) configure.pl: configure.1.pl $(CONFIGURE) $(CONFIGFILE) --ef=UTF-8 --in configure.1.pl --out configure.pl -exec: configure.pl - $(CHMOD) +x configure.pl +exec: configure.pl install.sh + $(CHMOD) +x configure.pl install.sh ifdef BIN_DIR @@ -55,7 +72,7 @@ endif clean: $(CONFIGURE) $(DEFAULT_CONFIGFILE) < makefile.1.mak > makefile - $(RM) configure.pl + $(RM) -f configure.pl PHONY: all exec bin_dir cp_bin rm_bin install uninstall clean diff --git a/makefile.1.mak b/makefile.1.mak index 7596466..027090b 100644 --- a/makefile.1.mak +++ b/makefile.1.mak @@ -1,3 +1,20 @@ +# "makefile" is automatically generated from "makefile.1.mak" +# +# Copyright (C) 2022, 2023, 2024 Balthasar Szczepański +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + DEFAULT_TARGET = debug ifndef TARGET TARGET = debug ###make_target: @@ -33,8 +50,8 @@ makefile: makefile.1.mak configure.1.pl $(CONFIGFILE) configure.pl: configure.1.pl $(CONFIGURE) $(CONFIGFILE) --ef=UTF-8 --in configure.1.pl --out configure.pl -exec: configure.pl - $(CHMOD) +x configure.pl +exec: configure.pl install.sh + $(CHMOD) +x configure.pl install.sh ifdef BIN_DIR @@ -55,7 +72,7 @@ endif clean: $(CONFIGURE) $(DEFAULT_CONFIGFILE) < makefile.1.mak > makefile - $(RM) configure.pl + $(RM) -f configure.pl PHONY: all exec bin_dir cp_bin rm_bin install uninstall clean -- 2.30.2