insilmaril@36: #!/bin/sh insilmaril@36: # insilmaril@36: # vym2txt.sh insilmaril@36: # insilmaril@36: VERSION="0.11" insilmaril@36: # Date: 20040417 insilmaril@36: # Author: Clemens Kraus (http://www.clemens-kraus.de) insilmaril@36: # insilmaril@36: #echo $@ insilmaril@36: insilmaril@36: insilmaril@36: unpacker() insilmaril@36: # Unpack vym-file, only if it is one insilmaril@36: { insilmaril@36: echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null insilmaril@36: insilmaril@36: if [ $? = 0 ] ; then insilmaril@36: echo ">> Unpacking files ..." insilmaril@36: unzip $VYMFILE_EXT -d $VYMFILE_PATH 1>/dev/null insilmaril@36: if [ $? -gt 0 ] ; then insilmaril@36: echo ">>> Error in unzip! Aborting." insilmaril@36: exit 4 insilmaril@36: fi insilmaril@36: fi insilmaril@36: } insilmaril@36: insilmaril@36: insilmaril@36: txt2xml() insilmaril@36: # change all txt-files into xml-format insilmaril@36: { insilmaril@36: for i in `ls $VYMFILE-note-*.txt 2>/dev/null` insilmaril@36: do insilmaril@36: # Check whether already modified insilmaril@36: grep "" $i 1>/dev/null insilmaril@36: insilmaril@36: if [ $? -gt 0 ] ; then insilmaril@36: echo ">> Modifying: "$i insilmaril@36: # Each line gets an additional -tag, because of the indents! insilmaril@36: sed -e 's,^,\ ,g' $i > $i"_tmp" insilmaril@36: insilmaril@36: #cp $i $i"_tmp" insilmaril@36: echo "" > $i insilmaril@36: echo "" >> $i insilmaril@36: #echo "> $i insilmaril@36: cat $i"_tmp" >> $i insilmaril@36: #echo "]]>" >> $i insilmaril@36: echo "" >> $i insilmaril@36: insilmaril@36: rm $i"_tmp" insilmaril@36: fi insilmaril@36: done insilmaril@36: } insilmaril@36: insilmaril@36: insilmaril@36: transform() insilmaril@36: { insilmaril@36: echo ">> Starting XSLT transformation ..." insilmaril@36: # sabcmd vym2html.xsl $VYMFILE".xml" \$filenamep=$VYMFILE \$wikistylep=$WIKISTYLEP \$genimagep=$GENIMAGEP \$stylesheetp=$STYLESHEETP > $VYMFILE".html" insilmaril@36: xsltproc -o $VYMFILE".txt" --stringparam filenamep `pwd`/"$VYMFILE" `dirname $STYLESHEETP`/vym2txt.xsl $VYMFILE".xml" insilmaril@36: insilmaril@36: if [ $? -gt 0 ] ; then insilmaril@36: echo ">>> Error in xsltproc! Aborting." insilmaril@36: exit 3 insilmaril@36: fi insilmaril@36: } insilmaril@36: insilmaril@36: insilmaril@36: remove_files() insilmaril@36: # remove all temporary unpacked vym-files insilmaril@36: { insilmaril@36: echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null insilmaril@36: insilmaril@36: if [ $? = 0 ] ; then insilmaril@36: echo ">> Removing temporary files ..." insilmaril@36: for i in `ls $VYMFILE-note-*.txt 2>/dev/null` insilmaril@36: do insilmaril@36: rm $i insilmaril@36: done insilmaril@36: insilmaril@36: for i in `ls $VYMFILE-image-*.* 2>/dev/null` insilmaril@36: do insilmaril@36: rm $i insilmaril@36: done insilmaril@36: insilmaril@36: rm $VYMFILE".xml" 2>/dev/null insilmaril@36: fi insilmaril@36: } insilmaril@36: insilmaril@36: # -------------------- Parameter check ----------------------- insilmaril@36: STYLESHEETP="" insilmaril@36: insilmaril@36: USAGE="USAGE:\t`basename $0` vymfile.[vym|xml] -sp=\077 [Options]\n" insilmaril@36: USAGE=$USAGE"\t-sp=\077: absolute stylesheet path (including name of stylesheet)\n" insilmaril@36: USAGE=$USAGE"Output:\tvymfile.txt\n\n" insilmaril@36: USAGE=$USAGE"Options:\n" insilmaril@36: USAGE=$USAGE"-v: prints the version of vym2txt\n" insilmaril@36: insilmaril@36: if [ "$1" = '-v' ]; then insilmaril@36: echo "vym2txt Version: "$VERSION insilmaril@36: exit 0 insilmaril@36: fi insilmaril@36: if [ $# -lt 1 -o $# -gt 2 -o "$1" = '-help' ]; then insilmaril@36: echo -e $USAGE insilmaril@36: exit 1 insilmaril@36: else insilmaril@36: VYMFILE_EXT=$1 insilmaril@36: VYMFILE=`echo $VYMFILE_EXT | cut -d. -f1` insilmaril@36: VYMFILE_PATH=`dirname $VYMFILE_EXT` insilmaril@36: fi insilmaril@36: insilmaril@36: for arg in $2 insilmaril@36: do insilmaril@36: if [ ${arg:0:3} = '-sp' ]; then # take first 3 chars insilmaril@36: STYLESHEETP=`echo $arg | cut -d= -f2` insilmaril@36: elif [ "$arg" = '-help' ]; then insilmaril@36: echo -e $USAGE insilmaril@36: exit 1 insilmaril@36: else insilmaril@36: echo -e $USAGE insilmaril@36: exit 1 insilmaril@36: fi insilmaril@36: done insilmaril@36: insilmaril@36: insilmaril@36: # ---------------------- Los geht's -------------------------- insilmaril@36: echo ">> Processing file '$VYMFILE_EXT' ..." insilmaril@36: insilmaril@36: # Unpack vym-file insilmaril@36: unpacker insilmaril@36: insilmaril@36: txt2xml insilmaril@36: insilmaril@36: # Transform insilmaril@36: transform insilmaril@36: insilmaril@36: # clean up insilmaril@36: remove_files insilmaril@36: insilmaril@36: echo ">> Ready!" insilmaril@36: echo ">> ---------------------" insilmaril@36: insilmaril@36: exit 0 insilmaril@36: insilmaril@36: