aboutsummaryrefslogtreecommitdiff
path: root/src/wrappers/common.sh
diff options
context:
space:
mode:
authorroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-12 07:04:09 +0000
committerroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-12 07:04:09 +0000
commit426cbadfef6c26323faedcab2cd5ea7efa64d1bb (patch)
treee16afb28eec790226a7b0524b8fb325594232e5c /src/wrappers/common.sh
parent6411ea7466f67f94816c541a22abb7249d36c377 (diff)
downloadpandoc-426cbadfef6c26323faedcab2cd5ea7efa64d1bb.tar.gz
Merge changes in branches/wrappers into trunk.
[in trunk] svn merge -r105:HEAD \ https://pandoc.googlecode.com/svn/branches/wrappers git-svn-id: https://pandoc.googlecode.com/svn/trunk@177 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/wrappers/common.sh')
-rw-r--r--src/wrappers/common.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/wrappers/common.sh b/src/wrappers/common.sh
new file mode 100644
index 000000000..99a83be50
--- /dev/null
+++ b/src/wrappers/common.sh
@@ -0,0 +1,56 @@
+THIS=${0##*/}
+
+NEWLINE='
+'
+WRAPPER_ARGS=
+WRAPPEE_ARGS=
+
+err () { echo "$*" | fold -s -w ${COLUMNS:-110} >&2; }
+errn () { printf "$*" | fold -s -w ${COLUMNS:-110} >&2; }
+
+usage () {
+ synopsis="$@"
+ err "Usage: $THIS $synopsis"
+ err "See $THIS(1) man file for details."
+}
+
+runpandoc () {
+ if [ -n "$WRAPPEE_ARGS" ]; then
+ # Unpack arguments that will be passed to pandoc.
+ oldifs="$IFS"; IFS="$NEWLINE"; set -- $WRAPPEE_ARGS "$@"; IFS="$oldifs"
+ case "$1" in --) shift;; esac # tolerate the existence of a leading '--'
+ fi
+
+ pandoc "$@"
+}
+
+# Portable which(1).
+pathfind () {
+ oldifs="$IFS"; IFS=':'
+ for _p in $PATH; do
+ if [ -x "$_p/$*" ] && [ -f "$_p/$*" ]; then
+ IFS="$oldifs"
+ return 0
+ fi
+ done
+ IFS="$oldifs"
+ return 1
+}
+
+HAVE_ICONV=
+if pathfind iconv; then
+ HAVE_ICONV=1
+ alias to_utf8='iconv -t utf-8'
+ alias from_utf8='iconv -f utf-8'
+else
+ err "Warning: iconv not present. Assuming UTF-8 character encoding."
+ alias to_utf8='cat'
+ alias from_utf8='cat'
+fi
+
+for p in pandoc $REQUIRED; do
+ pathfind $p || {
+ err "You need '$p' to use this program!"
+ exit 1
+ }
+done