]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/lily-guile.hh
Nitpick run.
[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);
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 Drul_array<Real> robust_scm2drul (SCM, Drul_array<Real>);
55 Interval robust_scm2interval (SCM, Drul_array<Real>);
56 Offset robust_scm2offset (SCM, Offset);
57
58 SCM ly_quote_scm (SCM s);
59 bool type_check_assignment (SCM val, SCM sym, SCM type_symbol);
60 String print_scm_val (SCM val);
61 SCM ly_number2string (SCM s);
62
63 SCM parse_symbol_list (char const *);
64 SCM robust_list_ref (int i, SCM l);
65 SCM alist_to_hashq (SCM);
66
67 SCM ly_alist_vals (SCM alist);
68 SCM ly_hash2alist (SCM tab);
69
70 /* inserts at front, removing dublicates */
71 inline SCM ly_assoc_front_x (SCM alist, SCM key, SCM val)
72 {
73   return scm_acons (key, val, scm_assoc_remove_x (alist, key));
74 }
75 inline bool ly_is_list (SCM x) { return SCM_NFALSEP (scm_list_p (x)); }
76 inline bool ly_is_procedure (SCM x) { return SCM_NFALSEP (scm_procedure_p (x)); }
77 inline bool ly_is_port (SCM x) { return SCM_NFALSEP (scm_port_p (x)); }
78
79 inline bool ly_is_equal (SCM x, SCM y)
80 {
81   return SCM_NFALSEP (scm_equal_p (x, y));
82 }
83
84 inline bool ly_scm2bool (SCM x) { return SCM_NFALSEP (x); }
85 inline char ly_scm2char (SCM x) { return SCM_CHAR (x); }
86 inline unsigned long ly_length (SCM x)
87 {
88   return scm_num2ulong (scm_length (x), 0, "ly_length");
89 }
90 inline SCM ly_bool2scm (bool x) { return SCM_BOOL (x); }
91
92 inline SCM ly_append2 (SCM x1, SCM x2)
93 {
94   return scm_append (scm_listify (x1, x2, SCM_UNDEFINED));
95 }
96 inline SCM ly_append3 (SCM x1, SCM x2, SCM x3)
97 {
98   return scm_append (scm_listify (x1, x2, x3, SCM_UNDEFINED));
99 }
100 inline SCM ly_append4 (SCM x1, SCM x2, SCM x3, SCM x4)
101 {
102   return scm_append (scm_listify (x1, x2, x3, x4, SCM_UNDEFINED));
103 }
104
105 /*
106   display and print newline.
107 */
108 extern "C" {
109   void ly_display_scm (SCM s);
110 }
111
112 void read_lily_scm_file (String);
113 void ly_c_init_guile ();
114
115 bool is_direction (SCM s);
116 bool is_number_pair (SCM);
117 bool is_axis (SCM);
118
119 /*
120   these conversion functions also do a typecheck on the argument, and
121   return a default value if S has the wrong type.
122 */
123
124 Direction to_dir (SCM s);
125 bool to_boolean (SCM s);
126
127 void init_ly_protection ();
128 unsigned int ly_scm_hash (SCM s);
129
130 SCM index_get_cell (SCM cell, Direction d);
131 SCM index_set_cell (SCM cell, Direction d, SCM val);
132
133 SCM ly_snoc (SCM s, SCM list);
134 SCM ly_split_list (SCM s, SCM lst);
135 SCM ly_unique (SCM lst);
136 SCM ly_list_qsort_uniq_x (SCM lst);
137
138 SCM ly_output_formats ();
139 SCM ly_kpathsea_find_file (SCM);
140
141 /*
142   snarfing.
143 */
144 void add_scm_init_func (void (*) ());
145
146 extern "C" {
147   typedef SCM (*Scheme_function_unknown) ();
148 }
149
150 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
151 typedef SCM (*Scheme_function_0) ();
152 typedef SCM (*Scheme_function_1) (SCM);
153 typedef SCM (*Scheme_function_2) (SCM, SCM);
154 typedef SCM (*Scheme_function_3) (SCM, SCM, SCM);
155 #else
156 typedef SCM (*Scheme_function_0) (...);
157 typedef SCM (*Scheme_function_1) (...);
158 typedef SCM (*Scheme_function_2) (...);
159 typedef SCM (*Scheme_function_3) (...);
160 #endif
161
162 #define scm_cdr ly_cdr
163 #define scm_car ly_car
164
165 #ifndef scm_is_pair
166 #define scm_is_pair ly_is_pair
167 #endif
168
169 inline SCM ly_car (SCM x) { return SCM_CAR (x); }
170 inline SCM ly_cdr (SCM x) { return SCM_CDR (x); }
171 inline bool ly_is_pair (SCM x) { return SCM_I_CONSP (x); }
172
173
174 #endif /* LILY_GUILE_HH */