]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lily-guile.cc
*** empty log message ***
[lilypond.git] / lily / lily-guile.cc
index a5cd70e2e9f92ebacd1b3642e9438d121af5b3b8..e0aeccaf3e82eabea3419836bbec7f2f5200e49b 100644 (file)
@@ -1,32 +1,21 @@
 /*
-  lily-guile.cc -- implement assorted guile functions
+  lily-guile.cc -- implement assorted SCM interface functions
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
                  Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-#include "lily-guile.hh"
 
 #include <cstdio>
 #include <cstdlib>
-#include <math.h>   /* isinf */
 #include <cstring> /* strdup, strchr */
 #include <cctype>
-
 #include <libintl.h>           // gettext on macos x
 
 #include "version.hh"
-
-/* MacOS S fix:
-   source-file.hh includes cmath which undefines isinf and isnan
-*/
-#ifdef __APPLE__
-inline int my_isinf (Real r) { return isinf (r); }
-inline int my_isnan (Real r) { return isnan (r); }
-#endif
-
+#include "lily-guile.hh"
 #include "libc-extension.hh"
 #include "main.hh"
 #include "file-path.hh"
@@ -36,6 +25,7 @@ inline int my_isnan (Real r) { return isnan (r); }
 #include "pitch.hh"
 #include "dimensions.hh"
 #include "source-file.hh"
+#include "misc.hh"
 
 // #define TEST_GC
 
@@ -48,7 +38,7 @@ ly_to_symbol (SCM scm)
 SCM
 ly_to_string (SCM scm)
 {
-  return scm_call_3 (ly_scheme_function ("format"), SCM_BOOL_F,
+  return scm_call_3 (ly_lily_module_constant ("format"), SCM_BOOL_F,
                     scm_makfrom0str ("~S"), scm);
 }
 
@@ -106,7 +96,7 @@ gulp_file_to_string (String fn, bool must_exist)
       return s;
     }
 
-  if (verbose_global_b)
+  if (be_verbose_global)
     progress_indication ("[" + s);
 
   int n;
@@ -114,21 +104,12 @@ gulp_file_to_string (String fn, bool must_exist)
   String result ((Byte*) str, n);
   delete[] str;
   
-  if (verbose_global_b)
+  if (be_verbose_global)
     progress_indication ("]");
 
   return result;
 }
 
-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.")
-{
-  SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
-  String contents = gulp_file_to_string (ly_scm2string (name), true);
-  return scm_from_locale_stringn (contents.get_str0 (), contents.length ());
-}
 
 
 extern "C" {
@@ -186,46 +167,6 @@ index_set_cell (SCM s, Direction d, SCM v)
   return s;
 }
   
-LY_DEFINE (ly_warn, "ly:warn",
-          1, 0, 1, (SCM str, SCM rest),
-          "Scheme callable function to issue the warning @code{msg}. "
-          "The message is formatted with @code{format} and @code{rest}.")
-{
-  SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "string");
-  progress_indication ("\n");
-
-  str = scm_simple_format (SCM_BOOL_F, str, rest);
-  warning ("lily-guile: " + ly_scm2string (str));
-  return SCM_UNSPECIFIED;
-}
-
-LY_DEFINE (ly_programming_error, "ly:programming-error",
-          1, 0, 1, (SCM str, SCM rest),
-          "Scheme callable function to issue the warning @code{msg}. "
-          "The message is formatted with @code{format} and @code{rest}.")
-{
-  SCM_ASSERT_TYPE (scm_is_string (str), str, SCM_ARG1, __FUNCTION__, "string");
-  progress_indication ("\n");
-
-  str = scm_simple_format (SCM_BOOL_F, str, rest);
-  programming_error (ly_scm2string (str));
-  return SCM_UNSPECIFIED;
-}
-
-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 (scm_is_number (s))
-    {
-      int i = scm_to_int (s);
-      return (i>= -1 && i <= 1)  ? SCM_BOOL_T : SCM_BOOL_F; 
-    }
-  return SCM_BOOL_F;
-}
-
 bool
 is_number_pair (SCM p)
 {
@@ -250,7 +191,7 @@ ly_init_ly_module (void *)
   for (int i = scm_init_funcs_->size () ; i--;)
     (scm_init_funcs_->elem (i)) ();
 
-  if (verbose_global_b)
+  if (be_verbose_global)
     progress_indication ("\n");
   
   scm_primitive_load_path (scm_makfrom0str ("lily.scm"));
@@ -282,23 +223,6 @@ is_direction (SCM s)
   return false;
 }
 
