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