aboutsummaryrefslogtreecommitdiff
path: root/wrappers/common.sh
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-11-29 02:02:34 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-11-29 02:02:34 +0000
commit9a67a486c2dc98d14d9687ceb4b01befa09114df (patch)
tree42d2f11f5e39a2850934b1ee6e36003df5802993 /wrappers/common.sh
parent47a4a3ab897ab748a4b7eab2ccb95cd9cb0e3864 (diff)
downloadpandoc-9a67a486c2dc98d14d9687ceb4b01befa09114df.tar.gz
Moved everything from src into the top-level directory.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1104 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'wrappers/common.sh')
-rw-r--r--wrappers/common.sh43
1 files changed, 43 insertions, 0 deletions
diff --git a/wrappers/common.sh b/wrappers/common.sh
new file mode 100644
index 000000000..9605f5940
--- /dev/null
+++ b/wrappers/common.sh
@@ -0,0 +1,43 @@
+THIS=${0##*/}
+
+NEWLINE='
+'
+
+err () { echo "$*" | fold -s -w ${COLUMNS:-110} >&2; }
+errn () { printf "$*" | fold -s -w ${COLUMNS:-110} >&2; }
+
+usage () {
+ err "$1 - $2" # short description
+ err "See the $1(1) man page for usage."
+}
+
+# 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
+}
+
+for p in pandoc $REQUIRED; do
+ pathfind $p || {
+ err "You need '$p' to use this program!"
+ exit 1
+ }
+done
+
+CONF=$(pandoc --dump-args "$@" 2>&1) || {
+ errcode=$?
+ echo "$CONF" | sed -e '/^pandoc \[OPTIONS\] \[FILES\]/,$d' >&2
+ [ $errcode -eq 2 ] && usage "$THIS" "$SYNOPSIS"
+ exit $errcode
+}
+
+OUTPUT=$(echo "$CONF" | sed -ne '1p')
+ARGS=$(echo "$CONF" | sed -e '1d')
+