This file is indexed.

/usr/bin/regina-python is in regina-normal 4.90-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#!/usr/bin/perl -w
#
# Regina - A Normal Surface Theory Calculator
# Python Startup Script
#
# Copyright (c) 2002-2011, Ben Burton
# For further details contact Ben Burton (bab@debian.org).
#
# This script simply starts the Python interpreter and imports the Regina
# calculation engine, i.e., the module 'regina'.
#
# DO NOT EDIT THIS FILE DIRECTLY.  It has been automatically generated
# by configure and any changes will be overwritten.  Try editing
# regina-python.in instead.
#
# 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.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.

use strict;
use File::Basename;

# --- Constants. ---

# The program name.
my $prog_name = $0;

# Address to which questions should be emailed.
my $regina_support = "regina-user\@lists.sourceforge.net";

# Default verbosity level.
my $default_verbosity = 1;

# Local configuration files.
my $home = $ENV{HOME};
if (! $home) {
    $home = `echo ~`;
}
my $python_conf = $home . "/.regina-python";
my $libs_conf = $home . "/.regina-libs";

# --- Variables. ---

my $quiet = 0;
my $verbose = 0;
my $interactive = 0;
my $nolibs = 0;
my $regina_home = '';
my $runscript_py = '';
my $from_source = 0;
my $python_lib_dir = '';
my @python_libs;
my $script = '';
my @script_args;

# In the absence of any user-specified options, use the python
# command that corresponds to the original build environment.

my $python_cmd = "/usr/bin/python2.7";
if (not -e $python_cmd) {
    &warn("W: The python command used during the build was: $python_cmd.\n");
    &warn("W: This command does not appear to be available now in the runtime environment.\n");
    $python_cmd = '';
}

# --- Extract variables from the configuration file.

if (open(CONF, $python_conf)) {
    my @lines = <CONF>;
    chomp @lines;
    close(CONF);

    foreach my $line (@lines) {
        if ($line =~ /^\s*$/ or $line =~ /^\s*#/) {
            next;
        }
        if ($line =~ /^\s*([A-Za-z_]+)\s*=\s*$/) {
            &warn("W: Variable $1 is not assigned a value in $python_conf.\n");
            next;
        }
        if ($line =~ /^\s*([A-Za-z_]+)\s*=\s*(\S(.*\S)?)\s*$/) {
            # We have a configuration variable.
            if ($1 eq 'REGINA_VERBOSITY') {
                &setVerbosity($2);
            } elsif ($1 eq 'REGINA_PYTHON') {
                &setPythonCmd($2);
            } elsif ($1 eq 'REGINA_PYLIBDIR') {
                &setPythonLibDir($2);
            } elsif ($1 eq 'REGINA_HOME') {
                &setReginaHome($2);
            } else {
                &warn("W: Unknown variable $1 in $python_conf.\n");
            }
            next;
        }
        &warn("W: Bad line in $python_conf:\n$line\n");
    }
}

# --- Extract variables from the environment. ---

if ($ENV{REGINA_VERBOSITY}) {
    &setVerbosity($ENV{REGINA_VERBOSITY});
}
if ($ENV{REGINA_HOME}) {
    &setReginaHome($ENV{REGINA_HOME});
}
if ($ENV{REGINA_PYTHON}) {
    &setPythonCmd($ENV{REGINA_PYTHON});
}
if ($ENV{REGINA_PYLIBDIR}) {
    &setPythonLibDir($ENV{REGINA_PYLIBDIR});
}

# --- Parse the command-line options. ---

my $readingScriptArgs = 0;
foreach my $arg (@ARGV) {
    if ($readingScriptArgs) {
        push @script_args, $arg;
        next;
    }

    if ($arg eq '-q' or $arg eq '--quiet') {
        $quiet = 1;
        $verbose = 0;
        next;
    }

    if ($arg eq '-v' or $arg eq '--verbose') {
        $quiet = 0;
        $verbose = 1;
        next;
    }

    if ($arg eq '-i' or $arg eq '--interactive') {
        $interactive = 1;
        next;
    }

    if ($arg eq '-n' or $arg eq '--nolibs') {
        $nolibs = 1;
        next;
    }

    if ($arg =~ /^-/) {
        &usage("Unrecognised option: $arg");
    }

    # We must be onto the script.
    $script = $arg;
    $readingScriptArgs = 1;
}

