2014-12-22 17:41:53 -06:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# "Compile" BASIC macro file to LibreOffice-compatible xba file
|
|
|
|
|
|
|
|
# compile SRC DESTINATION
|
|
|
|
compile() {
|
2015-04-24 23:15:43 -05:00
|
|
|
# Escape XML &<>'"
|
|
|
|
src=`sed "s/\&/\&/g; s/</\</g; s/>/\>/g; s/'/\'/g; s/\"/\"/g" "$1"`
|
2014-12-22 17:41:53 -06:00
|
|
|
|
2015-04-24 23:15:43 -05:00
|
|
|
xbafile="$2"
|
|
|
|
name="`basename "$xbafile" \".xba\"`"
|
2014-12-22 17:41:53 -06:00
|
|
|
|
2015-04-24 23:15:43 -05:00
|
|
|
XBA_TEMPLATE='<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">\n<script:module xmlns:script="http://openoffice.org/2000/script" script:name="%s" script:language="StarBasic">\n%s\n</script:module>'
|
2014-12-22 17:41:53 -06:00
|
|
|
|
2015-04-24 23:15:43 -05:00
|
|
|
printf "$XBA_TEMPLATE" "$name" "$src" > "$xbafile"
|
2014-12-22 17:41:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$#" -ne 2 ]; then
|
|
|
|
echo "Usage: $0 SOURCE DESTINATION"
|
|
|
|
else
|
|
|
|
compile "$1" "$2"
|
|
|
|
fi
|