PIM VCard converter vcard2om.pl

From Openmoko

(Difference between revisions)
Jump to: navigation, search
m (Copy the Script in Edit Mode of this Page)
 
(17 intermediate revisions by 2 users not shown)
Line 2: Line 2:
 
  input file; /media/card/pim/contacts.vcf
 
  input file; /media/card/pim/contacts.vcf
 
  outputfile: /home/root/.evolution/vCards.html
 
  outputfile: /home/root/.evolution/vCards.html
Change according to your VCF-files.
+
* the output file consists of a list of names in alphabetical oder without any contact details.
The script converts the VCF into to a hash and with that you can export to any other file format (SQL command for importing in an sqllite database).
+
* you can click on all the names in the list and your will be linked to the contact details
 +
* when you view on the contact details you can click on the name again and you are back in the list without details.
 +
 
 +
The script is very robust against parsing errors in the
 +
 
 +
Change the filenames according to your location of VCF-files. The input file and the outputfile are defined in the first few lines of script mentioned below.
 +
The script converts the VCF into to a hash and with that you can export to any other file format (SQL command for importing in an sqllite database - this not implemented yet).
 
=== Icon for the Converter ===
 
=== Icon for the Converter ===
Create an icon by copying one <tt>midori.desktop</tt> to <tt>convertvcf.desktop</tt> and change the settings with nano editor. The Exec command is <tt>perl /home/root/bin/vcard2om.pl</tt>, if you store the script in your /home/root/bin/ directory (an other directory is possible too).  
+
Create an icon by copying one <tt>midori.desktop</tt> to <tt>convertvcf.desktop</tt> and change the settings with nano editor. The Exec command is <tt>perl /home/root/bin/vcard2om.pl</tt>, if you store the script in your /home/root/bin/ directory (an other directory is possible too).
 +
 
 +
  [Desktop Entry]
 +
  Version=1.0
 +
  Type=Application
 +
  Name=convVCF
 +
  Comment=Convert VCF VCard file into HTML
 +
  Categories=GTK;Network;
 +
  MimeType=text/html;text/xml;application/xhtml+xml;application/xml;
 +
  Exec=perl /home/root/bin/vcard2html.pl
 +
  Icon=tools
 +
  Terminal=false
 +
  StartupNotify=true
 +
 
 +
Copy this to <tt>convertvcf2html.desktop</tt> and save to
 +
  /usr/share/applications
 +
