]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lily-guile.cc
2003 -> 2004
[lilypond.git] / lily / lily-guile.cc
index 680696c938142b0f4f507c590f3949a410b5a589..4cd7a34554bb2beaa56cbd95e4c34010d31d9d2c 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1998--2002 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
 
   Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
@@ -13,7 +13,7 @@
 #include <stdlib.h>
 #include <math.h>   /* isinf */
 #include <string.h> /* strdup, strchr */
-
+#include <ctype.h>
 
 #include "lily-proto.hh"
 
@@ -70,8 +70,6 @@ ly_quote_scm (SCM s)
   return scm_list_n (ly_symbol2scm ("quote"), s, SCM_UNDEFINED);
 }
 
-
-
 String
 ly_symbol2string (SCM s)
 {
@@ -79,7 +77,6 @@ ly_symbol2string (SCM s)
   return String ((Byte*)SCM_STRING_CHARS (s), (int) SCM_STRING_LENGTH (s));
 }
 
-
 String
 gulp_file_to_string (String fn)
 {
@@ -88,13 +85,12 @@ gulp_file_to_string (String fn)
     {
       String e = _f ("can't find file: `%s'", fn);
       e += " ";
-      e += _f ("(load path: `%s')", global_path.string ());
+      e += _f ("(load path: `%s')", global_path.to_string ());
       error (e);
     }
   else if (verbose_global_b)
     progress_indication ("[" + s);
 
-
   int n;
   char * str = gulp_file (s, &n);
   String result (str);
@@ -106,12 +102,10 @@ gulp_file_to_string (String fn)
   return result;
 }
 
-LY_DEFINE(ly_gulp_file, "ly-gulp-file", 1,0, 0,
+LY_DEFINE(ly_gulp_file, "ly:gulp-file", 1,0, 0,
          (SCM name),
-         "Read the file named @var{name}, and return its contents in a string. The
-file is looked up using the lilypond search path.
-
-")
+         "Read the file named @var{name}, and return its contents in a string. The "
+" file is looked up using the lilypond search path.")
 {
   return scm_makfrom0str (gulp_file_to_string (ly_scm2string (name)).to_str0 ());
 }
@@ -155,7 +149,7 @@ index_set_cell (SCM s, Direction d, SCM v)
   return s;
 }
   
