#!/usr/bin/env perl

#---------------------------------------------------------------------
#                           important note
#---------------------------------------------------------------------

# This software is provided on an  AS IS basis with ABSOLUTELY NO WAR-
# RANTY.  The  entire risk as to the  quality and  performance of  the
# software is with you.  Should the software prove defective,  you as-
# sume the cost of all necessary  servicing, repair or correction.  In
# no event will any of the developers,  or any other party, be  liable
# to anyone for damages arising out of use of the software, or inabil-
# ity to use the software.

#---------------------------------------------------------------------
#                            module setup
#---------------------------------------------------------------------

require 5.16.1  ;
use strict      ;
use Carp        ;
use warnings    ;
                                # Trap warnings
$SIG{__WARN__} = sub { die @_; };

#---------------------------------------------------------------------
#                           basic constants
#---------------------------------------------------------------------

use constant ZERO  => 0;        # Zero
use constant ONE   => 1;        # One
use constant TWO   => 2;        # Two

use constant FALSE => 0;        # Boolean FALSE
use constant TRUE  => 1;        # Boolean TRUE

#---------------------------------------------------------------------
#                         program parameters
#---------------------------------------------------------------------

my $PURPOSE  = 'ZIM ID to web-page display';
my $REVISION = '260505';

#---------------------------------------------------------------------
#                            main routine
#---------------------------------------------------------------------

sub Main
{
    select STDERR; $| = ONE;    # Force STDERR flush on write
    select STDOUT; $| = ONE;    # Force STDOUT flush on write

    my $LACARCH =  $ENV {'LACARCH'};
       $LACARCH =  "" unless defined $LACARCH;

    my $browser =  'uchromium';
       $browser =  'minibrowser' if $LACARCH eq 'glibc32';

    my $target  =  shift (@ARGV);
       $target  =  "" unless defined $target;
       $target  =~ s@^\s+@@;
       $target  =~ s@\s+\z@@s;

    if (length ($target))
    {
        die unless $target =~ m@^[a-z0-9._-]+\z@i;
        $target = "http://localhost:3500/viewer#$target";
    }
    else
    {
        $target = "http://localhost:3500/";
    }

    exec $browser, $target;
}

#---------------------------------------------------------------------
#                            main program
#---------------------------------------------------------------------

&Main();                        # Call the main routine
exit ZERO;                      # Normal exit
