1
|
1 #!/usr/bin/perl
|
|
2
|
|
3 use Calcon;
|
|
4
|
|
5 use strict;
|
|
6 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK
|
|
7 );
|
|
8
|
|
9 my %input = (
|
|
10 'Zaurus' => 'Calcon::Zaurus_read',
|
|
11 'Backup Zaurus' => 'Calcon::Zaurus_backup_read',
|
|
12 'Xcalendar' => 'Calcon::Xcalendar_read',
|
|
13 'Vcard' => 'Calcon::Vcard_read',
|
|
14 'SLA300' => 'Calcon::Sla300_read',
|
|
15 'iApp' => 'Calcon::iApp_read',
|
|
16 'Entourage' => 'Calcon::Entourage_read',
|
|
17 'File' => 'Calcon::File_read',
|
|
18 );
|
|
19
|
|
20 my %output = (
|
|
21 'Xcalendar' => 'Calcon::Xcalendar_write',
|
|
22 'Vcard' => 'Calcon::Vcard_write',
|
|
23 'SLA300' => 'Calcon::Sla300_write',
|
|
24 'AppleScript' => 'Calcon::iApp_write',
|
|
25 'iApp' => 'Calcon::iApp_write',
|
|
26 'Entourage' => 'Calcon::Entourage_write',
|
|
27 'Print' => 'Calcon::Print_write',
|
|
28 'File' => 'Calcon::File_write',
|
|
29 );
|
|
30
|
|
31
|
|
32 sub find_input {
|
|
33 my ($input) = @_;
|
|
34 my ($obj);
|
|
35
|
|
36 $input =~ s/(\W)/\\$1/g;
|
|
37 foreach my $key ( keys %input) {
|
|
38 if ($key =~ /^$input/i) {
|
|
39 $obj = $input{$key};
|
|
40 last;
|
|
41 }
|
|
42 }
|
|
43 $obj;
|
|
44 }
|
|
45
|
|
46 sub find_output {
|
|
47 my ($output) = @_;
|
|
48 my ($obj);
|
|
49
|
|
50 $output =~ s/(\W)/\\$1/g;
|
|
51 foreach my $key ( keys %output) {
|
|
52 if ($key =~ /^$output/i) {
|
|
53 $obj = $output{$key};
|
|
54 last;
|
|
55 }
|
|
56 }
|
|
57 $obj;
|
|
58 }
|
|
59
|
|
60 &usage if (! @ARGV);
|
|
61
|
|
62 my $mode = "input";
|
|
63 my $type = "file";
|
|
64 my $pool = Calcon::Pool->new();
|
|
65 my $last_flag = 0;
|
|
66
|
|
67 while(my $file = shift( @ARGV )) {
|
|
68 my ($obj,$out,$opt);
|
|
69
|
|
70 if ($file =~ /^-([^-]*)-([^-]*)((-[^-]*)*)/) {
|
|
71 $mode = $1;
|
|
72 $type = $2;
|
|
73 $opt = $3;
|
|
74 $file = shift(@ARGV);
|
|
75 } else {
|
|
76 &usage_die();
|
|
77 }
|
|
78
|
|
79 if (0 && $#ARGV==1 && $ARGV[0]=~/^-output/) {
|
|
80 # we need not pool interface for this case
|
|
81 # It does not help speed so we abandon it.
|
|
82 print "Simple Case\n";
|
|
83 my $output = $ARGV[1];
|
|
84
|
|
85 $obj = &find_input($type);
|
|
86 $obj = $obj->new($opt);
|
|
87
|
|
88 $ARGV[0] =~ /^-([^-]*)-([^-]*)((-[^-]*)*)/;
|
|
89 $mode = $1;
|
|
90 $type = $2;
|
|
91 $opt = $3;
|
|
92
|
|
93 my $out = &find_output($type);
|
|
94 $out = $out->new($opt,$output);
|
|
95 $obj->set_output($out);
|
|
96 $obj -> decode($file);
|
|
97
|
|
98 $last_flag = 1;
|
|
99 last;
|
|
100 }
|
|
101 # print "$mode $type $opt $file\n";
|
|
102 if ($mode eq 'input') {
|
|
103 $obj = &find_input($type);
|
|
104 $obj = $obj->new($opt);
|
|
105 $obj->set_output($pool);
|
|
106 $obj -> decode($file);
|
|
107 } elsif ($mode eq 'merge') {
|
|
108 $obj = &find_input($type);
|
|
109 $obj = $obj->new($opt);
|
|
110 $obj->set_output($pool);
|
|
111 $pool->merge_mode();
|
|
112 $obj -> decode($file);
|
|
113 } elsif ($mode eq 'delete') {
|
|
114 $obj = &find_input($type);
|
|
115 $obj = $obj->new($opt);
|
|
116 $obj->set_output($pool);
|
|
117 $pool->delete_mode();
|
|
118 $obj -> decode($file);
|
|
119 } elsif ($mode eq 'output') {
|
|
120 $obj = &find_output($type);
|
|
121 $obj = $obj->new($opt,$file);
|
|
122 $pool->set_output($obj);
|
|
123 $pool->output($obj);
|
|
124 $last_flag = 1;
|
|
125 last;
|
|
126 }
|
|
127 }
|
|
128
|
|
129 if (! $last_flag) {
|
|
130 my $opt = '';
|
|
131 my $obj = &find_output('File');
|
|
132 $obj = $obj->new($opt);
|
|
133 $pool->set_output($obj);
|
|
134 $pool->output($obj);
|
|
135 $last_flag = 1;
|
|
136 }
|
|
137
|
|
138
|
|
139 sub usage_die {
|
|
140 &usage();
|
|
141 die();
|
|
142 }
|
|
143
|
|
144 sub usage {
|
|
145 print "Usage: $0 -input-xcal ~/Calendar -output-print-FC /dev/stdout\n";
|
|
146 print " -[mode]-[type][-options] file-name\n";
|
|
147 print " mode: input, merge, delete\n";
|
|
148 print " input type: ",join(" ",keys %input),"\n";
|
|
149 print " output type: ",join(" ",keys %output),"\n";
|
|
150 print
|
|
151 "\t-n\tfile-out\n",
|
|
152 "\t-d\tdebug\n",
|
|
153 "\t-a\taddress only\n",
|
|
154 "\t-c\tcalendar only\n",
|
|
155 "\t-F\tfuture only\n",
|
|
156 "\t-t\ttommorrow\n",
|
|
157 "\t-C\tdisplay count\n",
|
|
158 "";
|
|
159 }
|
|
160
|
|
161 #
|
|
162
|