# 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
# 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
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;
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';
}
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;
}
}
+sub print_verbose {
+ (my $depth, my $level, my $text) = @_;
+ if ($level < $verbose) {
+ print STDERR (' 'x($depth + $level)).$text."\n";
+ }
+}
+
sub unescape1ch {
(my $to_escape) = @_;
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;
$value = parse_value($value, $depth+1, %cfg);
}
$cfg{$name} .= $value;
+ print_verbose($depth, 1, "pattern $name=$value");
print_debug($depth, "ADD $name=$value")
}
}
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);
}
}
+ # 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;
}
}
+# "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 <http://www.gnu.org/licenses/>.
+
DEFAULT_TARGET = debug
ifndef TARGET
TARGET = debug
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
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
+# "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 <http://www.gnu.org/licenses/>.
+
DEFAULT_TARGET = debug
ifndef TARGET
TARGET = debug ###make_target:
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
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