if ($interactive and not $script) {
    &usage("The interactive option (-i, --interactive) can only be used with a script.");
}

# --- Check that the current options are reasonable. ---

my $prefix = "/usr";
my $exec_prefix = "/usr";
my $datadir = "/usr/share";
my $libdir = "/usr/lib";
my $package = "regina-normal";

if (! $regina_home) {
    my $prog_dir = dirname($prog_name);
    if ( -f "$prog_dir/cmake_install.cmake" and -f "$prog_dir/../CMakeCache.txt") {
        &info("I: Running from the source tree.\n");
        $from_source = 1;

        # Setting $regina_home is interesting, because we want things
        # from both the builddir and the srcdir.  Use both.
        my $builddir = "$prog_dir/..";
        my $srcdir = "/build/buildd/regina-normal-4.90";
        $srcdir =~ /^\// or $srcdir = "$prog_dir/$srcdir";

        &setReginaHome($builddir, $srcdir);
    } else {
        &info("I: Running from an installation.\n");
        &setReginaHome("$datadir/$package");
    }
}

if (! $python_cmd) {
    my $which_python;
    chomp($which_python = `which python`);
    if (! $which_python) {
        &err("E: A Python interpreter could not be found.\n");
        &err("E: Set \$REGINA_PYTHON to a Python interpreter (such as /usr/bin/python)\n");
        &err("E: and try again.\n");
        exit 1;
    }
    &setPythonCmd($which_python);
}

if (! $python_lib_dir) {
    &setPythonLibDir($from_source ? "$regina_home/python/" :
        "$libdir/$package/python");
}

# --- Find the default charset to use for filename encodings. ---

my $codeset = undef;
eval {
    require I18N::Langinfo;
    $codeset = I18N::Langinfo::langinfo(I18N::Langinfo::CODESET());
};
if (not defined $codeset) {
    &warn("W: Could not determine default character encoding for filenames.\n");
    &warn("W: Try setting \$LANG if this is causing problems.\n");
}

# --- Read the list of libraries to load. ---

if ($nolibs) {
    &info("I: Not loading user libraries, as requested on the command-line.\n");
} elsif (open(LIBS, $libs_conf)) {
    my @lines = <LIBS>;
    chomp @lines;
    close(LIBS);

    my $lib;
    foreach my $line (@lines) {
        if ($line =~ /^\s*#/) {
            next;
        }
        if ($line =~ /^\s*(\S(.*\S)?)\s*$/) {
            # Treat this as a library file.
            $lib = $1;

            # Libraries are stored in UTF-8; convert to a local encoding
            # if we know how.
            if (defined $codeset) {
                if (not defined eval {
                    require Encode;
                    Encode::from_to($lib = $1, 'utf8', $codeset);
                }) {
                    &warn("W: Could not convert filename $1 from UTF-8 to $codeset.\n");
                    $lib = $1;
                }
            }
            if (-e $lib) {
                &info("I: Adding library $lib.\n");
                push @python_libs, $lib;
            } else {
                &err("E: Python library $lib does not exist (found in $libs_conf).\n");
            }
        }
    }
}

# --- Go ahead and run the application. ---

&extendEnvVar('PYTHONPATH', $python_lib_dir);

if ($from_source) {
    # Since we're running from the source tree, we need to ensure that
    # the calculation engine library can be found.
    &extendEnvVar('LD_LIBRARY_PATH', "$regina_home/engine/");

    # MacOS users will need DYLD_LIBRARY_PATH also.
    &extendEnvVar('DYLD_LIBRARY_PATH', "$regina_home/engine/");
}

my @fullCommandLine = ( $python_cmd );

