3 function STRING( inp ) {
4 gsub(/\\/, "\\\\", inp);
5 gsub(/\n/, "\\n", inp);
6 gsub(/\r/, "\\r", inp);
7 gsub(/\t/, "\\t", inp);
8 gsub(/\+/, "\\+", inp);
10 return inp ? inp : "\\";
13 function UNSTRING( inp, out, tmp ) {
15 if ( inp ~ /^\\\\/) { out = out "\\"; sub(/^\\\\/, "", inp); }
16 else if ( inp ~ /^\\n/) { out = out "\n"; sub(/^\\n/, "", inp); }
17 else if ( inp ~ /^\\r/) { out = out "\r"; sub(/^\\r/, "", inp); }
18 else if ( inp ~ /^\\t/) { out = out "\t"; sub(/^\\t/, "", inp); }
19 else if ( inp ~ /^\\+/) { out = out "+"; sub(/^\\+/, "", inp); }
20 else if ( inp ~ /^\+/) { out = out " "; sub(/^\+/, "", inp); }
21 else if ( inp ~ /^\\/) { out = out ""; sub(/^\+/, "", inp); }
22 else { tmp = inp; sub(/[\\+].*$/, "", tmp); out = out tmp; sub(/^[^\\+]*/, "", inp); }
27 function rx( regex ) {
28 gsub(/[].*+?^${}()|\\[]/, "\\\\&", regex);
34 fn = n = uid = iban = tmp = "";
35 split("", uid_n); split("", uid_fn); split("", uid_iban);
36 split("", iban_uid); split("", ibans); split("", uids);
38 split("", sure); split("", unsure); split("", unknown);
42 /^BEGIN;:VCARD$/ { fn = n = id = iban = tmp = ""; }
44 /^UID;[^:]*:/ { uid = $0; sub(/^[^;]+;[^:]*:/, "", uid); }
45 /^FN;[^:]*:/ { fn = $0; sub(/^[^;]+;[^:]*:/, "", fn); }
46 /^N;[^:]*:/ { n = $0; sub(/^[^;]+;[^:]*:/, "", n); sub(/;.*$/, "", n); }
47 /^X-IBAN;[^:]*:/ { tmp = $0; sub(/^[^;]+;[^:]*:/, "", tmp); iban = iban ? iban " " tmp : tmp; }
50 uid_n[uid] = n; uid_fn[uid] = fn; uid_iban[uid] = iban;
51 split(iban, ibans, / /);
52 for (iban in ibans) iban_uid[iban] = iban_uid[iban] ? iban_uid[iban] " " uid : uid;
53 fn = n = uid = iban = tmp = "";
56 strftime("%Y-%m-%d", $1, "UTC") == $2 && strftime("%Y-%m-%d", $3, "UTC") == $4 { ledger = 1; }
58 ledger && strftime("%Y-%m-%d", $2, "UTC") == $1 {
60 sure[$3] = iban_uid[$3];
62 for (uid in uid_fn) if ( match(UNSTRING($5), rx(uid_fn[uid])) ) {
63 if (! match(unsure[$3], rx(uid))) unsure[$3] = unsure[$3] ? unsure[$3] " " uid : uid;
66 for (uid in uid_n) if ( uid_n[uid] && match(UNSTRING($4), rx(uid_n[uid])) ) {
67 if (! match(unsure[$3], rx(uid))) unsure[$3] = unsure[$3] ? unsure[$3] " " uid : uid;
71 if (!($3 in sure) && !($3 in unsure)) unknown[$3] = $0;
77 split(iban_uid[iban], uids, / /);
78 for (uid in uids) line = line " " STRING(uid "/" uid_fn[uid]);
81 for (iban in unsure) {
82 line = "guess " iban " " STRING(unsure_rec[iban]);
83 split(unsure[iban], uids, / /);
84 for (k in uids) line = line " " STRING(uids[k] "/" uid_fn[uids[k]]);
87 for (iban in unknown) {
88 line = "unknown " iban " " unknown[iban];