From 8362bf63dea22bbf6736609b0f49c152f975eb63 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 20 Jan 2010 01:29:50 +0000 Subject: Added old abandoned KDE3 version of koffice git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- lib/templatescript.sh | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100755 lib/templatescript.sh (limited to 'lib/templatescript.sh') diff --git a/lib/templatescript.sh b/lib/templatescript.sh new file mode 100755 index 000000000..ec8a2be48 --- /dev/null +++ b/lib/templatescript.sh @@ -0,0 +1,155 @@ +#!/bin/sh +######### This script is finally not used as it is here. +######### But it can be used as a template for applying any kind of +######### processing to a KOffice document (mainly the shell part of it). + +if [ $# -ne 2 ]; then + echo "$0 :" + echo "converts a KPresenter document from the old format to the new one (v2)" + echo "due to the new text object." + echo + echo "Usage: $0 " + echo + echo "Copyright (c) David Faure 2000, licensed under the GPL version 2" + exit +fi + +if test ! -f $1; then + echo "$0 : Could not find file $1" + exit +fi + +echo "Creating temporary directory..." +tmpdir=/tmp/kprconverter +mkdir $tmpdir 2>/dev/null +cp $1 /tmp/kprconverter/input.kpr +lastdir=`pwd` +cd /tmp/kprconverter + +echo "Extracting XML document..." +tar xvzf input.kpr | sed -e 's/^/ /' && rm -f input.kpr || exit 1 + +echo "Converting document..." +perl -w -e \ +' +open(INPUT, "<$ARGV[0]") || die "Cannot open $ARGV[0]"; +open(OUTPUT, ">$ARGV[1]") || die "Cannot create $ARGV[1]"; +$objType=""; +$insideParag=0; +$insideObj=0; +$currentText=""; +$currentTextType=0; +while () +{ + if (/$/ type=$objType>/; + } + elsif (/<\/PARAGRAPH>/) + { + $insideParag=0; + s/<\/PARAGRAPH/<\/P/; + # Flush last text tag + $_ = $currentText . "\n" . $_ if ($currentText); + $currentText=""; + } + elsif (//) + { + $insideObj=1; + $_ = ""; # ignore + } + elsif (/<\/OBJ>/) + { + $insideObj=0; + $_ = ""; # ignore + } + elsif ($insideObj) + { + $toprint=""; + if (m/ this is a white space + { + # If we have a previous text element, we keep it (merging) + # Otherwise this white space is the first one in the object -> cheat + $currentTextType=0 if (!$currentText); + } + if (!$currentTextType) # 0 -> normal text + { + # If we have a previous text element, write it out + $toprint = $currentText . "\n" if ($currentText); + # Start a new text element + $currentText = " //; + chomp; + # Append all attributes + $currentText = $currentText . $_; + } + elsif (/(.*)<\/TEXT>/) + { + if (!$currentTextType) # normal text + { + # Close opening tag and append the text - but don t do more yet + @entities=split( "(&[a-z]+;)", $1); + $text=""; + foreach ( @entities ) + { + if (!/</ && !/>/ ) + { + # Replace & by & but only if not in an entity + s/\&/\&/g; + } + $text = $text . $_; + } + $currentText = $currentText . ">" . $text; + } + else + { + # White space. Simply appending, closing the text tag. + $toprint = $currentText . $1 . "\n"; + $currentText = ""; # reset + } + } + $_=$toprint; + } + + print OUTPUT $_; +} +close(INPUT); +close(OUTPUT); +' maindoc.xml newmaindoc.xml + +mv -f newmaindoc.xml maindoc.xml + +echo "Repackaging document..." +tar cvzf output.kpr * | sed -e 's/^/ /' +cd $lastdir +mv -f /tmp/kprconverter/output.kpr $2 + +echo "Done!" -- cgit v1.2.3