From 1b6f1e5beedad2bfa1400549bf3c01d14e209882 Mon Sep 17 00:00:00 2001 From: b Date: Fri, 12 May 2023 19:14:50 +0000 Subject: [PATCH] use botm-common library submodule --- .gitmodules | 3 ++ botm-common | 1 + botm_common.pm | 107 ------------------------------------------------- makefile | 2 +- makefile.1.mak | 2 +- 5 files changed, 6 insertions(+), 109 deletions(-) create mode 100644 .gitmodules create mode 160000 botm-common delete mode 100644 botm_common.pm diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..18429c3 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "botm-common"] + path = botm-common + url = ../../botm/common-perl diff --git a/botm-common b/botm-common new file mode 160000 index 0000000..341e2e9 --- /dev/null +++ b/botm-common @@ -0,0 +1 @@ +Subproject commit 341e2e9846e2f68a53b336eb5e741346e82b039e diff --git a/botm_common.pm b/botm_common.pm deleted file mode 100644 index a94f664..0000000 --- a/botm_common.pm +++ /dev/null @@ -1,107 +0,0 @@ -# Copyright (C) 2023 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 . - -package botm_common; - -use strict; -#use warnings; -use utf8; - -use Encode qw(encode decode); - -use Exporter; -use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); - -$VERSION = 1.000000; -@ISA = qw(Exporter); -@EXPORT = (); -@EXPORT_OK = qw(readdatafile); -%EXPORT_TAGS = (); - -sub readdatafile { - (my $path, my $encoding, my $content_only) = @_; - my $file; - my %data; - my $eoh=0; - - if ($encoding eq '') { - $encoding = 'utf8'; - } - if ($content_only) { - $eoh=1; - } - - # check if $path is actually a path or maybe a filehandle - # filehandles are references. - if(ref($path)) { - $file=$path; - unless (seek($file, 0, 0)) { - # return %data; - } - } - else { - unless (open ($file, "<:$encoding", $path)) { - return %data; - } - } - - # The name of header field in previous line. Required for header fields that - # occupy multiple lines. - my $lastname=''; - - while (defined(my $line = <$file>)) { - # $line = decode($encoding, $line); - my $name=''; - my $value=''; - - if ($eoh){ - unless($line eq'') { - $data{'content'} = $data{'content'}.$line; - } - next; - } - - $line =~ s/[\n]$//g; - - # Empty line - end of header. - if ($line eq ''){ - $eoh=1; - } - # Line starts with whitespace. It's a continuation of the previous line. - # Concatenate the field value, separated by newline. - elsif($line =~ /^[ \t](.*)$/){ - if($lastname ne '') { - $data{$lastname} .= "\n".$1; - } - } - # Line starts with a name followed by colon/equal sign. Save the value - elsif ($line =~ /^([ -9;-<>-~]+)((:[ \t])|=)(.*)$/) { - $name = lc($1); - $value = $4; - - $data{$name} = $value; - - $lastname = $name; - } - } - # If argument was a path the file must be closed. - unless (ref($path)) { - close ($file); - } - - return %data; -} - -1 diff --git a/makefile b/makefile index e54680c..a9cc2c6 100644 --- a/makefile +++ b/makefile @@ -57,7 +57,7 @@ BIN=\ $(EXEC) LIB=\ -botm_common.pm +botm-common/botm_common.pm all: $(BIN) diff --git a/makefile.1.mak b/makefile.1.mak index 71d5d7d..772aa5e 100644 --- a/makefile.1.mak +++ b/makefile.1.mak @@ -57,7 +57,7 @@ BIN=\ $(EXEC) LIB=\ -botm_common.pm +botm-common/botm_common.pm all: $(BIN) -- 2.30.2