File: configure-pstoimg

package info (click to toggle)
latex2html 98.1-pre2-b6-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 5,880 kB
  • ctags: 2,808
  • sloc: perl: 34,603; makefile: 690; sh: 107
file content (974 lines) | stat: -rwxr-xr-x 30,744 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
#!/usr/bin/perl -w
#use diagnostics;

if ($ENV{'LATEX2HTMLDIR'}) { $LATEX2HTMLDIR = $ENV{'LATEX2HTMLDIR'}; }
else {
  $LATEX2HTMLDIR='/usr/lib/latex2html'; # Inserted by installation script
}
if ("$ENV{'LATEX2HTMLDIR'}") { use lib $ENV{'LATEX2HTMLDIR'}; }
else {
  use lib '/usr/lib/latex2html'; # Inserted by installation script
}


###############################################################################
# $Id: configure-pstoimg,v 1.18 1998/05/06 22:33:14 latex2html Exp $
#
# Configure-Pstoimg
#
# Configuration Script for pstoimg
#
# Version V96.2
#
# Author: Marek Rouchal <marek@saftsack.fs.uni-bayreuth.de>
#
# This software is part of Latex2HTML, originally by Nikos Drakos
# It is published under the Gnu Public License and comes without any
# warranty.
#
# You aren't supposed to edit this script. You can specify command line
# options to customize it to your local setup.

###############################################################################
# Changes History
#
# $Log: configure-pstoimg,v $
# Revision 1.18  1998/05/06 22:33:14  latex2html
# -- fixed bug in parsing of output of "gs -h". Thanks Christoph Wutzke.
#
# Revision 1.17  1998/05/03 08:20:56  latex2html
#  --  added name of Ghostscript executable for OS/2 (thanks Uli Wortmann)
#  --  change use of &substitute_var_val  by Fabrice Popineau
#
# Revision 1.16  1998/04/28 10:41:25  latex2html
#  --  removed some debugging messages, sorry
#
# Revision 1.15  1998/04/28 10:39:02  latex2html
# 	implemented Fabrice Popineau's changes, for Win32 compatibility
#
#  --  uses a function &find_executable  defined in Override.pm
#  --  allows different name for the Ghostscript executable
#  --  defines $white_color and $bg_color for use with transparent images
#  --  opens scripts to be altered, before renaming for the backup
#  --  records both $GS_LIB and $GSLANDSCAPE into local.pm
#
# Revision 1.12  1997/09/27 10:37:47  JCL
# small change regarding EOF tag
#
# Revision 1.11  1997/08/13 15:27:33  JCL
# dies with message unless initialized via install-test
#
# Revision 1.10  1997/07/20 20:26:02  JCL
# .
#
# Revision 1.9  1997/07/20 20:13:38  JCL
# changed p/g (PNG/GIF) query
#
# Revision 1.8  1997/07/07 00:39:01  JCL
# smoothed the installation procedure:
#
#  - configure-pstoimg asks for the image type if invoked without args.
#  - configure-pstoimg now sets IMAGE_TYPE (gif|png) in latex2html.config
#    after it knows the image type.
#    Therefore, it needs the LATEX2HTMLDIR variable, which is substituted
#    by install-test.
#  - install-test checks for valid globbing
#  - install-test looks if LATEX2HTMLDIR is undefined, in this case it
#    prompts the user to get the directory and sets up latex2html.config.
#  - install-test substitutes LATEX2HTMLDIR also in configure-pstoimg
#    and prompts the user if to run configure-pstoimg finally.
#  - removed unused entries PBMPLUSDIR and USENETPBM from latex2html.config,
#    small changes to comments
#
# The installation scheme is now:
#   o unpack LaTeX2HTML
#   o copy the sources to the LaTeX2HTML directory
#
#   o run install-test and edit latex2html.config, or
#   o edit latex2html.config and run install-test
#
#   o translate manual
#
# Revision 1.7  1997/06/06 14:16:21  RRM
#  -   changed order of desirability among the Ghostscript devices,
#      so that anti-aliasing can be used, when possible
#
# Revision 1.6  1997/02/17 02:04:42  RRM
# small change regarding "_EOM_"
#
# Revision 1.5  1996/12/16 08:27:27  MRO
# Fixed minor things pstoimg and configure-pstoimg (extensions, switches).
#
# Revision 1.4  1996/12/15 18:35:53  MRO
# Changed pstoimg etc to enable runtime selection of output image format.
#
# Revision 1.3  1996/12/14 16:43:50  JCL
# changed the face substantially:
#  o chunked the code into functions
#  o creates or updates "local.pm" instead of pstoimg
#
# (end CVS log)
#
#---- patchlevel 3
# Fri Oct 25 1996: Eliminated some bugs and typos, introduced new option
#                  -center <width> to replace the awkward construction
#                  with -rightjustify -<witdth>
#                  Introduced PNG support and renamed pstogif to pstoimg
#---- patchlevel 2
#Thu Sep 19 1996: Removed some silly mistakes, changed &get_stdout_stderr,
#                 added a "\s*" in the parsing of command line options.
#                 Thanks to Ross Moore for the hints.
#---- patchlevel 1
#Tue Sep 17 1996: Adjusted some things to make this run under Perl4.036. It's
#                 now tested on perl5.003/Linux and perl4.036/IRIX.

