]> git.donarmstrong.com Git - lilypond.git/blob - lily/lily-guile.cc
release: 1.1.41
[lilypond.git] / lily / lily-guile.cc
1 /*
2   lily-guile.cc -- implement assorted guile functions
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--1999 Jan Nieuwenhuizen <janneke@gnu.org>
7
8   Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 */
10
11 #include <stdio.h>
12 #include "libc-extension.hh"
13 #include "lily-guile.hh"
14 #include "main.hh"
15 #include "simple-file-storage.hh"
16 #include "file-path.hh"
17 #include "debug.hh"
18
19
20
21
22 /*
23   scm_m_quote doesn't use any env, but needs one for a good signature in GUILE.
24
25   Why there is no gh_quote () in GUILE  beats me.
26 */
27
28 SCM
29 ly_quote_scm (SCM s)
30 {
31   return scm_cons2 (scm_i_quote, s, SCM_EOL);
32 }
33
34 /*
35   See: libguile/symbols.c
36
37   SCM
38   scm_string_to_symbol(s)
39   
40 */
41 SCM
42 ly_symbol (String name)
43 {
44   return gh_car (scm_intern (name.ch_C(), name.length_i()));
45 }
46
47 String
48 symbol_to_string (SCM s)
49 {
50   return String((Byte*)SCM_CHARS (s), (int) SCM_LENGTH(s));
51 }
52
53 SCM
54 ly_set_scm (String name, SCM val)
55 {
56   return scm_sysintern (name.ch_C(), val);
57   
58 }
59 /**
60
61    Read a file, and shove it down GUILE.  GUILE also has file read
62    functions, but you can't fiddle with the path of those.
63    
64  */
65 void
66 read_lily_scm_file (String fn)
67 {
68   String s = global_path.find (fn);
69   if (s == "")
70     {
71       String e = _f ("Can not find file `%s\'", fn);
72       e += " ";
73       e += _f ("(Load path is `%s\'", global_path.str ());
74       error (e);
75     }
76   else
77     *mlog << '[' << s;
78
79
80   Simple_file_storage f(s);
81   
82   gh_eval_str ((char *) f.ch_C());
83   *mlog << ']' << flush;  
84 }
85
86
87 void
88 ly_display_scm (SCM s)
89 {
90   gh_display (s);
91   gh_newline ();
92 }
93
94 String
95 ly_scm2string (SCM s)
96 {
97   int len; 
98   char * p = gh_scm2newstr (s , &len);
99   
100   String r (p);
101   delete p;
102   return r;
103 }
104
105 SCM
106 index_cell (SCM s, Direction d)
107 {
108   assert (d);
109   return (d == LEFT) ? SCM_CAR (s) : SCM_CDR (s);
110 }
111
112   
113 SCM
114 array_to_list (SCM *a , int l)
115 {
116   SCM list = SCM_EOL;
117   for (int i= l; i--;  )
118     {
119       list =  gh_cons (a[i], list);
120     }
121   return list;
122 }
123