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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
#!/bin/bash
# -------------------------------------------------------------------
#
# Shell program to start an instance of "acroread" on localhost via
# "pdfopen" and call "pdfopen" again every time when catching the SIGUSR1
# signal. This provides the same behaviour as "xdvi" for reloading changed
# files. Acrobat Reader doesn't come with a "watch file" option, hence
# this workaround, sigh...
#
# Copyright 2005, Thorsten Bonow
# ( thorsten.bonow at post.rwth-aachen.de ).
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# Description:
#
#
#
# Usage:
#
# startacrobat [ -h | --help ] [PDF document]
#
# Options:
#
# -h, --help Display this help message and exit.
#
# Known Bugs:
#
# No other instance of Acrobat Reader should be running: this script kills
# all of them on exit!
#
# Revision History:
#
# 01/05/2005 Initial version, adapted from "startxpdf"
# 28/08/2005 Adapted to "pdfopen" and "acrobat"
# 01/14/2006 Use HUP or USR1 signal for update to be fully
# compatible with latexmk 3.07 and 3.08
# (modification by John Collins (collins at phys.psu.edu))
#
#
# -------------------------------------------------------------------
# -------------------------------------------------------------------
# Constants
# -------------------------------------------------------------------
PROGNAME=$(basename $0)
VERSION="0.95A"
ACRO_RELOAD_EXEC="pdfopen --file"
ACROBAT_EXEC="acroread"
# -------------------------------------------------------------------
# Functions
# -------------------------------------------------------------------
function clean_up
{
# -----------------------------------------------------------------------
# Function to kill remote instance of acrobat
# No arguments
# -----------------------------------------------------------------------
return
}
function error_exit
{
# -----------------------------------------------------------------------
# Function for exit due to fatal program error
# Accepts 1 argument:
# string containing descriptive error message
# -----------------------------------------------------------------------
echo "${PROGNAME}: ${1:-"Unknown Error"}" >&2
clean_up
exit 1
}
function graceful_exit
{
# -----------------------------------------------------------------------
# Function called for a graceful exit
# No arguments
# -----------------------------------------------------------------------
clean_up
exit
}
function usage
{
# -----------------------------------------------------------------------
# Function to display usage message (does not exit)
# No arguments
# -----------------------------------------------------------------------
echo "Usage: ${PROGNAME} [-h | --help] [PDF document]"
}
function helptext
{
# -----------------------------------------------------------------------
# Function to display help message for program
# No arguments
# -----------------------------------------------------------------------
local tab=$(echo -en "\t\t")
cat <<- -EOF-
${PROGNAME} ver. ${VERSION}
Shell program to start an instance of "acroread" on localhost via
"acro-reload" and call "acro-reload" again every time when catching the
SIGUSR1 signal. This provides the same behaviour as "xdvi" for reloading
changed files. Acrobat Reader doesn't come with a "watch file" option,
hence this workaround, sigh...
$(usage)
Options:
-h, --help Display this help message and exit.
-EOF-
}
function signal_handle
{
# -----------------------------------------------------------------------
# Function to handle signals
# Accepts 1 argument:
# signal_spec
# -----------------------------------------------------------------------
case $1 in
INT) echo "$PROGNAME: Program aborted by user" >&2
clean_up
exit
;;
TERM) echo "$PROGNAME: Program terminated" >&2
clean_up
exit
;;
USR1) echo "$PROGNAME: Reloading..." >&2
$ACRO_RELOAD_EXEC $PDF_FILE
;;
*) error_exit "$PROGNAME: Terminating on unknown signal"
;;
esac
}
# -------------------------------------------------------------------
# Program starts here
# -------------------------------------------------------------------
##### Command Line Processing #####
if [ "$1" = "--help" ]; then
helptext
graceful_exit
fi
while getopts ":h" opt; do
case $opt in
h ) helptext
graceful_exit ;;
* ) usage
clean_up
exit 1
esac
done
PDF_FILE="$1"
##### Initialization And Setup #####
# Trap TERM and INT signals and properly exit
trap "signal_handle TERM" TERM
trap "signal_handle INT" INT
# Trap HUP and USR1 signals for reloading the PDF document
# Convert to USR1
# (Note HUP is used by gv, and USR1 by xdvi, so both signals have precedent)
trap "signal_handle USR1" HUP USR1
##### Main Logic #####
$ACRO_RELOAD_EXEC $PDF_FILE
while [ 1 ];
do
# sleeps again after being interrupted by SIGUSR1, breaks if Acrobat Reader is
# killed
sleep 1
eval pgrep "-f" "$ACROBAT_EXEC" ">/dev/null" || break
done
graceful_exit
|