diff options
author | G. Branden Robinson <g.branden.robinson@gmail.com> | 2022-02-15 19:30:50 +1100 |
---|---|---|
committer | G. Branden Robinson <g.branden.robinson@gmail.com> | 2022-02-21 22:03:21 +1100 |
commit | afc1999af86d95d0dfce22235c8bf4c02154c917 (patch) | |
tree | 407d85e5861ddf13dcf237224c96188ae4860fb6 /tmac/pdfpic.tmac | |
parent | c1da47268142b97f4683229cd5799d00be3d973e (diff) | |
download | groff-git-afc1999af86d95d0dfce22235c8bf4c02154c917.tar.gz |
[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.
Diffstat (limited to 'tmac/pdfpic.tmac')
-rw-r--r-- | tmac/pdfpic.tmac | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/tmac/pdfpic.tmac b/tmac/pdfpic.tmac index 3d0ff1d87..760b02c5c 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 |