]> git.donarmstrong.com Git - lilypond.git/blob - lily/function-documentation.cc
codingstyle nits: space before ( and after ,
[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 /* type predicates. */
17 #include "spanner.hh"
18 #include "item.hh"
19
20
21 static SCM doc_hash_table;
22
23 void
24 ly_check_name (string cxx, string scm_name)
25 {
26   string mangle = mangle_cxx_identifier (cxx);
27   if (mangle != scm_name)
28     {
29       programming_error ("wrong cxx name: " + mangle + ", " + cxx +  ", " + scm_name);
30     }
31 }
32
33
34 void
35 ly_add_function_documentation (SCM func,
36                                     string fname,
37                                     string varlist,
38                                     string doc)
39 {
40   if (doc == "")
41     return;
42
43   if (!doc_hash_table)
44     doc_hash_table = scm_permanent_object (scm_c_make_hash_table (59));
45
46   string s = string (" - ") + "LilyPond procedure: " + fname + " " + varlist
47     + "\n" + doc;
48
49   scm_set_procedure_property_x (func, ly_symbol2scm ("documentation"),
50                                 ly_string2scm (s));
51   SCM entry = scm_cons (ly_string2scm (varlist), ly_string2scm (doc));
52   scm_hashq_set_x (doc_hash_table, ly_symbol2scm (fname.c_str ()), entry);
53 }
54
55 LY_DEFINE (ly_get_all_function_documentation, "ly:get-all-function-documentation",
56            0, 0, 0, (),
57            "Get a hash table with all lilypond Scheme extension functions.")
58 {
59   return doc_hash_table;
60 }
61
62
63 #include <map>
64
65 map<void *, string>  type_names;
66   
67 void
68 ly_add_type_predicate (void *ptr,
69                        string name)
70 {
71   type_names[ptr] = name; 
72 }
73
74 string
75 predicate_to_typename (void *ptr)
76 {
77   if (type_names.find (ptr) == type_names.end ())
78     return "unknown type";
79   else
80     return type_names[ptr];
81 }
82
83 static int
84 arg_dir (int a, int b)
85 {
86   if (&a < &b)
87     return 1;
88   else
89     return -1;
90 }
91
92
93 int function_argument_direction;
94 void
95 init_func_doc ()
96 {
97   function_argument_direction = arg_dir (2,3);
98
99   ly_add_type_predicate ((void*) &scm_is_integer, "integer");
100   ly_add_type_predicate ((void*) &scm_is_bool, "boolean");
101   ly_add_type_predicate ((void*) &scm_is_pair, "pair");
102   ly_add_type_predicate ((void*) &is_number_pair, "number pair");
103   ly_add_type_predicate ((void*) &scm_is_number, "number");
104   ly_add_type_predicate ((void*) &scm_is_string, "string");
105   ly_add_type_predicate ((void*) &ly_is_symbol, "symbol");
106   ly_add_type_predicate ((void*) &scm_is_vector, "vector");
107   ly_add_type_predicate ((void*) &is_axis, "axis");
108   ly_add_type_predicate ((void*) &unsmob_spanner, "spanner");
109   ly_add_type_predicate ((void*) &unsmob_item, "item");
110 }
111
112 ADD_SCM_INIT_FUNC (func_doc, init_func_doc);