Initial import. vendor
authorinsilmaril
Sun Jan 30 12:59:07 2005 +0000 (2005-01-30)
branchvendor
changeset 3667e7883ab157
parent 35 5d3804ffc0ad
child 37 df767ed748f3
Initial import.
scripts/vym2html.sh
scripts/vym2txt.sh
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/vym2html.sh	Sun Jan 30 12:59:07 2005 +0000
     1.3 @@ -0,0 +1,250 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# vym2html.sh
     1.7 +#
     1.8 +VERSION="0.7"
     1.9 +# Date: 20040625
    1.10 +# Author: Clemens Kraus (http://www.clemens-kraus.de)
    1.11 +#
    1.12 +# AddOns: Uwe Drechsel
    1.13 +#echo $@
    1.14 +
    1.15 +
    1.16 +unpacker()
    1.17 +# Unpack vym-file, only if it is one
    1.18 +{
    1.19 +  echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null
    1.20 +
    1.21 +  if [ $? = 0 ] ; then
    1.22 +	  echo ">> Unpacking files ..."
    1.23 +	  unzip $VYMFILE_EXT -d $VYMPATH 1>/dev/null
    1.24 +	  if [ $? -gt 0 ] ; then
    1.25 +		echo ">>> Error in unzip! Aborting."
    1.26 +	  	exit 4
    1.27 +	  fi
    1.28 +  fi
    1.29 +}
    1.30 +
    1.31 +
    1.32 +transform()
    1.33 +{
    1.34 +  # copy stylesheet
    1.35 +  if [ -z $STYLESHEETP ] ; then
    1.36 +	  echo ">>> Error: could not process stylesheet "$STYLESHEETP"! Aborting."
    1.37 +	  exit 5
    1.38 +  else
    1.39 +	  if [ -n $VYMPATH ] ; then
    1.40 +		  if [ -n "$WIKISTYLEP" ] ; then
    1.41 +		    mkdir -p $VYMPATH/images
    1.42 +			cp `dirname $STYLESHEETP`/wiki/* $VYMPATH/images
    1.43 +			if [ $? -gt 0 ] ; then
    1.44 +				echo ">>> Warning: could not copy images for WIKI style
    1.45 +				\""$STYLESHEETP"/wiki/*\"!"
    1.46 +			else
    1.47 +			  echo ">> WIKI style images \""$STYLESHEETP"/wiki/*\" copied ..."
    1.48 +			fi  
    1.49 +		  fi
    1.50 +	  	cp `dirname $STYLESHEETP`/$CSSFILE $VYMPATH
    1.51 +		if [ $? -gt 0 ] ; then
    1.52 +			echo ">>> Warning: could not copy CSS-file \""$CSSFILE"\"!"
    1.53 +		else
    1.54 +		  echo ">> CSS-file \""$CSSFILE"\" copied ..."
    1.55 +		fi
    1.56 +	  fi
    1.57 +  fi
    1.58 +  
    1.59 +  echo ">> Starting XSLT transformation ..."
    1.60 +
    1.61 +  OPTIONS=" -o $VYMFILE.html \
    1.62 +  --stringparam filenamep \"$VYMFILE\" \
    1.63 +  --stringparam wikistylep \"$WIKISTYLEP\" \
    1.64 +  --stringparam genimagep \"$GENIMAGEP\" \
    1.65 +  --stringparam imageonlyp \"$IMAGEONLYP\" \
    1.66 +  --stringparam urlHeadingp \"$URLHEADING\" \
    1.67 +  --stringparam urlImagep \"$URLIMG\" \
    1.68 +  --stringparam stylesheetp $CSSFILE  \
    1.69 +  `dirname $STYLESHEETP`/vym2html.xsl \
    1.70 +  $VYMFILE.xml "
    1.71 +  
    1.72 +  
    1.73 +# echo Executing: xsltproc $OPTIONS 2>&1
    1.74 +#  xsltproc $OPTIONS 2>&1
    1.75 +
    1.76 +xsltproc -o $VYMPATH/$VYMNAME".html" --stringparam filenamep "$VYMPATH/$VYMNAME" --stringparam wikistylep "$WIKISTYLEP" --stringparam genimagep "$GENIMAGEP" --stringparam imageonlyp "$IMAGEONLYP" --stringparam urlHeadingp "$URLHEADING" --stringparam urlImagep "$URLIMAGE" --stringparam stylesheetp "$CSSFILE"  `dirname $STYLESHEETP`/vym2html.xsl  $VYMPATH/$VYMNAME".xml" 2>&1
    1.77 +
    1.78 +  if [ $? -gt 0 ] ; then
    1.79 +	  echo ">>> Error in xsltproc! Aborting."
    1.80 +	  exit 3
    1.81 +  fi
    1.82 +  
    1.83 +}
    1.84 +
    1.85 +
    1.86 +txt2html()
    1.87 +# change all txt-files into xml-format
    1.88 +{
    1.89 +  for i in `ls $VYMPATH/notes/$VYMNAME-note-*.txt 2>/dev/null`
    1.90 +  do
    1.91 +    # Check whether already modified
    1.92 +	grep "<note>" $i 1>/dev/null
    1.93 +	
    1.94 +	if [ $? -gt 0 ] ; then
    1.95 +	  echo ">> Modifying: "$i
    1.96 +	  cp $i $i"_tmp"
    1.97 +	  echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $i
    1.98 +	  echo "<note>" >> $i
    1.99 +	  if [ -z "$WIKISTYLEP" ] ; then
   1.100 +		  echo "<![CDATA[" >> $i
   1.101 +	  fi
   1.102 +	  
   1.103 +	  cat $i"_tmp" >> $i
   1.104 +  
   1.105 +	  if [ -z "$WIKISTYLEP" ] ; then
   1.106 +		  echo "]]>" >> $i
   1.107 +	  fi
   1.108 +	  echo "</note>" >> $i
   1.109 +  
   1.110 +	  rm $i"_tmp"
   1.111 +	fi
   1.112 +  done
   1.113 +}
   1.114 +
   1.115 +
   1.116 +remove_files()
   1.117 +# remove all temporary unpacked vym-files
   1.118 +{
   1.119 +  echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null
   1.120 +	
   1.121 +  if [ $? = 0 ] ; then
   1.122 +	echo ">> Removing temporary files ..."
   1.123 +	for i in `ls $VYMPATH/notes/$VYMNAME-note-*.txt 2>/dev/null`
   1.124 +	do
   1.125 +	  rm $i
   1.126 +	done
   1.127 +  
   1.128 +	for i in `ls $VYMPATH/images/$VYMNAME-image-*.* 2>/dev/null`
   1.129 +	do
   1.130 +	  rm $i
   1.131 +	done
   1.132 +  
   1.133 +	rm $VYMPATH/$VYMFILE".xml" 2>/dev/null
   1.134 +  fi
   1.135 +}
   1.136 +
   1.137 +
   1.138 +reducesize()
   1.139 +{
   1.140 +  # optional: reducing image-size
   1.141 +  echo ">> reducing image size to 256 colors ..."
   1.142 +  convert -colors 255 $VYMPATH/images/$VYMFILE".png" $VYMPATH/images/$VYMFILE".png"
   1.143 +}
   1.144 +
   1.145 +
   1.146 +# -------------------- Parameter check -----------------------
   1.147 +GENIMAGEP=""
   1.148 +IMAGEONLYP=""
   1.149 +WIKISTYLEP=""
   1.150 +STYLESHEETP=""
   1.151 +CSSFILE="vym.css"
   1.152 +
   1.153 +USAGE="USAGE:\t`basename $0`  vymfile.[vym|xml]  -sp=\077  [Options]\n
   1.154 +\t-sp=\077: absolute stylesheet path (including name of stylesheet)\n
   1.155 +Output:\tvymfile.html\n\n
   1.156 +Options:\n
   1.157 +-image: creates a clickable image at the beginning of the HTML-output\n
   1.158 +-imageonly: creates a clickable image without further HTML-output\n
   1.159 +-URLHeading: if set, URLs will show the heading\n
   1.160 +-URLImage: if set, URLs will show the globe visible in the map\n
   1.161 +-css=\077: tell vym2html to use this CSS-file, default is '$CSSFILE'\n
   1.162 +-v: prints the version of vym2html\n
   1.163 +-wikistyle: activates some wiki-shortcuts\n
   1.164 +\tWiki-style notation overview: \n
   1.165 +\tLines:\n
   1.166 +\t+ Big headlines start with the '+' character.\n
   1.167 +\t- Small headlines start with the '-' character.\n
   1.168 +\t  Normal text doesn't have any starting notation.\n
   1.169 +\t! Notes start with an exclamation.\n
   1.170 +\t. Indented text starts with a dot.\n
   1.171 +\t\077 Questions start with a question-mark, and\n
   1.172 +\t= Answers starts with the equal-sign.\n
   1.173 +\t\052 Points for a item-list\n
   1.174 +\t# clues\n
   1.175 +\n
   1.176 +\tLinks:\n
   1.177 +\tuse '{...}' or '{(Clemens homepage) http://www.clemens-kraus.de/}'\n\tfor external links.\n
   1.178 +\n
   1.179 +\tMarkup:\n
   1.180 +\t|This is bold| text, while |/this text is italic|, \n\t|*this is pre-formatted|, and |!this is a note|"
   1.181 +
   1.182 +if [ "$1" = '-v' ]; then
   1.183 +	  echo "vym2html Version: "$VERSION
   1.184 +	  exit 0
   1.185 +fi
   1.186 +
   1.187 +
   1.188 +if [ $# -lt 2  ]; then 
   1.189 +	echo -e $USAGE
   1.190 +	exit 1
   1.191 +else
   1.192 +	VYMFILE_EXT=$1
   1.193 +	VYMNAME=`echo $VYMFILE_EXT | sed "s/.*\///" | sed "s/\\..*$//"`
   1.194 +	VYMPATH=`dirname $VYMFILE_EXT`
   1.195 +fi
   1.196 +
   1.197 +shift 1
   1.198 +
   1.199 +for arg do
   1.200 +  if [ "$arg" = '-wikistyle' ]; then
   1.201 +	  WIKISTYLEP="yes"
   1.202 +  elif [ "$arg" = '-image' ]; then
   1.203 +	  GENIMAGEP="yes"
   1.204 +  elif [ "$arg" = '-imageonly' ]; then
   1.205 +	  IMAGEONLYP="yes"
   1.206 +	  GENIMAGEP="yes"
   1.207 +  elif [ ${arg:0:3} = '-sp' ]; then			# take first 3 chars
   1.208 +	  STYLESHEETP=`echo $arg | cut -d= -f2`
   1.209 +  elif [ ${arg:0:4} = '-css' ]; then		# take first 4 chars
   1.210 +	  CSSFILE=`echo $arg | cut -d= -f2`
   1.211 +  elif [ $arg = "-useURLHeading" ]; then
   1.212 +		URLHEADING="yes"		
   1.213 +  elif [ $arg = "-useURLImage" ]; then
   1.214 +		URLIMAGE="yes"		
   1.215 +  elif [ "$arg" = '-help' ]; then
   1.216 +	echo -e $USAGE
   1.217 +	exit 1
   1.218 +  else
   1.219 +	echo -e $USAGE
   1.220 +	exit 1
   1.221 +  fi
   1.222 +done
   1.223 +
   1.224 +#Debugging
   1.225 +echo VYMFILE_EXT=$VYMFILE_EXT
   1.226 +echo VYMNAME=$VYMNAME
   1.227 +echo VYMPATH=$VYMPATH
   1.228 +#echo WIKISTYLEP=$WIKISTYLEP
   1.229 +
   1.230 +
   1.231 +# ---------------------- Los geht's --------------------------
   1.232 +echo ">> Processing file '$VYMFILE_EXT' ..."
   1.233 +
   1.234 +# Unpack vym-file
   1.235 +unpacker
   1.236 +
   1.237 +# Modify "*-note-x.txt" files
   1.238 +txt2html
   1.239 +
   1.240 +# Transform
   1.241 +transform
   1.242 +
   1.243 +#reducesize
   1.244 +
   1.245 +# clean up
   1.246 +remove_files
   1.247 +
   1.248 +echo ">> Ready!"
   1.249 +echo ">> ---------------------"
   1.250 +
   1.251 +exit 0
   1.252 +
   1.253 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/scripts/vym2txt.sh	Sun Jan 30 12:59:07 2005 +0000
     2.3 @@ -0,0 +1,144 @@
     2.4 +#!/bin/sh
     2.5 +#
     2.6 +# vym2txt.sh
     2.7 +#
     2.8 +VERSION="0.11"
     2.9 +# Date: 20040417
    2.10 +# Author: Clemens Kraus (http://www.clemens-kraus.de)
    2.11 +#
    2.12 +#echo $@
    2.13 +
    2.14 +
    2.15 +unpacker()
    2.16 +# Unpack vym-file, only if it is one
    2.17 +{
    2.18 +  echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null
    2.19 +
    2.20 +  if [ $? = 0 ] ; then
    2.21 +	  echo ">> Unpacking files ..."
    2.22 +	  unzip $VYMFILE_EXT -d $VYMFILE_PATH 1>/dev/null
    2.23 +	  if [ $? -gt 0 ] ; then
    2.24 +		echo ">>> Error in unzip! Aborting."
    2.25 +	  	exit 4
    2.26 +	  fi
    2.27 +  fi
    2.28 +}
    2.29 +
    2.30 +
    2.31 +txt2xml()
    2.32 +# change all txt-files into xml-format
    2.33 +{
    2.34 +  for i in `ls $VYMFILE-note-*.txt 2>/dev/null`
    2.35 +  do
    2.36 +    # Check whether already modified
    2.37 +	grep "<note>" $i 1>/dev/null
    2.38 +	
    2.39 +	if [ $? -gt 0 ] ; then
    2.40 +	  echo ">> Modifying: "$i
    2.41 +	  # Each line gets an additional <line>-tag, because of the indents!
    2.42 +	  sed -e 's,^,<line><![CDATA[,g' -e 's,$,]]>\&#xA;</line>,g' $i > $i"_tmp"
    2.43 +	  
    2.44 +	  #cp $i $i"_tmp"
    2.45 +	  echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>" > $i
    2.46 +	  echo "<note>" >> $i
    2.47 +	  #echo "<![CDATA[" >> $i
    2.48 +	  cat $i"_tmp" >> $i
    2.49 +	  #echo "]]>" >> $i
    2.50 +	  echo "</note>" >> $i
    2.51 +  
    2.52 +	  rm $i"_tmp"
    2.53 +	fi
    2.54 +  done
    2.55 +}
    2.56 +
    2.57 +
    2.58 +transform()
    2.59 +{
    2.60 +  echo ">> Starting XSLT transformation ..."
    2.61 +# sabcmd vym2html.xsl $VYMFILE".xml"  \$filenamep=$VYMFILE \$wikistylep=$WIKISTYLEP \$genimagep=$GENIMAGEP \$stylesheetp=$STYLESHEETP > $VYMFILE".html"
    2.62 +  xsltproc -o $VYMFILE".txt" --stringparam filenamep `pwd`/"$VYMFILE" `dirname $STYLESHEETP`/vym2txt.xsl  $VYMFILE".xml"
    2.63 +  
    2.64 +  if [ $? -gt 0 ] ; then
    2.65 +	  echo ">>> Error in xsltproc! Aborting."
    2.66 +	  exit 3
    2.67 +  fi
    2.68 +}
    2.69 +
    2.70 +
    2.71 +remove_files()
    2.72 +# remove all temporary unpacked vym-files
    2.73 +{
    2.74 +  echo $VYMFILE_EXT | grep -F ".vym" 1>/dev/null
    2.75 +	
    2.76 +  if [ $? = 0 ] ; then
    2.77 +	echo ">> Removing temporary files ..."
    2.78 +	for i in `ls $VYMFILE-note-*.txt 2>/dev/null`
    2.79 +	do
    2.80 +	  rm $i
    2.81 +	done
    2.82 +  
    2.83 +	for i in `ls $VYMFILE-image-*.* 2>/dev/null`
    2.84 +	do
    2.85 +	  rm $i
    2.86 +	done
    2.87 +  
    2.88 +	rm $VYMFILE".xml" 2>/dev/null
    2.89 +  fi
    2.90 +}
    2.91 +
    2.92 +# -------------------- Parameter check -----------------------
    2.93 +STYLESHEETP=""
    2.94 +
    2.95 +USAGE="USAGE:\t`basename $0`  vymfile.[vym|xml]  -sp=\077  [Options]\n"
    2.96 +USAGE=$USAGE"\t-sp=\077: absolute stylesheet path (including name of stylesheet)\n"
    2.97 +USAGE=$USAGE"Output:\tvymfile.txt\n\n"
    2.98 +USAGE=$USAGE"Options:\n"
    2.99 +USAGE=$USAGE"-v: prints the version of vym2txt\n"
   2.100 +
   2.101 +if [ "$1" = '-v' ]; then
   2.102 +	  echo "vym2txt Version: "$VERSION
   2.103 +	  exit 0
   2.104 +fi
   2.105 +if [ $# -lt 1 -o $# -gt 2 -o "$1" = '-help' ]; then 
   2.106 +	echo -e $USAGE
   2.107 +	exit 1
   2.108 +else
   2.109 +	VYMFILE_EXT=$1
   2.110 +	VYMFILE=`echo $VYMFILE_EXT | cut -d. -f1`
   2.111 +	VYMFILE_PATH=`dirname $VYMFILE_EXT`
   2.112 +fi
   2.113 +
   2.114 +for arg in $2
   2.115 +do
   2.116 +  if [ ${arg:0:3} = '-sp' ]; then		# take first 3 chars
   2.117 +	  STYLESHEETP=`echo $arg | cut -d= -f2`
   2.118 +  elif [ "$arg" = '-help' ]; then
   2.119 +	echo -e $USAGE
   2.120 +	exit 1
   2.121 +  else
   2.122 +	echo -e $USAGE
   2.123 +	exit 1
   2.124 +  fi
   2.125 +done
   2.126 +
   2.127 +
   2.128 +# ---------------------- Los geht's --------------------------
   2.129 +echo ">> Processing file '$VYMFILE_EXT' ..."
   2.130 +
   2.131 +# Unpack vym-file
   2.132 +unpacker
   2.133 +
   2.134 +txt2xml
   2.135 +
   2.136 +# Transform
   2.137 +transform
   2.138 +
   2.139 +# clean up
   2.140 +remove_files
   2.141 +
   2.142 +echo ">> Ready!"
   2.143 +echo ">> ---------------------"
   2.144 +
   2.145 +exit 0
   2.146 +
   2.147 +