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