]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lily-guile.cc
* python/convertrules.py (string_or_scheme): Fix spelling error
[lilypond.git] / lily / lily-guile.cc
index 5b80d8580b4ba4f27bd04b0c635cd4afdc6c53c2..f0f90afa65fbb698989fa382c52fd322d78e478d 100644 (file)
@@ -25,6 +25,7 @@
 #include "misc.hh"
 #include "offset.hh"
 #include "pitch.hh"
+#include "string-convert.hh"
 #include "source-file.hh"
 #include "version.hh"
 #include "warn.hh"
@@ -41,6 +42,7 @@ SCM
 ly_to_string (SCM scm)
 {
   return scm_call_3 (ly_lily_module_constant ("format"), SCM_BOOL_F,
+
                     scm_makfrom0str ("~S"), scm);
 }
 
@@ -143,7 +145,7 @@ ly_scm2newstr (SCM str, size_t *lenp)
 
       if (lenp)
        *lenp = len;
-      
+
       return new_str;
     }
   return 0;
@@ -152,7 +154,7 @@ ly_scm2newstr (SCM str, size_t *lenp)
 SCM
 index_get_cell (SCM s, Direction d)
 {
-  
+
   assert (d);
   return (d == LEFT) ? scm_car (s) : scm_cdr (s);
 }
@@ -166,7 +168,7 @@ index_set_cell (SCM s, Direction d, SCM v)
     scm_set_cdr_x (s, v);
   return s;
 }
-  
+
 bool
 is_number_pair (SCM p)
 {
@@ -267,7 +269,7 @@ ly_scm2realdrul (SCM p)
 SCM
 ly_interval2scm (Drul_array<Real> i)
 {
-  return scm_cons (scm_make_real (i[LEFT]), scm_make_real (i[RIGHT]));
+  return scm_cons (scm_from_double (i[LEFT]), scm_from_double (i[RIGHT]));
 }
 
 bool
@@ -299,7 +301,7 @@ appendable_list_append (SCM l, SCM elt)
 SCM
 ly_offset2scm (Offset o)
 {
-  return scm_cons (scm_make_real (o[X_AXIS]), scm_make_real (o[Y_AXIS]));
+  return scm_cons (scm_from_double (o[X_AXIS]), scm_from_double (o[Y_AXIS]));
 }
 
 Offset
@@ -320,15 +322,13 @@ ly_deep_copy (SCM src)
       SCM nv = scm_c_make_vector (len, SCM_UNDEFINED);
       for (int i = 0;i < len; i++)
        {
-         SCM si = scm_int2num (i);
+         SCM si = scm_from_int (i);
          scm_vector_set_x (nv, si, ly_deep_copy (scm_vector_ref (src, si)));
        }
     }
   return src;
 }
 
-
-
 /* looks the key up in the cdrs of the alist-keys
    - ignoring the car and ignoring non-pair keys.
    Returns first match found, i.e.
@@ -351,46 +351,33 @@ ly_assoc_cdr (SCM key, SCM alist)
   if (scm_is_pair (alist))
     {
       SCM trykey = scm_caar (alist);
-      if (scm_is_pair (trykey) && to_boolean (scm_equal_p (key, scm_cdr (trykey))))
+      if (scm_is_pair (trykey)
+         && to_boolean (scm_equal_p (key, scm_cdr (trykey))))
        return scm_car (alist);
-      else
-       return ly_assoc_cdr (key, scm_cdr (alist));
+      return ly_assoc_cdr (key, scm_cdr (alist));
     }
   return SCM_BOOL_F;
 }
 
-/* LST has the form "sym1 sym2 sym3\nsym4\nsym5"
-   i.e. \n and ' ' can be used interchangeably as separators.  */
 SCM
-parse_symbol_list (char const *lst)
-{
-  char *s = strdup (lst);
-  char *orig = s;
-  SCM create_list = SCM_EOL;
-
-  char *e = s + strlen (s) - 1;
-  while (e >= s && isspace (*e))
-    *e-- = 0;
-
-  for (char *p = s; *p; p++)
-    if (*p == '\n')
-      *p = ' ';
-  
-  if (!s[0])
-    s = 0;
-  
-  while (s)
-    {
-      char *next = strchr (s, ' ');
-      if (next)
-       *next++ = 0;
-
-      create_list = scm_cons (ly_symbol2scm (s), create_list);
-      s = next;
-    }
+ly_string_array_to_scm (Array<String> a)
+{
+  SCM s = SCM_EOL;
+  for (int i = a.size () - 1; i >= 0; i--)
+    s = scm_cons (ly_symbol2scm (a[i].to_str0 ()), s);
+  return s;
+}
 
-  free (orig);
-  return create_list;
+/* SYMBOLS is a whitespace separated list.  */
+SCM
+parse_symbol_list (char const *symbols)
+{
+  while (isspace (*symbols))
+    *symbols++;
+  String s = symbols;
+  s.substitute ('\n', ' ');
+  s.substitute ('\t', ' ');
+  return ly_string_array_to_scm (String_convert::split (s, ' '));
 }
 
 SCM
@@ -453,7 +440,7 @@ type_check_assignment (SCM sym, SCM val, SCM type_symbol)
 
   SCM type = scm_object_property (sym, type_symbol);
 
-  if (type != SCM_EOL && !ly_c_procedure_p (type))
+  if (type != SCM_EOL && !ly_is_procedure (type))
     {
       warning (_f ("can't find property type-check for `%s' (%s).",
                   ly_symbol2string (sym).to_str0 (),
@@ -469,7 +456,7 @@ type_check_assignment (SCM sym, SCM val, SCM type_symbol)
   else
     {
       if (val != SCM_EOL
-         && ly_c_procedure_p (type)
+         && ly_is_procedure (type)
          && scm_call_1 (type, val) == SCM_BOOL_F)
        {
          ok = false;
@@ -499,7 +486,7 @@ ly_unique (SCM list)
   for (SCM i = list; scm_is_pair (i); i = scm_cdr (i))
     {
       if (!scm_is_pair (scm_cdr (i))
-         || !ly_c_equal_p (scm_car (i), scm_cadr (i)))
+         || !ly_is_equal (scm_car (i), scm_cadr (i)))
        unique = scm_cons (scm_car (i), unique);
     }
   return scm_reverse_x (unique, SCM_EOL);
@@ -560,7 +547,7 @@ ly_split_list (SCM s, SCM list)
     {
       SCM i = scm_car (after);
       after = scm_cdr (after);
-      if (ly_c_equal_p (i, s))
+      if (ly_is_equal (i, s))
        break;
       before = scm_cons (i, before);
     }
@@ -686,7 +673,7 @@ alist_equal_p (SCM a, SCM b)
       SCM l = scm_assoc (key, b);
 
       if (l == SCM_BOOL_F
-         || !ly_c_equal_p (scm_cdr (l), val))
+         || !ly_is_equal (scm_cdr (l), val))
 
        return false;
     }
@@ -698,9 +685,7 @@ ly_alist_vals (SCM alist)
 {
   SCM x = SCM_EOL;
   for (SCM p = alist; scm_is_pair (p); p = scm_cdr (p))
-    {
-      x = scm_cons (scm_cdar (p), x);
-    }
+    x = scm_cons (scm_cdar (p), x);
   return x;
 }