###############################################################################
# Default names
# You may specify alternative names via the command line, too
if ($^O =~ MSWin32) {
    $Default{'GS'}='gswin32c';
} elsif ($^O =~ os2) {
    $Default{'GS'}='gsos2.exe';
} else {
    $Default{'GS'}='gs';
}
$Default{'PNMCROP'}='pnmcrop';
$Default{'PNMFLIP'}='pnmflip';
$Default{'PPMTOGIF'}='ppmtogif';
$Default{'PNMTOPNG'}='pnmtopng';
$Default{'PPMQUANT'}='ppmquant';
$Default{'PNMCAT'}='pnmcat';
$Default{'PNMFILE'}='pnmfile';
$Default{'PBMMAKE'}='pbmmake';
# $Default{'BLANKPBM'}='icons/blank.pbm'; # obsolete, we now use PBMMAKE
# $Default{'PNMTILE'}='pnmtile';          # obsolete, we now use PBMMAKE
$Default{'GIFTRANS'}='giftrans';
$Default{'GIFTOOL'}='giftool';

@PATH = ".";
$dd = '/';

use Override qw($DEBUG getpwuid link setenv getenv symlink rename
               getcwd syswait find_executable
               substitute_var_val $LATEX2HTMLDIR
               make_directory_absolute unlink $dd $envkey $image_pre);

###############################################################################
# Parse the command line

die "Please run install-test, it will start this script automatically.\n"
    unless $LATEX2HTMLDIR;

if(@ARGV) {
   foreach(@ARGV) {
      if(/^(-h|--help)$/) {
         &usage;
         exit 0;
         }
      elsif(/^-gif$/) {
         $configure_gif = 1;
         }
      elsif(/^-png$/) {
         $configure_png = 1;
         }
      elsif(/^(\w+)=(\S+)\s*$/) { # variable=value
         $user_settings{$1}=$2;
         # print "Got option \$$1=$2\n";
         }
      else {
         &usage;
         die("Error: Illegal Argument \"$_\"\n");
         }
      }
   }

###############################################################################

&main;

sub main {
    &greetings;
    &next_step;
    &read_config_file;
    &check_image_extension;
    &next_step if $configure_gif;
    &setup_search_path;
    &configure_ghostscript;
    &next_step;
    &configure_pbmtools;
    &next_step;
    &configure_trans_n_inter;
    &next_step;
    &create_configuration;
    &mission_complete;
}


