blob: 422b2e7e16cfccb277265614d2fe455919035510 (
plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# Common functions for ePiX's shell scripts
#
PROG=$(basename $0)
# global variables for all scripts
EPIX_PID=$$
# Needn't be secure
EPIX_TEMPDIR=${PROG}-${EPIX_PID}
# Caution: Common logfile name for all ${PROG} processes in cwd,
# used until we've parsed command-line options. Will assign a
# unique name once we have an input file name.
EPIX_LOGFILE=${PROG}.log
if [ -f "${EPIX_LOGFILE}" ]; then rm -f "${EPIX_LOGFILE}"; fi
# These may need to be modified
declare -r SYSTEM_STDOUT=/dev/stdout
declare -r SYSTEM_STDERR=/dev/stderr
declare -r SYSTEM_DEVNULL=/dev/null
EPIX_STDOUT=$SYSTEM_DEVNULL
EPIX_STDERR=$SYSTEM_STDERR
declare EPIX_NOTFOUND
declare LATEX_PKGS
# in increasing order of severity
function ePiX_msg {
echo -e "$PROG: $@" | tee -a "$EPIX_LOGFILE" > "$EPIX_STDOUT"
}
function ePiX_warn {
echo -e "$PROG: WARNING: $@" | tee -a "$EPIX_LOGFILE" >"$EPIX_STDERR"
}
function ePiX_fail {
echo -e "$PROG: WARNING: $@" | tee -a "$EPIX_LOGFILE" >"$EPIX_STDERR"
if [ "$EPIX_OUTROOT" = "$EPIX_INROOT" ]; then unset EPIX_OUTROOT; fi
let failure=failure+1
}
function ePiX_die {
echo -e "$PROG: ERROR: $@" | tee -a "$EPIX_LOGFILE" >"$EPIX_STDERR"
echo -e "Transcript written on ${EPIX_LOGFILE}\n"
exit 1;
}
# Echo command to stderr/stdout and logfile, then run command
#
function ePiX_command {
ePiX_msg "$@"
("$@" 2>&1) | tee -a "$EPIX_LOGFILE" > "$EPIX_STDOUT"
}
# epix_parse_filename EPIX_INFILE MY_EXTENSIONS:
#
# Attempt to decompose EPIX_INFILE into EPIX_INROOT.EPIX_SUFFIX, with
# EPIX_SUFFIX in MY_EXTENSIONS, then check for existence of file.
# If EPIX_INFILE has no suffix, the first match (if any) wins.
# If no file is found, EPIX_NOTFOUND="yes"
#
function epix_parse_filename {
EPIX_INFILE="$1"
shift;
MY_EXTENSIONS="$@"
unset EPIX_INROOT
unset EPIX_SUFFIX
unset EPIX_NOTFOUND
local FOUND_CT=0
# Check for recognized extension
for EXT in $MY_EXTENSIONS; do
TMP_ROOT="${EPIX_INFILE%.$EXT}"
if [ "$EPIX_INFILE" = "$TMP_ROOT.$EXT" ]; then
EPIX_INROOT="$TMP_ROOT"
EPIX_SUFFIX="$EXT"
break
fi
done
# None found; were we given just the root?
if [ -z "$EPIX_SUFFIX" ]; then
EPIX_INROOT="${EPIX_INFILE%%.}"
# Search for (and count) completions
for EXT in $MY_EXTENSIONS; do
if [ -f "$EPIX_INROOT.$EXT" ]; then
if [ $FOUND_CT -eq 0 ]; then # first match wins
EPIX_INFILE="$EPIX_INROOT.$EXT"
EPIX_SUFFIX="$EXT"
fi
let FOUND_CT=FOUND_CT+1
fi
done
# no match
if [ $FOUND_CT -eq 0 ]; then EPIX_NOTFOUND="yes"; fi
# Found suffix, check for input file
else
if [ -f "$EPIX_INFILE" ]; then
let FOUND_CT=FOUND_CT+1
else
EPIX_NOTFOUND="yes"
fi
fi # if $EPIX_SUFFIX=""
# initialize logfile
EPIX_LOGFILE="${EPIX_INROOT}_${EPIX_SUFFIX}.log"
if [ -f "$EPIX_LOGFILE" ]; then rm "$EPIX_LOGFILE"; fi
touch "$EPIX_LOGFILE"
# Print status messages
ePiX_msg "Processing $EPIX_INFILE:"
if [ $FOUND_CT -eq 0 ]; then
ePiX_warn " No completion of \"$EPIX_INROOT\" found"
elif [ $FOUND_CT -ge 2 ]; then
ePiX_warn " Found $FOUND_CT completions of \"$EPIX_INROOT\", using $EPIX_INFILE"
elif [ "$EPIX_NOTFOUND" = "yes" ]; then
ePiX_warn " \"$EPIX_INFILE\" not found"
fi
} # end of epix_parse_filename
# Get extra LaTeX package names from file
function ePiX_usepackages()
{
TMP_PKGS=$(grep "%% usepackages " $1)
LATEX_PKGS=${TMP_PKGS#"%% usepackages "}
}
function ePiX_usage()
{
cat <<HELP
Usage: $1 [options] <file(s)>[$2]
HELP
}
function ePiX_version()
{
cat <<VERSION
$1 (ePiX 1.2.1)
Copyright (C) 2007 Andrew D. Hwang
VERSION
}
function ePiX_license()
{
cat <<LICENSE
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>
ePiX is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
LICENSE
}
function ePiX_bugreport()
{
my_decode="tr '[a-m][n-z]' '[n-z][a-m]'" # Mac OS X has no 'rot'
SPAMMY="<$(echo nujnat|$my_decode)@$(echo zngupf|$my_decode)."
SPAMMY="${SPAMMY}$(echo ubylpebff|$my_decode).$(echo rqh|$my_decode)>"
cat <<BUG
Please report bugs to $SPAMMY
BUG
}
|