bug-lilypond
[Top][All Lists]
Advanced

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

Re: Ghostscript fails with special characters in filename


From: Ian Hulin
Subject: Re: Ghostscript fails with special characters in filename
Date: Fri, 21 Aug 2009 16:56:27 +0100
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

Patrick McCarty wrote:
On 2009-08-20, Reinhold Kainhofer wrote:
Am Donnerstag, 20. August 2009 11:47:52 schrieb Reinhold Kainhofer:
Am Donnerstag, 20. August 2009 11:37:55 schrieb Patrick McCarty:
On 2009-08-20, Reinhold Kainhofer wrote:
To me this seems like guile is not able to properly handle wide UTF-8
characters properly and messes up the wide characters.
I've been following the Guile mailing lists recently, and it sounds
like UTF-8 handling will be improved in the next stable release.

In the meantime, does this patch work?
Yes, using ly:format instead of simple-format works here.
Of course, the same change needs to be done to the ps->png
conversion. Patch attached.

Hmm...

I just realized why the ~S was being used instead of ~a: the ~S allows
double quotes in the filename, but ~a does not.

So this would fail with your patch:

  $ lilypond \"file\".ly

Even though it is an unlikely filename, ly:format cannot accept it
using ~a.

Now, I'm having trouble finding an equivalent to ~S to use with
ly:format; such an option does not seem to exist.  I think we're
stuck, unless someone can implement an ~S format specifier for
ly:format.

Just thinking out loud. .

   * These patches work round a guile restriction, which they're
     planning to fix.

   * The patches fix 90% of the back-end crashes for pdf and png (do we
     need another for svg, by the way?)

   * You've identified a rare case which needs a fix to some pretty
     basic code.
   * You could add something like
     (set! filename string-regexp-substitute ("[^-[:alnum:]]" "_"
     filename)) to defend against this, see attached patch - it's
     Rheinhold's patch with some extra code to defend against the case
     you pointed out, changing the file\.pdf to file_.pdf.

Even if we don't do the last bit, we could go with Rheinhold's patch and document the restriction. It certainly fixes the problem well enough for my purposes in tracker 714.

Cheers,
Ian

>From c69fad382e5b5d518c82c798531c9048768cb81e Mon Sep 17 00:00:00 2001
From: Ian Hulin <address@hidden(none)>
Date: Fri, 21 Aug 2009 16:44:23 +0100
Subject: [PATCH] Issue 832 Wrong UTF-8 encoded filenames passed to gs
 1. Change simple-format calls to use ly:format
 2. Change "~S" directives to "-a"
 3. Defend against non-alphanumeric chars and quotes in output file-name
 supplied by user.

---
 scm/backend-library.scm |   17 +++++++++--------
 scm/ps-to-png.scm       |   11 ++++++-----
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/scm/backend-library.scm b/scm/backend-library.scm
index 3a4ccab..c86490d 100644
--- a/scm/backend-library.scm
+++ b/scm/backend-library.scm
@@ -75,18 +75,19 @@
   (search-executable '("gs")))
   
 (define-public (postscript->pdf paper-width paper-height name)
-  (let* ((pdf-name (string-append
-                   (dir-basename name ".ps" ".eps")
+  (let* ((filtered-name (string-regexp-substitute "[^-[:alnum:]]" "_" name))
+        (pdf-name (string-append
+                   (dir-basename filtered-name ".ps" ".eps")
                    ".pdf"))
-        (is-eps (string-match "\\.eps$" name))
+        (is-eps (string-match "\\.eps$" filtered-name))
         (paper-size-string (if is-eps
                                "-dEPSCrop"
                                (ly:format "-dDEVICEWIDTHPOINTS=~$\
  -dDEVICEHEIGHTPOINTS=~$"
                                        paper-width paper-height)))
 
-        (cmd (simple-format #f
-                     "~a\
+        (cmd (ly:format 
+"~a\
  ~a\
  ~a\
  ~a\
@@ -95,9 +96,9 @@
  -dBATCH\
  -r1200\
  -sDEVICE=pdfwrite\
- -sOutputFile=~S\
+ -sOutputFile=~a\
  -c .setpdfwrite\
- -f ~S\
+ -f ~a\
 "
                      (search-gs)
                      (if (ly:get-option 'verbose) "" "-q")
@@ -107,7 +108,7 @@
                          "-dSAFER")
                      paper-size-string
                      pdf-name
-                     name)))
+                     filtered-name)))
     ;; The wrapper on windows cannot handle `=' signs,
     ;; gs has a workaround with #.
     (if (eq? PLATFORM 'windows)
diff --git a/scm/ps-to-png.scm b/scm/ps-to-png.scm
index cb20163..019c2de 100644
--- a/scm/ps-to-png.scm
+++ b/scm/ps-to-png.scm
@@ -108,7 +108,8 @@
                      ((string-contains format-str "jpeg") "jpeg")
                      (else
                       (ly:error "Unknown pixmap format ~a" pixmap-format))))
-         (base (dir-basename ps-name ".ps" ".eps"))
+         (ps-filename (string-regexp-substitute "[^-[:alnum:]]" "_" ps-name))
+         (base (dir-basename ps-filename ".ps" ".eps"))
          (png1 (format "~a.~a" base extension))
          (pngn (format  "~a-page%d.~a" base extension))
          (page-count (ps-page-count ps-name))
@@ -120,16 +121,16 @@
               (format #f "-dDEVICEWIDTHPOINTS=~,2f -dDEVICEHEIGHTPOINTS=~,2f"
                       page-width page-height)
               "-dEPSCrop"))
-         (cmd (format #f "~a\
+         (cmd (ly:format "~a\
  ~a\
  ~a\
  -dGraphicsAlphaBits=4\
  -dTextAlphaBits=4\
  -dNOPAUSE\
  -sDEVICE=~a\
- -sOutputFile=~S\
- -r~S\
- ~S\
+ -sOutputFile=~a\
+ -r~a\
+ ~a\
  -c quit"
                       (search-gs)
                       (if be-verbose "" "-q")
-- 
1.6.0.4


reply via email to

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