aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/asciidoc
blob: 9e0d1967e5db10b8947bf995f7b04b7cca553784 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env sh

set -e
#set -x

TEMP=$(getopt -o 'a:b:d:hso:nv' -l 'attribute:,backend:,doctype:,help,no-header-footer,out-file:,section-numbers,safe,theme:,verbose,version' -n asciidoc -- "$@")

if [ $? -ne 0 ]; then
	exit 1
fi

eval set -- "$TEMP"
unset TEMP

NO_HEADER_FOOTER=0
OUT_DIR=
OUT_FILE=
SAFE=0
VERBOSE=0

while true; do
	case "$1" in
		'-a'|'--attribute')
			echo 'The option -a|--attribute is currently ignored.' >&2
			shift 2 ;;
		'-b'|'--backend')
			echo 'The option -b|--backend is currently ignored.' >&2
			shift 2 ;;
		'-d'|'--doctype')
			echo 'The option -d|--doctype is currently ignored.' >&2
			shift 2 ;;
		'-h'|'--help')
			echo 'TODO'
			exit 0 ;;
		'-s'|'--no-header-footer')
			NO_HEADER_FOOTER=1
			shift ;;
		'-o'|'--out-file')
			OUT_DIR=`dirname $2`
			OUT_FILE=`basename ${2%.*}`
			shift 2 ;;
		'-n'|'--section-numbers')
			echo 'The option -n|--section-numbers is currently ignored.' >&2
			shift ;;
		'--safe')
			SAFE=1
			shift ;;
		'--theme')
			echo 'The option --theme is currently ignored.' >&2
			shift ;;
		'-v'|'--verbose')
			VERBOSE=1
			shift ;;
		'--version')
			echo 'Asciideck compatibility script'
			exit 0 ;;
		'--')
			shift
			break ;;
		*)
			echo 'Unexpected error:' $1 >&2
			exit 1 ;;
	esac
done

IN_FILE=

case "$1" in
	'')
		echo 'No file name was provided. Use - for standard input.' >&2
		exit 1 ;;
	'-')
		PARSE_CALL="asciideck:parse_stdin()" ;;
	*)
		IN_FILE=$1
		PARSE_CALL="asciideck:parse_file(\"$IN_FILE\")" ;;
esac

if [ $IN_FILE -a -z $OUT_FILE ]; then
	OUT_DIR=`dirname $IN_FILE`
	OUT_FILE=`basename ${IN_FILE%.*}`
fi

if [ $OUT_FILE ]; then
	TRANSLATE_OPTS="#{outdir => \"$OUT_DIR\", outfile => \"$OUT_FILE\"}"
else
	TRANSLATE_OPTS="#{}"
fi

<&0 erl +A0 -boot no_dot_erlang -noshell -pz `dirname $0`/../ebin -eval " \
	case asciideck:to_html($PARSE_CALL, $TRANSLATE_OPTS) of \
		ok -> ok; \
		Output -> io:format(\"~s~n\", [Output]) \
	end, \
	halt()"