summaryrefslogtreecommitdiff
path: root/support/acroread_new/acroread_new.pl
blob: bbca000d688e30b407ed39dc45f5b340085a059e (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
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q'
  if 0;
use strict;
$^W=1; # turn warning on
#
# acroread_new
#
# Copyright (C) 2002 Heiko Oberdiek.
#
# This program may be distributed and/or modified under the
# conditions of the LaTeX Project Public License, either version 1.2
# of this license or (at your option) any later version.
# The latest version of this license is in
#   http://www.latex-project.org/lppl.txt
# and version 1.2 or later is part of all distributions of LaTeX
# version 1999/12/01 or later.
#
# This file "acroread_new.pl" may be renamed to "acroread_new"
# for installation purposes.
#
# Documentation: acroread_new --help
#
my $file      = "acroread_new.pl";
my $program   = uc($&) if $file =~ /^([\w_]+)/;
my $version   = "1.0";
my $date      = "2002/01/10";
my $author    = "Heiko Oberdiek";
my $copyright = "Copyright (c) 2002 by $author.";
#
# History:
#   2002/01/10 v1.0: First version.
#

my $tempdir      = "/tmp";
my $basename     = "\L$program\E_$$";

my @acroreadoptions = ();
foreach(@ARGV) {
  if (/^--tempdir=(.*)$/) {
    $tempdir = $1;
    next;
  }
  if (/^--basename=(.*)$/) {
    $basename = $1;
    next;
  }
  if (/^--help$/) {
    print <<"END_OF_HELP";
$program $version, $date - $copyright

Function: If acroread is started again, it will use
  a previously started instance. Exiting acroread will
  close all windows that belongs to that instance.
  This script runs acroread with a changed name, so
  several instances of acroread can be started
  independently from each other.

Caution: ~/.acrorc is read and written by each
  acroread instance. That can cause problems,
  if several instances are closed at the same
  time, for example.

Syntax: \L$program\E [options] [arguments for acroread]

Options:
  --help             print usage
  --tempdir=<name>   directory <name> for temporary files ($tempdir)
  --basename=<name>  basename of the acroread instance ($basename)

The help screen of acroread is available by option "-help".

END_OF_HELP
    exit 0;
  }
  push(@acroreadoptions, $_);
}
$tempdir .= "/" unless $tempdir eq "" or $tempdir =~ /\/$/;

my $acroread_org = `which acroread`;
my $acroread_new = "$tempdir$basename.sh";
my $cmd_new      = "$tempdir$basename.bin";

sub clean {
  unlink($acroread_new);
  unlink($cmd_new);
}

$SIG{__DIE__} = \&clean;
$SIG{'HUP'}   = \&clean;
$SIG{'QUIT'}  = \&clean;
$SIG{'TERM'}  = \&clean;

open(IN, $acroread_org) or
    die "!!! Error: Cannot open `$acroread_org'!\n";
open(OUT, ">$acroread_new") or
    die "!!! Error: Cannot write `$acroread_new'!\n";

while (<IN>) {
  print OUT;
  if (/^ACRO_EXEC_CMD=/) {
    print OUT <<"ENDMARK";

\#
\# [$program] Make link for new acroread instance.
\#
ACRO_EXEC_CMD_NEW="$cmd_new"
ln -s "\$ACRO_EXEC_CMD" "\$ACRO_EXEC_CMD_NEW"
if [ -h "\$ACRO_EXEC_CMD_NEW" ] ; then
  ACRO_EXEC_CMD="\$ACRO_EXEC_CMD_NEW"
else
  echo "ERROR: Creation of symbolic link '\$ACRO_EXEC_CMD_NEW' failed."
  exit 1
fi

ENDMARK
  }
}
close(IN);
close(OUT);
chmod('0500', $acroread_new);

system("$acroread_new @acroreadoptions");

clean();

__END__