Skip to content

Commit

Permalink
Update ShellOpen to handle versioned files; add ShellOpen into SEE-PD…
Browse files Browse the repository at this point in the history
…F in place of MacOS-specific open. (#1410)

* Update PDFSTREAM: integrate ShellOpen into PDF-SEE in place of MacOS specific calls; update how PDFCONVERTER is set to fix bug whereby it was always ps2pdf

* Fix ShellOpen so that if a file to open is versioned then that file is copied to tmp and its filename is changed from foo.pdf;25 to foo~25~.pdf and this tmp is passed to the opener instead of the original file.  This is so that the extension is preserved as the last thing when there are versions.  The extension as the last thing is used by most openers to determine the file type.

* Oops. Checked in the wriong versions of UNIXUTILS(.DFASL) last commit.  Correcting that here.
  • Loading branch information
fghalasz authored Nov 11, 2023
1 parent 328d3f5 commit c62c183
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 41 deletions.
52 changes: 30 additions & 22 deletions library/PDFSTREAM
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
(DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP" BASE 10)

(FILECREATED " 1-Oct-2023 20:53:05" {WMEDLEY}<library>PDFSTREAM.;54 13917
(FILECREATED " 9-Oct-2023 00:42:25" {DSK}<home>frank>il>medley>gmedley>library>PDFSTREAM.;2 14029

:EDIT-BY rmk
:CHANGES-TO (FNS SEE-PDF OPEN-PDF-STREAM PS-TO-PDF PDFCONVERTER)
(VARS PDFSTREAMCOMS)

:CHANGES-TO (FNS SEE-PDF)

:PREVIOUS-DATE " 1-Oct-2023 15:29:33" {WMEDLEY}<library>PDFSTREAM.;53)
:PREVIOUS-DATE " 1-Oct-2023 20:53:05" {DSK}<home>frank>il>medley>gmedley>library>PDFSTREAM.;1
)


(PRETTYCOMPRINT PDFSTREAMCOMS)
Expand Down Expand Up @@ -39,12 +39,13 @@

(* ;; "Implementation of PDF streams")

(INITVARS (PDFCONVERTER 'ps2pdf))
(INITVARS (PDFCONVERTER NIL))
(* ; "Mac with ghostscript?")
(ALISTS (PDF-CONVERTER-TEMPLATES ps2pdf pstopdf))
(GLOBALVARS PDFCONVERTER PDF-CONVERTER-TEMPLATES)
(FNS OPEN-PDF-STREAM CLOSE-PDF-STREAM PS-TO-PDF)
(FNS SEE-PDF)))
(FNS SEE-PDF)
(FNS PDFCONVERTER)))

(FILESLOAD (SYSLOAD)
POSTSCRIPTSTREAM)
Expand Down Expand Up @@ -132,7 +133,7 @@
(* ;; "Implementation of PDF streams")


(RPAQ? PDFCONVERTER 'ps2pdf)
(RPAQ? PDFCONVERTER NIL)



Expand Down Expand Up @@ -166,9 +167,9 @@
(* ;; "If FILE is on the LPT device, we could just ssume that it can be printed directly, no point in converting. But then we would alo have to lie and give it a PDF extension so it thinks that we are heading to a PDF printer.")

(OPENPOSTSCRIPTSTREAM FILE OPTIONS)
else (CL:UNLESS (OR (ASSOC (OR PDFCONVERTER (MKATOM (UNIX-GETENV "MEDLEY-PDFCONVERTER")))
PDF-CONVERTER-TEMPLATES))
(ERROR "POSTSCRIPT-to-PDF converter is not specified"))
else (CL:UNLESS (ASSOC (PDFCONVERTER)
PDF-CONVERTER-TEMPLATES)
(ERROR "A specified POSTSCRIPT-to-PDF converter cannot be found"))
(SETQ FILE (OR (AND (NEQ FILE T)
(OUTFILEP FILE))
(ERROR "PDF target file not found" FILE)))
Expand Down Expand Up @@ -216,6 +217,9 @@
(SETQ PSFILE (FULLNAME (TRUEFILENAME PSFILE)))
(CL:UNLESS (INFILEP PSFILE)
(ERROR "NO PS FILE TO CONVERT"))
(CL:UNLESS (ASSOC (PDFCONVERTER)
PDF-CONVERTER-TEMPLATES)
(ERROR "A specified POSTSCRIPT-to-PDF converter cannot be found"))
(SETQ PDFFILE (if PDFFILE
then (TRUEFILENAME PDFFILE)
else (PACKFILENAME 'EXTENSION 'pdf 'BODY PSFILE)))
Expand All @@ -237,10 +241,7 @@
(ERRORFILE \, (SLASHIT (TRUEFILENAME
ERRORFILE)
NIL T)))
(ASSOC (OR PDFCONVERTER
(MKATOM (UNIX-GETENV
"MEDLEY-PDFCONVERTER"
)))
(ASSOC (PDFCONVERTER)
PDF-CONVERTER-TEMPLATES]

(* ;; "Now use Medley names")
Expand All @@ -263,14 +264,21 @@
[LAMBDA (PDFFILE) (* ; "Edited 1-Oct-2023 20:47 by rmk")
(* ; "Edited 26-Sep-2023 16:52 by rmk")

(* ;; "Good for Mac, not sure about Windows etc.")
(* ;; "Use the ShellOpener for this machine to open the PDF file outside of Medley")

(ShellOpen (PACKFILENAME 'BODY PDFFILE 'EXTENSION 'PDF])
)
(DEFINEQ

(ShellCommand (CONCAT "open -a Preview " (UNIX-FILE-NAME (PACKFILENAME 'BODY PDFFILE 'EXTENSION
'PDF)
'INPUT])
(PDFCONVERTER
[LAMBDA NIL
(SETQ PDFCONVERTER (OR PDFCONVERTER (MKATOM (UNIX-GETENV "MEDLEY-PDFCONVERTER"))
(CAR (for TEMPLATE in PDF-CONVERTER-TEMPLATES
thereis (ShellWhich (CAR TEMPLATE])
)
(DECLARE%: DONTCOPY
(FILEMAP (NIL (3078 5692 (PDFFILEP 3088 . 4002) (PDF.HARDCOPYW 4004 . 4602) (PDF.TEXT 4604 . 5321) (
PDF.TEDIT 5323 . 5690)) (6136 13355 (OPEN-PDF-STREAM 6146 . 8324) (CLOSE-PDF-STREAM 8326 . 9613) (
PS-TO-PDF 9615 . 13353)) (13356 13894 (SEE-PDF 13366 . 13892)))))
(FILEMAP (NIL (3208 5822 (PDFFILEP 3218 . 4132) (PDF.HARDCOPYW 4134 . 4732) (PDF.TEXT 4734 . 5451) (
PDF.TEDIT 5453 . 5820)) (6262 13322 (OPEN-PDF-STREAM 6272 . 8408) (CLOSE-PDF-STREAM 8410 . 9697) (
PS-TO-PDF 9699 . 13320)) (13323 13721 (SEE-PDF 13333 . 13719)) (13722 14006 (PDFCONVERTER 13732 .
14004)))))
STOP
Binary file modified library/PDFSTREAM.LCOM
Binary file not shown.
66 changes: 47 additions & 19 deletions library/UNIXUTILS
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
(DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP" BASE 10)

(FILECREATED " 8-Oct-2023 15:06:52" {DSK}<home>frank>il>medley>gmedley>library>UNIXUTILS.;15 14696
(FILECREATED "10-Nov-2023 21:59:02" {DSK}<home>frank>il>medley>gmedley>library>UNIXUTILS.;24 16469

:CHANGES-TO (FNS ShellOpen UNIX-FILE-NAME ShellBrowser ShellBrowse ShellOpener)
(VARS UNIXUTILSCOMS)
:CHANGES-TO (FNS ShellOpen SLASHIT)

:PREVIOUS-DATE " 8-Oct-2023 02:35:47" {DSK}<home>frank>il>medley>gmedley>library>UNIXUTILS.;14
)
:PREVIOUS-DATE "10-Nov-2023 19:34:44"
{DSK}<home>frank>il>medley>gmedley>docs>primer>UNIXUTILS.;10)


(PRETTYCOMPRINT UNIXUTILSCOMS)
Expand Down Expand Up @@ -155,6 +154,7 @@

(* ;; " Returns T is all goes well; returns an error string if all does not go well")

(RANDSET T)
(SETQ FilenameOrURL (MKSTRING FilenameOrURL))
(if (OR (EQ (STRPOS "http://" (L-CASE FilenameOrURL))
1)
Expand All @@ -172,13 +172,42 @@
T)
else (CONCAT "Unable to find a browser to open: " FilenameOrURL)))
else
(LET ((OPENER (ShellOpener))
(UNIXFILE (UNIX-FILE-NAME FilenameOrURL 'INPUT T)))
(if (NOT UNIXFILE)
then (CONCAT "File not found: " FilenameOrURL)
elseif (NOT (STREQUAL OPENER "true"))
then (CL:WITH-OPEN-STREAM
(SHELLSTREAM (OPENSTREAM (CONCAT "{CORE}SHELLOUT" (RAND))
(LET*
((OPENER (ShellOpener))
(FULLNAME (FULLNAME FilenameOrURL)))
(if (NOT FULLNAME)
then (CONCAT "File not found: " FilenameOrURL)
elseif (STREQUAL OPENER "true")
then (CONCAT "Unable to find a file opener to open: " FilenameOrURL)
else (LET* ((VERSION.SPECIFIED (FILENAMEFIELD FilenameOrURL 'VERSION))
(UNPACKED (UNPACKFILENAME.STRING FULLNAME))
(NEWNAME (CONCAT (LISTGET UNPACKED 'NAME)
"~"
(LISTGET UNPACKED 'VERSION)
"~"))
(EXTENSION (LISTGET UNPACKED 'EXTENSION))
[UNVERSIONED (LET (FN (UNPACKED (COPY UNPACKED)))
(LISTPUT UNPACKED 'VERSION NIL)
(LISTPUT UNPACKED 'HOST NIL)
(SETQ FN (PACKFILENAME.STRING UNPACKED))
(if (STREQUAL (SUBSTRING FN -1)
".")
then (SETQ FN (SUBSTRING UNIXFILE 1 -2)))
(SETQ FN (SLASHIT FN]
(UNVERSIONED.EXISTS (INFILEP (CONCAT "{UNIX}" UNVERSIONED)))
(TMPDIR (CONCAT "/tmp/" (RAND 1000 9999)))
(TARGETFILE.LISP (PACKFILENAME.STRING 'HOST "{UNIX}" 'DIRECTORY TMPDIR
'NAME NEWNAME 'EXTENSION EXTENSION))
(TARGETFILE.UNIX (SLASHIT (PACKFILENAME.STRING 'HOST NIL 'DIRECTORY TMPDIR
'NAME NEWNAME 'EXTENSION EXTENSION)))
(UNIXFILE NIL))
(DECLARE (SPECVARS UNIXFILE))
(if (OR VERSION.SPECIFIED (NOT UNVERSIONED.EXISTS))
then (COPYFILE FULLNAME TARGETFILE.LISP)
(SETQ UNIXFILE TARGETFILE.UNIX)
else (SETQ UNIXFILE UNVERSIONED))
(CL:WITH-OPEN-STREAM
(SHELLSTREAM (OPENSTREAM (CONCAT "{CORE}SHELLOUT" (RAND 1000 9999))
'BOTH))
(ShellCommand (CONCAT OPENER " '" UNIXFILE "'"
" >>/tmp/ShellOpener-warnings-$$.txt")
Expand All @@ -197,8 +226,7 @@
(CL:LOOP (PRINTCCODE (READCCODE SHELLSTREAM)
STRINGSTREAM))
OUT))
OUTSTRING)))
else (CONCAT "Unable to find a file opener to open: " FilenameOrURL])
OUTSTRING])

(PROCESS-COMMAND
[LAMBDA (CMD) (* ; "Edited 17-Jul-2022 08:17 by rmk")
Expand All @@ -221,8 +249,8 @@

(LET [LASTDIRPOS SLASHED (DIRPOS (ADD1 (OR (STRPOS "}" X)
0]
[SETQ SLASHED (CONCATCODES (FOR I C FROM DIRPOS WHILE (SETQ C (NTHCHARCODE X I))
COLLECT (SELCHARQ C
[SETQ SLASHED (CONCATCODES (for I C from DIRPOS while (SETQ C (NTHCHARCODE X I))
collect (SELCHARQ C
((< >)
(SETQ LASTDIRPOS I)
(CHARCODE /))
Expand Down Expand Up @@ -285,7 +313,7 @@

(PUTPROPS UNIXUTILS FILETYPE CL:COMPILE-FILE)
(DECLARE%: DONTCOPY
(FILEMAP (NIL (1144 1517 (ShellCommand 1144 . 1517)) (1519 1916 (ShellWhich 1519 . 1916)) (1917 14618
(ShellBrowser 1927 . 3675) (ShellBrowse 3677 . 4362) (ShellOpener 4364 . 6052) (ShellOpen 6054 . 9357)
(PROCESS-COMMAND 9359 . 9972) (SLASHIT 9974 . 12016) (UNIX-FILE-NAME 12018 . 14616)))))
(FILEMAP (NIL (1065 1438 (ShellCommand 1065 . 1438)) (1440 1837 (ShellWhich 1440 . 1837)) (1838 16391
(ShellBrowser 1848 . 3596) (ShellBrowse 3598 . 4283) (ShellOpener 4285 . 5973) (ShellOpen 5975 . 11130
) (PROCESS-COMMAND 11132 . 11745) (SLASHIT 11747 . 13789) (UNIX-FILE-NAME 13791 . 16389)))))
STOP
Binary file modified library/UNIXUTILS.DFASL
Binary file not shown.

0 comments on commit c62c183

Please sign in to comment.