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