([http://wiki.openmoko.org/wiki/SHR_User_Manual SHR], OM, ...)
 +
 
 
=== Install Perl ===
 
=== Install Perl ===
 
Install perl before with:
 
Install perl before with:
 
   opkg install perl
 
   opkg install perl
 +
=== Start the Script ===
 +
Start the script with perl:
 +
  perl /home/root/bin/vcard2om.pl
 +
 +
=== Syncing VCF files with unison ===
 +
You can sync the vcf (VCard) files from your desktop computer with [[Unison]].
 +
 
=== Copy the Script in Edit Mode of this Page ===
 
=== Copy the Script in Edit Mode of this Page ===
 
If you want to copy the following script, go to <i>edit</i> of the page and copy the code of the script inbetween the PRE-Tags, because some characters are not shown as they should in the ''preview'' of this page. And now the script just for an overview:
 
If you want to copy the following script, go to <i>edit</i> of the page and copy the code of the script inbetween the PRE-Tags, because some characters are not shown as they should in the ''preview'' of this page. And now the script just for an overview:
Line 14: Line 44:
 
#!/usr/bin/perl
 
#!/usr/bin/perl
  
my %options = ();
+
my %options;
 
$options{infile}  = "/media/card/pim/contacts.vcf";
 
$options{infile}  = "/media/card/pim/contacts.vcf";
 
$options{outfile} = "/home/root/.evolution/vCards.html";
 
$options{outfile} = "/home/root/.evolution/vCards.html";
Line 31: Line 61:
  
 
my $flocking = 1;
 
my $flocking = 1;
my @FileArray = ();
+
my @FileArray;
my @OutFileArray = ();
+
my @OutFileArray;
my %OutFileHash = ();
+
my %OutFileHash;
 +
my %OutNameHash;
 +
 
 
my $OUTFORMAT = uc($outformat);
 
my $OUTFORMAT = uc($outformat);
  
my @SplitArray     = ();
+
my @SplitArray;
my @SplitArrayID   = ();
+
my @SplitArrayID;
my @SplitArrayValue = ();  
+
my @SplitArrayValue;  
my @IDarray         = ();
+
my @IDarray;
my %AdressHash = ();
+
my %AdressHash;
  
if( $options{"help"} ) {
+
if( $options{help} ) {
     &usage("Parameter: --help");
+
     usage("Parameter: --help");
 
}
 
}
if( defined $options{"infile"} ) {
+
if( defined $options{infile} ) {
   &load_textfile($options{"infile"},\@FileArray);
+
   load_textfile($options{infile},\@FileArray);
   print "\n Input file:  ".$options{"infile"}." loaded\n";
+
   print "\n Input file:  $options{infile} loaded\n";
 
} else {
 
} else {
&usage("ERROR: You must define an -infile=myfilename.vcf");
+
usage("ERROR: You must define an -infile=myfilename.vcf");
};
+
}
if( defined $options{"outfile"} ) {
+
if( defined $options{outfile} ) {
   print "\n Output file:  ".$options{"outfile"}." \n";
+
   print "\n Output file:  $options{outfile} \n";
 
} else {
 
} else {
&usage("ERROR: You must define an -outfile=myoutfilename.csv");
+
usage("ERROR: You must define an -outfile=myoutfilename.$outformat");
};
+
}
 
#######################################################################
 
#######################################################################
 
print "\nStart parsing file....";
 
print "\nStart parsing file....";
Line 65: Line 97:
 
foreach my $line (@FileArray) {
 
foreach my $line (@FileArray) {
 
   if  ( $line  =~ /^BEGIN\:VCARD/ ) {
 
   if  ( $line  =~ /^BEGIN\:VCARD/ ) {
       $count = $count + 1;
+
       $count++;
 
       print "\nParse record $count " ;
 
       print "\nParse record $count " ;
 
       %AdressHash = ();
 
       %AdressHash = ();
Line 72: Line 104:
 
   } elsif ( $line =~ /^END\:VCARD/ ) {
 
   } elsif ( $line =~ /^END\:VCARD/ ) {
 
       print "\ndone";
 
       print "\ndone";
      #&show_hash(\%AdressHash,"Record $count");
 
 
       my $vID = $AdressHash{LastName}." ".$AdressHash{FirstName};
 
       my $vID = $AdressHash{LastName}." ".$AdressHash{FirstName};
       $OutFileHash{$vID} = &create_string_from_hash(\%AdressHash);
+
       $OutFileHash{$vID} = create_string_from_hash(\%AdressHash,$count);
 +
      $OutNameHash{$vID} = create_linklist_from_hash(\%AdressHash,$count);
 
   } else {
 
   } else {
 
     ## EMAIL;INTERNET;WORK:themail@example.net
 
     ## EMAIL;INTERNET;WORK:themail@example.net
     @SplitArray = split(/\:/,$line);
+
     @SplitArray = split(/:/,$line);
 
     ## SplitArray[0]= EMAIL;INTERNET;WORK
 
     ## SplitArray[0]= EMAIL;INTERNET;WORK
     ## SplitArray[0]= themail@example.net
+
     ## SplitArray[1]= themail@example.net
 
     ## Convert to HTML
 
     ## Convert to HTML
 
     @SplitArrayID = split(/;/,$SplitArray[0]);
 
     @SplitArrayID = split(/;/,$SplitArray[0]);
Line 85: Line 117:
 
     ## SplitArray2[1]= INTERNET
 
     ## SplitArray2[1]= INTERNET
 
     ## SplitArray2[2]= WORKFile
 
     ## SplitArray2[2]= WORKFile
 +
    ## The Values could also be separated by ";" so split them into array of values
 
     @SplitArrayValue = split(/;/,$SplitArray[1]);
 
     @SplitArrayValue = split(/;/,$SplitArray[1]);
     $SplitArray[1] = &modify_fileline($SplitArray[1]);
+
     $SplitArray[1] = modify_fileline($SplitArray[1]);
    my $i = 0;
+
 
     foreach (@SplitArrayValue) {
 
     foreach (@SplitArrayValue) {
       $SplitArrayValue[$i] = &modify_fileline($SplitArrayValue[$i]);
+
       $_ = modify_fileline($_);
      $i+=1;
+
     }
     };
+
     append_ID(\@IDarray,$SplitArray[0]);
    ## The Values could also be separated by ";"
+
     &append_ID(\@IDarray,$SplitArray[0]);
+
 
     print "\n$count: $line";
 
     print "\n$count: $line";
 
   ##################################################
 
   ##################################################
 
   # Now we decide what to do with the vCard Content  
 
   # Now we decide what to do with the vCard Content  
   # everything is stored in the hash AdressHash
+
   # everything is stored in the hash AdressHash e.g.
 +
  # $AdressHash{LastName}  = "Miller";
 +
  # $AdressHash{FirstName} = "Paul";
 
   ##################################################
 
   ##################################################
   # e-Mail
+
   #### e-Mail
 
     if ( $SplitArray[0] =~ /^EMAIL/ ) {
 
     if ( $SplitArray[0] =~ /^EMAIL/ ) {
 
         $AdressHash{EMail} .= $SplitArray[1];
 
         $AdressHash{EMail} .= $SplitArray[1];
     } elsif ($SplitArray[1] =~ /([a-zA_Z0-9\_\-\.]+@[a-zA_Z0-9\_\-\.]+)/) {
+
     } elsif ($SplitArray[1] =~ /([\w\-\.]+\@[\w\-\.]+)/) {
 
         $AdressHash{EMail} .= $1;
 
         $AdressHash{EMail} .= $1;
         $SplitArray[1] =~ s/[a-zA_Z0-9\_\-\.]+@[a-zA_Z0-9\_\-\.]+//g;
+
         $SplitArray[1] =~ s/[\w\-\.]+\@[\w\-\.]+//g;
     };
+
     }
   # Name
+
   #### LastName FirstName
     if ( $SplitArray[0] =~ /^N[;]*/ ) {
+
     if ( $SplitArray[0] =~ /^N;*/ ) {
 
$AdressHash{LastName}  = $SplitArrayValue[0];
 
$AdressHash{LastName}  = $SplitArrayValue[0];
 
$AdressHash{FirstName} = $SplitArrayValue[1];
 
$AdressHash{FirstName} = $SplitArrayValue[1];
     };
+
     }
   # Adress
+
   #### Adress
     if ( $SplitArray[0] =~ /^ADR[;]*/ ) {
+
     if ( $SplitArray[0] =~ /^ADR;*/ ) {
        $SplitArray[1] =~ s/\\n/$newline/g;
+
  $AdressHash{Adress}    = convert_adress($SplitArray[1]);
$SplitArray[1] =~ s/\\,/,/g;
+
     }
        $SplitArray[1] =~ s/\\//g;
+
   #### Fax and Phone
        $SplitArray[1] =~ s/\/$//g;
+
$SplitArray[1] =~ s/ $//g;
+
$SplitArray[1] =~ s/,$//g;
+
$AdressHash{Adress}    = $SplitArray[1];
+
     };
+
   # Fax and Phone
+
 
     if ( $SplitArray[0] =~ /FAX/ ) {
 
     if ( $SplitArray[0] =~ /FAX/ ) {
 
         $AdressHash{Fax} .= $SplitArrayValue[0];
 
         $AdressHash{Fax} .= $SplitArrayValue[0];
Line 133: Line 159:
 
         }
 
         }
 
     }
 
     }
   }; ## main if-elsif-else
+
    ###############################################################
}; ## end foreach  
+
   } ## main if-elsif-else
 +
} ## end foreach  
 
