aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2013-02-23 19:15:17 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2013-02-23 19:15:17 +0100
commitfd4b89e797c1efc73304fa4da073fb31f55527f1 (patch)
tree71979801338b2e5a6e25fa2f300c5edd5ba70551 /src
parent1b636e3cc7326e9139ff107b2818703181c6e7f7 (diff)
downloadsciteco-fd4b89e797c1efc73304fa4da073fb31f55527f1.tar.gz
fixed symbol lists: sort order must correspond with search order (determined by comparision function)
* lists were sorted lexicographically (like strcmp()), but searched caseless (like strcasecmp()) * lists are now sorted with strcasecmp()-like comparision * caselessness is thus a property of the SymbolList * use new language features in symbols-extract.tes
Diffstat (limited to 'src')
-rwxr-xr-xsrc/symbols-extract.tes53
-rw-r--r--src/symbols.cpp5
-rw-r--r--src/symbols.h16
3 files changed, 42 insertions, 32 deletions
diff --git a/src/symbols-extract.tes b/src/symbols-extract.tes
index ec3a76a..9f2c61a 100755
--- a/src/symbols-extract.tes
+++ b/src/symbols-extract.tes
@@ -1,57 +1,62 @@
#!./sciteco-minimal -m
! ./symbols-extract.tes <input file> <output file> <prefix pattern list> <array name> !
-! <pos1,pos2>Mc - Compare string at pos1 with string at pos2 !
-@^Uc{
- U.2U.1 -.%.1^[ -.%.2^[
- <Q.1A-(Q.2A)U.c Q.1A"C|Q.2A"C|;'' Q.c"N;' %.1^[%.2>
+! <pos1,pos2>M{symcasecmp} - Compare symbol at pos1 with symbol at pos2 (caseless) !
+@{symcasecmp}{
+ U.2U.1 -.%.1 -.%.2
+ @.#lo{
+ U.v Q.v"W a-A%.v | Q.v"CQ.v|0' '
+ }
+ <Q.1A:M.#loU.a Q.2A:M.#loU.b
+ Q.a-Q.bU.c Q.c"N;' -Q.a;
+ %.1%.2>
Q.c
}
-! <i,j>Mx - Exchange line at I with line at J (I < J), returning new J !
-@^Ux{
+! <i,j>M{exchange} - Exchange line at I with line at J (I < J), returning new J !
+@{exchange}{
U.jU.i
Q.jJ X.xK
- Q.iJ G.x .-Q.i%.j^[ .-(X.xL.)%.j^[ -K
+ Q.iJ G.x .-Q.i%.j .-(X.xL.)%.j -K
Q.jJ G.x
Q.j
}
-! <i,j>Mq - Sort lines beginning at I until J using Quicksort algorithm !
-@^Uq{
+! <i,j>M{qsort} - Sort lines beginning at I until J using Quicksort algorithm !
+@{qsort}{
U.rU.l
Q.l-Q.r"<
Q.lU.i Q.rJB .U.j
<
- Q.iJ <.,Q.rMc-1; .-Q.r; L> .U.i
- Q.jJ <.,Q.rMc:; .-Q.l-1:; B> .U.j
+ Q.iJ <.,Q.rM{symcasecmp}-1; .-Q.r; L> .U.i
+ Q.jJ <.,Q.rM{symcasecmp}:; .-Q.l-1:; B> .U.j
Q.i-Q.j;
- Q.i,Q.jMxU.j
+ Q.i,Q.jM{exchange}U.j
>
- Q.i,Q.rMc"> Q.i,Q.rMxU.r '
+ Q.i,Q.rM{symcasecmp}"> Q.i,Q.rM{exchange}U.r '
- Q.l-Q.i"< Q.iJB Q.l,.Mq '
- Q.i-Q.r"< Q.iJL .,Q.rMq '
+ Q.l-Q.i"< Q.iJB Q.l,.M{qsort} '
+ Q.i-Q.r"< Q.iJL .,Q.rM{qsort} '
'
}
! read commandline arguments !
-LR 0Xi 2LR 0Xo 2LR 0Xp 2LR 0Xn HK
+LR 0X#in 2LR 0X#ou 2LR 0X#pa 2LR 0X#na HK
! copy all defines in input file beginning with prefix !
-EBQi <S#defineS[Qp]; -SS :Xa> EF
+EBQ#in <S#defineS[Q#pa]; -SS :Xa> EF
! sort all defines !
-Ga ZJB 0,.Mq J
+Ga ZJB 0,.M{qsort} J
! format as C/C++ array !
I/*
- * AUTOGENERATED FROM Qi
+ * AUTOGENERATED FROM Q#in
* DO NOT EDIT
*/
#ifdef HAVE_CONFIG_H
@@ -60,7 +65,7 @@ I/*
#include <glib.h>
-#include "Qi"
+#include "Q#in"
#include "sciteco.h"
#include "symbols.h"
@@ -69,7 +74,7 @@ static const SymbolList::Entry entries[] = {
<
.,W.Xa 0KK
I#ifdef Qa
- {"Qa", ^EQa},
+ {"Qa", Qa},
#endif

.-Z;>
@@ -79,12 +84,12 @@ __attribute__((constructor(PRIO_SYMBOLS)))
static void
initialize(void)
{
- Symbols::Qn.entries = entries;
- Symbols::Qn.size = G_N_ELEMENTS(entries);
+ Symbols::Q#na.entries = entries;
+ Symbols::Q#na.size = G_N_ELEMENTS(entries);
}

! write output file !
-EWQo
+EWQ#ou
EX
diff --git a/src/symbols.cpp b/src/symbols.cpp
index 5b0de92..60abf57 100644
--- a/src/symbols.cpp
+++ b/src/symbols.cpp
@@ -39,17 +39,14 @@ namespace Symbols {
* binary search.
*/
gint
-SymbolList::lookup(const gchar *name, const gchar *prefix, bool case_sensitive)
+SymbolList::lookup(const gchar *name, const gchar *prefix)
{
- int (*cmp_fnc)(const char *, const char *, size_t);
gint prefix_skip = strlen(prefix);
gint name_len = strlen(name);
gint left = 0;
gint right = size - 1;
- cmp_fnc = case_sensitive ? strncmp : g_ascii_strncasecmp;
-
if (!cmp_fnc(name, prefix, prefix_skip))
prefix_skip = 0;
diff --git a/src/symbols.h b/src/symbols.h
index bc4a291..bb27d01 100644
--- a/src/symbols.h
+++ b/src/symbols.h
@@ -18,6 +18,7 @@
#ifndef __SYMBOLS_H
#define __SYMBOLS_H
+#include <string.h>
#include <glib.h>
class SymbolList {
@@ -31,19 +32,26 @@ public:
gint size;
private:
+ int (*cmp_fnc)(const char *, const char *, size_t);
+
/* for auto-completions */
GList *list;
public:
- SymbolList(const Entry *_entries = NULL, gint _size = 0)
- : entries(_entries), size(_size), list(NULL) {}
+ SymbolList(const Entry *_entries = NULL, gint _size = 0,
+ bool case_sensitive = false)
+ : entries(_entries), size(_size), list(NULL)
+ {
+ cmp_fnc = case_sensitive ? strncmp
+ : g_ascii_strncasecmp;
+ }
+
~SymbolList()
{
g_list_free(list);
}
- gint lookup(const gchar *name, const gchar *prefix = "",
- bool case_sensitive = false);
+ gint lookup(const gchar *name, const gchar *prefix = "");
GList *get_glist(void);
};