]> git.donarmstrong.com Git - lilypond.git/blob - lily/lily-guile.cc
release: 1.1.62
[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
12 #include <stdio.h>
13 #include <stdlib.h>
14
15 #include "libc-extension.hh"
16 #include "lily-guile.hh"
17 #include "main.hh"
18 #include "simple-file-storage.hh"
19 #include "file-path.hh"
20 #include "debug.hh"
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 void
65 read_lily_scm_file (String fn)
66 {
67   String s = global_path.find (fn);
68   if (s == "")
69     {
70       String e = _f ("Can not find file `%s\'", fn);
71       e += " ";
72       e += _f ("(Load path is `%s\'", global_path.str ());
73       error (e);
74     }
75   else
76     *mlog << '[' << s;
77
78
79   Simple_file_storage f(s);
80   
81   gh_eval_str ((char *) f.ch_C());
82   *mlog << ']' << flush;  
83 }
84
85
86 SCM
87 ly_gulp_file (SCM name)
88 {
89   String fn (ly_scm2string (name));
90  String s = global_path.find (fn);
91   if (s == "")
92     {
93       String e = _f ("Can not find file `%s\'", fn);
94       e += " ";
95       e += _f ("(Load path is `%s\'", global_path.str ());
96       error (e);
97     }
98   else
99     *mlog << '[' << s;
100
101
102   Simple_file_storage f(s);
103   return gh_str02scm (f.ch_C());
104 }
105
106 void
107 ly_display_scm (SCM s)
108 {
109   gh_display (s);
110   gh_newline ();
111 }
112
113 String
114 ly_scm2string (SCM s)
115 {
116   int len; 
117   char * p = gh_scm2newstr (s , &len);
118   
119   String r (p);
120   //  delete p;
121   free (p);
122   return r;
123 }
124
125 SCM
126 index_cell (SCM s, Direction d)
127 {
128   assert (d);
129   return (d == LEFT) ? SCM_CAR (s) : SCM_CDR (s);
130 }
131
132   
133 SCM
134 array_to_list (SCM *a , int l)
135 {
136   SCM list = SCM_EOL;
137   for (int i= l; i--;  )
138     {
139       list =  gh_cons (a[i], list);
140     }
141   return list;
142 }
143
144 SCM
145 ly_warning (SCM str)
146 {
147   assert (gh_string_p (str));
148   warning ("lily-guile: " + ly_scm2string (str));
149   return SCM_BOOL_T;
150 }
151
152 void
153 init_functions ()
154 {
155   scm_make_gsubr ("ly-warn", 1, 0, 0, ly_warning);
156   scm_make_gsubr ("ly-gulp-file", 1,0, 0, ly_gulp_file);
157 }
158
159 extern void init_symbols ();
160
161 void
162 init_lily_guile ()
163 {
164   init_symbols();
165   init_functions ();
166 }