"Fossies" - the Fresh Open Source Software Archive

Member "latex2html-2021.2/config/config.pl" (1 Jul 2021, 78594 Bytes) of package /linux/www/latex2html-2021.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "config.pl" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2021_vs_2021.2.

    1 #! /usr/bin/perl -w
    2 
    3 ###############################################################################
    4 # $Id: config.pl,v 1.49 2002/09/27 09:26:56 RRM Exp $
    5 #
    6 # config.pl
    7 #
    8 # Accompanies LaTeX2HTML
    9 #
   10 # Finds local configuration. Does a lot of checks to find external
   11 # programs. See the manual and the INSTALL file for further
   12 # documentation.
   13 #
   14 # Author: Marek Rouchal <marek@saftsack.fs.uni-bayreuth.de>
   15 #
   16 # This software is part of Latex2HTML, originally by Nikos Drakos
   17 # It is published under the GNU Public License and comes without any
   18 # warranty.
   19 #
   20 # You aren't supposed to edit this script. You can specify command line
   21 # options to customize it to your local setup.
   22 
   23 ###############################################################################
   24 # Changes History
   25 #
   26 # $Log: config.pl,v $
   27 # Revision 1.49  2002/09/27 09:26:56  RRM
   28 #  --  increased version number to  2002-2-1  (from 2002-2)
   29 #      else automatic package software complains about checksum mismatch
   30 #      whenever there is a change to *any* file in the distribution
   31 #
   32 # Revision 1.48  2002/08/20 11:33:54  RRM
   33 #  --  increase version to  2002-2, due to changes in  latex2html.pin
   34 #
   35 # Revision 1.47  2002/08/17 00:15:42  RRM
   36 #  --  fixed the order of the pnmcrop test:  ($vers >= 10 || $sub_vers > 10)
   37 #      Thanks to Shigeharu TAKENO  for this fix.  <shige@iee.niit.ac.jp>
   38 #
   39 # Revision 1.46  2002/07/10 12:18:00  RRM
   40 #  --  support netpbm version 10.x
   41 #      thanks to  Shigeharu TAKENO  for the patch
   42 #
   43 # Revision 1.45  2002/04/28 12:32:02  RRM
   44 #  --  handle $DVPSOPT and $ICONSERVER as variables configurable via prefs.pm
   45 #
   46 # Revision 1.44  2002/04/27 23:14:56  RRM
   47 #  --  forgot to uncomment the test for  ppmtojpeg  after testing
   48 #      now it will be found, for converting exotic formats to jpeg
   49 #
   50 # Revision 1.43  2002/04/27 11:31:23  RRM
   51 #      new release version:  2002-1
   52 #
   53 #  --  implements $LATEX2HTMLDIR (shared) and $LATEX2HTMLPLATDIR (unshared)
   54 #      puts unshared l2hconf.pm into $LATEX2HTMLPLATDIR (platform-specific)
   55 #      other modules into $LATEX2HTMLDIR (shareable across platforms)
   56 #
   57 #  --  checks for more graphics conversion utilities, for use with revised
   58 #       graphics.perl  and  graphicx.perl
   59 #
   60 # Revision 1.42  2002/04/10 00:32:40  RRM
   61 #  --  added directories starting /usr/share to the search path for GS
   62 #  --  default for library installation is now /usr/share/lib/latex2html
   63 #      (thanks to Nelson Beebe, Utah) for this improvement.
   64 #
   65 # Revision 1.41  2002/03/20 04:32:02  RRM
   66 #  --  change version number to  '2002'
   67 #
   68 # Revision 1.40  2002/02/28 19:25:21  RRM
   69 #  -- fixed bug in gs version, introduced with previous edit
   70 #
   71 # Revision 1.39  2002/02/23 23:56:57  RRM
   72 #  --  recognise Ghostscript PRE-RELEASE versions;
   73 #      thanks to David R. Morrison <drm@math.duke.edu>.
   74 #
   75 # Revision 1.38  2001/10/25 10:39:27  RRM
   76 #  --  pnmcrop -verbose  option only with versions  9.11+
   77 #
   78 # Revision 1.37  2001/10/18 10:37:53  RRM
   79 #  --  initialise $PNMCROPOPT, for *all* versions of pnmcrop
   80 #
   81 # Revision 1.36  2001/08/21 10:39:15  RRM
   82 #  --  use $PNMCROPOPT with versions v9.12+ of  pnmcrop
   83 #
   84 # Revision 1.35  2001/03/25 02:54:36  RRM
   85 #  --  fixed the pnmcrop version test: >11 instead of >12
   86 #  --  added the -sides  switch for these latest versions.
   87 #
   88 # Revision 1.34  2001/03/25 02:13:00  RRM
   89 #      This detects the new Netpbm utilities, versions 8.x --> v9.11 and later
   90 #   available from  sourceforge.org.
   91 #      For versions up to 9.11, a variable $PNMBLACK is set to ' -black ',
   92 #      to allow correct cropping of black cropping-bars.
   93 #      With versions v9.12 and later, we use:  pnmcrop -sides -verbose
   94 #      which make the -black redundant, and works also with colored bars.
   95 #
   96 # Revision 1.33  2000/12/21 08:16:46  RRM
   97 #  --  increased the version number to  2K.1beta
   98 #
   99 # Revision 1.32  2000/07/13 14:22:44  MRO
  100 #
  101 # -- fixed bug in Ghostscript detection. Enhanced it to work with 6.x
  102 #
  103 # Revision 1.31  2000/07/11 17:38:59  MRO
  104 #
  105 #
  106 # added support for Ghostscript tester releases
  107 #
  108 # Revision 1.30  1999/11/09 00:43:42  MRO
  109 #
  110 #
  111 # -- added some changes suggested on the mail list recently: mainly cleanup
  112 #    of -dir option
  113 # -- added installation support for latex2html styles
  114 #
  115 # Revision 1.29  1999/11/04 08:23:52  RRM
  116 #  --  recognise:  Aladdin Ghostscript <num>.<num>
  117 #
  118 # Revision 1.28  1999/11/03 12:45:30  RRM
  119 #  --  recognise  'BETA RELEASE' versions of Ghostscript
  120 #
  121 # Revision 1.27  1999/10/26 22:32:56  MRO
  122 #
  123 # -- added a credit
  124 # -- reworked parts of the INSTALL documentation
  125 # -- installation now tries to install styles
  126 #
  127 # Revision 1.26  1999/10/25 21:18:22  MRO
  128 #
  129 # -- added more configure options (Jens' suggestions)
  130 # -- fixed bug in regexp range reported by Achim Haertel
  131 # -- fixed old references in documentation (related to mail list/archive)
  132 #
  133 # Revision 1.25  1999/10/17 09:18:00  MRO
  134 #
  135 # -- Makefile now supports building of a *.zip container, too
  136 # -- enhanced config.pl to add drive letter on DOSish platforms
  137 #
  138 # Revision 1.24  1999/10/06 22:04:13  MRO
  139 #
  140 # -- texexpand: latex2html calls texexpand with the -out option instead of
  141 #    output redirection: this is safer on non-UNIX platforms
  142 # -- pstoimg: now there's no default cropping (useful for standalone
  143 #    conversions). latex2html was changes appropriately
  144 # -- minor cleanups in latex2html script and documentation
  145 #
  146 # Revision 1.23  1999/10/03 18:40:42  MRO
  147 #
  148 # -- some cleanups for beta2
  149 # -- "make check" now checks all Perl code
  150 #
  151 # Revision 1.22  1999/10/03 11:09:38  RRM
  152 #     v99.2 beta  the alpha has been stable for a long time now
  153 #     only minor errors have been reported recently
  154 #
  155 # Revision 1.21  1999/09/23 08:56:58  RRM
  156 #  --  this version should be "thread-safe" now
  157 #   --- there are no more *-globs . References are used throughout.
  158 #  --  UTF8 implemented completely, as an output encoding
  159 #  --  use of full entitity names is implemented as an output encoding
  160 #  --  mechanism available to choose whether to allow 8-bit chars in the
  161 #   output, or UTF8 or entity names or images
  162 #  --  implemented post-processing search for ,, << >> ligatures
  163 #
  164 # Revision 1.20  1999/09/14 22:02:02  MRO
  165 #
  166 # -- numerous cleanups, no new features
  167 #
  168 # Revision 1.19  1999/09/13 21:58:41  MRO
  169 #
  170 # -- replaces open_tags by reference open_tags_R, should now be transparent
  171 # -- added some more test stuff, enhanced Makefile
  172 # -- cleaned up README and INSTALL
  173 #
  174 # Revision 1.18  1999/09/09 00:30:58  MRO
  175 #
  176 #
  177 # -- removed all *_ where possible
  178 #
  179 # Revision 1.17  1999/08/31 23:04:22  MRO
  180 #
  181 # -- started to get rid of *_ etc, some parts are still open
  182 #
  183 # Revision 1.16  1999/08/30 22:45:09  MRO
  184 #
  185 # -- perl now reports line numbers respective to .pin file - eases
  186 #    code development!
  187 # -- l2hcfg.pm is installed, too for furtjer reference
  188 # -- some minor bugs (hopefully) fixed.
  189 #
  190 # Revision 1.15  1999/08/26 23:33:42  MRO
  191 #
  192 # -- added option to load l2hcfg.pm from previous installation
  193 # -- fixed a bunch of bugs reported by Stefan Klupsch (thanks!)
  194 #
  195 # Revision 1.14  1999/07/11 08:37:08  RRM
  196 #  --  advanced the alpha-number
  197 #  --  much better support for non-latin1 charsets and unicode entities
  198 #  --  added  techexpl.pl  extension for using IBM TechExplorer plug-in
  199 #
  200 # Revision 1.13  1999/07/10 10:14:02  RRM
  201 #  --  Revision 1.13 has some bug-fixes and implements file-markers,
  202 #   so that plug-ins may get the original LaTeX source inputs
  203 #
  204 # Revision 1.12  1999/06/24 07:30:45  MRO
  205 #
  206 #
  207 # -- remove DMBtest.db after config procedure (Linux)
  208 #
  209 # Revision 1.11  1999/06/24 07:28:59  MRO
  210 #
  211 #
  212 # -- removed L2HMODULE
  213 # -- fixed processing of -info switch
  214 # -- changed option order for dvips on win32 (thanks JCL)
  215 # -- bumped version to 99.2a8
  216 #
  217 # Revision 1.10  1999/06/10 23:00:01  MRO
  218 #
  219 #
  220 # -- fixed an artifact in the *ball icons
  221 # -- cleanups
  222 # -- option documentation added
  223 # -- fixed bug in color perl (determining path to rgb/crayola)
  224 #
  225 # Revision 1.9  1999/06/06 14:24:57  MRO
  226 #
  227 #
  228 # -- many cleanups wrt. to TeXlive
  229 # -- changed $* to /m as far as possible. $* is deprecated in perl5, all
  230 #    occurrences should be removed.
  231 #
  232 # Revision 1.8  1999/06/04 15:30:19  MRO
  233 #
  234 #
  235 # -- fixed errors introduced by cleaning up TMP*
  236 # -- made pstoimg -quiet really quiet
  237 # -- pstoimg -debug now saves intermediate result files
  238 # -- several fixes for OS/2
  239 #
  240 # Revision 1.7  1999/06/03 13:02:44  RRM
  241 #  --  merged fixes to latex2html collected over the past months
  242 #  --  new features include resizable images (in MSIE only, Netscape fails)
  243 #  --  allows customised treatment of theorem-like environments
  244 #  --  some fixes/improvements to styles/{alltt,amsmath,amstex,makeidx}.perl
  245 #   and minor edits to  versions/{html3_1,math,frame}.pl and others
  246 #
  247 # Revision 1.6  1999/06/03 12:15:49  MRO
  248 #
  249 #
  250 # - cleaned up the TMP / TMPDIR / TMP_ mechansim. Should work much the
  251 #   same now, but the code should be easier to understand.
  252 #
  253 # - cleaned up L2hos, added an INSTALLation FAQ, beautified the test
  254 #   document a little bit
  255 #
  256 # Revision 1.5  1999/06/01 06:55:41  MRO
  257 #
  258 #
  259 # - fixed small bug in L2hos/*
  260 # - added some test_mode related output to latex2html
  261 # - improved documentation
  262 # - fixed small bug in pstoimg wrt. OS2
  263 #
  264 # Revision 1.4  1999/05/31 07:49:13  MRO
  265 #
  266 #
  267 # - a lot of cleanups wrt. OS/2
  268 # - make test now available (TEST.BAT on Win32, TEST.CMD on OS/2)
  269 # - re-inserted L2HCONFIG environment
  270 # - added some new subs to L2hos (path2os, path2URL, Cwd)
  271 #
  272 # Revision 1.3  1999/05/21 06:49:06  MRO
  273 #
  274 #
  275 # -- first attempt to make things work out of the box on Win32. There
  276 #    are still problems with the directory/path separators
  277 #
  278 # Revision 1.2  1999/05/19 23:54:06  MRO
  279 #
  280 #
  281 # -- uniquified icons - some of them look a little bit strange, might
  282 #    need to be fixed.
  283 # -- got rid of unlink errors, cleaned up some cosmetics
  284 #
  285 # Revision 1.1  1999/05/11 06:10:03  MRO
  286 #
  287 #
  288 # - merged config stuff, did first tries on Linux. Simple document
  289 #   passes! More test required, have to ger rid of Warnings in texexpand
  290 #
  291 # Revision 1.27  1999/05/05 19:47:11  MRO
  292 #
  293 #
  294 # - many cosmetic changes
  295 # - final backup before merge
  296 #
  297 # Revision 1.26  1999/03/15 23:00:54  MRO
  298 #
  299 #
  300 # - moved L2hos modules to top level directory, so that no dir-
  301 #   delimiter is necessary in the @INC-statement.
  302 # - changed strategy for "shave": Do not rely on STDERR redirection any
  303 #   more (caused problems on at least Win32)
  304 #
  305 # Revision 1.25  1999/02/23 23:32:33  MRO
  306 #
  307 #
  308 # -- few changes for Win32
  309 #
  310 # Revision 1.24  1999/02/14 23:44:36  MRO
  311 #
  312 #
  313 # -- first attempt to fix Win32 problems
  314 #
  315 # Revision 1.23  1999/02/11 00:18:31  MRO
  316 #
  317 #
  318 # -- cleaned up warppers, TeXlive stuff and Makefile
  319 #
  320 # Revision 1.22  1999/02/10 01:37:14  MRO
  321 #
  322 #
  323 # -- changed os-dependency structure again - now neat OO modules are
  324 #    used: portable, extensible, neat!
  325 # -- some minor cleanups and bugfixes
  326 #
  327 # Revision 1.21  1998/12/12 16:39:16  MRO
  328 #
  329 #
  330 # -- cosmetic changes, reworked catching of STDERR in config.pl (Win32)
  331 # -- new configure opt --disable-paths
  332 # -- major cleanups
  333 #
  334 # Revision 1.20  1998/12/08 23:50:35  MRO
  335 #
  336 #
  337 # -- small change for Solaris
  338 # -- added new target test_pstoimg in Makefile
  339 # -- fixed bug in latex2html
  340 #
  341 # Revision 1.19  1998/12/07 23:19:59  MRO
  342 #
  343 #
  344 # -- added POD documentation to pstoimg and did a general cleanup
  345 # -- some finetuning of config procedure and modules
  346 #
  347 # Revision 1.18  1998/10/31 14:13:08  MRO
  348 # -- changed OS-dependent module loading strategy: Modules are now located in
  349 #    different (OS-specific) directories nut have the same name: Easier to
  350 #    maintain and cleaner code
  351 # -- Cleaned up config procedure
  352 # -- Extended makefile functionality
  353 #
  354 # Revision 1.17  1998/08/09 17:58:19  MRO
  355 # -- save update
  356 #
  357 # Revision 1.16  1998/07/01 19:35:00  MRO
  358 # -- added more wrapper templates, updated config.pl and pertially build.pl
  359 #
  360 # Revision 1.15  1998/06/30 23:12:14  MRO
  361 # -- Reworked os dependency setup, mainly for TeXlive integration.
  362 #    Started wrapper coding.
  363 #
  364 # Revision 1.14  1998/06/14 14:10:41  latex2html
  365 # -- Started to implement TeXlive configuration and better OS specific
  366 #    handling (Batch files)                              (Marek)
  367 #
  368 # Revision 1.13  1998/06/07 22:35:26  latex2html
  369 # -- included things I learned from the Win95 port to config procedure:
  370 #    GS_LIB, Win32 module calls, directory separator stuff, ... (Marek)
  371 #
  372 # Revision 1.12  1998/06/01 12:58:05  latex2html
  373 # -- Cleanup and cosmetics.
  374 #
  375 # Revision 1.11  1998/05/14 22:27:42  latex2html
  376 # -- more work on config procedure (Makefile, GS_LIB)
  377 # -- tested pstoimg in 98.1 environment successfully on Linux
  378 #
  379 # Revision 1.10  1998/05/06 22:31:20  latex2html
  380 # -- Enhancements to the config procedure: Added a "generic" target
  381 #    in the Makefile for the TeXlive CD (not perfect yet)
  382 # -- included test for kpsewhich / Web2C
  383 # -- included latest stuff from Override.pm into os_*.pm
  384 #
  385 # Revision 1.9  1998/03/23 23:42:31  latex2html
  386 # -- fixed bug in configure.in ($PERL)
  387 # -- fixed bug in config.pl (correct version numbering for dvips 5.58f)
  388 # -- removed obsolete install-sh (also from configure.in)
  389 #
  390 # Revision 1.8  1998/03/19 23:38:10  latex2html
  391 # -- made pstoimg plug-in compatible with old one (touchwood!)
  392 # -- cleaned up, added some comments
  393 # -- inserted version information output
  394 # -- incorporated patches to make OS/2 run better (thanks Uli)
  395 # -- updated Makefile: make, make test, make install should work now
  396 #
  397 # Revision 1.7  1998/03/17 23:26:44  latex2html
  398 # -- fixed some bugs in config.pl
  399 # -- first version of install.pl finished
  400 #
  401 # Revision 1.6  1998/03/16 23:33:08  latex2html
  402 # -- small quirk fixed (removal of DBM test files)
  403 #
  404 # Revision 1.5  1998/03/16 23:31:58  latex2html
  405 # -- lots of cosmetic changes and bugfixes, thanks to Uli Wortmann
  406 #    for OS/2 testing
  407 # -- start of install procedure; checks for installation paths implemented
  408 #
  409 # Revision 1.4  1998/03/12 23:04:15  latex2html
  410 # -- small change in DBM check (no more dot in database name)
  411 #
  412 # Revision 1.3  1998/03/11 23:44:06  latex2html
  413 # -- cleaned up config.pl and reworked dvips checks
  414 # -- got pstoimg.pin up to par with the regular pstoimg
  415 # -- cosmetic changes
  416 # -- runs now under Win95 with Fabrice Popineau's Win32 tools (gs, TeX,...)
  417 #
  418 # Revision 1.2  1998/03/02 23:38:44  latex2html
  419 # Reworked configuration procedure substantially. Fixed some killing bugs.
  420 # Should now run on Win32, too.
  421 # The file prefs.pm contains user-configurable stuff for DOS platforms.
  422 # UNIX users can override the settings with the configure utility (preferred).
  423 #
  424 # Revision 1.1  1998/02/14 19:31:57  latex2html
  425 # Preliminary checkin of configuration procedure
  426 #
  427 ###############################################################################
  428 
  429 package main;
  430 
  431 use strict;
  432 require 5.00305;
  433 use Cwd;
  434 use IO::File;
  435 
  436 use FindBin;
  437 use lib "$FindBin::Bin/..";
  438 use L2hos;
  439 
  440 #use diagnostics;
  441 use vars qw(%prefs %cfg %newcfg);
  442 
  443 # This is the central place to modify the release name and date!!!
  444 my $RELEASE = '2021.2';
  445 my $VERSION = 'Released July 1, 2021';
  446 
  447 # --------------------------------------------------------------------------
  448 # Open log
  449 # --------------------------------------------------------------------------
  450 
  451 # Use the same logfile as configure
  452 my $LOGFILE = 'config.log';
  453 my $LOG = new IO::File ">>$LOGFILE";
  454 logit("Cannot append to $LOGFILE: $!\n") unless(defined $LOG);
  455 
  456 # --------------------------------------------------------------------------
  457 # Parse command line
  458 # --------------------------------------------------------------------------
  459 
  460 my %opt;
  461 foreach (@ARGV) {
  462   # allow for two delimiting characters; DOS ignores '='!!!
  463   if(/^(\w+)[=+](.*)/) {
  464     $opt{$1} = $2 || '';
  465     # logit("Debug: $1 = +$2+\n");
  466   }
  467 }
  468 
  469 # --------------------------------------------------------------------------
  470 # Initialize
  471 # --------------------------------------------------------------------------
  472 
  473 # The name of the configuration file to create
  474 my $CFGFILE = 'cfgcache.pm';
  475 logit("\nconfig.pl, Release $RELEASE ($VERSION)\n");
  476 logit("Accompanies LaTeX2HTML, (C) 1999 GNU Public License.\n\n");
  477 
  478 # This hash contains the final configuration
  479 %newcfg = ('distver' => $RELEASE,
  480        'release_date' => $VERSION);
  481 
  482 # Try to read old config file; will be loaded to %cfg
  483 my $oldconfig = $opt{'OLDCONFIG'} || $CFGFILE;
  484 &checking("for old config file ($oldconfig)");
  485 if(eval "require '$oldconfig';" && %cfgcache::cfg) {
  486   &result('loaded');
  487   %cfg = %cfgcache::cfg;
  488   undef %cfgcache::cfg;
  489 } else {
  490   &result('not found (ok)');
  491   %cfg = ();
  492 }
  493 
  494 # --------------------------------------------------------------------------
  495 # Determine platform we are running on
  496 # --------------------------------------------------------------------------
  497 
  498 # Platform types are currently: unix dos win32 os2 macos
  499 
  500 &checking('for platform');
  501 
  502 my @paths = (); # Paths where executables are located
  503 my $dd = L2hos->dd; # The directory delimiter character (e.g. UNIX: "/")
  504 my $pathd = L2hos->pathd; # The path delimiter character (e.g. UNIX: ":")
  505 $newcfg{'plat'} = L2hos->plat;
  506 $newcfg{'NULLFILE'} = L2hos->nulldev;
  507 
  508 my $cwd = L2hos->Cwd(); # get the current directory
  509 #$cwd =~ s:/:$dd:g; # beautify the path delimiter(s)
  510 $cwd = cwd() unless(-d $cwd); # test if it still works :-)
  511 $newcfg{'srcdir'} = $cwd;
  512 
  513 # ----------------------------------------------------------------------------
  514 # win32: Windows 95, Windows NT
  515 # ----------------------------------------------------------------------------
  516 
  517 if(L2hos->plat eq 'win32') {
  518   &result("$^O (Windows 32 bit)");
  519   if($ENV{'PATH'}) {
  520     @paths = split(/\Q$pathd/,$ENV{'PATH'});
  521   } else {
  522     @paths = qw(.);
  523   }
  524 }
  525 
  526 # ----------------------------------------------------------------------------
  527 # dos: DOS, Windows 3.x
  528 # ----------------------------------------------------------------------------
  529 
  530 elsif(L2hos->plat eq 'dos') {
  531   &result("$^O (DOS/Windows 3.x)");
  532   if($ENV{'PATH'}) {
  533     @paths = split(/\Q$pathd/,$ENV{'PATH'});
  534   } else {
  535     @paths = qw(.);
  536   }
  537 }
  538 
  539 # ----------------------------------------------------------------------------
  540 # os2: OS/2
  541 # ----------------------------------------------------------------------------
  542 
  543 elsif(L2hos->plat eq 'os2') {
  544   &result("$^O (OS/2)");
  545   if($ENV{'PATH'}) {
  546     @paths = split(/\Q$pathd/,$ENV{'PATH'});
  547   } else {
  548     @paths = qw(.);
  549   }
  550 }
  551 
  552 # ----------------------------------------------------------------------------
  553 # macos: MacOS
  554 # ----------------------------------------------------------------------------
  555 
  556 # MRO: This is probably screwed, someone needs to test this
  557 
  558 elsif(L2hos->plat eq 'macOS') {
  559   &result("$^O (MacOS)");
  560   if($ENV{'PATH'}) {
  561     @paths = split(/\Q$pathd/,$ENV{'PATH'});
  562   } else {
  563     @paths = qw(.);
  564   }
  565 }
  566 
  567 # ----------------------------------------------------------------------------
  568 # unix: all UNIXes and clones
  569 # ----------------------------------------------------------------------------
  570 
  571 else { # unix
  572   &result("$^O (assuming $newcfg{plat})");
  573   if($ENV{'PATH'}) {
  574     @paths = split(/\Q$pathd/,$ENV{'PATH'});
  575   } else {
  576     @paths = qw(.);
  577   }
  578 }
  579 
  580 # --------------------------------------------------------------------------
  581 # Read preferences file
  582 #
  583 # This step is postponed to this point in order to allow platform dependent
  584 # configuration defaults in the preferences file.
  585 # --------------------------------------------------------------------------
  586 
  587 unless(require 'prefs.pm') {
  588   logit("Error: Preferences file not found.\n");
  589   cleanup(1);
  590   exit 1;
  591 }
  592 import prefs;
  593 
  594 # --------------------------------------------------------------------------
  595 # If we're running in TeXlive-Mode, copy the predefined cfgcache.pm and stop
  596 # --------------------------------------------------------------------------
  597 
  598 if(&is_true(&get_name('TEXLIVE'))) {
  599   &Copy('texlive.pm',$CFGFILE);
  600   logit("Writing predefined configuration file for TeXlive\n");
  601   exit 0;
  602 }
  603 
  604 # --------------------------------------------------------------------------
  605 # Add extra executable search path(s)
  606 # --------------------------------------------------------------------------
  607 
  608 my $extrapath = $opt{EXTRAPATH} || $prefs{EXTRAPATH} || '';
  609 @paths = grep(-d, uniquify(@paths, split(/\Q$pathd/,$extrapath)));
  610 #logit("DEBUG: EXTRAPATH=$extrapath\n");
  611 #logit("DEBUG: PATH=" . join(':',@paths) . "\n");
  612 
  613 # --------------------------------------------------------------------------
  614 # Perl Version
  615 #
  616 # The perl version is checked by the require command above; the following is
  617 # added for cosmetical reasons
  618 # --------------------------------------------------------------------------
  619 
  620 # only perl gets an absolute pathname
  621 my $abs_path_names = 1;
  622 if($opt{'PERL'}) {
  623   $newcfg{'PERL'} = &find_prog(&get_name('PERL',1));
  624 } else {
  625   $newcfg{'PERL'} = &find_prog($^X); # take the perl internal executable name
  626 }
  627 &checking('perl version');
  628 &result($]);
  629 
  630 # Read perl's own Config module
  631 # used to get path for perldoc
  632 use Config qw(%Config);
  633 $newcfg{PERLSCRIPTDIR} = $Config{scriptdir};
  634 
  635 # the other programs can live without
  636 $abs_path_names = &get_name('ABSPATHS');
  637 
  638 # --------------------------------------------------------------------------
  639 # DBM check
  640 # --------------------------------------------------------------------------
  641 
  642 &checking('if perl supports some dbm');
  643 
  644 my %array;
  645 unless(dbmopen(%array,'DBMtest',0755)) {
  646   my $err = $@ || 'dbmopen failed';
  647   &result('no');
  648   logit("Error: Perl reported DBM error: $err\nLaTeX2HTML needs some DBM.\n");
  649   cleanup(1);
  650   exit 1;
  651 }
  652 else {
  653   #JCL: we do not need to write sth into it, if Perl lacks DBM we
  654   # detected it with dbmopen before...
  655   dbmclose(%array);
  656   &result('yes');
  657 }
  658 unlink qw(DBMtest DBMtest.dir DBMtest.pag DBMtest.db); # ignore any errors
  659 
  660 # --------------------------------------------------------------------------
  661 # Globbing Check
  662 # --------------------------------------------------------------------------
  663 
  664 &checking('if perl globbing works');
  665 
  666 open(TMP,">TEST1.TMP"); close TMP; # create temporary test files
  667 open(TMP,">TEST2.TMP"); close TMP;
  668 my @list = (<TEST*.TMP>); # glob test
  669 unlink qw(TEST1.TMP TEST2.TMP); # remove temporary test files
  670 
  671 unless(grep(/^TEST[12]\.TMP$/i,@list) == 2) {
  672   &result('no');
  673   logit("  Cannot live without globbing\n");
  674   # Try to find out what is going wrong
  675   # Perl uses full_csh to perform globbing, this may change of course
  676   my $csh = eval {require 'Config.pm'; &Config::FETCH('','full_csh')};
  677   if($csh) {
  678     unless(-f $csh) {
  679       logit("Error: $csh does not exist\n");
  680     }
  681     elsif(!-x $csh) {
  682       logit("Error: $csh is not executable\n");
  683     }
  684     else {
  685       logit("Error: unknown globbing problem, check perl installation\n");
  686     }
  687   }
  688   else {
  689     logit("Error: perl globbing failed. Couldn't determine csh info.\n");
  690   }
  691   cleanup(1);
  692   exit 1;
  693 }
  694 else {
  695   &result('yes');
  696 }
  697 
  698 # --------------------------------------------------------------------------
  699 # Hashbang script starts
  700 # --------------------------------------------------------------------------
  701 
  702 $newcfg{'texlive'} = &is_true(&get_name('TEXLIVE'));
  703 $newcfg{'wrapper'} = &is_true(&get_name('WRAPPER'));
  704 
  705 $newcfg{'HASHBANG'} = 0;
  706 $newcfg{'exec_extension'} = '';
  707 $newcfg{'perl_starter'} = '';
  708 $newcfg{'PERLHEADER'} = '';
  709 $newcfg{'PERLFOOTER'} = '';
  710 
  711 # Unix: Use #! mechanism, if it works
  712 
  713 if($newcfg{'plat'} =~ /unix/i) {
  714   if(&is_true(&get_name('HASHBANG'))) {
  715     $newcfg{'PERLHEADER'} = "#! $newcfg{'PERL'} -w\n";
  716     $newcfg{'HASHBANG'} = 1;
  717   }
  718   else {
  719     # Hashbang script starts are not allowed; use this "killer" to
  720     # start the script on (almost) all sorts of shells...
  721     $newcfg{'PERLHEADER'} = <<"EOF";
  722 # -*- perl -*- -w
  723 eval '(exit \$?0)' && eval 'exec $newcfg{'PERL'} -S \$0 \${1+"\$\@"}'
  724   & eval 'exec $newcfg{'PERL'} -S \$0 \$argv:q'
  725   if 0; # suppress this stuff in perl
  726 EOF
  727     $newcfg{'perl_starter'} = $newcfg{'PERL'};
  728   }
  729 }
  730 
  731 # OS/2: Use the "extproc" mechanism
  732 
  733 elsif($newcfg{'plat'} =~ /os2/i) {
  734   $newcfg{'PERLHEADER'} = "extproc $newcfg{'PERL'} -S -w\n";
  735   $newcfg{'exec_extension'} = '.cmd';
  736   $newcfg{'perl_starter'} = $newcfg{'PERL'};
  737 }
  738 
  739 # DOS/Windows: Create BATch files
  740 
  741 elsif($newcfg{'plat'} =~ /dos|win32/i) {
  742   $newcfg{'PERLHEADER'} = <<"EOF";
  743 \@rem = '--*-Perl-*--
  744 \@echo off
  745 set arg=
  746 set prog=%0
  747 :one
  748 set arg=%*
  749 :two
  750 if exist %prog%.bat goto indot
  751 $newcfg{'PERL'} -x -S %prog% %arg%
  752 goto endofperl
  753 :indot
  754 $newcfg{'PERL'} -x %prog%.bat %arg%
  755 set arg=
  756 set prog=
  757 goto endofperl
  758 \@rem ';
  759 #! perl -w
  760 # line 21
  761 EOF
  762   $newcfg{'PERLFOOTER'} = <<"EOF";
  763 __END__
  764 :endofperl
  765 EOF
  766   $newcfg{'exec_extension'} = '.bat';
  767   $newcfg{'perl_starter'} = "$newcfg{'PERL'} -x";
  768 }
  769 
  770 # other OSes have no means for starting up scripts
  771 
  772 else {
  773   $newcfg{'PERLHEADER'} = "# -*- perl -*- -w\n";
  774   $newcfg{'perl_starter'} = $newcfg{'PERL'};
  775 }
  776 
  777 # --------------------------------------------------------------------------
  778 # Images
  779 #
  780 # Supported image output formats: GIF and PNG
  781 #
  782 # Note that the GIF format has some legal restrictions: Due to the usage
  783 # of LZW compression in the GIF format, that is licensed by Unisys, every
  784 # program creating GIFs has to have a license from Unisys when run for
  785 # commercial purposes.
  786 # --------------------------------------------------------------------------
  787 
  788 $opt{'have_pstoimg'} = 1; # be optimistic that pstoimg can be built
  789 $opt{'IMAGES'} = &is_true(&get_name('IMAGES'));
  790 $opt{'GIF'} = &is_true(&get_name('GIF'));
  791 $opt{'PNG'} = &is_true(&get_name('PNG'));
  792 $opt{'SVG'} = &is_true(&get_name('SVG'));
  793 
  794 unless($opt{'GIF'} || $opt{'PNG'}) {
  795   $opt{'IMAGES'} = 0;
  796   $opt{'have_pstoimg'} = 0;
  797   logit("Warning: Both GIF and PNG support disabled. LaTeX2HTML won't generate any images.\n");
  798 }
  799 
  800 # --------------------------------------------------------------------------
  801 # TeX, LaTeX, IniTeX, Web2C
  802 # --------------------------------------------------------------------------
  803 
  804 $newcfg{'TEX'} = '';
  805 
  806 if($opt{'IMAGES'}) {
  807   my $tex = &find_prog(&get_name('TEX',1));
  808   if($tex) {
  809     $newcfg{'TEX'} = $tex;
  810   }
  811 }
  812   
  813 $newcfg{'LATEX'} = '';
  814 
  815 if($opt{'IMAGES'}) {
  816   my $latex = &find_prog(&get_name('LATEX',1));
  817   if($latex) {
  818     $newcfg{'LATEX'} = $latex;
  819   }
  820   else {
  821     $opt{'IMAGES'} = 0;
  822     &warn_no_images();
  823   }
  824 }
  825   
  826 $newcfg{'PDFLATEX'} = '';
  827 
  828 if($opt{'IMAGES'}) {
  829   my $pdflatex = &find_prog(&get_name('PDFLATEX',1));
  830   if($pdflatex) {
  831     $newcfg{'PDFLATEX'} = $pdflatex;
  832   }
  833   else {
  834     $opt{'IMAGES'} = 0;
  835     &warn_no_images();
  836   }
  837 }
  838   
  839 $newcfg{'LUALATEX'} = '';
  840 
  841 if($opt{'IMAGES'}) {
  842   my $lualatex = &find_prog(&get_name('LUALATEX',1));
  843   if($lualatex) {
  844     $newcfg{'LUALATEX'} = $lualatex;
  845   }
  846   else {
  847     $opt{'IMAGES'} = 0;
  848     &warn_no_images();
  849   }
  850 }
  851   
  852 $newcfg{'DVILUALATEX'} = '';
  853 
  854 if($opt{'IMAGES'}) {
  855   my $dvilualatex = &find_prog(&get_name('DVILUALATEX',1));
  856   if($dvilualatex) {
  857     $newcfg{'DVILUALATEX'} = $dvilualatex;
  858   }
  859   else {
  860     $opt{'IMAGES'} = 0;
  861     &warn_no_images();
  862   }
  863 }
  864   
  865 $newcfg{'INITEX'} = '';
  866 
  867 if($opt{'IMAGES'}) {
  868   my $initex = &find_prog(&get_name('INITEX',1));
  869   if($initex) {
  870     $newcfg{'INITEX'} = $initex;
  871   }
  872 }
  873 
  874 $newcfg{'KPSEWHICH'} = '';
  875 $newcfg{'WEB2C'} = 0;
  876 my $kpath = '';
  877 
  878 my $kpsewhich = &find_prog(&get_name('KPSEWHICH',1));
  879 if($kpsewhich) {
  880   $newcfg{'KPSEWHICH'} = $kpsewhich;
  881   &checking('for kpsewhich syntax');
  882   my @try_opts = ('-show-path=tex', '-p tex');
  883   my $try;
  884   my $num = 1;
  885   foreach $try (@try_opts) {
  886     my ($stat,$out,$err) = &get_out_err("$kpsewhich $try");
  887     if($stat == 0) { # ok
  888       $newcfg{'WEB2C'} = $num;
  889       &result("ok (style=$num)");
  890       $kpath = $out;
  891       last;
  892     }
  893     $num++;
  894   }
  895   if(--$num > $#try_opts) {
  896     &result("no, from which planet is your kpsewhich?");
  897     $newcfg{'KPSEWHICH'} = '';
  898   }
  899 }
  900 
  901 &checking('for TeX include path');
  902 my $texpath = $opt{TEXPATH} || $prefs{TEXPATH} || '';
  903 if($texpath eq 'no') {
  904     $texpath = '';
  905 }
  906 elsif(!$texpath && $kpath) {
  907   my @texpaths = ();
  908   chomp($kpath);
  909   foreach(split(/\Q$pathd/,$kpath)) {
  910     s/^!+//; # strip leading !'s
  911     s:[/\\]+$::; # strip trailing path delims
  912     $_ = L2hos->path2os($_);
  913     if(L2hos->is_absolute_path($_) && -d) {
  914       push(@texpaths,$_);
  915     }
  916   }
  917   if(@texpaths > 1) {
  918     ($texpath) = grep(-d $_.$dd.'latex', @texpaths);
  919     $texpath = $texpaths[0] unless($texpath);
  920   } else {
  921     $texpath = $texpaths[0] || '';
  922   }
  923   if(-d $texpath.$dd.'latex') {
  924     $texpath .= $dd . 'latex';
  925   }
  926   if(-d $texpath.$dd.'latex2html') {
  927     $texpath .= $dd . 'latex2html';
  928   } else {
  929     $texpath .= $dd . 'html';
  930   }
  931 }
  932 unless($texpath) {
  933   logit("NONE\nWarning: Will not automatically install LaTeX2HTML style files.\n");
  934 } else {
  935   &result($texpath);
  936   # find the ls-R update tool
  937   $newcfg{'MKTEXLSR'} = &find_prog(&get_name('MKTEXLSR',1));
  938 }
  939 $newcfg{'TEXPATH'} = $texpath;
  940 
  941 # --------------------------------------------------------------------------
  942 # dvips
  943 #
  944 # This (and gs) is the most complicated setup feature. It is advisable to
  945 # get the latest version of dvips for best results, i.e. currently(?)
  946 # 5.76
  947 # --------------------------------------------------------------------------
  948 
  949 $newcfg{'DVIPS'} = '';
  950 $newcfg{'DVIPSOPT'} = $prefs{'DVIPSOPT'}||'';
  951 $newcfg{'PK_GENERATION'} = 0;
  952 $newcfg{'have_dvipsmode'} = '';
  953 $newcfg{'METAMODE'} = '';
  954 $newcfg{'METADPI'} = 0;
  955 
  956 if($opt{'IMAGES'}) {
  957   my $dvips = &find_prog(&get_name('DVIPS',1));
  958   if($dvips) {
  959     my @switches = '';
  960     &checking('dvips version');
  961     my $veropt;
  962     my $version = '';
  963 
  964     # Try to determine the version. Obstacles: output goes to STDOUT or
  965     # STDERR and can have different formats
  966 
  967     my @tryopts;
  968     if($newcfg{'plat'} eq 'os2') {
  969       # --version requires pressing \n on OS/2
  970       @tryopts = ('','--version','-?','-v');
  971     } elsif($newcfg{'plat'} eq 'win32') {
  972       # --version requires pressing \n on MikTeX
  973       @tryopts = ('','--version','-?','-v');
  974     } else {
  975       @tryopts = ('--version','','-?','-v');
  976     }
  977     foreach $veropt (@tryopts) {
  978       my ($stat,$msg,$err) = &get_out_err("$dvips $veropt");
  979       $msg .= $err || '';
  980       if(!$stat && $msg =~ /(?:^| )dvips(?:\(k\)|k|)\s*(\d+[.]?\d*[A-Z]?)/is) {
  981         $version = $1;
  982         last;
  983       }
  984     }
  985     unless($version) {
  986       $opt{'IMAGES'} = 0;
  987       &result('no');
  988       logit(qq{Error: could not determine dvips version\n});
  989       &warn_no_images();
  990     }
  991     else {
  992       &result($version);
  993       my $numeric = $version;
  994       # convert letter minor number to decimal
  995       if($numeric =~ /(\d+[.]?\d*)([A-Z])/i) {
  996         my ($primary,$secondary) = ($1,$2);
  997         if($secondary) {
  998           $secondary = unpack('C',uc($2))-unpack('C','A')+1;
  999           $secondary = "0$secondary" if($secondary < 10);
 1000         }
 1001         else {
 1002           $secondary = '00';
 1003         }
 1004         $numeric = "$primary$secondary";
 1005       }
 1006       if($numeric < 5.516) {
 1007         logit(<<"EOF");
 1008 Warning: This dvips version does not support all features requested by pstoimg.
 1009          It is recommended to upgrade to a more recent version.
 1010 EOF
 1011       }
 1012       &checking('if dvips supports the combination of -E and -i -S 1');
 1013       # this option is available since 5.62
 1014       if($numeric > 5.61 && &is_true(&get_name('EPS'))) {
 1015         push(@switches, '-E');
 1016         &result('yes');
 1017       }
 1018       else {
 1019         &result('no');
 1020       }
 1021       if(&is_true(&get_name('REVERSE'))) {
 1022         push(@switches, '-r0');
 1023       }
 1024       $newcfg{'DVIPS'} = $dvips;
 1025       $newcfg{'DVIPSOPT'} .= join(' ','',@switches) if (@switches);
 1026 
 1027       # Font generation
 1028       if(&is_true(&get_name('PK'))) {
 1029         $newcfg{'PK_GENERATION'} = 1;
 1030         $newcfg{'METAMODE'} = lc(&get_name('METAMODE'));
 1031         $newcfg{'METADPI'} = &get_name('METADPI') || 0;
 1032         logit("Note: Will use PK generation (mode=$newcfg{'METAMODE'}, dpi=$newcfg{'METADPI'})\n");
 1033         &checking('if dvips supports the -mode switch');
 1034         # the -mode switch is available since 5.58c
 1035         if($numeric >= 5.5803) {
 1036           $newcfg{'have_dvipsmode'} = 1;
 1037           &result('yes');
 1038         }
 1039         else {
 1040           $newcfg{'have_dvipsmode'} = 0;
 1041           &result('no');
 1042         }
 1043       }
 1044       else {
 1045         $newcfg{'PK_GENERATION'} = 0;
 1046       }
 1047     }
 1048   }
 1049   else {
 1050     $opt{'IMAGES'} = 0;
 1051     &warn_no_images();
 1052   }
 1053 }
 1054 
 1055 # --------------------------------------------------------------------------
 1056 # dvipng
 1057 # --------------------------------------------------------------------------
 1058 
 1059 $newcfg{'DVIPNG'} = '';
 1060 
 1061 if($opt{'IMAGES'}) {
 1062   my $dvipng = &find_prog(&get_name('DVIPNG',1));
 1063   if($dvipng) {
 1064     $newcfg{'DVIPNG'} = $dvipng;
 1065   }
 1066 }
 1067 
 1068 # --------------------------------------------------------------------------
 1069 # pdftocairo
 1070 # --------------------------------------------------------------------------
 1071 
 1072 $newcfg{'PDFTOCAIRO'} = '';
 1073 
 1074 if($opt{'IMAGES'}) {
 1075   my $pdftocairo = &find_prog(&get_name('PDFTOCAIRO',1));
 1076   if($pdftocairo) {
 1077     $newcfg{'PDFTOCAIRO'} = $pdftocairo;
 1078   } else {
 1079     $opt{'SVG'} = 0;
 1080   }
 1081 }
 1082 
 1083 # --------------------------------------------------------------------------
 1084 # ps2pdf
 1085 # --------------------------------------------------------------------------
 1086 
 1087 $newcfg{'PS2PDF'} = '';
 1088 
 1089 if($opt{'IMAGES'}) {
 1090   my $ps2pdf = &find_prog(&get_name('PS2PDF',1));
 1091   if($ps2pdf) {
 1092     $newcfg{'PS2PDF'} = $ps2pdf;
 1093   }
 1094 }
 1095 
 1096 # --------------------------------------------------------------------------
 1097 # pdfcrop
 1098 # --------------------------------------------------------------------------
 1099 
 1100 $newcfg{'PDFCROP'} = '';
 1101 
 1102 if($opt{'IMAGES'}) {
 1103   my $pdfcrop = &find_prog(&get_name('PDFCROP',1));
 1104   if($pdfcrop) {
 1105     $newcfg{'PDFCROP'} = $pdfcrop;
 1106   }
 1107 }
 1108 
 1109 # HTML validator
 1110 # checks the validity of the generated HTML
 1111 # The support is very rudimentary here.
 1112 
 1113 $newcfg{'HTML_VALIDATOR'} = '';
 1114 
 1115 my $validator = &find_prog(&get_name('HTML_VALIDATOR',1));
 1116 if($validator) {
 1117   $newcfg{'HTML_VALIDATOR'} = $validator;
 1118 }
 1119 
 1120   
 1121 # --------------------------------------------------------------------------
 1122 # Ghostscript
 1123 #
 1124 # There are versions from 2.6.1 to 5.x available and running out there.
 1125 # We have to make the best out of every single one. If you asked me, I'd say:
 1126 # get 4.03 or some 5.x and everything would be perfect.
 1127 # --------------------------------------------------------------------------
 1128 
 1129 $newcfg{'GS'} = '';
 1130 $newcfg{'GSDEVICE'} = '';
 1131 $newcfg{'GSALIASDEVICE'} = '';
 1132 $newcfg{'have_geometry'} = 0;
 1133 $newcfg{'GSLANDSCAPE'} = '';
 1134 $newcfg{'GS_LIB'} = '';
 1135 
 1136 if($opt{'have_pstoimg'}) {
 1137   my $gs = &find_prog(&get_name('GS',1));
 1138   if($gs) {
 1139     my @gs_devs;
 1140     my @gs_lib_path;
 1141     my $gs_version;
 1142 
 1143     my $flag = 0;
 1144     unless(open(GS,"$gs -h 2>&1|")) {
 1145       $opt{'have_pstoimg'} = 0;
 1146       logit("Error: could not execute $gs\n");
 1147       &warn_no_images();
 1148     }
 1149     else {
 1150       &checking('for ghostscript version');
 1151 
 1152       # Parse output of "gs -h". This should give us all the facts we
 1153       # need for configuring Ghostscript.
 1154 
 1155       while (<GS>) {
 1156         chomp;
 1157         if($flag == 0 && /Ghostscript\s*(?:Version|(?:PRE-|BETA |TESTER )RELEASE|)\s*(\d+[.]?\d*)/i) {
 1158           $gs_version = $1;
 1159           $flag = 1;
 1160         }
 1161         elsif($flag && /^\s*Available devices/i) {
 1162           $flag = 2; # Now look for the devices
 1163         }
 1164         elsif($flag && /^\s*Search path/i) {
 1165           $flag = 3; # Now look for the gs lib path
 1166         }
 1167         elsif ($flag == 2) {
 1168           # if line starts with whitespace, then we're in the devices list
 1169           if(/^\s+(.*?)\s*$/) {
 1170             push(@gs_devs,split(/\s+/,$1));
 1171           }
 1172           else {
 1173             $flag = 1; # no more devices
 1174             redo;
 1175           }
 1176         }
 1177         elsif ($flag == 3) {
 1178           # if line starts with whitespace, then we're in the search path list
 1179           if(/^\s+(.*?)\s*$/ && length($1)) {
 1180             foreach(split(/\s*[$pathd]+\s*/,$1)) {
 1181               push(@gs_lib_path,L2hos->path2os($_)) if(length && -d $_);
 1182             }
 1183           }
 1184           else {
 1185             $flag = 1;
 1186             redo;
 1187           } # no more path entries
 1188         }
 1189       }
 1190       close(GS);
 1191 
 1192       # Configure things determined by the Ghostscript version
 1193 
 1194       unless($gs_version) {
 1195         &result('no');
 1196         $opt{'have_pstoimg'} = 0;
 1197         logit("Error: could not determine gs version\n");
 1198         &warn_no_images();
 1199       }
 1200       else {
 1201         &result($gs_version);
 1202         if($gs_version < 3.3) {
 1203           logit(<<"EOF");
 1204 Warning: Your Ghostscript interpreter is quite outdated. To make use of the
 1205          advanced features of pstoimg, you should install Ghostscript 4.03 or
 1206          5.x on your system.
 1207 EOF
 1208         }
 1209         else {
 1210           $newcfg{'have_geometry'} = 1;
 1211         }
 1212         $newcfg{'GS'} = $gs;
 1213         &checking('for ghostscript portable bitmap device');
 1214         if(@gs_devs) {
 1215           unless(&determine_gsdevice('GSDEVICE',q(pnmraw ppmraw pgnmraw pgmraw pbmraw ppm pgnm pgm pnm pbm),@gs_devs)) {
 1216             $opt{'have_pstoimg'} = 0;
 1217           }
 1218         }
 1219         else {
 1220           &result('no');
 1221           $opt{'have_pstoimg'} = 0;
 1222           logit("Error: could not determine gs devices\n");
 1223           &warn_no_images();
 1224         }
 1225         if($opt{'have_pstoimg'} && $gs_version > 4.02) {
 1226           &checking('for full color device for anti-aliasing');
 1227           &determine_gsdevice('GSALIASDEVICE',q(ppmraw pgmraw pnmraw pgnmraw ppm pgm pgnm pnm),@gs_devs);
 1228         }
 1229         else {
 1230           $newcfg{'GSALIASDEVICE'} = '';
 1231         }
 1232 
 1233         # Set up the Ghostscript library path
 1234 
 1235         &checking('for ghostscript library path');
 1236         my @try_path = @gs_lib_path;
 1237 
 1238         # Filter valid paths from environment, if set
 1239 
 1240         if($ENV{'GS_LIB'}) {
 1241           my @gspaths = grep(-d $_,split(/\s*[$pathd]\s*/,$ENV{'GS_LIB'}));
 1242           push(@try_path,@gspaths) if(@gspaths);
 1243         }
 1244 
 1245         # Add some sensible guesses
 1246 
 1247         if($newcfg{'plat'} =~ /dos|win32|os2/i ) {
 1248           my $gsdir = $gs;
 1249           $gsdir =~ s|\Q$dd\E[^$dd$dd]*$||; # strip name of executable
 1250           # try this directory and the parent
 1251           push(@try_path,$gsdir,"$gsdir${dd}..");
 1252         }
 1253         elsif($newcfg{'plat'} =~ /unix/i ) {
 1254           push(@try_path,qw(/usr/share/ghostscript /usr/lib/ghostscript
 1255             /usr/local/ghostscript /usr/local/share/ghostscript
 1256             /usr/local/lib/ghostscript/usr/share/gs /usr/lib/gs /usr/local/gs
 1257         /usr/share/lib/gs /usr/share/gs /usr/share/ghostscript
 1258             /usr/local/share/gs /usr/local/lib/gs));
 1259         }
 1260 
 1261         # Now look for "gs_init.ps". Also try to add
 1262         # - the Ghostscript version or
 1263         # - "gs<version>"
 1264         # to the path. This should cover a large number of configurations.
 1265 
 1266         my $path;
 1267         my @right_paths = ();
 1268         my $gs_lib = 0;
 1269     # 2017-04-11 shige: 2-24)
 1270     my $gs_stand_ps;
 1271         Gslibpaths: foreach $path (@try_path) {
 1272           foreach('',"$dd$gs_version","${dd}gs$gs_version") {
 1273             my $testpath = $path . $_;
 1274             # if(!$gs_lib && -d $testpath && -s "$testpath${dd}gs_init.ps") {
 1275         # 2017-04-11, 2019-12-03 shige: 2-24)
 1276         if ($testpath =~ /tlgs/) { $gs_stand_ps = "landscap.ps"; }
 1277         else { $gs_stand_ps = "gs_init.ps"; }
 1278             if(!$gs_lib && -d $testpath && -s "$testpath${dd}$gs_stand_ps") {
 1279               push(@right_paths,L2hos->path2os($testpath));
 1280               $gs_lib = 1;
 1281             }
 1282             last Gslibpaths if($gs_lib);
 1283           }
 1284         }
 1285 
 1286         my @additional_paths = ();
 1287         unless($gs_lib) {
 1288           &result('no');
 1289           logit(<<"EOF");
 1290 Warning: Could not determine GS_LIB path.
 1291          Ghostscript may not work due to missing startup files.
 1292          You need to set the value of GS_LIB manually in $CFGFILE.
 1293 Hint:    Search for the file 'gs_init.ps'. 
 1294          This directory should be set in GS_LIB.
 1295          Separate the entries with the "$pathd" character. The current
 1296          directory "." should be included, too.
 1297 EOF
 1298         }
 1299         else {
 1300            #push(@right_paths,'.');
 1301        # 2019-12-16 shige: 2-24) 
 1302            my $item;
 1303            foreach $item (@right_paths) {
 1304              $item = &simplify_path($item);
 1305              if(!grep($_ eq $item, @gs_lib_path)) {
 1306                push(@additional_paths,$item);
 1307              }
 1308            }
 1309            if(@additional_paths) {
 1310              $newcfg{'GS_LIB'} = join($pathd,@additional_paths);
 1311              &result("$newcfg{'GS_LIB'} (in addition to built-in paths)");
 1312            }
 1313            else {
 1314              $newcfg{'GS_LIB'} = '';
 1315              &result("built-in paths are correct");
 1316            }
 1317          }
 1318 
 1319         # The old Ghostscripts (<3.x) don't have the "-g" option. To enable
 1320         # efficient image creation, try to determine "landscap.ps" so that
 1321         # rotation can be used to minimize the area of the generated bitmap.
 1322 
 1323         push(@gs_lib_path,@additional_paths);
 1324         if($opt{'have_pstoimg'} && !$newcfg{'have_geometry'}) {
 1325           &checking('for landscap.ps');
 1326           my $landscap;
 1327           if(@gs_lib_path) {
 1328             foreach(@gs_lib_path) {
 1329               $landscap = "$_${dd}landscap.ps";
 1330               if(-s $landscap){
 1331                 &result($newcfg{'GSLANDSCAPE'} = $landscap);
 1332                 last;
 1333               }
 1334               undef $landscap;
 1335             }
 1336           }
 1337           unless($landscap) {
 1338             &result('no');
 1339             logit(<<"EOF");
 1340 Warning: Could not find landscap.ps
 1341          You may want to set the value of GSLANDSCAPE
 1342          (path to landscap.ps) manually in $CFGFILE.
 1343 EOF
 1344           }
 1345         }
 1346       }
 1347     }
 1348   }
 1349   else {
 1350     $opt{'have_pstoimg'} = 0;
 1351     &warn_no_images();
 1352   }
 1353 }
 1354 
 1355 # --------------------------------------------------------------------------
 1356 # PNMCROP
 1357 #
 1358 # The crucial point of pnmcrop is the "-l" option (crop from the left).
 1359 # It only works in the 1mar1994p1 version, but pstoimg depends heavily on it.
 1360 # --------------------------------------------------------------------------
 1361 # rrm. 2001/3/17:
 1362 # Later revisions (v9.x) require  -left etc. and need  -verbosity 
 1363 # to produce the messages that say what cropping has been performed.
 1364 # --------------------------------------------------------------------------
 1365 
 1366 $newcfg{'PNMCROP'} = '';
 1367 $newcfg{'PNMBLACK'} = '';
 1368 $newcfg{'PNMCROPOPT'} = '';
 1369 
 1370 if($opt{'have_pstoimg'}) {
 1371   my $pnmcrop = &find_prog(&get_name('PNMCROP',1));
 1372   if($pnmcrop) {
 1373     my ($stat,$msg,$err) = ('','','');
 1374     ($stat,$msg,$err) = &get_out_err("$pnmcrop -version");
 1375     my $vers = '';
 1376     my $major_vers = '';
 1377     $msg = $msg || $err;
 1378     if ($msg =~ /(^|\s*)Version.*\s([\d\.]+)\s*([\n\r]|$)/is) {
 1379         $vers = $2;
 1380         ($major_vers) = $vers =~ /^(\d+)/;
 1381     }
 1382     if ($vers =~ /(\d+\.\d+)(?:\.\d+)+/) {
 1383         $vers = $1;
 1384         ($major_vers) = $vers =~ /^(\d+)/;
 1385     }
 1386     &checking('if pnmcrop can crop from one direction');
 1387     if ($major_vers =~ /^199/) {
 1388     # try left crop
 1389         my $timg = "config${dd}timg.pnm";
 1390     ($stat,$msg,$err) = &get_out_err("$pnmcrop -l $timg");
 1391     } elsif ($major_vers > 8) {
 1392     my $sub_vers = '';
 1393     if ($vers =~ /9\.(\d+)/) {
 1394         $sub_vers = $1;
 1395         unless ($sub_vers > 11) {
 1396         $newcfg{'PNMBLACK'} = ' -black ';
 1397         print
 1398     "\n Please update to Netpbm 9.12+, from sourceforge.org/projects/netpbm/\n",
 1399     " else colored cropping-bars will not be removed.\n";
 1400         } else {
 1401 #       $pnmcrop .= ' -sides ';
 1402         $newcfg{'PNMCROPOPT'} = ' -sides ';
 1403         }
 1404     } else { $newcfg{'PNMCROPOPT'} = ' -sides '; }
 1405     $msg = 'there is nothing to crop'; $stat = '';
 1406     } else {
 1407     print "\nThis $vers for $pnmcrop is not recognisable.";
 1408     $stat = 1;
 1409     }
 1410 
 1411     unless(!$stat && $msg =~ /^p\d+[\s\n]+\d+\s+\d+|nothing to crop/is) {
 1412       $opt{'have_pstoimg'} = 0;
 1413       &result('no');
 1414       &warn_no_images();
 1415       logit(<<"EOF");
 1416 Hint: Get netpbm version 1mar1994p1 (the p1 is important!) to fix this
 1417       error, or later versions (v9.15+) from  sourceforge.net .
 1418 EOF
 1419     }
 1420     else {
 1421       &result('yes');
 1422       $newcfg{'PNMCROP'} = $pnmcrop;
 1423     }
 1424   }
 1425   else {
 1426     $opt{'have_pstoimg'} = 0;
 1427     &warn_no_images();
 1428   }
 1429 }
 1430 
 1431 # --------------------------------------------------------------------------
 1432 # PNMFLIP
 1433 # --------------------------------------------------------------------------
 1434 
 1435 $newcfg{'PNMFLIP'} = '';
 1436 
 1437 if(1) {
 1438   my $pnmflip = &find_prog(&get_name('PNMFLIP',1));
 1439   if($pnmflip) {
 1440     $newcfg{'PNMFLIP'} = $pnmflip;
 1441   } else {
 1442      &warn_no_graphics('flipping');
 1443   }
 1444 }
 1445 
 1446 # --------------------------------------------------------------------------
 1447 # PNMQUANT
 1448 # --------------------------------------------------------------------------
 1449 
 1450 $newcfg{'PNMQUANT'} = '';
 1451 
 1452 if(1) {
 1453   my $pnmquant = &find_prog(&get_name('PNMQUANT',1));
 1454   if($pnmquant) {
 1455     $newcfg{'PNMQUANT'} = $pnmquant;
 1456   }
 1457 }
 1458 
 1459 # --------------------------------------------------------------------------
 1460 # PNMFILE
 1461 # --------------------------------------------------------------------------
 1462 
 1463 $newcfg{'PNMFILE'} = '';
 1464 
 1465 if(1) {
 1466   my $pnmfile = &find_prog(&get_name('PNMFILE',1));
 1467   if($pnmfile) {
 1468     $newcfg{'PNMFILE'} = $pnmfile;
 1469   }
 1470 }
 1471 
 1472 # --------------------------------------------------------------------------
 1473 # PNMCAT
 1474 # --------------------------------------------------------------------------
 1475 
 1476 $newcfg{'PNMCAT'} = '';
 1477 
 1478 if(1) {
 1479   my $pnmcat = &find_prog(&get_name('PNMCAT',1));
 1480   if($pnmcat) {
 1481     $newcfg{'PNMCAT'} = $pnmcat;
 1482   } else {
 1483      &warn_no_graphics('concatenation');
 1484   }
 1485 }
 1486 
 1487 # --------------------------------------------------------------------------
 1488 # PBMMAKE
 1489 # --------------------------------------------------------------------------
 1490 
 1491 $newcfg{'PBMMAKE'} = '';
 1492 
 1493 if(1) {
 1494   my $pbmmake = &find_prog(&get_name('PBMMAKE',1));
 1495   if($pbmmake) {
 1496     $newcfg{'PBMMAKE'} = $pbmmake;
 1497   } else {
 1498      &warn_no_graphics('padding');
 1499   }
 1500 }
 1501 
 1502 # --------------------------------------------------------------------------
 1503 # PPMTOGIF
 1504 #
 1505 # Some versions of ppmtogif can produce transparent and interlaced GIFs.
 1506 # --------------------------------------------------------------------------
 1507 
 1508 $newcfg{'PPMTOGIF'} = '';
 1509 $newcfg{'gif_trans'} = '';
 1510 $newcfg{'gif_interlace'} = '';
 1511 
 1512 #if(($opt{'have_pstoimg'} && $opt{'GIF'})||(1)) {
 1513 if(1) {
 1514   my $ppmtogif = &find_prog(&get_name('PPMTOGIF',1));
 1515   if($ppmtogif) {
 1516     my ($stat,$msg,$err) = ('','','');
 1517     ($stat,$msg,$err) = &get_out_err("$ppmtogif -version");
 1518     $msg = $msg || $err;
 1519     my $vers = '';
 1520     if ($msg =~ /(^|\s*)Version.*\s([\d\.]+)\s*([\n\r]|$)/is) { $vers = $2; }
 1521     &checking('if ppmtogif can make transparent GIFs');
 1522     if ($vers =~ /^199/) {
 1523     # '-h' is an invalid option. Nevertheless it forces ppmtogif to output a
 1524     # usage information to stderr. We'll have a closer look at that.
 1525     ($stat,$msg,$err) = &get_out_err("$ppmtogif -h");
 1526     $msg .= $err || '';
 1527     } else {
 1528     $msg = 
 1529   'ppmtogif [-interlace] [-sort] [-map mapfile] [-transparent color] [-comment text]';
 1530     }
 1531     $newcfg{'PPMTOGIF'} = $ppmtogif;
 1532 
 1533     if ($opt{'have_pstoimg'} && $opt{'GIF'}) {
 1534     unless($msg =~ /ppm(to|2)gif/i) {
 1535       $opt{'GIF'} = 0;
 1536       result("error\n    Execution of $ppmtogif did not produce expected output\n");
 1537     }
 1538     else {
 1539       if($msg =~ /-transparent/i) {
 1540         &result('yes');
 1541         $newcfg{'gif_trans'} = 'netpbm';
 1542       }
 1543       else {
 1544         &result('no');
 1545       }
 1546       &checking('if ppmtogif can make interlaced GIFs');
 1547       if($msg =~ /-interlace/i) {
 1548         &result('yes');
 1549         $newcfg{'gif_interlace'} = 'netpbm';
 1550       }
 1551       else {
 1552         &result('no');
 1553       }
 1554     }}
 1555   }
 1556   else {
 1557     $opt{'GIF'} = 0;
 1558   }
 1559 }
 1560 
 1561 # --------------------------------------------------------------------------
 1562 # PNMTOPNG
 1563 # --------------------------------------------------------------------------
 1564 
 1565 $newcfg{'PNMTOPNG'} = '';
 1566 
 1567 #if($opt{'have_pstoimg'} && $opt{'PNG'}) {
 1568 if(1) {
 1569   my $pnmtopng = &find_prog(&get_name('PNMTOPNG',1));
 1570   if($pnmtopng) {
 1571     $newcfg{'PNMTOPNG'} = $pnmtopng;
 1572   }
 1573   else {
 1574     $opt{'PNG'} = 0;
 1575   }
 1576 }
 1577 
 1578 $newcfg{'have_images'} = $opt{'IMAGES'};
 1579 if($opt{'have_pstoimg'}) {
 1580   if($opt{'GIF'} || $opt{'PNG'}) {
 1581     $newcfg{'have_pstoimg'} = 1;
 1582   }
 1583   else {
 1584     $newcfg{'have_images'} = $newcfg{'have_pstoimg'} = 0;
 1585     &warn_no_images();
 1586   }
 1587 }
 1588 else {
 1589   $newcfg{'have_images'} = $newcfg{'have_pstoimg'} = 0;
 1590 }
 1591 
 1592 # --------------------------------------------------------------------------
 1593 # PPMTOJPEG
 1594 # --------------------------------------------------------------------------
 1595 # used in  graphics-support.perl  for handling \includegraphics options
 1596 
 1597 $newcfg{'PPMTOJPEG'} = '';
 1598 
 1599 if(1) {
 1600   my $ppmtojpeg = &find_prog(&get_name('PPMTOJPEG',1));
 1601   if($ppmtojpeg) {
 1602     $newcfg{'PPMTOJPEG'} = $ppmtojpeg;
 1603   } else {
 1604      &warn_no_image_type('jpg');
 1605   }
 1606 }
 1607 
 1608 
 1609 $newcfg{'IMAGE_TYPES'} = '';
 1610 
 1611 if($newcfg{'have_pstoimg'}) {
 1612   my @imgtypes = ();
 1613   if($opt{'SVG'}) {
 1614     push(@imgtypes,'svg');
 1615   }
 1616   if($opt{'PNG'}) {
 1617     push(@imgtypes,'png');
 1618   }
 1619   if($opt{'GIF'}) {
 1620     push(@imgtypes,'gif');
 1621   }
 1622   $newcfg{'IMAGE_TYPES'} = join(' ',@imgtypes);
 1623 }
 1624 
 1625 # --------------------------------------------------------------------------
 1626 # PNMCUT
 1627 # --------------------------------------------------------------------------
 1628 # used in  graphics-support.perl  for handling \includegraphics options
 1629 
 1630 $newcfg{'PNMCUT'} = '';
 1631 
 1632 if(1) {
 1633   my $pnmcut = &find_prog(&get_name('PNMCUT',1));
 1634   if($pnmcut) {
 1635     $newcfg{'PNMCUT'} = $pnmcut;
 1636   } else {
 1637      &warn_no_graphics('viewport');
 1638   }
 1639 }
 1640 
 1641 # --------------------------------------------------------------------------
 1642 # PNMPAD
 1643 # --------------------------------------------------------------------------
 1644 # used in  graphics-support.perl  for handling \includegraphics options
 1645 
 1646 $newcfg{'PNMPAD'} = '';
 1647 
 1648 if(1) {
 1649   my $pnmpad = &find_prog(&get_name('PNMPAD',1));
 1650   if($pnmpad) {
 1651     $newcfg{'PNMPAD'} = $pnmpad;
 1652   } else {
 1653      &warn_no_graphics('padding');
 1654   }
 1655 }
 1656 
 1657 # --------------------------------------------------------------------------
 1658 # PNMROTATE
 1659 # --------------------------------------------------------------------------
 1660 # used in  graphics-support.perl  for handling \includegraphics options
 1661 
 1662 $newcfg{'PNMROTATE'} = '';
 1663 
 1664 if(1) {
 1665   my $pnmrotate = &find_prog(&get_name('PNMROTATE',1));
 1666   if($pnmrotate) {
 1667     $newcfg{'PNMROTATE'} = $pnmrotate;
 1668   } else {
 1669      &warn_no_graphics('rotation');
 1670   }
 1671 }
 1672 
 1673 # --------------------------------------------------------------------------
 1674 # PNMSCALE
 1675 # --------------------------------------------------------------------------
 1676 # used in  graphics-support.perl  for handling \includegraphics options
 1677 
 1678 $newcfg{'PNMSCALE'} = '';
 1679 
 1680 if(1) {
 1681   my $pnmscale = &find_prog(&get_name('PNMSCALE',1));
 1682   if($pnmscale) {
 1683     $newcfg{'PNMSCALE'} = $pnmscale;
 1684   } else {
 1685      &warn_no_graphics('scaling');
 1686   }
 1687 }
 1688 
 1689 # --------------------------------------------------------------------------
 1690 # GIFTOPNM
 1691 # --------------------------------------------------------------------------
 1692 # used in  graphics-support.perl  for handling \includegraphics options
 1693 
 1694 $newcfg{'GIFTOPNM'} = '';
 1695 
 1696 if(1) {
 1697   my $giftopnm = &find_prog(&get_name('GIFTOPNM',1));
 1698   if($giftopnm) {
 1699     $newcfg{'GIFTOPNM'} = $giftopnm;
 1700   } else {
 1701      &warn_no_image_type('gif');
 1702   }
 1703 }
 1704 
 1705 # --------------------------------------------------------------------------
 1706 # JPEGTOPNM
 1707 # --------------------------------------------------------------------------
 1708 # used in  graphics-support.perl  for handling \includegraphics options
 1709 
 1710 $newcfg{'JPEGTOPNM'} = '';
 1711 
 1712 if(1) {
 1713   my $jpegtopnm = &find_prog(&get_name('JPEGTOPNM',1));
 1714   if($jpegtopnm) {
 1715     $newcfg{'JPEGTOPNM'} = $jpegtopnm;
 1716   } else {
 1717      &warn_no_image_type('jpeg');
 1718   }
 1719 }
 1720 
 1721 # --------------------------------------------------------------------------
 1722 # PNGTOPNM
 1723 # --------------------------------------------------------------------------
 1724 # used in  graphics-support.perl  for handling \includegraphics options
 1725 
 1726 $newcfg{'PNGTOPNM'} = '';
 1727 
 1728 if(1) {
 1729   my $pngtopnm = &find_prog(&get_name('PNGTOPNM',1));
 1730   if($pngtopnm) {
 1731     $newcfg{'PNGTOPNM'} = $pngtopnm;
 1732   } else {
 1733      &warn_no_image_type('png');
 1734   }
 1735 }
 1736 
 1737 # --------------------------------------------------------------------------
 1738 # TIFFTOPNM
 1739 # --------------------------------------------------------------------------
 1740 # used in  graphics-support.perl  for handling \includegraphics options
 1741 
 1742 $newcfg{'TIFFTOPNM'} = '';
 1743 
 1744 if(1) {
 1745   my $tifftopnm = &find_prog(&get_name('TIFFTOPNM',1));
 1746   if($tifftopnm) {
 1747     $newcfg{'TIFFTOPNM'} = $tifftopnm;
 1748   } else {
 1749      &warn_no_image_type('tiff');
 1750   }
 1751 }
 1752 
 1753 # --------------------------------------------------------------------------
 1754 # ANYTOPNM
 1755 # --------------------------------------------------------------------------
 1756 # used in  graphics-support.perl  for handling \includegraphics options
 1757 
 1758 $newcfg{'ANYTOPNM'} = '';
 1759 
 1760 if(1) {
 1761   my $anytopnm = &find_prog(&get_name('ANYTOPNM',1));
 1762   if($anytopnm) {
 1763     $newcfg{'ANYTOPNM'} = $anytopnm;
 1764   } else {
 1765      &warn_no_image_type('arbitrary');
 1766   }
 1767 }
 1768 
 1769 # --------------------------------------------------------------------------
 1770 # BMPTOPPM
 1771 # --------------------------------------------------------------------------
 1772 # used in  graphics-support.perl  for handling \includegraphics options
 1773 
 1774 $newcfg{'BMPTOPPM'} = '';
 1775 
 1776 if(1) {
 1777   my $bmptoppm = &find_prog(&get_name('BMPTOPPM',1));
 1778   if($bmptoppm) {
 1779     $newcfg{'BMPTOPPM'} = $bmptoppm;
 1780   } else {
 1781      &warn_no_image_type('bmp');
 1782   }
 1783 }
 1784 
 1785 # --------------------------------------------------------------------------
 1786 # PCXTOPPM
 1787 # --------------------------------------------------------------------------
 1788 # used in  graphics-support.perl  for handling \includegraphics options
 1789 
 1790 $newcfg{'PCXTOPPM'} = '';
 1791 
 1792 if(1) {
 1793   my $pcxtoppm = &find_prog(&get_name('PCXTOPPM',1));
 1794   if($pcxtoppm) {
 1795     $newcfg{'PCXTOPPM'} = $pcxtoppm;
 1796   } else {
 1797      &warn_no_image_type('pcx');
 1798   }
 1799 }
 1800 
 1801 # --------------------------------------------------------------------------
 1802 # SGITOPNM
 1803 # --------------------------------------------------------------------------
 1804 # used in  graphics-support.perl  for handling \includegraphics options
 1805 
 1806 $newcfg{'SGITOPNM'} = '';
 1807 
 1808 if(1) {
 1809   my $sgitopnm = &find_prog(&get_name('SGITOPNM',1));
 1810   if($sgitopnm) {
 1811     $newcfg{'SGITOPNM'} = $sgitopnm;
 1812   } else {
 1813      &warn_no_image_type('sgi');
 1814   }
 1815 }
 1816 
 1817 # --------------------------------------------------------------------------
 1818 # XBMTOPBM
 1819 # --------------------------------------------------------------------------
 1820 # used in  graphics-support.perl  for handling \includegraphics options
 1821 
 1822 $newcfg{'XBMTOPBM'} = '';
 1823 
 1824 if(1) {
 1825   my $xbmtopnm = &find_prog(&get_name('XBMTOPBM',1));
 1826   if($xbmtopnm) {
 1827     $newcfg{'XBMTOPBM'} = $xbmtopnm;
 1828   } else {
 1829      &warn_no_image_type('xbm');
 1830   }
 1831 }
 1832 
 1833 # --------------------------------------------------------------------------
 1834 # XWDTOPNM
 1835 # --------------------------------------------------------------------------
 1836 # used in  graphics-support.perl  for handling \includegraphics options
 1837 
 1838 $newcfg{'XWDTOPNM'} = '';
 1839 
 1840 if(1) {
 1841   my $xwdtopnm = &find_prog(&get_name('XWDTOPNM',1));
 1842   if($xwdtopnm) {
 1843     $newcfg{'XWDTOPNM'} = $xwdtopnm;
 1844   } else {
 1845      &warn_no_image_type('xwd');
 1846   }
 1847 }
 1848 
 1849 # --------------------------------------------------------------------------
 1850 # GIFTOOL
 1851 #
 1852 # Only needed if ppmtogif lacks -transparent and/or -interlaced
 1853 # --------------------------------------------------------------------------
 1854 
 1855 if($newcfg{'have_pstoimg'} && $opt{'GIF'} &&
 1856   (!$newcfg{'gif_trans'} || !$newcfg{'gif_interlace'})) {
 1857   my $giftool = &find_prog(&get_name('GIFTOOL',1));
 1858   if($giftool) {
 1859     $newcfg{'GIFTOOL'} = $giftool;
 1860     $newcfg{'gif_trans'} = 'giftool' if(!$newcfg{'gif_trans'});
 1861     $newcfg{'gif_interlace'} = 'giftool' if(!$newcfg{'gif_interlace'});
 1862   }
 1863 }
 1864 
 1865 # --------------------------------------------------------------------------
 1866 # GIFTRANS
 1867 #
 1868 # Only needed if ppmtogif lacks -transparent
 1869 # --------------------------------------------------------------------------
 1870 
 1871 if($newcfg{'have_pstoimg'} && $opt{'GIF'} && !$newcfg{'gif_trans'}) {
 1872   my $giftrans = &find_prog(&get_name('GIFTRANS',1));
 1873   if($giftrans) {
 1874     $newcfg{'GIFTRANS'} = $giftrans;
 1875     $newcfg{'gif_trans'} = 'giftrans';
 1876   }
 1877 }
 1878 
 1879 # --------------------------------------------------------------------------
 1880 # Pipes
 1881 # --------------------------------------------------------------------------
 1882 
 1883 if(&is_true(&get_name('PIPES'))) {
 1884   &checking('if multiple pipes work');
 1885   if($newcfg{'plat'} =~ /win32|dos/i) {
 1886     &result('no');
 1887     logit("Unfortunately multiple pipes are not reliable on this OS.\n");
 1888     $newcfg{'pipes'} = 0;
 1889   }
 1890   else {
 1891     my $cmd = "echo 101" .  (" | $newcfg{'PERL'} config${dd}pipetest.pl" x 8);
 1892     my $out = `$cmd`;
 1893     chomp $out;
 1894     if($out == 109) {
 1895       &result('yes');
 1896       $newcfg{'pipes'} = 1;
 1897     }
 1898     else {
 1899       &result('no');
 1900       $newcfg{'pipes'} = 0;
 1901     }
 1902   }
 1903 }
 1904 else {
 1905   $newcfg{'pipes'} = 0;
 1906 }
 1907 
 1908 # --------------------------------------------------------------------------
 1909 # temporary disk space
 1910 #
 1911 # try all sorts of places and check whether they are directories and
 1912 # we have write permission
 1913 # --------------------------------------------------------------------------
 1914 
 1915 &checking('for temporary disk space');
 1916 $newcfg{'TMPSPACE'} = '';
 1917 my @tmp = ();
 1918 push(@tmp,$cfg{'TMPSPACE'}) if($cfg{'TMPSPACE'});
 1919 push(@tmp,$prefs{'TMPSPACE'}) if($prefs{'TMPSPACE'});
 1920 push(@tmp,$ENV{'TMP'}) if($ENV{'TMP'});
 1921 push(@tmp,$ENV{'TEMP'}) if($ENV{'TEMP'});
 1922 if($newcfg{'plat'} =~ /dos|win32/i) {
 1923   push(@tmp,qw(C:\\TMP C:\\TEMP C:\\WINDOWS\\TEMP C:\\WINNT\\TEMP));
 1924 }
 1925 elsif($newcfg{'plat'} =~ /unix/i) { # unix
 1926   push(@tmp,qw(/tmp /usr/tmp /var/tmp /usr/local/tmp));
 1927 }
 1928 elsif($newcfg{'plat'} =~ /os2/i) { # OS/2
 1929   # no specific items here yet!
 1930 }
 1931 else {
 1932   logit("\nWarning: Check on this platform ($^O) not yet implemented... ");
 1933 }
 1934 
 1935 foreach(@tmp) {
 1936   if(-d && -w _) {
 1937     $newcfg{'TMPSPACE'} = $_;
 1938     last;
 1939   }
 1940 }
 1941 if($newcfg{'TMPSPACE'}) {
 1942   &result($newcfg{'TMPSPACE'});
 1943 }
 1944 else {
 1945   &result('no');
 1946   $newcfg{'TMPSPACE'} = '.'; # poor man's tmp
 1947 }
 1948 
 1949 # --------------------------------------------------------------------------
 1950 # the installation paths
 1951 # --------------------------------------------------------------------------
 1952 
 1953 $newcfg{'PREFIX'} = $opt{'PREFIX'} || '';
 1954 $newcfg{'PREFIX'} =~ s/^NONE$//;
 1955 my $have_prefix = 0;
 1956 unless($newcfg{'PREFIX'}) {
 1957   $newcfg{'PREFIX'} = $cfg{'PREFIX'} || $prefs{'PREFIX'} || '';
 1958   unless($newcfg{'PREFIX'}) {
 1959     logit("Error: You must specify an installation PREFIX\n");
 1960     cleanup(1);
 1961     exit 1;
 1962   }
 1963 } else {
 1964   $have_prefix = 1;
 1965 }
 1966 $newcfg{'PREFIX'} =~ s|[/\\]+|$dd|g; # replace /\ with correct delimiter
 1967 $newcfg{'PREFIX'} =~ s|[$dd$dd]+$||; # strip trailing directory delimiter(s)
 1968 add_drive_letter($newcfg{'PREFIX'});
 1969 
 1970 $newcfg{'BINDIR'} = $opt{'BINDIR'} || '';
 1971 
 1972 # kludge for GNU autoconf
 1973 $newcfg{'BINDIR'} =~ s:\$\{exec_prefix\}.*::;
 1974 
 1975 unless($newcfg{'BINDIR'}) {
 1976   $newcfg{'BINDIR'} = $prefs{'BINDIR'} || '';
 1977   $newcfg{'BINDIR'} ||= $cfg{'BINDIR'} unless($have_prefix);
 1978 }
 1979 if($newcfg{'BINDIR'}) {
 1980   $newcfg{'BINDIR'} =~ s|[$dd$dd]+$||; # strip trailing directory delimiters
 1981 }
 1982 else {
 1983   $newcfg{'BINDIR'} = "$newcfg{'PREFIX'}${dd}bin";
 1984 }
 1985 add_drive_letter($newcfg{'BINDIR'});
 1986 
 1987 $newcfg{'SHLIBDIR'} = $opt{'SHLIBDIR'} || '';
 1988 $newcfg{'LIBDIR'} = $opt{'LIBDIR'} || '';
 1989 
 1990 # kludge for GNU autoconf
 1991 $newcfg{'LIBDIR'} =~ s:\$\{exec_prefix\}.*::;
 1992 $newcfg{'SHLIBDIR'} =~ s:\$\{exec_prefix\}.*::;
 1993 
 1994 unless($newcfg{'SHLIBDIR'}) {
 1995   $newcfg{'SHLIBDIR'} = $prefs{'SHLIBDIR'} || '';
 1996   $newcfg{'SHLIBDIR'} ||= $cfg{'SHLIBDIR'} unless($have_prefix);
 1997 }
 1998 unless($newcfg{'LIBDIR'}) {
 1999   $newcfg{'LIBDIR'} = $prefs{'LIBDIR'} || '';
 2000   $newcfg{'LIBDIR'} ||= $cfg{'LIBDIR'} unless($have_prefix);
 2001 }
 2002 
 2003 if($newcfg{'SHLIBDIR'}) {
 2004   $newcfg{'SHLIBDIR'} =~ s|[$dd$dd]+$||; # strip trailing directory delimiters
 2005 }
 2006 else {
 2007   # similar to the perl installation procedure, append latex2html only
 2008   # if it does not appear in the PREFIX
 2009   if($newcfg{'PREFIX'} =~ /l2h|latex2html/i) {
 2010     $newcfg{'SHLIBDIR'} = $newcfg{'PREFIX'};
 2011   }
 2012   else {
 2013     $newcfg{'SHLIBDIR'} = "$newcfg{'PREFIX'}${dd}share${dd}lib${dd}latex2html";
 2014   }
 2015 }
 2016 add_drive_letter($newcfg{'SHLIBDIR'});
 2017 
 2018 $newcfg{'LATEX2HTMLDIR'} = $newcfg{'SHLIBDIR'};
 2019 # make sure the device is prepended!
 2020 if($newcfg{'plat'} =~ /win|dos|os2/i) {
 2021   unless($newcfg{'LATEX2HTMLDIR'} =~ /^[A-Z]:/i) {
 2022     my ($drive) = $cwd =~ /^([A-Z]:)/i;
 2023     unless($drive) {
 2024       logit("Fatal: Cannot determine current drive letter\n");
 2025       cleanup(1);
 2026       exit 1;
 2027     }
 2028     $newcfg{'LATEX2HTMLDIR'} = "$drive$newcfg{'LATEX2HTMLDIR'}";
 2029   }
 2030 }
 2031 
 2032 if($newcfg{'LIBDIR'}) {
 2033   $newcfg{'LIBDIR'} =~ s|[$dd$dd]+$||; # strip trailing directory delimiters
 2034 }
 2035 else {
 2036   # similar to the perl installation procedure, append latex2html only
 2037   # if it does not appear in the PREFIX
 2038   if($newcfg{'PREFIX'} =~ /l2h|latex2html/i) {
 2039     $newcfg{'LIBDIR'} = $newcfg{'PREFIX'};
 2040   }
 2041   else {
 2042     $newcfg{'LIBDIR'} = "$newcfg{'PREFIX'}${dd}lib${dd}latex2html";
 2043   }
 2044 }
 2045 add_drive_letter($newcfg{'LIBDIR'});
 2046 
 2047 $newcfg{'LATEX2HTMLPLATDIR'} = $newcfg{'LIBDIR'};
 2048 # make sure the device is prepended!
 2049 if($newcfg{'plat'} =~ /win|dos|os2/i) {
 2050   unless($newcfg{'LATEX2HTMLPLATDIR'} =~ /^[A-Z]:/i) {
 2051     my ($drive) = $cwd =~ /^([A-Z]:)/i;
 2052     unless($drive) {
 2053       logit("Fatal: Cannot determine current drive letter\n");
 2054       cleanup(1);
 2055       exit 1;
 2056     }
 2057     $newcfg{'LATEX2HTMLPLATDIR'} = "$drive$newcfg{'LATEX2HTMLPLATDIR'}";
 2058   }
 2059 }
 2060 
 2061 # how to call the scripts
 2062 if($newcfg{'texlive'}) {
 2063   $newcfg{'scriptdir'} = $newcfg{'SHLIBDIR'};
 2064   $newcfg{'scriptext'} = '.pl';
 2065 } elsif($newcfg{'wrapper'}) {
 2066   $newcfg{'scriptdir'} = $newcfg{'SHLIBDIR'};
 2067   $newcfg{'scriptext'} = '.pl';
 2068 } else {
 2069   $newcfg{'scriptdir'} = $newcfg{'BINDIR'};
 2070   $newcfg{'scriptext'} = $newcfg{'exec_extension'};
 2071 }
 2072 
 2073 # --------------------------------------------------------------------------
 2074 # some other paths
 2075 # --------------------------------------------------------------------------
 2076 
 2077 $newcfg{'RGBCOLORFILE'} = $opt{'RGB'} || $cfg{'RGBCOLORFILE'} ||
 2078   $prefs{'RGB'} || "$newcfg{'SHLIBDIR'}${dd}styles${dd}rgb.txt";
 2079 $newcfg{'CRAYOLAFILE'} = $opt{'CRAYOLA'} || $cfg{'CRAYOLAFILE'} || 
 2080   $prefs{'CRAYOLA'} || "$newcfg{'SHLIBDIR'}${dd}styles${dd}crayola.txt";
 2081 
 2082 $newcfg{'ICONSTORAGE'} = $opt{'ICONSTORAGE'} || $cfg{'ICONSTORAGE'} ||
 2083   $prefs{'ICONSTORAGE'} || '';
 2084 $newcfg{'ICONPATH'} = $opt{'ICONPATH'} || $cfg{'ICONPATH'} ||
 2085   $prefs{'ICONPATH'} || '';
 2086 $newcfg{'ICONSERVER'} = $opt{'ICONSERVER'} || $cfg{'ICONSERVER'} ||
 2087   $prefs{'ICONSERVER'} || '';
 2088 
 2089 # use a file: URL to access icons if no server path given
 2090 unless($newcfg{'ICONPATH'}) {
 2091   $newcfg{'ICONPATH'} = L2hos->path2URL("$newcfg{'SHLIBDIR'}${dd}icons");
 2092 }
 2093 
 2094 # --------------------------------------------------------------------------
 2095 # generate configuration file
 2096 # --------------------------------------------------------------------------
 2097 
 2098 logit("creating $CFGFILE\n");
 2099 unless(open(OUT,">$CFGFILE")) {
 2100   logit("Error: Cannot write $CFGFILE: $!\n");
 2101   cleanup(1);
 2102   exit 1;
 2103 }
 2104 
 2105 print OUT <<"EOT";
 2106 # LaTeX2HTML site specific configuration file
 2107 # generated by config.pl
 2108 
 2109 # You may edit this file to get around deficiencies of the configuration
 2110 # procedure, but you have to be sure of what you are doing!
 2111 # If you think there are bugs in the configuration procedure, please report
 2112 # them. See the BUGS file on how to do it. Your help is appreciated!
 2113 
 2114 package cfgcache;
 2115 require Exporter;
 2116 \@ISA = qw(Exporter);
 2117 \@EXPORT = qw(\%cfg);
 2118 
 2119 EOT
 2120 $newcfg{'dd'} = $dd;
 2121 my $key;
 2122 foreach $key (sort keys %newcfg) {
 2123   my $val = $newcfg{$key};
 2124   if($val =~ /\n/s) { # contains newlines?
 2125     chomp $val;
 2126     print OUT "\$cfg{'$key'} = <<'EOQ';\n$val\nEOQ\n";
 2127   }
 2128   else {
 2129     $val =~ s:\\:\\\\:g; # escape backslashes
 2130     my $delim = '';
 2131     my $i;
 2132     foreach $i (qw(' ' | : ! + " " $ % / . = * ;)) {
 2133       unless($val =~ /\Q$i/) {
 2134         $delim = $i;
 2135         last;
 2136       }
 2137     }
 2138     unless($delim) {
 2139       logit("Fatal: Could not find delimiter for $key=$val\n");
 2140       cleanup(1);
 2141       exit 1;
 2142     }
 2143     print OUT "\$cfg{'$key'} = q$delim$val$delim;\n";
 2144   }
 2145 }
 2146 print OUT "\n1; # must be last line\n";
 2147 close(OUT);
 2148 
 2149 # --------------------------------------------------------------------------
 2150 # Generate batch files for DOS/OS2 testing/installation
 2151 # --------------------------------------------------------------------------
 2152 
 2153 if($newcfg{'plat'} =~ /dos|win|os2/) {
 2154   my $testfile = "test$newcfg{'exec_extension'}";
 2155   logit("creating $testfile\n");
 2156   unless(open(OUT,">$testfile")) {
 2157     logit("Error: Cannot write $testfile: $!\n");
 2158     cleanup();
 2159     exit 1;
 2160   }
 2161   my ($dir,$latex2html);
 2162   if($newcfg{'wrapper'}) {
 2163     $dir = "$cwd\\bin";
 2164     $latex2html = "$dir\\latex2html$newcfg{'exec_extension'}";
 2165   }
 2166   elsif($newcfg{'texlive'}) {
 2167     $dir = "$cwd\\bin\\$newcfg{'plat'}";
 2168     $latex2html = "$dir\\latex2html$newcfg{'exec_extension'}";
 2169   }
 2170   else {
 2171     $dir = $cwd;
 2172     $latex2html = "$dir\\latex2html$newcfg{'exec_extension'}";
 2173   }
 2174   print OUT <<"EOF";
 2175 \@ECHO OFF
 2176 REM this is a batch file for testing the build of LaTeX2HTML
 2177 REM on DOS, Win or OS/2 as these platforms lack a "make" utility
 2178 
 2179 set LATEX2HTMLDIR=$cwd
 2180 set OPATH=%PATH%
 2181 REM for OS/2, we need to set the PATH accordingly
 2182 PATH $dir;%PATH%
 2183 
 2184 ECHO ... checking latex2html
 2185 $newcfg{'PERL'} -c $cwd\\latex2html$newcfg{'scriptext'}
 2186 IF ERRORLEVEL 1 GOTO ERROR
 2187 
 2188 ECHO ... checking texexpand
 2189 $newcfg{'PERL'} -c $cwd\\texexpand$newcfg{'scriptext'}
 2190 IF ERRORLEVEL 1 GOTO ERROR
 2191 
 2192 ECHO ... checking pstoimg
 2193 $newcfg{'PERL'} -c $cwd\\pstoimg$newcfg{'scriptext'}
 2194 IF ERRORLEVEL 1 GOTO ERROR
 2195 
 2196 cd tests
 2197 echo *** Running $latex2html -test_mode %1 %2 %3 %4 %5 %6 %7 %8 %9 l2htest.tex
 2198 call $latex2html -test_mode %1 %2 %3 %4 %5 %6 %7 %8 %9 l2htest.tex
 2199 cd ..
 2200 :ERROR
 2201 PATH %OPATH%
 2202 set OPATH=
 2203 set LATEX2HTMLDIR=
 2204 EOF
 2205   close(OUT);
 2206 
 2207   # now for the install
 2208 
 2209   $testfile = "install$newcfg{'exec_extension'}";
 2210   logit("creating $testfile\n");
 2211   unless(open(OUT,">$testfile")) {
 2212     logit("Error: Cannot write $testfile: $!\n");
 2213     cleanup();
 2214     exit 1;
 2215   }
 2216 
 2217   print OUT <<"EOT";
 2218 \@ECHO OFF
 2219 REM this is a batch file for installing LaTeX2HTML
 2220 REM on DOS, Win or OS/2 as these platforms lack a "make" utility
 2221 
 2222 $newcfg{'PERL'} config\\install.pl
 2223 EOT
 2224   close(OUT);
 2225 }
 2226 
 2227 logit(<<"EOF");
 2228 Note: Will install...
 2229       ... executables to   : $newcfg{'BINDIR'}
 2230       ... shared library items to : $newcfg{'SHLIBDIR'}
 2231       ... unshared library items to : $newcfg{'LIBDIR'}
 2232 EOF
 2233 
 2234 # --------------------------------------------------------------------------
 2235 # The end!
 2236 # --------------------------------------------------------------------------
 2237 
 2238 exit 0;
 2239 
 2240 # --------------------------------------------------------------------------
 2241 # helpers, subs, ...
 2242 # --------------------------------------------------------------------------
 2243 
 2244 sub checking {
 2245   my ($str) = @_;
 2246   logit("checking $str... ");
 2247 }
 2248 
 2249 sub result {
 2250   my ($str) = @_;
 2251   logit("$str\n");
 2252 }
 2253 
 2254 #------------------------------------------------------------------------------
 2255 # Return the value for a configuration option from the command line argument
 2256 # or from the environment or from the preferences file:
 2257 #------------------------------------------------------------------------------
 2258 
 2259 sub get_name {
 2260   my ($name,$flag) = @_;
 2261   # accumulate the matching items if $flag is true
 2262   my @stack;
 2263   if(defined $opt{$name} && $opt{$name} !~ /^\s*$/) {
 2264     return $opt{$name} unless($flag);
 2265     push(@stack,$opt{$name});
 2266   }
 2267   if(defined $cfg{$name} && $cfg{$name} !~ /^\s*$/) {
 2268     return $cfg{$name} unless($flag);
 2269     push(@stack,$cfg{$name});
 2270     my $base = $cfg{$name};
 2271     $base =~ s:^.*[/$dd$dd]::;
 2272     push(@stack,$base);
 2273   }
 2274   # MRO: logic for environment included in configure
 2275   #if(defined $ENV{$name} && $ENV{$name} !~ /^\s*$/) {
 2276   #  return $ENV{$name} unless($flag);
 2277   #  push(@stack,$ENV{$name});
 2278   #}
 2279   if(defined $prefs{$name} && $prefs{$name} !~ /^\s*$/) {
 2280     return $prefs{$name} unless($flag);
 2281     push(@stack,$prefs{$name});
 2282   }
 2283   return(@stack) if (@stack);
 2284   logit(qq{Error: Cannot find a value for config option "$name"\n});
 2285   cleanup(1);
 2286   exit 1;
 2287 }
 2288 
 2289 #------------------------------------------------------------------------------
 2290 # parse a true/false setting
 2291 #------------------------------------------------------------------------------
 2292 
 2293 sub is_true {
 2294   my ($val) = @_;
 2295   return ($val && ($val =~ /^\s*(y|1)/i)) ? 1 : 0;
 2296 }
 2297 
 2298 #------------------------------------------------------------------------------
 2299 # search executable PATH for some program
 2300 #------------------------------------------------------------------------------
 2301 
 2302 sub find_prog {
 2303   my @names = @_;
 2304 
 2305   my $drive_rx = '';
 2306   if($newcfg{'plat'} =~ /dos|win|os2/) {
 2307     $drive_rx = '([A-Z]:)?';
 2308   }
 2309   if(@names == 1) {
 2310     @names = split(/[\s,]/,$names[0]);
 2311   }
 2312   my $found = 0;
 2313   my ($name,$path,$prog);
 2314   Search: foreach $name (@names) {
 2315     my $base = $name;
 2316     $base =~ s:^.*[/$dd$dd]::; # strip path
 2317     &checking("for $base");
 2318     if($name =~ /\Q$dd/) { # contains dir delimiter?
 2319       unless($name =~ /^$drive_rx\Q$dd/oi) { # absolute dir?
 2320         $name = &simplify_path("$cwd$dd$name");
 2321       }
 2322       $prog = &check_prog($name);
 2323       if($prog) {
 2324         $found++;
 2325         &result($prog);
 2326         last Search;
 2327       }
 2328       else {
 2329         &result('no');
 2330       }
 2331     }
 2332     else {
 2333       foreach $path (@paths) {
 2334         $prog = &check_prog(($path) ? "$path$dd$name" : $name);
 2335         if($prog) {
 2336           $found++;
 2337           &result($prog);
 2338           last Search;
 2339         }
 2340       }
 2341       &result('no');
 2342     }
 2343   }
 2344   if($found) {
 2345     unless(is_true($abs_path_names)) {
 2346       $prog =~ s:^.*[/$dd$dd]::; # strip path
 2347     }
 2348     return $prog;
 2349   }
 2350   undef;
 2351 }
 2352 
 2353 #------------------------------------------------------------------------------
 2354 # check for existence of some executable
 2355 # add extensions as required on certain platforms
 2356 #------------------------------------------------------------------------------
 2357 
 2358 sub check_prog {
 2359   my ($path) = @_;
 2360   my @extensions = ();
 2361   if($newcfg{'plat'} =~ /dos|win32|os2/i) {
 2362     if($path =~ /\.\w{3}$/i) { # has valid extension
 2363       if(-s $path && !-d _) {
 2364         return $path;
 2365       }
 2366     }
 2367     else { # look for extensions
 2368       my @Extensions = ($newcfg{'plat'} =~ /os2/i) ?
 2369         qw(.exe .com .bat .cmd) : qw(.exe .com .bat);
 2370       my $ext;
 2371       foreach $ext (@Extensions) {
 2372         if(-s "$path$ext" && !-d _) {
 2373           return "$path$ext";
 2374         }
 2375       }
 2376     }
 2377   }
 2378   else { # do the regular check
 2379     if(-x $path && !-d _) {
 2380       return $path;
 2381     }
 2382   }
 2383   ''; # failure
 2384 }
 2385 
 2386 #------------------------------------------------------------------------------
 2387 # Capture output to STDOUT and STDERR. Must work on all platforms, therefore
 2388 # an external script is used that provides for the filehandle redirection.
 2389 # In theory it can of course be done by open("-|"), but forking is not
 2390 # supported on all platforms. I hope this is the least common denominator...
 2391 #------------------------------------------------------------------------------
 2392 
 2393 sub get_out_err {
 2394   my ($cmd) = @_;
 2395 
 2396   # redir.pl does the redirection for us
 2397   unless(open(IN,"$newcfg{PERL} config${dd}redir.pl $cmd |")) {
 2398     return(255,'',$!);
 2399   }
 2400   my @out = ();
 2401   my @err = ();
 2402   my $flag = 0;
 2403   # parse the output
 2404   while(defined($_ = <IN>)) {
 2405     chomp;
 2406     if($flag == 0 && /^---STDERR---$/) {
 2407       $flag = 1;
 2408     }
 2409     elsif($flag == 1 && /^---STDOUT---$/) {
 2410       $flag = 2;
 2411     }
 2412     elsif($flag == 1) {
 2413       push(@err,$_) unless(/^\s*$/);
 2414     }
 2415     elsif($flag == 2) {
 2416       push(@out,$_) unless(/^\s*$/);
 2417     }
 2418     else {
 2419       logit("\ndebug: unexpected output: +$_+\n");
 2420     }
 2421   }
 2422 
 2423   close(IN); # close on a pipe sets $?
 2424   my $stat = $?;
 2425   $stat >>= 8 if($stat > 255);
 2426   my $out = join("\n",@out) || '';
 2427   my $err = join("\n",@err) || '';
 2428 
 2429   #logit("\nDEBUG: stat +$stat+\n");
 2430   #logit("\nDEBUG: out  +$out+\n");
 2431   #logit("\nDEBUG: err  +$err+\n");
 2432   #my $a = <STDIN>;
 2433   ($stat,$out,$err);
 2434 }
 2435 
 2436 #------------------------------------------------------------------------------
 2437 # Get one of a list of desired Ghostscript devices
 2438 #------------------------------------------------------------------------------
 2439 
 2440 sub determine_gsdevice {
 2441   my ($type,$desired,@gs_devs) = @_;
 2442 
 2443   my $dev = $opt{$type} || $cfg{$type} || $prefs{$type};
 2444   if($dev) {
 2445     my $found;
 2446     if(($found) = grep(/^\Q$dev\E$/i,@gs_devs)) {
 2447       &result($newcfg{$type} = $found);
 2448     }
 2449     else {
 2450       &result('no');
 2451       logit("Error: $newcfg{'GS'} does not support device '$dev'. Valid are '",
 2452         join(' ',@gs_devs),"'\n");
 2453       return 0;
 2454     }
 2455   }
 2456   else { # look for one of the following
 2457     my @desired_dev = split(/\s+/,$desired);
 2458     my $found = '';
 2459     my $dev;
 2460     foreach $dev (@desired_dev) {
 2461       if(($found) = grep(/^\Q$dev\E$/i,@gs_devs)) {
 2462         last;
 2463       }
 2464     }
 2465     if($found) {
 2466       &result($newcfg{$type} = $found);
 2467     }
 2468     else {
 2469       &result('no');
 2470       logit("Error:  $newcfg{'GS'} does not support any of '", join(' ',@desired_dev),"'\n");
 2471       return 0;
 2472     }
 2473   }
 2474   1;
 2475 }
 2476 
 2477 #------------------------------------------------------------------------------
 2478 # Print a sad message...
 2479 #------------------------------------------------------------------------------
 2480 
 2481 sub warn_no_images {
 2482   logit("Warning: Will not be able to generate images due to above failure.\n");
 2483   1;
 2484 }
 2485 
 2486 sub warn_no_graphics {
 2487   logit("Warning: You may need to rely on LaTeX to generate images with $_[0] effects.\n");
 2488   1;
 2489 }
 2490 
 2491 sub warn_no_image_type {
 2492   logit("Warning: You cannot directly translate/modify graphics of $_[0] format.\n");
 2493   1;
 2494 }
 2495 
 2496 #------------------------------------------------------------------------------
 2497 # A very simple copy procedure
 2498 #------------------------------------------------------------------------------
 2499 
 2500 sub Copy {
 2501   my ($src,$dest) = @_;
 2502 
 2503   unless(open(IN,"<$src")) {
 2504     logit(qq{Error: Cannot read "$src": $!\n});
 2505     return 0;
 2506   }
 2507   local($/) = undef;
 2508   binmode IN;
 2509   my $contents = <IN>;
 2510   close(IN);
 2511   unless(open(OUT,">$dest")) {
 2512     logit(qq{Error: Cannot write "$dest": $!\n});
 2513     return 0;
 2514   }
 2515   binmode OUT;
 2516   print OUT $contents;
 2517   unless(close(OUT)) {
 2518     logit(qq{Error: Could not write "$dest": $!\n});
 2519     return 0;
 2520   }
 2521   1;
 2522 }
 2523 
 2524 #------------------------------------------------------------------------------
 2525 # delete multiple entries from an array !not used!
 2526 #------------------------------------------------------------------------------
 2527 
 2528 sub uniquify {
 2529   my @ary = @_;
 2530   my %seen = ();
 2531   return(grep(!$seen{$_}++,@ary));
 2532 }
 2533 
 2534 #------------------------------------------------------------------------------
 2535 # simplify path: remove dir/.. pairs from path
 2536 # Attention! This may not work properly if symbolic links are
 2537 # involved.
 2538 #------------------------------------------------------------------------------
 2539 
 2540 sub simplify_path {
 2541   my ($path) = @_;
 2542 
 2543   # Replace // and /./ by /
 2544   $path =~ s:\Q$dd\E\.?\Q$dd\E:$dd:g;
 2545   1 while($path =~ s:\Q$dd\E[^$dd$dd]+\Q$dd\E\.\.(\Q$dd\E|$):$1:);
 2546   $path;
 2547 }
 2548 
 2549 #------------------------------------------------------------------------------
 2550 # Write everything to screen and logfile
 2551 #------------------------------------------------------------------------------
 2552 
 2553 sub logit {
 2554   print @_;
 2555   print $LOG @_ if(defined $LOG);
 2556   
 2557 }
 2558 
 2559 #------------------------------------------------------------------------------
 2560 # do some cleanups before exit
 2561 #------------------------------------------------------------------------------
 2562 
 2563 sub cleanup {
 2564   my ($err) = @_;
 2565 
 2566   if(defined $LOG) {
 2567     $LOG->close;
 2568   }
 2569   if($err) {
 2570     unlink $CFGFILE;
 2571   }
 2572 }
 2573 
 2574 #------------------------------------------------------------------------------
 2575 # on DOSish systems prepend drive letter if not present
 2576 #------------------------------------------------------------------------------
 2577 
 2578 sub add_drive_letter {
 2579   if($newcfg{'plat'} =~ /win|dos|os2/ && $_[0] !~ /^[A-Z]:/i) {
 2580     my $cwd = L2hos->Cwd();
 2581     my ($drive) = ($cwd =~ /^([A-Z]:)/i);
 2582     if($drive) {
 2583       $_[0] = "$drive$_[0]";
 2584     } else {
 2585       logit("\nError: Cannot parse drive letter from current directory\n");
 2586     }
 2587   }
 2588   $_[0];
 2589 }
 2590 
 2591 __END__
 2592 
 2593 ##############################################################################
 2594 # kpsewhich style 1:
 2595 #
 2596 #Usage: C:\TEX\BIN\WIN32\KPSEWH~1.EXE [OPTION]... [FILENAME]...
 2597 #  Standalone path lookup and expansion for Kpathsea.
 2598 #
 2599 #-debug=NUM             set debugging flags.
 2600 #-D, -dpi=NUM           use a base resolution of NUM; default 600.
 2601 #-expand-braces=STRING  output variable and brace expansion of STRING.
 2602 #-expand-path=STRING    output complete path expansion of STRING.
 2603 #-expand-var=STRING     output variable expansion of STRING.
 2604 #-format=NAME           use file type NAME (see list below).
 2605 #-help                  print this message and exit.
 2606 #-interactive           ask for additional filenames to look up.
 2607 #[-no]-mktex=FMT        disable/enable mktexFMT generation (FMT=pk/mf/tex/tfm).
 2608 #-mode=STRING           set device name for $MAKETEX_MODE to STRING;
 2609 #                       no default.
 2610 #-must-exist            search the disk as well as ls-R if necessary
 2611 #-path=STRING           search in the path STRING.
 2612 #-progname=STRING       set program name to STRING.
 2613 #-show-path=NAME        output search path for file type NAME (see list below).
 2614 #-version               print version number and exit.
 2615 #
 2616 #Email bug reports to tex-k@mail.tug.org.
 2617 #
 2618 #Recognized format names and their suffixes:
 2619 #gf: gf
 2620 #pk: pk
 2621 #bitmap font:
 2622 #tfm: .tfm
 2623 #afm: .afm
 2624 #base: .base
 2625 #bib: .bib
 2626 #bst: .bst
 2627 #cnf: .cnf
 2628 #ls-R: ls-R
 2629 #fmt: .fmt .efmt .efm
 2630 #map: .map
 2631 #mem: .mem
 2632 #mf: .mf
 2633 #mfpool: .pool
 2634 #mft: .mft
 2635 #mp: .mp
 2636 #mppool: .pool
 2637 #MetaPost support:
 2638 #ocp: .ocp
 2639 #ofm: .ofm .tfm
 2640 #opl: .opl
 2641 #otp: .otp
 2642 #ovf: .ovf
 2643 #ovp: .ovp
 2644 #graphic/figure: .eps .epsi
 2645 #tex: .tex
 2646 #TeX system documentation:
 2647 #texpool: .pool
 2648 #TeX system sources:
 2649 #PostScript header: .pro .enc
 2650 #Troff fonts:
 2651 #type1 fonts: .pfa .pfb
 2652 #vf: .vf
 2653 #dvips config:
 2654 #ist: .ist
 2655 #truetype fonts: .ttf .ttc
 2656 #type42 fonts:
 2657 #web2c files:
 2658 #other text files:
 2659 #other binary files:
 2660 #
 2661 ##############################################################################
 2662 # kpsewhich style 2:
 2663 #
 2664 #kpsewhich: unknown option 'h' ignored.
 2665 #Usage: kpsewhich: [options] pathtype filename
 2666 #
 2667 #Valid options are the following:
 2668 #  -n progname  : pretend to be progname to kpathsea
 2669 #  -m mode      : set Metafont mode
 2670 #  -w           : act like kpsewhich
 2671 #  -p           : act like kpsepath
 2672 #  -v           : act like kpsexpand
 2673 #
 2674 #Valid pathtypes are:
 2675 #  gf            : generic font bitmap
 2676 #  pk            : packed bitmap font
 2677 #  base          : Metafont memory dump
 2678 #  bib           : BibTeX bibliography source
 2679 #  bst           : BibTeX style files
 2680 #  cnf           : Kpathsea runtime configuration files
 2681 #  fmt           : TeX memory dump
 2682 #  mem           : MetaPost memory dump
 2683 #  mf            : Metafont source
 2684 #  mfpool        : Metafont program strings
 2685 #  mp            : MetaPost source
 2686 #  mppool        : MetaPost program strings
 2687 #  mpsupport     : MetaPost support files
 2688 #  pict          : Other kinds of figures
 2689 #  tex           : TeX source
 2690 #  texpool       : TeX program strings
 2691 #  tfm           : TeX font metrics
 2692 #  vf            : virtual font
 2693 #  dvips_config  : dvips config files
 2694 #  dvips_header  : dvips header files
 2695 #  troff_font    : troff fonts