if ($script) {
    if (! -e $script) {
        &usage("E: The script $script could not be found.");
    }
    my @fullCommandLine = ( $python_cmd );
    $interactive and push @fullCommandLine, '-i';
    push @fullCommandLine, $runscript_py;
    push @fullCommandLine, @python_libs;
    push @fullCommandLine, ( '--', $script );
    push @fullCommandLine, @script_args;
    exec @fullCommandLine or &execError();
} else {
    my @fullCommandLine = ( $python_cmd, '-i', $runscript_py );
    push @fullCommandLine, @python_libs;
    exec @fullCommandLine or &execError();
}

# --- Helper routines. ---

# Set various configuration options.
#
sub setVerbosity() {
    &info("I: Setting verbosity to $_[0].\n");
    if ($_[0] eq '0') {
        $quiet = 1;
        $verbose = 0;
    } elsif ($_[0] eq '1') {
        $quiet = 0;
        $verbose = 0;
    } elsif ($_[0] eq '2') {
        $quiet = 0;
        $verbose = 1;
    } else {
        &err("E: The verbosity level $_[0] is not recognised.\n");
        &err("E: This should be 0 (errors), 1 (errors/warnings) or 2 (everything).\n");
    }
}
sub setPythonCmd() {
    &info("I: Setting python command to $_[0].\n");
    $python_cmd = $_[0];
}
sub setPythonLibDir() {
    &info("I: Setting python module directory to $_[0].\n");
    if ( ! -e "$_[0]/regina.so") {
        &err("E: The calculation engine module 'regina.so' could not be \n");
        &err("   found in the directory $_[0].\n");
        &err("E: Please set \$REGINA_PYLIBDIR to the directory containing\n");
        &err("   the module 'regina.so' and try again.\n");
        exit 1;
    }
    $python_lib_dir = $_[0];
}
sub setReginaHome() {
    # Set both $regina_home and $runscript_py.
    if (defined $_[1]) {
        # Interpret the two arguments as a "binary" home and a "source" home.
        # This makes sense when running out of the source tree.
        &info("I: Setting Regina home directories to ($_[0], $_[1]).\n");
        $regina_home = $_[0];
        $runscript_py = "$_[1]/python/runscript.py";
    } else {
        # Interpret the single argument as a traditional REGINA_HOME.
        # This makes sense when running out of a standard installation.
        &info("I: Setting Regina home directory to $_[0].\n");
        $regina_home = $_[0];
        $runscript_py = "$_[0]/internal/scripts/runscript.py";
    }

    # Sanity test.
    if ( ! -e $runscript_py) {
        &err("E: \$REGINA_HOME should be set to the Regina base directory.\n");
        &err("   This is the directory containing the 'scripts' subdirectory,\n");
        &err("   the 'icons' subdirectory and so on.\n");
        &err("E: It is currently set to $regina_home .\n");
        exit 1;
    }
}
sub extendEnvVar() {
    &info("I: Appending $_[1] to \$$_[0].\n");
    if ($ENV{$_[0]}) {
        $ENV{$_[0]} = "$_[1]:$ENV{$_[0]}";
    } else {
        $ENV{$_[0]} = $_[1];
    }
}

# Write the given message to stderr if verbose mode is on.
#
sub info {
    if ($verbose) {
        print STDERR $_[0];
    }
}
# Write the given message to stderr if quiet mode is off.
#
sub warn {
    if (! $quiet) {
        print STDERR $_[0];
    }
}

# Write the given message to stderr.
#
sub err {
    print STDERR $_[0];
}

# Display usage information and exit.
#
sub usage {
    my $msg = shift;
    defined($msg) and print STDERR "$msg\n\n";
    print STDERR "Usage: 1. $prog_name [ -q, --quiet | -v, --verbose ]\n";
    print STDERR "       2. $prog_name [ -q, --quiet | -v, --verbose ]\n";
    print STDERR "               [ -i, --interactive ] script [ script_args ... ]\n";
    exit 1;
}

# The python interpreter could not be started.
#
sub execError() {
    &err("E: An error occurred whilst trying to start the Python interpreter.\n");
    &err("E: Run '$prog_name --verbose' to see more detailed diagnostic output,\n");
    &err("   including the runtime options being used.\n");
    &err("E: If you still cannot resolve the problem, please mail\n");
    &err("   $regina_support for assistance.\n");
}