sub read_config_file {
    &deal_with_forward_references;
    require("latex2html.config") if
	((-f "latex2html.config") ||
	 (-f "$LATEX2HTMLDIR${dd}latex2html.config") ||
	 die "Could not find file latex2html.config or $LATEX2HTMLDIR${dd}latex2
html.config\n");
}

# Changes lines of the form:
# $IMAGE_TYPE=... to
# $IMAGE_TYPE='GIF' (or 'PNG', repsectively)
#
sub substitute_img_var {
  local($file) = @_;
  local($type) = ($configure_gif ? "gif" : "png");
  local($SUCCESS) = 0;
  
  # Added for Debian.
  my $filename = "$LATEX2HTMLDIR${dd}$file";
  if ($file =~ m/latex2html.config/o) {
    $filename = "/etc/latex2html.config";
  }
  if ( (-f "$filename") ||
       die "\nCannot find $filename\nPlease check the value of \$LATEX2HTMLDIR in latex2html.config\n") {
    rename("$filename","$filename.bak") || die "Cannot rename $filename: $!";
    open(IN, "<$filename.bak") || die "Cannot open $filename.bak: $!";
    open(OUT, ">$filename")    || die "Cannot open $filename: $!";
    chmod(0755, "$filename")   if -x "$filename.bak";
    
    while (<IN>) {
      s/\$IMAGE_TYPE\s*=.*$/
	do {$SUCCESS = 1;
	    "\$IMAGE_TYPE='$type';" .
	      "# Inserted by installation script"}/eo;
      print OUT;
    }
    close IN;
    close OUT;
  }
  $SUCCESS;
}


sub deal_with_forward_references {
    foreach ("ignore_commands", "process_commands_in_tex") {
	eval "sub $_ {}"}
}


###############################################################################
# Preamble
###############################################################################
sub greetings {

    print <<"_EOM_";

This is configure-pstoimg V96.2 by Marek Rouchal

Welcome to the Configuration of pstoimg!

You will be guided in few steps through the setup of pstoimg, the part of
latex2html that produces bitmap images from the LaTeX source.
Type 'configure-pstoimg -h' for a brief usage information and a list of
user-definable options.

_EOM_
}


###############################################################################
# Legal notice for GIF format
###############################################################################
sub check_image_extension {

    if(!$configure_gif && !$configure_png) {
        print <<"_EOM_";

Pstoimg can support both GIF and PNG format.
Please note that there are certain legal limitations on the use of the GIF
image format.

If you go on, pstoimg will be configured for GIF or PNG format.
You may reconfigure pstoimg at any time by saying configure-pstoimg.
Which format do you want to have supported?
Answer g (GIF) or p (PNG).

_EOM_
      while (!$configure_gif && !$configure_png) {
	$_=<STDIN>;
	if (/^\s*g/) {
	    $configure_gif=1;
	}
	if (/^\s*p/) {
	    $configure_png=1;
	}
      }
    }
    print "Configuring for ",($configure_gif?"GIF":"PNG")," format.\n";
    print "Changing \$IMAGE_TYPE in latex2html.config...",
#	(&substitute_img_var("latex2html.config")?"succeeded\n":"\n*failed*\n");
        (&substitute_var_val("latex2html.config", "^\\\$IMAGE_TYPE\\\s*=.*"
		, "\$IMAGE_TYPE = '" .($configure_gif ? "gif":"png")
		    . "';")? "succeeded\n":"\n*failed*\n");
}


###############################################################################
# Search Path
###############################################################################
sub setup_search_path {

    $_ = (defined $user_settings{'PATH'})
         ? join(":",$user_settings{'PATH'},$ENV{'PATH'}) : $ENV{'PATH'};
    foreach(split(/:/)) {
        s+/$++;
        push(@PATH,$_);
    }
}


###############################################################################
# Ghostscript Configuration
###############################################################################
sub configure_ghostscript {

    print <<"_EOM_";

Ghostscript Configuration
=========================

_EOM_

# Try to determine path
    $gs=$user_settings{'GS'} || $Default{'GS'};
    $GS=&find_executable($gs,@PATH);

    die <<"_EOM_" unless(defined $GS);
Fatal Error: \"$gs\" not found. Pstoimg will not work.
             You must have Ghostscript installed on your system. You can find
             Ghostscript as source code or precompiled binary on every major
             ftp site. If you decide to build your own gs do not forget to
             include the pnmraw device for best latex2html performance.
             Current version of Aladdin Ghostscript is 4.03.
_EOM_
# Get gs devices
    $gs_devs="";
    $flag=0;
    open(GS,"$GS -h |") || die <<"_EOM_";
Fatal Error: Execution of \"$gs -h\" failed:
             $!
_EOM_
    while (<GS>) {
        if(/Ghostscript\s*(Version|)\s*([\d\.]+)/i) {
            $gs_version=$2;
        }
        if(/Available devices/i) {
            $flag=1; # Now look for the devices
        }
        elsif(/^\s*Search path/i) {
            $flag=2; # Now look for the gs lib path
        }
        elsif ($flag == 1) {
# if line starts with whitespace, then we're in the devices list
            if(/^\s+/) {
                chop;
                $gs_devs .= $_;
            }
            else { $flag=0; } # no more devices
        }
        elsif ($flag == 2) {
# if line starts with whitespace, then we're in the search path list
            if(/^\s+/) {
                chop;
                push(@gs_lib_path,split(${envkey},$_));
            }
            else { $flag=0; } # no more path entries
        }
    }
    close(GS);

    print "Ghostscript is \"$GS\"";
    if(defined $gs_version) {
        print ", Version $gs_version\n"; 
    }
    else {
        print "\n";
    }
    $Configuration{'GS'}=$GS;                                       

# GS Devices needed for pstoimg in order of descending preference
    $gs_desired_devs="ppmraw pgnmraw pgmraw pnmraw pbmraw ppm pgnm pgm pnm pbm";

    $gs_desired_devs=join(" ",$user_settings{'GS_DEVICE'},$gs_desired_devs)
        if(defined $user_settings{'GS_DEVICE'});

    foreach(split(" ",$gs_desired_devs)) {
        if($gs_devs =~ /\b$_\b/) {
    	    $GS_DEVICE=$_;
    	    last;
        }
    }
    die <<"_EOM_" unless defined $GS_DEVICE;
Fatal Error: No appropriate Ghostscript device found.
             Pstoimg needs one of the following devices:
             \"$gs_desired_devs\"
_EOM_

    if (defined $user_settings{'GS_DEVICE'} &&
        "$user_settings{'GS_DEVICE'}" ne "$GS_DEVICE") {
        print <<"_EOM_";
Warning: This version of Ghostscript doesn't support a \"$user_settings{'GS_DEVICE'}\" device.
         Pstoimg will use the $GS_DEVICE device instead.
_EOM_
    }
    else {
        print "Pstoimg will use the $GS_DEVICE device.\n";
    }
    $Configuration{'GS_DEVICE'}=$GS_DEVICE;

#    if(!@gs_lib_path) {
#        print "Trying to guess the Ghostscript library path...\n";
#        @gs_lib_path = ('/usr/share/ghostscript','/usr/lib/ghostscript/',
#            '/usr/local/ghostscript','/usr/local/share/ghostscript',
#            '/usr/local/lib/ghostscript');
    if ($^O =~ MSWin32) {
        local($gs_dir);
        $gs_dir = $GS;
        $gs_dir =~ s/\\/${dd}/g;
        $gs_dir =~ s!/[^/]*$!!;
        @gs_lib_path = ("$gs_dir", "$gs_dir/fonts", "$gs_dir/../fonts");
        $GS_LIB = join(";", @gs_lib_path);
    } else {
        if(!@gs_lib_path) {
            print "Trying to guess the Ghostscript library path...\n";
            @gs_lib_path = ('/usr/share/ghostscript','/usr/lib/ghostscript/',
                '/usr/local/ghostscript','/usr/local/share/ghostscript',
                '/usr/local/lib/ghostscript');
        }
        $GS_LIB = join(";", @gs_lib_path);
    }
    foreach $path (@gs_lib_path) {
        $path =~ s/^\s*(\S*)\s*$/$1/; # strip whitespace
        if(-d "$path" && -f "$path/landscap.ps") {
            $GSLANDSCAPE = "$path/landscap.ps";
            print "Ghostscript library path is $path\n";
        }
    }
    if(!$GS_LIB) {
        $GS_LIB = "";
        print <<"_EOM_";
Warning: Couldn't determine Ghostscript library path (the path where e.g.
         landscap.ps resides). You have to include \$GS_LIB_PATH = <path>
         by hand in local.pm

_EOM_
    }
    $Configuration{'GS_LIB'} = $GS_LIB;
    $Configuration{'GSLANDSCAPE'} = $GSLANDSCAPE;
}


