]> git.donarmstrong.com Git - lilypond.git/blob - lily/function-documentation.cc
909eb1030b50a9ffe2a7f104f4ab40f1b2272cd2
[lilypond.git] / lily / function-documentation.cc
1 /*
2   function-documentation.cc -- Scheme doc strings.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include <cstring>
10 using namespace std;
11
12 #include "std-string.hh"
13 #include "lily-guile.hh"
14 #include "warn.hh"
15
16
17 static SCM doc_hash_table;
18
19 void
20 ly_check_name (string cxx, string scm_name)
21 {
22   string mangle = mangle_cxx_identifier (cxx);
23   if (mangle != scm_name)
24     {
25       programming_error ("wrong cxx name: " + mangle + ", " + cxx +  ", " + scm_name);
26     }
27 }
28
29
30 void
31 ly_add_function_documentation (SCM func,
32                                     string fname,
33                                     string varlist,
34                                     string doc)
35 {
36   if (doc == "")
37     return;
38
39   if (!doc_hash_table)
40     doc_hash_table = scm_permanent_object (scm_c_make_hash_table (59));
41
42   string s = string (" - ") + "LilyPond procedure: " + fname + " " + varlist
43     + "\n" + doc;
44
45   scm_set_procedure_property_x (func, ly_symbol2scm ("documentation"),
46                                 ly_string2scm (s));
47   SCM entry = scm_cons (ly_string2scm (varlist), ly_string2scm (doc));
48   scm_hashq_set_x (doc_hash_table, ly_symbol2scm (fname.c_str ()), entry);
49 }
50
51 LY_DEFINE (ly_get_all_function_documentation, "ly:get-all-function-documentation",
52            0, 0, 0, (),
53            "Get a hash table with all LilyPond Scheme extension functions.")
54 {
55   return doc_hash_table;
56 }
57
58
59 #include <map>
60
61 map<void *, string>  type_names;
62   
63 void
64 ly_add_type_predicate (void *ptr,
65                        string name)
66 {
67   type_names[ptr] = name; 
68 }
69
70 string
71 predicate_to_typename (void *ptr)
72 {
73   if (type_names.find (ptr) == type_names.end ())
74     {
75       programming_error ("Unknown type predicate");
76       return "unknown type";
77     }
78   else
79     return type_names[ptr];
80 }
81
82 /* type predicates. */
83 #include "spanner.hh"
84 #include "item.hh"
85 #include "music.hh"
86 #include "music-function.hh"
87 #include "performance.hh"
88 #include "paper-score.hh"
89 #include "global-context.hh"
90 #include "input.hh"
91
92 void
93 init_func_doc ()
94 {
95   ly_add_type_predicate ((void*) &is_direction, "direction");
96   ly_add_type_predicate ((void*) &is_music_function, "Music_function");
97   ly_add_type_predicate ((void*) &ly_is_port, "port");
98   ly_add_type_predicate ((void*) &ly_cheap_is_list, "list");
99   ly_add_type_predicate ((void*) &unsmob_global_context, "Global_context");
100   ly_add_type_predicate ((void*) &unsmob_input, "Input");
101   ly_add_type_predicate ((void*) &unsmob_moment, "Moment");
102   ly_add_type_predicate ((void*) &unsmob_paper_score, "Paper_score");
103   ly_add_type_predicate ((void*) &unsmob_performance, "Performance");
104
105   ly_add_type_predicate ((void*) &is_axis, "axis");
106   ly_add_type_predicate ((void*) &is_number_pair, "number pair");
107   ly_add_type_predicate ((void*) &ly_is_list, "list");
108   ly_add_type_predicate ((void*) &ly_is_procedure, "procedure");
109   ly_add_type_predicate ((void*) &ly_is_symbol, "symbol");
110   ly_add_type_predicate ((void*) &scm_is_bool, "boolean");
111   ly_add_type_predicate ((void*) &scm_is_integer, "integer");
112   ly_add_type_predicate ((void*) &scm_is_number, "number");
113   ly_add_type_predicate ((void*) &scm_is_pair, "pair");
114   ly_add_type_predicate ((void*) &scm_is_rational, "rational");
115   ly_add_type_predicate ((void*) &scm_is_string, "string");
116   ly_add_type_predicate ((void*) &scm_is_vector, "vector");
117   ly_add_type_predicate ((void*) &unsmob_item, "Item");
118   ly_add_type_predicate ((void*) &unsmob_music, "Music");
119   ly_add_type_predicate ((void*) &unsmob_spanner, "Spanner");
120 }
121
122 ADD_SCM_INIT_FUNC (func_doc, init_func_doc);