@OutFileArray = ("<html>\n<head>\n","<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\">
 
@OutFileArray = ("<html>\n<head>\n","<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\">
 
","\n<title>Contacts</title>\n</head>\n<body>","$table_begin");
 
","\n<title>Contacts</title>\n</head>\n<body>","$table_begin");
my @OutFileIDs = keys(%OutFileHash);
+
my @OutFileIDs = sort keys(%OutFileHash);
foreach my $vID (sort @OutFileIDs) {
+
push(@OutFileArray,@OutNameHash{@OutFileIDs});
    push(@OutFileArray,$OutFileHash{$vID});
+
push(@OutFileArray,"$table_end");
};
+
push(@OutFileArray,"<P></P>");
 +
push(@OutFileArray,"$table_begin");
 +
push(@OutFileArray,@OutFileHash{@OutFileIDs});
 
push(@OutFileArray,"$table_end\n</body></html>");
 
push(@OutFileArray,"$table_end\n</body></html>");
&save_textfile($options{"outfile"},\@OutFileArray);
+
save_textfile($options{outfile},\@OutFileArray);
print "\n Output file:  ".$options{"outfile"}." saved\n";
+
### print all tags used in the vCard file
print "\nUsed ID in vCard file ".$options{infile};
+
print "\n Output file:  $options{outfile} saved\n";
#@IDarray = ("ID1","ID2","ID3");
+
print "\nUsed ID in vCard file $options{infile}";
print "\n".&create_array_line("",\@IDarray," ");
+
print "\n".create_array_line("",\@IDarray," ");
 
print "\n";
 
print "\n";
###########################################################################################
+
 
 +
#### END of Script
 +
#######################################################################
 
   
 
   
 
#######################################################################
 
#######################################################################
# show the content of an array as one line splitted in table elements
+
# create a string from the content of the VCard hash record
 +
# this sub creates the HTML output of one VCard
 +
# modify this to create a SQL command or CSV from the hash
 
#######################################################################
 
#######################################################################
 +
#
 
sub create_string_from_hash {
 
sub create_string_from_hash {
my $ppHash       =  @_[0]; ## p=Parameter,p=Pointer
+
my ($ppHash,$pCount)  =  @_; ## p=Parameter,p=Pointer
 
         my $vReturnString = $row_head_begin;
 
         my $vReturnString = $row_head_begin;
         if ($ppHash->{Tel} eq "") {
+
         $vReturnString .= "$col_begin<A NAME=\"N$pCount\"><A HREF=\"#L$pCount\">$ppHash->{LastName}".
            $ppHash->{Tel} = $ppHash->{Mobil};
+
                      ", $ppHash->{FirstName}</A>$col_end";
        };
+
        if ($ppHash->{Tel} eq "") {
+
          $ppHash->{Tel} = "W: ".$ppHash->{TelWork};
+
        };
+
  $vReturnString .= $col_begin.$ppHash->{LastName}.", ".$ppHash->{FirstName}.$col_end;
+
        $vReturnString .= $col_begin."W: ".$ppHash->{TelWork}.$col_end;  
+
 
         $vReturnString .= $row_head_end;
 
         $vReturnString .= $row_head_end;
         $vReturnString .= $row_begin;
+
         if ($ppHash->{Tel} ne "") {
        $ppHash->{Tel} =~ s/[^ 0-9\-\/ W:]//g;
+
          $vReturnString .= $row_begin;
         $vReturnString .= $col_begin."T: ".$ppHash->{Tel}.$col_end;
+
          $vReturnString .= $col_begin."Tel: ".$ppHash->{Tel}.$col_end;
         if ($ppHash->{Fax} eq "") {
+
          $vReturnString .= $row_end;
            $vReturnString .= $col_begin."eM: ".$ppHash->{EMail}.$col_end;  
+
         }
         } else {  
+
        if ($ppHash->{TelWork} ne "") {
            $vReturnString .= $col_begin."Fax: ".$ppHash->{TelWork}.$col_end;
+
          $vReturnString .= $row_begin;
         };
+
          $vReturnString .= $col_begin."Work: ".$ppHash->{TelWork}.$col_end;  
         $vReturnString .= $row_end;
+
          $vReturnString .= $row_end;
        $vReturnString .= $row_begin;
+
        }
        $vReturnString .= $col_begin."Mob: ".$ppHash->{Mobil}.$col_end;  
+
         if ($ppHash->{Mobil} ne "") {
         $vReturnString .= $col_begin."Adr: ".$ppHash->{Adress}.$col_end;  
+
      $vReturnString .= $row_begin;
        $vReturnString .= $row_end;
+
      $vReturnString .= $col_begin."Mobile: ".$ppHash->{Mobil}.$col_end;
 +
          $vReturnString .= $row_end;
 +
         }
 +
        if ($ppHash->{Fax} ne "") {
 +
          $vReturnString .= $row_begin;
 +
          $vReturnString .= $col_begin."Fax: ".$ppHash->{TelWork}.$col_end;
 +
         }
 +
         if ($ppHash->{EMail} ne "") {
 +
          $vReturnString .= $row_begin;
 +
          $vReturnString .= $col_begin."e-Mail: ".$ppHash->{EMail}.$col_end;
 +
          $vReturnString .= $row_end;
 +
         }
 +
        if ($ppHash->{Adress} ne "") {
 +
          $vReturnString .= $row_begin;
 +
          $vReturnString .= $col_begin."Adr: ".$ppHash->{Adress}.$col_end;  
 +
          $vReturnString .= $row_end;
 +
        }
 
         return $vReturnString;
 
         return $vReturnString;
 
}
 
}
   
+
 
 +
#######################################################################
 +
# show the content of a hash as one line in a table
 +
#######################################################################
 +
sub create_linklist_from_hash {
 +
my ($ppHash,$pCount) =  @_; ## p=Parameter,p=Pointer
 +
        my $vReturnString = $row_head_begin;
 +
        $vReturnString .= $col_begin."<A NAME=\"L$pCount\"><A HREF=\"#N$pCount\">".
 +
        $ppHash->{LastName}.", ".$ppHash->{FirstName}."</A>".$col_end;
 +
        $vReturnString .= $row_head_end;
 +
        return $vReturnString;
 +
}
 +
 
 
################################################
 
################################################
 
## usage is displayed, if no parameter inserted
 
## usage is displayed, if no parameter inserted
Line 189: Line 245:
 
if (defined $_[0]) {
 
if (defined $_[0]) {
 
$pOutput = $_[0];
 
$pOutput = $_[0];
};
+
}
 
     select(STDERR);
 
     select(STDERR);
 
     print <<EOUsage;
 
     print <<EOUsage;
Line 209: Line 265:
  
 
##############################################################################
 
##############################################################################
# void* load_textfile ($dateiname, \@zeilen_rueckgabewert)
+
# void* load_textfile ($pFilename, \@Pointer_to_Array_of_Strings)
#
+
# Der Inhalt von $dateiname wird zeilenweise nach @{\@zeilen_rueckgabewert}
+
# gepumpt. Scheint dazu gedacht zu sein, Datenbankinhalte in den Speicher
+
# zu holen; wird kaum verwendet.
+
 
##############################################################################
 
##############################################################################
 
#
 
#
 
sub load_textfile {
 
sub load_textfile {
my $pFilename =  @_[0];
+
my ($pFilename, $ppLines) =  @_;  
my $ppLines   =  @_[1];  
+
 
 
 
if(!-e $pFilename) {
 
if(!-e $pFilename) {
Line 224: Line 275:
 
exit(1);
 
exit(1);
 
} else {
 
} else {
open (LOADTEXTFILE, "<$pFilename") or print $!;
+
open (LOADTEXTFILE, '<', $pFilename) or print $!;
 
if($flocking) {flock LOADTEXTFILE, 2;}
 
if($flocking) {flock LOADTEXTFILE, 2;}
@{$ppLines} = <LOADTEXTFILE>;
+
@$ppLines = <LOADTEXTFILE>;
 
if($flocking) {flock LOADTEXTFILE, 8;}
 
if($flocking) {flock LOADTEXTFILE, 8;}
 
  close LOADTEXTFILE;
 
  close LOADTEXTFILE;
foreach my $fileline(@{$ppLines}) {
+
}
chop($fileline);
+
chomp($fileline);
+
} }  
+
 
}
 
}
  
 
##############################################################################
 
##############################################################################
# void* save_textfile ($dateiname, \@dateiinhalt);
+
# void* save_textfile ($pFilename, \@Pointer_to_Array_of_Strings)
#
+
# Schreibt die Daten aus @{\@dateiinhalt} nach $dateiname;
+
 
##############################################################################
 
##############################################################################
 
#
 
#
 
sub save_textfile {
 
sub save_textfile {
my $pFilename = $_[0];
+
my ($pFilename, $ppLines) = @_;  
my $ppLines   = $_[1];  
+
 
 
 
if ($pFilename eq "") {
 
if ($pFilename eq "") {
Line 249: Line 294:
 
exit(1);
 
exit(1);
 
}
 
}
open (SAVETEXTFILE, ">$pFilename") or print $!;
+
open (SAVETEXTFILE, '>', $pFilename) or print $!;
 
if($flocking) {flock SAVETEXTFILE, 2;}
 
if($flocking) {flock SAVETEXTFILE, 2;}
foreach my $fileline (@{$ppLines}) {
+
foreach my $fileline (@$ppLines) {
 
print SAVETEXTFILE "$fileline\n";
 
print SAVETEXTFILE "$fileline\n";
};
+
}
 
if($flocking) {flock SAVETEXTFILE, 8;}
 
if($flocking) {flock SAVETEXTFILE, 8;}
 
  close SAVETEXTFILE;
 
  close SAVETEXTFILE;
 
}
 
}
  
 +
#################################################
 +
# convert the content of addresses in the vCard record
 +
#################################################
  
#######################################################################
+
sub convert_adress {
# show the content of an array as one line splitted in table elements
+
      my $pAddress = shift;
#######################################################################
+
      $pAddress =~ s/\\n/$newline/g;
sub show_hash {
+
      $pAddress =~ s/\\,/,/g;
my $ppHash        = @_[0]; ## p=Parameter,p=Pointer
+
      $pAddress =~ s/\\//g;
my $pTitle        = @_[1]; ## p=Parameter
+
      $pAddress =~ s/\/$//g;  
print "\nShow Hash:  $pTitle $table_begin";
+
      $pAddress =~ s/ $//g;  
        &show_hash_header($ppHash);
+
      $pAddress =~ s/,$//g;
        &show_hash_line($ppHash);
+
      return $pAddress;  
print "$table_end\n";
+
 
}
 
}
 
sub show_hash_header {
 
my $ppHash        =  @_[0]; ## p=Parameter,p=Pointer
 
my @lvArrayKeys  = keys(%{$ppHash});
 
print $row_head_begin;
 
foreach my $item(@lvArrayKeys) {
 
print "$col_begin$item$col_end";
 
};
 
print $row_head_end;
 
}
 
 
 
sub show_hash_line {
 
my $ppHash        =  @_[0]; ## p=Parameter,p=Pointer
 
my @lvArrayValues = values(%{$ppHash});
 
print $row_begin;
 
foreach my $item(@lvArrayValues) {
 
print "$col_begin$item$col_end";
 
};
 
print $row_end;
 
}
 
#######################################################################
 
#### show the content of an array as a table with one column and
 
#### as many lines as the length of the array
 
#######################################################################
 
sub show_array {
 
my $ppArray      =  @_[0]; ## p=Parameter,p=Pointer
 
my $pTitle        =  @_[1]; ## p=Parameter
 
print "Show Array $pTitle $table_begin";
 
        print $row_begin;
 
foreach my $item(@{$ppArray}) {
 
print "$col_begin$item$col_end";
 
};
 
print $row_end;
 
print $table_end;
 
 
}
 
#######################################################################
 
#### show the content of an array as a table with one column and
 
#### as many lines as the length of the array
 
#######################################################################
 
sub create_array_line {
 
my $pPreSeparator  =  $_[0]; ## p=Parameter,p=Pointer
 
my $ppArray        =  $_[1]; ## p=Parameter,p=Pointer
 
my $pPostSeparator =  $_[2]; ## p=Parameter,p=Pointer
 
my $ReturnString = "";
 
foreach my $item(@{$ppArray}) {
 
$ReturnString .= "$pPreSeparator$item$pPostSeparator";
 
};
 
        return $ReturnString;
 
}
 
 
  
 
#################################################
 
#################################################
Line 328: Line 323:
  
 
sub modify_fileline {
 
sub modify_fileline {
my $pFileLine = $_[0];
+
my $pFileLine = shift;
 
my $BakFileLine = $pFileLine;
 
my $BakFileLine = $pFileLine;
 
$pFileLine =~ s/^[ ;]+//g;
 
$pFileLine =~ s/^[ ;]+//g;
Line 346: Line 341:
 
###########################################
 
###########################################
 
if ($BakFileLine ne $pFileLine) {
 
if ($BakFileLine ne $pFileLine) {
    print "\nCHANGES: ".$pFileLine."\n"
+
    print "\nCHANGES: $pFileLine\n"
};
+
}
 
return $pFileLine;
 
return $pFileLine;
 
}
 
}
Line 355: Line 350:
 
#######################################################################
 
#######################################################################
 
sub append_ID {
 
sub append_ID {
     my $ppArray =  $_[0]; ## p=Parameter,p=Pointer
+
     my $ppArray =  shift; ## p=Parameter,p=Pointer
     my $pNewID  =  $_[1];
+
     my $pNewID  =  shift;
    my $found = 0;
+
     #$pNewID =~ s/[^a-z\d ]//ig;  
     #$pNewID =~ s/[^A-Za-z0-9 ]//g;  
+
     if (!grep {$pNewID eq $_} @$ppArray) {
     foreach my $oldID (@{$ppArray}) {
+
       push(@$ppArray,$pNewID);
        if ($pNewID eq $oldID) {
+
            $found = 1;
+
        }
+
    };
+
    if ($found == 0) {
+
       push(@{$ppArray},$pNewID);
+
 
     }  
 
     }  
 
}
 
}
Line 371: Line 360:
  
 
</pre>
 
</pre>
 +
 +
[[Category:PIM]]

Latest revision as of 07:07, 4 August 2010

Tiis script comverts a VCard vcf-File from the SD card to an HTML-File visible with Midori.

input file; /media/card/pim/contacts.vcf
outputfile: /home/root/.evolution/vCards.html
  • the output file consists of a list of names in alphabetical oder without any contact details.
  • you can click on all the names in the list and your will be linked to the contact details
  • when you view on the contact details you can click on the name again and you are back in the list without details.

The script is very robust against parsing errors in the

Change the filenames according to your location of VCF-files. The input file and the outputfile are defined in the first few lines of script mentioned below. The script converts the VCF into to a hash and with that you can export to any other file format (SQL command for importing in an sqllite database - this not implemented yet).

Contents

[edit] Icon for the Converter

Create an icon by copying one midori.desktop to convertvcf.desktop and change the settings with nano editor. The Exec command is perl /home/root/bin/vcard2om.pl, if you store the script in your /home/root/bin/ directory (an other directory is possible too).

 [Desktop Entry]
 Version=1.0
 Type=Application
 Name=convVCF
 Comment=Convert VCF VCard file into HTML
 Categories=GTK;Network;
 MimeType=text/html;text/xml;application/xhtml+xml;application/xml;
 Exec=perl /home/root/bin/vcard2html.pl 
 Icon=tools
 Terminal=false
 StartupNotify=true

Copy this to convertvcf2html.desktop and save to

 /usr/share/applications

(SHR, OM, ...)

[edit] Install Perl

Install perl before with:

 opkg install perl

[edit] Start the Script

Start the script with perl:

  perl /home/root/bin/vcard2om.pl

[edit] Syncing VCF files with unison

You can sync the vcf (VCard) files from your desktop computer with Unison.

[edit] Copy the Script in Edit Mode of this Page

If you want to copy the following script, go to edit of the page and copy the code of the script inbetween the PRE-Tags, because some characters are not shown as they should in the preview of this page. And now the script just for an overview:

#!/usr/bin/perl

my %options;
$options{infile}  = "/media/card/pim/contacts.vcf";
$options{outfile} = "/home/root/.evolution/vCards.html";
my $outformat = "html";
#-----------------------------------------------------------------
my $table_begin = "<table border='1'>";
my $table_end   = "</table>";
my $row_head_begin = "<TR bgcolor=\"#C0C0C0\">";
my $row_head_end   = "</TR>\n";
my $row_begin = "<tr>";
my $row_end   = "</tr>";
my $col_begin = "<td><span style=\"font-size:0.3em\">";
my $col_end   = "</span></td>";
my $newline   = "<br>";
#-----------------------------------------------------------------

my $flocking = 1;
my @FileArray;
my @OutFileArray;
my %OutFileHash;
my %OutNameHash;

my $OUTFORMAT = uc($outformat);

my @SplitArray;
my @SplitArrayID;
my @SplitArrayValue; 
my @IDarray;
my %AdressHash;

if( $options{help} ) {
    usage("Parameter: --help");
}
if( defined $options{infile} ) {
  load_textfile($options{infile},\@FileArray);
  print "\n Input file:  $options{infile} loaded\n";
} else {
	usage("ERROR: You must define an -infile=myfilename.vcf");
}
if( defined $options{outfile} ) {
  print "\n Output file:  $options{outfile} \n";
} else {
	usage("ERROR: You must define an -outfile=myoutfilename.$outformat");
}
#######################################################################
print "\nStart parsing file....";
print "\n----------------------";

print "\n";
my $newID = "";
my $count = 0;
foreach my $line (@FileArray) {
  if  ( $line  =~ /^BEGIN\:VCARD/ ) {
      $count++;
      print "\nParse record $count " ;
      %AdressHash = ();
  } elsif ($line =~ /^VERSION\:/) {
      print "in $line";
  } elsif ( $line =~ /^END\:VCARD/ ) {
      print "\ndone";
      my $vID = $AdressHash{LastName}." ".$AdressHash{FirstName};
      $OutFileHash{$vID} = create_string_from_hash(\%AdressHash,$count);
      $OutNameHash{$vID} = create_linklist_from_hash(\%AdressHash,$count);
  } else {
    ## EMAIL;INTERNET;WORK:themail@example.net
    @SplitArray = split(/:/,$line);
    ## SplitArray[0]= EMAIL;INTERNET;WORK
    ## SplitArray[1]= themail@example.net
    ## Convert to HTML
    @SplitArrayID = split(/;/,$SplitArray[0]);
    ## SplitArray2[0]= EMAIL
    ## SplitArray2[1]= INTERNET
    ## SplitArray2[2]= WORKFile
    ## The Values could also be separated by ";" so split them into array of values
    @SplitArrayValue = split(/;/,$SplitArray[1]);
    $SplitArray[1] = modify_fileline($SplitArray[1]);
    foreach (@SplitArrayValue) {
       $_ = modify_fileline($_);
    }
    append_ID(\@IDarray,$SplitArray[0]);
    print "\n$count: $line";
   ##################################################
   # Now we decide what to do with the vCard Content 
   # everything is stored in the hash AdressHash e.g.
   #	$AdressHash{LastName}  = "Miller";
   #	$AdressHash{FirstName} = "Paul";
   ##################################################
   #### e-Mail
    if ( $SplitArray[0] =~ /^EMAIL/ ) {
        $AdressHash{EMail} .= $SplitArray[1];
    } elsif ($SplitArray[1] =~ /([\w\-\.]+\@[\w\-\.]+)/) {
        $AdressHash{EMail} .= $1;
        $SplitArray[1] =~ s/[\w\-\.]+\@[\w\-\.]+//g;
    }
   #### LastName FirstName
    if ( $SplitArray[0] =~ /^N;*/ ) {
	$AdressHash{LastName}  = $SplitArrayValue[0];
	$AdressHash{FirstName} = $SplitArrayValue[1];
    }
   #### Adress
    if ( $SplitArray[0] =~ /^ADR;*/ ) {
  	$AdressHash{Adress}    = convert_adress($SplitArray[1]);
    }
   #### Fax and Phone
    if ( $SplitArray[0] =~ /FAX/ ) {
        $AdressHash{Fax} .= $SplitArrayValue[0];
    } elsif ($SplitArray[0] =~ /TEL;WORK/) {
        $AdressHash{TelWork} .= $SplitArrayValue[0];
    } elsif ( $SplitArray[0] =~ /TEL/ )  {
        if ($SplitArrayValue[0] =~ /^01/) {
             $AdressHash{Mobil} .= $SplitArrayValue[0];
        } else {
	     $AdressHash{Tel} .= $SplitArrayValue[0];
        }
    }
    ###############################################################
  } ## main if-elsif-else
} ## end foreach 
@OutFileArray = ("<html>\n<head>\n","<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\">
","\n<title>Contacts</title>\n</head>\n<body>","$table_begin");
my @OutFileIDs = sort keys(%OutFileHash);
push(@OutFileArray,@OutNameHash{@OutFileIDs});
push(@OutFileArray,"$table_end");
push(@OutFileArray,"<P></P>");
push(@OutFileArray,"$table_begin");
push(@OutFileArray,@OutFileHash{@OutFileIDs});
push(@OutFileArray,"$table_end\n</body></html>");
save_textfile($options{outfile},\@OutFileArray);
### print all tags used in the vCard file
print "\n Output file:  $options{outfile} saved\n";
print "\nUsed ID in vCard file $options{infile}";
print "\n".create_array_line("",\@IDarray," ");
print "\n";

#### END of Script
#######################################################################
 
#######################################################################
# create a string from the content of the VCard hash record
# this sub creates the HTML output of one VCard
# modify this to create a SQL command or CSV from the hash
#######################################################################
#
sub create_string_from_hash {
	my ($ppHash,$pCount)  =  @_; ## p=Parameter,p=Pointer
        my $vReturnString = $row_head_begin;
        $vReturnString .= "$col_begin<A NAME=\"N$pCount\"><A HREF=\"#L$pCount\">$ppHash->{LastName}".
     	                  ", $ppHash->{FirstName}</A>$col_end";
        $vReturnString .= $row_head_end;
        if ($ppHash->{Tel} ne "") {
           $vReturnString .= $row_begin;
           $vReturnString .= $col_begin."Tel: ".$ppHash->{Tel}.$col_end; 
           $vReturnString .= $row_end;
        }
        if ($ppHash->{TelWork} ne "") {
           $vReturnString .= $row_begin;
           $vReturnString .= $col_begin."Work: ".$ppHash->{TelWork}.$col_end; 
           $vReturnString .= $row_end;
        }
        if ($ppHash->{Mobil} ne "") {
	       $vReturnString .= $row_begin;
    	   $vReturnString .= $col_begin."Mobile: ".$ppHash->{Mobil}.$col_end; 
           $vReturnString .= $row_end;
        }
        if ($ppHash->{Fax} ne "") {
           $vReturnString .= $row_begin;
           $vReturnString .= $col_begin."Fax: ".$ppHash->{TelWork}.$col_end;
        }
        if ($ppHash->{EMail} ne "") {
           $vReturnString .= $row_begin;
           $vReturnString .= $col_begin."e-Mail: ".$ppHash->{EMail}.$col_end; 
           $vReturnString .= $row_end;
        }
        if ($ppHash->{Adress} ne "") {
           $vReturnString .= $row_begin;
           $vReturnString .= $col_begin."Adr: ".$ppHash->{Adress}.$col_end; 
           $vReturnString .= $row_end;
        }
        return $vReturnString;
}

#######################################################################
# show the content of a hash as one line in a table
#######################################################################
sub create_linklist_from_hash {
	my ($ppHash,$pCount)  =  @_; ## p=Parameter,p=Pointer
        my $vReturnString = $row_head_begin;
        $vReturnString .= $col_begin."<A NAME=\"L$pCount\"><A HREF=\"#N$pCount\">".
        		$ppHash->{LastName}.", ".$ppHash->{FirstName}."</A>".$col_end;
        $vReturnString .= $row_head_end;
        return $vReturnString;
}
  
################################################
## usage is displayed, if no parameter inserted
################################################

sub usage {
	my $pOutput = "";
	if (defined $_[0]) {
		$pOutput = $_[0];
	}
    select(STDERR);
    print <<EOUsage;
    
$0 [options]
  Options:

    --help                    DFileisplay this help message
    --infile  <filename>      File that will be parsed in vCard format
    --outfile <filename>      File that will be generated in $OUTFORMAT format
    
 
  $pOutput
EOUsage

    exit(1);

}

##############################################################################
# void* load_textfile ($pFilename, \@Pointer_to_Array_of_Strings)
##############################################################################
#
sub load_textfile {
	my ($pFilename, $ppLines) =  @_; 
	
	if(!-e $pFilename) {
		print "\n ERROR\n$pFilename does not exist.\n";
		exit(1);
	} else {
		open (LOADTEXTFILE, '<', $pFilename) or print $!;
			if($flocking) {flock LOADTEXTFILE, 2;}
			@$ppLines = <LOADTEXTFILE>;
			if($flocking) {flock LOADTEXTFILE, 8;}
 		close LOADTEXTFILE;
	}
}

##############################################################################
# void* save_textfile ($pFilename, \@Pointer_to_Array_of_Strings)
##############################################################################
#
sub save_textfile {
	my ($pFilename, $ppLines) = @_; 
	
	if ($pFilename eq "") {
		print "\n ERROR\nNo Filename specified in parameter (save_textfile():103.\n";
		exit(1);
	}
	open (SAVETEXTFILE, '>', $pFilename) or print $!;
		if($flocking) {flock SAVETEXTFILE, 2;}
		foreach my $fileline (@$ppLines) {
			print SAVETEXTFILE "$fileline\n";
		}
		if($flocking) {flock SAVETEXTFILE, 8;}
 	close SAVETEXTFILE;
}

#################################################
# convert the content of addresses in the vCard record
#################################################

sub convert_adress {
      my $pAddress = shift;
      $pAddress =~ s/\\n/$newline/g;
      $pAddress =~ s/\\,/,/g;
      $pAddress =~ s/\\//g;
      $pAddress =~ s/\/$//g; 
      $pAddress =~ s/ $//g; 
      $pAddress =~ s/,$//g;
      return $pAddress; 
}

#################################################
# Modify Fileline and return modified content	#
#################################################

sub modify_fileline {
	my $pFileLine = shift;
	my $BakFileLine = $pFileLine;
	$pFileLine =~ s/^[ ;]+//g;
	$pFileLine =~ s/[;]+/, /g;
	$pFileLine =~ s/\\,$/,/g;
	$pFileLine =~ s/[ ,]+$//g;
	$pFileLine =~ s/[\\][n]$/$newline/g;
	#### CHANGE FILE ##########################
	$pFileLine =~ s/ä/ä/g;
	$pFileLine =~ s/ö/ö/g;
	$pFileLine =~ s/ü/ü/g;
	$pFileLine =~ s/Ä/Ä/g;
	$pFileLine =~ s/Ö/Ö/g;
	$pFileLine =~ s/Ü/Ü/g;
	$pFileLine =~ s/ß/ß/g;
	$pFileLine =~ s/´/'/g;
	###########################################
	if ($BakFileLine ne $pFileLine) {
	    print "\nCHANGES: $pFileLine\n"
	}
	return $pFileLine;
}

#######################################################################
#### append an ID to an array if the ID is not in the array
#######################################################################
sub append_ID {
    my $ppArray =  shift; ## p=Parameter,p=Pointer
    my $pNewID  =  shift;
    #$pNewID =~ s/[^a-z\d ]//ig; 
    if (!grep {$pNewID eq $_} @$ppArray) {
       push(@$ppArray,$pNewID);
     } 
}
#########################################################################

Personal tools

Tiis script comverts a VCard vcf-File from the SD card to an HTML-File visible with Midori.

input file; /media/card/pim/contacts.vcf
outputfile: /home/root/.evolution/vCards.html

Change according to your VCF-files. The script converts the VCF into to a hash and with that you can export to any other file format (SQL command for importing in an sqllite database).

Icon for the Converter

Create an icon by copying one midori.desktop to convertvcf.desktop and change the settings with nano editor. The Exec command is perl /home/root/bin/vcard2om.pl, if you store the script in your /home/root/bin/ directory (an other directory is possible too).

Install Perl

Install perl before with:

 opkg install perl

Copy the Script in Edit Mode of this Page

If you want to copy the following script, go to edit of the page and copy the code of the script inbetween the PRE-Tags, because some characters are not shown as they should in the preview of this page. And now the script just for an overview:

#!/usr/bin/perl

my %options = ();
$options{infile}  = "/media/card/pim/contacts.vcf";
$options{outfile} = "/home/root/.evolution/vCards.html";
my $outformat = "html";
#-----------------------------------------------------------------
my $table_begin = "<table border='1'>";
my $table_end   = "</table>";
my $row_head_begin = "<TR bgcolor=\"#C0C0C0\">";
my $row_head_end   = "</TR>\n";
my $row_begin = "<tr>";
my $row_end   = "</tr>";
my $col_begin = "<td><span style=\"font-size:0.3em\">";
my $col_end   = "</span></td>";
my $newline   = "<br>";
#-----------------------------------------------------------------

my $flocking = 1;
my @FileArray = ();
my @OutFileArray = ();
my %OutFileHash  = ();
my $OUTFORMAT = uc($outformat);

my @SplitArray      = ();
my @SplitArrayID    = ();
my @SplitArrayValue = (); 
my @IDarray         = ();
my %AdressHash  = ();

if( $options{"help"} ) {
    &usage("Parameter: --help");
}
if( defined $options{"infile"} ) {
  &load_textfile($options{"infile"},\@FileArray);
  print "\n Input file:  ".$options{"infile"}." loaded\n";
} else {
	&usage("ERROR: You must define an -infile=myfilename.vcf");
};
if( defined $options{"outfile"} ) {
  print "\n Output file:  ".$options{"outfile"}." \n";
} else {
	&usage("ERROR: You must define an -outfile=myoutfilename.csv");
};
#######################################################################
print "\nStart parsing file....";
print "\n----------------------";

print "\n";
my $newID = "";
my $count = 0;
foreach my $line (@FileArray) {
  if  ( $line  =~ /^BEGIN\:VCARD/ ) {
      $count = $count + 1;
      print "\nParse record $count " ;
      %AdressHash = ();
  } elsif ($line =~ /^VERSION\:/) {
      print "in $line";
  } elsif ( $line =~ /^END\:VCARD/ ) {
      print "\ndone";
      #&show_hash(\%AdressHash,"Record $count");
      my $vID = $AdressHash{LastName}." ".$AdressHash{FirstName};
      $OutFileHash{$vID} = &create_string_from_hash(\%AdressHash);
  } else {
    ## EMAIL;INTERNET;WORK:themail@example.net
    @SplitArray = split(/\:/,$line);
    ## SplitArray[0]= EMAIL;INTERNET;WORK
    ## SplitArray[0]= themail@example.net
    ## Convert to HTML
    @SplitArrayID = split(/;/,$SplitArray[0]);
    ## SplitArray2[0]= EMAIL
    ## SplitArray2[1]= INTERNET
    ## SplitArray2[2]= WORKFile
    @SplitArrayValue = split(/;/,$SplitArray[1]);
    $SplitArray[1] = &modify_fileline($SplitArray[1]);
    my $i = 0;
    foreach (@SplitArrayValue) {
       $SplitArrayValue[$i] = &modify_fileline($SplitArrayValue[$i]);
       $i+=1;
    };
    ## The Values could also be separated by ";"
    &append_ID(\@IDarray,$SplitArray[0]);
    print "\n$count: $line";
   ##################################################
   # Now we decide what to do with the vCard Content 
   # everything is stored in the hash AdressHash
   ##################################################
   # e-Mail
    if ( $SplitArray[0] =~ /^EMAIL/ ) {
        $AdressHash{EMail} .= $SplitArray[1];
    } elsif ($SplitArray[1] =~ /([a-zA_Z0-9\_\-\.]+@[a-zA_Z0-9\_\-\.]+)/) {
        $AdressHash{EMail} .= $1;
        $SplitArray[1] =~ s/[a-zA_Z0-9\_\-\.]+@[a-zA_Z0-9\_\-\.]+//g;
    };
   # Name
    if ( $SplitArray[0] =~ /^N[;]*/ ) {
	$AdressHash{LastName}  = $SplitArrayValue[0];
	$AdressHash{FirstName} = $SplitArrayValue[1];
    };
   # Adress
    if ( $SplitArray[0] =~ /^ADR[;]*/ ) {
        $SplitArray[1] =~ s/\\n/$newline/g;
	$SplitArray[1] =~ s/\\,/,/g;
        $SplitArray[1] =~ s/\\//g;
        $SplitArray[1] =~ s/\/$//g; 
	$SplitArray[1] =~ s/ $//g; 
	$SplitArray[1] =~ s/,$//g; 
	$AdressHash{Adress}    = $SplitArray[1];
    };
   # Fax and Phone
    if ( $SplitArray[0] =~ /FAX/ ) {
        $AdressHash{Fax} .= $SplitArrayValue[0];
    } elsif ($SplitArray[0] =~ /TEL;WORK/) {
        $AdressHash{TelWork} .= $SplitArrayValue[0];
    } elsif ( $SplitArray[0] =~ /TEL/ )  {
        if ($SplitArrayValue[0] =~ /^01/) {
             $AdressHash{Mobil} .= $SplitArrayValue[0];
        } else {
	     $AdressHash{Tel} .= $SplitArrayValue[0];
        }
    }
  }; ## main if-elsif-else
}; ## end foreach 
@OutFileArray = ("<html>\n<head>\n","<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\">
","\n<title>Contacts</title>\n</head>\n<body>","$table_begin");
my @OutFileIDs = keys(%OutFileHash);
foreach my $vID (sort @OutFileIDs) {
    push(@OutFileArray,$OutFileHash{$vID});
};
push(@OutFileArray,"$table_end\n</body></html>");
&save_textfile($options{"outfile"},\@OutFileArray);
print "\n Output file:  ".$options{"outfile"}." saved\n";
print "\nUsed ID in vCard file ".$options{infile};
#@IDarray = ("ID1","ID2","ID3");
print "\n".&create_array_line("",\@IDarray," ");
print "\n";
###########################################################################################
 
#######################################################################
# show the content of an array as one line splitted in table elements
#######################################################################
sub create_string_from_hash {
	my $ppHash        =  @_[0]; ## p=Parameter,p=Pointer
        my $vReturnString = $row_head_begin;
        if ($ppHash->{Tel} eq "") {
            $ppHash->{Tel} = $ppHash->{Mobil};
        };
        if ($ppHash->{Tel} eq "") {
           $ppHash->{Tel} = "W: ".$ppHash->{TelWork};
        };
  	$vReturnString .= $col_begin.$ppHash->{LastName}.", ".$ppHash->{FirstName}.$col_end;
        $vReturnString .= $col_begin."W: ".$ppHash->{TelWork}.$col_end; 
        $vReturnString .= $row_head_end;
        $vReturnString .= $row_begin;
        $ppHash->{Tel} =~ s/[^ 0-9\-\/ W:]//g;
        $vReturnString .= $col_begin."T: ".$ppHash->{Tel}.$col_end;
        if ($ppHash->{Fax} eq "") {
             $vReturnString .= $col_begin."eM: ".$ppHash->{EMail}.$col_end; 
        } else { 
             $vReturnString .= $col_begin."Fax: ".$ppHash->{TelWork}.$col_end;
        }; 
        $vReturnString .= $row_end;
        $vReturnString .= $row_begin;
        $vReturnString .= $col_begin."Mob: ".$ppHash->{Mobil}.$col_end; 
        $vReturnString .= $col_begin."Adr: ".$ppHash->{Adress}.$col_end; 
        $vReturnString .= $row_end;
        return $vReturnString;
}
 
################################################
## usage is displayed, if no parameter inserted
################################################

sub usage {
	my $pOutput = "";
	if (defined $_[0]) {
		$pOutput = $_[0];
	};
    select(STDERR);
    print <<EOUsage;
    
$0 [options]
  Options:

    --help                    DFileisplay this help message
    --infile  <filename>      File that will be parsed in vCard format
    --outfile <filename>      File that will be generated in $OUTFORMAT format
    
 
  $pOutput
EOUsage

    exit(1);

}

##############################################################################
# void* load_textfile ($dateiname, \@zeilen_rueckgabewert)
#
# Der Inhalt von $dateiname wird zeilenweise nach @{\@zeilen_rueckgabewert}
# gepumpt. Scheint dazu gedacht zu sein, Datenbankinhalte in den Speicher
# zu holen; wird kaum verwendet.
##############################################################################
#
sub load_textfile {
	my $pFilename =  @_[0];
	my $ppLines   =  @_[1]; 
	
	if(!-e $pFilename) {
		print "\n ERROR\n$pFilename does not exist.\n";
		exit(1);
	} else {
		open (LOADTEXTFILE, "<$pFilename") or print $!;
			if($flocking) {flock LOADTEXTFILE, 2;}
			@{$ppLines} = <LOADTEXTFILE>;
			if($flocking) {flock LOADTEXTFILE, 8;}
 		close LOADTEXTFILE;
 		foreach my $fileline(@{$ppLines}) {
 			chop($fileline);
 			chomp($fileline);
	}	} 
}

##############################################################################
# void* save_textfile ($dateiname, \@dateiinhalt);
#
# Schreibt die Daten aus @{\@dateiinhalt} nach $dateiname;
##############################################################################
#
sub save_textfile {
	my $pFilename = $_[0];
	my $ppLines   = $_[1]; 
	
	if ($pFilename eq "") {
		print "\n ERROR\nNo Filename specified in parameter (save_textfile():103.\n";
		exit(1);
	}
	open (SAVETEXTFILE, ">$pFilename") or print $!;
		if($flocking) {flock SAVETEXTFILE, 2;}
		foreach my $fileline (@{$ppLines}) {
			print SAVETEXTFILE "$fileline\n";
		};
		if($flocking) {flock SAVETEXTFILE, 8;}
 	close SAVETEXTFILE;
}


#######################################################################
# show the content of an array as one line splitted in table elements
#######################################################################
sub show_hash {
	my $ppHash        =  @_[0]; ## p=Parameter,p=Pointer
	my $pTitle        =  @_[1]; ## p=Parameter
	print "\nShow Hash:  $pTitle $table_begin";
        &show_hash_header($ppHash);
        &show_hash_line($ppHash);
	print "$table_end\n";
}

sub show_hash_header {
	my $ppHash        =  @_[0]; ## p=Parameter,p=Pointer
	my @lvArrayKeys   = keys(%{$ppHash});
	print $row_head_begin;
	foreach my $item(@lvArrayKeys) {
		print "$col_begin$item$col_end";
	};
	print $row_head_end;
}


sub show_hash_line {
	my $ppHash        =  @_[0]; ## p=Parameter,p=Pointer
	my @lvArrayValues = values(%{$ppHash});
	print $row_begin;
	foreach my $item(@lvArrayValues) {
		print "$col_begin$item$col_end";
	};
	print $row_end;
}
#######################################################################
#### show the content of an array as a table with one column and
#### as many lines as the length of the array
#######################################################################
sub show_array {
	my $ppArray       =  @_[0]; ## p=Parameter,p=Pointer
	my $pTitle        =  @_[1]; ## p=Parameter
	print "Show Array $pTitle $table_begin";
        print $row_begin;
	foreach my $item(@{$ppArray}) {
		print "$col_begin$item$col_end";
	};
	print $row_end;
	print $table_end;

}
#######################################################################
#### show the content of an array as a table with one column and
#### as many lines as the length of the array
#######################################################################
sub create_array_line {
	my $pPreSeparator  =  $_[0]; ## p=Parameter,p=Pointer
	my $ppArray        =  $_[1]; ## p=Parameter,p=Pointer
	my $pPostSeparator =  $_[2]; ## p=Parameter,p=Pointer
	my $ReturnString = "";
	foreach my $item(@{$ppArray}) {
		$ReturnString .= "$pPreSeparator$item$pPostSeparator";
	};
        return $ReturnString;
}


#################################################
# Modify Fileline and return modified content	#
#################################################

sub modify_fileline {
	my $pFileLine = $_[0];
	my $BakFileLine = $pFileLine;
	$pFileLine =~ s/^[ ;]+//g;
	$pFileLine =~ s/[;]+/, /g;
	$pFileLine =~ s/\\,$/,/g;
	$pFileLine =~ s/[ ,]+$//g;
	$pFileLine =~ s/[\\][n]$/$newline/g;
	#### CHANGE FILE ##########################
	$pFileLine =~ s/ä/ä/g;
	$pFileLine =~ s/ö/ö/g;
	$pFileLine =~ s/ü/ü/g;
	$pFileLine =~ s/Ä/Ä/g;
	$pFileLine =~ s/Ö/Ö/g;
	$pFileLine =~ s/Ü/Ü/g;
	$pFileLine =~ s/ß/ß/g;
	$pFileLine =~ s/´/'/g;
	###########################################
	if ($BakFileLine ne $pFileLine) {
	    print "\nCHANGES: ".$pFileLine."\n"
	};
	return $pFileLine;
}

#######################################################################
#### append an ID to an array if the ID is not in the array
#######################################################################
sub append_ID {
    my $ppArray =  $_[0]; ## p=Parameter,p=Pointer
    my $pNewID  =  $_[1];
    my $found = 0;
    #$pNewID =~ s/[^A-Za-z0-9 ]//g; 
    foreach my $oldID (@{$ppArray}) {
        if ($pNewID eq $oldID) {
            $found = 1;
        }
    };
    if ($found == 0) {
       push(@{$ppArray},$pNewID);
     } 
}
#########################################################################