###############################################################################
# Netpbm/Pbmplus Configuration
###############################################################################
sub configure_pbmtools {

    print <<"_EOM_";

Netpbm/Pbmplus Configuration
============================

_EOM_
    if($configure_gif) {
        $ppmtogif=$user_settings{'PPMTOGIF'} || $Default{'PPMTOGIF'};
        $PPMTOGIF=&find_executable($ppmtogif,@PATH);
        die <<"_EOM_" unless defined $PPMTOGIF;
Fatal Error: \"$ppmtogif\" not found.
             Pstoimg won't be able to produce GIF images.
      Clues: Is Netpbm/Pbmplus installed on your system?
             Are the executables in the search path?
             Do You have execute permissions?
             If none of the above apply, get the netpbm package
             (source code or binary) from any major ftp site and
             install it on your system.
_EOM_

# -h is an invalid option. Nevertheless it forces ppmtogif to output a
# usage information to stderr
        print "$ppmtogif is $PPMTOGIF\n";
        $Configuration{'PPMTOGIF'}=$PPMTOGIF;
        # $Configuration{'EXTENSION'}='gif'; # is now runtime setting
        $_=join(" ",&get_stdout_stderr("$PPMTOGIF -h"));
        if(/-transparent/) {
            $HOWTO_TRANSPARENT_GIF="netpbm";
            print "    $ppmtogif understands -transparent. Good!\n";
        }
        if(/-interlace/) {
            $HOWTO_INTERLACE_GIF="netpbm";
            print "    $ppmtogif understands -interlace. Good!\n";
        }
    }
    if($configure_png) {
        $pnmtopng=$user_settings{'PNMTOPNG'} || $Default{'PNMTOPNG'};
        $PNMTOPNG=&find_executable($pnmtopng,@PATH);
        die <<"_EOM_" unless defined $PNMTOPNG;
Fatal Error: \"$pnmtopng\" not found.
             Pstoimg won't be able to produce png images.
      Clues: Is pnmtopng installed on your system? Do you have the
             libpng/libz libraries?  Are the executables in the search path?
             Do you have execute permissions?
             If none of the above apply, get pnmtopng (it may require
             libpng and libz) - either source code or binary - from any major
             ftp site and install it on your system.
_EOM_
        print "$pnmtopng is $PNMTOPNG\n";
        $Configuration{'PNMTOPNG'}=$PNMTOPNG;
        # $Configuration{'EXTENSION'}='png'; # is now runtime setting
# MRO: pnmtopng is capable to do these jobs. period.
#        $_ = join(" ",&get_stdout_stderr("$PNMTOPNG -help"));
#        if(/-transparent/) {
#            $HOWTO_TRANSPARENT="netpbm";
#            print "    $pnmtopng understands -transparent. Good!\n";
#        }
#        if(/-interlace/) {
#            $HOWTO_INTERLACE="netpbm";
#            print "    $pnmtopng understands -interlace. Good!\n";
#        }
    }
    $pnmcrop=$user_settings{'PNMCROP'} || $Default{'PNMCROP'};
    $PNMCROP=&find_executable($pnmcrop,@PATH);
    die <<"_EOM_" unless defined $PNMCROP;
Fatal Error: \"$pnmcrop\" not found.
             pstoimg won't be able to crop images.
      Clues: Is Netpbm/Pbmplus installed correctly on your system?
             Are the executables in the search path?
             Do You have execute permissions?
_EOM_
    print "$pnmcrop is $PNMCROP\n";
    $Configuration{'PNMCROP'}=$PNMCROP;

    $warnings=0;

    $pnmflip=$user_settings{'PNMFLIP'} || $Default{'PNMFLIP'};
    $PNMFLIP=&find_executable($pnmflip,@PATH);
    if(defined $PNMFLIP) {
        print "$pnmflip is $PNMFLIP\n";
    }
    else {
        warn <<"_EOM_";
Warning:     \"$pnmflip\" not found.
             pstoimg won't be able to flip images.
_EOM_
       $warnings=1;
       $PNMFLIP="";
    }
    $Configuration{'PNMFLIP'}=$PNMFLIP;

    $ppmquant=$user_settings{'PPMQUANT'} || $Default{'PPMQUANT'};
    $PPMQUANT=&find_executable($ppmquant,@PATH);
    if(defined $PPMQUANT) {
        print "$ppmquant is $PPMQUANT\n";
    }
    else {
        warn <<"_EOM_";
Warning:     \"$ppmquant\" not found.
             pstoimg won't be able to reduce colors of images. You may run 
             into problems if you include color images in your LaTeX source.
_EOM_
        $warnings=1;
        $PPMQUANT="";
    }
    $Configuration{'PPMQUANT'}=$PPMQUANT;

    $pnmfile=$user_settings{'PNMFILE'} || $Default{'PNMFILE'};
    $PNMFILE=&find_executable($pnmfile,@PATH);

    if(defined $PNMFILE) {
        print "$pnmfile is $PNMFILE\n";
    }
    else {
        warn <<"_EOM_";
Warning:     \"$pnmfile\" not found.
             pstoimg won't be able to right/top justify equations.
_EOM_
        $warnings=1;
        $PNMFILE="";
    }
    $Configuration{'PNMFILE'}=$PNMFILE;

# Not needed any more, we now use pbmmake
# $pnmtile=$user_settings{'PNMTILE'} || $Default{'PNMTILE'};
# $PNMTILE=&find_executable($pnmtile);
# if(defined $PNMTILE) {
#    print "$pnmtile is $PNMTILE\n";
#    }
# else {
#    warn <<"_EOM_";
# Warning:     \"$pnmtile\" not found.
#              pstoimg won't be able to right/top justify equations.
# _EOM_
#    $warnings=1;
#    $PNMTILE="";
#    }
# $Configuration{'PNMTILE'}=$PNMTILE;

    $pnmcat=$user_settings{'PNMCAT'} || $Default{'PNMCAT'};
    $PNMCAT=&find_executable($pnmcat,@PATH);

    if(defined $PNMCAT) {
        print "$pnmcat is $PNMCAT\n";
    }
    else {
        warn <<"_EOM_";
Warning:     \"$pnmcat\" not found.
             pstoimg won't be able to right/top justify equations.
_EOM_
        $warnings=1;
        $PNMCAT="";
    }
    $Configuration{'PNMCAT'}=$PNMCAT;

    $pbmmake=$user_settings{'PBMMAKE'} || $Default{'PBMMAKE'};
    $PBMMAKE=&find_executable($pbmmake,@PATH);
    if(defined $PBMMAKE) {
        print "$pbmmake is $PBMMAKE\n";
    }
    else {
        warn <<"_EOM_";
Warning:     \"$pbmmake\" not found.
             pstoimg won't be able to right/top justify equations.
_EOM_
        $warnings=1;
        $PBMMAKE="";
    }
    $Configuration{'PBMMAKE'}=$PBMMAKE;

    if($warnings == 1) {
        print <<"_EOM_";
      Clues: Is Netpbm/Pbmplus installed correctly on your system?
             Are the executables in the search path?
             Do You have execute permissions?
_EOM_
    }
}


