[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice
Subject:    patch: Perl again ;)
From:       Werner Trobin <wtrobin () mandrakesoft ! com>
Date:       2000-08-30 18:49:38
[Download RAW message or body]

Hi!

I got my hands on a few old files and found a few bugs.
(the fixes are already in CVS). However, the loading
still didn't work, so I started to hack the conversion
script again.

This works for me and as it looks it can't harm and other
files. The problem is that it doesn't handle xpm properly
(dunno why). I'll check that now.

David?

P.S. If you need the files and the appropriate web presentation
to test, please visit http://devel-home.kde.org/~ctibirna/

-- 
Werner Trobin - wtrobin@mandrakesoft.com
["kpresenter.diff" (text/plain)]

Index: kprconverter.pl
===================================================================
RCS file: /home/kde/koffice/kpresenter/kprconverter.pl,v
retrieving revision 1.5
diff -b -u -p -r1.5 kprconverter.pl
--- kprconverter.pl	2000/08/29 13:20:03	1.5
+++ kprconverter.pl	2000/08/30 18:37:36
@@ -1,18 +1,32 @@
 # converts a KPresenter document from the old format to the new one (v2)
 # due to the new text object
+
+use Time::Local;
+
 open(INPUT, "<$ARGV[0]") || die "Cannot open $ARGV[0]";
 open(OUTPUT, ">$ARGV[1]") || die "Cannot create $ARGV[1]";
 $objType="";
 $insideParag=0;
 $insideObj=0;
+$insidePixmaps=0;  # are we inside the <PIXMAPS> tags?
 $currentText="";
 $currentTextType=0;
 while (<INPUT>)
 {
   if (/<DOC/)
     {
+      # store the url because this is a prart of the "path" for the images
+      $url=$1 if(m/url=\"(.*)\"/);
       s/>$/ syntaxVersion=\"2\">/;
     }
+  elsif (/<PIXMAPS>/)
+    {
+      $insidePixmaps=1;
+    }
+  elsif (/<\/PIXMAPS>/)
+    {
+      $insidePixmaps=0;
+    }
   elsif (/<TEXTOBJ/)
     {
       # Save object type of the TEXTOBJ tag
@@ -115,6 +129,38 @@ while (<INPUT>)
 	    }
 	}
       $_=$toprint;
+    }
+  elsif ($insidePixmaps)
+    {
+      if(/\s+name=\"/)
+        {
+          # Aha - this file is not version 2 but was created as "proper" tgz \
storage... medieval times :) +          print "Found a name attribute, no need to \
create one.\n"; +        }
+      elsif (/<KEY(.*)\/>/)
+      {
+        # Okay - plain old kpresenter magic...
+        $key=$1;
+        # Note: The .*? is needed because it would be too greedy otherwise
+        $filename=$1 if($key =~ /filename=\"(.*?)\"/);
+        # Get the values - really straightforward
+        $year=$1 if($key =~ /year=\"(\d+)\"/);
+        $month=$1 if($key =~ /month=\"(\d+)\"/);
+        $day=$1 if($key =~ /day=\"(\d+)\"/);
+        $hour=$1 if($key =~ /hour=\"(\d+)\"/);
+        $minute=$1 if($key =~ /minute=\"(\d+)\"/);
+        $second=$1 if($key =~ /second=\"(\d+)\"/);
+        # In Perl the month is <0...11>!!!
+        $timestamp=timegm($second, $minute, $hour, $day, $month-1, $year);
+        # Unfortunately we even have to mess with that string...
+        $timestring=scalar gmtime($timestamp);
+        # There are still some spaces too much when day<10
+        $timestring =~ s/  / /;
+        # Okay. Now let's cat the whole caboodle...
+        $nameattrib=$url . $filename . "_" . $timestring;
+        # ...and put it in place.
+        s/\/>/ name=\"$nameattrib\" \/>/;
+      }
     }
 
   print OUTPUT $_;



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic