From c62c183ae4b93d2c6b2bb7ec9f9b2f32e7771f39 Mon Sep 17 00:00:00 2001 From: Frank Halasz Date: Sat, 11 Nov 2023 11:05:24 -0800 Subject: [PATCH] Update ShellOpen to handle versioned files; add ShellOpen into SEE-PDF 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. --- library/PDFSTREAM | 52 +++++++++++++++++-------------- library/PDFSTREAM.LCOM | Bin 5191 -> 5449 bytes library/UNIXUTILS | 66 ++++++++++++++++++++++++++++------------ library/UNIXUTILS.DFASL | Bin 6443 -> 7433 bytes 4 files changed, 77 insertions(+), 41 deletions(-) diff --git a/library/PDFSTREAM b/library/PDFSTREAM index 1534669e2..9565197ac 100644 --- a/library/PDFSTREAM +++ b/library/PDFSTREAM @@ -1,12 +1,12 @@ (DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP" BASE 10) -(FILECREATED " 1-Oct-2023 20:53:05" {WMEDLEY}PDFSTREAM.;54 13917 +(FILECREATED " 9-Oct-2023 00:42:25" {DSK}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}PDFSTREAM.;53) + :PREVIOUS-DATE " 1-Oct-2023 20:53:05" {DSK}frank>il>medley>gmedley>library>PDFSTREAM.;1 +) (PRETTYCOMPRINT PDFSTREAMCOMS) @@ -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) @@ -132,7 +133,7 @@ (* ;; "Implementation of PDF streams") -(RPAQ? PDFCONVERTER 'ps2pdf) +(RPAQ? PDFCONVERTER NIL) @@ -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))) @@ -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))) @@ -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") @@ -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 diff --git a/library/PDFSTREAM.LCOM b/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z_dGsRtU&1yvE3;0Y7KXb$tY=+TKw+( zi%H;r&HualNiva`ljw)pfjDGIF8q%Rcfl|rjF7a3A9y|xN>6Qd!iNjbIze`0L&tItw@CT!EmN8`De>l9YP(z#ztH#5mUfm02 z!?kI6e5r$5jaVQ(KnwiG>=pj|^5wi!1SLNlD`2CcDNw+_d#z?|_x}1}Z@AuzI|uOx z+OTsQeO7^ci)-_S0SfB482W=l7!Tw9?(J^eQPLO)l&Me!&sf(E3oz`_w~K4Z ze*VU<3sVa1vNEta(j9`lZ*j0kr`*Tqi!fEU-}&lybW- zbDgYux)Yxg^V^dAqEVNDw&iqfVkvQCkP`5HRP#BW6?jCCqrGg~}TS3aLRi~Hf}2mb?U)_^1c diff --git a/library/UNIXUTILS b/library/UNIXUTILS index 2150c55e1..ec67d36ce 100644 --- a/library/UNIXUTILS +++ b/library/UNIXUTILS @@ -1,12 +1,11 @@ (DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP" BASE 10) -(FILECREATED " 8-Oct-2023 15:06:52" {DSK}frank>il>medley>gmedley>library>UNIXUTILS.;15 14696 +(FILECREATED "10-Nov-2023 21:59:02" {DSK}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}frank>il>medley>gmedley>library>UNIXUTILS.;14 -) + :PREVIOUS-DATE "10-Nov-2023 19:34:44" +{DSK}frank>il>medley>gmedley>docs>primer>UNIXUTILS.;10) (PRETTYCOMPRINT UNIXUTILSCOMS) @@ -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) @@ -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") @@ -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") @@ -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 /)) @@ -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 diff --git a/library/UNIXUTILS.DFASL b/library/UNIXUTILS.DFASL index 8cfdae7d1b4ad2fefc52a2506d71c8d3a74f770c..991032ba28a1646074547c04fd2f2ce840671639 100644 GIT binary patch delta 2292 zcmZuyZ){Ul6o2==c3Zc0?Q6G=KU1m^W^{kLZa^3+EA87>d3~>GI~mDvK^bi5HXKD` z1}iM^VY3mJ7xg_Q#2E|1u5Mxvd;q#PX1%(NH zK(Kf8DOU0-K3{S=dDK`oJ#c97gl5!IsYT=NzR=L=f-iQWXc^j!EGAZr> zvLu^K#S>}n2JG+FA5+trgrTePMztrA$!2&3@D<&9{-%MK1H(IX?g9x_Q_qg&I+Sq81dNU6G- z<{YzZP8(Y@=9s%WF9#@*ZMO!P#BA9z;m_?Dv8U_fLm6ffK1z_%Z^mS>LD^Jy7EP^WdKc@n`@rVF z*3qC)73n%~)nX(5-?(%Yte$^)SZ@uNK>9|6enEXm7pcNYG@Q4qP@J`!P@EEO$Ea$) zD~kO{Q+961&h4q4J*iTHsTLBGjY6vxT8+?LBwnB`#f`|QSs!HM&GsG;?0YiL zAp91q;qs$$1r!$ys2a=Wjr2C8zC?SMk)g%8ycG8#!S~T+p5O-v-ywJb;X_NX5pt9k zM-fdc$VBDEv@QTE{Z1@ql)kek>Om|#2Z2sHd_kaj#wz$a@QNND$%S@}>>u9Q7D9fD zIpML`Tjt8j5M8q7BbA%jC3C#;HKDHbe#LpryzbrD%WJJdna-;kE!AF`g$9)g3 zIt~tXsJ>zqc!UG|IIa^uE7 D`2beC delta 1230 zcmZuwS!fec6rC+;nlx&fq&3>&Ah>|7Cehd$*Vs(b(8)~6Bw9t$T2pBiBV`J%)hdG4 z!G%Y0UJT;~idy&9jjcOs#Cnl< z7dGU(M2M)NA$8Hz^4|aCLM|anDixDLH_P+MdBr=nGL9<4B`R;X?`Ie`fNEUV zy~{Q+EQ(VMpF~o=c=qO0O5ec2?zC}T8D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