]> git.donarmstrong.com Git - lilypond.git/blob - lily/keyword.cc
* flower
[lilypond.git] / lily / keyword.cc
1 /*
2   keyword.cc -- keywords and identifiers
3 */
4
5 #include "keyword.hh"
6
7 #include <cstring>
8 #include <cstdlib>
9
10 /* for qsort */
11 int tabcmp (Keyword_ent const &p1, Keyword_ent const &p2)
12 {
13   return strcmp (p1.name_, p2.name_);
14 }
15
16 Keyword_table::Keyword_table (Keyword_ent *tab)
17 {
18   while (tab->name_)
19     {
20       table_.push (*tab++);
21     }
22
23   table_.sort (tabcmp);
24 }
25
26 int
27 Keyword_table::lookup (char const *s) const
28 {
29   Keyword_ent e;
30   e.name_ = s;
31   int idx = binary_search (table_, e, tabcmp);
32   if (idx >= 0)
33     return table_[idx].tokcode_;
34   else
35     return -1;
36 }