]> git.donarmstrong.com Git - lilypond.git/blob - lily/keyword.cc
70c84e59e2a6bfc9719f08dd62d41a171ba51444
[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     table_.push (*tab++);
20
21   table_.sort (tabcmp);
22 }
23
24 int
25 Keyword_table::lookup (char const *s) const
26 {
27   Keyword_ent e;
28   e.name_ = s;
29   int idx = binary_search (table_, e, tabcmp);
30   if (idx >= 0)
31     return table_[idx].tokcode_;
32   else
33     return -1;
34 }