]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/lily-guile.hh
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / include / lily-guile.hh
1 /*
2   lily-guile.hh encapsulate guile
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #ifndef LILY_GUILE_HH
10 #define LILY_GUILE_HH
11
12 #if __MINGW32__
13 #include "mingw-compatibility.hh"
14 #endif
15
16 #include <libguile.h>
17
18
19 /*
20   Hack for various MacOS incarnations.
21  */
22 #ifndef GUILE_ELLIPSIS
23 #define GUILE_ELLIPSIS 
24 #endif
25
26 #include "guile-compatibility.hh"
27 #include "interval.hh"
28 #include "lily-guile-macros.hh"
29 #include "ly-module.hh"
30
31 /** Conversion functions follow the GUILE naming convention, i.e.
32     A ly_B2A (B b);  */
33
34 SCM ly_last (SCM list);
35 SCM ly_write2scm (SCM s);
36 SCM ly_deep_copy (SCM);
37 SCM ly_truncate_list (int k, SCM lst);
38
39 SCM ly_to_string (SCM scm);
40 SCM ly_to_symbol (SCM scm);
41
42 extern SCM global_lily_module;
43
44 string gulp_file_to_string (string fn, bool must_exist, int size);
45
46 string ly_scm2string (SCM s);
47 string ly_symbol2string (SCM);
48 SCM ly_offset2scm (Offset);
49 Offset ly_scm2offset (SCM);
50 SCM ly_chain_assoc (SCM key, SCM achain);
51 SCM ly_chain_assoc_get (SCM key, SCM achain, SCM dfault);
52 SCM ly_assoc_cdr (SCM key, SCM alist);
53 SCM ly_assoc_get (SCM key, SCM alist, SCM def);
54 Interval ly_scm2interval (SCM);
55 Drul_array<Real> ly_scm2realdrul (SCM);
56 Slice int_list_to_slice (SCM l);
57 SCM ly_interval2scm (Drul_array<Real>);
58 char *ly_scm2newstr (SCM str, size_t *lenp);
59
60 Real robust_scm2double (SCM, double);
61 int robust_scm2int (SCM, int);
62 Direction robust_scm2dir (SCM, Direction);
63 Drul_array<Real> robust_scm2drul (SCM, Drul_array<Real>);
64 Drul_array<bool> robust_scm2booldrul (SCM, Drul_array<bool>);
65 Interval robust_scm2interval (SCM, Drul_array<Real>);
66 Offset robust_scm2offset (SCM, Offset);
67
68 SCM ly_quote_scm (SCM s);
69 bool type_check_assignment (SCM val, SCM sym, SCM type_symbol);
70 string print_scm_val (SCM val);
71 SCM ly_number2string (SCM s);
72
73 SCM parse_symbol_list (char const *);
74 SCM robust_list_ref (int i, SCM l);
75 SCM alist_to_hashq (SCM);
76
77 SCM ly_alist_vals (SCM alist);
78 SCM ly_hash2alist (SCM tab);
79
80 int procedure_arity (SCM);
81
82 /* inserts at front, removing dublicates */
83 inline SCM ly_assoc_front_x (SCM alist, SCM key, SCM val)
84 {
85   return scm_acons (key, val, scm_assoc_remove_x (alist, key));
86 }
87 inline bool ly_is_list (SCM x) { return SCM_NFALSEP (scm_list_p (x)); }
88 inline bool ly_is_procedure (SCM x) { return SCM_NFALSEP (scm_procedure_p (x)); }
89 inline bool ly_is_port (SCM x) { return SCM_NFALSEP (scm_port_p (x)); }
90
91 inline bool ly_is_equal (SCM x, SCM y)
92 {
93   return SCM_NFALSEP (scm_equal_p (x, y));
94 }
95
96 inline bool ly_scm2bool (SCM x) { return SCM_NFALSEP (x); }
97 inline char ly_scm2char (SCM x) { return SCM_CHAR (x); }
98 inline unsigned long ly_length (SCM x)
99 {
100   return scm_num2ulong (scm_length (x), 0, "ly_length");
101 }
102 inline SCM ly_bool2scm (bool x) { return SCM_BOOL (x); }
103
104 inline SCM ly_append2 (SCM x1, SCM x2)
105 {
106   return scm_append (scm_listify (x1, x2, SCM_UNDEFINED));
107 }
108 inline SCM ly_append3 (SCM x1, SCM x2, SCM x3)
109 {
110   return scm_append (scm_listify (x1, x2, x3, SCM_UNDEFINED));
111 }
112 inline SCM ly_append4 (SCM x1, SCM x2, SCM x3, SCM x4)
113 {
114   return scm_append (scm_listify (x1, x2, x3, x4, SCM_UNDEFINED));
115 }
116
117 /*
118   display and print newline.
119 */
120 extern "C" {
121   void ly_display_scm (SCM s);
122 }
123
124 void read_lily_scm_file (string);
125 void ly_c_init_guile ();
126
127 bool is_direction (SCM s);
128 bool is_number_pair (SCM);
129 bool is_axis (SCM);
130
131 /*
132   these conversion functions also do a typecheck on the argument, and
133   return a default value if S has the wrong type.
134 */
135
136 Direction to_dir (SCM s);
137 bool to_boolean (SCM s);
138
139 void init_ly_protection ();
140 unsigned int ly_scm_hash (SCM s);
141
142 SCM index_get_cell (SCM cell, Direction d);
143 SCM index_set_cell (SCM cell, Direction d, SCM val);
144
145 SCM ly_snoc (SCM s, SCM list);
146 SCM ly_split_list (SCM s, SCM lst);
147 SCM ly_unique (SCM lst);
148 SCM ly_list_qsort_uniq_x (SCM lst);
149
150 SCM ly_output_formats ();
151 SCM ly_kpathsea_find_file (SCM);
152
153 /*
154   snarfing.
155 */
156 void add_scm_init_func (void (*) ());
157
158 extern "C" {
159   typedef SCM (*Scheme_function_unknown) (GUILE_ELLIPSIS);
160 }
161
162 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
163 typedef SCM (*Scheme_function_0) ();
164 typedef SCM (*Scheme_function_1) (SCM);
165 typedef SCM (*Scheme_function_2) (SCM, SCM);
166 typedef SCM (*Scheme_function_3) (SCM, SCM, SCM);
167 #else
168 typedef SCM (*Scheme_function_0) (GUILE_ELLIPSIS);
169 typedef SCM (*Scheme_function_1) (GUILE_ELLIPSIS);
170 typedef SCM (*Scheme_function_2) (GUILE_ELLIPSIS);
171 typedef SCM (*Scheme_function_3) (GUILE_ELLIPSIS);
172 #endif
173
174 #define scm_cdr ly_cdr
175 #define scm_car ly_car
176
177 #ifndef scm_is_pair
178 #define scm_is_pair ly_is_pair
179 #endif
180
181 inline SCM ly_car (SCM x) { return SCM_CAR (x); }
182 inline SCM ly_cdr (SCM x) { return SCM_CDR (x); }
183 inline bool ly_is_pair (SCM x) { return SCM_I_CONSP (x); }
184
185
186 #endif /* LILY_GUILE_HH */