summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/tlgs/gswin32/ps2ps.tlu
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/tlgs/gswin32/ps2ps.tlu')
-rwxr-xr-xMaster/texmf-dist/scripts/tlgs/gswin32/ps2ps.tlu117
1 files changed, 90 insertions, 27 deletions
diff --git a/Master/texmf-dist/scripts/tlgs/gswin32/ps2ps.tlu b/Master/texmf-dist/scripts/tlgs/gswin32/ps2ps.tlu
index 2d414700ebb..063fc76d0cc 100755
--- a/Master/texmf-dist/scripts/tlgs/gswin32/ps2ps.tlu
+++ b/Master/texmf-dist/scripts/tlgs/gswin32/ps2ps.tlu
@@ -5,8 +5,21 @@
-- Copyright (C) 2010 Reinhard Kotucha.
-- You may freely use, modify and/or distribute this file.
--- Replacement for ps2ps.bat.
--- 'Distill' PostScript.
+-- Replacement for ps2ps2.bat.
+-- Converting PostScript 3 or PDF into PostScript 2 with the
+-- Ghostscript 'ps2write' device.
+-- This generates a PDF-style stream with an attached
+-- PostScript program to interpret it.
+
+
+local function usage (progname)
+ local message=
+ 'Usage: '..progname..' [options] <inputfile> <outputfile>\n\n'..
+ ' <inputfile> can be either a PS, EPS, PDF file, or stdin.\n'..
+ ' A single hyphen (-) denotes stdin.\n'
+ return message
+end
+
function fixwin(args_unix)
if os.type == 'windows' then
@@ -21,47 +34,97 @@ function fixwin(args_unix)
end
end
-if os.type == 'windows' then
- gs='gswin32c'
-else
- gs='gs'
-end
+local function push (t, ...)
+ local args={...}
+ for _,v in ipairs(args) do
+ if type(v) == 'table' then
+ for _,x in ipairs(v) do
+ t[#t+1]=x
+ end
+ else
+ t[#t+1]=v
+ end
+ end
+end
-files={}
-options={'-dNOPAUSE', '-dBATCH', '-dSAFER'}
-for i=1, #arg do
- if string.find(arg[i], '^%-$') then
- files[#files+1]=arg[i]
- elseif string.find(arg[i], '^%-') then
- options[#options+1]=arg[i]
+local function filename (file)
+ -- strip path
+ if string.find(file, '[/\\]') then
+ return string.match(file, '.*[/\\](.*)$')
else
- files[#files+1]=arg[i]
+ return file
end
end
-if #files ~= 2 then
- io.stderr:write('Usage: ps2ps [options] input.ps output.ps\n')
- io.stderr:write(' e.g. ps2ps -sPAPERSIZE=a4 input.ps output.ps\n')
- os.exit(1)
+local function basename (file)
+ -- strip extension
+ return string.match(filename(file), '(.*)%..*')
end
-command={gs, '-q', '-sDEVICE=pswrite'}
+local function extension (file)
+ -- return extension if available, false otherwise.
+ local fn=filename(file)
+ if fn:find('%.') then
+ return string.match(fn, '.*%.(.*)')
+ end
+end
+
+
+local function parse_cmdline ()
+ local files={}
+ local options={}
+
+ local progname
+ local basename=filename(arg[0])
+ if basename:find('%.') then
+ progname=basename:match('(.*)%..*')
+ else
+ progname=basename
+ end
-if os.type=='unix' then
- command[#command+1]='-sstdout=%stderr'
+ for i=1, #arg do
+ if string.find(arg[i], '^%-.+') then
+ push(options, arg[i])
+ else
+ push(files, arg[i])
+ end
+ end
+ files.input =files[1]
+ files.output=files[2]
+
+ return progname, options, files
end
-command[#command+1]='-sOutputFile='..files[2]
-for i=1, #options do
- command[#command+1]=options[i]
+local function check_files (progname, files)
+ if #files < 2 then
+ io.stderr:write(usage(progname))
+ os.exit(1)
+ end
end
-command[#command+1]=files[1]
+-- main --
+
+local progname, options, file=parse_cmdline()
+
+check_files (progname, file)
+
+-- setup command
+
+local command={}
+if os.type == 'unix' then command={'gs'} else command={'gswin32c'} end
+
+push(command, '-q', '-sDEVICE=ps2write')
+
+if os.type=='unix' then push(command, '-sstdout=%stderr') end
+
+push(command, '-sOutputFile='..file.output)
+push(command, '-dNOPAUSE', '-dBATCH', '-P-', '-dSAFER')
+push(command, options, file.input)
command=fixwin(command)
@@ -69,7 +132,7 @@ command=fixwin(command)
for i=0, #command do
print (command[i])
end
-os.exit(ret)
+os.exit(0)
--]]
ret=os.spawn(command)