From 2763382dd803916e34e6575904147d7e3594a7f6 Mon Sep 17 00:00:00 2001 From: roktas Date: Sun, 12 Nov 2006 21:17:06 +0000 Subject: 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 --- markdown2pdf | 53 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'markdown2pdf') 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 $? -- cgit v1.2.3