diff pool.pl @ 17:1fc0675b44cd

hg init
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 02 Sep 2011 18:29:56 +0900
parents
children 12ddd9dd9fc6
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pool.pl	Fri Sep 02 18:29:56 2011 +0900
@@ -0,0 +1,175 @@
+#!/usr/bin/perl 
+
+use Calcon;
+
+use strict;
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK 
+);
+
+my %input = (
+    'Zaurus' 	=> 'Calcon::Zaurus_read',
+    'Backup Zaurus' 	=> 'Calcon::Zaurus_backup_read',
+    'Xcalendar' => 'Calcon::Xcalendar_read',
+    'Vcard' 	=> 'Calcon::Vcard_read',
+    'SLA300' 	=> 'Calcon::Sla300_read',
+    'iApp' 	=> 'Calcon::iApp_read',
+  'Entourage'	=> 'Calcon::Entourage_read',
+    'File' 	=> 'Calcon::File_read',
+);
+
+my %output = (
+    'Xcalendar'	=> 'Calcon::Xcalendar_write',
+    'Vcard' 	=> 'Calcon::Vcard_write',
+    'SLA300'	=> 'Calcon::Sla300_write',
+  'AppleScript'	=> 'Calcon::iApp_write',
+    'iApp' 	=> 'Calcon::iApp_write',
+ 'Address Book' => 'Calcon::Vcard_Apple_write',
+  'Entourage'	=> 'Calcon::Entourage_write',
+    'Print' 	=> 'Calcon::Print_write',
+    'N702' 	=> 'Calcon::Vcard_N702iD_write',
+    'File' 	=> 'Calcon::File_write',
+);
+
+
+sub find_input {
+    my ($input) = @_;
+    my ($obj);
+
+    $input =~ s/(\W)/\\$1/g;
+    foreach my $key ( keys %input) {
+	if ($key =~ /^$input/i) {
+	    $obj  = $input{$key}; 
+	    last;
+	}
+    }
+    $obj;
+}
+
+sub find_output {
+    my ($output) = @_;
+    my ($obj);
+
+    $output =~ s/(\W)/\\$1/g;
+    foreach my $key ( keys %output) {
+	if ($key =~ /^$output/i) {
+	    $obj  = $output{$key}; 
+	    last;
+	}
+    }
+    $obj;
+}
+
+&usage if (! @ARGV); 
+
+my $mode = "input";
+my $type = "file";
+my $pool = Calcon::Pool->new();
+my $last_flag = 0;
+my $first_flag = 1;
+
+while(my $file = shift( @ARGV )) {
+    my ($obj,$out,$opt);
+
+    if ($file =~ /^-([^-]*)-([^-]*)((-[^-]*)*)/) {
+	$mode = $1;
+	$type = $2;
+	$opt = $3;
+	$file = shift(@ARGV);
+	$first_flag = 0;
+    } else {
+	&usage_die();
+
+#
+#       decode を呼び出しても処理は繰り返し行われないらしい
+#
+#	if ($first_flag) {
+#	    &usage_die();
+#	} else {
+#	    $file = shift(@ARGV);
+#	}
+    }
+
+    if (0 && $#ARGV==1 && $ARGV[0]=~/^-output/) {
+	# we need not pool interface for this case
+        # It does not help speed so we abandon it.
+	print "Simple Case\n";
+	my $output = $ARGV[1];
+
+	$obj = &find_input($type);
+	$obj = $obj->new($opt);
+
+        $ARGV[0] =~ /^-([^-]*)-([^-]*)((-[^-]*)*)/;
+	$mode = $1;
+	$type = $2;
+	$opt = $3;
+
+	my $out = &find_output($type);
+	$out = $out->new($opt,$output);
+	$obj->set_output($out);
+	$obj -> decode($file);
+
+	$last_flag = 1;
+	last;
+    }
+#    print "$mode $type $opt $file\n";
+    if ($mode eq 'input') {
+	$obj = &find_input($type);
+	$obj = $obj->new($opt);
+	$obj->set_output($pool);
+	$obj -> decode($file);
+    } elsif ($mode eq 'merge') {
+	$obj = &find_input($type);
+	$obj = $obj->new($opt);
+	$obj->set_output($pool);
+	$pool->merge_mode();
+	$obj -> decode($file);
+    } elsif ($mode eq 'delete') {
+	$obj = &find_input($type);
+	$obj = $obj->new($opt);
+	$obj->set_output($pool);
+	$pool->delete_mode();
+	$obj -> decode($file);
+    } elsif ($mode eq 'output') {
+	$obj = &find_output($type);
+	$obj = $obj->new($opt,$file);
+	$pool->set_output($obj);
+	$pool->output($obj);
+	$last_flag = 1;
+	last;
+    }
+}
+
+if (! $last_flag) {
+	my $opt = '';
+	my $obj = &find_output('File');
+	$obj = $obj->new($opt);
+	$pool->set_output($obj);
+	$pool->output($obj);
+	$last_flag = 1;
+}
+
+
+sub usage_die {
+    &usage();
+    die();
+}
+
+sub usage {
+    print "Usage: $0 -input-xcal ~/Calendar -output-print-FC /dev/stdout\n";
+    print "     -[mode]-[type][-options] file-name\n";
+    print "  mode:  input, merge, delete\n";
+    print "  input  type: ",join(" ",keys %input),"\n";
+    print "  output type: ",join(" ",keys %output),"\n";
+    print
+      "\t-n\tfile-out\n",
+      "\t-d\tdebug\n",
+      "\t-a\taddress only\n",
+      "\t-c\tcalendar only\n",
+      "\t-F\tfuture only\n",
+      "\t-t\ttommorrow\n",
+      "\t-C\tdisplay count\n",
+      "";
+}
+
+#
+