-LY_DEFINE (ly_assoc_get, "ly:assoc-get",
-          2, 1, 0,
-          (SCM key, SCM alist, SCM default_value),
-          "Return value if KEY in ALIST, else DEFAULT-VALUE "
-          "(or #f if not specified).")
-{
-  SCM handle = scm_assoc (key, alist);
-
-  if (default_value == SCM_UNDEFINED)
-    default_value = SCM_BOOL_F;
-  
-  if (scm_is_pair (handle))
-    return scm_cdr (handle);
-  else
-    return default_value;
-}
-
 bool
 is_axis (SCM s)
 {
@@ -374,68 +298,14 @@ ly_scm2offset (SCM s)
                 scm_to_double (scm_cdr (s)));
 }
 
-LY_DEFINE (ly_number2string, "ly:number->string",
-          1, 0, 0, (SCM s),
-          "Convert @var{num} to a string without generating many decimals.")
-{
-  SCM_ASSERT_TYPE (scm_is_number (s), s, SCM_ARG1, __FUNCTION__, "number");
-
-  char str[400];                       // ugh.
-
-  if (scm_exact_p (s) == SCM_BOOL_F)
-    {
-      Real r (scm_to_double (s));
-#ifdef __APPLE__
-      if (my_isinf (r) || my_isnan (r))
-#else
-      if (isinf (r) || isnan (r))
-#endif
-       {
-         programming_error ("Infinity or NaN encountered while converting Real number; setting to zero.");
-         r = 0.0;
-       }
-
-      sprintf (str, "%08.4f", r);
-    }
-  else
-    sprintf (str, "%d", scm_to_int (s));
-
-  return scm_makfrom0str (str);
-}
-
-
-
-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 ")" ;
-  
-  return scm_c_eval_string ((char*)vs);
-}
-
-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_dimension_p,  "ly:dimension?", 1, 0, 0, (SCM d),
-         "Return @var{d} is a number. Used to distinguish length "
-         "variables from normal numbers.")
-{
-  return scm_number_p (d);
-}
-
 SCM
 ly_deep_copy (SCM src)
 {
   if (scm_is_pair (src))
     return scm_cons (ly_deep_copy (scm_car (src)), ly_deep_copy (scm_cdr (src)));
-  else if (ly_c_vector_p (src))
+  else if (scm_is_vector (src))
     {
-      int len = SCM_VECTOR_LENGTH (src);
+      int len = scm_c_vector_length (src);
       SCM nv = scm_c_make_vector (len, SCM_UNDEFINED);
       for (int i = 0 ;i < len ; i++)
        {
@@ -611,7 +481,7 @@ type_check_assignment (SCM sym, SCM val,  SCM type_symbol)
                 + "  " + _ ("Perhaps you made a typing error?"));
 
        /* Be strict when being anal :) */
-       if (internal_type_checking_global_b)
+       if (do_internal_type_checking_global)
          abort ();
        
        warning (_ ("Doing assignment anyway."));
@@ -624,7 +494,7 @@ type_check_assignment (SCM sym, SCM val,  SCM type_symbol)
        {
          SCM errport = scm_current_error_port ();
          ok = false;
-         SCM typefunc = ly_scheme_function ("type-name");
+         SCM typefunc = ly_lily_module_constant ("type-name");
          SCM type_name = scm_call_1 (typefunc, type);
 
         
@@ -834,22 +704,21 @@ alist_to_hashq (SCM alist)
   return tab; 
 }
 
-/*
-  Debugging mem leaks:
- */
-LY_DEFINE (ly_protects, "ly:protects",
-          0, 0, 0, (),
-         "Return hash of protected objects.")
-{
-  return scm_protects;
-}
 
-LY_DEFINE (ly_gettext, "ly:gettext",
-          1, 0, 0, (SCM string),
-          "Gettext wrapper.")
+bool
+alist_equal_p (SCM a, SCM b)
 {
-  SCM_ASSERT_TYPE (scm_is_string (string), string, SCM_ARG1,
-                  __FUNCTION__, "string");
-  return scm_makfrom0str (gettext (scm_i_string_chars (string)));
-}
+  for (SCM s = a;
+       scm_is_pair (s); s = scm_cdr (s))
+    {
+      SCM key = scm_caar (s);
+      SCM val = scm_cdar (s);
+      SCM l = scm_assoc (key, b);
+
+      if (l == SCM_BOOL_F
+         || !ly_c_equal_p ( scm_cdr (l), val))
 
+       return false;
+    }
+  return true;
+}