###############################################################################
# Transparent/Interlaced Configuration
###############################################################################
sub configure_trans_n_inter {

    print <<"_EOM_";

Transparent/Interlaced Image Configuration
==========================================

_EOM_
    if ($configure_png) {
        print "Using $PNMTOPNG to make transparent/interlaced PNGs.\n";
    }
    if(defined $HOWTO_TRANSPARENT_GIF) {
        print "Using $HOWTO_TRANSPARENT_GIF to make transparent GIFs.\n";
    }
    if(defined $HOWTO_INTERLACE_GIF) {
        print "Using $HOWTO_INTERLACE_GIF to make interlaced GIFs.\n";
    }
    if ($configure_gif &&
        (!defined $HOWTO_TRANSPARENT_GIF || !defined $HOWTO_INTERLACE_GIF)) {

        $giftool=$user_settings{'GIFTOOL'} || $Default{'GIFTOOL'};
        $GIFTOOL=&find_executable($giftool,@PATH);
        if(defined $GIFTOOL) {
            $_=join(" ",&get_stdout_stderr("$GIFTOOL -h"));
            if(/-rgb/ && !defined $HOWTO_TRANSPARENT_GIF) {
                $HOWTO_TRANSPARENT_GIF="giftool";
                print "Will use $GIFTOOL to make images transparent\n";
                $Configuration{'GIFTOOL'}=$GIFTOOL;
            }
            if(/-i/ && !defined $HOWTO_INTERLACE_GIF) {
                $HOWTO_INTERLACE_GIF="giftool";
                print "Will use $GIFTOOL to make images interlaced\n";
                $Configuration{'GIFTOOL'}=$GIFTOOL;
            }
        }
    }
    if($configure_gif && !defined $HOWTO_TRANSPARENT_GIF) {
        $giftrans=$user_settings{'GIFTRANS'} || $Default{'GIFTRANS'};
        $GIFTRANS=&find_executable($giftrans,@PATH);

        if(defined $GIFTRANS) {
            $_=(&get_stdout_stderr($GIFTRANS))[0];
            if(/-t/) {
                $HOWTO_TRANSPARENT_GIF="giftrans";
                print "Will use $GIFTRANS to make images transparent\n";
                $Configuration{'GIFTRANS'}=$GIFTRANS;
            }
        }
    }
    if($configure_gif && !defined $HOWTO_TRANSPARENT_GIF) {
        $HOWTO_TRANSPARENT_GIF="";
        warn <<"_EOM_";
Warning: Pstoimg won't be able to create transparent GIFs, i.e. the
         images will have an ugly white background when viewed with the
         browser. You may want to get one of the following packages from
         any major ftp site, each of them capable of creating transparent
         GIF images: Netpbm, giftool, giftrans.
_EOM_
    }
    if($configure_gif && !defined $HOWTO_INTERLACE_GIF) {
        $HOWTO_INTERLACE_GIF="";
        warn <<"_EOM_";
Warning: Pstoimg won't be able to create interlaced images. Interlaced
         images build up very quickly while downloading starting from a
         coarse grid and becoming sharper with the process of downloading.
         You can easily do without this, but it is a convenient thing. You
         may want to get one of the following packages from any major ftp
         site to make interlaced images: Netpbm, giftool
_EOM_
    }
   
    if($configure_gif) {
        $Configuration{'HOWTO_TRANSPARENT_GIF'}=$HOWTO_TRANSPARENT_GIF;
        $Configuration{'HOWTO_INTERLACE_GIF'}=$HOWTO_INTERLACE_GIF;
    }
    if ($^O =~ MSWin32) {
        $Configuration{'white_color'} = "#ffffff";
        $Configuration{'bg_color'} = "#bfbfbf";
    } else {
        $Configuration{'white_color'} = "\\#ffffff";
        $Configuration{'bg_color'} = "\\#bfbfbf";
    }
}


