]> git.donarmstrong.com Git - lilypond.git/blob - lily/lily-guile.cc
release: 1.1.5
[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 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
18 SCM
19 ly_append (SCM a, SCM b)
20 {
21   return gh_call2 (gh_eval_str ("append"), a, b);
22 }
23
24 SCM
25 ly_list1 (SCM a)
26 {
27   return gh_list (a, SCM_UNDEFINED);
28 }
29
30 SCM
31 ly_quote ()
32 {
33   return gh_eval_str ("'quote");
34 }
35
36 SCM
37 ly_quote_scm (SCM s)
38 {
39   return gh_list (ly_quote (), s, SCM_UNDEFINED);
40 }
41
42 SCM
43 ly_eval (SCM a)
44 {
45   return gh_call1 (gh_eval_str ("eval"), a);
46 }
47
48 SCM
49 ly_lambda_o ()
50 {
51   return gh_eval_str ("'(lambda (o))");
52 }
53
54 SCM
55 ly_func_o (char const* name)
56 {
57   char buf[200];                // ugh.
58   snprintf (buf, 200, "'(%s o)", name);
59   return gh_eval_str (buf);
60 }
61
62
63 SCM
64 lambda_scm (String str, Array<int> args_arr)
65 {
66   if (str.empty_b ())
67     {
68       str = "empty";
69       args_arr.clear ();
70     }
71   SCM args_scm = SCM_EOL;
72   for (int i = args_arr.size () - 1; i >= 0; i--)
73     args_scm = gh_cons (gh_int2scm (args_arr[i]), args_scm);
74   SCM scm =
75     ly_append (ly_lambda_o (), 
76     ly_list1 (ly_append (ly_func_o (str.ch_l ()), args_scm)));
77   return scm;
78 }
79
80 SCM
81 lambda_scm (String str, Array<Scalar> args_arr)
82 {
83   if (str.empty_b ())
84     {
85       str = "empty";
86       args_arr.clear ();
87     }
88   SCM args_scm = SCM_EOL;
89   for (int i = args_arr.size () - 1; i >= 0; i--)
90     args_scm = gh_cons (gh_str02scm (args_arr[i].ch_l ()), args_scm);
91   SCM scm =
92     ly_append (ly_lambda_o (), 
93     ly_list1 (ly_append (ly_func_o (str.ch_l ()), args_scm)));
94   return scm;
95 }
96
97 SCM
98 lambda_scm (String str, Array<Real> args_arr)
99 {
100   if (str.empty_b ())
101     {
102       str = "empty";
103       args_arr.clear ();
104     }
105   SCM args_scm = SCM_EOL;
106   for (int i = args_arr.size (); i--; )
107     args_scm = gh_cons (gh_double2scm (args_arr[i]), args_scm);
108   
109   SCM scm =
110     ly_append (ly_lambda_o (), 
111     ly_list1 (ly_append (ly_func_o (str.ch_l ()), args_scm)));
112   return scm;
113 }
114
115
116
117 void
118 read_lily_scm_file (String fn)
119 {
120   String s = global_path.find (fn);
121   Simple_file_storage f(s);
122   
123   gh_eval_str (f.ch_C());
124 }