]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lily-guile.cc
*** empty log message ***
[lilypond.git] / lily / lily-guile.cc
index 500aa5d178957055539e95eb5d684400b2f103b6..17409239b14a6e2956cfebc70cd79ef759629e17 100644 (file)
@@ -14,6 +14,8 @@
 #include <cstring> /* strdup, strchr */
 #include <cctype>
 
+using namespace std;
+
 #include "config.hh"
 
 #include "dimensions.hh"
@@ -25,6 +27,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 +44,7 @@ SCM
 ly_to_string (SCM scm)
 {
   return scm_call_3 (ly_lily_module_constant ("format"), SCM_BOOL_F,
+
                     scm_makfrom0str ("~S"), scm);
 }
 
@@ -82,7 +86,7 @@ ly_symbol2string (SCM s)
 }
 
 String
-gulp_file_to_string (String fn, bool must_exist)
+gulp_file_to_string (String fn, bool must_exist, int size)
 {
   String s = global_path.find (fn);
   if (s == "")
@@ -101,7 +105,7 @@ gulp_file_to_string (String fn, bool must_exist)
   if (be_verbose_global)
     progress_indication ("[" + s);
 
-  int n;
+  int n = size;
   char *str = gulp_file (s, &n);
   String result ((Byte *) str, n);
   delete[] str;
@@ -143,7 +147,7 @@ ly_scm2newstr (SCM str, size_t *lenp)
 
       if (lenp)
        *lenp = len;
-      
+
       return new_str;
     }
   return 0;
@@ -152,7 +156,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 +170,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 +271,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 +303,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 +324,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 +353,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
@@ -698,9 +687,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;
 }