-LY_DEFINE(ly_warning,"ly-warn", 1, 0, 0,
+LY_DEFINE(ly_warning,"ly:warn", 1, 0, 0,
   (SCM str),"Scheme callable function to issue the warning @code{msg}.")
 {
   SCM_ASSERT_TYPE (gh_string_p (str), str, SCM_ARG1, __FUNCTION__, "string");
@@ -163,10 +157,9 @@ LY_DEFINE(ly_warning,"ly-warn", 1, 0, 0,
   return SCM_BOOL_T;
 }
 
-LY_DEFINE(ly_isdir,  "dir?", 1,0, 0,  (SCM s),
-         "type predicate. A direction is a -1, 0 or 1, where -1 represents left or
-down and 1 represents right or up.
-")
+LY_DEFINE(ly_dir_p,  "ly:dir?", 1,0, 0,  (SCM s),
+         "type predicate. A direction is a -1, 0 or 1, where -1 represents "
+         "left or down and 1 represents right or up. ")
 {
   if (gh_number_p (s))
     {
@@ -177,7 +170,7 @@ down and 1 represents right or up.
 }
 
 bool
-ly_number_pair_p (SCM p)
+is_number_pair (SCM p)
 {
   return gh_pair_p (p) && gh_number_p (ly_car (p)) && gh_number_p (ly_cdr (p));
 }
@@ -195,23 +188,25 @@ void add_scm_init_func (void (*f) ())
 
 
 void
-ly_init_guile ()
+ly_init_ly_module (void *)
 {
-  SCM last_mod = scm_current_module ();
-  scm_set_current_module (scm_c_resolve_module ("lily"));
-
-  scm_c_use_module ("guile");
-  
   for (int i=scm_init_funcs_->size () ; i--;)
     (scm_init_funcs_->elem (i)) ();
 
   if (verbose_global_b)
     progress_indication ("\n");
+  
+  scm_primitive_load_path (scm_makfrom0str ("lily.scm"));
+}
 
 
-  scm_primitive_load_path (scm_makfrom0str ("lily.scm"));
+SCM lily_module ;
 
-  scm_set_current_module (last_mod);
+void
+ly_init_guile ()
+{
+  lily_module = scm_c_define_module ("lily", ly_init_ly_module, 0);
+  scm_c_use_module ("lily");
 }
 
 unsigned int ly_scm_hash (SCM s)
@@ -222,7 +217,7 @@ unsigned int ly_scm_hash (SCM s)
 
 
 bool
-ly_dir_p (SCM s)
+is_direction (SCM s)
 {
   if (gh_number_p (s))
     {
@@ -234,7 +229,7 @@ ly_dir_p (SCM s)
 
 
 bool
-ly_axis_p (SCM s)
+is_axis (SCM s)
 {
   if (gh_number_p (s))
     {
@@ -258,6 +253,13 @@ ly_scm2interval (SCM p)
                    gh_scm2double (ly_cdr (p)));
 }
 
+Drul_array<Real>
+ly_scm2realdrul (SCM p)
+{
+  return  Drul_array<Real> (gh_scm2double (ly_car (p)),
+                           gh_scm2double (ly_cdr (p)));
+}
+
 SCM
 ly_interval2scm (Drul_array<Real> i)
 {
@@ -311,11 +313,10 @@ ly_scm2offset (SCM s)
 }
 
    
-LY_DEFINE(ly_number2string,  "ly-number->string", 1, 0,0,
+LY_DEFINE(ly_number2string,  "ly:number->string", 1, 0,0,
          (SCM s),
-         " converts @var{num} to a string without generating many decimals. It
-leaves a space at the end.
-")
+         " converts @var{num} to a string without generating many decimals. It "
+"leaves a space at the end.")
 {
   SCM_ASSERT_TYPE (gh_number_p (s), s, SCM_ARG1, __FUNCTION__, "number");
 
@@ -365,26 +366,27 @@ wave_sweep_goodbye (void *dummy1, void *dummy2, void *dummy3)
 
 
 #include "version.hh"
-LY_DEFINE(ly_version,  "ly-version", 0, 0, 0, (),
-         "Return the current lilypond version as a list, e.g.
-@code{(1 3 127 uu1)}. 
-")
+LY_DEFINE(ly_version,  "ly:version", 0, 0, 0, (),
+         "Return the current lilypond version as a list, e.g. @code{(1 3 127 uu1)}. ")
 {
-  char const* vs =  "\' (" MAJOR_VERSION " " MINOR_VERSION " "  PATCH_LEVEL " " MY_PATCH_LEVEL ")" ;
+  char const* vs =  "\'(" MAJOR_VERSION " " MINOR_VERSION " "  PATCH_LEVEL " " MY_PATCH_LEVEL ")" ;
   
   return gh_eval_str ((char*)vs);
 }
 
-LY_DEFINE(ly_unit,  "ly-unit", 0, 0, 0, (),
+LY_DEFINE(ly_unit,  "ly:unit", 0, 0, 0, (),
          "Return the unit used for lengths as a string.")
 {
   return scm_makfrom0str (INTERNAL_UNIT);
 }
 
-LY_DEFINE(ly_verbose,  "ly-verbose", 0, 0, 0, (),
-  "Return whether lilypond is being run in verbose mode.")
+
+
+LY_DEFINE(ly_dimension_p,  "ly:dimension?", 1, 0, 0, (SCM d),
+         "Return @var{d} is a number. Used to distinguish length "
+         "variables from normal numbers.")
 {
-  return gh_bool2scm (verbose_global_b);
+  return scm_number_p (d);
 }
 
 static void
@@ -484,6 +486,10 @@ parse_symbol_list (const char * list)
   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')
@@ -557,11 +563,22 @@ type_check_assignment (SCM sym, SCM val,  SCM type_symbol)
   if (val == SCM_EOL || val == SCM_BOOL_F)
     return ok;
 
-  
-  SCM type = SCM_EOL;
+  if (!gh_symbol_p (sym))
+#if 0
+    return false;
+#else
+  /*
+    This is used for autoBeamSettings.
 
-  if (gh_symbol_p (sym))
-    type = scm_object_property (sym, type_symbol);
+    TODO: deprecate the use of \override and \revert for
+    autoBeamSettings?
+
+    or use a symbol autoBeamSettingS?  
+   */
+  return true; 
+#endif
+  
+  SCM type = scm_object_property (sym, type_symbol);
 
   if (type != SCM_EOL && !gh_procedure_p (type))
       {
@@ -689,8 +706,6 @@ int_list_to_slice (SCM l)
 }
 
 
-
-
 /*
   Return I-th element, or last elt L. If I < 0, then we take the first
   element.
@@ -706,46 +721,67 @@ robust_list_ref(int i, SCM l)
   return gh_car(l);
 }
 
-static int module_count;
 
-SCM
-ly_make_anonymous_module ()
+
+Real
+robust_scm2double (SCM k, double x)
 {
-  String s = "*anonymous-ly-" + to_string (module_count++) +  "*";
-  SCM mod = scm_c_resolve_module (s.to_str0());
+  if (gh_number_p (k))
+    x = gh_scm2double (k);
+  return x;
+}
 
-  scm_module_define (mod, ly_symbol2scm ("symbols-defined-here"), SCM_EOL);
-  return mod;
+Interval
+robust_scm2interval (SCM k, Drul_array<Real> v)
+{
+  Interval i;
+  i[LEFT]= v[LEFT];
+  i[RIGHT]= v[RIGHT];
+  if (is_number_pair (k))
+    i = ly_scm2interval (k);
+  return i;
 }
 
-void
-ly_copy_module_variable (SCM dest, SCM src)
+Drul_array<Real>
+robust_scm2drul (SCM k, Drul_array<Real> v)
 {
-  SCM defd = ly_symbol2scm ("symbols-defined-here");
-  SCM dvar = scm_module_lookup (src, ly_symbol2scm ("symbols-defined-here"));
-  SCM lst =  scm_variable_ref (dvar);
-  for (SCM s =lst; gh_pair_p (s); s  = gh_cdr (s))
-    {
-      SCM var  = scm_module_lookup (src, gh_car (s));
-      scm_module_define (dest, gh_car (s),
-                        scm_variable_ref (var));
-    }
+  if (is_number_pair (k))
+    v = ly_scm2interval (k);
+  return v;
+}
+
+Offset
+robust_scm2offset (SCM k, Offset o)
+{
+  if (is_number_pair (k))
+    o = ly_scm2offset (k);
 
-  scm_module_define (dest, defd, lst);
+  return o;
 }
 
-SCM
-ly_module_to_alist (SCM mod)
+
+int
+robust_scm2int (SCM k, int o)
 {
-  SCM defd = ly_symbol2scm ("symbols-defined-here");
-  SCM dvar = scm_module_lookup (mod, defd);
-  SCM lst = scm_variable_ref (dvar);
+  if (scm_integer_p (k) == SCM_BOOL_T)
+    o = gh_scm2int (k);
+
+  return o;
+}
+
 
-  SCM alist =  SCM_EOL;
-  for (SCM s =lst; gh_pair_p (s); s  = gh_cdr (s))
+SCM
+alist_to_hashq (SCM alist)
+{
+  int i = scm_ilength (alist);
+  if (i < 0)
+    return scm_make_vector (gh_int2scm (0), SCM_EOL);
+         
+  SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
+  for (SCM s = alist; gh_pair_p (s); s = ly_cdr (s))
     {
-      SCM var  = scm_module_lookup (mod, gh_car (s));
-      alist= scm_cons (scm_cons (gh_car(s), scm_variable_ref (var)), alist);
+      SCM pt = ly_cdar (s);
+      scm_hashq_set_x (tab, ly_caar (s), pt);
     }
-  return alist;
+  return tab; 
 }