###############################################################################
# Modification of pstoimg
###############################################################################
sub create_configuration {

    print <<"_EOM_";
Setup pstoimg
=============
_EOM_

    if ( -f "/etc/l2hpstoimg.cfg") {
	&update_local_pm;
    }
    else {
	&create_local_pm;
    }
}


sub create_local_pm {

    print <<"_EOM_";

Creating local configuration file...

_EOM_

    open(OUT, ">/etc/l2hpstoimg.cfg");
    local($vars) = "";
    foreach(keys %Configuration) {
        $vars .= "\$$_ = '$Configuration{$_}'; # Inserted by configure-pstoimg\n";
    }
    print OUT <<"_EOF_";
#################################################################
# local.pm
#
# Local Configuration for LaTeX2HTML
#
# This file is created automatically. Do not edit!
#
#################################################################

package main;

### start pstoimg configuration ###
$vars
### end pstoimg configuration ###

1;
_EOF_
    close OUT;
}


sub update_local_pm {

    print <<"_EOM_";

Updating local configuration file...

_EOM_

    # $config_vars=join("|",keys %Configuration);

    rename("/etc/l2hpstoimg.cfg","/etc/l2hpstoimg.dpkg-old");
    open(IN, "</etc/l2hpstoimg.dpkg-old");
    open(OUT, ">/etc/l2hpstoimg.cfg");

    local($vars) = "";
    foreach(keys %Configuration) {
        $vars .= "\$$_ = '$Configuration{$_}'; # Inserted by configure-pstoimg\n";
    }

    local($on) = 0;
    while (<IN>) {
	if (/end pstoimg configuration/) {
	    print OUT $vars;
	    $on = 0;
	}
	print OUT unless $on;
	$on++ if /start pstoimg configuration/;
    }
    close IN;
    close OUT;
}

