]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/keyword.cc
* lily/include/scm-hash.hh (class Scheme_hash_table): idem.
[lilypond.git] / lily / keyword.cc
index ebedc63b2ba61d1507910e79457d46b5f628b581..de6aca9e495cd7a6c6496384a0c3d7e2d6b377ca 100644 (file)
@@ -1,62 +1,35 @@
 /*
   keyword.cc -- keywords and identifiers
  */
-
+#include <string.h>
 #include <stdlib.h>
-
-#include "my-lily-lexer.hh"
 #include "keyword.hh"
 
+
 /* 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;
-
-  /* count keywords */
-  for (maxkey = 0; table[maxkey].name; maxkey++);
+  while (tab->name_)
+    {
+      table_.push (*tab++);
+    }
 
-  /* 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,
-          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;
-    }
-  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;
 }
-