1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/scripts/vym2txt.sh Wed Apr 11 09:21:16 2007 +0000
1.3 @@ -0,0 +1,144 @@
1.4 +#!/bin/sh
1.5 +#
1.6 +# vym2txt.sh
1.7 +#
1.8 +VERSION="0.11"
1.9 +# Date: 20040417
1.10 +# Author: Clemens Kraus (http://www.clemens-kraus.de)
1.11 +#
1.12 +#echo $@
1.13 +
1.14 +
1.15 +unpacker()
1.16 +# Unpack vym-file, only if it is one
1.17 +{
1.18 + echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null
1.19 +
1.20 + if [ $? = 0 ] ; then
1.21 + echo ">> Unpacking files ..."
1.22 + unzip $VYMFILE_EXT -d $VYMFILE_PATH 1>/dev/null
1.23 + if [ $? -gt 0 ] ; then
1.24 + echo ">>> Error in unzip! Aborting."
1.25 + exit 4
1.26 + fi
1.27 + fi
1.28 +}
1.29 +
1.30 +
1.31 +txt2xml()
1.32 +# change all txt-files into xml-format
1.33 +{
1.34 + for i in `ls $VYMFILE-note-*.txt 2>/dev/null`
1.35 + do
1.36 + # Check whether already modified
1.37 + grep "<note>" $i 1>/dev/null
1.38 +
1.39 + if [ $? -gt 0 ] ; then
1.40 + echo ">> Modifying: "$i
1.41 + # Each line gets an additional <line>-tag, because of the indents!
1.42 + sed -e 's,^,<line><![CDATA[,g' -e 's,$,]]>\
</line>,g' $i > $i"_tmp"
1.43 +
1.44 + #cp $i $i"_tmp"
1.45 + echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" > $i
1.46 + echo "<note>" >> $i
1.47 + #echo "<![CDATA[" >> $i
1.48 + cat $i"_tmp" >> $i
1.49 + #echo "]]>" >> $i
1.50 + echo "</note>" >> $i
1.51 +
1.52 + rm $i"_tmp"
1.53 + fi
1.54 + done
1.55 +}
1.56 +
1.57 +
1.58 +transform()
1.59 +{
1.60 + echo ">> Starting XSLT transformation ..."
1.61 +# sabcmd vym2html.xsl $VYMFILE".xml" \$filenamep=$VYMFILE \$wikistylep=$WIKISTYLEP \$genimagep=$GENIMAGEP \$stylesheetp=$STYLESHEETP > $VYMFILE".html"
1.62 + xsltproc -o $VYMFILE".txt" --stringparam filenamep `pwd`/"$VYMFILE" `dirname $STYLESHEETP`/vym2txt.xsl $VYMFILE".xml"
1.63 +
1.64 + if [ $? -gt 0 ] ; then
1.65 + echo ">>> Error in xsltproc! Aborting."
1.66 + exit 3
1.67 + fi
1.68 +}
1.69 +
1.70 +
1.71 +remove_files()
1.72 +# remove all temporary unpacked vym-files
1.73 +{
1.74 + echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null
1.75 +
1.76 + if [ $? = 0 ] ; then
1.77 + echo ">> Removing temporary files ..."
1.78 + for i in `ls $VYMFILE-note-*.txt 2>/dev/null`
1.79 + do
1.80 + rm $i
1.81 + done
1.82 +
1.83 + for i in `ls $VYMFILE-image-*.* 2>/dev/null`
1.84 + do
1.85 + rm $i
1.86 + done
1.87 +
1.88 + rm $VYMFILE".xml" 2>/dev/null
1.89 + fi
1.90 +}
1.91 +
1.92 +# -------------------- Parameter check -----------------------
1.93 +STYLESHEETP=""
1.94 +
1.95 +USAGE="USAGE:\t`basename $0` vymfile.[vym|xml] -sp=\077 [Options]\n"
1.96 +USAGE=$USAGE"\t-sp=\077: absolute stylesheet path (including name of stylesheet)\n"
1.97 +USAGE=$USAGE"Output:\tvymfile.txt\n\n"
1.98 +USAGE=$USAGE"Options:\n"
1.99 +USAGE=$USAGE"-v: prints the version of vym2txt\n"
1.100 +
1.101 +if [ "$1" = '-v' ]; then
1.102 + echo "vym2txt Version: "$VERSION
1.103 + exit 0
1.104 +fi
1.105 +if [ $# -lt 1 -o $# -gt 2 -o "$1" = '-help' ]; then
1.106 + echo -e $USAGE
1.107 + exit 1
1.108 +else
1.109 + VYMFILE_EXT=$1
1.110 + VYMFILE=`echo $VYMFILE_EXT | cut -d. -f1`
1.111 + VYMFILE_PATH=`dirname $VYMFILE_EXT`
1.112 +fi
1.113 +
1.114 +for arg in $2
1.115 +do
1.116 + if [ ${arg:0:3} = '-sp' ]; then # take first 3 chars
1.117 + STYLESHEETP=`echo $arg | cut -d= -f2`
1.118 + elif [ "$arg" = '-help' ]; then
1.119 + echo -e $USAGE
1.120 + exit 1
1.121 + else
1.122 + echo -e $USAGE
1.123 + exit 1
1.124 + fi
1.125 +done
1.126 +
1.127 +
1.128 +# ---------------------- Los geht's --------------------------
1.129 +echo ">> Processing file '$VYMFILE_EXT' ..."
1.130 +
1.131 +# Unpack vym-file
1.132 +unpacker
1.133 +
1.134 +txt2xml
1.135 +
1.136 +# Transform
1.137 +transform
1.138 +
1.139 +# clean up
1.140 +remove_files
1.141 +
1.142 +echo ">> Ready!"
1.143 +echo ">> ---------------------"
1.144 +
1.145 +exit 0
1.146 +
1.147 +