#$pwd = cwd;
#$BLANKPBM=(defined $user_settings{'BLANKPBM'}) ? $user_settings{'BLANKPBM'} :
#   $pwd . "/icons/blank.pbm";
#die <<"_EOM_" unless (-r $BLANKPBM);
#Fatal Error: Can't read $BLANKPBM: $!
#             blank.pbm is required for justifying equations and is part of
#             the latex2html distribution. Chdir to the latex2html directory.
#_EOM_
#print "Using $BLANKPBM as blank.pbm\n";
#$Configuration{'BLANKPBM'}=$BLANKPBM;



###############################################################################
# The end
###############################################################################
sub mission_complete {
    print <<"_EOM_";

Well done!
Pstoimg is now hopefully configured to run on your system.
Type 'pstoimg -h' for a brief usage information.
Please specify the desired image format in the file latex2html.config.

_EOM_
    exit 0;
}


###############################################################################

#RRM: moved to Override.pm (thanks, Fabrice Popineau)
#
#sub find_executable {
#    local($name) = $_[0];
#    if($name =~ m+^/+) {
#        if(-e "$name" && -x _ ) {
#            return "$name";
#        }
#    }
#    if($name =~ s+.*/++o) {
#        warn "Warning: Stripping invalid path from $name\n";
#    }
#    foreach(@PATH) {
#        if(-e "$_/$name") {
#            if( -x _ ) {
#                return "$_/$name";
#            }
#            else {
#                warn "Warning: $_/$name exists, but is not executable.\n";
#            }
#        }
#    }
#    return(undef);
#}


