aboutsummaryrefslogtreecommitdiffhomepage
path: root/symbols.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'symbols.cpp')
-rw-r--r--symbols.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/symbols.cpp b/symbols.cpp
new file mode 100644
index 0000000..c123ebc
--- /dev/null
+++ b/symbols.cpp
@@ -0,0 +1,47 @@
+#include <glib.h>
+
+#include "symbols.h"
+
+/*
+ * defaults for sciteco-minimal
+ */
+namespace Symbols {
+ SymbolList __attribute__((weak)) scintilla;
+}
+
+/*
+ * Since symbol lists are presorted constant arrays we can do a simple
+ * binary search.
+ */
+gint
+SymbolList::lookup(const gchar *name)
+{
+ gint left = 0;
+ gint right = size - 1;
+
+ while (left <= right) {
+ gint cur = left + (right-left)/2;
+ gint cmp = g_strcmp0(entries[cur].name, name);
+
+ if (!cmp)
+ return entries[cur].value;
+
+ if (cmp > 0)
+ right = cur-1;
+ else /* cmp < 0 */
+ left = cur+1;
+ }
+
+ return -1;
+}
+
+GList *
+SymbolList::get_glist(void)
+{
+ GList *list = NULL;
+
+ while (size--)
+ list = g_list_prepend(list, (gchar *)entries[size].name);
+
+ return list;
+}