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