]> git.donarmstrong.com Git - lilypond.git/blob - lily/lily-guile.cc
patch::: 1.1.49.uu1
[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
24
25 /*
26   scm_m_quote doesn't use any env, but needs one for a good signature in GUILE.
27
28   Why there is no gh_quote () in GUILE  beats me.
29 */
30
31 SCM
32 ly_quote_scm (SCM s)
33 {
34   return scm_cons2 (scm_i_quote, s, SCM_EOL);
35 }
36
37 /*
38   See: libguile/symbols.c
39
40   SCM
41   scm_string_to_symbol(s)
42   
43 */
44 SCM
45 ly_symbol (String name)
46 {
47   return gh_car (scm_intern (name.ch_C(), name.length_i()));
48 }
49
50 String
51 symbol_to_string (SCM s)
52 {
53   return String((Byte*)SCM_CHARS (s), (int) SCM_LENGTH(s));
54 }
55
56 SCM
57 ly_set_scm (String name, SCM val)
58 {
59   return scm_sysintern (name.ch_C(), val);
60   
61 }
62 /**
63
64    Read a file, and shove it down GUILE.  GUILE also has file read
65    functions, but you can't fiddle with the path of those.
66    
67  */
68 void
69 read_lily_scm_file (String fn)
70 {
71   String s = global_path.find (fn);
72   if (s == "")
73     {
74       String e = _f ("Can not find file `%s\'", fn);
75       e += " ";
76       e += _f ("(Load path is `%s\'", global_path.str ());
77       error (e);
78     }
79   else
80     *mlog << '[' << s;
81
82
83   Simple_file_storage f(s);
84   
85   gh_eval_str ((char *) f.ch_C());
86   *mlog << ']' << flush;  
87 }
88
89
90 void
91 ly_display_scm (SCM s)
92 {
93   gh_display (s);
94   gh_newline ();
95 }
96
97 String
98 ly_scm2string (SCM s)
99 {
100   int len; 
101   char * p = gh_scm2newstr (s , &len);
102   
103   String r (p);
104   //  delete p;
105   free (p);
106   return r;
107 }
108
109 SCM
110 index_cell (SCM s, Direction d)
111 {
112   assert (d);
113   return (d == LEFT) ? SCM_CAR (s) : SCM_CDR (s);
114 }
115
116   
117 SCM
118 array_to_list (SCM *a , int l)
119 {
120   SCM list = SCM_EOL;
121   for (int i= l; i--;  )
122     {
123       list =  gh_cons (a[i], list);
124     }
125   return list;
126 }
127
128 SCM
129 ly_warning (SCM str)
130 {
131   assert (gh_string_p (str));
132   warning ("lily-guile: " + ly_scm2string (str));
133   return SCM_BOOL_T;
134 }
135
136 void
137 init_functions ()
138 {
139   scm_make_gsubr ("ly-warn", 1, 0, 0, ly_warning);
140 }
141
142
143 extern void init_symbols ();
144
145 void
146 init_lily_guile ()
147 {
148   init_symbols();
149   init_functions ();
150 }