X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fkeyword.cc;h=70c84e59e2a6bfc9719f08dd62d41a171ba51444;hb=b6a3535923f893b4c593203c3421361ae02eba7c;hp=e235d6a9734337e162da0cd262b3e341bf616992;hpb=fc3e875d6bf06f0680e897faffdcab36ad975a03;p=lilypond.git diff --git a/lily/keyword.cc b/lily/keyword.cc index e235d6a973..70c84e59e2 100644 --- a/lily/keyword.cc +++ b/lily/keyword.cc @@ -1,62 +1,34 @@ /* keyword.cc -- keywords and identifiers - */ -#include -#include +*/ + #include "keyword.hh" +#include +#include /* for qsort */ -int - tabcmp (void const * p1, void const * p2) +int tabcmp (Keyword_ent const &p1, Keyword_ent const &p2) { - return strcmp (( (Keyword_ent const *) p1)->name, - ((Keyword_ent const *) p2)->name); + return strcmp (p1.name_, p2.name_); } Keyword_table::Keyword_table (Keyword_ent *tab) { - table = tab; + while (tab->name_) + table_.push (*tab++); - /* count keywords */ - for (maxkey = 0; table[maxkey].name; maxkey++) - ; - - /* sort them */ - qsort (table, maxkey, sizeof (Keyword_ent), tabcmp); + table_.sort (tabcmp); } -/* - lookup with binsearch, return tokencode. -*/ int Keyword_table::lookup (char const *s) const { - int lo; - int hi; - int cmp; - int result; - lo = 0; - hi = maxkey; - - /* binary search */ - do - { - cmp = (lo + hi) / 2; - - result = strcmp (s, table[cmp].name); - - if (result < 0) - hi = cmp; - else - lo = cmp; - } - while (hi - lo > 1); - if (!strcmp (s, table[lo].name)) - { - return table[lo].tokcode; - } + Keyword_ent e; + e.name_ = s; + int idx = binary_search (table_, e, tabcmp); + if (idx >= 0) + return table_[idx].tokcode_; else - return -1; /* not found */ + return -1; } -