]> git.donarmstrong.com Git - lilypond.git/blob - lily/function-documentation.cc
Web-ja: update introduction
[lilypond.git] / lily / function-documentation.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <cstring>
21 #include <map>
22 using namespace std;
23
24 #include "std-string.hh"
25 #include "lily-guile.hh"
26 #include "warn.hh"
27
28 /* type predicates. */
29 #include "global-context.hh"
30 #include "input.hh"
31 #include "item.hh"
32 #include "music.hh"
33 #include "music-function.hh"
34 #include "paper-score.hh"
35 #include "performance.hh"
36 #include "protected-scm.hh"
37 #include "spanner.hh"
38 #include "stream-event.hh"
39 #include "unpure-pure-container.hh"
40
41 static Protected_scm doc_hash_table;
42
43 void
44 ly_check_name (const string &cxx, const string &scm_name)
45 {
46   string mangle = mangle_cxx_identifier (cxx);
47   if (mangle != scm_name)
48     {
49       programming_error ("wrong cxx name: " + mangle + ", " + cxx + ", " + scm_name);
50     }
51 }
52
53 void
54 ly_add_function_documentation (SCM func,
55                                const string &fname,
56                                const string &varlist,
57                                const string &doc)
58 {
59   if (doc == "")
60     return;
61
62   if (!doc_hash_table.is_bound ())
63     doc_hash_table = scm_c_make_hash_table (59);
64
65   string s = string (" - ") + "LilyPond procedure: " + fname + " " + varlist
66              + "\n" + doc;
67
68   scm_set_procedure_property_x (func, ly_symbol2scm ("documentation"),
69                                 ly_string2scm (s));
70   SCM entry = scm_cons (ly_string2scm (varlist), ly_string2scm (doc));
71   scm_hashq_set_x (doc_hash_table, ly_symbol2scm (fname.c_str ()), entry);
72 }
73
74 LY_DEFINE (ly_get_all_function_documentation, "ly:get-all-function-documentation",
75            0, 0, 0, (),
76            "Get a hash table with all LilyPond Scheme extension functions.")
77 {
78   return doc_hash_table;
79 }
80
81 map<void *, string> type_names;
82
83 void
84 ly_add_type_predicate (void *ptr,
85                        const string &name)
86 {
87   type_names[ptr] = name;
88 }
89
90 string
91 predicate_to_typename (void *ptr)
92 {
93   if (type_names.find (ptr) == type_names.end ())
94     {
95       programming_error ("Unknown type predicate");
96       return "unknown type";
97     }
98   else
99     return type_names[ptr];
100 }
101
102 void
103 init_func_doc ()
104 {
105   ly_add_type_predicate ((void *) &is_direction, "direction");
106   ly_add_type_predicate ((void *) &ly_is_port, "port");
107   ly_add_type_predicate ((void *) &ly_cheap_is_list, "list");
108   ly_add_type_predicate ((void *) &unsmob<Global_context>, "Global_context");
109   ly_add_type_predicate ((void *) &unsmob<Paper_score>, "Paper_score");
110   ly_add_type_predicate ((void *) &unsmob<Performance>, "Performance");
111   ly_add_type_predicate ((void *) &is_axis, "axis");
112   ly_add_type_predicate ((void *) &is_number_pair, "number pair");
113   ly_add_type_predicate ((void *) &ly_is_list, "list");
114   ly_add_type_predicate ((void *) &ly_is_procedure, "procedure");
115   ly_add_type_predicate ((void *) &ly_is_symbol, "symbol");
116   ly_add_type_predicate ((void *) &scm_is_bool, "boolean");
117   ly_add_type_predicate ((void *) &scm_is_integer, "integer");
118   ly_add_type_predicate ((void *) &scm_is_number, "number");
119   ly_add_type_predicate ((void *) &scm_is_pair, "pair");
120   ly_add_type_predicate ((void *) &scm_is_rational, "rational");
121   ly_add_type_predicate ((void *) &scm_is_string, "string");
122   ly_add_type_predicate ((void *) &scm_is_vector, "vector");
123   ly_add_type_predicate ((void *) &unsmob<Item>, "Item");
124   ly_add_type_predicate ((void *) &unsmob<Music>, "Music");
125   ly_add_type_predicate ((void *) &unsmob<Spanner>, "Spanner");
126   ly_add_type_predicate ((void *) &unsmob<Stream_event>, "Stream_event");
127 }
128
129 ADD_SCM_INIT_FUNC (func_doc, init_func_doc);