groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 08/35: [pdfpic]: Fix Savannah #62055 for Unix systems.


From: G. Branden Robinson
Subject: [groff] 08/35: [pdfpic]: Fix Savannah #62055 for Unix systems.
Date: Mon, 21 Feb 2022 06:15:52 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit afc1999af86d95d0dfce22235c8bf4c02154c917
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Feb 15 19:30:50 2022 +1100

    [pdfpic]: Fix Savannah #62055 for Unix systems.
    
    * tmac/pdfpic.tmac: Search for temporary directories as groff(1) does,
      instead of going straight to /tmp.
    
      (pdfpic@get-temporary-directory): New function checks each of its
      arguments for validity as a temporary directory; if one is found, its
      name is left in `pdfpic*temporary-directory`.
    
      (pdfpic@cleanup): Remove strings `pdfpic*temporary-directory` and
      `pdfpic*temporary-file`.
    
      (PDFPIC): Call `pdfpic@get-temporary-directory`, using the contents of
      the environment variables $GROFF_TMPDIR and $TMPDIR, and then /tmp, in
      that order.  Store the temporary file name in string
      `pdfpic*temporary-file`.  Use this string in subsequent `sy` and `so`
      requests.
    
    Fixes <https://savannah.gnu.org/bugs/?62055> for Unix systems.
---
 ChangeLog        | 17 +++++++++++++++++
 tmac/pdfpic.tmac | 31 ++++++++++++++++++++++++++++---
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 582f1b04..628adfde 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2022-02-15  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * tmac/pdfpic.tmac: Search for temporary directories as groff(1)
+       does, instead of going straight to /tmp.
+       (pdfpic@get-temporary-directory): New function checks each of
+       its arguments for validity as a temporary directory; if one is
+       found, its name is left in `pdfpic*temporary-directory`.
+       (pdfpic@cleanup): Remove strings `pdfpic*temporary-directory`
+       and `pdfpic*temporary-file`.
+       (PDFPIC): Call `pdfpic@get-temporary-directory`, using the
+       contents of the environment variables $GROFF_TMPDIR and $TMPDIR,
+       and then /tmp, in that order.  Store the temporary file name in
+       string `pdfpic*temporary-file`.  Use this string in subsequent
+       `sy` and `so` requests.
+
+       Fixes <https://savannah.gnu.org/bugs/?62055> for Unix systems.
+
 2022-02-15  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [tests]: Add test for PDFPIC fallback to PSPIC.
diff --git a/tmac/pdfpic.tmac b/tmac/pdfpic.tmac
index 3d0ff1d8..760b02c5 100644
--- a/tmac/pdfpic.tmac
+++ b/tmac/pdfpic.tmac
@@ -15,6 +15,21 @@
 .do nr *groff_pdfpic_tmac_C \n[.cp]
 .cp 0
 .
+.\" Locate a directory to house temporary files.  Check each argument
+.\" in turn, confirming its existence, writability, and searchability.
+.\"
+.\" `pdfpic*temporary-directory` contains its name if one is found, and
+.\" is empty otherwise.
+.de pdfpic@get-temporary-directory
+.  ds pdfpic*temporary-directory \" empty
+.  while !'\\$1'' \{\
+.    sy test -d \\$1 && test -w \\$1 && test -x \\$1
+.    if \\n[systat]=0 .ds pdfpic*temporary-directory \\$1
+.    ie '\\*[pdfpic*temporary-directory]'' .shift
+.    el                                    .break
+.  \}
+..
+.
 .\" A user may wish to append an 'ab' to this macro using 'am'.  That
 .\" is why we don't 'return X' from here to return from two scopes.
 .de pdfpic@error
@@ -25,6 +40,8 @@
 .  rm pdfpic*pspic-args
 .  rm pdfpic*file-extension
 .  rm pdfpic*file-name-base
+.  rm pdfpic*temporary-directory
+.  rm pdfpic*temporary-file
 .  rr pdfpic*do-conversion
 .  rr pdfpic*offset-mode
 .  rr pdfpic*indentation
@@ -118,6 +135,14 @@
 .    return
 .  \}
 .
+.  pdfpic@get-temporary-directory \\V[GROFF_TMPDIR] \\V[TMPDIR] /tmp
+.  if 'pdfpic*temporary-directory'' \{\
+.    pdfpic@error cannot locate a usable temporary directory; \
+skipping '\\$1'
+.    return
+.  \}
+.  ds pdfpic*temporary-file \\*[pdfpic*temporary-directory]/pdfpic\n[$$]
+.
 .  \" Get image dimensions.  The `tr` command to strip null bytes is
 .  \" distasteful, but its necessity is imposed on us.  See
 .  \" <https://gitlab.freedesktop.org/poppler/poppler/-/issues/776>.
@@ -128,15 +153,15 @@ grep "Page *size" | \
 sed -e 's/Page *size: *\\([[:digit:].]*\\) *x *\\([[:digit:].]*\\).*$/\
 .nr pdfpic*width (p;\\1)\\n\
 .nr pdfpic*height  (p;\\2)/' \
-> /tmp/pdfpic\n[$$]
+> @*[pdfpic*temporary-file]
 .  ec
 .  if \\n[systat] \{\
 .    pdfpic@error retrieval of '\\$1' image dimensions failed with \
 exit status \\n[systat]; skipping
 .    return
 .  \}
-.  so /tmp/pdfpic\\n[$$]
-.  sy rm /tmp/pdfpic\\n[$$]
+.  so \\*[pdfpic*temporary-file]
+.  sy rm \\*[pdfpic*temporary-file]
 .
 .  nr pdfpic*did-pdfinfo-work 1
 .  if !r pdfpic*width .nr pdfpic*did-pdfinfo-work 0



reply via email to

[Prev in Thread] Current Thread [Next in Thread]