updated git and svn scripts
[xrzperl.git] / epub_split_xhtml
blobdd7d193c3f32ff669502c935e61fc1c6f39c9183
1 #!/usr/bin/perl -w
2 # $Id$
3 use strict;
4 require v5.10.0;
5 our $VERSION = 'v0.1';
7 BEGIN
9 my $PROGRAM_DIR = $0;
10 $PROGRAM_DIR =~ s/[^\/\\]+$//;
11 $PROGRAM_DIR = "./" unless($PROGRAM_DIR);
12 unshift @INC,
13 map "$PROGRAM_DIR$_",qw{modules lib ../modules ..lib};
16 my %OPTS;
17 my @OPTIONS = qw/help|h|? version|ver edit-me manual|man size|s=i/;
19 if(@ARGV)
21 require Getopt::Long;
22 require MyPlace::Usage;
23 Getopt::Long::GetOptions(\%OPTS,@OPTIONS);
24 MyPlace::Usage::Process(\%OPTS,$VERSION);
26 else
28 require MyPlace::Usage;
29 MyPlace::Usage::PrintHelp();
32 my $max_size = $OPTS{size} ? $OPTS{size} * 1000 : 256000;
33 my @target_files = @ARGV;
35 die("No target files.\n") unless(@target_files);
37 use File::stat;
38 foreach my $filename(@target_files)
40 if(! -f $filename)
42 print STDERR "File not accesable : \"$filename\"\n";
43 next;
45 my $stat = stat($filename);
46 if($stat->size <= $max_size) {
47 print STDERR "File size does not exceed $max_size.\n \"$filename\" [Ignored]\n";
48 next;
50 print STDERR "Spliting $filename...";
51 print STDERR "\n",&split_file($max_size,$filename);
54 sub split_file {
55 my($max_size,$filename) = @_;
56 $filename =~ m/^(.+)\.([^\.]+)$/;
57 my $basename = $1 or $filename;
58 my $ext = $2 ? ".$2" : "";
60 my $data;
62 local $|='';
63 open FI,"<",$filename or return("$!\n");
64 $data = <FI>;
65 close FI;
67 return "Nothing to do\n" unless($data);
69 if($data =~ m/^([.\n]+)<body>([.\n]+)<\/body>([.\n]+)$/) {
70 my $head = $1;
71 my $body = $2;
72 my $foot = $3;
73 die("Not implemented.");
75 else {
76 return "Nothing to do\n";
82 __END__
84 =pod
86 =head1 NAME
88 epub_split_xhtml - PERL script
90 =head1 SYNOPSIS
92 epub_split_xhtml [options] ...
94 =head1 OPTIONS
96 =over 12
98 =item B<--version>
100 Print version infomation.
102 =item B<-h>,B<--help>
104 Print a brief help message and exits.
106 =item B<--manual>,B<--man>
108 View application manual
110 =item B<--edit-me>
112 Invoke 'editor' against the source
114 =back
116 =head1 DESCRIPTION
118 ___DESC___
120 =head1 CHANGELOG
122 2010-06-06 xiaoranzzz <xiaoranzzz@myplace.hell>
124 * file created.
126 =head1 AUTHOR
128 xiaoranzzz <xiaoranzzz@myplace.hell>
130 =cut