]> git.donarmstrong.com Git - lilypond.git/commitdiff
Use our own ~s ly:format placeholder, since guile is broken with wide chars
authorReinhold Kainhofer <reinhold@kainhofer.com>
Thu, 20 Aug 2009 09:54:20 +0000 (11:54 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Sat, 29 Aug 2009 19:44:59 +0000 (21:44 +0200)
We need our own ~S format placeholder to escape quotes, so use
lilypond's string formating to make wide utf-8 chars work in filenames

Guile seems unable to handle wide characters, so we mustn't use
simple-format or format, because that will break with non-ANSI characters
(char code > 255). Instead, Implement our own ~S placeholder, that
wraps the string in double quotes and escapes backslashes, double
quotes, percent and dollar signs.

Use this format placeholder to generate the proper cmd line args
for our calls to gs.

lily/general-scheme.cc
scm/backend-library.scm
scm/ps-to-png.scm

index b74354c6bc788adc96545aee8c8c11506ca85ae8..8d1f05e8efa7f958220d81c09e4c117709b82cca 100644 (file)
@@ -411,7 +411,7 @@ LY_DEFINE (ly_truncate_list_x, "ly:truncate-list!",
 }
 
 string
-format_single_argument (SCM arg, int precision)
+format_single_argument (SCM arg, int precision, bool escape = false)
 {
   if (scm_is_integer (arg) && scm_exact_p (arg) == SCM_BOOL_T)
     return (String_convert::int_string (scm_to_int (arg)));
@@ -430,7 +430,19 @@ format_single_argument (SCM arg, int precision)
        return (String_convert::form_string ("%.*lf", precision, val));
     }
   else if (scm_is_string (arg))
-    return (ly_scm2string (arg));
+    {
+      string s = ly_scm2string (arg);
+      if (escape)
+        {
+          // Escape backslashes and double quotes, wrap it in double quotes
+          replace_all (&s, "\\", "\\\\");
+          replace_all (&s, "\"", "\\\"");
+          replace_all (&s, "%", "\\%");
+          replace_all (&s, "$", "\\$");
+          s = "\"" + s + "\"";
+        }
+      return s;
+    }
   else if (scm_is_symbol (arg))
     return (ly_symbol2string (arg));
   else
@@ -445,7 +457,8 @@ format_single_argument (SCM arg, int precision)
 
 LY_DEFINE (ly_format, "ly:format",
           1, 0, 1, (SCM str, SCM rest),
-          "LilyPond specific format, supporting @code{~a} and @code{~[0-9]f}.")
+          "LilyPond specific format, supporting @code{~a} and @code{~[0-9]f}. "
+          "Basic support for @code{~s} is also provided.")
 {
   LY_ASSERT_TYPE (scm_is_string, str, 1);
 
@@ -491,6 +504,8 @@ LY_DEFINE (ly_format, "ly:format",
                   
          if (spec == 'a' || spec == 'A' || spec == 'f' || spec == '$')
            results.push_back (format_single_argument (arg, precision));
+         else if (spec == 's' || spec == 'S')
+           results.push_back (format_single_argument (arg, precision, true));
          else if (spec == 'l')
            {
              SCM s = arg;
index 3a4ccab817871d821b3e6641e1b0e4d044191e2f..2f1bc6f41acffa7ac6c317c9b727e9a6b3ce9196 100644 (file)
@@ -85,7 +85,7 @@
  -dDEVICEHEIGHTPOINTS=~$"
                                        paper-width paper-height)))
 
-        (cmd (simple-format #f
+        (cmd (ly:format
                      "~a\
  ~a\
  ~a\
index cb20163c01e2062f495a7b95fa076e8975c74f5b..e220d8c7ca899021f4d913464b55147ec81c6372 100644 (file)
               (format #f "-dDEVICEWIDTHPOINTS=~,2f -dDEVICEHEIGHTPOINTS=~,2f"
                       page-width page-height)
               "-dEPSCrop"))
-         (cmd (format #f "~a\
+         (cmd (ly:format "~a\
  ~a\
  ~a\
  -dGraphicsAlphaBits=4\
  -dNOPAUSE\
  -sDEVICE=~a\
  -sOutputFile=~S\
- -r~S\
+ -r~a\
  ~S\
  -c quit"
                       (search-gs)