-
Notifications
You must be signed in to change notification settings - Fork 0
/
palmantimerge
executable file
·42 lines (38 loc) · 1.08 KB
/
palmantimerge
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/perl -W
# Inhibit automatic merging in Simple Mobile Tools Contacts
# Elmar Klausmeier, 10-May-2020
use strict;
my @singleCard = (); # all info between BEGIN:VCARD and END:VCARD
my ($name) = ""; # N: part, i.e., lastname semicolon firstname
my ($clashes,$line,$org) = (0,"","");
my %allCards = {}; # each entry is list of single cards belonging to same first and lastname, so hash of array of array
while (<>) {
if (/BEGIN:VCARD/) {
($name,@singleCard) = ("", ());
push @singleCard, $_;
} elsif (/END:VCARD/) {
push @singleCard, $_;
push @{ $allCards{$name} }, [ @singleCard ];
} else {
push @singleCard, $_;
$name = $_ if (/^N:/);
}
}
for $name (keys %allCards) {
$clashes = $#{$allCards{$name}};
# printf("%s: %d\n", $name, $#{$allCards{$name}});
for my $sglCrd (@{$allCards{$name}}) {
if ($clashes == 0) {
for $line (@{$sglCrd}) { print $line; }
} else {
$org = "";
for $line (@{$sglCrd}) {
$org = $1 if ($line =~ /^ORG:([ \-\+\w]+)/);
}
for $line (@{$sglCrd}) {
$line =~ s/;/ \/${org}\/;/ if ($line =~ /^N:/);
print $line;
}
}
}
}