]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lily-guile.cc
* scm/lily.scm (tex-output-expression): new function, eval within
[lilypond.git] / lily / lily-guile.cc
index a91937a2ff152f4664cf7c84755dec99315780ec..954ef38c5813249ee28736869e29530e55063ea7 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1998--2003 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"
 
@@ -22,8 +22,8 @@
 
  source-file.hh includes cmath which undefines isinf and isnan
 */
-inline int my_isinf(Real r) { return isinf(r); }
-inline int my_isnan(Real r) { return isnan(r); }
+inline int my_isinf (Real r) { return isinf (r); }
+inline int my_isnan (Real r) { return isnan (r); }
 
 
 
@@ -102,10 +102,10 @@ gulp_file_to_string (String fn)
   return result;
 }
 
-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.")
+LY_DEFINE (ly_gulp_file, "ly:gulp-file",
+          1, 0, 0, (SCM name),
+         "Read the file @var{name}, and return its contents in a string.  "
+          "The file is looked up using the search path.")
 {
   return scm_makfrom0str (gulp_file_to_string (ly_scm2string (name)).to_str0 ());
 }
@@ -126,7 +126,7 @@ ly_scm2string (SCM s)
 {
   assert (gh_string_p (s));
 
-  char *p = SCM_STRING_CHARS(s);
+  char *p = SCM_STRING_CHARS (s);
   String r (p);
   return r;
 }
@@ -149,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");
@@ -157,9 +157,10 @@ LY_DEFINE(ly_warning,"ly:warn", 1, 0, 0,
   return SCM_BOOL_T;
 }
 
-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. ")
+LY_DEFINE (ly_dir_p,  "ly:dir?", 1,0, 0,  (SCM s),
+         "type predicate. A direction is @code{-1}, @code{0} or "
+          "@code{1}, where @code{-1} represents "
+         "left or down and @code{1} represents right or up.")
 {
   if (gh_number_p (s))
     {
@@ -200,12 +201,12 @@ ly_init_ly_module (void *)
 }
 
 
-SCM lily_module ;
+SCM global_lily_module;
 
 void
 ly_init_guile ()
 {
-  lily_module = scm_c_define_module ("lily", ly_init_ly_module, 0);
+  global_lily_module = scm_c_define_module ("lily", ly_init_ly_module, 0);
   scm_c_use_module ("lily");
 }
 
@@ -253,6 +254,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)
 {
@@ -306,7 +314,7 @@ 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.")
@@ -359,7 +367,7 @@ wave_sweep_goodbye (void *dummy1, void *dummy2, void *dummy3)
 
 
 #include "version.hh"
-LY_DEFINE(ly_version,  "ly:version", 0, 0, 0, (),
+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 ")" ;
@@ -367,7 +375,7 @@ LY_DEFINE(ly_version,  "ly:version", 0, 0, 0, (),
   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);
@@ -375,7 +383,7 @@ LY_DEFINE(ly_unit,  "ly:unit", 0, 0, 0, (),
 
 
 
-LY_DEFINE(ly_dimension_p,  "ly:dimension?", 1, 0, 0, (SCM d),
+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.")
 {
@@ -457,9 +465,9 @@ SCM
 ly_assoc_cdr (SCM key, SCM alist)
 {
   if (gh_pair_p (alist)) {
-    SCM trykey = ly_caar(alist);
-    if(gh_pair_p(trykey) && to_boolean(scm_equal_p(key,ly_cdr(trykey))))
-      return ly_car(alist);
+    SCM trykey = ly_caar (alist);
+    if (gh_pair_p (trykey) && to_boolean (scm_equal_p (key,ly_cdr (trykey))))
+      return ly_car (alist);
     else
       return ly_assoc_cdr (key, ly_cdr (alist));
   }
@@ -672,12 +680,12 @@ taint (SCM *)
 SCM
 display_list (SCM s)
 {
-  SCM p = scm_current_output_port();
+  SCM p = scm_current_output_port ();
 
   scm_puts ("(", p);
-  for (; gh_pair_p(s); s =gh_cdr(s))
+  for (; gh_pair_p (s); s =gh_cdr (s))
     {
-      scm_display (gh_car(s), p);
+      scm_display (gh_car (s), p);
       scm_puts (" ", p);      
     }
   scm_puts (")", p);
@@ -699,8 +707,6 @@ int_list_to_slice (SCM l)
 }
 
 
-
-
 /*
   Return I-th element, or last elt L. If I < 0, then we take the first
   element.
@@ -708,11 +714,86 @@ int_list_to_slice (SCM l)
   PRE: length (L) > 0
  */
 SCM
-robust_list_ref(int i, SCM l)
+robust_list_ref (int i, SCM l)
 {
-  while (i-- > 0 && gh_pair_p (gh_cdr(l)))
+  while (i-- > 0 && gh_pair_p (gh_cdr (l)))
     l = gh_cdr (l);
 
-  return gh_car(l);
+  return gh_car (l);
+}
+
+
+
+Real
+robust_scm2double (SCM k, double x)
+{
+  if (gh_number_p (k))
+    x = gh_scm2double (k);
+  return x;
+}
+
+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;
 }
 
+Drul_array<Real>
+robust_scm2drul (SCM k, Drul_array<Real> v)
+{
+  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);
+
+  return o;
+}
+
+
+int
+robust_scm2int (SCM k, int o)
+{
+  if (scm_integer_p (k) == SCM_BOOL_T)
+    o = gh_scm2int (k);
+
+  return o;
+}
+
+
+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 pt = ly_cdar (s);
+      scm_hashq_set_x (tab, ly_caar (s), pt);
+    }
+  return tab; 
+}
+
+#if 1
+/*
+  Debugging mem leaks:
+ */
+LY_DEFINE (ly_protects, "ly:protects", 0, 0, 0, (),
+         "Return hash of protected objects.")
+{
+  return scm_protects;
+}
+#endif