annotate calcon.pl @ 25:98d017d452c6 default tip

add sqlite3 based iCal
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 19 Feb 2023 10:36:01 +0900
parents 1fc0675b44cd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #!/usr/bin/perl
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 use Calcon;
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 use strict;
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 $opt_f $opt_t $opt_n $opt_d $opt_h $opt_F $opt_O $opt_a $opt_c $opt_T
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 );
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 my %input = (
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 'Zaurus' => 'Calcon::Zaurus_read',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 'Backup Zaurus' => 'Calcon::Zaurus_backup_read',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 'Xcalendar' => 'Calcon::Xcalendar_read',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 'Vcard' => 'Calcon::Vcard_read',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 'SLA300' => 'Calcon::Sla300_read',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 'iApp' => 'Calcon::iApp_read',
25
98d017d452c6 add sqlite3 based iCal
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 17
diff changeset
17 'iCal' => 'Calcon::iApps_read',
17
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 'Entourage' => 'Calcon::Entourage_read',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 'File' => 'Calcon::File_read',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 );
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 my %output = (
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 'Xcalendar' => 'Calcon::Xcalendar_write',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 'Vcard' => 'Calcon::Vcard_write',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 'SLA300' => 'Calcon::Sla300_write',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 'AppleScript' => 'Calcon::iApp_write',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 'iApp' => 'Calcon::iApp_write',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 'Address Book' => 'Calcon::Vcard_Apple_write',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 'Entourage' => 'Calcon::Entourage_write',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 'Print' => 'Calcon::Print_write',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 'File' => 'Calcon::File_write',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 'N702' => 'Calcon::Vcard_N702iD_write',
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 );
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 use Getopt::Std;
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 getopts('f:t:ndhO:acFT');
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 if ($opt_h) {
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 print "Usage: $0 [-d -n] -f input_type -t output_type inputfile\n";
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 print " input type: ",join(" ",keys %input),"\n";
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 print " output type: ",join(" ",keys %output),"\n";
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 exit 0;
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 }
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 # print "option: $opt_f $opt_t\n";
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 my $from_opts;
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 my $to_opts;
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 if (! @ARGV) { @ARGV = ('/dev/stdin'); }
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 foreach my $file ( @ARGV ) {
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 my ($obj,$out);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 $opt_f = 'file' if (!$opt_f);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 $opt_t = 'file' if (!$opt_t);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 if ($opt_f =~ s/:.*//) { $from_opts = $&; }
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 $opt_f =~ s/(\W)/\\$1/g;
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 foreach my $key ( keys %input) {
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 if ($key =~ /^$opt_f/i) {
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 $obj = $input{$key};
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 last;
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 }
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 }
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 $obj = $obj->new($from_opts);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 if ($opt_t =~ s/:.*//) { $to_opts = $&; }
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 $to_opts .= '-n' if ($opt_n);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 $opt_t =~ s/(\W)/\\$1/g;
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 foreach my $key ( keys %output) {
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 if ($key =~ /^$opt_t/i) {
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 $out = $output{$key};
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 last;
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 }
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 }
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 $out = $out->new($to_opts);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 # print "$obj $out\n";
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 $obj->set_output($out);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 # $out->{'-file-out'} = $opt_n; too late
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 foreach my $o ( $obj, $out) {
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 $o->set_debug(1) if ($opt_d);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 $o->{'-address-only'} = 1 if ($opt_a);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 $o->{'-calendar-only'} = 1 if ($opt_c);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 $o->{'-future-only'} = 1 if ($opt_F);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 $o->{'-tomorrow'} = 1 if ($opt_T);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 }
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 # print "option: $opt_f $opt_t\n";
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 $obj -> decode($file);
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 }
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 #
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 __END__
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 =head1 NAME
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 calcon.pl -- Convert Various Calendar/Address data format
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 =head1 SYNOPSIS
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 perl calcon.pl -f from -t form [-d] [-n]
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 =head1 DESCRIPTION
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 -f from-format
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 File format
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 Zaurus Read Zaurus MI C1 Compact Flast
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 Xcalendar
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 vCal/vCard
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 iApp via Applescript
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 Entourage via Applescript
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 -t from-format
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 File format
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 iCal and Addres Book Applescript execution (-f put result into files in script-out )
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 vCal/vCard
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 Zaurus SLA-300
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 Entourage via Applescript
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 Address Book (Mac OS X 10.4 Address Book)
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 -a addres only
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 -c calendar only
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 -F future only
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 -T tomorrow only
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 -h show help
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 -d debug
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 -n non-execution mode for applescript
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 scripts are put into script-out directory
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134
1fc0675b44cd hg init
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 =cut