X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fkeyword.cc;h=ea7f14901dd736503930df6488db12194ce9a876;hb=3a7b6b3cbd35499a0993d46c302f37853f1b9c51;hp=14903cfb61ae5a59d1274e2d08ef8ebe721b35a5;hpb=daee8243ff1c66bc714455a2d265ab02f03546ec;p=lilypond.git diff --git a/lily/keyword.cc b/lily/keyword.cc index 14903cfb61..ea7f14901d 100644 --- a/lily/keyword.cc +++ b/lily/keyword.cc @@ -1,79 +1,62 @@ /* keyword.cc -- keywords and identifiers */ - +#include #include - -#include "glob.hh" -#include "lexer.hh" -//#include "mudobs.hh" -//#include "gram.hh" - -/* for the keyword table */ -struct Keyword_ent -{ - const char *name; - int tokcode; -}; - -struct Keyword_table -{ - Keyword_ent *table; - int maxkey; - Keyword_table(Keyword_ent *); - int lookup(const char *s) const; -}; +#include "keyword.hh" /* for qsort */ int - tabcmp(const void * p1, const void * p2) + tabcmp (void const * p1, void const * p2) { - return strcmp(((const Keyword_ent *) p1)->name, - ((const Keyword_ent *) p2)->name); + return strcmp (((Keyword_ent const *) p1)->name, + ((Keyword_ent const *) p2)->name); } -Keyword_table::Keyword_table(Keyword_ent *tab) +Keyword_table::Keyword_table (Keyword_ent *tab) { - table = tab; + table = tab; - /* count keywords */ - for (maxkey = 0; table[maxkey].name; maxkey++); + /* count keywords */ + for (maxkey = 0; table[maxkey].name; maxkey++) + ; - /* sort them */ - qsort(table, maxkey, sizeof(Keyword_ent), tabcmp); + /* sort them */ + qsort (table, maxkey, sizeof (Keyword_ent), tabcmp); } /* lookup with binsearch, return tokencode. */ int -Keyword_table::lookup(const char *s)const +Keyword_table::lookup (char const *s) const { - int lo, - hi, - cmp, - 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; + 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; } - while (hi - lo > 1); - if (!strcmp(s, table[lo].name)) - { - return table[lo].tokcode; - } else - return -1; /* not found */ + else + return -1; /* not found */ }