]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/general-scheme.cc
(do_chroot_jail): paranoia security for webserver
[lilypond.git] / lily / general-scheme.cc
index 727bdeb73bace1270dba0f7a75a27c03a035fc66..c26dfbfa13c0af31fe090da8f5c73600f0f1dcb4 100644 (file)
@@ -3,15 +3,17 @@
 
   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 "config.hh"
 
-#include <math.h>   /* isinf */
+#include <libintl.h>  /* gettext on MacOS X */
+#include <math.h>  /* isinf */
 #include <stdio.h>
-#include <libintl.h>           // gettext on macos x
+#include <string.h>  /* memset */
+#include <wchar.h>  /* wcrtomb */
 
 #include "libc-extension.hh"
 #include "lily-guile.hh"
@@ -31,6 +33,10 @@ inline int my_isnan (Real r) { return isnan (r); }
 #endif
 
 
+/*
+  Ugh. Gulped file is copied twice. (maybe thrice if you count stdio
+  buffering.)
+ */
 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.  "
@@ -98,7 +104,6 @@ LY_DEFINE (ly_assoc_get, "ly:assoc-get",
     return default_value;
 }
 
-
 LY_DEFINE (ly_number2string, "ly:number->string",
           1, 0, 0, (SCM s),
           "Convert @var{num} to a string without generating many decimals.")
@@ -128,9 +133,7 @@ LY_DEFINE (ly_number2string, "ly:number->string",
   return scm_makfrom0str (str);
 }
 
-
-
-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 ")" ;
@@ -138,15 +141,13 @@ LY_DEFINE (ly_version,  "ly:version", 0, 0, 0, (),
   return scm_c_eval_string ((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_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.")
 {
@@ -169,12 +170,9 @@ LY_DEFINE (ly_gettext, "ly:gettext",
 {
   SCM_ASSERT_TYPE (scm_is_string (string), string, SCM_ARG1,
                   __FUNCTION__, "string");
-  return scm_makfrom0str (gettext (scm_i_string_chars (string)));
+  return scm_makfrom0str (_ (scm_i_string_chars (string)).to_str0 ());
 }
 
-
-
-
 LY_DEFINE (ly_output_backend, "ly:output-backend",
            0, 0, 0, (),
            "Return name of output backend.")
@@ -182,7 +180,6 @@ LY_DEFINE (ly_output_backend, "ly:output-backend",
   return scm_makfrom0str (output_backend_global.to_str0 ());
 }
 
-
 LY_DEFINE (ly_output_formats, "ly:output-formats",
            0, 0, 0, (),
            "Formats passed to --format as a list of strings, "
@@ -197,3 +194,22 @@ LY_DEFINE (ly_output_formats, "ly:output-formats",
 
   return lst;
 }
+
+LY_DEFINE (ly_wchar_to_utf_8, "ly:wide-char->utf-8",
+          1, 0, 0, (SCM wc),
+          "Encode the Unicode codepoint @var{wc} as UTF-8")
+{
+  char buf[100];
+
+  SCM_ASSERT_TYPE (scm_is_integer (wc), wc, SCM_ARG1, __FUNCTION__, "integer");
+  wchar_t wide_char = (wchar_t) scm_to_int (wc);
+
+  mbstate_t state;
+  memset (&state, '\0', sizeof (state));
+  memset (buf, '\0', sizeof (buf));
+
+  wcrtomb (buf, wide_char, &state);
+  
+  return scm_makfrom0str (buf);
+}
+