Group :: Text tools
RPM: ooo2txt
Main Changelog Spec Patches Sources Download Gear Bugs and FR Repocop
Patch: ooo2txt.006.pl.diff
Download
Download
--- ooo2txt.006.pl-old 2006-07-10 12:14:27.000000000 +0200
+++ ooo2txt.006.pl 2006-07-10 13:46:45.000000000 +0200
@@ -1,3 +1,4 @@
+#! /usr/bin/perl -w
# -----------------------------------------------------------------
# Autor : F. Labbe
# privat : fred@frederic-labbe.com
@@ -26,29 +27,25 @@
# XML::Twig
# -----------------------------------------------------------------
+use strict;
use Getopt::Std;
use XML::Twig;
use Archive::Zip qw(:ERROR_CODES);
use File::Temp qw/ tempfile/;
+my $usage_error = "=> ooo2txt $ooo2txt_version
+=> usage (source) : perl ooo2txt [-f all] ooo_file
+=> usage (binary) : ooo2txt [-f all] ooo_file
+
+=> see http://ooo2txt.fr.st/
+";
+
# test si un parametre saisie
if (@ARGV < 1)
{
- die <<EOF
-=> ooo2txt $ooo2txt_version
-=> usage (source) : perl ooo2txt [-f all] ooo_file
-=> usage (binary) : ooo2txt [-f all] ooo_file
-
-=> see http://ooo2txt.fr.st/
-EOF
+ die $usage_error;
}
-
-
-
-
-
-
my $USAGE= "USAGE: $0 [-f all] ooo_file
see http://ooo2txt.fr.st/";
@@ -59,6 +56,7 @@
getopts('nvhe:f:', \%opt);
die "$0 version $ooo2txt_version\n" if( $opt{v});
die $USAGE, "\n" if( $opt{h});
+my $FIELD_NAME = '';
$FIELD_NAME=$opt{f} if( $opt{f});
my $zip = Archive::Zip->new();
@@ -66,8 +64,16 @@
#nom du fichier OOo
my $zip_name = shift(@ARGV);
+if (@ARGV)
+{
+ print STDERR "Warning: ignored args @ARGV\n";
+}
+
+my $conv;
+my $state={}; # various state information used during parsing;
+
# test si fichier existe
-if (open(CONTROL, $zip_name))
+if (-r $zip_name)
{
my $status = $zip->read( $zip_name );
die "Read of $zip_name failed\n"
@@ -77,24 +83,24 @@
my $file = $zip->memberNamed($OOO_XML_CONTENT) or die "Can't access data file $OOO_XML_CONTENT in zip.\n";
my $xml = tempfile();
- my $status= $file->extractToFileHandle($xml) and die "Extracting $OOO_XML_CONTENT from $zip_name failed\n";
+ my $extract_status= $file->extractToFileHandle($xml) and die "Extracting $OOO_XML_CONTENT from $zip_name failed\n";
seek( $xml, 0, 0);
- my %option;
- $option{output_encoding}= $opt{e} if( $opt{e});
+# my %option;
+# $option{output_encoding}= $opt{e} if( $opt{e});
- my $state={}; # various state information used during parsing;
- my $conv= $opt{e} ? XML::Twig::encoding_filter( $opt{e}) : sub { return @_; };
+ #$conv= $opt{e} ? XML::Twig::encoding_filter( $opt{e}) : sub { return @_; };
+ my $t;
# test
# EXTRACT FIELD_NAME ?
if (length($FIELD_NAME) > 0)
{
#my $conv = XML::Twig::unicode_convert('latin1');
- $t= XML::Twig->new( %option,
+ $t= XML::Twig->new(# %option,
# output_filter=> $conv,
twig_roots => {
# 'text:h' => \&h,
@@ -111,31 +117,33 @@
# DUMP TEXT
else
{
- $t= XML::Twig->new( %option,
+ $t= XML::Twig->new( #%option,
twig_roots => {
'text:h' => \&h,
'text:p' => sub { print $conv->( $_->text), "\n"; },
+ #'text:p' => sub { print $_->text, "\n"; },
},
);
}
+ if( $opt{e})
+ {
+ $t->set_output_encoding($opt{e});
+ $conv = $t->output_filter;
+ }
+ else
+ {
+ $conv = sub { return @_; };
+ }
-
-
- # Affichage du texte
+ # Affichage du texte
$t->parse( $xml);
}
else
{
-print ("
+print "
File $zip_name not found.
-=> ooo2txt v$ooo2txt_version
-=> usage (source) : perl ooo2txt [-f all] ooo_file
-=> usage (binary) : ooo2txt [-f all] ooo_file
-
-=> see http://ooo2txt.fr.st/
-");
-
+$usage_error";
}