]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lily-guile.cc
*** empty log message ***
[lilypond.git] / lily / lily-guile.cc
index 6f70bae5f5406825a65fe54b115fe507ccb46e05..064ed54fabe32b27c46e99ef33e56017f0a2c3e0 100644 (file)
@@ -75,7 +75,7 @@ ly_quote_scm (SCM s)
   return scm_list_n (ly_symbol2scm ("quote"), s, SCM_UNDEFINED);
 }
 
-std::string
+string
 ly_symbol2string (SCM s)
 {
   /*
@@ -85,15 +85,15 @@ ly_symbol2string (SCM s)
   return ly_scm2string (str);
 }
 
-std::string
-gulp_file_to_string (std::string fn, bool must_exist, int size)
+string
+gulp_file_to_string (string fn, bool must_exist, int size)
 {
-  std::string s = global_path.find (fn);
+  string s = global_path.find (fn);
   if (s == "")
     {
       if (must_exist)
        {
-         std::string e = _f ("can't find file: `%s'", fn);
+         string e = _f ("can't find file: `%s'", fn);
          e += " ";
          e += _f ("(load path: `%s')", global_path.to_string ());
          error (e);
@@ -105,10 +105,8 @@ gulp_file_to_string (std::string fn, bool must_exist, int size)
   if (be_verbose_global)
     progress_indication ("[" + s);
 
-  int n = size;
-  char *str = gulp_file (s, &n);
-  std::string result (str, n);
-  delete[] str;
+  vector<char> chars = gulp_file (s, size);
+  string result (&chars[0], chars.size ());
 
   if (be_verbose_global)
     progress_indication ("]");
@@ -116,22 +114,19 @@ gulp_file_to_string (std::string fn, bool must_exist, int size)
   return result;
 }
 
-extern "C" {
-  // maybe gdb 5.0 becomes quicker if it doesn't do fancy C++ typing?
-  void
-  ly_display_scm (SCM s)
-  {
-    scm_display (s, scm_current_output_port ());
-    scm_newline (scm_current_output_port ());
-  }
-};
+void
+ly_display_scm (void *s)
+{
+  scm_display ((SCM)s, scm_current_output_port ());
+  scm_newline (scm_current_output_port ());
+}
 
-std::string
+string
 ly_scm2string (SCM str)
 {
   assert (scm_is_string (str));
-  return std::string (scm_i_string_chars (str),
-                    (int) scm_i_string_length (str));
+  return string (scm_i_string_chars (str),
+                (int) scm_i_string_length (str));
 }
 
 char *
@@ -179,12 +174,12 @@ is_number_pair (SCM p)
 }
 
 typedef void (*Void_fptr) ();
-std::vector<Void_fptr> *scm_init_funcs_;
+vector<Void_fptr> *scm_init_funcs_;
 
 void add_scm_init_func (void (*f) ())
 {
   if (!scm_init_funcs_)
-    scm_init_funcs_ = new std::vector<Void_fptr>;
+    scm_init_funcs_ = new vector<Void_fptr>;
 
   scm_init_funcs_->push_back (f);
 }
@@ -193,7 +188,7 @@ void
 ly_init_ly_module (void *)
 {
   for (vsize i = scm_init_funcs_->size (); i--;)
-    (scm_init_funcs_->elem (i)) ();
+    (scm_init_funcs_->at (i)) ();
 
   if (be_verbose_global)
     {
@@ -356,7 +351,7 @@ ly_assoc_cdr (SCM key, SCM alist)
 }
 
 SCM
-ly_string_array_to_scm (std::vector<std::string> a)
+ly_string_array_to_scm (vector<string> a)
 {
   SCM s = SCM_EOL;
   for (vsize i = a.size (); i ; i--)
@@ -370,10 +365,10 @@ parse_symbol_list (char const *symbols)
 {
   while (isspace (*symbols))
     *symbols++;
-  std::string s = symbols;
+  string s = symbols;
   replace_all (s, '\n', ' ');
   replace_all (s, '\t', ' ');
-  return ly_string_array_to_scm (String_convert::split (s, ' '));
+  return ly_string_array_to_scm (string_split (s, ' '));
 }
 
 SCM
@@ -394,10 +389,10 @@ ly_truncate_list (int k, SCM lst)
   return lst;
 }
 
-std::string
+string
 print_scm_val (SCM val)
 {
-  std::string realval = ly_scm2string (ly_write2scm (val));
+  string realval = ly_scm2string (ly_write2scm (val));
   if (realval.length () > 200)
     realval = realval.substr (0, 100)
       + "\n :\n :\n"
@@ -498,7 +493,9 @@ scm_default_compare (void const *a, void const *b)
   return pa < pb ? -1 : 1;
 }
 
-/*  Modify LST in place: qsort it.  */
+/*  Modify LST in place: qsort it.
+
+FIXME: unused, junk? */
 SCM
 ly_list_qsort_uniq_x (SCM lst)
 {
@@ -721,3 +718,23 @@ procedure_arity (SCM proc)
   SCM fixed = scm_car (arity);
   return scm_to_int (fixed);
 }
+
+string
+mangle_cxx_identifier (string cxx_id)
+{
+  if (cxx_id.substr (0, 3) == "ly_")
+    cxx_id = cxx_id.replace (0, 3, "ly:");
+  else
+    {
+      cxx_id = String_convert::to_lower (cxx_id);
+      cxx_id = "ly:" + cxx_id;
+    }
+  if (cxx_id.substr (cxx_id.length () - 2) == "_p")
+    cxx_id = cxx_id.replace (cxx_id.length () - 2, 1, "?");
+  else if (cxx_id.substr (cxx_id.length () - 2) == "_x")
+    cxx_id = cxx_id.replace (cxx_id.length () - 2, 1, "!");
+
+  cxx_id = replace_all (cxx_id, '_', '-');
+  return cxx_id;
+}
+