root/trunk/xml/lgt2txt.sh

Revision 4662, 4.3 KB (checked in by pmoura, 6 days ago)

Updated copyright notice.

  • Property svn:mime-type set to application/x-sh
  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1#!/bin/sh
2
3## ================================================================
4## Logtalk - Open source object-oriented logic programming language
5## Release 2.35.0
6##
7## Copyright (c) 1998-2009 Paulo Moura.        All Rights Reserved.
8## Logtalk is free software.  You can redistribute it and/or modify
9## it under the terms of the "Artistic License 2.0" as published by
10## The Perl Foundation. Consult the "LICENSE.txt" file for details.
11## ================================================================
12
13if ! [ "$LOGTALKHOME" ]; then
14    echo "The environment variable LOGTALKHOME should be defined first, pointing"
15    echo "to your Logtalk installation directory!"
16    echo "Trying the default locations for the Logtalk installation..."
17    if [ -d "/usr/local/share/logtalk" ]; then
18        LOGTALKHOME=/usr/local/share/logtalk
19        echo "... using Logtalk installation found at /usr/local/share/logtalk"
20    elif [ -d "/usr/share/logtalk" ]; then
21        LOGTALKHOME=/usr/share/logtalk
22        echo "... using Logtalk installation found at /usr/share/logtalk"
23    elif [ -d "/opt/local/share/logtalk" ]; then
24        LOGTALKHOME=/opt/local/share/logtalk
25        echo "... using Logtalk installation found at /opt/local/share/logtalk"
26    elif [ -d "/opt/share/logtalk" ]; then
27        LOGTALKHOME=/opt/share/logtalk
28        echo "... using Logtalk installation found at /opt/share/logtalk"
29    else
30        echo "... unable to locate Logtalk installation directory!"
31        echo
32        exit 1
33    fi
34    echo
35elif ! [ -d "$LOGTALKHOME" ]; then
36    echo "The environment variable LOGTALKHOME points to a non-existing directory!"
37    echo "Its current value is: $LOGTALKHOME"
38    echo "The variable must be set to your Logtalk installation directory!"
39    echo
40    exit 1
41fi
42export LOGTALKHOME
43
44if ! [ "$LOGTALKUSER" ]; then
45    echo "The environment variable LOGTALKUSER should be defined first, pointing"
46    echo "to your Logtalk user directory!"
47    echo "Trying the default location for the Logtalk user directory..."
48    export LOGTALKUSER=$HOME/logtalk
49    if [ -d "$LOGTALKUSER" ]; then     
50        echo "... using Logtalk user directory found at $LOGTALKUSER"
51    else
52        echo "... Logtalk user directory not found at default location. Creating a"
53        echo "new Logtalk user directory by running the \"cplgtdirs\" shell script:"
54        cplgtdirs
55    fi
56elif ! [ -d "$LOGTALKUSER" ]; then
57    echo "Cannot find \$LOGTALKUSER directory! Creating a new Logtalk user directory"
58    echo "by running the \"cplgtdirs\" shell script:"
59    cplgtdirs
60fi
61echo
62
63xslt="$LOGTALKUSER/xml/lgttxt.xsl"
64
65processor=xsltproc
66# processor=xalan
67# processor=sabcmd
68
69directory="."
70
71usage_help()
72{
73    echo
74    echo "This script converts all Logtalk XML documenting files in the"
75    echo "current directory to text files"
76    echo
77    echo "Usage:"
78    echo "  $0 -d directory -p processor"
79    echo "  $0 -h"
80    echo
81    echo "Optional arguments:"
82    echo "  -d output directory for the text files (default is $directory)"
83    echo "  -p XSLT processor (xsltproc, xalan, or sabcmd; default is $processor)"
84    echo "  -h help"
85    echo
86    exit 1
87}
88
89while getopts "d:p:h" Option
90do
91    case $Option in
92        d) d_arg="$OPTARG";;
93        p) p_arg="$OPTARG";;
94        h) usage_help;;
95        *) usage_help;;
96    esac
97done
98
99if [ "$d_arg" != "" ] && [ ! -d "$d_arg" ] ; then
100    echo "Error! directory does not exists: $d_arg"
101    usage_help
102    exit 1
103elif [ "$d_arg" != "" ] ; then
104    directory=$d_arg
105fi
106
107if [ "$p_arg" != "" ] && [ "$p_arg" != "fop" ] && [ "$p_arg" != "xep" ] && [ "$p_arg" != "xinc" ] ; then
108    echo "Error! Unsupported XSL-FO processor: $p_arg"
109    usage_help
110    exit 1
111elif [ "$p_arg" != "" ] ; then
112    processor=$p_arg
113fi
114
115if ! [ -e "./logtalk.dtd" ] ; then
116    cp "$LOGTALKHOME"/xml/logtalk.dtd .
117fi
118
119if ! [ -e "./custom.ent" ] ; then
120    cp "$LOGTALKUSER"/xml/custom.ent .
121fi
122
123if ! [ -e "./logtalk.xsd" ] ; then
124    cp "$LOGTALKHOME"/xml/logtalk.xsd .
125fi
126
127if [ `(ls *.xml | wc -l) 2> /dev/null` -gt 0 ] ; then
128    echo
129    echo "converting XML files to text files..."
130    for file in *.xml; do
131        echo "  converting $file"
132        name="`expr "$file" : '\(.*\)\.[^./]*$' \| "$file"`"
133        case "$processor" in
134            xsltproc)   eval xsltproc -o \"$directory\"/\"$name.txt\" \"$xslt\" \"$file\";;
135            xalan)      eval xalan -o \"$directory\"/\"$name.txt\" \"$file\" \"$xslt\";;
136            sabcmd)     eval sabcmd \"$xslt\" \"$file\" \"$directory\"/\"$name.txt\";;
137        esac
138    done
139    echo "conversion done"
140    echo
141else
142    echo
143    echo "No XML files exist in the current directory!"
144    echo
145fi
146
147rm -f logtalk.dtd
148rm -f logtalk.xsd
149
150exit 0
Note: See TracBrowser for help on using the browser.