From: Reinhold Kainhofer Date: Thu, 20 Aug 2009 09:54:20 +0000 (+0200) Subject: Use our own ~s ly:format placeholder, since guile is broken with wide chars X-Git-Tag: release/2.13.4-1~116 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=2c8b5c7dcb118ad985c425433623bbe5207472c3;p=lilypond.git Use our own ~s ly:format placeholder, since guile is broken with wide chars 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. --- diff --git a/lily/general-scheme.cc b/lily/general-scheme.cc index b74354c6bc..8d1f05e8ef 100644 --- a/lily/general-scheme.cc +++ b/lily/general-scheme.cc @@ -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; diff --git a/scm/backend-library.scm b/scm/backend-library.scm index 3a4ccab817..2f1bc6f41a 100644 --- a/scm/backend-library.scm +++ b/scm/backend-library.scm @@ -85,7 +85,7 @@ -dDEVICEHEIGHTPOINTS=~$" paper-width paper-height))) - (cmd (simple-format #f + (cmd (ly:format "~a\ ~a\ ~a\ diff --git a/scm/ps-to-png.scm b/scm/ps-to-png.scm index cb20163c01..e220d8c7ca 100644 --- a/scm/ps-to-png.scm +++ b/scm/ps-to-png.scm @@ -120,7 +120,7 @@ (format #f "-dDEVICEWIDTHPOINTS=~,2f -dDEVICEHEIGHTPOINTS=~,2f" page-width page-height) "-dEPSCrop")) - (cmd (format #f "~a\ + (cmd (ly:format "~a\ ~a\ ~a\ -dGraphicsAlphaBits=4\ @@ -128,7 +128,7 @@ -dNOPAUSE\ -sDEVICE=~a\ -sOutputFile=~S\ - -r~S\ + -r~a\ ~S\ -c quit" (search-gs)