asm/preproc.c: use nasm_add_string_to_strlist()
[nasm.git] / doc / pspdf.pl
blob238806682b4dfe4988c3c774b659c9163c16a86a
1 #!/usr/bin/perl
3 # Wrapper around a variety of programs that can do PS -> PDF conversion
6 use strict;
7 use File::Spec;
9 my $compress = 1;
11 my $win32_ok = eval {
12 require Win32::TieRegistry;
13 Win32::TieRegistry->import();
17 while ($ARGV[0] =~ /^-(.*)$/) {
18 my $opt = $1;
19 shift @ARGV;
21 if ($opt eq '-nocompress') {
22 $compress = 0;
26 my ($in, $out) = @ARGV;
28 if (!defined($out)) {
29 die "Usage: $0 [-nocompress] infile ou{ tfile\n";
32 # If Win32, help GhostScript out with some defaults
33 sub win32_gs_help() {
34 return if (!$win32_ok);
36 use Sort::Versions;
37 use sort 'stable';
39 my $Reg = $::Registry->Open('', {Access => 'KEY_READ', Delimiter => '/'});
40 my $dir;
41 my @gs;
43 foreach my $k1 ('HKEY_CURRENT_USER/Software/',
44 'HKEY_LOCAL_MACHINE/SOFTWARE/') {
45 foreach my $k2 ('Artifex/', '') {
46 foreach my $k3 ('GPL Ghostscript/', 'AFPL Ghostscript/',
47 'Ghostscript/') {
48 my $r = $Reg->{$k1.$k2.$k3};
49 if (ref($r) eq 'Win32::TieRegistry') {
50 foreach my $k (keys(%$r)) {
51 my $rk = $r->{$k};
52 if (ref($rk) eq 'Win32::TieRegistry' &&
53 defined($rk->{'/GS_LIB'})) {
54 push @gs, $rk;
62 @gs = sort {
63 my($av) = $a->Path =~ m:^.*/([^/]+)/$:;
64 my($bv) = $b->Path =~ m:^.*/([^/]+)/$:;
65 versioncmp($av, $bv);
66 } @gs;
68 return unless (scalar(@gs));
70 $ENV{'PATH'} .= ';' . $gs[0]->{'/GS_LIB'};
71 $ENV{'GS_FONTPATH'} .= (defined($ENV{'GS_FONTPATH'}) ? ';' : '')
72 . $ENV{'windir'}.'\\fonts';
75 # Remove output file
76 unlink($out);
78 # 1. Acrobat distiller
79 my $r = system('acrodist', '-n', '-q', '--nosecurity', '-o', $out, $in);
80 exit 0 if ( !$r && -f $out );
82 # 2. ps2pdf (from Ghostscript)
83 # The -I clause helps Ghostscript pick up the Fontdir file written by findfont.ph
84 # GhostScript uses # rather than - to separate options and values on Windows, it seems...
85 win32_gs_help();
86 my $o = $win32_ok ? '#' : '-';
87 my $r = system('ps2pdf', "-dOptimize${o}true", "-dEmbedAllFonts${o}true",
88 "-dCompressPages${o}" . ($compress ? 'true' : 'false'),
89 "-dUseFlateCompression${o}true", $in, $out);
90 exit 0 if ( !$r && -f $out );
92 # 3. pstopdf (BSD/MacOS X utility)
93 my $r = system('pstopdf', $in, '-o', $out);
94 exit 0 if ( !$r && -f $out );
96 # Otherwise, fail
97 unlink($out);
98 exit 1;