X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fkeyword.cc;h=b5f7947ada203e31550ee041a557f37f439b115c;hb=97a0169312a260933246ab224e4f8b0969871dd5;hp=b273df2d6e2dbcb1d25bd645cdbbdeb94bcbe154;hpb=1cf3d59c1559fb9774c4c1c8cae155cfe54a927c;p=lilypond.git diff --git a/lily/keyword.cc b/lily/keyword.cc index b273df2d6e..b5f7947ada 100644 --- a/lily/keyword.cc +++ b/lily/keyword.cc @@ -1,64 +1,34 @@ /* keyword.cc -- keywords and identifiers - */ - -#include - +*/ #include "keyword.hh" +#include +#include +using namespace std; /* for qsort */ -int - tabcmp (void const * p1, void const * p2) +bool tab_less (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_) < 0; } Keyword_table::Keyword_table (Keyword_ent *tab) { - table = tab; + while (tab->name_) + table_.push_back (*tab++); - /* count keywords */ - for (maxkey = 0; table[maxkey].name; maxkey++) - ; - - /* sort them */ - qsort (table, maxkey, sizeof (Keyword_ent), tabcmp); + vector_sort (table_, tab_less); } -/* - lookup with binsearch, return tokencode. -*/ -int +vsize 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; - } - else - return -1; /* not found */ + Keyword_ent e; + e.name_ = s; + vsize idx = binary_search (table_, e, tab_less); + if (idx != VPOS) + return table_[idx].tokcode_; + return VPOS; } -