+++ /dev/null
-# 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 <http://www.gnu.org/licenses/>.
-
-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