]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/general-scheme.cc
Prepare introduction of Waf build system
[lilypond.git] / lily / general-scheme.cc
index fd27481938d232f69edcfa5388d5a4c7e6b40597..43ff7456238ba1fd8a6b9e602f21d2bb59fb610b 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1998--2007 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1998--2009 Jan Nieuwenhuizen <janneke@gnu.org>
   Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
@@ -140,9 +140,10 @@ LY_DEFINE (ly_warning, "ly:warning",
 
 LY_DEFINE (ly_dir_p, "ly:dir?",
           1, 0, 0, (SCM s),
-          "A type predicate.  The direction@tie{}@code{s} is @code{-1},"
-          " @code{0} or@tie{}@code{1}, where @code{-1} represents"
-          " left or down and @code{1} represents right or up.")
+          "Is @var{s} a direction?  Valid directions are @code{-1},"
+          " @code{0}, or@tie{}@code{1}, where @code{-1} represents"
+          " left or down, @code{1}@tie{}represents right or up, and @code{0}"
+          " represents a neutral direction.")
 {
   if (scm_is_number (s))
     {
@@ -311,10 +312,10 @@ LY_DEFINE (ly_effective_prefix, "ly:effective-prefix",
 }
 
 LY_DEFINE (ly_chain_assoc_get, "ly:chain-assoc-get",
-          2, 1, 0, (SCM key, SCM achain, SCM dfault),
+          2, 1, 0, (SCM key, SCM achain, SCM val),
           "Return value for @var{key} from a list of alists @var{achain}."
-          "  If no entry is found, return @var{dfault} or @code{#f} if no"
-          " @var{dfault} is specified.")
+          "  If no entry is found, return @var{val} or @code{#f} if"
+          " @var{val} is not specified.")
 {
   if (scm_is_pair (achain))
     {
@@ -322,9 +323,9 @@ LY_DEFINE (ly_chain_assoc_get, "ly:chain-assoc-get",
       if (scm_is_pair (handle))
        return scm_cdr (handle);
       else
-       return ly_chain_assoc_get (key, scm_cdr (achain), dfault);
+       return ly_chain_assoc_get (key, scm_cdr (achain), val);
     }
-  return dfault == SCM_UNDEFINED ? SCM_BOOL_F : dfault;
+  return val == SCM_UNDEFINED ? SCM_BOOL_F : val;
 }
 
 
@@ -345,10 +346,11 @@ LY_DEFINE (ly_stderr_redirect, "ly:stderr-redirect",
 }
 
 static SCM
-accumulate_symbol (void *closure, SCM key, SCM val, SCM result)
+accumulate_symbol (void * /* closure */,
+                  SCM key,
+                  SCM /* val */,
+                  SCM result)
 {
-  (void) closure;
-  (void) val;
   return scm_cons (key, result);
 }
 
@@ -409,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)));
@@ -428,7 +430,20 @@ 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, "\"", "\\\"");
+          // don't replace percents, since the png backend uses %d as escape sequence
+          // replace_all (&s, "%", "\\%");
+          replace_all (&s, "$", "\\$");
+          s = "\"" + s + "\"";
+        }
+      return s;
+    }
   else if (scm_is_symbol (arg))
     return (ly_symbol2string (arg));
   else
@@ -443,7 +458,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);
 
@@ -489,6 +505,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;