###############################################################################
sub get_stdout_stderr {
    local($prog) = $_[0];
    local(@stack);

    open(SO, ">&STDOUT");
    stat(SO); # to suppress warnings...
    open(SE, ">&STDERR");
    stat(SE); # to suppress warnings...

    open(FOO, ">foo$$") || die "Can't open foo$$\n";
    open(STDOUT, ">&FOO") || die "Can't redirect stdout\n";
    open(STDERR,">&FOO") || die "Can't dup stdout\n";

    select(STDERR); $| = 1;
    select(STDOUT); $| = 1;

    system("$prog");
#    `$prog >& foo$$`; # This was a hack...

    open(STDOUT, ">&SO");
    open(STDERR, ">&SE");

    close(FOO);
    close(SO);
    close(SE);

    open(FOO,"<foo$$");
    while(<FOO>) {
        push(@stack,$_);
        }
    close(FOO);
    unlink "foo$$";
    return @stack;
}


###############################################################################
sub next_step {
   print "\nHit return to proceed to the next configuration step.\n";
   $_=<STDIN>;
}


###############################################################################
sub usage {
   print <<'_EOM_';

This is configure-pstoimg V96.2 by Marek Rouchal
       - configures pstoimg for your system

This software is part of LaTeX2HTML by Nikos Drakos

Usage: configure-pstoimg [-gif] [-png] [OPT=VAL [OPT2=VAL2 [...]]]
       configure-pstoimg -h

Options: -gif     Configure pstoimg for GIF image format
         -png     Configure pstoimg for PNG image format
         -h       Show this message
         OPT=VAL  Set configuration preferences:

   General options:
     PATH      A colon-separated list of directories where to look for
               executables. Your environment PATH is searched automatically.
   Ghostscript options:
     GS        Name (not path) of the Ghostscript executable
     GS_DEVICE Ghostscript output device (pnmraw recommended)
   Netpbm/Pbmplus Options:
     PNGTOPNM  Name (not path) of the pnmtopng executable (default: pnmtopng)
     PPMTOGIF  Name (not path) of the ppmtogif executable (default: ppmtogif)
     PPMQUANT  Name (not path) of the pnmquant executable (default: ppmquant)
     PNMCROP   Name (not path) of the pnmcrop executable (default: pnmcrop)
     PNMFLIP   Name (not path) of the pnmflip executable (default: pnmflip)
     PNMFILE   Name (not path) of the pnmfile executable (default: pnmfile)
     PBMMAKE   Name (not path) of the pbmmake executable (default: pbmmake)
     PNMCAT    Name (not path) of the pnmcat executable (default: pnmcat)
     GIFTOOL   Name (not path) of the giftool executable (default: giftool)
     GIFTRANS  Name (not path) of the giftrans executable (default: giftrans)
   Required Packages:
     For best performance, your system should have the following packages:
           Ghostscript-4.03, netpbm-1mar1994, pnmtopng-2.31
     These packages are freely available from any major ftp site.
_EOM_
## These are obsolete:
#     PNMTILE   Name (not path) of the pnmtile executable (default: pnmtile)
#   Alignment Image
#     BLANKPBM  Path (and name) to the blank.pbm file supplied with latex2html
   return 0;
   }