aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-11-12 21:17:06 +0000
committerroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-11-12 21:17:06 +0000
commit2763382dd803916e34e6575904147d7e3594a7f6 (patch)
treec87b10e109f87a7336b9b4022ef2da6314757290
parent8e5f3e684c13a4b48d0ed24a15560f2631fc8e93 (diff)
downloadpandoc-2763382dd803916e34e6575904147d7e3594a7f6.tar.gz
Replace which(1) in all wrappers with 'pathfind', a POSIX-compliant shell
function. Expand tabs to four spaces. git-svn-id: https://pandoc.googlecode.com/svn/trunk@94 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r--html2markdown23
-rw-r--r--latex2markdown21
-rw-r--r--markdown2html21
-rw-r--r--markdown2latex21
-rw-r--r--markdown2pdf53
5 files changed, 102 insertions, 37 deletions
diff --git a/html2markdown b/html2markdown
index 48232acbb..4320ce9b1 100644
--- a/html2markdown
+++ b/html2markdown
@@ -2,11 +2,24 @@
# converts html to markdown
# uses an available program to fetch URL and tidy to normalize it first
+pathfind () { # portable which(1), code taken from Debian Developer's Reference
+ OLDIFS="$IFS"
+ IFS=:
+ for _p in $PATH; do
+ if [ -x "$_p/$*" ]; then
+ IFS="$OLDIFS"
+ return 0
+ fi
+ done
+ IFS="$OLDIFS"
+ return 1
+}
+
for p in pandoc tidy; do
- which $p >/dev/null 2>&1 || {
- echo >&2 "You need '$p' to use this program!"
- exit 1
- }
+ pathfind $p || {
+ echo >&2 "You need '$p' to use this program!"
+ exit 1
+ }
done
if [ -z "$1" ] || [ -f $1 ]; then
@@ -17,7 +30,7 @@ else
# Treat given argument as an URL. Locate a
# sensible text based browser (note the order).
for p in wget lynx w3m curl links w3c; do
- if which $p >/dev/null 2>&1; then
+ if pathfind $p; then
DUMPER=$p
break
fi
diff --git a/latex2markdown b/latex2markdown
index e5e276d62..4f5efef83 100644
--- a/latex2markdown
+++ b/latex2markdown
@@ -1,11 +1,24 @@
#!/bin/sh -e
# runs pandoc to convert latex to markdown
+pathfind () { # portable which(1), code taken from Debian Developer's Reference
+ OLDIFS="$IFS"
+ IFS=:
+ for _p in $PATH; do
+ if [ -x "$_p/$*" ]; then
+ IFS="$OLDIFS"
+ return 0
+ fi
+ done
+ IFS="$OLDIFS"
+ return 1
+}
+
for p in pandoc; do
- which $p >/dev/null 2>&1 || {
- echo >&2 "You need '$p' to use this program!"
- exit 1
- }
+ pathfind $p || {
+ echo >&2 "You need '$p' to use this program!"
+ exit 1
+ }
done
iconv -t utf-8 $* | pandoc $PANDOC_OPTS -r latex -w markdown -s | iconv -f utf-8
diff --git a/markdown2html b/markdown2html
index d71e434b4..280c1cf90 100644
--- a/markdown2html
+++ b/markdown2html
@@ -1,11 +1,24 @@
#!/bin/sh -e
# converts markdown to HTML
+pathfind () { # portable which(1), code taken from Debian Developer's Reference
+ OLDIFS="$IFS"
+ IFS=:
+ for _p in $PATH; do
+ if [ -x "$_p/$*" ]; then
+ IFS="$OLDIFS"
+ return 0
+ fi
+ done
+ IFS="$OLDIFS"
+ return 1
+}
+
for p in pandoc; do
- which $p >/dev/null 2>&1 || {
- echo >&2 "You need '$p' to use this program!"
- exit 1
- }
+ pathfind $p || {
+ echo >&2 "You need '$p' to use this program!"
+ exit 1
+ }
done
iconv -t utf-8 $* | pandoc $PANDOC_OPTS | iconv -f utf-8
diff --git a/markdown2latex b/markdown2latex
index 59a467fbc..0fc2077cb 100644
--- a/markdown2latex
+++ b/markdown2latex
@@ -1,11 +1,24 @@
#!/bin/sh -e
# converts markdown to latex
+pathfind () { # portable which(1), code taken from Debian Developer's Reference
+ OLDIFS="$IFS"
+ IFS=:
+ for _p in $PATH; do
+ if [ -x "$_p/$*" ]; then
+ IFS="$OLDIFS"
+ return 0
+ fi
+ done
+ IFS="$OLDIFS"
+ return 1
+}
+
for p in pandoc; do
- which $p >/dev/null 2>&1 || {
- echo >&2 "You need '$p' to use this program!"
- exit 1
- }
+ pathfind $p || {
+ echo >&2 "You need '$p' to use this program!"
+ exit 1
+ }
done
iconv -t utf-8 $* | pandoc $PANDOC_OPTS -w latex -s | iconv -f utf-8
diff --git a/markdown2pdf b/markdown2pdf
index 4af407fb7..59c0ba634 100644
--- a/markdown2pdf
+++ b/markdown2pdf
@@ -1,34 +1,47 @@
#!/bin/sh
# converts markdown to latex, then uses latex to make a PDF
+pathfind () { # portable which(1), code taken from Debian Developer's Reference
+ OLDIFS="$IFS"
+ IFS=:
+ for _p in $PATH; do
+ if [ -x "$_p/$*" ]; then
+ IFS="$OLDIFS"
+ return 0
+ fi
+ done
+ IFS="$OLDIFS"
+ return 1
+}
+
for p in pandoc pdflatex; do
- which $p >/dev/null 2>&1 || {
- echo >&2 "You need '$p' to use this program!"
- exit 1
- }
+ pathfind $p || {
+ echo >&2 "You need '$p' to use this program!"
+ exit 1
+ }
done
outfile=
for option; do
if [ -n "$prev" ]; then
- eval "$prev=\$option"
- prev=
- shift
- continue
+ eval "$prev=\$option"
+ prev=
+ shift
+ continue
fi
optarg=$(expr "x$option" : 'x[^=]*=\(.*\)')
case $option in
-h | --h | --help )
- help=1
- shift ;;
+ help=1
+ shift ;;
-o | --o | --output )
- prev=outfile
- shift ;;
+ prev=outfile
+ shift ;;
-o=* | --o=* | --output=* )
- outfile=$optarg
- shift ;;
+ outfile=$optarg
+ shift ;;
-* ) echo >&2 "$0: unknown option: $option; aborting"
- exit 1 ;;
+ exit 1 ;;
* ) break ;;
esac
done
@@ -41,9 +54,9 @@ done
infile=$1
if [ -z "$outfile" ]; then
if [ -n "$infile" ]; then
- outfile=${infile%.*}.pdf
+ outfile=${infile%.*}.pdf
else
- outfile='stdin.pdf' # input is STDIN, since no argument given
+ outfile='stdin.pdf' # input is STDIN, since no argument given
fi
fi
@@ -61,9 +74,9 @@ pandoc $PANDOC_OPTS -w latex -s | \
iconv -f utf-8 > $TEMP/$BASE.tex && (
cd $TEMP
if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
- echo >&2 "LaTeX errors:"
- cat >&2 $BASE.log
- exit 1
+ echo >&2 "LaTeX errors:"
+ cat >&2 $BASE.log
+ exit 1
fi
) || exit $?