dict @ 0a2e62f57734f820cd20e151d1150342408552ed

ref: Apply astyle --style=linux
   1diff --git a/dict/main.c b/dict/main.c
   2index e5573fea55a25a90f4ad79493f38ec58e3886a3b..b743e07a307618cbf522b7a770da37953dd605f2 100644
   3--- a/dict/main.c
   4+++ b/dict/main.c
   5@@ -14,24 +14,25 @@
   6 void search(char*, int);
   7 int run(const char*, const char*);
   8 
   9-int main(int argc, char** argv) {
  10+int main(int argc, char** argv)
  11+{
  12     int opt;
  13     char* txt = NULL;
  14     char* db = NULL;
  15 
  16     while ((opt = getopt(argc, argv, "t:d:h")) != -1) {
  17         switch(opt) {
  18-            case 't':
  19-                txt = copy_achar(optarg);
  20-                break;
  21-            case 'd':
  22-                db = copy_achar(optarg);
  23-                break;
  24-            case 'h':
  25-                  // fall through
  26-            default:
  27-                printf("Usage: %s", argv[0]);
  28-                goto end;
  29+        case 't':
  30+            txt = copy_achar(optarg);
  31+            break;
  32+        case 'd':
  33+            db = copy_achar(optarg);
  34+            break;
  35+        case 'h':
  36+        // fall through
  37+        default:
  38+            printf("Usage: %s", argv[0]);
  39+            goto end;
  40         }
  41     }
  42 
  43@@ -46,7 +47,8 @@
  44     return r;
  45 }
  46 
  47-int run(const char *db, const char *txt) {
  48+int run(const char *db, const char *txt)
  49+{
  50     data = new_data(db);
  51     bootstrap(data);
  52 
  53@@ -92,7 +94,8 @@     free_data(data);
  54     return 0;
  55 }
  56 
  57-void search(char *sch, int len) {
  58+void search(char *sch, int len)
  59+{
  60     char s[len+2];
  61 
  62     sprintf(s, "%%%*s%%", len, sch);
  63@@ -107,5 +110,3 @@             printw("%s", item->Line);
  64     }
  65     refresh();
  66 }
  67-
  68-
  69diff --git a/ext/spellfix.c b/ext/spellfix.c
  70index a0c5aafd1009b6cfe79f5d46c98572f77a335706..77840a56ca6b73a38a338ffefd7bee2ef009f02c 100644
  71--- a/ext/spellfix.c
  72+++ b/ext/spellfix.c
  73@@ -30,8 +30,8 @@ # include <stdlib.h>
  74 # include <assert.h>
  75 # define ALWAYS(X)  1
  76 # define NEVER(X)   0
  77-  typedef unsigned char u8;
  78-  typedef unsigned short u16;
  79+typedef unsigned char u8;
  80+typedef unsigned short u16;
  81 #endif
  82 #include <ctype.h>
  83 
  84@@ -73,99 +73,99 @@ ** The following table gives the character class for non-initial ASCII
  85 ** characters.
  86 */
  87 static const unsigned char midClass[] = {
  88- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
  89- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
  90- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
  91- /*   */ CCLASS_SPACE,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
  92- /*   */ CCLASS_SPACE,    /*   */ CCLASS_SPACE,   /*   */ CCLASS_OTHER,
  93- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
  94- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
  95- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
  96- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
  97- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
  98- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_SPACE,
  99- /* ! */ CCLASS_OTHER,    /* " */ CCLASS_OTHER,   /* # */ CCLASS_OTHER,
 100- /* $ */ CCLASS_OTHER,    /* % */ CCLASS_OTHER,   /* & */ CCLASS_OTHER,
 101- /* ' */ CCLASS_SILENT,   /* ( */ CCLASS_OTHER,   /* ) */ CCLASS_OTHER,
 102- /* * */ CCLASS_OTHER,    /* + */ CCLASS_OTHER,   /* , */ CCLASS_OTHER,
 103- /* - */ CCLASS_OTHER,    /* . */ CCLASS_OTHER,   /* / */ CCLASS_OTHER,
 104- /* 0 */ CCLASS_DIGIT,    /* 1 */ CCLASS_DIGIT,   /* 2 */ CCLASS_DIGIT,
 105- /* 3 */ CCLASS_DIGIT,    /* 4 */ CCLASS_DIGIT,   /* 5 */ CCLASS_DIGIT,
 106- /* 6 */ CCLASS_DIGIT,    /* 7 */ CCLASS_DIGIT,   /* 8 */ CCLASS_DIGIT,
 107- /* 9 */ CCLASS_DIGIT,    /* : */ CCLASS_OTHER,   /* ; */ CCLASS_OTHER,
 108- /* < */ CCLASS_OTHER,    /* = */ CCLASS_OTHER,   /* > */ CCLASS_OTHER,
 109- /* ? */ CCLASS_OTHER,    /* @ */ CCLASS_OTHER,   /* A */ CCLASS_VOWEL,
 110- /* B */ CCLASS_B,        /* C */ CCLASS_C,       /* D */ CCLASS_D,
 111- /* E */ CCLASS_VOWEL,    /* F */ CCLASS_B,       /* G */ CCLASS_C,
 112- /* H */ CCLASS_SILENT,   /* I */ CCLASS_VOWEL,   /* J */ CCLASS_C,
 113- /* K */ CCLASS_C,        /* L */ CCLASS_L,       /* M */ CCLASS_M,
 114- /* N */ CCLASS_M,        /* O */ CCLASS_VOWEL,   /* P */ CCLASS_B,
 115- /* Q */ CCLASS_C,        /* R */ CCLASS_R,       /* S */ CCLASS_C,
 116- /* T */ CCLASS_D,        /* U */ CCLASS_VOWEL,   /* V */ CCLASS_B,
 117- /* W */ CCLASS_B,        /* X */ CCLASS_C,       /* Y */ CCLASS_VOWEL,
 118- /* Z */ CCLASS_C,        /* [ */ CCLASS_OTHER,   /* \ */ CCLASS_OTHER,
 119- /* ] */ CCLASS_OTHER,    /* ^ */ CCLASS_OTHER,   /* _ */ CCLASS_OTHER,
 120- /* ` */ CCLASS_OTHER,    /* a */ CCLASS_VOWEL,   /* b */ CCLASS_B,
 121- /* c */ CCLASS_C,        /* d */ CCLASS_D,       /* e */ CCLASS_VOWEL,
 122- /* f */ CCLASS_B,        /* g */ CCLASS_C,       /* h */ CCLASS_SILENT,
 123- /* i */ CCLASS_VOWEL,    /* j */ CCLASS_C,       /* k */ CCLASS_C,
 124- /* l */ CCLASS_L,        /* m */ CCLASS_M,       /* n */ CCLASS_M,
 125- /* o */ CCLASS_VOWEL,    /* p */ CCLASS_B,       /* q */ CCLASS_C,
 126- /* r */ CCLASS_R,        /* s */ CCLASS_C,       /* t */ CCLASS_D,
 127- /* u */ CCLASS_VOWEL,    /* v */ CCLASS_B,       /* w */ CCLASS_B,
 128- /* x */ CCLASS_C,        /* y */ CCLASS_VOWEL,   /* z */ CCLASS_C,
 129- /* { */ CCLASS_OTHER,    /* | */ CCLASS_OTHER,   /* } */ CCLASS_OTHER,
 130- /* ~ */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   
 131+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 132+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 133+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 134+    /*   */ CCLASS_SPACE,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 135+    /*   */ CCLASS_SPACE,    /*   */ CCLASS_SPACE,   /*   */ CCLASS_OTHER,
 136+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 137+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 138+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 139+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 140+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 141+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_SPACE,
 142+    /* ! */ CCLASS_OTHER,    /* " */ CCLASS_OTHER,   /* # */ CCLASS_OTHER,
 143+    /* $ */ CCLASS_OTHER,    /* % */ CCLASS_OTHER,   /* & */ CCLASS_OTHER,
 144+    /* ' */ CCLASS_SILENT,   /* ( */ CCLASS_OTHER,   /* ) */ CCLASS_OTHER,
 145+    /* * */ CCLASS_OTHER,    /* + */ CCLASS_OTHER,   /* , */ CCLASS_OTHER,
 146+    /* - */ CCLASS_OTHER,    /* . */ CCLASS_OTHER,   /* / */ CCLASS_OTHER,
 147+    /* 0 */ CCLASS_DIGIT,    /* 1 */ CCLASS_DIGIT,   /* 2 */ CCLASS_DIGIT,
 148+    /* 3 */ CCLASS_DIGIT,    /* 4 */ CCLASS_DIGIT,   /* 5 */ CCLASS_DIGIT,
 149+    /* 6 */ CCLASS_DIGIT,    /* 7 */ CCLASS_DIGIT,   /* 8 */ CCLASS_DIGIT,
 150+    /* 9 */ CCLASS_DIGIT,    /* : */ CCLASS_OTHER,   /* ; */ CCLASS_OTHER,
 151+    /* < */ CCLASS_OTHER,    /* = */ CCLASS_OTHER,   /* > */ CCLASS_OTHER,
 152+    /* ? */ CCLASS_OTHER,    /* @ */ CCLASS_OTHER,   /* A */ CCLASS_VOWEL,
 153+    /* B */ CCLASS_B,        /* C */ CCLASS_C,       /* D */ CCLASS_D,
 154+    /* E */ CCLASS_VOWEL,    /* F */ CCLASS_B,       /* G */ CCLASS_C,
 155+    /* H */ CCLASS_SILENT,   /* I */ CCLASS_VOWEL,   /* J */ CCLASS_C,
 156+    /* K */ CCLASS_C,        /* L */ CCLASS_L,       /* M */ CCLASS_M,
 157+    /* N */ CCLASS_M,        /* O */ CCLASS_VOWEL,   /* P */ CCLASS_B,
 158+    /* Q */ CCLASS_C,        /* R */ CCLASS_R,       /* S */ CCLASS_C,
 159+    /* T */ CCLASS_D,        /* U */ CCLASS_VOWEL,   /* V */ CCLASS_B,
 160+    /* W */ CCLASS_B,        /* X */ CCLASS_C,       /* Y */ CCLASS_VOWEL,
 161+    /* Z */ CCLASS_C,        /* [ */ CCLASS_OTHER,   /* \ */ CCLASS_OTHER,
 162+    /* ] */ CCLASS_OTHER,    /* ^ */ CCLASS_OTHER,   /* _ */ CCLASS_OTHER,
 163+    /* ` */ CCLASS_OTHER,    /* a */ CCLASS_VOWEL,   /* b */ CCLASS_B,
 164+    /* c */ CCLASS_C,        /* d */ CCLASS_D,       /* e */ CCLASS_VOWEL,
 165+    /* f */ CCLASS_B,        /* g */ CCLASS_C,       /* h */ CCLASS_SILENT,
 166+    /* i */ CCLASS_VOWEL,    /* j */ CCLASS_C,       /* k */ CCLASS_C,
 167+    /* l */ CCLASS_L,        /* m */ CCLASS_M,       /* n */ CCLASS_M,
 168+    /* o */ CCLASS_VOWEL,    /* p */ CCLASS_B,       /* q */ CCLASS_C,
 169+    /* r */ CCLASS_R,        /* s */ CCLASS_C,       /* t */ CCLASS_D,
 170+    /* u */ CCLASS_VOWEL,    /* v */ CCLASS_B,       /* w */ CCLASS_B,
 171+    /* x */ CCLASS_C,        /* y */ CCLASS_VOWEL,   /* z */ CCLASS_C,
 172+    /* { */ CCLASS_OTHER,    /* | */ CCLASS_OTHER,   /* } */ CCLASS_OTHER,
 173+    /* ~ */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,
 174 };
 175-/* 
 176+/*
 177 ** This tables gives the character class for ASCII characters that form the
 178 ** initial character of a word.  The only difference from midClass is with
 179 ** the letters H, W, and Y.
 180 */
 181 static const unsigned char initClass[] = {
 182- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 183- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 184- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 185- /*   */ CCLASS_SPACE,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 186- /*   */ CCLASS_SPACE,    /*   */ CCLASS_SPACE,   /*   */ CCLASS_OTHER,
 187- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 188- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 189- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 190- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 191- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 192- /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_SPACE,
 193- /* ! */ CCLASS_OTHER,    /* " */ CCLASS_OTHER,   /* # */ CCLASS_OTHER,
 194- /* $ */ CCLASS_OTHER,    /* % */ CCLASS_OTHER,   /* & */ CCLASS_OTHER,
 195- /* ' */ CCLASS_OTHER,    /* ( */ CCLASS_OTHER,   /* ) */ CCLASS_OTHER,
 196- /* * */ CCLASS_OTHER,    /* + */ CCLASS_OTHER,   /* , */ CCLASS_OTHER,
 197- /* - */ CCLASS_OTHER,    /* . */ CCLASS_OTHER,   /* / */ CCLASS_OTHER,
 198- /* 0 */ CCLASS_DIGIT,    /* 1 */ CCLASS_DIGIT,   /* 2 */ CCLASS_DIGIT,
 199- /* 3 */ CCLASS_DIGIT,    /* 4 */ CCLASS_DIGIT,   /* 5 */ CCLASS_DIGIT,
 200- /* 6 */ CCLASS_DIGIT,    /* 7 */ CCLASS_DIGIT,   /* 8 */ CCLASS_DIGIT,
 201- /* 9 */ CCLASS_DIGIT,    /* : */ CCLASS_OTHER,   /* ; */ CCLASS_OTHER,
 202- /* < */ CCLASS_OTHER,    /* = */ CCLASS_OTHER,   /* > */ CCLASS_OTHER,
 203- /* ? */ CCLASS_OTHER,    /* @ */ CCLASS_OTHER,   /* A */ CCLASS_VOWEL,
 204- /* B */ CCLASS_B,        /* C */ CCLASS_C,       /* D */ CCLASS_D,
 205- /* E */ CCLASS_VOWEL,    /* F */ CCLASS_B,       /* G */ CCLASS_C,
 206- /* H */ CCLASS_SILENT,   /* I */ CCLASS_VOWEL,   /* J */ CCLASS_C,
 207- /* K */ CCLASS_C,        /* L */ CCLASS_L,       /* M */ CCLASS_M,
 208- /* N */ CCLASS_M,        /* O */ CCLASS_VOWEL,   /* P */ CCLASS_B,
 209- /* Q */ CCLASS_C,        /* R */ CCLASS_R,       /* S */ CCLASS_C,
 210- /* T */ CCLASS_D,        /* U */ CCLASS_VOWEL,   /* V */ CCLASS_B,
 211- /* W */ CCLASS_B,        /* X */ CCLASS_C,       /* Y */ CCLASS_Y,
 212- /* Z */ CCLASS_C,        /* [ */ CCLASS_OTHER,   /* \ */ CCLASS_OTHER,
 213- /* ] */ CCLASS_OTHER,    /* ^ */ CCLASS_OTHER,   /* _ */ CCLASS_OTHER,
 214- /* ` */ CCLASS_OTHER,    /* a */ CCLASS_VOWEL,   /* b */ CCLASS_B,
 215- /* c */ CCLASS_C,        /* d */ CCLASS_D,       /* e */ CCLASS_VOWEL,
 216- /* f */ CCLASS_B,        /* g */ CCLASS_C,       /* h */ CCLASS_SILENT,
 217- /* i */ CCLASS_VOWEL,    /* j */ CCLASS_C,       /* k */ CCLASS_C,
 218- /* l */ CCLASS_L,        /* m */ CCLASS_M,       /* n */ CCLASS_M,
 219- /* o */ CCLASS_VOWEL,    /* p */ CCLASS_B,       /* q */ CCLASS_C,
 220- /* r */ CCLASS_R,        /* s */ CCLASS_C,       /* t */ CCLASS_D,
 221- /* u */ CCLASS_VOWEL,    /* v */ CCLASS_B,       /* w */ CCLASS_B,
 222- /* x */ CCLASS_C,        /* y */ CCLASS_Y,       /* z */ CCLASS_C,
 223- /* { */ CCLASS_OTHER,    /* | */ CCLASS_OTHER,   /* } */ CCLASS_OTHER,
 224- /* ~ */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   
 225+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 226+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 227+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 228+    /*   */ CCLASS_SPACE,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 229+    /*   */ CCLASS_SPACE,    /*   */ CCLASS_SPACE,   /*   */ CCLASS_OTHER,
 230+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 231+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 232+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 233+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 234+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_OTHER,
 235+    /*   */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,   /*   */ CCLASS_SPACE,
 236+    /* ! */ CCLASS_OTHER,    /* " */ CCLASS_OTHER,   /* # */ CCLASS_OTHER,
 237+    /* $ */ CCLASS_OTHER,    /* % */ CCLASS_OTHER,   /* & */ CCLASS_OTHER,
 238+    /* ' */ CCLASS_OTHER,    /* ( */ CCLASS_OTHER,   /* ) */ CCLASS_OTHER,
 239+    /* * */ CCLASS_OTHER,    /* + */ CCLASS_OTHER,   /* , */ CCLASS_OTHER,
 240+    /* - */ CCLASS_OTHER,    /* . */ CCLASS_OTHER,   /* / */ CCLASS_OTHER,
 241+    /* 0 */ CCLASS_DIGIT,    /* 1 */ CCLASS_DIGIT,   /* 2 */ CCLASS_DIGIT,
 242+    /* 3 */ CCLASS_DIGIT,    /* 4 */ CCLASS_DIGIT,   /* 5 */ CCLASS_DIGIT,
 243+    /* 6 */ CCLASS_DIGIT,    /* 7 */ CCLASS_DIGIT,   /* 8 */ CCLASS_DIGIT,
 244+    /* 9 */ CCLASS_DIGIT,    /* : */ CCLASS_OTHER,   /* ; */ CCLASS_OTHER,
 245+    /* < */ CCLASS_OTHER,    /* = */ CCLASS_OTHER,   /* > */ CCLASS_OTHER,
 246+    /* ? */ CCLASS_OTHER,    /* @ */ CCLASS_OTHER,   /* A */ CCLASS_VOWEL,
 247+    /* B */ CCLASS_B,        /* C */ CCLASS_C,       /* D */ CCLASS_D,
 248+    /* E */ CCLASS_VOWEL,    /* F */ CCLASS_B,       /* G */ CCLASS_C,
 249+    /* H */ CCLASS_SILENT,   /* I */ CCLASS_VOWEL,   /* J */ CCLASS_C,
 250+    /* K */ CCLASS_C,        /* L */ CCLASS_L,       /* M */ CCLASS_M,
 251+    /* N */ CCLASS_M,        /* O */ CCLASS_VOWEL,   /* P */ CCLASS_B,
 252+    /* Q */ CCLASS_C,        /* R */ CCLASS_R,       /* S */ CCLASS_C,
 253+    /* T */ CCLASS_D,        /* U */ CCLASS_VOWEL,   /* V */ CCLASS_B,
 254+    /* W */ CCLASS_B,        /* X */ CCLASS_C,       /* Y */ CCLASS_Y,
 255+    /* Z */ CCLASS_C,        /* [ */ CCLASS_OTHER,   /* \ */ CCLASS_OTHER,
 256+    /* ] */ CCLASS_OTHER,    /* ^ */ CCLASS_OTHER,   /* _ */ CCLASS_OTHER,
 257+    /* ` */ CCLASS_OTHER,    /* a */ CCLASS_VOWEL,   /* b */ CCLASS_B,
 258+    /* c */ CCLASS_C,        /* d */ CCLASS_D,       /* e */ CCLASS_VOWEL,
 259+    /* f */ CCLASS_B,        /* g */ CCLASS_C,       /* h */ CCLASS_SILENT,
 260+    /* i */ CCLASS_VOWEL,    /* j */ CCLASS_C,       /* k */ CCLASS_C,
 261+    /* l */ CCLASS_L,        /* m */ CCLASS_M,       /* n */ CCLASS_M,
 262+    /* o */ CCLASS_VOWEL,    /* p */ CCLASS_B,       /* q */ CCLASS_C,
 263+    /* r */ CCLASS_R,        /* s */ CCLASS_C,       /* t */ CCLASS_D,
 264+    /* u */ CCLASS_VOWEL,    /* v */ CCLASS_B,       /* w */ CCLASS_B,
 265+    /* x */ CCLASS_C,        /* y */ CCLASS_Y,       /* z */ CCLASS_C,
 266+    /* { */ CCLASS_OTHER,    /* | */ CCLASS_OTHER,   /* } */ CCLASS_OTHER,
 267+    /* ~ */ CCLASS_OTHER,    /*   */ CCLASS_OTHER,
 268 };
 269 
 270 /*
 271@@ -189,54 +189,58 @@ **   * Omit K in KN or G in GN at the beginning of a word
 272 **
 273 ** Space to hold the result is obtained from sqlite3_malloc()
 274 **
 275-** Return NULL if memory allocation fails.  
 276+** Return NULL if memory allocation fails.
 277 */
 278-static unsigned char *phoneticHash(const unsigned char *zIn, int nIn){
 279-  unsigned char *zOut = sqlite3_malloc64( nIn + 1 );
 280-  int i;
 281-  int nOut = 0;
 282-  char cPrev = 0x77;
 283-  char cPrevX = 0x77;
 284-  const unsigned char *aClass = initClass;
 285+static unsigned char *phoneticHash(const unsigned char *zIn, int nIn)
 286+{
 287+    unsigned char *zOut = sqlite3_malloc64( nIn + 1 );
 288+    int i;
 289+    int nOut = 0;
 290+    char cPrev = 0x77;
 291+    char cPrevX = 0x77;
 292+    const unsigned char *aClass = initClass;
 293 
 294-  if( zOut==0 ) return 0;
 295-  if( nIn>2 ){
 296-    switch( zIn[0] ){
 297-      case 'g': 
 298-      case 'k': {
 299-        if( zIn[1]=='n' ){ zIn++; nIn--; }
 300-        break;
 301-      }
 302-    }
 303-  }
 304-  for(i=0; i<nIn; i++){
 305-    unsigned char c = zIn[i];
 306-    if( i+1<nIn ){
 307-      if( c=='w' && zIn[i+1]=='r' ) continue;
 308-      if( c=='d' && (zIn[i+1]=='j' || zIn[i+1]=='g') ) continue;
 309-      if( i+2<nIn ){
 310-        if( c=='t' && zIn[i+1]=='c' && zIn[i+2]=='h' ) continue;
 311-      }
 312-    }
 313-    c = aClass[c&0x7f];
 314-    if( c==CCLASS_SPACE ) continue;
 315-    if( c==CCLASS_OTHER && cPrev!=CCLASS_DIGIT ) continue;
 316-    aClass = midClass;
 317-    if( c==CCLASS_VOWEL && (cPrevX==CCLASS_R || cPrevX==CCLASS_L) ){
 318-       continue; /* No vowels beside L or R */ 
 319+    if( zOut==0 ) return 0;
 320+    if( nIn>2 ) {
 321+        switch( zIn[0] ) {
 322+        case 'g':
 323+        case 'k': {
 324+            if( zIn[1]=='n' ) {
 325+                zIn++;
 326+                nIn--;
 327+            }
 328+            break;
 329+        }
 330+        }
 331     }
 332-    if( (c==CCLASS_R || c==CCLASS_L) && cPrevX==CCLASS_VOWEL ){
 333-       nOut--;   /* No vowels beside L or R */
 334+    for(i=0; i<nIn; i++) {
 335+        unsigned char c = zIn[i];
 336+        if( i+1<nIn ) {
 337+            if( c=='w' && zIn[i+1]=='r' ) continue;
 338+            if( c=='d' && (zIn[i+1]=='j' || zIn[i+1]=='g') ) continue;
 339+            if( i+2<nIn ) {
 340+                if( c=='t' && zIn[i+1]=='c' && zIn[i+2]=='h' ) continue;
 341+            }
 342+        }
 343+        c = aClass[c&0x7f];
 344+        if( c==CCLASS_SPACE ) continue;
 345+        if( c==CCLASS_OTHER && cPrev!=CCLASS_DIGIT ) continue;
 346+        aClass = midClass;
 347+        if( c==CCLASS_VOWEL && (cPrevX==CCLASS_R || cPrevX==CCLASS_L) ) {
 348+            continue; /* No vowels beside L or R */
 349+        }
 350+        if( (c==CCLASS_R || c==CCLASS_L) && cPrevX==CCLASS_VOWEL ) {
 351+            nOut--;   /* No vowels beside L or R */
 352+        }
 353+        cPrev = c;
 354+        if( c==CCLASS_SILENT ) continue;
 355+        cPrevX = c;
 356+        c = className[c];
 357+        assert( nOut>=0 );
 358+        if( nOut==0 || c!=zOut[nOut-1] ) zOut[nOut++] = c;
 359     }
 360-    cPrev = c;
 361-    if( c==CCLASS_SILENT ) continue;
 362-    cPrevX = c;
 363-    c = className[c];
 364-    assert( nOut>=0 );
 365-    if( nOut==0 || c!=zOut[nOut-1] ) zOut[nOut++] = c;
 366-  }
 367-  zOut[nOut] = 0;
 368-  return zOut;
 369+    zOut[nOut] = 0;
 370+    return zOut;
 371 }
 372 
 373 /*
 374@@ -244,29 +248,31 @@ ** This is an SQL function wrapper around phoneticHash().  See
 375 ** the description of phoneticHash() for additional information.
 376 */
 377 static void phoneticHashSqlFunc(
 378-  sqlite3_context *context,
 379-  int argc,
 380-  sqlite3_value **argv
 381-){
 382-  const unsigned char *zIn;
 383-  unsigned char *zOut;
 384+    sqlite3_context *context,
 385+    int argc,
 386+    sqlite3_value **argv
 387+)
 388+{
 389+    const unsigned char *zIn;
 390+    unsigned char *zOut;
 391 
 392-  zIn = sqlite3_value_text(argv[0]);
 393-  if( zIn==0 ) return;
 394-  zOut = phoneticHash(zIn, sqlite3_value_bytes(argv[0]));
 395-  if( zOut==0 ){
 396-    sqlite3_result_error_nomem(context);
 397-  }else{
 398-    sqlite3_result_text(context, (char*)zOut, -1, sqlite3_free);
 399-  }
 400+    zIn = sqlite3_value_text(argv[0]);
 401+    if( zIn==0 ) return;
 402+    zOut = phoneticHash(zIn, sqlite3_value_bytes(argv[0]));
 403+    if( zOut==0 ) {
 404+        sqlite3_result_error_nomem(context);
 405+    } else {
 406+        sqlite3_result_text(context, (char*)zOut, -1, sqlite3_free);
 407+    }
 408 }
 409 
 410 /*
 411 ** Return the character class number for a character given its
 412 ** context.
 413 */
 414-static char characterClass(char cPrev, char c){
 415-  return cPrev==0 ? initClass[c&0x7f] : midClass[c&0x7f];
 416+static char characterClass(char cPrev, char c)
 417+{
 418+    return cPrev==0 ? initClass[c&0x7f] : midClass[c&0x7f];
 419 }
 420 
 421 /*
 422@@ -274,34 +280,35 @@ ** Return the cost of inserting or deleting character c immediately
 423 ** following character cPrev.  If cPrev==0, that means c is the first
 424 ** character of the word.
 425 */
 426-static int insertOrDeleteCost(char cPrev, char c, char cNext){
 427-  char classC = characterClass(cPrev, c);
 428-  char classCprev;
 429+static int insertOrDeleteCost(char cPrev, char c, char cNext)
 430+{
 431+    char classC = characterClass(cPrev, c);
 432+    char classCprev;
 433 
 434-  if( classC==CCLASS_SILENT ){
 435-    /* Insert or delete "silent" characters such as H or W */
 436-    return 1;
 437-  }
 438-  if( cPrev==c ){
 439-    /* Repeated characters, or miss a repeat */
 440-    return 10;
 441-  }
 442-  if( classC==CCLASS_VOWEL && (cPrev=='r' || cNext=='r') ){
 443-    return 20;  /* Insert a vowel before or after 'r' */
 444-  }
 445-  classCprev = characterClass(cPrev, cPrev);
 446-  if( classC==classCprev ){
 447-    if( classC==CCLASS_VOWEL ){
 448-      /* Remove or add a new vowel to a vowel cluster */
 449-      return 15;
 450-    }else{
 451-      /* Remove or add a consonant not in the same class */
 452-      return 50;
 453+    if( classC==CCLASS_SILENT ) {
 454+        /* Insert or delete "silent" characters such as H or W */
 455+        return 1;
 456     }
 457-  }
 458+    if( cPrev==c ) {
 459+        /* Repeated characters, or miss a repeat */
 460+        return 10;
 461+    }
 462+    if( classC==CCLASS_VOWEL && (cPrev=='r' || cNext=='r') ) {
 463+        return 20;  /* Insert a vowel before or after 'r' */
 464+    }
 465+    classCprev = characterClass(cPrev, cPrev);
 466+    if( classC==classCprev ) {
 467+        if( classC==CCLASS_VOWEL ) {
 468+            /* Remove or add a new vowel to a vowel cluster */
 469+            return 15;
 470+        } else {
 471+            /* Remove or add a consonant not in the same class */
 472+            return 50;
 473+        }
 474+    }
 475 
 476-  /* any other character insertion or deletion */
 477-  return 100;
 478+    /* any other character insertion or deletion */
 479+    return 100;
 480 }
 481 
 482 /*
 483@@ -315,29 +322,30 @@ ** Return the cost of substituting cTo in place of cFrom assuming
 484 ** the previous character is cPrev.  If cPrev==0 then cTo is the first
 485 ** character of the word.
 486 */
 487-static int substituteCost(char cPrev, char cFrom, char cTo){
 488-  char classFrom, classTo;
 489-  if( cFrom==cTo ){
 490-    /* Exact match */
 491-    return 0;
 492-  }
 493-  if( cFrom==(cTo^0x20) && ((cTo>='A' && cTo<='Z') || (cTo>='a' && cTo<='z')) ){
 494-    /* differ only in case */
 495-    return 0;
 496-  }
 497-  classFrom = characterClass(cPrev, cFrom);
 498-  classTo = characterClass(cPrev, cTo);
 499-  if( classFrom==classTo ){
 500-    /* Same character class */
 501-    return 40;
 502-  }
 503-  if( classFrom>=CCLASS_B && classFrom<=CCLASS_Y
 504-      && classTo>=CCLASS_B && classTo<=CCLASS_Y ){
 505-    /* Convert from one consonant to another, but in a different class */
 506-    return 75;
 507-  }
 508-  /* Any other subsitution */
 509-  return 100;
 510+static int substituteCost(char cPrev, char cFrom, char cTo)
 511+{
 512+    char classFrom, classTo;
 513+    if( cFrom==cTo ) {
 514+        /* Exact match */
 515+        return 0;
 516+    }
 517+    if( cFrom==(cTo^0x20) && ((cTo>='A' && cTo<='Z') || (cTo>='a' && cTo<='z')) ) {
 518+        /* differ only in case */
 519+        return 0;
 520+    }
 521+    classFrom = characterClass(cPrev, cFrom);
 522+    classTo = characterClass(cPrev, cTo);
 523+    if( classFrom==classTo ) {
 524+        /* Same character class */
 525+        return 40;
 526+    }
 527+    if( classFrom>=CCLASS_B && classFrom<=CCLASS_Y
 528+        && classTo>=CCLASS_B && classTo<=CCLASS_Y ) {
 529+        /* Convert from one consonant to another, but in a different class */
 530+        return 75;
 531+    }
 532+    /* Any other subsitution */
 533+    return 100;
 534 }
 535 
 536 /*
 537@@ -351,7 +359,7 @@ **
 538 ** Negative values indicate an error:
 539 **    -1  One of the inputs is NULL
 540 **    -2  Non-ASCII characters on input
 541-**    -3  Unable to allocate memory 
 542+**    -3  Unable to allocate memory
 543 **
 544 ** If pnMatch is not NULL, then *pnMatch is set to the number of bytes
 545 ** of zB that matched the pattern in zA. If zA does not end with a '*',
 546@@ -359,152 +367,158 @@ ** then this value is always the number of bytes in zB (i.e. strlen(zB)).
 547 ** If zA does end in a '*', then it is the number of bytes in the prefix
 548 ** of zB that was deemed to match zA.
 549 */
 550-static int editdist1(const char *zA, const char *zB, int *pnMatch){
 551-  int nA, nB;            /* Number of characters in zA[] and zB[] */
 552-  int xA, xB;            /* Loop counters for zA[] and zB[] */
 553-  char cA = 0, cB;       /* Current character of zA and zB */
 554-  char cAprev, cBprev;   /* Previous character of zA and zB */
 555-  char cAnext, cBnext;   /* Next character in zA and zB */
 556-  int d;                 /* North-west cost value */
 557-  int dc = 0;            /* North-west character value */
 558-  int res;               /* Final result */
 559-  int *m;                /* The cost matrix */
 560-  char *cx;              /* Corresponding character values */
 561-  int *toFree = 0;       /* Malloced space */
 562-  int nMatch = 0;
 563-  int mStack[60+15];     /* Stack space to use if not too much is needed */
 564+static int editdist1(const char *zA, const char *zB, int *pnMatch)
 565+{
 566+    int nA, nB;            /* Number of characters in zA[] and zB[] */
 567+    int xA, xB;            /* Loop counters for zA[] and zB[] */
 568+    char cA = 0, cB;       /* Current character of zA and zB */
 569+    char cAprev, cBprev;   /* Previous character of zA and zB */
 570+    char cAnext, cBnext;   /* Next character in zA and zB */
 571+    int d;                 /* North-west cost value */
 572+    int dc = 0;            /* North-west character value */
 573+    int res;               /* Final result */
 574+    int *m;                /* The cost matrix */
 575+    char *cx;              /* Corresponding character values */
 576+    int *toFree = 0;       /* Malloced space */
 577+    int nMatch = 0;
 578+    int mStack[60+15];     /* Stack space to use if not too much is needed */
 579 
 580-  /* Early out if either input is NULL */
 581-  if( zA==0 || zB==0 ) return -1;
 582+    /* Early out if either input is NULL */
 583+    if( zA==0 || zB==0 ) return -1;
 584 
 585-  /* Skip any common prefix */
 586-  while( zA[0] && zA[0]==zB[0] ){ dc = zA[0]; zA++; zB++; nMatch++; }
 587-  if( pnMatch ) *pnMatch = nMatch;
 588-  if( zA[0]==0 && zB[0]==0 ) return 0;
 589+    /* Skip any common prefix */
 590+    while( zA[0] && zA[0]==zB[0] ) {
 591+        dc = zA[0];
 592+        zA++;
 593+        zB++;
 594+        nMatch++;
 595+    }
 596+    if( pnMatch ) *pnMatch = nMatch;
 597+    if( zA[0]==0 && zB[0]==0 ) return 0;
 598 
 599 #if 0
 600-  printf("A=\"%s\" B=\"%s\" dc=%c\n", zA, zB, dc?dc:' ');
 601+    printf("A=\"%s\" B=\"%s\" dc=%c\n", zA, zB, dc?dc:' ');
 602 #endif
 603 
 604-  /* Verify input strings and measure their lengths */
 605-  for(nA=0; zA[nA]; nA++){
 606-    if( zA[nA]&0x80 ) return -2;
 607-  }
 608-  for(nB=0; zB[nB]; nB++){
 609-    if( zB[nB]&0x80 ) return -2;
 610-  }
 611+    /* Verify input strings and measure their lengths */
 612+    for(nA=0; zA[nA]; nA++) {
 613+        if( zA[nA]&0x80 ) return -2;
 614+    }
 615+    for(nB=0; zB[nB]; nB++) {
 616+        if( zB[nB]&0x80 ) return -2;
 617+    }
 618 
 619-  /* Special processing if either string is empty */
 620-  if( nA==0 ){
 621-    cBprev = (char)dc;
 622-    for(xB=res=0; (cB = zB[xB])!=0; xB++){
 623-      res += insertOrDeleteCost(cBprev, cB, zB[xB+1])/FINAL_INS_COST_DIV;
 624-      cBprev = cB;
 625+    /* Special processing if either string is empty */
 626+    if( nA==0 ) {
 627+        cBprev = (char)dc;
 628+        for(xB=res=0; (cB = zB[xB])!=0; xB++) {
 629+            res += insertOrDeleteCost(cBprev, cB, zB[xB+1])/FINAL_INS_COST_DIV;
 630+            cBprev = cB;
 631+        }
 632+        return res;
 633     }
 634-    return res;
 635-  }
 636-  if( nB==0 ){
 637-    cAprev = (char)dc;
 638-    for(xA=res=0; (cA = zA[xA])!=0; xA++){
 639-      res += insertOrDeleteCost(cAprev, cA, zA[xA+1]);
 640-      cAprev = cA;
 641+    if( nB==0 ) {
 642+        cAprev = (char)dc;
 643+        for(xA=res=0; (cA = zA[xA])!=0; xA++) {
 644+            res += insertOrDeleteCost(cAprev, cA, zA[xA+1]);
 645+            cAprev = cA;
 646+        }
 647+        return res;
 648     }
 649-    return res;
 650-  }
 651 
 652-  /* A is a prefix of B */
 653-  if( zA[0]=='*' && zA[1]==0 ) return 0;
 654+    /* A is a prefix of B */
 655+    if( zA[0]=='*' && zA[1]==0 ) return 0;
 656 
 657-  /* Allocate and initialize the Wagner matrix */
 658-  if( nB<(sizeof(mStack)*4)/(sizeof(mStack[0])*5) ){
 659-    m = mStack;
 660-  }else{
 661-    m = toFree = sqlite3_malloc64( (nB+1)*5*sizeof(m[0])/4 );
 662-    if( m==0 ) return -3;
 663-  }
 664-  cx = (char*)&m[nB+1];
 665+    /* Allocate and initialize the Wagner matrix */
 666+    if( nB<(sizeof(mStack)*4)/(sizeof(mStack[0])*5) ) {
 667+        m = mStack;
 668+    } else {
 669+        m = toFree = sqlite3_malloc64( (nB+1)*5*sizeof(m[0])/4 );
 670+        if( m==0 ) return -3;
 671+    }
 672+    cx = (char*)&m[nB+1];
 673 
 674-  /* Compute the Wagner edit distance */
 675-  m[0] = 0;
 676-  cx[0] = (char)dc;
 677-  cBprev = (char)dc;
 678-  for(xB=1; xB<=nB; xB++){
 679-    cBnext = zB[xB];
 680-    cB = zB[xB-1];
 681-    cx[xB] = cB;
 682-    m[xB] = m[xB-1] + insertOrDeleteCost(cBprev, cB, cBnext);
 683-    cBprev = cB;
 684-  }
 685-  cAprev = (char)dc;
 686-  for(xA=1; xA<=nA; xA++){
 687-    int lastA = (xA==nA);
 688-    cA = zA[xA-1];
 689-    cAnext = zA[xA];
 690-    if( cA=='*' && lastA ) break;
 691-    d = m[0];
 692-    dc = cx[0];
 693-    m[0] = d + insertOrDeleteCost(cAprev, cA, cAnext);
 694-    cBprev = 0;
 695-    for(xB=1; xB<=nB; xB++){
 696-      int totalCost, insCost, delCost, subCost, ncx;
 697-      cB = zB[xB-1];
 698-      cBnext = zB[xB];
 699+    /* Compute the Wagner edit distance */
 700+    m[0] = 0;
 701+    cx[0] = (char)dc;
 702+    cBprev = (char)dc;
 703+    for(xB=1; xB<=nB; xB++) {
 704+        cBnext = zB[xB];
 705+        cB = zB[xB-1];
 706+        cx[xB] = cB;
 707+        m[xB] = m[xB-1] + insertOrDeleteCost(cBprev, cB, cBnext);
 708+        cBprev = cB;
 709+    }
 710+    cAprev = (char)dc;
 711+    for(xA=1; xA<=nA; xA++) {
 712+        int lastA = (xA==nA);
 713+        cA = zA[xA-1];
 714+        cAnext = zA[xA];
 715+        if( cA=='*' && lastA ) break;
 716+        d = m[0];
 717+        dc = cx[0];
 718+        m[0] = d + insertOrDeleteCost(cAprev, cA, cAnext);
 719+        cBprev = 0;
 720+        for(xB=1; xB<=nB; xB++) {
 721+            int totalCost, insCost, delCost, subCost, ncx;
 722+            cB = zB[xB-1];
 723+            cBnext = zB[xB];
 724 
 725-      /* Cost to insert cB */
 726-      insCost = insertOrDeleteCost(cx[xB-1], cB, cBnext);
 727-      if( lastA ) insCost /= FINAL_INS_COST_DIV;
 728+            /* Cost to insert cB */
 729+            insCost = insertOrDeleteCost(cx[xB-1], cB, cBnext);
 730+            if( lastA ) insCost /= FINAL_INS_COST_DIV;
 731 
 732-      /* Cost to delete cA */
 733-      delCost = insertOrDeleteCost(cx[xB], cA, cBnext);
 734+            /* Cost to delete cA */
 735+            delCost = insertOrDeleteCost(cx[xB], cA, cBnext);
 736 
 737-      /* Cost to substitute cA->cB */
 738-      subCost = substituteCost(cx[xB-1], cA, cB);
 739+            /* Cost to substitute cA->cB */
 740+            subCost = substituteCost(cx[xB-1], cA, cB);
 741 
 742-      /* Best cost */
 743-      totalCost = insCost + m[xB-1];
 744-      ncx = cB;
 745-      if( (delCost + m[xB])<totalCost ){
 746-        totalCost = delCost + m[xB];
 747-        ncx = cA;
 748-      }
 749-      if( (subCost + d)<totalCost ){
 750-        totalCost = subCost + d;
 751-      }
 752+            /* Best cost */
 753+            totalCost = insCost + m[xB-1];
 754+            ncx = cB;
 755+            if( (delCost + m[xB])<totalCost ) {
 756+                totalCost = delCost + m[xB];
 757+                ncx = cA;
 758+            }
 759+            if( (subCost + d)<totalCost ) {
 760+                totalCost = subCost + d;
 761+            }
 762 
 763 #if 0
 764-      printf("%d,%d d=%4d u=%4d r=%4d dc=%c cA=%c cB=%c"
 765-             " ins=%4d del=%4d sub=%4d t=%4d ncx=%c\n",
 766-             xA, xB, d, m[xB], m[xB-1], dc?dc:' ', cA, cB,
 767-             insCost, delCost, subCost, totalCost, ncx?ncx:' ');
 768+            printf("%d,%d d=%4d u=%4d r=%4d dc=%c cA=%c cB=%c"
 769+                   " ins=%4d del=%4d sub=%4d t=%4d ncx=%c\n",
 770+                   xA, xB, d, m[xB], m[xB-1], dc?dc:' ', cA, cB,
 771+                   insCost, delCost, subCost, totalCost, ncx?ncx:' ');
 772 #endif
 773 
 774-      /* Update the matrix */
 775-      d = m[xB];
 776-      dc = cx[xB];
 777-      m[xB] = totalCost;
 778-      cx[xB] = (char)ncx;
 779-      cBprev = cB;
 780+            /* Update the matrix */
 781+            d = m[xB];
 782+            dc = cx[xB];
 783+            m[xB] = totalCost;
 784+            cx[xB] = (char)ncx;
 785+            cBprev = cB;
 786+        }
 787+        cAprev = cA;
 788     }
 789-    cAprev = cA;
 790-  }
 791 
 792-  /* Free the wagner matrix and return the result */
 793-  if( cA=='*' ){
 794-    res = m[1];
 795-    for(xB=1; xB<=nB; xB++){
 796-      if( m[xB]<res ){
 797-        res = m[xB];
 798-        if( pnMatch ) *pnMatch = xB+nMatch;
 799-      }
 800+    /* Free the wagner matrix and return the result */
 801+    if( cA=='*' ) {
 802+        res = m[1];
 803+        for(xB=1; xB<=nB; xB++) {
 804+            if( m[xB]<res ) {
 805+                res = m[xB];
 806+                if( pnMatch ) *pnMatch = xB+nMatch;
 807+            }
 808+        }
 809+    } else {
 810+        res = m[nB];
 811+        /* In the current implementation, pnMatch is always NULL if zA does
 812+        ** not end in "*" */
 813+        assert( pnMatch==0 );
 814     }
 815-  }else{
 816-    res = m[nB];
 817-    /* In the current implementation, pnMatch is always NULL if zA does
 818-    ** not end in "*" */
 819-    assert( pnMatch==0 );
 820-  }
 821-  sqlite3_free(toFree);
 822-  return res;
 823+    sqlite3_free(toFree);
 824+    return res;
 825 }
 826 
 827 /*
 828@@ -516,25 +530,26 @@ ** a prefix of B and extra characters on the end of B have minimal additional
 829 ** cost.
 830 */
 831 static void editdistSqlFunc(
 832-  sqlite3_context *context,
 833-  int argc,
 834-  sqlite3_value **argv
 835-){
 836-  int res = editdist1(
 837-                    (const char*)sqlite3_value_text(argv[0]),
 838-                    (const char*)sqlite3_value_text(argv[1]),
 839-                    0);
 840-  if( res<0 ){
 841-    if( res==(-3) ){
 842-      sqlite3_result_error_nomem(context);
 843-    }else if( res==(-2) ){
 844-      sqlite3_result_error(context, "non-ASCII input to editdist()", -1);
 845-    }else{
 846-      sqlite3_result_error(context, "NULL input to editdist()", -1);
 847+    sqlite3_context *context,
 848+    int argc,
 849+    sqlite3_value **argv
 850+)
 851+{
 852+    int res = editdist1(
 853+                  (const char*)sqlite3_value_text(argv[0]),
 854+                  (const char*)sqlite3_value_text(argv[1]),
 855+                  0);
 856+    if( res<0 ) {
 857+        if( res==(-3) ) {
 858+            sqlite3_result_error_nomem(context);
 859+        } else if( res==(-2) ) {
 860+            sqlite3_result_error(context, "non-ASCII input to editdist()", -1);
 861+        } else {
 862+            sqlite3_result_error(context, "NULL input to editdist()", -1);
 863+        }
 864+    } else {
 865+        sqlite3_result_int(context, res);
 866     }
 867-  }else{ 
 868-    sqlite3_result_int(context, res);
 869-  }
 870 }
 871 
 872 /* End of the fixed-cost edit distance implementation
 873@@ -552,30 +567,28 @@ typedef struct EditDist3To EditDist3To;
 874 typedef struct EditDist3ToString EditDist3ToString;
 875 typedef struct EditDist3Lang EditDist3Lang;
 876 
 877-
 878 /*
 879 ** An entry in the edit cost table
 880 */
 881 struct EditDist3Cost {
 882-  EditDist3Cost *pNext;     /* Next cost element */
 883-  u8 nFrom;                 /* Number of bytes in aFrom */
 884-  u8 nTo;                   /* Number of bytes in aTo */
 885-  u16 iCost;                /* Cost of this transformation */
 886-  char a[4]    ;            /* FROM string followed by TO string */
 887-  /* Additional TO and FROM string bytes appended as necessary */
 888+    EditDist3Cost *pNext;     /* Next cost element */
 889+    u8 nFrom;                 /* Number of bytes in aFrom */
 890+    u8 nTo;                   /* Number of bytes in aTo */
 891+    u16 iCost;                /* Cost of this transformation */
 892+    char a[4]    ;            /* FROM string followed by TO string */
 893+    /* Additional TO and FROM string bytes appended as necessary */
 894 };
 895 
 896 /*
 897-** Edit costs for a particular language ID 
 898+** Edit costs for a particular language ID
 899 */
 900 struct EditDist3Lang {
 901-  int iLang;             /* Language ID */
 902-  int iInsCost;          /* Default insertion cost */
 903-  int iDelCost;          /* Default deletion cost */
 904-  int iSubCost;          /* Default substitution cost */
 905-  EditDist3Cost *pCost;  /* Costs */
 906+    int iLang;             /* Language ID */
 907+    int iInsCost;          /* Default insertion cost */
 908+    int iDelCost;          /* Default deletion cost */
 909+    int iSubCost;          /* Default substitution cost */
 910+    EditDist3Cost *pCost;  /* Costs */
 911 };
 912-
 913 
 914 /*
 915 ** The default EditDist3Lang object, with default costs.
 916@@ -586,19 +599,19 @@ /*
 917 ** Complete configuration
 918 */
 919 struct EditDist3Config {
 920-  int nLang;             /* Number of language IDs.  Size of a[] */
 921-  EditDist3Lang *a;      /* One for each distinct language ID */
 922+    int nLang;             /* Number of language IDs.  Size of a[] */
 923+    EditDist3Lang *a;      /* One for each distinct language ID */
 924 };
 925 
 926 /*
 927 ** Extra information about each character in the FROM string.
 928 */
 929 struct EditDist3From {
 930-  int nSubst;              /* Number of substitution cost entries */
 931-  int nDel;                /* Number of deletion cost entries */
 932-  int nByte;               /* Number of bytes in this character */
 933-  EditDist3Cost **apSubst; /* Array of substitution costs for this element */
 934-  EditDist3Cost **apDel;   /* Array of deletion cost entries */
 935+    int nSubst;              /* Number of substitution cost entries */
 936+    int nDel;                /* Number of deletion cost entries */
 937+    int nByte;               /* Number of bytes in this character */
 938+    EditDist3Cost **apSubst; /* Array of substitution costs for this element */
 939+    EditDist3Cost **apDel;   /* Array of deletion cost entries */
 940 };
 941 
 942 /*
 943@@ -609,66 +622,69 @@ ** In other words, the common case will be to measure the edit distance
 944 ** from a single origin string to multiple target strings.
 945 */
 946 struct EditDist3FromString {
 947-  char *z;                 /* The complete text of the FROM string */
 948-  int n;                   /* Number of characters in the FROM string */
 949-  int isPrefix;            /* True if ends with '*' character */
 950-  EditDist3From *a;        /* Extra info about each char of the FROM string */
 951+    char *z;                 /* The complete text of the FROM string */
 952+    int n;                   /* Number of characters in the FROM string */
 953+    int isPrefix;            /* True if ends with '*' character */
 954+    EditDist3From *a;        /* Extra info about each char of the FROM string */
 955 };
 956 
 957 /*
 958 ** Extra information about each character in the TO string.
 959 */
 960 struct EditDist3To {
 961-  int nIns;                /* Number of insertion cost entries */
 962-  int nByte;               /* Number of bytes in this character */
 963-  EditDist3Cost **apIns;   /* Array of deletion cost entries */
 964+    int nIns;                /* Number of insertion cost entries */
 965+    int nByte;               /* Number of bytes in this character */
 966+    EditDist3Cost **apIns;   /* Array of deletion cost entries */
 967 };
 968 
 969 /*
 970 ** A precompiled FROM string
 971 */
 972 struct EditDist3ToString {
 973-  char *z;                 /* The complete text of the TO string */
 974-  int n;                   /* Number of characters in the TO string */
 975-  EditDist3To *a;          /* Extra info about each char of the TO string */
 976+    char *z;                 /* The complete text of the TO string */
 977+    int n;                   /* Number of characters in the TO string */
 978+    EditDist3To *a;          /* Extra info about each char of the TO string */
 979 };
 980 
 981 /*
 982 ** Clear or delete an instance of the object that records all edit-distance
 983 ** weights.
 984 */
 985-static void editDist3ConfigClear(EditDist3Config *p){
 986-  int i;
 987-  if( p==0 ) return;
 988-  for(i=0; i<p->nLang; i++){
 989-    EditDist3Cost *pCost, *pNext;
 990-    pCost = p->a[i].pCost;
 991-    while( pCost ){
 992-      pNext = pCost->pNext;
 993-      sqlite3_free(pCost);
 994-      pCost = pNext;
 995+static void editDist3ConfigClear(EditDist3Config *p)
 996+{
 997+    int i;
 998+    if( p==0 ) return;
 999+    for(i=0; i<p->nLang; i++) {
1000+        EditDist3Cost *pCost, *pNext;
1001+        pCost = p->a[i].pCost;
1002+        while( pCost ) {
1003+            pNext = pCost->pNext;
1004+            sqlite3_free(pCost);
1005+            pCost = pNext;
1006+        }
1007     }
1008-  }
1009-  sqlite3_free(p->a);
1010-  memset(p, 0, sizeof(*p));
1011+    sqlite3_free(p->a);
1012+    memset(p, 0, sizeof(*p));
1013 }
1014-static void editDist3ConfigDelete(void *pIn){
1015-  EditDist3Config *p = (EditDist3Config*)pIn;
1016-  editDist3ConfigClear(p);
1017-  sqlite3_free(p);
1018+static void editDist3ConfigDelete(void *pIn)
1019+{
1020+    EditDist3Config *p = (EditDist3Config*)pIn;
1021+    editDist3ConfigClear(p);
1022+    sqlite3_free(p);
1023 }
1024 
1025 /* Compare the FROM values of two EditDist3Cost objects, for sorting.
1026 ** Return negative, zero, or positive if the A is less than, equal to,
1027 ** or greater than B.
1028 */
1029-static int editDist3CostCompare(EditDist3Cost *pA, EditDist3Cost *pB){
1030-  int n = pA->nFrom;
1031-  int rc;
1032-  if( n>pB->nFrom ) n = pB->nFrom;
1033-  rc = strncmp(pA->a, pB->a, n);
1034-  if( rc==0 ) rc = pA->nFrom - pB->nFrom;
1035-  return rc;
1036+static int editDist3CostCompare(EditDist3Cost *pA, EditDist3Cost *pB)
1037+{
1038+    int n = pA->nFrom;
1039+    int rc;
1040+    if( n>pB->nFrom ) n = pB->nFrom;
1041+    rc = strncmp(pA->a, pB->a, n);
1042+    if( rc==0 ) rc = pA->nFrom - pB->nFrom;
1043+    return rc;
1044 }
1045 
1046 /*
1047@@ -676,183 +692,195 @@ ** Merge together two sorted lists of EditDist3Cost objects, in order
1048 ** of increasing FROM.
1049 */
1050 static EditDist3Cost *editDist3CostMerge(
1051-  EditDist3Cost *pA,
1052-  EditDist3Cost *pB
1053-){
1054-  EditDist3Cost *pHead = 0;
1055-  EditDist3Cost **ppTail = &pHead;
1056-  EditDist3Cost *p;
1057-  while( pA && pB ){
1058-    if( editDist3CostCompare(pA,pB)<=0 ){
1059-      p = pA;
1060-      pA = pA->pNext;
1061-    }else{
1062-      p = pB;
1063-      pB = pB->pNext;
1064+    EditDist3Cost *pA,
1065+    EditDist3Cost *pB
1066+)
1067+{
1068+    EditDist3Cost *pHead = 0;
1069+    EditDist3Cost **ppTail = &pHead;
1070+    EditDist3Cost *p;
1071+    while( pA && pB ) {
1072+        if( editDist3CostCompare(pA,pB)<=0 ) {
1073+            p = pA;
1074+            pA = pA->pNext;
1075+        } else {
1076+            p = pB;
1077+            pB = pB->pNext;
1078+        }
1079+        *ppTail = p;
1080+        ppTail =  &p->pNext;
1081+    }
1082+    if( pA ) {
1083+        *ppTail = pA;
1084+    } else {
1085+        *ppTail = pB;
1086     }
1087-    *ppTail = p;
1088-    ppTail =  &p->pNext;
1089-  }
1090-  if( pA ){
1091-    *ppTail = pA;
1092-  }else{
1093-    *ppTail = pB;
1094-  }
1095-  return pHead;
1096+    return pHead;
1097 }
1098 
1099 /*
1100 ** Sort a list of EditDist3Cost objects into order of increasing FROM
1101 */
1102-static EditDist3Cost *editDist3CostSort(EditDist3Cost *pList){
1103-  EditDist3Cost *ap[60], *p;
1104-  int i;
1105-  int mx = 0;
1106-  ap[0] = 0;
1107-  ap[1] = 0;
1108-  while( pList ){
1109-    p = pList;
1110-    pList = p->pNext;
1111-    p->pNext = 0;
1112-    for(i=0; ap[i]; i++){
1113-      p = editDist3CostMerge(ap[i],p);
1114-      ap[i] = 0;
1115+static EditDist3Cost *editDist3CostSort(EditDist3Cost *pList)
1116+{
1117+    EditDist3Cost *ap[60], *p;
1118+    int i;
1119+    int mx = 0;
1120+    ap[0] = 0;
1121+    ap[1] = 0;
1122+    while( pList ) {
1123+        p = pList;
1124+        pList = p->pNext;
1125+        p->pNext = 0;
1126+        for(i=0; ap[i]; i++) {
1127+            p = editDist3CostMerge(ap[i],p);
1128+            ap[i] = 0;
1129+        }
1130+        ap[i] = p;
1131+        if( i>mx ) {
1132+            mx = i;
1133+            ap[i+1] = 0;
1134+        }
1135     }
1136-    ap[i] = p;
1137-    if( i>mx ){
1138-      mx = i;
1139-      ap[i+1] = 0;
1140+    p = 0;
1141+    for(i=0; i<=mx; i++) {
1142+        if( ap[i] ) p = editDist3CostMerge(p,ap[i]);
1143     }
1144-  }
1145-  p = 0;
1146-  for(i=0; i<=mx; i++){
1147-    if( ap[i] ) p = editDist3CostMerge(p,ap[i]);
1148-  }
1149-  return p;
1150+    return p;
1151 }
1152 
1153 /*
1154 ** Load all edit-distance weights from a table.
1155 */
1156 static int editDist3ConfigLoad(
1157-  EditDist3Config *p,      /* The edit distance configuration to load */
1158-  sqlite3 *db,            /* Load from this database */
1159-  const char *zTable      /* Name of the table from which to load */
1160-){
1161-  sqlite3_stmt *pStmt;
1162-  int rc, rc2;
1163-  char *zSql;
1164-  int iLangPrev = -9999;
1165-  EditDist3Lang *pLang = 0;
1166+    EditDist3Config *p,      /* The edit distance configuration to load */
1167+    sqlite3 *db,            /* Load from this database */
1168+    const char *zTable      /* Name of the table from which to load */
1169+)
1170+{
1171+    sqlite3_stmt *pStmt;
1172+    int rc, rc2;
1173+    char *zSql;
1174+    int iLangPrev = -9999;
1175+    EditDist3Lang *pLang = 0;
1176 
1177-  zSql = sqlite3_mprintf("SELECT iLang, cFrom, cTo, iCost"
1178-                         " FROM \"%w\" WHERE iLang>=0 ORDER BY iLang", zTable);
1179-  if( zSql==0 ) return SQLITE_NOMEM;
1180-  rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
1181-  sqlite3_free(zSql);
1182-  if( rc ) return rc;
1183-  editDist3ConfigClear(p);
1184-  while( sqlite3_step(pStmt)==SQLITE_ROW ){
1185-    int iLang = sqlite3_column_int(pStmt, 0);
1186-    const char *zFrom = (const char*)sqlite3_column_text(pStmt, 1);
1187-    int nFrom = zFrom ? sqlite3_column_bytes(pStmt, 1) : 0;
1188-    const char *zTo = (const char*)sqlite3_column_text(pStmt, 2);
1189-    int nTo = zTo ? sqlite3_column_bytes(pStmt, 2) : 0;
1190-    int iCost = sqlite3_column_int(pStmt, 3);
1191+    zSql = sqlite3_mprintf("SELECT iLang, cFrom, cTo, iCost"
1192+                           " FROM \"%w\" WHERE iLang>=0 ORDER BY iLang", zTable);
1193+    if( zSql==0 ) return SQLITE_NOMEM;
1194+    rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
1195+    sqlite3_free(zSql);
1196+    if( rc ) return rc;
1197+    editDist3ConfigClear(p);
1198+    while( sqlite3_step(pStmt)==SQLITE_ROW ) {
1199+        int iLang = sqlite3_column_int(pStmt, 0);
1200+        const char *zFrom = (const char*)sqlite3_column_text(pStmt, 1);
1201+        int nFrom = zFrom ? sqlite3_column_bytes(pStmt, 1) : 0;
1202+        const char *zTo = (const char*)sqlite3_column_text(pStmt, 2);
1203+        int nTo = zTo ? sqlite3_column_bytes(pStmt, 2) : 0;
1204+        int iCost = sqlite3_column_int(pStmt, 3);
1205 
1206-    assert( zFrom!=0 || nFrom==0 );
1207-    assert( zTo!=0 || nTo==0 );
1208-    if( nFrom>100 || nTo>100 ) continue;
1209-    if( iCost<0 ) continue;
1210-    if( iCost>=10000 ) continue;  /* Costs above 10K are considered infinite */
1211-    if( pLang==0 || iLang!=iLangPrev ){
1212-      EditDist3Lang *pNew;
1213-      pNew = sqlite3_realloc64(p->a, (p->nLang+1)*sizeof(p->a[0]));
1214-      if( pNew==0 ){ rc = SQLITE_NOMEM; break; }
1215-      p->a = pNew;
1216-      pLang = &p->a[p->nLang];
1217-      p->nLang++;
1218-      pLang->iLang = iLang;
1219-      pLang->iInsCost = 100;
1220-      pLang->iDelCost = 100;
1221-      pLang->iSubCost = 150;
1222-      pLang->pCost = 0;
1223-      iLangPrev = iLang;
1224+        assert( zFrom!=0 || nFrom==0 );
1225+        assert( zTo!=0 || nTo==0 );
1226+        if( nFrom>100 || nTo>100 ) continue;
1227+        if( iCost<0 ) continue;
1228+        if( iCost>=10000 ) continue;  /* Costs above 10K are considered infinite */
1229+        if( pLang==0 || iLang!=iLangPrev ) {
1230+            EditDist3Lang *pNew;
1231+            pNew = sqlite3_realloc64(p->a, (p->nLang+1)*sizeof(p->a[0]));
1232+            if( pNew==0 ) {
1233+                rc = SQLITE_NOMEM;
1234+                break;
1235+            }
1236+            p->a = pNew;
1237+            pLang = &p->a[p->nLang];
1238+            p->nLang++;
1239+            pLang->iLang = iLang;
1240+            pLang->iInsCost = 100;
1241+            pLang->iDelCost = 100;
1242+            pLang->iSubCost = 150;
1243+            pLang->pCost = 0;
1244+            iLangPrev = iLang;
1245+        }
1246+        if( nFrom==1 && zFrom[0]=='?' && nTo==0 ) {
1247+            pLang->iDelCost = iCost;
1248+        } else if( nFrom==0 && nTo==1 && zTo[0]=='?' ) {
1249+            pLang->iInsCost = iCost;
1250+        } else if( nFrom==1 && nTo==1 && zFrom[0]=='?' && zTo[0]=='?' ) {
1251+            pLang->iSubCost = iCost;
1252+        } else {
1253+            EditDist3Cost *pCost;
1254+            int nExtra = nFrom + nTo - 4;
1255+            if( nExtra<0 ) nExtra = 0;
1256+            pCost = sqlite3_malloc64( sizeof(*pCost) + nExtra );
1257+            if( pCost==0 ) {
1258+                rc = SQLITE_NOMEM;
1259+                break;
1260+            }
1261+            pCost->nFrom = (u8)nFrom;
1262+            pCost->nTo = (u8)nTo;
1263+            pCost->iCost = (u16)iCost;
1264+            memcpy(pCost->a, zFrom, nFrom);
1265+            memcpy(pCost->a + nFrom, zTo, nTo);
1266+            pCost->pNext = pLang->pCost;
1267+            pLang->pCost = pCost;
1268+        }
1269     }
1270-    if( nFrom==1 && zFrom[0]=='?' && nTo==0 ){
1271-      pLang->iDelCost = iCost;
1272-    }else if( nFrom==0 && nTo==1 && zTo[0]=='?' ){
1273-      pLang->iInsCost = iCost;
1274-    }else if( nFrom==1 && nTo==1 && zFrom[0]=='?' && zTo[0]=='?' ){
1275-      pLang->iSubCost = iCost;
1276-    }else{
1277-      EditDist3Cost *pCost;
1278-      int nExtra = nFrom + nTo - 4;
1279-      if( nExtra<0 ) nExtra = 0;
1280-      pCost = sqlite3_malloc64( sizeof(*pCost) + nExtra );
1281-      if( pCost==0 ){ rc = SQLITE_NOMEM; break; }
1282-      pCost->nFrom = (u8)nFrom;
1283-      pCost->nTo = (u8)nTo;
1284-      pCost->iCost = (u16)iCost;
1285-      memcpy(pCost->a, zFrom, nFrom);
1286-      memcpy(pCost->a + nFrom, zTo, nTo);
1287-      pCost->pNext = pLang->pCost;
1288-      pLang->pCost = pCost; 
1289-    }
1290-  }
1291-  rc2 = sqlite3_finalize(pStmt);
1292-  if( rc==SQLITE_OK ) rc = rc2;
1293-  if( rc==SQLITE_OK ){
1294-    int iLang;
1295-    for(iLang=0; iLang<p->nLang; iLang++){
1296-      p->a[iLang].pCost = editDist3CostSort(p->a[iLang].pCost);
1297+    rc2 = sqlite3_finalize(pStmt);
1298+    if( rc==SQLITE_OK ) rc = rc2;
1299+    if( rc==SQLITE_OK ) {
1300+        int iLang;
1301+        for(iLang=0; iLang<p->nLang; iLang++) {
1302+            p->a[iLang].pCost = editDist3CostSort(p->a[iLang].pCost);
1303+        }
1304     }
1305-  }
1306-  return rc;
1307+    return rc;
1308 }
1309 
1310 /*
1311 ** Return the length (in bytes) of a utf-8 character.  Or return a maximum
1312 ** of N.
1313 */
1314-static int utf8Len(unsigned char c, int N){
1315-  int len = 1;
1316-  if( c>0x7f ){
1317-    if( (c&0xe0)==0xc0 ){
1318-      len = 2;
1319-    }else if( (c&0xf0)==0xe0 ){
1320-      len = 3;
1321-    }else{
1322-      len = 4;
1323+static int utf8Len(unsigned char c, int N)
1324+{
1325+    int len = 1;
1326+    if( c>0x7f ) {
1327+        if( (c&0xe0)==0xc0 ) {
1328+            len = 2;
1329+        } else if( (c&0xf0)==0xe0 ) {
1330+            len = 3;
1331+        } else {
1332+            len = 4;
1333+        }
1334     }
1335-  }
1336-  if( len>N ) len = N;
1337-  return len;
1338+    if( len>N ) len = N;
1339+    return len;
1340 }
1341 
1342 /*
1343 ** Return TRUE (non-zero) if the To side of the given cost matches
1344 ** the given string.
1345 */
1346-static int matchTo(EditDist3Cost *p, const char *z, int n){
1347-  assert( n>0 );
1348-  if( p->a[p->nFrom]!=z[0] ) return 0;
1349-  if( p->nTo>n ) return 0;
1350-  if( strncmp(p->a+p->nFrom, z, p->nTo)!=0 ) return 0;
1351-  return 1;
1352+static int matchTo(EditDist3Cost *p, const char *z, int n)
1353+{
1354+    assert( n>0 );
1355+    if( p->a[p->nFrom]!=z[0] ) return 0;
1356+    if( p->nTo>n ) return 0;
1357+    if( strncmp(p->a+p->nFrom, z, p->nTo)!=0 ) return 0;
1358+    return 1;
1359 }
1360 
1361 /*
1362 ** Return TRUE (non-zero) if the From side of the given cost matches
1363 ** the given string.
1364 */
1365-static int matchFrom(EditDist3Cost *p, const char *z, int n){
1366-  assert( p->nFrom<=n );
1367-  if( p->nFrom ){
1368-    if( p->a[0]!=z[0] ) return 0;
1369-    if( strncmp(p->a, z, p->nFrom)!=0 ) return 0;
1370-  }
1371-  return 1;
1372+static int matchFrom(EditDist3Cost *p, const char *z, int n)
1373+{
1374+    assert( p->nFrom<=n );
1375+    if( p->nFrom ) {
1376+        if( p->a[0]!=z[0] ) return 0;
1377+        if( strncmp(p->a, z, p->nFrom)!=0 ) return 0;
1378+    }
1379+    return 1;
1380 }
1381 
1382 /*
1383@@ -860,92 +888,95 @@ ** Return TRUE (non-zero) of the next FROM character and the next TO
1384 ** character are the same.
1385 */
1386 static int matchFromTo(
1387-  EditDist3FromString *pStr,  /* Left hand string */
1388-  int n1,                     /* Index of comparison character on the left */
1389-  const char *z2,             /* Right-handl comparison character */
1390-  int n2                      /* Bytes remaining in z2[] */
1391-){
1392-  int b1 = pStr->a[n1].nByte;
1393-  if( b1>n2 ) return 0;
1394-  assert( b1>0 );
1395-  if( pStr->z[n1]!=z2[0] ) return 0;
1396-  if( strncmp(pStr->z+n1, z2, b1)!=0 ) return 0;
1397-  return 1;
1398+    EditDist3FromString *pStr,  /* Left hand string */
1399+    int n1,                     /* Index of comparison character on the left */
1400+    const char *z2,             /* Right-handl comparison character */
1401+    int n2                      /* Bytes remaining in z2[] */
1402+)
1403+{
1404+    int b1 = pStr->a[n1].nByte;
1405+    if( b1>n2 ) return 0;
1406+    assert( b1>0 );
1407+    if( pStr->z[n1]!=z2[0] ) return 0;
1408+    if( strncmp(pStr->z+n1, z2, b1)!=0 ) return 0;
1409+    return 1;
1410 }
1411 
1412 /*
1413 ** Delete an EditDist3FromString objecct
1414 */
1415-static void editDist3FromStringDelete(EditDist3FromString *p){
1416-  int i;
1417-  if( p ){
1418-    for(i=0; i<p->n; i++){
1419-      sqlite3_free(p->a[i].apDel);
1420-      sqlite3_free(p->a[i].apSubst);
1421+static void editDist3FromStringDelete(EditDist3FromString *p)
1422+{
1423+    int i;
1424+    if( p ) {
1425+        for(i=0; i<p->n; i++) {
1426+            sqlite3_free(p->a[i].apDel);
1427+            sqlite3_free(p->a[i].apSubst);
1428+        }
1429+        sqlite3_free(p);
1430     }
1431-    sqlite3_free(p);
1432-  }
1433 }
1434 
1435 /*
1436 ** Create a EditDist3FromString object.
1437 */
1438 static EditDist3FromString *editDist3FromStringNew(
1439-  const EditDist3Lang *pLang,
1440-  const char *z,
1441-  int n
1442-){
1443-  EditDist3FromString *pStr;
1444-  EditDist3Cost *p;
1445-  int i;
1446-
1447-  if( z==0 ) return 0;
1448-  if( n<0 ) n = (int)strlen(z);
1449-  pStr = sqlite3_malloc64( sizeof(*pStr) + sizeof(pStr->a[0])*n + n + 1 );
1450-  if( pStr==0 ) return 0;
1451-  pStr->a = (EditDist3From*)&pStr[1];
1452-  memset(pStr->a, 0, sizeof(pStr->a[0])*n);
1453-  pStr->n = n;
1454-  pStr->z = (char*)&pStr->a[n];
1455-  memcpy(pStr->z, z, n+1);
1456-  if( n && z[n-1]=='*' ){
1457-    pStr->isPrefix = 1;
1458-    n--;
1459-    pStr->n--;
1460-    pStr->z[n] = 0;
1461-  }else{
1462-    pStr->isPrefix = 0;
1463-  }
1464+    const EditDist3Lang *pLang,
1465+    const char *z,
1466+    int n
1467+)
1468+{
1469+    EditDist3FromString *pStr;
1470+    EditDist3Cost *p;
1471+    int i;
1472 
1473-  for(i=0; i<n; i++){
1474-    EditDist3From *pFrom = &pStr->a[i];
1475-    memset(pFrom, 0, sizeof(*pFrom));
1476-    pFrom->nByte = utf8Len((unsigned char)z[i], n-i);
1477-    for(p=pLang->pCost; p; p=p->pNext){
1478-      EditDist3Cost **apNew;
1479-      if( i+p->nFrom>n ) continue;
1480-      if( matchFrom(p, z+i, n-i)==0 ) continue;
1481-      if( p->nTo==0 ){
1482-        apNew = sqlite3_realloc64(pFrom->apDel,
1483-                                sizeof(*apNew)*(pFrom->nDel+1));
1484-        if( apNew==0 ) break;
1485-        pFrom->apDel = apNew;
1486-        apNew[pFrom->nDel++] = p;
1487-      }else{
1488-        apNew = sqlite3_realloc64(pFrom->apSubst,
1489-                                sizeof(*apNew)*(pFrom->nSubst+1));
1490-        if( apNew==0 ) break;
1491-        pFrom->apSubst = apNew;
1492-        apNew[pFrom->nSubst++] = p;
1493-      }
1494+    if( z==0 ) return 0;
1495+    if( n<0 ) n = (int)strlen(z);
1496+    pStr = sqlite3_malloc64( sizeof(*pStr) + sizeof(pStr->a[0])*n + n + 1 );
1497+    if( pStr==0 ) return 0;
1498+    pStr->a = (EditDist3From*)&pStr[1];
1499+    memset(pStr->a, 0, sizeof(pStr->a[0])*n);
1500+    pStr->n = n;
1501+    pStr->z = (char*)&pStr->a[n];
1502+    memcpy(pStr->z, z, n+1);
1503+    if( n && z[n-1]=='*' ) {
1504+        pStr->isPrefix = 1;
1505+        n--;
1506+        pStr->n--;
1507+        pStr->z[n] = 0;
1508+    } else {
1509+        pStr->isPrefix = 0;
1510     }
1511-    if( p ){
1512-      editDist3FromStringDelete(pStr);
1513-      pStr = 0;
1514-      break;
1515+
1516+    for(i=0; i<n; i++) {
1517+        EditDist3From *pFrom = &pStr->a[i];
1518+        memset(pFrom, 0, sizeof(*pFrom));
1519+        pFrom->nByte = utf8Len((unsigned char)z[i], n-i);
1520+        for(p=pLang->pCost; p; p=p->pNext) {
1521+            EditDist3Cost **apNew;
1522+            if( i+p->nFrom>n ) continue;
1523+            if( matchFrom(p, z+i, n-i)==0 ) continue;
1524+            if( p->nTo==0 ) {
1525+                apNew = sqlite3_realloc64(pFrom->apDel,
1526+                                          sizeof(*apNew)*(pFrom->nDel+1));
1527+                if( apNew==0 ) break;
1528+                pFrom->apDel = apNew;
1529+                apNew[pFrom->nDel++] = p;
1530+            } else {
1531+                apNew = sqlite3_realloc64(pFrom->apSubst,
1532+                                          sizeof(*apNew)*(pFrom->nSubst+1));
1533+                if( apNew==0 ) break;
1534+                pFrom->apSubst = apNew;
1535+                apNew[pFrom->nSubst++] = p;
1536+            }
1537+        }
1538+        if( p ) {
1539+            editDist3FromStringDelete(pStr);
1540+            pStr = 0;
1541+            break;
1542+        }
1543     }
1544-  }
1545-  return pStr;
1546+    return pStr;
1547 }
1548 
1549 /*
1550@@ -953,20 +984,21 @@ ** Update entry m[i] such that it is the minimum of its current value
1551 ** and m[j]+iCost.
1552 */
1553 static void updateCost(
1554-  unsigned int *m,
1555-  int i,
1556-  int j,
1557-  int iCost
1558-){
1559-  unsigned int b;
1560-  assert( iCost>=0 );
1561-  assert( iCost<10000 );
1562-  b = m[j] + iCost;
1563-  if( b<m[i] ) m[i] = b;
1564+    unsigned int *m,
1565+    int i,
1566+    int j,
1567+    int iCost
1568+)
1569+{
1570+    unsigned int b;
1571+    assert( iCost>=0 );
1572+    assert( iCost<10000 );
1573+    b = m[j] + iCost;
1574+    if( b<m[i] ) m[i] = b;
1575 }
1576 
1577 /*
1578-** How much stack space (int bytes) to use for Wagner matrix in 
1579+** How much stack space (int bytes) to use for Wagner matrix in
1580 ** editDist3Core().  If more space than this is required, the entire
1581 ** matrix is taken from the heap.  To reduce the load on the memory
1582 ** allocator, make this value as large as practical for the
1583@@ -984,178 +1016,180 @@ ** If pnMatch is not NULL, then *pnMatch is set to the number of characters
1584 ** (not bytes) in z2 that matched the search pattern in *pFrom. If pFrom does
1585 ** not contain the pattern for a prefix-search, then this is always the number
1586 ** of characters in z2. If pFrom does contain a prefix search pattern, then
1587-** it is the number of characters in the prefix of z2 that was deemed to 
1588+** it is the number of characters in the prefix of z2 that was deemed to
1589 ** match pFrom.
1590 */
1591 static int editDist3Core(
1592-  EditDist3FromString *pFrom,  /* The FROM string */
1593-  const char *z2,              /* The TO string */
1594-  int n2,                      /* Length of the TO string */
1595-  const EditDist3Lang *pLang,  /* Edit weights for a particular language ID */
1596-  int *pnMatch                 /* OUT: Characters in matched prefix */
1597-){
1598-  int k, n;
1599-  int i1, b1;
1600-  int i2, b2;
1601-  EditDist3FromString f = *pFrom;
1602-  EditDist3To *a2;
1603-  unsigned int *m;
1604-  unsigned int *pToFree;
1605-  int szRow;
1606-  EditDist3Cost *p;
1607-  int res;
1608-  sqlite3_uint64 nByte;
1609-  unsigned int stackSpace[SQLITE_SPELLFIX_STACKALLOC_SZ/sizeof(unsigned int)];
1610+    EditDist3FromString *pFrom,  /* The FROM string */
1611+    const char *z2,              /* The TO string */
1612+    int n2,                      /* Length of the TO string */
1613+    const EditDist3Lang *pLang,  /* Edit weights for a particular language ID */
1614+    int *pnMatch                 /* OUT: Characters in matched prefix */
1615+)
1616+{
1617+    int k, n;
1618+    int i1, b1;
1619+    int i2, b2;
1620+    EditDist3FromString f = *pFrom;
1621+    EditDist3To *a2;
1622+    unsigned int *m;
1623+    unsigned int *pToFree;
1624+    int szRow;
1625+    EditDist3Cost *p;
1626+    int res;
1627+    sqlite3_uint64 nByte;
1628+    unsigned int stackSpace[SQLITE_SPELLFIX_STACKALLOC_SZ/sizeof(unsigned int)];
1629 
1630-  /* allocate the Wagner matrix and the aTo[] array for the TO string */
1631-  n = (f.n+1)*(n2+1);
1632-  n = (n+1)&~1;
1633-  nByte = n*sizeof(m[0]) + sizeof(a2[0])*n2;
1634-  if( nByte<=sizeof(stackSpace) ){
1635-    m = stackSpace;
1636-    pToFree = 0;
1637-  }else{
1638-    m = pToFree = sqlite3_malloc64( nByte );
1639-    if( m==0 ) return -1;            /* Out of memory */
1640-  }
1641-  a2 = (EditDist3To*)&m[n];
1642-  memset(a2, 0, sizeof(a2[0])*n2);
1643+    /* allocate the Wagner matrix and the aTo[] array for the TO string */
1644+    n = (f.n+1)*(n2+1);
1645+    n = (n+1)&~1;
1646+    nByte = n*sizeof(m[0]) + sizeof(a2[0])*n2;
1647+    if( nByte<=sizeof(stackSpace) ) {
1648+        m = stackSpace;
1649+        pToFree = 0;
1650+    } else {
1651+        m = pToFree = sqlite3_malloc64( nByte );
1652+        if( m==0 ) return -1;            /* Out of memory */
1653+    }
1654+    a2 = (EditDist3To*)&m[n];
1655+    memset(a2, 0, sizeof(a2[0])*n2);
1656 
1657-  /* Fill in the a1[] matrix for all characters of the TO string */
1658-  for(i2=0; i2<n2; i2++){
1659-    a2[i2].nByte = utf8Len((unsigned char)z2[i2], n2-i2);
1660-    for(p=pLang->pCost; p; p=p->pNext){
1661-      EditDist3Cost **apNew;
1662-      if( p->nFrom>0 ) break;
1663-      if( i2+p->nTo>n2 ) continue;
1664-      if( p->a[0]>z2[i2] ) break;
1665-      if( matchTo(p, z2+i2, n2-i2)==0 ) continue;
1666-      a2[i2].nIns++;
1667-      apNew = sqlite3_realloc64(a2[i2].apIns, sizeof(*apNew)*a2[i2].nIns);
1668-      if( apNew==0 ){
1669-        res = -1;  /* Out of memory */
1670-        goto editDist3Abort;
1671-      }
1672-      a2[i2].apIns = apNew;
1673-      a2[i2].apIns[a2[i2].nIns-1] = p;
1674+    /* Fill in the a1[] matrix for all characters of the TO string */
1675+    for(i2=0; i2<n2; i2++) {
1676+        a2[i2].nByte = utf8Len((unsigned char)z2[i2], n2-i2);
1677+        for(p=pLang->pCost; p; p=p->pNext) {
1678+            EditDist3Cost **apNew;
1679+            if( p->nFrom>0 ) break;
1680+            if( i2+p->nTo>n2 ) continue;
1681+            if( p->a[0]>z2[i2] ) break;
1682+            if( matchTo(p, z2+i2, n2-i2)==0 ) continue;
1683+            a2[i2].nIns++;
1684+            apNew = sqlite3_realloc64(a2[i2].apIns, sizeof(*apNew)*a2[i2].nIns);
1685+            if( apNew==0 ) {
1686+                res = -1;  /* Out of memory */
1687+                goto editDist3Abort;
1688+            }
1689+            a2[i2].apIns = apNew;
1690+            a2[i2].apIns[a2[i2].nIns-1] = p;
1691+        }
1692     }
1693-  }
1694 
1695-  /* Prepare to compute the minimum edit distance */
1696-  szRow = f.n+1;
1697-  memset(m, 0x01, (n2+1)*szRow*sizeof(m[0]));
1698-  m[0] = 0;
1699+    /* Prepare to compute the minimum edit distance */
1700+    szRow = f.n+1;
1701+    memset(m, 0x01, (n2+1)*szRow*sizeof(m[0]));
1702+    m[0] = 0;
1703 
1704-  /* First fill in the top-row of the matrix with FROM deletion costs */
1705-  for(i1=0; i1<f.n; i1 += b1){
1706-    b1 = f.a[i1].nByte;
1707-    updateCost(m, i1+b1, i1, pLang->iDelCost);
1708-    for(k=0; k<f.a[i1].nDel; k++){
1709-      p = f.a[i1].apDel[k];
1710-      updateCost(m, i1+p->nFrom, i1, p->iCost);
1711+    /* First fill in the top-row of the matrix with FROM deletion costs */
1712+    for(i1=0; i1<f.n; i1 += b1) {
1713+        b1 = f.a[i1].nByte;
1714+        updateCost(m, i1+b1, i1, pLang->iDelCost);
1715+        for(k=0; k<f.a[i1].nDel; k++) {
1716+            p = f.a[i1].apDel[k];
1717+            updateCost(m, i1+p->nFrom, i1, p->iCost);
1718+        }
1719     }
1720-  }
1721 
1722-  /* Fill in all subsequent rows, top-to-bottom, left-to-right */
1723-  for(i2=0; i2<n2; i2 += b2){
1724-    int rx;      /* Starting index for current row */
1725-    int rxp;     /* Starting index for previous row */
1726-    b2 = a2[i2].nByte;
1727-    rx = szRow*(i2+b2);
1728-    rxp = szRow*i2;
1729-    updateCost(m, rx, rxp, pLang->iInsCost);
1730-    for(k=0; k<a2[i2].nIns; k++){
1731-      p = a2[i2].apIns[k];
1732-      updateCost(m, szRow*(i2+p->nTo), rxp, p->iCost);
1733-    }
1734-    for(i1=0; i1<f.n; i1+=b1){
1735-      int cx;    /* Index of current cell */
1736-      int cxp;   /* Index of cell immediately to the left */
1737-      int cxd;   /* Index of cell to the left and one row above */
1738-      int cxu;   /* Index of cell immediately above */
1739-      b1 = f.a[i1].nByte;
1740-      cxp = rx + i1;
1741-      cx = cxp + b1;
1742-      cxd = rxp + i1;
1743-      cxu = cxd + b1;
1744-      updateCost(m, cx, cxp, pLang->iDelCost);
1745-      for(k=0; k<f.a[i1].nDel; k++){
1746-        p = f.a[i1].apDel[k];
1747-        updateCost(m, cxp+p->nFrom, cxp, p->iCost);
1748-      }
1749-      updateCost(m, cx, cxu, pLang->iInsCost);
1750-      if( matchFromTo(&f, i1, z2+i2, n2-i2) ){
1751-        updateCost(m, cx, cxd, 0);
1752-      }
1753-      updateCost(m, cx, cxd, pLang->iSubCost);
1754-      for(k=0; k<f.a[i1].nSubst; k++){
1755-        p = f.a[i1].apSubst[k];
1756-        if( matchTo(p, z2+i2, n2-i2) ){
1757-          updateCost(m, cxd+p->nFrom+szRow*p->nTo, cxd, p->iCost);
1758+    /* Fill in all subsequent rows, top-to-bottom, left-to-right */
1759+    for(i2=0; i2<n2; i2 += b2) {
1760+        int rx;      /* Starting index for current row */
1761+        int rxp;     /* Starting index for previous row */
1762+        b2 = a2[i2].nByte;
1763+        rx = szRow*(i2+b2);
1764+        rxp = szRow*i2;
1765+        updateCost(m, rx, rxp, pLang->iInsCost);
1766+        for(k=0; k<a2[i2].nIns; k++) {
1767+            p = a2[i2].apIns[k];
1768+            updateCost(m, szRow*(i2+p->nTo), rxp, p->iCost);
1769+        }
1770+        for(i1=0; i1<f.n; i1+=b1) {
1771+            int cx;    /* Index of current cell */
1772+            int cxp;   /* Index of cell immediately to the left */
1773+            int cxd;   /* Index of cell to the left and one row above */
1774+            int cxu;   /* Index of cell immediately above */
1775+            b1 = f.a[i1].nByte;
1776+            cxp = rx + i1;
1777+            cx = cxp + b1;
1778+            cxd = rxp + i1;
1779+            cxu = cxd + b1;
1780+            updateCost(m, cx, cxp, pLang->iDelCost);
1781+            for(k=0; k<f.a[i1].nDel; k++) {
1782+                p = f.a[i1].apDel[k];
1783+                updateCost(m, cxp+p->nFrom, cxp, p->iCost);
1784+            }
1785+            updateCost(m, cx, cxu, pLang->iInsCost);
1786+            if( matchFromTo(&f, i1, z2+i2, n2-i2) ) {
1787+                updateCost(m, cx, cxd, 0);
1788+            }
1789+            updateCost(m, cx, cxd, pLang->iSubCost);
1790+            for(k=0; k<f.a[i1].nSubst; k++) {
1791+                p = f.a[i1].apSubst[k];
1792+                if( matchTo(p, z2+i2, n2-i2) ) {
1793+                    updateCost(m, cxd+p->nFrom+szRow*p->nTo, cxd, p->iCost);
1794+                }
1795+            }
1796         }
1797-      }
1798     }
1799-  }
1800 
1801 #if 0  /* Enable for debugging */
1802-  printf("         ^");
1803-  for(i1=0; i1<f.n; i1++) printf(" %c-%2x", f.z[i1], f.z[i1]&0xff);
1804-  printf("\n   ^:");
1805-  for(i1=0; i1<szRow; i1++){
1806-    int v = m[i1];
1807-    if( v>9999 ) printf(" ****");
1808-    else         printf(" %4d", v);
1809-  }
1810-  printf("\n");
1811-  for(i2=0; i2<n2; i2++){
1812-    printf("%c-%02x:", z2[i2], z2[i2]&0xff);
1813-    for(i1=0; i1<szRow; i1++){
1814-      int v = m[(i2+1)*szRow+i1];
1815-      if( v>9999 ) printf(" ****");
1816-      else         printf(" %4d", v);
1817+    printf("         ^");
1818+    for(i1=0; i1<f.n; i1++) printf(" %c-%2x", f.z[i1], f.z[i1]&0xff);
1819+    printf("\n   ^:");
1820+    for(i1=0; i1<szRow; i1++) {
1821+        int v = m[i1];
1822+        if( v>9999 ) printf(" ****");
1823+        else         printf(" %4d", v);
1824     }
1825     printf("\n");
1826-  }
1827+    for(i2=0; i2<n2; i2++) {
1828+        printf("%c-%02x:", z2[i2], z2[i2]&0xff);
1829+        for(i1=0; i1<szRow; i1++) {
1830+            int v = m[(i2+1)*szRow+i1];
1831+            if( v>9999 ) printf(" ****");
1832+            else         printf(" %4d", v);
1833+        }
1834+        printf("\n");
1835+    }
1836 #endif
1837 
1838-  /* Free memory allocations and return the result */
1839-  res = (int)m[szRow*(n2+1)-1];
1840-  n = n2;
1841-  if( f.isPrefix ){
1842-    for(i2=1; i2<=n2; i2++){
1843-      int b = m[szRow*i2-1];
1844-      if( b<=res ){ 
1845-        res = b;
1846-        n = i2 - 1;
1847-      }
1848+    /* Free memory allocations and return the result */
1849+    res = (int)m[szRow*(n2+1)-1];
1850+    n = n2;
1851+    if( f.isPrefix ) {
1852+        for(i2=1; i2<=n2; i2++) {
1853+            int b = m[szRow*i2-1];
1854+            if( b<=res ) {
1855+                res = b;
1856+                n = i2 - 1;
1857+            }
1858+        }
1859     }
1860-  }
1861-  if( pnMatch ){
1862-    int nExtra = 0;
1863-    for(k=0; k<n; k++){
1864-      if( (z2[k] & 0xc0)==0x80 ) nExtra++;
1865+    if( pnMatch ) {
1866+        int nExtra = 0;
1867+        for(k=0; k<n; k++) {
1868+            if( (z2[k] & 0xc0)==0x80 ) nExtra++;
1869+        }
1870+        *pnMatch = n - nExtra;
1871     }
1872-    *pnMatch = n - nExtra;
1873-  }
1874 
1875 editDist3Abort:
1876-  for(i2=0; i2<n2; i2++) sqlite3_free(a2[i2].apIns);
1877-  sqlite3_free(pToFree);
1878-  return res;
1879+    for(i2=0; i2<n2; i2++) sqlite3_free(a2[i2].apIns);
1880+    sqlite3_free(pToFree);
1881+    return res;
1882 }
1883 
1884 /*
1885 ** Get an appropriate EditDist3Lang object.
1886 */
1887 static const EditDist3Lang *editDist3FindLang(
1888-  EditDist3Config *pConfig,
1889-  int iLang
1890-){
1891-  int i;
1892-  for(i=0; i<pConfig->nLang; i++){
1893-    if( pConfig->a[i].iLang==iLang ) return &pConfig->a[i];
1894-  }
1895-  return &editDist3Lang;
1896+    EditDist3Config *pConfig,
1897+    int iLang
1898+)
1899+{
1900+    int i;
1901+    for(i=0; i<pConfig->nLang; i++) {
1902+        if( pConfig->a[i].iLang==iLang ) return &pConfig->a[i];
1903+    }
1904+    return &editDist3Lang;
1905 }
1906 
1907 /*
1908@@ -1168,66 +1202,68 @@ **
1909 ** The second form loads edit weights into memory from a table.
1910 */
1911 static void editDist3SqlFunc(
1912-  sqlite3_context *context,
1913-  int argc,
1914-  sqlite3_value **argv
1915-){
1916-  EditDist3Config *pConfig = (EditDist3Config*)sqlite3_user_data(context);
1917-  sqlite3 *db = sqlite3_context_db_handle(context);
1918-  int rc;
1919-  if( argc==1 ){
1920-    const char *zTable = (const char*)sqlite3_value_text(argv[0]);
1921-    rc = editDist3ConfigLoad(pConfig, db, zTable);
1922-    if( rc ) sqlite3_result_error_code(context, rc);
1923-  }else{
1924-    const char *zA = (const char*)sqlite3_value_text(argv[0]);
1925-    const char *zB = (const char*)sqlite3_value_text(argv[1]);
1926-    int nA = sqlite3_value_bytes(argv[0]);
1927-    int nB = sqlite3_value_bytes(argv[1]);
1928-    int iLang = argc==3 ? sqlite3_value_int(argv[2]) : 0;
1929-    const EditDist3Lang *pLang = editDist3FindLang(pConfig, iLang);
1930-    EditDist3FromString *pFrom;
1931-    int dist;
1932+    sqlite3_context *context,
1933+    int argc,
1934+    sqlite3_value **argv
1935+)
1936+{
1937+    EditDist3Config *pConfig = (EditDist3Config*)sqlite3_user_data(context);
1938+    sqlite3 *db = sqlite3_context_db_handle(context);
1939+    int rc;
1940+    if( argc==1 ) {
1941+        const char *zTable = (const char*)sqlite3_value_text(argv[0]);
1942+        rc = editDist3ConfigLoad(pConfig, db, zTable);
1943+        if( rc ) sqlite3_result_error_code(context, rc);
1944+    } else {
1945+        const char *zA = (const char*)sqlite3_value_text(argv[0]);
1946+        const char *zB = (const char*)sqlite3_value_text(argv[1]);
1947+        int nA = sqlite3_value_bytes(argv[0]);
1948+        int nB = sqlite3_value_bytes(argv[1]);
1949+        int iLang = argc==3 ? sqlite3_value_int(argv[2]) : 0;
1950+        const EditDist3Lang *pLang = editDist3FindLang(pConfig, iLang);
1951+        EditDist3FromString *pFrom;
1952+        int dist;
1953 
1954-    pFrom = editDist3FromStringNew(pLang, zA, nA);
1955-    if( pFrom==0 ){
1956-      sqlite3_result_error_nomem(context);
1957-      return;
1958-    }
1959-    dist = editDist3Core(pFrom, zB, nB, pLang, 0);
1960-    editDist3FromStringDelete(pFrom);
1961-    if( dist==(-1) ){
1962-      sqlite3_result_error_nomem(context);
1963-    }else{
1964-      sqlite3_result_int(context, dist);
1965+        pFrom = editDist3FromStringNew(pLang, zA, nA);
1966+        if( pFrom==0 ) {
1967+            sqlite3_result_error_nomem(context);
1968+            return;
1969+        }
1970+        dist = editDist3Core(pFrom, zB, nB, pLang, 0);
1971+        editDist3FromStringDelete(pFrom);
1972+        if( dist==(-1) ) {
1973+            sqlite3_result_error_nomem(context);
1974+        } else {
1975+            sqlite3_result_int(context, dist);
1976+        }
1977     }
1978-  } 
1979 }
1980 
1981 /*
1982 ** Register the editDist3 function with SQLite
1983 */
1984-static int editDist3Install(sqlite3 *db){
1985-  int rc;
1986-  EditDist3Config *pConfig = sqlite3_malloc64( sizeof(*pConfig) );
1987-  if( pConfig==0 ) return SQLITE_NOMEM;
1988-  memset(pConfig, 0, sizeof(*pConfig));
1989-  rc = sqlite3_create_function_v2(db, "editdist3",
1990-              2, SQLITE_UTF8|SQLITE_DETERMINISTIC, pConfig,
1991-              editDist3SqlFunc, 0, 0, 0);
1992-  if( rc==SQLITE_OK ){
1993+static int editDist3Install(sqlite3 *db)
1994+{
1995+    int rc;
1996+    EditDist3Config *pConfig = sqlite3_malloc64( sizeof(*pConfig) );
1997+    if( pConfig==0 ) return SQLITE_NOMEM;
1998+    memset(pConfig, 0, sizeof(*pConfig));
1999     rc = sqlite3_create_function_v2(db, "editdist3",
2000-                3, SQLITE_UTF8|SQLITE_DETERMINISTIC, pConfig,
2001-                editDist3SqlFunc, 0, 0, 0);
2002-  }
2003-  if( rc==SQLITE_OK ){
2004-    rc = sqlite3_create_function_v2(db, "editdist3",
2005-                1, SQLITE_UTF8|SQLITE_DETERMINISTIC, pConfig,
2006-                editDist3SqlFunc, 0, 0, editDist3ConfigDelete);
2007-  }else{
2008-    sqlite3_free(pConfig);
2009-  }
2010-  return rc;
2011+                                    2, SQLITE_UTF8|SQLITE_DETERMINISTIC, pConfig,
2012+                                    editDist3SqlFunc, 0, 0, 0);
2013+    if( rc==SQLITE_OK ) {
2014+        rc = sqlite3_create_function_v2(db, "editdist3",
2015+                                        3, SQLITE_UTF8|SQLITE_DETERMINISTIC, pConfig,
2016+                                        editDist3SqlFunc, 0, 0, 0);
2017+    }
2018+    if( rc==SQLITE_OK ) {
2019+        rc = sqlite3_create_function_v2(db, "editdist3",
2020+                                        1, SQLITE_UTF8|SQLITE_DETERMINISTIC, pConfig,
2021+                                        editDist3SqlFunc, 0, 0, editDist3ConfigDelete);
2022+    } else {
2023+        sqlite3_free(pConfig);
2024+    }
2025+    return rc;
2026 }
2027 /* End configurable cost unicode edit distance routines
2028 ******************************************************************************
2029@@ -1241,62 +1277,64 @@ ** This lookup table is used to help decode the first byte of
2030 ** a multi-byte UTF8 character.
2031 */
2032 static const unsigned char sqlite3Utf8Trans1[] = {
2033-  0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2034-  0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
2035-  0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2036-  0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2037-  0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2038-  0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
2039-  0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2040-  0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
2041+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2042+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
2043+    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2044+    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
2045+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2046+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
2047+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2048+    0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
2049 };
2050 #endif
2051 
2052 /*
2053 ** Return the value of the first UTF-8 character in the string.
2054 */
2055-static int utf8Read(const unsigned char *z, int n, int *pSize){
2056-  int c, i;
2057+static int utf8Read(const unsigned char *z, int n, int *pSize)
2058+{
2059+    int c, i;
2060 
2061-  /* All callers to this routine (in the current implementation)
2062-  ** always have n>0. */
2063-  if( NEVER(n==0) ){
2064-    c = i = 0;
2065-  }else{
2066-    c = z[0];
2067-    i = 1;
2068-    if( c>=0xc0 ){
2069-      c = sqlite3Utf8Trans1[c-0xc0];
2070-      while( i<n && (z[i] & 0xc0)==0x80 ){
2071-        c = (c<<6) + (0x3f & z[i++]);
2072-      }
2073+    /* All callers to this routine (in the current implementation)
2074+    ** always have n>0. */
2075+    if( NEVER(n==0) ) {
2076+        c = i = 0;
2077+    } else {
2078+        c = z[0];
2079+        i = 1;
2080+        if( c>=0xc0 ) {
2081+            c = sqlite3Utf8Trans1[c-0xc0];
2082+            while( i<n && (z[i] & 0xc0)==0x80 ) {
2083+                c = (c<<6) + (0x3f & z[i++]);
2084+            }
2085+        }
2086     }
2087-  }
2088-  *pSize = i;
2089-  return c;
2090+    *pSize = i;
2091+    return c;
2092 }
2093 
2094 /*
2095 ** Return the number of characters in the utf-8 string in the nIn byte
2096 ** buffer pointed to by zIn.
2097 */
2098-static int utf8Charlen(const char *zIn, int nIn){
2099-  int i;
2100-  int nChar = 0;
2101-  for(i=0; i<nIn; nChar++){
2102-    int sz;
2103-    utf8Read((const unsigned char *)&zIn[i], nIn-i, &sz);
2104-    i += sz;
2105-  }
2106-  return nChar;
2107+static int utf8Charlen(const char *zIn, int nIn)
2108+{
2109+    int i;
2110+    int nChar = 0;
2111+    for(i=0; i<nIn; nChar++) {
2112+        int sz;
2113+        utf8Read((const unsigned char *)&zIn[i], nIn-i, &sz);
2114+        i += sz;
2115+    }
2116+    return nChar;
2117 }
2118 
2119 typedef struct Transliteration Transliteration;
2120 struct Transliteration {
2121- unsigned short int cFrom;
2122- unsigned char cTo0, cTo1, cTo2, cTo3;
2123+    unsigned short int cFrom;
2124+    unsigned char cTo0, cTo1, cTo2, cTo3;
2125 #ifdef SQLITE_SPELLFIX_5BYTE_MAPPINGS
2126- unsigned char cTo4;
2127+    unsigned char cTo4;
2128 #endif
2129 };
2130 
2131@@ -1304,400 +1342,401 @@ /*
2132 ** Table of translations from unicode characters into ASCII.
2133 */
2134 static const Transliteration translit[] = {
2135-  { 0x00A0,  0x20, 0x00, 0x00, 0x00 },  /*   to   */
2136-  { 0x00B5,  0x75, 0x00, 0x00, 0x00 },  /* µ to u */
2137-  { 0x00C0,  0x41, 0x00, 0x00, 0x00 },  /* À to A */
2138-  { 0x00C1,  0x41, 0x00, 0x00, 0x00 },  /* Á to A */
2139-  { 0x00C2,  0x41, 0x00, 0x00, 0x00 },  /* Â to A */
2140-  { 0x00C3,  0x41, 0x00, 0x00, 0x00 },  /* Ã to A */
2141-  { 0x00C4,  0x41, 0x65, 0x00, 0x00 },  /* Ä to Ae */
2142-  { 0x00C5,  0x41, 0x61, 0x00, 0x00 },  /* Å to Aa */
2143-  { 0x00C6,  0x41, 0x45, 0x00, 0x00 },  /* Æ to AE */
2144-  { 0x00C7,  0x43, 0x00, 0x00, 0x00 },  /* Ç to C */
2145-  { 0x00C8,  0x45, 0x00, 0x00, 0x00 },  /* È to E */
2146-  { 0x00C9,  0x45, 0x00, 0x00, 0x00 },  /* É to E */
2147-  { 0x00CA,  0x45, 0x00, 0x00, 0x00 },  /* Ê to E */
2148-  { 0x00CB,  0x45, 0x00, 0x00, 0x00 },  /* Ë to E */
2149-  { 0x00CC,  0x49, 0x00, 0x00, 0x00 },  /* Ì to I */
2150-  { 0x00CD,  0x49, 0x00, 0x00, 0x00 },  /* Í to I */
2151-  { 0x00CE,  0x49, 0x00, 0x00, 0x00 },  /* Î to I */
2152-  { 0x00CF,  0x49, 0x00, 0x00, 0x00 },  /* Ï to I */
2153-  { 0x00D0,  0x44, 0x00, 0x00, 0x00 },  /* Ð to D */
2154-  { 0x00D1,  0x4E, 0x00, 0x00, 0x00 },  /* Ñ to N */
2155-  { 0x00D2,  0x4F, 0x00, 0x00, 0x00 },  /* Ò to O */
2156-  { 0x00D3,  0x4F, 0x00, 0x00, 0x00 },  /* Ó to O */
2157-  { 0x00D4,  0x4F, 0x00, 0x00, 0x00 },  /* Ô to O */
2158-  { 0x00D5,  0x4F, 0x00, 0x00, 0x00 },  /* Õ to O */
2159-  { 0x00D6,  0x4F, 0x65, 0x00, 0x00 },  /* Ö to Oe */
2160-  { 0x00D7,  0x78, 0x00, 0x00, 0x00 },  /* × to x */
2161-  { 0x00D8,  0x4F, 0x00, 0x00, 0x00 },  /* Ø to O */
2162-  { 0x00D9,  0x55, 0x00, 0x00, 0x00 },  /* Ù to U */
2163-  { 0x00DA,  0x55, 0x00, 0x00, 0x00 },  /* Ú to U */
2164-  { 0x00DB,  0x55, 0x00, 0x00, 0x00 },  /* Û to U */
2165-  { 0x00DC,  0x55, 0x65, 0x00, 0x00 },  /* Ü to Ue */
2166-  { 0x00DD,  0x59, 0x00, 0x00, 0x00 },  /* Ý to Y */
2167-  { 0x00DE,  0x54, 0x68, 0x00, 0x00 },  /* Þ to Th */
2168-  { 0x00DF,  0x73, 0x73, 0x00, 0x00 },  /* ß to ss */
2169-  { 0x00E0,  0x61, 0x00, 0x00, 0x00 },  /* à to a */
2170-  { 0x00E1,  0x61, 0x00, 0x00, 0x00 },  /* á to a */
2171-  { 0x00E2,  0x61, 0x00, 0x00, 0x00 },  /* â to a */
2172-  { 0x00E3,  0x61, 0x00, 0x00, 0x00 },  /* ã to a */
2173-  { 0x00E4,  0x61, 0x65, 0x00, 0x00 },  /* ä to ae */
2174-  { 0x00E5,  0x61, 0x61, 0x00, 0x00 },  /* å to aa */
2175-  { 0x00E6,  0x61, 0x65, 0x00, 0x00 },  /* æ to ae */
2176-  { 0x00E7,  0x63, 0x00, 0x00, 0x00 },  /* ç to c */
2177-  { 0x00E8,  0x65, 0x00, 0x00, 0x00 },  /* è to e */
2178-  { 0x00E9,  0x65, 0x00, 0x00, 0x00 },  /* é to e */
2179-  { 0x00EA,  0x65, 0x00, 0x00, 0x00 },  /* ê to e */
2180-  { 0x00EB,  0x65, 0x00, 0x00, 0x00 },  /* ë to e */
2181-  { 0x00EC,  0x69, 0x00, 0x00, 0x00 },  /* ì to i */
2182-  { 0x00ED,  0x69, 0x00, 0x00, 0x00 },  /* í to i */
2183-  { 0x00EE,  0x69, 0x00, 0x00, 0x00 },  /* î to i */
2184-  { 0x00EF,  0x69, 0x00, 0x00, 0x00 },  /* ï to i */
2185-  { 0x00F0,  0x64, 0x00, 0x00, 0x00 },  /* ð to d */
2186-  { 0x00F1,  0x6E, 0x00, 0x00, 0x00 },  /* ñ to n */
2187-  { 0x00F2,  0x6F, 0x00, 0x00, 0x00 },  /* ò to o */
2188-  { 0x00F3,  0x6F, 0x00, 0x00, 0x00 },  /* ó to o */
2189-  { 0x00F4,  0x6F, 0x00, 0x00, 0x00 },  /* ô to o */
2190-  { 0x00F5,  0x6F, 0x00, 0x00, 0x00 },  /* õ to o */
2191-  { 0x00F6,  0x6F, 0x65, 0x00, 0x00 },  /* ö to oe */
2192-  { 0x00F7,  0x3A, 0x00, 0x00, 0x00 },  /* ÷ to : */
2193-  { 0x00F8,  0x6F, 0x00, 0x00, 0x00 },  /* ø to o */
2194-  { 0x00F9,  0x75, 0x00, 0x00, 0x00 },  /* ù to u */
2195-  { 0x00FA,  0x75, 0x00, 0x00, 0x00 },  /* ú to u */
2196-  { 0x00FB,  0x75, 0x00, 0x00, 0x00 },  /* û to u */
2197-  { 0x00FC,  0x75, 0x65, 0x00, 0x00 },  /* ü to ue */
2198-  { 0x00FD,  0x79, 0x00, 0x00, 0x00 },  /* ý to y */
2199-  { 0x00FE,  0x74, 0x68, 0x00, 0x00 },  /* þ to th */
2200-  { 0x00FF,  0x79, 0x00, 0x00, 0x00 },  /* ÿ to y */
2201-  { 0x0100,  0x41, 0x00, 0x00, 0x00 },  /* Ā to A */
2202-  { 0x0101,  0x61, 0x00, 0x00, 0x00 },  /* ā to a */
2203-  { 0x0102,  0x41, 0x00, 0x00, 0x00 },  /* Ă to A */
2204-  { 0x0103,  0x61, 0x00, 0x00, 0x00 },  /* ă to a */
2205-  { 0x0104,  0x41, 0x00, 0x00, 0x00 },  /* Ą to A */
2206-  { 0x0105,  0x61, 0x00, 0x00, 0x00 },  /* ą to a */
2207-  { 0x0106,  0x43, 0x00, 0x00, 0x00 },  /* Ć to C */
2208-  { 0x0107,  0x63, 0x00, 0x00, 0x00 },  /* ć to c */
2209-  { 0x0108,  0x43, 0x68, 0x00, 0x00 },  /* Ĉ to Ch */
2210-  { 0x0109,  0x63, 0x68, 0x00, 0x00 },  /* ĉ to ch */
2211-  { 0x010A,  0x43, 0x00, 0x00, 0x00 },  /* Ċ to C */
2212-  { 0x010B,  0x63, 0x00, 0x00, 0x00 },  /* ċ to c */
2213-  { 0x010C,  0x43, 0x00, 0x00, 0x00 },  /* Č to C */
2214-  { 0x010D,  0x63, 0x00, 0x00, 0x00 },  /* č to c */
2215-  { 0x010E,  0x44, 0x00, 0x00, 0x00 },  /* Ď to D */
2216-  { 0x010F,  0x64, 0x00, 0x00, 0x00 },  /* ď to d */
2217-  { 0x0110,  0x44, 0x00, 0x00, 0x00 },  /* Đ to D */
2218-  { 0x0111,  0x64, 0x00, 0x00, 0x00 },  /* đ to d */
2219-  { 0x0112,  0x45, 0x00, 0x00, 0x00 },  /* Ē to E */
2220-  { 0x0113,  0x65, 0x00, 0x00, 0x00 },  /* ē to e */
2221-  { 0x0114,  0x45, 0x00, 0x00, 0x00 },  /* Ĕ to E */
2222-  { 0x0115,  0x65, 0x00, 0x00, 0x00 },  /* ĕ to e */
2223-  { 0x0116,  0x45, 0x00, 0x00, 0x00 },  /* Ė to E */
2224-  { 0x0117,  0x65, 0x00, 0x00, 0x00 },  /* ė to e */
2225-  { 0x0118,  0x45, 0x00, 0x00, 0x00 },  /* Ę to E */
2226-  { 0x0119,  0x65, 0x00, 0x00, 0x00 },  /* ę to e */
2227-  { 0x011A,  0x45, 0x00, 0x00, 0x00 },  /* Ě to E */
2228-  { 0x011B,  0x65, 0x00, 0x00, 0x00 },  /* ě to e */
2229-  { 0x011C,  0x47, 0x68, 0x00, 0x00 },  /* Ĝ to Gh */
2230-  { 0x011D,  0x67, 0x68, 0x00, 0x00 },  /* ĝ to gh */
2231-  { 0x011E,  0x47, 0x00, 0x00, 0x00 },  /* Ğ to G */
2232-  { 0x011F,  0x67, 0x00, 0x00, 0x00 },  /* ğ to g */
2233-  { 0x0120,  0x47, 0x00, 0x00, 0x00 },  /* Ġ to G */
2234-  { 0x0121,  0x67, 0x00, 0x00, 0x00 },  /* ġ to g */
2235-  { 0x0122,  0x47, 0x00, 0x00, 0x00 },  /* Ģ to G */
2236-  { 0x0123,  0x67, 0x00, 0x00, 0x00 },  /* ģ to g */
2237-  { 0x0124,  0x48, 0x68, 0x00, 0x00 },  /* Ĥ to Hh */
2238-  { 0x0125,  0x68, 0x68, 0x00, 0x00 },  /* ĥ to hh */
2239-  { 0x0126,  0x48, 0x00, 0x00, 0x00 },  /* Ħ to H */
2240-  { 0x0127,  0x68, 0x00, 0x00, 0x00 },  /* ħ to h */
2241-  { 0x0128,  0x49, 0x00, 0x00, 0x00 },  /* Ĩ to I */
2242-  { 0x0129,  0x69, 0x00, 0x00, 0x00 },  /* ĩ to i */
2243-  { 0x012A,  0x49, 0x00, 0x00, 0x00 },  /* Ī to I */
2244-  { 0x012B,  0x69, 0x00, 0x00, 0x00 },  /* ī to i */
2245-  { 0x012C,  0x49, 0x00, 0x00, 0x00 },  /* Ĭ to I */
2246-  { 0x012D,  0x69, 0x00, 0x00, 0x00 },  /* ĭ to i */
2247-  { 0x012E,  0x49, 0x00, 0x00, 0x00 },  /* Į to I */
2248-  { 0x012F,  0x69, 0x00, 0x00, 0x00 },  /* į to i */
2249-  { 0x0130,  0x49, 0x00, 0x00, 0x00 },  /* İ to I */
2250-  { 0x0131,  0x69, 0x00, 0x00, 0x00 },  /* ı to i */
2251-  { 0x0132,  0x49, 0x4A, 0x00, 0x00 },  /* IJ to IJ */
2252-  { 0x0133,  0x69, 0x6A, 0x00, 0x00 },  /* ij to ij */
2253-  { 0x0134,  0x4A, 0x68, 0x00, 0x00 },  /* Ĵ to Jh */
2254-  { 0x0135,  0x6A, 0x68, 0x00, 0x00 },  /* ĵ to jh */
2255-  { 0x0136,  0x4B, 0x00, 0x00, 0x00 },  /* Ķ to K */
2256-  { 0x0137,  0x6B, 0x00, 0x00, 0x00 },  /* ķ to k */
2257-  { 0x0138,  0x6B, 0x00, 0x00, 0x00 },  /* ĸ to k */
2258-  { 0x0139,  0x4C, 0x00, 0x00, 0x00 },  /* Ĺ to L */
2259-  { 0x013A,  0x6C, 0x00, 0x00, 0x00 },  /* ĺ to l */
2260-  { 0x013B,  0x4C, 0x00, 0x00, 0x00 },  /* Ļ to L */
2261-  { 0x013C,  0x6C, 0x00, 0x00, 0x00 },  /* ļ to l */
2262-  { 0x013D,  0x4C, 0x00, 0x00, 0x00 },  /* Ľ to L */
2263-  { 0x013E,  0x6C, 0x00, 0x00, 0x00 },  /* ľ to l */
2264-  { 0x013F,  0x4C, 0x2E, 0x00, 0x00 },  /* Ŀ to L. */
2265-  { 0x0140,  0x6C, 0x2E, 0x00, 0x00 },  /* ŀ to l. */
2266-  { 0x0141,  0x4C, 0x00, 0x00, 0x00 },  /* Ł to L */
2267-  { 0x0142,  0x6C, 0x00, 0x00, 0x00 },  /* ł to l */
2268-  { 0x0143,  0x4E, 0x00, 0x00, 0x00 },  /* Ń to N */
2269-  { 0x0144,  0x6E, 0x00, 0x00, 0x00 },  /* ń to n */
2270-  { 0x0145,  0x4E, 0x00, 0x00, 0x00 },  /* Ņ to N */
2271-  { 0x0146,  0x6E, 0x00, 0x00, 0x00 },  /* ņ to n */
2272-  { 0x0147,  0x4E, 0x00, 0x00, 0x00 },  /* Ň to N */
2273-  { 0x0148,  0x6E, 0x00, 0x00, 0x00 },  /* ň to n */
2274-  { 0x0149,  0x27, 0x6E, 0x00, 0x00 },  /* ʼn to 'n */
2275-  { 0x014A,  0x4E, 0x47, 0x00, 0x00 },  /* Ŋ to NG */
2276-  { 0x014B,  0x6E, 0x67, 0x00, 0x00 },  /* ŋ to ng */
2277-  { 0x014C,  0x4F, 0x00, 0x00, 0x00 },  /* Ō to O */
2278-  { 0x014D,  0x6F, 0x00, 0x00, 0x00 },  /* ō to o */
2279-  { 0x014E,  0x4F, 0x00, 0x00, 0x00 },  /* Ŏ to O */
2280-  { 0x014F,  0x6F, 0x00, 0x00, 0x00 },  /* ŏ to o */
2281-  { 0x0150,  0x4F, 0x00, 0x00, 0x00 },  /* Ő to O */
2282-  { 0x0151,  0x6F, 0x00, 0x00, 0x00 },  /* ő to o */
2283-  { 0x0152,  0x4F, 0x45, 0x00, 0x00 },  /* Œ to OE */
2284-  { 0x0153,  0x6F, 0x65, 0x00, 0x00 },  /* œ to oe */
2285-  { 0x0154,  0x52, 0x00, 0x00, 0x00 },  /* Ŕ to R */
2286-  { 0x0155,  0x72, 0x00, 0x00, 0x00 },  /* ŕ to r */
2287-  { 0x0156,  0x52, 0x00, 0x00, 0x00 },  /* Ŗ to R */
2288-  { 0x0157,  0x72, 0x00, 0x00, 0x00 },  /* ŗ to r */
2289-  { 0x0158,  0x52, 0x00, 0x00, 0x00 },  /* Ř to R */
2290-  { 0x0159,  0x72, 0x00, 0x00, 0x00 },  /* ř to r */
2291-  { 0x015A,  0x53, 0x00, 0x00, 0x00 },  /* Ś to S */
2292-  { 0x015B,  0x73, 0x00, 0x00, 0x00 },  /* ś to s */
2293-  { 0x015C,  0x53, 0x68, 0x00, 0x00 },  /* Ŝ to Sh */
2294-  { 0x015D,  0x73, 0x68, 0x00, 0x00 },  /* ŝ to sh */
2295-  { 0x015E,  0x53, 0x00, 0x00, 0x00 },  /* Ş to S */
2296-  { 0x015F,  0x73, 0x00, 0x00, 0x00 },  /* ş to s */
2297-  { 0x0160,  0x53, 0x00, 0x00, 0x00 },  /* Š to S */
2298-  { 0x0161,  0x73, 0x00, 0x00, 0x00 },  /* š to s */
2299-  { 0x0162,  0x54, 0x00, 0x00, 0x00 },  /* Ţ to T */
2300-  { 0x0163,  0x74, 0x00, 0x00, 0x00 },  /* ţ to t */
2301-  { 0x0164,  0x54, 0x00, 0x00, 0x00 },  /* Ť to T */
2302-  { 0x0165,  0x74, 0x00, 0x00, 0x00 },  /* ť to t */
2303-  { 0x0166,  0x54, 0x00, 0x00, 0x00 },  /* Ŧ to T */
2304-  { 0x0167,  0x74, 0x00, 0x00, 0x00 },  /* ŧ to t */
2305-  { 0x0168,  0x55, 0x00, 0x00, 0x00 },  /* Ũ to U */
2306-  { 0x0169,  0x75, 0x00, 0x00, 0x00 },  /* ũ to u */
2307-  { 0x016A,  0x55, 0x00, 0x00, 0x00 },  /* Ū to U */
2308-  { 0x016B,  0x75, 0x00, 0x00, 0x00 },  /* ū to u */
2309-  { 0x016C,  0x55, 0x00, 0x00, 0x00 },  /* Ŭ to U */
2310-  { 0x016D,  0x75, 0x00, 0x00, 0x00 },  /* ŭ to u */
2311-  { 0x016E,  0x55, 0x00, 0x00, 0x00 },  /* Ů to U */
2312-  { 0x016F,  0x75, 0x00, 0x00, 0x00 },  /* ů to u */
2313-  { 0x0170,  0x55, 0x00, 0x00, 0x00 },  /* Ű to U */
2314-  { 0x0171,  0x75, 0x00, 0x00, 0x00 },  /* ű to u */
2315-  { 0x0172,  0x55, 0x00, 0x00, 0x00 },  /* Ų to U */
2316-  { 0x0173,  0x75, 0x00, 0x00, 0x00 },  /* ų to u */
2317-  { 0x0174,  0x57, 0x00, 0x00, 0x00 },  /* Ŵ to W */
2318-  { 0x0175,  0x77, 0x00, 0x00, 0x00 },  /* ŵ to w */
2319-  { 0x0176,  0x59, 0x00, 0x00, 0x00 },  /* Ŷ to Y */
2320-  { 0x0177,  0x79, 0x00, 0x00, 0x00 },  /* ŷ to y */
2321-  { 0x0178,  0x59, 0x00, 0x00, 0x00 },  /* Ÿ to Y */
2322-  { 0x0179,  0x5A, 0x00, 0x00, 0x00 },  /* Ź to Z */
2323-  { 0x017A,  0x7A, 0x00, 0x00, 0x00 },  /* ź to z */
2324-  { 0x017B,  0x5A, 0x00, 0x00, 0x00 },  /* Ż to Z */
2325-  { 0x017C,  0x7A, 0x00, 0x00, 0x00 },  /* ż to z */
2326-  { 0x017D,  0x5A, 0x00, 0x00, 0x00 },  /* Ž to Z */
2327-  { 0x017E,  0x7A, 0x00, 0x00, 0x00 },  /* ž to z */
2328-  { 0x017F,  0x73, 0x00, 0x00, 0x00 },  /* ſ to s */
2329-  { 0x0192,  0x66, 0x00, 0x00, 0x00 },  /* ƒ to f */
2330-  { 0x0218,  0x53, 0x00, 0x00, 0x00 },  /* Ș to S */
2331-  { 0x0219,  0x73, 0x00, 0x00, 0x00 },  /* ș to s */
2332-  { 0x021A,  0x54, 0x00, 0x00, 0x00 },  /* Ț to T */
2333-  { 0x021B,  0x74, 0x00, 0x00, 0x00 },  /* ț to t */
2334-  { 0x0386,  0x41, 0x00, 0x00, 0x00 },  /* Ά to A */
2335-  { 0x0388,  0x45, 0x00, 0x00, 0x00 },  /* Έ to E */
2336-  { 0x0389,  0x49, 0x00, 0x00, 0x00 },  /* Ή to I */
2337-  { 0x038A,  0x49, 0x00, 0x00, 0x00 },  /* Ί to I */
2338-  { 0x038C,  0x4f, 0x00, 0x00, 0x00 },  /* Ό to O */
2339-  { 0x038E,  0x59, 0x00, 0x00, 0x00 },  /* Ύ to Y */
2340-  { 0x038F,  0x4f, 0x00, 0x00, 0x00 },  /* Ώ to O */
2341-  { 0x0390,  0x69, 0x00, 0x00, 0x00 },  /* ΐ to i */
2342-  { 0x0391,  0x41, 0x00, 0x00, 0x00 },  /* Α to A */
2343-  { 0x0392,  0x42, 0x00, 0x00, 0x00 },  /* Β to B */
2344-  { 0x0393,  0x47, 0x00, 0x00, 0x00 },  /* Γ to G */
2345-  { 0x0394,  0x44, 0x00, 0x00, 0x00 },  /* Δ to D */
2346-  { 0x0395,  0x45, 0x00, 0x00, 0x00 },  /* Ε to E */
2347-  { 0x0396,  0x5a, 0x00, 0x00, 0x00 },  /* Ζ to Z */
2348-  { 0x0397,  0x49, 0x00, 0x00, 0x00 },  /* Η to I */
2349-  { 0x0398,  0x54, 0x68, 0x00, 0x00 },  /* Θ to Th */
2350-  { 0x0399,  0x49, 0x00, 0x00, 0x00 },  /* Ι to I */
2351-  { 0x039A,  0x4b, 0x00, 0x00, 0x00 },  /* Κ to K */
2352-  { 0x039B,  0x4c, 0x00, 0x00, 0x00 },  /* Λ to L */
2353-  { 0x039C,  0x4d, 0x00, 0x00, 0x00 },  /* Μ to M */
2354-  { 0x039D,  0x4e, 0x00, 0x00, 0x00 },  /* Ν to N */
2355-  { 0x039E,  0x58, 0x00, 0x00, 0x00 },  /* Ξ to X */
2356-  { 0x039F,  0x4f, 0x00, 0x00, 0x00 },  /* Ο to O */
2357-  { 0x03A0,  0x50, 0x00, 0x00, 0x00 },  /* Π to P */
2358-  { 0x03A1,  0x52, 0x00, 0x00, 0x00 },  /* Ρ to R */
2359-  { 0x03A3,  0x53, 0x00, 0x00, 0x00 },  /* Σ to S */
2360-  { 0x03A4,  0x54, 0x00, 0x00, 0x00 },  /* Τ to T */
2361-  { 0x03A5,  0x59, 0x00, 0x00, 0x00 },  /* Υ to Y */
2362-  { 0x03A6,  0x46, 0x00, 0x00, 0x00 },  /* Φ to F */
2363-  { 0x03A7,  0x43, 0x68, 0x00, 0x00 },  /* Χ to Ch */
2364-  { 0x03A8,  0x50, 0x73, 0x00, 0x00 },  /* Ψ to Ps */
2365-  { 0x03A9,  0x4f, 0x00, 0x00, 0x00 },  /* Ω to O */
2366-  { 0x03AA,  0x49, 0x00, 0x00, 0x00 },  /* Ϊ to I */
2367-  { 0x03AB,  0x59, 0x00, 0x00, 0x00 },  /* Ϋ to Y */
2368-  { 0x03AC,  0x61, 0x00, 0x00, 0x00 },  /* ά to a */
2369-  { 0x03AD,  0x65, 0x00, 0x00, 0x00 },  /* έ to e */
2370-  { 0x03AE,  0x69, 0x00, 0x00, 0x00 },  /* ή to i */
2371-  { 0x03AF,  0x69, 0x00, 0x00, 0x00 },  /* ί to i */
2372-  { 0x03B1,  0x61, 0x00, 0x00, 0x00 },  /* α to a */
2373-  { 0x03B2,  0x62, 0x00, 0x00, 0x00 },  /* β to b */
2374-  { 0x03B3,  0x67, 0x00, 0x00, 0x00 },  /* γ to g */
2375-  { 0x03B4,  0x64, 0x00, 0x00, 0x00 },  /* δ to d */
2376-  { 0x03B5,  0x65, 0x00, 0x00, 0x00 },  /* ε to e */
2377-  { 0x03B6,  0x7a, 0x00, 0x00, 0x00 },  /* ζ to z */
2378-  { 0x03B7,  0x69, 0x00, 0x00, 0x00 },  /* η to i */
2379-  { 0x03B8,  0x74, 0x68, 0x00, 0x00 },  /* θ to th */
2380-  { 0x03B9,  0x69, 0x00, 0x00, 0x00 },  /* ι to i */
2381-  { 0x03BA,  0x6b, 0x00, 0x00, 0x00 },  /* κ to k */
2382-  { 0x03BB,  0x6c, 0x00, 0x00, 0x00 },  /* λ to l */
2383-  { 0x03BC,  0x6d, 0x00, 0x00, 0x00 },  /* μ to m */
2384-  { 0x03BD,  0x6e, 0x00, 0x00, 0x00 },  /* ν to n */
2385-  { 0x03BE,  0x78, 0x00, 0x00, 0x00 },  /* ξ to x */
2386-  { 0x03BF,  0x6f, 0x00, 0x00, 0x00 },  /* ο to o */
2387-  { 0x03C0,  0x70, 0x00, 0x00, 0x00 },  /* π to p */
2388-  { 0x03C1,  0x72, 0x00, 0x00, 0x00 },  /* ρ to r */
2389-  { 0x03C3,  0x73, 0x00, 0x00, 0x00 },  /* σ to s */
2390-  { 0x03C4,  0x74, 0x00, 0x00, 0x00 },  /* τ to t */
2391-  { 0x03C5,  0x79, 0x00, 0x00, 0x00 },  /* υ to y */
2392-  { 0x03C6,  0x66, 0x00, 0x00, 0x00 },  /* φ to f */
2393-  { 0x03C7,  0x63, 0x68, 0x00, 0x00 },  /* χ to ch */
2394-  { 0x03C8,  0x70, 0x73, 0x00, 0x00 },  /* ψ to ps */
2395-  { 0x03C9,  0x6f, 0x00, 0x00, 0x00 },  /* ω to o */
2396-  { 0x03CA,  0x69, 0x00, 0x00, 0x00 },  /* ϊ to i */
2397-  { 0x03CB,  0x79, 0x00, 0x00, 0x00 },  /* ϋ to y */
2398-  { 0x03CC,  0x6f, 0x00, 0x00, 0x00 },  /* ό to o */
2399-  { 0x03CD,  0x79, 0x00, 0x00, 0x00 },  /* ύ to y */
2400-  { 0x03CE,  0x69, 0x00, 0x00, 0x00 },  /* ώ to i */
2401-  { 0x0400,  0x45, 0x00, 0x00, 0x00 },  /* Ѐ to E */
2402-  { 0x0401,  0x45, 0x00, 0x00, 0x00 },  /* Ё to E */
2403-  { 0x0402,  0x44, 0x00, 0x00, 0x00 },  /* Ђ to D */
2404-  { 0x0403,  0x47, 0x00, 0x00, 0x00 },  /* Ѓ to G */
2405-  { 0x0404,  0x45, 0x00, 0x00, 0x00 },  /* Є to E */
2406-  { 0x0405,  0x5a, 0x00, 0x00, 0x00 },  /* Ѕ to Z */
2407-  { 0x0406,  0x49, 0x00, 0x00, 0x00 },  /* І to I */
2408-  { 0x0407,  0x49, 0x00, 0x00, 0x00 },  /* Ї to I */
2409-  { 0x0408,  0x4a, 0x00, 0x00, 0x00 },  /* Ј to J */
2410-  { 0x0409,  0x49, 0x00, 0x00, 0x00 },  /* Љ to I */
2411-  { 0x040A,  0x4e, 0x00, 0x00, 0x00 },  /* Њ to N */
2412-  { 0x040B,  0x44, 0x00, 0x00, 0x00 },  /* Ћ to D */
2413-  { 0x040C,  0x4b, 0x00, 0x00, 0x00 },  /* Ќ to K */
2414-  { 0x040D,  0x49, 0x00, 0x00, 0x00 },  /* Ѝ to I */
2415-  { 0x040E,  0x55, 0x00, 0x00, 0x00 },  /* Ў to U */
2416-  { 0x040F,  0x44, 0x00, 0x00, 0x00 },  /* Џ to D */
2417-  { 0x0410,  0x41, 0x00, 0x00, 0x00 },  /* А to A */
2418-  { 0x0411,  0x42, 0x00, 0x00, 0x00 },  /* Б to B */
2419-  { 0x0412,  0x56, 0x00, 0x00, 0x00 },  /* В to V */
2420-  { 0x0413,  0x47, 0x00, 0x00, 0x00 },  /* Г to G */
2421-  { 0x0414,  0x44, 0x00, 0x00, 0x00 },  /* Д to D */
2422-  { 0x0415,  0x45, 0x00, 0x00, 0x00 },  /* Е to E */
2423-  { 0x0416,  0x5a, 0x68, 0x00, 0x00 },  /* Ж to Zh */
2424-  { 0x0417,  0x5a, 0x00, 0x00, 0x00 },  /* З to Z */
2425-  { 0x0418,  0x49, 0x00, 0x00, 0x00 },  /* И to I */
2426-  { 0x0419,  0x49, 0x00, 0x00, 0x00 },  /* Й to I */
2427-  { 0x041A,  0x4b, 0x00, 0x00, 0x00 },  /* К to K */
2428-  { 0x041B,  0x4c, 0x00, 0x00, 0x00 },  /* Л to L */
2429-  { 0x041C,  0x4d, 0x00, 0x00, 0x00 },  /* М to M */
2430-  { 0x041D,  0x4e, 0x00, 0x00, 0x00 },  /* Н to N */
2431-  { 0x041E,  0x4f, 0x00, 0x00, 0x00 },  /* О to O */
2432-  { 0x041F,  0x50, 0x00, 0x00, 0x00 },  /* П to P */
2433-  { 0x0420,  0x52, 0x00, 0x00, 0x00 },  /* Р to R */
2434-  { 0x0421,  0x53, 0x00, 0x00, 0x00 },  /* С to S */
2435-  { 0x0422,  0x54, 0x00, 0x00, 0x00 },  /* Т to T */
2436-  { 0x0423,  0x55, 0x00, 0x00, 0x00 },  /* У to U */
2437-  { 0x0424,  0x46, 0x00, 0x00, 0x00 },  /* Ф to F */
2438-  { 0x0425,  0x4b, 0x68, 0x00, 0x00 },  /* Х to Kh */
2439-  { 0x0426,  0x54, 0x63, 0x00, 0x00 },  /* Ц to Tc */
2440-  { 0x0427,  0x43, 0x68, 0x00, 0x00 },  /* Ч to Ch */
2441-  { 0x0428,  0x53, 0x68, 0x00, 0x00 },  /* Ш to Sh */
2442-  { 0x0429,  0x53, 0x68, 0x63, 0x68 },  /* Щ to Shch */
2443-  { 0x042A,  0x61, 0x00, 0x00, 0x00 },  /*  to A */
2444-  { 0x042B,  0x59, 0x00, 0x00, 0x00 },  /* Ы to Y */
2445-  { 0x042C,  0x59, 0x00, 0x00, 0x00 },  /*  to Y */
2446-  { 0x042D,  0x45, 0x00, 0x00, 0x00 },  /* Э to E */
2447-  { 0x042E,  0x49, 0x75, 0x00, 0x00 },  /* Ю to Iu */
2448-  { 0x042F,  0x49, 0x61, 0x00, 0x00 },  /* Я to Ia */
2449-  { 0x0430,  0x61, 0x00, 0x00, 0x00 },  /* а to a */
2450-  { 0x0431,  0x62, 0x00, 0x00, 0x00 },  /* б to b */
2451-  { 0x0432,  0x76, 0x00, 0x00, 0x00 },  /* в to v */
2452-  { 0x0433,  0x67, 0x00, 0x00, 0x00 },  /* г to g */
2453-  { 0x0434,  0x64, 0x00, 0x00, 0x00 },  /* д to d */
2454-  { 0x0435,  0x65, 0x00, 0x00, 0x00 },  /* е to e */
2455-  { 0x0436,  0x7a, 0x68, 0x00, 0x00 },  /* ж to zh */
2456-  { 0x0437,  0x7a, 0x00, 0x00, 0x00 },  /* з to z */
2457-  { 0x0438,  0x69, 0x00, 0x00, 0x00 },  /* и to i */
2458-  { 0x0439,  0x69, 0x00, 0x00, 0x00 },  /* й to i */
2459-  { 0x043A,  0x6b, 0x00, 0x00, 0x00 },  /* к to k */
2460-  { 0x043B,  0x6c, 0x00, 0x00, 0x00 },  /* л to l */
2461-  { 0x043C,  0x6d, 0x00, 0x00, 0x00 },  /* м to m */
2462-  { 0x043D,  0x6e, 0x00, 0x00, 0x00 },  /* н to n */
2463-  { 0x043E,  0x6f, 0x00, 0x00, 0x00 },  /* о to o */
2464-  { 0x043F,  0x70, 0x00, 0x00, 0x00 },  /* п to p */
2465-  { 0x0440,  0x72, 0x00, 0x00, 0x00 },  /* р to r */
2466-  { 0x0441,  0x73, 0x00, 0x00, 0x00 },  /* с to s */
2467-  { 0x0442,  0x74, 0x00, 0x00, 0x00 },  /* т to t */
2468-  { 0x0443,  0x75, 0x00, 0x00, 0x00 },  /* у to u */
2469-  { 0x0444,  0x66, 0x00, 0x00, 0x00 },  /* ф to f */
2470-  { 0x0445,  0x6b, 0x68, 0x00, 0x00 },  /* х to kh */
2471-  { 0x0446,  0x74, 0x63, 0x00, 0x00 },  /* ц to tc */
2472-  { 0x0447,  0x63, 0x68, 0x00, 0x00 },  /* ч to ch */
2473-  { 0x0448,  0x73, 0x68, 0x00, 0x00 },  /* ш to sh */
2474-  { 0x0449,  0x73, 0x68, 0x63, 0x68 },  /* щ to shch */
2475-  { 0x044A,  0x61, 0x00, 0x00, 0x00 },  /*  to a */
2476-  { 0x044B,  0x79, 0x00, 0x00, 0x00 },  /* ы to y */
2477-  { 0x044C,  0x79, 0x00, 0x00, 0x00 },  /*  to y */
2478-  { 0x044D,  0x65, 0x00, 0x00, 0x00 },  /* э to e */
2479-  { 0x044E,  0x69, 0x75, 0x00, 0x00 },  /* ю to iu */
2480-  { 0x044F,  0x69, 0x61, 0x00, 0x00 },  /* я to ia */
2481-  { 0x0450,  0x65, 0x00, 0x00, 0x00 },  /* ѐ to e */
2482-  { 0x0451,  0x65, 0x00, 0x00, 0x00 },  /* ё to e */
2483-  { 0x0452,  0x64, 0x00, 0x00, 0x00 },  /* ђ to d */
2484-  { 0x0453,  0x67, 0x00, 0x00, 0x00 },  /* ѓ to g */
2485-  { 0x0454,  0x65, 0x00, 0x00, 0x00 },  /* є to e */
2486-  { 0x0455,  0x7a, 0x00, 0x00, 0x00 },  /* ѕ to z */
2487-  { 0x0456,  0x69, 0x00, 0x00, 0x00 },  /* і to i */
2488-  { 0x0457,  0x69, 0x00, 0x00, 0x00 },  /* ї to i */
2489-  { 0x0458,  0x6a, 0x00, 0x00, 0x00 },  /* ј to j */
2490-  { 0x0459,  0x69, 0x00, 0x00, 0x00 },  /* љ to i */
2491-  { 0x045A,  0x6e, 0x00, 0x00, 0x00 },  /* њ to n */
2492-  { 0x045B,  0x64, 0x00, 0x00, 0x00 },  /* ћ to d */
2493-  { 0x045C,  0x6b, 0x00, 0x00, 0x00 },  /* ќ to k */
2494-  { 0x045D,  0x69, 0x00, 0x00, 0x00 },  /* ѝ to i */
2495-  { 0x045E,  0x75, 0x00, 0x00, 0x00 },  /* ў to u */
2496-  { 0x045F,  0x64, 0x00, 0x00, 0x00 },  /* џ to d */
2497-  { 0x1E02,  0x42, 0x00, 0x00, 0x00 },  /* Ḃ to B */
2498-  { 0x1E03,  0x62, 0x00, 0x00, 0x00 },  /* ḃ to b */
2499-  { 0x1E0A,  0x44, 0x00, 0x00, 0x00 },  /* Ḋ to D */
2500-  { 0x1E0B,  0x64, 0x00, 0x00, 0x00 },  /* ḋ to d */
2501-  { 0x1E1E,  0x46, 0x00, 0x00, 0x00 },  /* Ḟ to F */
2502-  { 0x1E1F,  0x66, 0x00, 0x00, 0x00 },  /* ḟ to f */
2503-  { 0x1E40,  0x4D, 0x00, 0x00, 0x00 },  /* Ṁ to M */
2504-  { 0x1E41,  0x6D, 0x00, 0x00, 0x00 },  /* ṁ to m */
2505-  { 0x1E56,  0x50, 0x00, 0x00, 0x00 },  /* Ṗ to P */
2506-  { 0x1E57,  0x70, 0x00, 0x00, 0x00 },  /* ṗ to p */
2507-  { 0x1E60,  0x53, 0x00, 0x00, 0x00 },  /* Ṡ to S */
2508-  { 0x1E61,  0x73, 0x00, 0x00, 0x00 },  /* ṡ to s */
2509-  { 0x1E6A,  0x54, 0x00, 0x00, 0x00 },  /* Ṫ to T */
2510-  { 0x1E6B,  0x74, 0x00, 0x00, 0x00 },  /* ṫ to t */
2511-  { 0x1E80,  0x57, 0x00, 0x00, 0x00 },  /* Ẁ to W */
2512-  { 0x1E81,  0x77, 0x00, 0x00, 0x00 },  /* ẁ to w */
2513-  { 0x1E82,  0x57, 0x00, 0x00, 0x00 },  /* Ẃ to W */
2514-  { 0x1E83,  0x77, 0x00, 0x00, 0x00 },  /* ẃ to w */
2515-  { 0x1E84,  0x57, 0x00, 0x00, 0x00 },  /* Ẅ to W */
2516-  { 0x1E85,  0x77, 0x00, 0x00, 0x00 },  /* ẅ to w */
2517-  { 0x1EF2,  0x59, 0x00, 0x00, 0x00 },  /* Ỳ to Y */
2518-  { 0x1EF3,  0x79, 0x00, 0x00, 0x00 },  /* ỳ to y */
2519-  { 0xFB00,  0x66, 0x66, 0x00, 0x00 },  /* ff to ff */
2520-  { 0xFB01,  0x66, 0x69, 0x00, 0x00 },  /* fi to fi */
2521-  { 0xFB02,  0x66, 0x6C, 0x00, 0x00 },  /* fl to fl */
2522-  { 0xFB05,  0x73, 0x74, 0x00, 0x00 },  /* ſt to st */
2523-  { 0xFB06,  0x73, 0x74, 0x00, 0x00 },  /* st to st */
2524+    { 0x00A0,  0x20, 0x00, 0x00, 0x00 },  /*   to   */
2525+    { 0x00B5,  0x75, 0x00, 0x00, 0x00 },  /* µ to u */
2526+    { 0x00C0,  0x41, 0x00, 0x00, 0x00 },  /* À to A */
2527+    { 0x00C1,  0x41, 0x00, 0x00, 0x00 },  /* Á to A */
2528+    { 0x00C2,  0x41, 0x00, 0x00, 0x00 },  /* Â to A */
2529+    { 0x00C3,  0x41, 0x00, 0x00, 0x00 },  /* Ã to A */
2530+    { 0x00C4,  0x41, 0x65, 0x00, 0x00 },  /* Ä to Ae */
2531+    { 0x00C5,  0x41, 0x61, 0x00, 0x00 },  /* Å to Aa */
2532+    { 0x00C6,  0x41, 0x45, 0x00, 0x00 },  /* Æ to AE */
2533+    { 0x00C7,  0x43, 0x00, 0x00, 0x00 },  /* Ç to C */
2534+    { 0x00C8,  0x45, 0x00, 0x00, 0x00 },  /* È to E */
2535+    { 0x00C9,  0x45, 0x00, 0x00, 0x00 },  /* É to E */
2536+    { 0x00CA,  0x45, 0x00, 0x00, 0x00 },  /* Ê to E */
2537+    { 0x00CB,  0x45, 0x00, 0x00, 0x00 },  /* Ë to E */
2538+    { 0x00CC,  0x49, 0x00, 0x00, 0x00 },  /* Ì to I */
2539+    { 0x00CD,  0x49, 0x00, 0x00, 0x00 },  /* Í to I */
2540+    { 0x00CE,  0x49, 0x00, 0x00, 0x00 },  /* Î to I */
2541+    { 0x00CF,  0x49, 0x00, 0x00, 0x00 },  /* Ï to I */
2542+    { 0x00D0,  0x44, 0x00, 0x00, 0x00 },  /* Ð to D */
2543+    { 0x00D1,  0x4E, 0x00, 0x00, 0x00 },  /* Ñ to N */
2544+    { 0x00D2,  0x4F, 0x00, 0x00, 0x00 },  /* Ò to O */
2545+    { 0x00D3,  0x4F, 0x00, 0x00, 0x00 },  /* Ó to O */
2546+    { 0x00D4,  0x4F, 0x00, 0x00, 0x00 },  /* Ô to O */
2547+    { 0x00D5,  0x4F, 0x00, 0x00, 0x00 },  /* Õ to O */
2548+    { 0x00D6,  0x4F, 0x65, 0x00, 0x00 },  /* Ö to Oe */
2549+    { 0x00D7,  0x78, 0x00, 0x00, 0x00 },  /* × to x */
2550+    { 0x00D8,  0x4F, 0x00, 0x00, 0x00 },  /* Ø to O */
2551+    { 0x00D9,  0x55, 0x00, 0x00, 0x00 },  /* Ù to U */
2552+    { 0x00DA,  0x55, 0x00, 0x00, 0x00 },  /* Ú to U */
2553+    { 0x00DB,  0x55, 0x00, 0x00, 0x00 },  /* Û to U */
2554+    { 0x00DC,  0x55, 0x65, 0x00, 0x00 },  /* Ü to Ue */
2555+    { 0x00DD,  0x59, 0x00, 0x00, 0x00 },  /* Ý to Y */
2556+    { 0x00DE,  0x54, 0x68, 0x00, 0x00 },  /* Þ to Th */
2557+    { 0x00DF,  0x73, 0x73, 0x00, 0x00 },  /* ß to ss */
2558+    { 0x00E0,  0x61, 0x00, 0x00, 0x00 },  /* à to a */
2559+    { 0x00E1,  0x61, 0x00, 0x00, 0x00 },  /* á to a */
2560+    { 0x00E2,  0x61, 0x00, 0x00, 0x00 },  /* â to a */
2561+    { 0x00E3,  0x61, 0x00, 0x00, 0x00 },  /* ã to a */
2562+    { 0x00E4,  0x61, 0x65, 0x00, 0x00 },  /* ä to ae */
2563+    { 0x00E5,  0x61, 0x61, 0x00, 0x00 },  /* å to aa */
2564+    { 0x00E6,  0x61, 0x65, 0x00, 0x00 },  /* æ to ae */
2565+    { 0x00E7,  0x63, 0x00, 0x00, 0x00 },  /* ç to c */
2566+    { 0x00E8,  0x65, 0x00, 0x00, 0x00 },  /* è to e */
2567+    { 0x00E9,  0x65, 0x00, 0x00, 0x00 },  /* é to e */
2568+    { 0x00EA,  0x65, 0x00, 0x00, 0x00 },  /* ê to e */
2569+    { 0x00EB,  0x65, 0x00, 0x00, 0x00 },  /* ë to e */
2570+    { 0x00EC,  0x69, 0x00, 0x00, 0x00 },  /* ì to i */
2571+    { 0x00ED,  0x69, 0x00, 0x00, 0x00 },  /* í to i */
2572+    { 0x00EE,  0x69, 0x00, 0x00, 0x00 },  /* î to i */
2573+    { 0x00EF,  0x69, 0x00, 0x00, 0x00 },  /* ï to i */
2574+    { 0x00F0,  0x64, 0x00, 0x00, 0x00 },  /* ð to d */
2575+    { 0x00F1,  0x6E, 0x00, 0x00, 0x00 },  /* ñ to n */
2576+    { 0x00F2,  0x6F, 0x00, 0x00, 0x00 },  /* ò to o */
2577+    { 0x00F3,  0x6F, 0x00, 0x00, 0x00 },  /* ó to o */
2578+    { 0x00F4,  0x6F, 0x00, 0x00, 0x00 },  /* ô to o */
2579+    { 0x00F5,  0x6F, 0x00, 0x00, 0x00 },  /* õ to o */
2580+    { 0x00F6,  0x6F, 0x65, 0x00, 0x00 },  /* ö to oe */
2581+    { 0x00F7,  0x3A, 0x00, 0x00, 0x00 },  /* ÷ to : */
2582+    { 0x00F8,  0x6F, 0x00, 0x00, 0x00 },  /* ø to o */
2583+    { 0x00F9,  0x75, 0x00, 0x00, 0x00 },  /* ù to u */
2584+    { 0x00FA,  0x75, 0x00, 0x00, 0x00 },  /* ú to u */
2585+    { 0x00FB,  0x75, 0x00, 0x00, 0x00 },  /* û to u */
2586+    { 0x00FC,  0x75, 0x65, 0x00, 0x00 },  /* ü to ue */
2587+    { 0x00FD,  0x79, 0x00, 0x00, 0x00 },  /* ý to y */
2588+    { 0x00FE,  0x74, 0x68, 0x00, 0x00 },  /* þ to th */
2589+    { 0x00FF,  0x79, 0x00, 0x00, 0x00 },  /* ÿ to y */
2590+    { 0x0100,  0x41, 0x00, 0x00, 0x00 },  /* Ā to A */
2591+    { 0x0101,  0x61, 0x00, 0x00, 0x00 },  /* ā to a */
2592+    { 0x0102,  0x41, 0x00, 0x00, 0x00 },  /* Ă to A */
2593+    { 0x0103,  0x61, 0x00, 0x00, 0x00 },  /* ă to a */
2594+    { 0x0104,  0x41, 0x00, 0x00, 0x00 },  /* Ą to A */
2595+    { 0x0105,  0x61, 0x00, 0x00, 0x00 },  /* ą to a */
2596+    { 0x0106,  0x43, 0x00, 0x00, 0x00 },  /* Ć to C */
2597+    { 0x0107,  0x63, 0x00, 0x00, 0x00 },  /* ć to c */
2598+    { 0x0108,  0x43, 0x68, 0x00, 0x00 },  /* Ĉ to Ch */
2599+    { 0x0109,  0x63, 0x68, 0x00, 0x00 },  /* ĉ to ch */
2600+    { 0x010A,  0x43, 0x00, 0x00, 0x00 },  /* Ċ to C */
2601+    { 0x010B,  0x63, 0x00, 0x00, 0x00 },  /* ċ to c */
2602+    { 0x010C,  0x43, 0x00, 0x00, 0x00 },  /* Č to C */
2603+    { 0x010D,  0x63, 0x00, 0x00, 0x00 },  /* č to c */
2604+    { 0x010E,  0x44, 0x00, 0x00, 0x00 },  /* Ď to D */
2605+    { 0x010F,  0x64, 0x00, 0x00, 0x00 },  /* ď to d */
2606+    { 0x0110,  0x44, 0x00, 0x00, 0x00 },  /* Đ to D */
2607+    { 0x0111,  0x64, 0x00, 0x00, 0x00 },  /* đ to d */
2608+    { 0x0112,  0x45, 0x00, 0x00, 0x00 },  /* Ē to E */
2609+    { 0x0113,  0x65, 0x00, 0x00, 0x00 },  /* ē to e */
2610+    { 0x0114,  0x45, 0x00, 0x00, 0x00 },  /* Ĕ to E */
2611+    { 0x0115,  0x65, 0x00, 0x00, 0x00 },  /* ĕ to e */
2612+    { 0x0116,  0x45, 0x00, 0x00, 0x00 },  /* Ė to E */
2613+    { 0x0117,  0x65, 0x00, 0x00, 0x00 },  /* ė to e */
2614+    { 0x0118,  0x45, 0x00, 0x00, 0x00 },  /* Ę to E */
2615+    { 0x0119,  0x65, 0x00, 0x00, 0x00 },  /* ę to e */
2616+    { 0x011A,  0x45, 0x00, 0x00, 0x00 },  /* Ě to E */
2617+    { 0x011B,  0x65, 0x00, 0x00, 0x00 },  /* ě to e */
2618+    { 0x011C,  0x47, 0x68, 0x00, 0x00 },  /* Ĝ to Gh */
2619+    { 0x011D,  0x67, 0x68, 0x00, 0x00 },  /* ĝ to gh */
2620+    { 0x011E,  0x47, 0x00, 0x00, 0x00 },  /* Ğ to G */
2621+    { 0x011F,  0x67, 0x00, 0x00, 0x00 },  /* ğ to g */
2622+    { 0x0120,  0x47, 0x00, 0x00, 0x00 },  /* Ġ to G */
2623+    { 0x0121,  0x67, 0x00, 0x00, 0x00 },  /* ġ to g */
2624+    { 0x0122,  0x47, 0x00, 0x00, 0x00 },  /* Ģ to G */
2625+    { 0x0123,  0x67, 0x00, 0x00, 0x00 },  /* ģ to g */
2626+    { 0x0124,  0x48, 0x68, 0x00, 0x00 },  /* Ĥ to Hh */
2627+    { 0x0125,  0x68, 0x68, 0x00, 0x00 },  /* ĥ to hh */
2628+    { 0x0126,  0x48, 0x00, 0x00, 0x00 },  /* Ħ to H */
2629+    { 0x0127,  0x68, 0x00, 0x00, 0x00 },  /* ħ to h */
2630+    { 0x0128,  0x49, 0x00, 0x00, 0x00 },  /* Ĩ to I */
2631+    { 0x0129,  0x69, 0x00, 0x00, 0x00 },  /* ĩ to i */
2632+    { 0x012A,  0x49, 0x00, 0x00, 0x00 },  /* Ī to I */
2633+    { 0x012B,  0x69, 0x00, 0x00, 0x00 },  /* ī to i */
2634+    { 0x012C,  0x49, 0x00, 0x00, 0x00 },  /* Ĭ to I */
2635+    { 0x012D,  0x69, 0x00, 0x00, 0x00 },  /* ĭ to i */
2636+    { 0x012E,  0x49, 0x00, 0x00, 0x00 },  /* Į to I */
2637+    { 0x012F,  0x69, 0x00, 0x00, 0x00 },  /* į to i */
2638+    { 0x0130,  0x49, 0x00, 0x00, 0x00 },  /* İ to I */
2639+    { 0x0131,  0x69, 0x00, 0x00, 0x00 },  /* ı to i */
2640+    { 0x0132,  0x49, 0x4A, 0x00, 0x00 },  /* IJ to IJ */
2641+    { 0x0133,  0x69, 0x6A, 0x00, 0x00 },  /* ij to ij */
2642+    { 0x0134,  0x4A, 0x68, 0x00, 0x00 },  /* Ĵ to Jh */
2643+    { 0x0135,  0x6A, 0x68, 0x00, 0x00 },  /* ĵ to jh */
2644+    { 0x0136,  0x4B, 0x00, 0x00, 0x00 },  /* Ķ to K */
2645+    { 0x0137,  0x6B, 0x00, 0x00, 0x00 },  /* ķ to k */
2646+    { 0x0138,  0x6B, 0x00, 0x00, 0x00 },  /* ĸ to k */
2647+    { 0x0139,  0x4C, 0x00, 0x00, 0x00 },  /* Ĺ to L */
2648+    { 0x013A,  0x6C, 0x00, 0x00, 0x00 },  /* ĺ to l */
2649+    { 0x013B,  0x4C, 0x00, 0x00, 0x00 },  /* Ļ to L */
2650+    { 0x013C,  0x6C, 0x00, 0x00, 0x00 },  /* ļ to l */
2651+    { 0x013D,  0x4C, 0x00, 0x00, 0x00 },  /* Ľ to L */
2652+    { 0x013E,  0x6C, 0x00, 0x00, 0x00 },  /* ľ to l */
2653+    { 0x013F,  0x4C, 0x2E, 0x00, 0x00 },  /* Ŀ to L. */
2654+    { 0x0140,  0x6C, 0x2E, 0x00, 0x00 },  /* ŀ to l. */
2655+    { 0x0141,  0x4C, 0x00, 0x00, 0x00 },  /* Ł to L */
2656+    { 0x0142,  0x6C, 0x00, 0x00, 0x00 },  /* ł to l */
2657+    { 0x0143,  0x4E, 0x00, 0x00, 0x00 },  /* Ń to N */
2658+    { 0x0144,  0x6E, 0x00, 0x00, 0x00 },  /* ń to n */
2659+    { 0x0145,  0x4E, 0x00, 0x00, 0x00 },  /* Ņ to N */
2660+    { 0x0146,  0x6E, 0x00, 0x00, 0x00 },  /* ņ to n */
2661+    { 0x0147,  0x4E, 0x00, 0x00, 0x00 },  /* Ň to N */
2662+    { 0x0148,  0x6E, 0x00, 0x00, 0x00 },  /* ň to n */
2663+    { 0x0149,  0x27, 0x6E, 0x00, 0x00 },  /* ʼn to 'n */
2664+    { 0x014A,  0x4E, 0x47, 0x00, 0x00 },  /* Ŋ to NG */
2665+    { 0x014B,  0x6E, 0x67, 0x00, 0x00 },  /* ŋ to ng */
2666+    { 0x014C,  0x4F, 0x00, 0x00, 0x00 },  /* Ō to O */
2667+    { 0x014D,  0x6F, 0x00, 0x00, 0x00 },  /* ō to o */
2668+    { 0x014E,  0x4F, 0x00, 0x00, 0x00 },  /* Ŏ to O */
2669+    { 0x014F,  0x6F, 0x00, 0x00, 0x00 },  /* ŏ to o */
2670+    { 0x0150,  0x4F, 0x00, 0x00, 0x00 },  /* Ő to O */
2671+    { 0x0151,  0x6F, 0x00, 0x00, 0x00 },  /* ő to o */
2672+    { 0x0152,  0x4F, 0x45, 0x00, 0x00 },  /* Œ to OE */
2673+    { 0x0153,  0x6F, 0x65, 0x00, 0x00 },  /* œ to oe */
2674+    { 0x0154,  0x52, 0x00, 0x00, 0x00 },  /* Ŕ to R */
2675+    { 0x0155,  0x72, 0x00, 0x00, 0x00 },  /* ŕ to r */
2676+    { 0x0156,  0x52, 0x00, 0x00, 0x00 },  /* Ŗ to R */
2677+    { 0x0157,  0x72, 0x00, 0x00, 0x00 },  /* ŗ to r */
2678+    { 0x0158,  0x52, 0x00, 0x00, 0x00 },  /* Ř to R */
2679+    { 0x0159,  0x72, 0x00, 0x00, 0x00 },  /* ř to r */
2680+    { 0x015A,  0x53, 0x00, 0x00, 0x00 },  /* Ś to S */
2681+    { 0x015B,  0x73, 0x00, 0x00, 0x00 },  /* ś to s */
2682+    { 0x015C,  0x53, 0x68, 0x00, 0x00 },  /* Ŝ to Sh */
2683+    { 0x015D,  0x73, 0x68, 0x00, 0x00 },  /* ŝ to sh */
2684+    { 0x015E,  0x53, 0x00, 0x00, 0x00 },  /* Ş to S */
2685+    { 0x015F,  0x73, 0x00, 0x00, 0x00 },  /* ş to s */
2686+    { 0x0160,  0x53, 0x00, 0x00, 0x00 },  /* Š to S */
2687+    { 0x0161,  0x73, 0x00, 0x00, 0x00 },  /* š to s */
2688+    { 0x0162,  0x54, 0x00, 0x00, 0x00 },  /* Ţ to T */
2689+    { 0x0163,  0x74, 0x00, 0x00, 0x00 },  /* ţ to t */
2690+    { 0x0164,  0x54, 0x00, 0x00, 0x00 },  /* Ť to T */
2691+    { 0x0165,  0x74, 0x00, 0x00, 0x00 },  /* ť to t */
2692+    { 0x0166,  0x54, 0x00, 0x00, 0x00 },  /* Ŧ to T */
2693+    { 0x0167,  0x74, 0x00, 0x00, 0x00 },  /* ŧ to t */
2694+    { 0x0168,  0x55, 0x00, 0x00, 0x00 },  /* Ũ to U */
2695+    { 0x0169,  0x75, 0x00, 0x00, 0x00 },  /* ũ to u */
2696+    { 0x016A,  0x55, 0x00, 0x00, 0x00 },  /* Ū to U */
2697+    { 0x016B,  0x75, 0x00, 0x00, 0x00 },  /* ū to u */
2698+    { 0x016C,  0x55, 0x00, 0x00, 0x00 },  /* Ŭ to U */
2699+    { 0x016D,  0x75, 0x00, 0x00, 0x00 },  /* ŭ to u */
2700+    { 0x016E,  0x55, 0x00, 0x00, 0x00 },  /* Ů to U */
2701+    { 0x016F,  0x75, 0x00, 0x00, 0x00 },  /* ů to u */
2702+    { 0x0170,  0x55, 0x00, 0x00, 0x00 },  /* Ű to U */
2703+    { 0x0171,  0x75, 0x00, 0x00, 0x00 },  /* ű to u */
2704+    { 0x0172,  0x55, 0x00, 0x00, 0x00 },  /* Ų to U */
2705+    { 0x0173,  0x75, 0x00, 0x00, 0x00 },  /* ų to u */
2706+    { 0x0174,  0x57, 0x00, 0x00, 0x00 },  /* Ŵ to W */
2707+    { 0x0175,  0x77, 0x00, 0x00, 0x00 },  /* ŵ to w */
2708+    { 0x0176,  0x59, 0x00, 0x00, 0x00 },  /* Ŷ to Y */
2709+    { 0x0177,  0x79, 0x00, 0x00, 0x00 },  /* ŷ to y */
2710+    { 0x0178,  0x59, 0x00, 0x00, 0x00 },  /* Ÿ to Y */
2711+    { 0x0179,  0x5A, 0x00, 0x00, 0x00 },  /* Ź to Z */
2712+    { 0x017A,  0x7A, 0x00, 0x00, 0x00 },  /* ź to z */
2713+    { 0x017B,  0x5A, 0x00, 0x00, 0x00 },  /* Ż to Z */
2714+    { 0x017C,  0x7A, 0x00, 0x00, 0x00 },  /* ż to z */
2715+    { 0x017D,  0x5A, 0x00, 0x00, 0x00 },  /* Ž to Z */
2716+    { 0x017E,  0x7A, 0x00, 0x00, 0x00 },  /* ž to z */
2717+    { 0x017F,  0x73, 0x00, 0x00, 0x00 },  /* ſ to s */
2718+    { 0x0192,  0x66, 0x00, 0x00, 0x00 },  /* ƒ to f */
2719+    { 0x0218,  0x53, 0x00, 0x00, 0x00 },  /* Ș to S */
2720+    { 0x0219,  0x73, 0x00, 0x00, 0x00 },  /* ș to s */
2721+    { 0x021A,  0x54, 0x00, 0x00, 0x00 },  /* Ț to T */
2722+    { 0x021B,  0x74, 0x00, 0x00, 0x00 },  /* ț to t */
2723+    { 0x0386,  0x41, 0x00, 0x00, 0x00 },  /* Ά to A */
2724+    { 0x0388,  0x45, 0x00, 0x00, 0x00 },  /* Έ to E */
2725+    { 0x0389,  0x49, 0x00, 0x00, 0x00 },  /* Ή to I */
2726+    { 0x038A,  0x49, 0x00, 0x00, 0x00 },  /* Ί to I */
2727+    { 0x038C,  0x4f, 0x00, 0x00, 0x00 },  /* Ό to O */
2728+    { 0x038E,  0x59, 0x00, 0x00, 0x00 },  /* Ύ to Y */
2729+    { 0x038F,  0x4f, 0x00, 0x00, 0x00 },  /* Ώ to O */
2730+    { 0x0390,  0x69, 0x00, 0x00, 0x00 },  /* ΐ to i */
2731+    { 0x0391,  0x41, 0x00, 0x00, 0x00 },  /* Α to A */
2732+    { 0x0392,  0x42, 0x00, 0x00, 0x00 },  /* Β to B */
2733+    { 0x0393,  0x47, 0x00, 0x00, 0x00 },  /* Γ to G */
2734+    { 0x0394,  0x44, 0x00, 0x00, 0x00 },  /* Δ to D */
2735+    { 0x0395,  0x45, 0x00, 0x00, 0x00 },  /* Ε to E */
2736+    { 0x0396,  0x5a, 0x00, 0x00, 0x00 },  /* Ζ to Z */
2737+    { 0x0397,  0x49, 0x00, 0x00, 0x00 },  /* Η to I */
2738+    { 0x0398,  0x54, 0x68, 0x00, 0x00 },  /* Θ to Th */
2739+    { 0x0399,  0x49, 0x00, 0x00, 0x00 },  /* Ι to I */
2740+    { 0x039A,  0x4b, 0x00, 0x00, 0x00 },  /* Κ to K */
2741+    { 0x039B,  0x4c, 0x00, 0x00, 0x00 },  /* Λ to L */
2742+    { 0x039C,  0x4d, 0x00, 0x00, 0x00 },  /* Μ to M */
2743+    { 0x039D,  0x4e, 0x00, 0x00, 0x00 },  /* Ν to N */
2744+    { 0x039E,  0x58, 0x00, 0x00, 0x00 },  /* Ξ to X */
2745+    { 0x039F,  0x4f, 0x00, 0x00, 0x00 },  /* Ο to O */
2746+    { 0x03A0,  0x50, 0x00, 0x00, 0x00 },  /* Π to P */
2747+    { 0x03A1,  0x52, 0x00, 0x00, 0x00 },  /* Ρ to R */
2748+    { 0x03A3,  0x53, 0x00, 0x00, 0x00 },  /* Σ to S */
2749+    { 0x03A4,  0x54, 0x00, 0x00, 0x00 },  /* Τ to T */
2750+    { 0x03A5,  0x59, 0x00, 0x00, 0x00 },  /* Υ to Y */
2751+    { 0x03A6,  0x46, 0x00, 0x00, 0x00 },  /* Φ to F */
2752+    { 0x03A7,  0x43, 0x68, 0x00, 0x00 },  /* Χ to Ch */
2753+    { 0x03A8,  0x50, 0x73, 0x00, 0x00 },  /* Ψ to Ps */
2754+    { 0x03A9,  0x4f, 0x00, 0x00, 0x00 },  /* Ω to O */
2755+    { 0x03AA,  0x49, 0x00, 0x00, 0x00 },  /* Ϊ to I */
2756+    { 0x03AB,  0x59, 0x00, 0x00, 0x00 },  /* Ϋ to Y */
2757+    { 0x03AC,  0x61, 0x00, 0x00, 0x00 },  /* ά to a */
2758+    { 0x03AD,  0x65, 0x00, 0x00, 0x00 },  /* έ to e */
2759+    { 0x03AE,  0x69, 0x00, 0x00, 0x00 },  /* ή to i */
2760+    { 0x03AF,  0x69, 0x00, 0x00, 0x00 },  /* ί to i */
2761+    { 0x03B1,  0x61, 0x00, 0x00, 0x00 },  /* α to a */
2762+    { 0x03B2,  0x62, 0x00, 0x00, 0x00 },  /* β to b */
2763+    { 0x03B3,  0x67, 0x00, 0x00, 0x00 },  /* γ to g */
2764+    { 0x03B4,  0x64, 0x00, 0x00, 0x00 },  /* δ to d */
2765+    { 0x03B5,  0x65, 0x00, 0x00, 0x00 },  /* ε to e */
2766+    { 0x03B6,  0x7a, 0x00, 0x00, 0x00 },  /* ζ to z */
2767+    { 0x03B7,  0x69, 0x00, 0x00, 0x00 },  /* η to i */
2768+    { 0x03B8,  0x74, 0x68, 0x00, 0x00 },  /* θ to th */
2769+    { 0x03B9,  0x69, 0x00, 0x00, 0x00 },  /* ι to i */
2770+    { 0x03BA,  0x6b, 0x00, 0x00, 0x00 },  /* κ to k */
2771+    { 0x03BB,  0x6c, 0x00, 0x00, 0x00 },  /* λ to l */
2772+    { 0x03BC,  0x6d, 0x00, 0x00, 0x00 },  /* μ to m */
2773+    { 0x03BD,  0x6e, 0x00, 0x00, 0x00 },  /* ν to n */
2774+    { 0x03BE,  0x78, 0x00, 0x00, 0x00 },  /* ξ to x */
2775+    { 0x03BF,  0x6f, 0x00, 0x00, 0x00 },  /* ο to o */
2776+    { 0x03C0,  0x70, 0x00, 0x00, 0x00 },  /* π to p */
2777+    { 0x03C1,  0x72, 0x00, 0x00, 0x00 },  /* ρ to r */
2778+    { 0x03C3,  0x73, 0x00, 0x00, 0x00 },  /* σ to s */
2779+    { 0x03C4,  0x74, 0x00, 0x00, 0x00 },  /* τ to t */
2780+    { 0x03C5,  0x79, 0x00, 0x00, 0x00 },  /* υ to y */
2781+    { 0x03C6,  0x66, 0x00, 0x00, 0x00 },  /* φ to f */
2782+    { 0x03C7,  0x63, 0x68, 0x00, 0x00 },  /* χ to ch */
2783+    { 0x03C8,  0x70, 0x73, 0x00, 0x00 },  /* ψ to ps */
2784+    { 0x03C9,  0x6f, 0x00, 0x00, 0x00 },  /* ω to o */
2785+    { 0x03CA,  0x69, 0x00, 0x00, 0x00 },  /* ϊ to i */
2786+    { 0x03CB,  0x79, 0x00, 0x00, 0x00 },  /* ϋ to y */
2787+    { 0x03CC,  0x6f, 0x00, 0x00, 0x00 },  /* ό to o */
2788+    { 0x03CD,  0x79, 0x00, 0x00, 0x00 },  /* ύ to y */
2789+    { 0x03CE,  0x69, 0x00, 0x00, 0x00 },  /* ώ to i */
2790+    { 0x0400,  0x45, 0x00, 0x00, 0x00 },  /* Ѐ to E */
2791+    { 0x0401,  0x45, 0x00, 0x00, 0x00 },  /* Ё to E */
2792+    { 0x0402,  0x44, 0x00, 0x00, 0x00 },  /* Ђ to D */
2793+    { 0x0403,  0x47, 0x00, 0x00, 0x00 },  /* Ѓ to G */
2794+    { 0x0404,  0x45, 0x00, 0x00, 0x00 },  /* Є to E */
2795+    { 0x0405,  0x5a, 0x00, 0x00, 0x00 },  /* Ѕ to Z */
2796+    { 0x0406,  0x49, 0x00, 0x00, 0x00 },  /* І to I */
2797+    { 0x0407,  0x49, 0x00, 0x00, 0x00 },  /* Ї to I */
2798+    { 0x0408,  0x4a, 0x00, 0x00, 0x00 },  /* Ј to J */
2799+    { 0x0409,  0x49, 0x00, 0x00, 0x00 },  /* Љ to I */
2800+    { 0x040A,  0x4e, 0x00, 0x00, 0x00 },  /* Њ to N */
2801+    { 0x040B,  0x44, 0x00, 0x00, 0x00 },  /* Ћ to D */
2802+    { 0x040C,  0x4b, 0x00, 0x00, 0x00 },  /* Ќ to K */
2803+    { 0x040D,  0x49, 0x00, 0x00, 0x00 },  /* Ѝ to I */
2804+    { 0x040E,  0x55, 0x00, 0x00, 0x00 },  /* Ў to U */
2805+    { 0x040F,  0x44, 0x00, 0x00, 0x00 },  /* Џ to D */
2806+    { 0x0410,  0x41, 0x00, 0x00, 0x00 },  /* А to A */
2807+    { 0x0411,  0x42, 0x00, 0x00, 0x00 },  /* Б to B */
2808+    { 0x0412,  0x56, 0x00, 0x00, 0x00 },  /* В to V */
2809+    { 0x0413,  0x47, 0x00, 0x00, 0x00 },  /* Г to G */
2810+    { 0x0414,  0x44, 0x00, 0x00, 0x00 },  /* Д to D */
2811+    { 0x0415,  0x45, 0x00, 0x00, 0x00 },  /* Е to E */
2812+    { 0x0416,  0x5a, 0x68, 0x00, 0x00 },  /* Ж to Zh */
2813+    { 0x0417,  0x5a, 0x00, 0x00, 0x00 },  /* З to Z */
2814+    { 0x0418,  0x49, 0x00, 0x00, 0x00 },  /* И to I */
2815+    { 0x0419,  0x49, 0x00, 0x00, 0x00 },  /* Й to I */
2816+    { 0x041A,  0x4b, 0x00, 0x00, 0x00 },  /* К to K */
2817+    { 0x041B,  0x4c, 0x00, 0x00, 0x00 },  /* Л to L */
2818+    { 0x041C,  0x4d, 0x00, 0x00, 0x00 },  /* М to M */
2819+    { 0x041D,  0x4e, 0x00, 0x00, 0x00 },  /* Н to N */
2820+    { 0x041E,  0x4f, 0x00, 0x00, 0x00 },  /* О to O */
2821+    { 0x041F,  0x50, 0x00, 0x00, 0x00 },  /* П to P */
2822+    { 0x0420,  0x52, 0x00, 0x00, 0x00 },  /* Р to R */
2823+    { 0x0421,  0x53, 0x00, 0x00, 0x00 },  /* С to S */
2824+    { 0x0422,  0x54, 0x00, 0x00, 0x00 },  /* Т to T */
2825+    { 0x0423,  0x55, 0x00, 0x00, 0x00 },  /* У to U */
2826+    { 0x0424,  0x46, 0x00, 0x00, 0x00 },  /* Ф to F */
2827+    { 0x0425,  0x4b, 0x68, 0x00, 0x00 },  /* Х to Kh */
2828+    { 0x0426,  0x54, 0x63, 0x00, 0x00 },  /* Ц to Tc */
2829+    { 0x0427,  0x43, 0x68, 0x00, 0x00 },  /* Ч to Ch */
2830+    { 0x0428,  0x53, 0x68, 0x00, 0x00 },  /* Ш to Sh */
2831+    { 0x0429,  0x53, 0x68, 0x63, 0x68 },  /* Щ to Shch */
2832+    { 0x042A,  0x61, 0x00, 0x00, 0x00 },  /*  to A */
2833+    { 0x042B,  0x59, 0x00, 0x00, 0x00 },  /* Ы to Y */
2834+    { 0x042C,  0x59, 0x00, 0x00, 0x00 },  /*  to Y */
2835+    { 0x042D,  0x45, 0x00, 0x00, 0x00 },  /* Э to E */
2836+    { 0x042E,  0x49, 0x75, 0x00, 0x00 },  /* Ю to Iu */
2837+    { 0x042F,  0x49, 0x61, 0x00, 0x00 },  /* Я to Ia */
2838+    { 0x0430,  0x61, 0x00, 0x00, 0x00 },  /* а to a */
2839+    { 0x0431,  0x62, 0x00, 0x00, 0x00 },  /* б to b */
2840+    { 0x0432,  0x76, 0x00, 0x00, 0x00 },  /* в to v */
2841+    { 0x0433,  0x67, 0x00, 0x00, 0x00 },  /* г to g */
2842+    { 0x0434,  0x64, 0x00, 0x00, 0x00 },  /* д to d */
2843+    { 0x0435,  0x65, 0x00, 0x00, 0x00 },  /* е to e */
2844+    { 0x0436,  0x7a, 0x68, 0x00, 0x00 },  /* ж to zh */
2845+    { 0x0437,  0x7a, 0x00, 0x00, 0x00 },  /* з to z */
2846+    { 0x0438,  0x69, 0x00, 0x00, 0x00 },  /* и to i */
2847+    { 0x0439,  0x69, 0x00, 0x00, 0x00 },  /* й to i */
2848+    { 0x043A,  0x6b, 0x00, 0x00, 0x00 },  /* к to k */
2849+    { 0x043B,  0x6c, 0x00, 0x00, 0x00 },  /* л to l */
2850+    { 0x043C,  0x6d, 0x00, 0x00, 0x00 },  /* м to m */
2851+    { 0x043D,  0x6e, 0x00, 0x00, 0x00 },  /* н to n */
2852+    { 0x043E,  0x6f, 0x00, 0x00, 0x00 },  /* о to o */
2853+    { 0x043F,  0x70, 0x00, 0x00, 0x00 },  /* п to p */
2854+    { 0x0440,  0x72, 0x00, 0x00, 0x00 },  /* р to r */
2855+    { 0x0441,  0x73, 0x00, 0x00, 0x00 },  /* с to s */
2856+    { 0x0442,  0x74, 0x00, 0x00, 0x00 },  /* т to t */
2857+    { 0x0443,  0x75, 0x00, 0x00, 0x00 },  /* у to u */
2858+    { 0x0444,  0x66, 0x00, 0x00, 0x00 },  /* ф to f */
2859+    { 0x0445,  0x6b, 0x68, 0x00, 0x00 },  /* х to kh */
2860+    { 0x0446,  0x74, 0x63, 0x00, 0x00 },  /* ц to tc */
2861+    { 0x0447,  0x63, 0x68, 0x00, 0x00 },  /* ч to ch */
2862+    { 0x0448,  0x73, 0x68, 0x00, 0x00 },  /* ш to sh */
2863+    { 0x0449,  0x73, 0x68, 0x63, 0x68 },  /* щ to shch */
2864+    { 0x044A,  0x61, 0x00, 0x00, 0x00 },  /*  to a */
2865+    { 0x044B,  0x79, 0x00, 0x00, 0x00 },  /* ы to y */
2866+    { 0x044C,  0x79, 0x00, 0x00, 0x00 },  /*  to y */
2867+    { 0x044D,  0x65, 0x00, 0x00, 0x00 },  /* э to e */
2868+    { 0x044E,  0x69, 0x75, 0x00, 0x00 },  /* ю to iu */
2869+    { 0x044F,  0x69, 0x61, 0x00, 0x00 },  /* я to ia */
2870+    { 0x0450,  0x65, 0x00, 0x00, 0x00 },  /* ѐ to e */
2871+    { 0x0451,  0x65, 0x00, 0x00, 0x00 },  /* ё to e */
2872+    { 0x0452,  0x64, 0x00, 0x00, 0x00 },  /* ђ to d */
2873+    { 0x0453,  0x67, 0x00, 0x00, 0x00 },  /* ѓ to g */
2874+    { 0x0454,  0x65, 0x00, 0x00, 0x00 },  /* є to e */
2875+    { 0x0455,  0x7a, 0x00, 0x00, 0x00 },  /* ѕ to z */
2876+    { 0x0456,  0x69, 0x00, 0x00, 0x00 },  /* і to i */
2877+    { 0x0457,  0x69, 0x00, 0x00, 0x00 },  /* ї to i */
2878+    { 0x0458,  0x6a, 0x00, 0x00, 0x00 },  /* ј to j */
2879+    { 0x0459,  0x69, 0x00, 0x00, 0x00 },  /* љ to i */
2880+    { 0x045A,  0x6e, 0x00, 0x00, 0x00 },  /* њ to n */
2881+    { 0x045B,  0x64, 0x00, 0x00, 0x00 },  /* ћ to d */
2882+    { 0x045C,  0x6b, 0x00, 0x00, 0x00 },  /* ќ to k */
2883+    { 0x045D,  0x69, 0x00, 0x00, 0x00 },  /* ѝ to i */
2884+    { 0x045E,  0x75, 0x00, 0x00, 0x00 },  /* ў to u */
2885+    { 0x045F,  0x64, 0x00, 0x00, 0x00 },  /* џ to d */
2886+    { 0x1E02,  0x42, 0x00, 0x00, 0x00 },  /* Ḃ to B */
2887+    { 0x1E03,  0x62, 0x00, 0x00, 0x00 },  /* ḃ to b */
2888+    { 0x1E0A,  0x44, 0x00, 0x00, 0x00 },  /* Ḋ to D */
2889+    { 0x1E0B,  0x64, 0x00, 0x00, 0x00 },  /* ḋ to d */
2890+    { 0x1E1E,  0x46, 0x00, 0x00, 0x00 },  /* Ḟ to F */
2891+    { 0x1E1F,  0x66, 0x00, 0x00, 0x00 },  /* ḟ to f */
2892+    { 0x1E40,  0x4D, 0x00, 0x00, 0x00 },  /* Ṁ to M */
2893+    { 0x1E41,  0x6D, 0x00, 0x00, 0x00 },  /* ṁ to m */
2894+    { 0x1E56,  0x50, 0x00, 0x00, 0x00 },  /* Ṗ to P */
2895+    { 0x1E57,  0x70, 0x00, 0x00, 0x00 },  /* ṗ to p */
2896+    { 0x1E60,  0x53, 0x00, 0x00, 0x00 },  /* Ṡ to S */
2897+    { 0x1E61,  0x73, 0x00, 0x00, 0x00 },  /* ṡ to s */
2898+    { 0x1E6A,  0x54, 0x00, 0x00, 0x00 },  /* Ṫ to T */
2899+    { 0x1E6B,  0x74, 0x00, 0x00, 0x00 },  /* ṫ to t */
2900+    { 0x1E80,  0x57, 0x00, 0x00, 0x00 },  /* Ẁ to W */
2901+    { 0x1E81,  0x77, 0x00, 0x00, 0x00 },  /* ẁ to w */
2902+    { 0x1E82,  0x57, 0x00, 0x00, 0x00 },  /* Ẃ to W */
2903+    { 0x1E83,  0x77, 0x00, 0x00, 0x00 },  /* ẃ to w */
2904+    { 0x1E84,  0x57, 0x00, 0x00, 0x00 },  /* Ẅ to W */
2905+    { 0x1E85,  0x77, 0x00, 0x00, 0x00 },  /* ẅ to w */
2906+    { 0x1EF2,  0x59, 0x00, 0x00, 0x00 },  /* Ỳ to Y */
2907+    { 0x1EF3,  0x79, 0x00, 0x00, 0x00 },  /* ỳ to y */
2908+    { 0xFB00,  0x66, 0x66, 0x00, 0x00 },  /* ff to ff */
2909+    { 0xFB01,  0x66, 0x69, 0x00, 0x00 },  /* fi to fi */
2910+    { 0xFB02,  0x66, 0x6C, 0x00, 0x00 },  /* fl to fl */
2911+    { 0xFB05,  0x73, 0x74, 0x00, 0x00 },  /* ſt to st */
2912+    { 0xFB06,  0x73, 0x74, 0x00, 0x00 },  /* st to st */
2913 };
2914 
2915-static const Transliteration *spellfixFindTranslit(int c, int *pxTop){
2916-  *pxTop = (sizeof(translit)/sizeof(translit[0])) - 1;
2917-  return translit;
2918+static const Transliteration *spellfixFindTranslit(int c, int *pxTop)
2919+{
2920+    *pxTop = (sizeof(translit)/sizeof(translit[0])) - 1;
2921+    return translit;
2922 }
2923 
2924 /*
2925@@ -1710,56 +1749,57 @@ **
2926 ** Space to hold the returned string comes from sqlite3_malloc() and
2927 ** should be freed by the caller.
2928 */
2929-static unsigned char *transliterate(const unsigned char *zIn, int nIn){
2930+static unsigned char *transliterate(const unsigned char *zIn, int nIn)
2931+{
2932 #ifdef SQLITE_SPELLFIX_5BYTE_MAPPINGS
2933-  unsigned char *zOut = sqlite3_malloc64( nIn*5 + 1 );
2934+    unsigned char *zOut = sqlite3_malloc64( nIn*5 + 1 );
2935 #else
2936-  unsigned char *zOut = sqlite3_malloc64( nIn*4 + 1 );
2937+    unsigned char *zOut = sqlite3_malloc64( nIn*4 + 1 );
2938 #endif
2939-  int c, sz, nOut;
2940-  if( zOut==0 ) return 0;
2941-  nOut = 0;
2942-  while( nIn>0 ){
2943-    c = utf8Read(zIn, nIn, &sz);
2944-    zIn += sz;
2945-    nIn -= sz;
2946-    if( c<=127 ){
2947-      zOut[nOut++] = (unsigned char)c;
2948-    }else{
2949-      int xTop, xBtm, x;
2950-      const Transliteration *tbl = spellfixFindTranslit(c, &xTop);
2951-      xBtm = 0;
2952-      while( xTop>=xBtm ){
2953-        x = (xTop + xBtm)/2;
2954-        if( tbl[x].cFrom==c ){
2955-          zOut[nOut++] = tbl[x].cTo0;
2956-          if( tbl[x].cTo1 ){
2957-            zOut[nOut++] = tbl[x].cTo1;
2958-            if( tbl[x].cTo2 ){
2959-              zOut[nOut++] = tbl[x].cTo2;
2960-              if( tbl[x].cTo3 ){
2961-                zOut[nOut++] = tbl[x].cTo3;
2962+    int c, sz, nOut;
2963+    if( zOut==0 ) return 0;
2964+    nOut = 0;
2965+    while( nIn>0 ) {
2966+        c = utf8Read(zIn, nIn, &sz);
2967+        zIn += sz;
2968+        nIn -= sz;
2969+        if( c<=127 ) {
2970+            zOut[nOut++] = (unsigned char)c;
2971+        } else {
2972+            int xTop, xBtm, x;
2973+            const Transliteration *tbl = spellfixFindTranslit(c, &xTop);
2974+            xBtm = 0;
2975+            while( xTop>=xBtm ) {
2976+                x = (xTop + xBtm)/2;
2977+                if( tbl[x].cFrom==c ) {
2978+                    zOut[nOut++] = tbl[x].cTo0;
2979+                    if( tbl[x].cTo1 ) {
2980+                        zOut[nOut++] = tbl[x].cTo1;
2981+                        if( tbl[x].cTo2 ) {
2982+                            zOut[nOut++] = tbl[x].cTo2;
2983+                            if( tbl[x].cTo3 ) {
2984+                                zOut[nOut++] = tbl[x].cTo3;
2985 #ifdef SQLITE_SPELLFIX_5BYTE_MAPPINGS
2986-                if( tbl[x].cTo4 ){
2987-                  zOut[nOut++] = tbl[x].cTo4;
2988+                                if( tbl[x].cTo4 ) {
2989+                                    zOut[nOut++] = tbl[x].cTo4;
2990+                                }
2991+#endif /* SQLITE_SPELLFIX_5BYTE_MAPPINGS */
2992+                            }
2993+                        }
2994+                    }
2995+                    c = 0;
2996+                    break;
2997+                } else if( tbl[x].cFrom>c ) {
2998+                    xTop = x-1;
2999+                } else {
3000+                    xBtm = x+1;
3001                 }
3002-#endif /* SQLITE_SPELLFIX_5BYTE_MAPPINGS */
3003-              }
3004             }
3005-          }
3006-          c = 0;
3007-          break;
3008-        }else if( tbl[x].cFrom>c ){
3009-          xTop = x-1;
3010-        }else{
3011-          xBtm = x+1;
3012+            if( c ) zOut[nOut++] = '?';
3013         }
3014-      }
3015-      if( c ) zOut[nOut++] = '?';
3016     }
3017-  }
3018-  zOut[nOut] = 0;
3019-  return zOut;
3020+    zOut[nOut] = 0;
3021+    return zOut;
3022 }
3023 
3024 /*
3025@@ -1768,65 +1808,66 @@ ** string that transliterates to an ASCII string nTrans bytes or longer.
3026 ** Or, if the transliteration of the input string is less than nTrans
3027 ** bytes in size, return the number of characters in the input string.
3028 */
3029-static int translen_to_charlen(const char *zIn, int nIn, int nTrans){
3030-  int i, c, sz, nOut;
3031-  int nChar;
3032+static int translen_to_charlen(const char *zIn, int nIn, int nTrans)
3033+{
3034+    int i, c, sz, nOut;
3035+    int nChar;
3036 
3037-  i = nOut = 0;
3038-  for(nChar=0; i<nIn && nOut<nTrans; nChar++){
3039-    c = utf8Read((const unsigned char *)&zIn[i], nIn-i, &sz);
3040-    i += sz;
3041+    i = nOut = 0;
3042+    for(nChar=0; i<nIn && nOut<nTrans; nChar++) {
3043+        c = utf8Read((const unsigned char *)&zIn[i], nIn-i, &sz);
3044+        i += sz;
3045 
3046-    nOut++;
3047-    if( c>=128 ){
3048-      int xTop, xBtm, x;
3049-      const Transliteration *tbl = spellfixFindTranslit(c, &xTop);
3050-      xBtm = 0;
3051-      while( xTop>=xBtm ){
3052-        x = (xTop + xBtm)/2;
3053-        if( tbl[x].cFrom==c ){
3054-          if( tbl[x].cTo1 ){
3055-            nOut++;
3056-            if( tbl[x].cTo2 ){
3057-              nOut++;
3058-              if( tbl[x].cTo3 ){
3059-                nOut++;
3060-              }
3061+        nOut++;
3062+        if( c>=128 ) {
3063+            int xTop, xBtm, x;
3064+            const Transliteration *tbl = spellfixFindTranslit(c, &xTop);
3065+            xBtm = 0;
3066+            while( xTop>=xBtm ) {
3067+                x = (xTop + xBtm)/2;
3068+                if( tbl[x].cFrom==c ) {
3069+                    if( tbl[x].cTo1 ) {
3070+                        nOut++;
3071+                        if( tbl[x].cTo2 ) {
3072+                            nOut++;
3073+                            if( tbl[x].cTo3 ) {
3074+                                nOut++;
3075+                            }
3076+                        }
3077+                    }
3078+                    break;
3079+                } else if( tbl[x].cFrom>c ) {
3080+                    xTop = x-1;
3081+                } else {
3082+                    xBtm = x+1;
3083+                }
3084             }
3085-          }
3086-          break;
3087-        }else if( tbl[x].cFrom>c ){
3088-          xTop = x-1;
3089-        }else{
3090-          xBtm = x+1;
3091         }
3092-      }
3093     }
3094-  }
3095 
3096-  return nChar;
3097+    return nChar;
3098 }
3099-
3100 
3101 /*
3102 **    spellfix1_translit(X)
3103 **
3104-** Convert a string that contains non-ASCII Roman characters into 
3105+** Convert a string that contains non-ASCII Roman characters into
3106 ** pure ASCII.
3107 */
3108 static void transliterateSqlFunc(
3109-  sqlite3_context *context,
3110-  int argc,
3111-  sqlite3_value **argv
3112-){
3113-  const unsigned char *zIn = sqlite3_value_text(argv[0]);
3114-  int nIn = sqlite3_value_bytes(argv[0]);
3115-  unsigned char *zOut = transliterate(zIn, nIn);
3116-  if( zOut==0 ){
3117-    sqlite3_result_error_nomem(context);
3118-  }else{
3119-    sqlite3_result_text(context, (char*)zOut, -1, sqlite3_free);
3120-  }
3121+    sqlite3_context *context,
3122+    int argc,
3123+    sqlite3_value **argv
3124+)
3125+{
3126+    const unsigned char *zIn = sqlite3_value_text(argv[0]);
3127+    int nIn = sqlite3_value_bytes(argv[0]);
3128+    unsigned char *zOut = transliterate(zIn, nIn);
3129+    if( zOut==0 ) {
3130+        sqlite3_result_error_nomem(context);
3131+    } else {
3132+        sqlite3_result_text(context, (char*)zOut, -1, sqlite3_free);
3133+    }
3134 }
3135 
3136 /*
3137@@ -1846,53 +1887,68 @@ ** two or more of the above scripts or 999 if X contains no characters
3138 ** from any of the above scripts.
3139 */
3140 static void scriptCodeSqlFunc(
3141-  sqlite3_context *context,
3142-  int argc,
3143-  sqlite3_value **argv
3144-){
3145-  const unsigned char *zIn = sqlite3_value_text(argv[0]);
3146-  int nIn = sqlite3_value_bytes(argv[0]);
3147-  int c, sz;
3148-  int scriptMask = 0;
3149-  int res;
3150-  int seenDigit = 0;
3151+    sqlite3_context *context,
3152+    int argc,
3153+    sqlite3_value **argv
3154+)
3155+{
3156+    const unsigned char *zIn = sqlite3_value_text(argv[0]);
3157+    int nIn = sqlite3_value_bytes(argv[0]);
3158+    int c, sz;
3159+    int scriptMask = 0;
3160+    int res;
3161+    int seenDigit = 0;
3162 # define SCRIPT_LATIN       0x0001
3163 # define SCRIPT_CYRILLIC    0x0002
3164 # define SCRIPT_GREEK       0x0004
3165 # define SCRIPT_HEBREW      0x0008
3166 # define SCRIPT_ARABIC      0x0010
3167 
3168-  while( nIn>0 ){
3169-    c = utf8Read(zIn, nIn, &sz);
3170-    zIn += sz;
3171-    nIn -= sz;
3172-    if( c<0x02af ){
3173-      if( c>=0x80 || midClass[c&0x7f]<CCLASS_DIGIT ){
3174-        scriptMask |= SCRIPT_LATIN;
3175-      }else if( c>='0' && c<='9' ){
3176-        seenDigit = 1;
3177-      }
3178-    }else if( c>=0x0400 && c<=0x04ff ){
3179-      scriptMask |= SCRIPT_CYRILLIC;
3180-    }else if( c>=0x0386 && c<=0x03ce ){
3181-      scriptMask |= SCRIPT_GREEK;
3182-    }else if( c>=0x0590 && c<=0x05ff ){
3183-      scriptMask |= SCRIPT_HEBREW;
3184-    }else if( c>=0x0600 && c<=0x06ff ){
3185-      scriptMask |= SCRIPT_ARABIC;
3186+    while( nIn>0 ) {
3187+        c = utf8Read(zIn, nIn, &sz);
3188+        zIn += sz;
3189+        nIn -= sz;
3190+        if( c<0x02af ) {
3191+            if( c>=0x80 || midClass[c&0x7f]<CCLASS_DIGIT ) {
3192+                scriptMask |= SCRIPT_LATIN;
3193+            } else if( c>='0' && c<='9' ) {
3194+                seenDigit = 1;
3195+            }
3196+        } else if( c>=0x0400 && c<=0x04ff ) {
3197+            scriptMask |= SCRIPT_CYRILLIC;
3198+        } else if( c>=0x0386 && c<=0x03ce ) {
3199+            scriptMask |= SCRIPT_GREEK;
3200+        } else if( c>=0x0590 && c<=0x05ff ) {
3201+            scriptMask |= SCRIPT_HEBREW;
3202+        } else if( c>=0x0600 && c<=0x06ff ) {
3203+            scriptMask |= SCRIPT_ARABIC;
3204+        }
3205     }
3206-  }
3207-  if( scriptMask==0 && seenDigit ) scriptMask = SCRIPT_LATIN;
3208-  switch( scriptMask ){
3209-    case 0:                res = 999; break;
3210-    case SCRIPT_LATIN:     res = 215; break;
3211-    case SCRIPT_CYRILLIC:  res = 220; break;
3212-    case SCRIPT_GREEK:     res = 200; break;
3213-    case SCRIPT_HEBREW:    res = 125; break;
3214-    case SCRIPT_ARABIC:    res = 160; break;
3215-    default:               res = 998; break;
3216-  }
3217-  sqlite3_result_int(context, res);
3218+    if( scriptMask==0 && seenDigit ) scriptMask = SCRIPT_LATIN;
3219+    switch( scriptMask ) {
3220+    case 0:
3221+        res = 999;
3222+        break;
3223+    case SCRIPT_LATIN:
3224+        res = 215;
3225+        break;
3226+    case SCRIPT_CYRILLIC:
3227+        res = 220;
3228+        break;
3229+    case SCRIPT_GREEK:
3230+        res = 200;
3231+        break;
3232+    case SCRIPT_HEBREW:
3233+        res = 125;
3234+        break;
3235+    case SCRIPT_ARABIC:
3236+        res = 160;
3237+        break;
3238+    default:
3239+        res = 998;
3240+        break;
3241+    }
3242+    sqlite3_result_int(context, res);
3243 }
3244 
3245 /* End transliterate
3246@@ -1912,37 +1968,37 @@ typedef struct spellfix1_cursor spellfix1_cursor;
3247 
3248 /* Fuzzy-search virtual table object */
3249 struct spellfix1_vtab {
3250-  sqlite3_vtab base;         /* Base class - must be first */
3251-  sqlite3 *db;               /* Database connection */
3252-  char *zDbName;             /* Name of database holding this table */
3253-  char *zTableName;          /* Name of the virtual table */
3254-  char *zCostTable;          /* Table holding edit-distance cost numbers */
3255-  EditDist3Config *pConfig3; /* Parsed edit distance costs */
3256+    sqlite3_vtab base;         /* Base class - must be first */
3257+    sqlite3 *db;               /* Database connection */
3258+    char *zDbName;             /* Name of database holding this table */
3259+    char *zTableName;          /* Name of the virtual table */
3260+    char *zCostTable;          /* Table holding edit-distance cost numbers */
3261+    EditDist3Config *pConfig3; /* Parsed edit distance costs */
3262 };
3263 
3264 /* Fuzzy-search cursor object */
3265 struct spellfix1_cursor {
3266-  sqlite3_vtab_cursor base;    /* Base class - must be first */
3267-  spellfix1_vtab *pVTab;       /* The table to which this cursor belongs */
3268-  char *zPattern;              /* rhs of MATCH clause */
3269-  int idxNum;                  /* idxNum value passed to xFilter() */
3270-  int nRow;                    /* Number of rows of content */
3271-  int nAlloc;                  /* Number of allocated rows */
3272-  int iRow;                    /* Current row of content */
3273-  int iLang;                   /* Value of the langid= constraint */
3274-  int iTop;                    /* Value of the top= constraint */
3275-  int iScope;                  /* Value of the scope= constraint */
3276-  int nSearch;                 /* Number of vocabulary items checked */
3277-  sqlite3_stmt *pFullScan;     /* Shadow query for a full table scan */
3278-  struct spellfix1_row {       /* For each row of content */
3279-    sqlite3_int64 iRowid;         /* Rowid for this row */
3280-    char *zWord;                  /* Text for this row */
3281-    int iRank;                    /* Rank for this row */
3282-    int iDistance;                /* Distance from pattern for this row */
3283-    int iScore;                   /* Score for sorting */
3284-    int iMatchlen;                /* Value of matchlen column (or -1) */
3285-    char zHash[SPELLFIX_MX_HASH]; /* the phonehash used for this match */
3286-  } *a; 
3287+    sqlite3_vtab_cursor base;    /* Base class - must be first */
3288+    spellfix1_vtab *pVTab;       /* The table to which this cursor belongs */
3289+    char *zPattern;              /* rhs of MATCH clause */
3290+    int idxNum;                  /* idxNum value passed to xFilter() */
3291+    int nRow;                    /* Number of rows of content */
3292+    int nAlloc;                  /* Number of allocated rows */
3293+    int iRow;                    /* Current row of content */
3294+    int iLang;                   /* Value of the langid= constraint */
3295+    int iTop;                    /* Value of the top= constraint */
3296+    int iScope;                  /* Value of the scope= constraint */
3297+    int nSearch;                 /* Number of vocabulary items checked */
3298+    sqlite3_stmt *pFullScan;     /* Shadow query for a full table scan */
3299+    struct spellfix1_row {       /* For each row of content */
3300+        sqlite3_int64 iRowid;         /* Rowid for this row */
3301+        char *zWord;                  /* Text for this row */
3302+        int iRank;                    /* Rank for this row */
3303+        int iDistance;                /* Distance from pattern for this row */
3304+        int iScore;                   /* Score for sorting */
3305+        int iMatchlen;                /* Value of matchlen column (or -1) */
3306+        char zHash[SPELLFIX_MX_HASH]; /* the phonehash used for this match */
3307+    } *a;
3308 };
3309 
3310 /*
3311@@ -1953,84 +2009,90 @@ **
3312 ** If *pRc is initially non-zero then this routine is a no-op.
3313 */
3314 static void spellfix1DbExec(
3315-  int *pRc,              /* Success code */
3316-  sqlite3 *db,           /* Database in which to run SQL */
3317-  const char *zFormat,   /* Format string for SQL */
3318-  ...                    /* Arguments to the format string */
3319-){
3320-  va_list ap;
3321-  char *zSql;
3322-  if( *pRc ) return;
3323-  va_start(ap, zFormat);
3324-  zSql = sqlite3_vmprintf(zFormat, ap);
3325-  va_end(ap);
3326-  if( zSql==0 ){
3327-    *pRc = SQLITE_NOMEM;
3328-  }else{
3329-    *pRc = sqlite3_exec(db, zSql, 0, 0, 0);
3330-    sqlite3_free(zSql);
3331-  }
3332+    int *pRc,              /* Success code */
3333+    sqlite3 *db,           /* Database in which to run SQL */
3334+    const char *zFormat,   /* Format string for SQL */
3335+    ...                    /* Arguments to the format string */
3336+)
3337+{
3338+    va_list ap;
3339+    char *zSql;
3340+    if( *pRc ) return;
3341+    va_start(ap, zFormat);
3342+    zSql = sqlite3_vmprintf(zFormat, ap);
3343+    va_end(ap);
3344+    if( zSql==0 ) {
3345+        *pRc = SQLITE_NOMEM;
3346+    } else {
3347+        *pRc = sqlite3_exec(db, zSql, 0, 0, 0);
3348+        sqlite3_free(zSql);
3349+    }
3350 }
3351 
3352 /*
3353 ** xDisconnect/xDestroy method for the fuzzy-search module.
3354 */
3355-static int spellfix1Uninit(int isDestroy, sqlite3_vtab *pVTab){
3356-  spellfix1_vtab *p = (spellfix1_vtab*)pVTab;
3357-  int rc = SQLITE_OK;
3358-  if( isDestroy ){
3359-    sqlite3 *db = p->db;
3360-    spellfix1DbExec(&rc, db, "DROP TABLE IF EXISTS \"%w\".\"%w_vocab\"",
3361-                  p->zDbName, p->zTableName);
3362-  }
3363-  if( rc==SQLITE_OK ){
3364-    sqlite3_free(p->zTableName);
3365-    editDist3ConfigDelete(p->pConfig3);
3366-    sqlite3_free(p->zCostTable);
3367-    sqlite3_free(p);
3368-  }
3369-  return rc;
3370+static int spellfix1Uninit(int isDestroy, sqlite3_vtab *pVTab)
3371+{
3372+    spellfix1_vtab *p = (spellfix1_vtab*)pVTab;
3373+    int rc = SQLITE_OK;
3374+    if( isDestroy ) {
3375+        sqlite3 *db = p->db;
3376+        spellfix1DbExec(&rc, db, "DROP TABLE IF EXISTS \"%w\".\"%w_vocab\"",
3377+                        p->zDbName, p->zTableName);
3378+    }
3379+    if( rc==SQLITE_OK ) {
3380+        sqlite3_free(p->zTableName);
3381+        editDist3ConfigDelete(p->pConfig3);
3382+        sqlite3_free(p->zCostTable);
3383+        sqlite3_free(p);
3384+    }
3385+    return rc;
3386 }
3387-static int spellfix1Disconnect(sqlite3_vtab *pVTab){
3388-  return spellfix1Uninit(0, pVTab);
3389+static int spellfix1Disconnect(sqlite3_vtab *pVTab)
3390+{
3391+    return spellfix1Uninit(0, pVTab);
3392 }
3393-static int spellfix1Destroy(sqlite3_vtab *pVTab){
3394-  return spellfix1Uninit(1, pVTab);
3395+static int spellfix1Destroy(sqlite3_vtab *pVTab)
3396+{
3397+    return spellfix1Uninit(1, pVTab);
3398 }
3399 
3400 /*
3401 ** Make a copy of a string.  Remove leading and trailing whitespace
3402 ** and dequote it.
3403 */
3404-static char *spellfix1Dequote(const char *zIn){
3405-  char *zOut;
3406-  int i, j;
3407-  char c;
3408-  while( isspace((unsigned char)zIn[0]) ) zIn++;
3409-  zOut = sqlite3_mprintf("%s", zIn);
3410-  if( zOut==0 ) return 0;
3411-  i = (int)strlen(zOut);
3412+static char *spellfix1Dequote(const char *zIn)
3413+{
3414+    char *zOut;
3415+    int i, j;
3416+    char c;
3417+    while( isspace((unsigned char)zIn[0]) ) zIn++;
3418+    zOut = sqlite3_mprintf("%s", zIn);
3419+    if( zOut==0 ) return 0;
3420+    i = (int)strlen(zOut);
3421 #if 0  /* The parser will never leave spaces at the end */
3422-  while( i>0 && isspace(zOut[i-1]) ){ i--; }
3423+    while( i>0 && isspace(zOut[i-1]) ) {
3424+        i--;
3425+    }
3426 #endif
3427-  zOut[i] = 0;
3428-  c = zOut[0];
3429-  if( c=='\'' || c=='"' ){
3430-    for(i=1, j=0; ALWAYS(zOut[i]); i++){
3431-      zOut[j++] = zOut[i];
3432-      if( zOut[i]==c ){
3433-        if( zOut[i+1]==c ){
3434-          i++;
3435-        }else{
3436-          zOut[j-1] = 0;
3437-          break;
3438+    zOut[i] = 0;
3439+    c = zOut[0];
3440+    if( c=='\'' || c=='"' ) {
3441+        for(i=1, j=0; ALWAYS(zOut[i]); i++) {
3442+            zOut[j++] = zOut[i];
3443+            if( zOut[i]==c ) {
3444+                if( zOut[i+1]==c ) {
3445+                    i++;
3446+                } else {
3447+                    zOut[j-1] = 0;
3448+                    break;
3449+                }
3450+            }
3451         }
3452-      }
3453     }
3454-  }
3455-  return zOut;
3456+    return zOut;
3457 }
3458-
3459 
3460 /*
3461 ** xConnect/xCreate method for the spellfix1 module. Arguments are:
3462@@ -2041,41 +2103,42 @@ **   argv[2]   -> table name
3463 **   argv[3].. -> optional arguments (i.e. "edit_cost_table" parameter)
3464 */
3465 static int spellfix1Init(
3466-  int isCreate,
3467-  sqlite3 *db,
3468-  void *pAux,
3469-  int argc, const char *const*argv,
3470-  sqlite3_vtab **ppVTab,
3471-  char **pzErr
3472-){
3473-  spellfix1_vtab *pNew = 0;
3474-  /* const char *zModule = argv[0]; // not used */
3475-  const char *zDbName = argv[1];
3476-  const char *zTableName = argv[2];
3477-  int nDbName;
3478-  int rc = SQLITE_OK;
3479-  int i;
3480+    int isCreate,
3481+    sqlite3 *db,
3482+    void *pAux,
3483+    int argc, const char *const*argv,
3484+    sqlite3_vtab **ppVTab,
3485+    char **pzErr
3486+)
3487+{
3488+    spellfix1_vtab *pNew = 0;
3489+    /* const char *zModule = argv[0]; // not used */
3490+    const char *zDbName = argv[1];
3491+    const char *zTableName = argv[2];
3492+    int nDbName;
3493+    int rc = SQLITE_OK;
3494+    int i;
3495 
3496-  nDbName = (int)strlen(zDbName);
3497-  pNew = sqlite3_malloc64( sizeof(*pNew) + nDbName + 1);
3498-  if( pNew==0 ){
3499-    rc = SQLITE_NOMEM;
3500-  }else{
3501-    memset(pNew, 0, sizeof(*pNew));
3502-    pNew->zDbName = (char*)&pNew[1];
3503-    memcpy(pNew->zDbName, zDbName, nDbName+1);
3504-    pNew->zTableName = sqlite3_mprintf("%s", zTableName);
3505-    pNew->db = db;
3506-    if( pNew->zTableName==0 ){
3507-      rc = SQLITE_NOMEM;
3508-    }else{
3509-      sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
3510-      rc = sqlite3_declare_vtab(db, 
3511-           "CREATE TABLE x(word,rank,distance,langid, "
3512-           "score, matchlen, phonehash HIDDEN, "
3513-           "top HIDDEN, scope HIDDEN, srchcnt HIDDEN, "
3514-           "soundslike HIDDEN, command HIDDEN)"
3515-      );
3516+    nDbName = (int)strlen(zDbName);
3517+    pNew = sqlite3_malloc64( sizeof(*pNew) + nDbName + 1);
3518+    if( pNew==0 ) {
3519+        rc = SQLITE_NOMEM;
3520+    } else {
3521+        memset(pNew, 0, sizeof(*pNew));
3522+        pNew->zDbName = (char*)&pNew[1];
3523+        memcpy(pNew->zDbName, zDbName, nDbName+1);
3524+        pNew->zTableName = sqlite3_mprintf("%s", zTableName);
3525+        pNew->db = db;
3526+        if( pNew->zTableName==0 ) {
3527+            rc = SQLITE_NOMEM;
3528+        } else {
3529+            sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
3530+            rc = sqlite3_declare_vtab(db,
3531+                                      "CREATE TABLE x(word,rank,distance,langid, "
3532+                                      "score, matchlen, phonehash HIDDEN, "
3533+                                      "top HIDDEN, scope HIDDEN, srchcnt HIDDEN, "
3534+                                      "soundslike HIDDEN, command HIDDEN)"
3535+                                     );
3536 #define SPELLFIX_COL_WORD            0
3537 #define SPELLFIX_COL_RANK            1
3538 #define SPELLFIX_COL_DISTANCE        2
3539@@ -2088,113 +2151,117 @@ #define SPELLFIX_COL_SCOPE           8
3540 #define SPELLFIX_COL_SRCHCNT         9
3541 #define SPELLFIX_COL_SOUNDSLIKE     10
3542 #define SPELLFIX_COL_COMMAND        11
3543+        }
3544+        if( rc==SQLITE_OK && isCreate ) {
3545+            spellfix1DbExec(&rc, db,
3546+                            "CREATE TABLE IF NOT EXISTS \"%w\".\"%w_vocab\"(\n"
3547+                            "  id INTEGER PRIMARY KEY,\n"
3548+                            "  rank INT,\n"
3549+                            "  langid INT,\n"
3550+                            "  word TEXT,\n"
3551+                            "  k1 TEXT,\n"
3552+                            "  k2 TEXT\n"
3553+                            ");\n",
3554+                            zDbName, zTableName
3555+                           );
3556+            spellfix1DbExec(&rc, db,
3557+                            "CREATE INDEX IF NOT EXISTS \"%w\".\"%w_vocab_index_langid_k2\" "
3558+                            "ON \"%w_vocab\"(langid,k2);",
3559+                            zDbName, zTableName, zTableName
3560+                           );
3561+        }
3562+        for(i=3; rc==SQLITE_OK && i<argc; i++) {
3563+            if( strncmp(argv[i],"edit_cost_table=",16)==0 && pNew->zCostTable==0 ) {
3564+                pNew->zCostTable = spellfix1Dequote(&argv[i][16]);
3565+                if( pNew->zCostTable==0 ) rc = SQLITE_NOMEM;
3566+                continue;
3567+            }
3568+            *pzErr = sqlite3_mprintf("bad argument to spellfix1(): \"%s\"", argv[i]);
3569+            rc = SQLITE_ERROR;
3570+        }
3571     }
3572-    if( rc==SQLITE_OK && isCreate ){
3573-      spellfix1DbExec(&rc, db,
3574-         "CREATE TABLE IF NOT EXISTS \"%w\".\"%w_vocab\"(\n"
3575-         "  id INTEGER PRIMARY KEY,\n"
3576-         "  rank INT,\n"
3577-         "  langid INT,\n"
3578-         "  word TEXT,\n"
3579-         "  k1 TEXT,\n"
3580-         "  k2 TEXT\n"
3581-         ");\n",
3582-         zDbName, zTableName
3583-      );
3584-      spellfix1DbExec(&rc, db,
3585-         "CREATE INDEX IF NOT EXISTS \"%w\".\"%w_vocab_index_langid_k2\" "
3586-            "ON \"%w_vocab\"(langid,k2);",
3587-         zDbName, zTableName, zTableName
3588-      );
3589+
3590+    if( rc && pNew ) {
3591+        *ppVTab = 0;
3592+        spellfix1Uninit(0, &pNew->base);
3593+    } else {
3594+        *ppVTab = (sqlite3_vtab *)pNew;
3595     }
3596-    for(i=3; rc==SQLITE_OK && i<argc; i++){
3597-      if( strncmp(argv[i],"edit_cost_table=",16)==0 && pNew->zCostTable==0 ){
3598-        pNew->zCostTable = spellfix1Dequote(&argv[i][16]);
3599-        if( pNew->zCostTable==0 ) rc = SQLITE_NOMEM;
3600-        continue;
3601-      }
3602-      *pzErr = sqlite3_mprintf("bad argument to spellfix1(): \"%s\"", argv[i]);
3603-      rc = SQLITE_ERROR; 
3604-    }
3605-  }
3606-
3607-  if( rc && pNew ){
3608-    *ppVTab = 0;
3609-    spellfix1Uninit(0, &pNew->base);
3610-  }else{
3611-    *ppVTab = (sqlite3_vtab *)pNew;
3612-  }
3613-  return rc;
3614+    return rc;
3615 }
3616 
3617 /*
3618 ** The xConnect and xCreate methods
3619 */
3620 static int spellfix1Connect(
3621-  sqlite3 *db,
3622-  void *pAux,
3623-  int argc, const char *const*argv,
3624-  sqlite3_vtab **ppVTab,
3625-  char **pzErr
3626-){
3627-  return spellfix1Init(0, db, pAux, argc, argv, ppVTab, pzErr);
3628+    sqlite3 *db,
3629+    void *pAux,
3630+    int argc, const char *const*argv,
3631+    sqlite3_vtab **ppVTab,
3632+    char **pzErr
3633+)
3634+{
3635+    return spellfix1Init(0, db, pAux, argc, argv, ppVTab, pzErr);
3636 }
3637 static int spellfix1Create(
3638-  sqlite3 *db,
3639-  void *pAux,
3640-  int argc, const char *const*argv,
3641-  sqlite3_vtab **ppVTab,
3642-  char **pzErr
3643-){
3644-  return spellfix1Init(1, db, pAux, argc, argv, ppVTab, pzErr);
3645+    sqlite3 *db,
3646+    void *pAux,
3647+    int argc, const char *const*argv,
3648+    sqlite3_vtab **ppVTab,
3649+    char **pzErr
3650+)
3651+{
3652+    return spellfix1Init(1, db, pAux, argc, argv, ppVTab, pzErr);
3653 }
3654 
3655 /*
3656 ** Clear all of the content from a cursor.
3657 */
3658-static void spellfix1ResetCursor(spellfix1_cursor *pCur){
3659-  int i;
3660-  for(i=0; i<pCur->nRow; i++){
3661-    sqlite3_free(pCur->a[i].zWord);
3662-  }
3663-  pCur->nRow = 0;
3664-  pCur->iRow = 0;
3665-  pCur->nSearch = 0;
3666-  if( pCur->pFullScan ){
3667-    sqlite3_finalize(pCur->pFullScan);
3668-    pCur->pFullScan = 0;
3669-  }
3670+static void spellfix1ResetCursor(spellfix1_cursor *pCur)
3671+{
3672+    int i;
3673+    for(i=0; i<pCur->nRow; i++) {
3674+        sqlite3_free(pCur->a[i].zWord);
3675+    }
3676+    pCur->nRow = 0;
3677+    pCur->iRow = 0;
3678+    pCur->nSearch = 0;
3679+    if( pCur->pFullScan ) {
3680+        sqlite3_finalize(pCur->pFullScan);
3681+        pCur->pFullScan = 0;
3682+    }
3683 }
3684 
3685 /*
3686 ** Resize the cursor to hold up to N rows of content
3687 */
3688-static void spellfix1ResizeCursor(spellfix1_cursor *pCur, int N){
3689-  struct spellfix1_row *aNew;
3690-  assert( N>=pCur->nRow );
3691-  aNew = sqlite3_realloc64(pCur->a, sizeof(pCur->a[0])*N);
3692-  if( aNew==0 && N>0 ){
3693-    spellfix1ResetCursor(pCur);
3694-    sqlite3_free(pCur->a);
3695-    pCur->nAlloc = 0;
3696-    pCur->a = 0;
3697-  }else{
3698-    pCur->nAlloc = N;
3699-    pCur->a = aNew;
3700-  }
3701+static void spellfix1ResizeCursor(spellfix1_cursor *pCur, int N)
3702+{
3703+    struct spellfix1_row *aNew;
3704+    assert( N>=pCur->nRow );
3705+    aNew = sqlite3_realloc64(pCur->a, sizeof(pCur->a[0])*N);
3706+    if( aNew==0 && N>0 ) {
3707+        spellfix1ResetCursor(pCur);
3708+        sqlite3_free(pCur->a);
3709+        pCur->nAlloc = 0;
3710+        pCur->a = 0;
3711+    } else {
3712+        pCur->nAlloc = N;
3713+        pCur->a = aNew;
3714+    }
3715 }
3716-
3717 
3718 /*
3719 ** Close a fuzzy-search cursor.
3720 */
3721-static int spellfix1Close(sqlite3_vtab_cursor *cur){
3722-  spellfix1_cursor *pCur = (spellfix1_cursor *)cur;
3723-  spellfix1ResetCursor(pCur);
3724-  spellfix1ResizeCursor(pCur, 0);
3725-  sqlite3_free(pCur->zPattern);
3726-  sqlite3_free(pCur);
3727-  return SQLITE_OK;
3728+static int spellfix1Close(sqlite3_vtab_cursor *cur)
3729+{
3730+    spellfix1_cursor *pCur = (spellfix1_cursor *)cur;
3731+    spellfix1ResetCursor(pCur);
3732+    spellfix1ResizeCursor(pCur, 0);
3733+    sqlite3_free(pCur->zPattern);
3734+    sqlite3_free(pCur);
3735+    return SQLITE_OK;
3736 }
3737 
3738 #define SPELLFIX_IDXNUM_MATCH  0x01         /* word MATCH $str */
3739@@ -2214,149 +2281,153 @@ **
3740 ** filter.argv[*] values contains $str, $langid, $top, $scope and $rowid
3741 ** if specified and in that order.
3742 */
3743-static int spellfix1BestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
3744-  int iPlan = 0;
3745-  int iLangTerm = -1;
3746-  int iTopTerm = -1;
3747-  int iScopeTerm = -1;
3748-  int iDistTerm = -1;
3749-  int iRowidTerm = -1;
3750-  int i;
3751-  const struct sqlite3_index_constraint *pConstraint;
3752-  pConstraint = pIdxInfo->aConstraint;
3753-  for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
3754-    if( pConstraint->usable==0 ) continue;
3755+static int spellfix1BestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo)
3756+{
3757+    int iPlan = 0;
3758+    int iLangTerm = -1;
3759+    int iTopTerm = -1;
3760+    int iScopeTerm = -1;
3761+    int iDistTerm = -1;
3762+    int iRowidTerm = -1;
3763+    int i;
3764+    const struct sqlite3_index_constraint *pConstraint;
3765+    pConstraint = pIdxInfo->aConstraint;
3766+    for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++) {
3767+        if( pConstraint->usable==0 ) continue;
3768 
3769-    /* Terms of the form:  word MATCH $str */
3770-    if( (iPlan & SPELLFIX_IDXNUM_MATCH)==0 
3771-     && pConstraint->iColumn==SPELLFIX_COL_WORD
3772-     && pConstraint->op==SQLITE_INDEX_CONSTRAINT_MATCH
3773-    ){
3774-      iPlan |= SPELLFIX_IDXNUM_MATCH;
3775-      pIdxInfo->aConstraintUsage[i].argvIndex = 1;
3776-      pIdxInfo->aConstraintUsage[i].omit = 1;
3777-    }
3778+        /* Terms of the form:  word MATCH $str */
3779+        if( (iPlan & SPELLFIX_IDXNUM_MATCH)==0
3780+            && pConstraint->iColumn==SPELLFIX_COL_WORD
3781+            && pConstraint->op==SQLITE_INDEX_CONSTRAINT_MATCH
3782+          ) {
3783+            iPlan |= SPELLFIX_IDXNUM_MATCH;
3784+            pIdxInfo->aConstraintUsage[i].argvIndex = 1;
3785+            pIdxInfo->aConstraintUsage[i].omit = 1;
3786+        }
3787 
3788-    /* Terms of the form:  langid = $langid  */
3789-    if( (iPlan & SPELLFIX_IDXNUM_LANGID)==0
3790-     && pConstraint->iColumn==SPELLFIX_COL_LANGID
3791-     && pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ
3792-    ){
3793-      iPlan |= SPELLFIX_IDXNUM_LANGID;
3794-      iLangTerm = i;
3795-    }
3796+        /* Terms of the form:  langid = $langid  */
3797+        if( (iPlan & SPELLFIX_IDXNUM_LANGID)==0
3798+            && pConstraint->iColumn==SPELLFIX_COL_LANGID
3799+            && pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ
3800+          ) {
3801+            iPlan |= SPELLFIX_IDXNUM_LANGID;
3802+            iLangTerm = i;
3803+        }
3804 
3805-    /* Terms of the form:  top = $top */
3806-    if( (iPlan & SPELLFIX_IDXNUM_TOP)==0
3807-     && pConstraint->iColumn==SPELLFIX_COL_TOP
3808-     && pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ
3809-    ){
3810-      iPlan |= SPELLFIX_IDXNUM_TOP;
3811-      iTopTerm = i;
3812-    }
3813+        /* Terms of the form:  top = $top */
3814+        if( (iPlan & SPELLFIX_IDXNUM_TOP)==0
3815+            && pConstraint->iColumn==SPELLFIX_COL_TOP
3816+            && pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ
3817+          ) {
3818+            iPlan |= SPELLFIX_IDXNUM_TOP;
3819+            iTopTerm = i;
3820+        }
3821 
3822-    /* Terms of the form:  scope = $scope */
3823-    if( (iPlan & SPELLFIX_IDXNUM_SCOPE)==0
3824-     && pConstraint->iColumn==SPELLFIX_COL_SCOPE
3825-     && pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ
3826-    ){
3827-      iPlan |= SPELLFIX_IDXNUM_SCOPE;
3828-      iScopeTerm = i;
3829-    }
3830+        /* Terms of the form:  scope = $scope */
3831+        if( (iPlan & SPELLFIX_IDXNUM_SCOPE)==0
3832+            && pConstraint->iColumn==SPELLFIX_COL_SCOPE
3833+            && pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ
3834+          ) {
3835+            iPlan |= SPELLFIX_IDXNUM_SCOPE;
3836+            iScopeTerm = i;
3837+        }
3838 
3839-    /* Terms of the form:  distance < $dist or distance <= $dist */
3840-    if( (iPlan & SPELLFIX_IDXNUM_DIST)==0
3841-     && pConstraint->iColumn==SPELLFIX_COL_DISTANCE
3842-     && (pConstraint->op==SQLITE_INDEX_CONSTRAINT_LT
3843-          || pConstraint->op==SQLITE_INDEX_CONSTRAINT_LE)
3844-    ){
3845-      if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_LT ){
3846-        iPlan |= SPELLFIX_IDXNUM_DISTLT;
3847-      }else{
3848-        iPlan |= SPELLFIX_IDXNUM_DISTLE;
3849-      }
3850-      iDistTerm = i;
3851-    }
3852+        /* Terms of the form:  distance < $dist or distance <= $dist */
3853+        if( (iPlan & SPELLFIX_IDXNUM_DIST)==0
3854+            && pConstraint->iColumn==SPELLFIX_COL_DISTANCE
3855+            && (pConstraint->op==SQLITE_INDEX_CONSTRAINT_LT
3856+                || pConstraint->op==SQLITE_INDEX_CONSTRAINT_LE)
3857+          ) {
3858+            if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_LT ) {
3859+                iPlan |= SPELLFIX_IDXNUM_DISTLT;
3860+            } else {
3861+                iPlan |= SPELLFIX_IDXNUM_DISTLE;
3862+            }
3863+            iDistTerm = i;
3864+        }
3865 
3866-    /* Terms of the form:  distance < $dist or distance <= $dist */
3867-    if( (iPlan & SPELLFIX_IDXNUM_ROWID)==0
3868-     && pConstraint->iColumn<0
3869-     && pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ
3870-    ){
3871-      iPlan |= SPELLFIX_IDXNUM_ROWID;
3872-      iRowidTerm = i;
3873+        /* Terms of the form:  distance < $dist or distance <= $dist */
3874+        if( (iPlan & SPELLFIX_IDXNUM_ROWID)==0
3875+            && pConstraint->iColumn<0
3876+            && pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ
3877+          ) {
3878+            iPlan |= SPELLFIX_IDXNUM_ROWID;
3879+            iRowidTerm = i;
3880+        }
3881     }
3882-  }
3883-  if( iPlan&SPELLFIX_IDXNUM_MATCH ){
3884-    int idx = 2;
3885-    pIdxInfo->idxNum = iPlan;
3886-    if( pIdxInfo->nOrderBy==1
3887-     && pIdxInfo->aOrderBy[0].iColumn==SPELLFIX_COL_SCORE
3888-     && pIdxInfo->aOrderBy[0].desc==0
3889-    ){
3890-      pIdxInfo->orderByConsumed = 1;  /* Default order by iScore */
3891+    if( iPlan&SPELLFIX_IDXNUM_MATCH ) {
3892+        int idx = 2;
3893+        pIdxInfo->idxNum = iPlan;
3894+        if( pIdxInfo->nOrderBy==1
3895+            && pIdxInfo->aOrderBy[0].iColumn==SPELLFIX_COL_SCORE
3896+            && pIdxInfo->aOrderBy[0].desc==0
3897+          ) {
3898+            pIdxInfo->orderByConsumed = 1;  /* Default order by iScore */
3899+        }
3900+        if( iPlan&SPELLFIX_IDXNUM_LANGID ) {
3901+            pIdxInfo->aConstraintUsage[iLangTerm].argvIndex = idx++;
3902+            pIdxInfo->aConstraintUsage[iLangTerm].omit = 1;
3903+        }
3904+        if( iPlan&SPELLFIX_IDXNUM_TOP ) {
3905+            pIdxInfo->aConstraintUsage[iTopTerm].argvIndex = idx++;
3906+            pIdxInfo->aConstraintUsage[iTopTerm].omit = 1;
3907+        }
3908+        if( iPlan&SPELLFIX_IDXNUM_SCOPE ) {
3909+            pIdxInfo->aConstraintUsage[iScopeTerm].argvIndex = idx++;
3910+            pIdxInfo->aConstraintUsage[iScopeTerm].omit = 1;
3911+        }
3912+        if( iPlan&SPELLFIX_IDXNUM_DIST ) {
3913+            pIdxInfo->aConstraintUsage[iDistTerm].argvIndex = idx++;
3914+            pIdxInfo->aConstraintUsage[iDistTerm].omit = 1;
3915+        }
3916+        pIdxInfo->estimatedCost = 1e5;
3917+    } else if( (iPlan & SPELLFIX_IDXNUM_ROWID) ) {
3918+        pIdxInfo->idxNum = SPELLFIX_IDXNUM_ROWID;
3919+        pIdxInfo->aConstraintUsage[iRowidTerm].argvIndex = 1;
3920+        pIdxInfo->aConstraintUsage[iRowidTerm].omit = 1;
3921+        pIdxInfo->estimatedCost = 5;
3922+    } else {
3923+        pIdxInfo->idxNum = 0;
3924+        pIdxInfo->estimatedCost = 1e50;
3925     }
3926-    if( iPlan&SPELLFIX_IDXNUM_LANGID ){
3927-      pIdxInfo->aConstraintUsage[iLangTerm].argvIndex = idx++;
3928-      pIdxInfo->aConstraintUsage[iLangTerm].omit = 1;
3929-    }
3930-    if( iPlan&SPELLFIX_IDXNUM_TOP ){
3931-      pIdxInfo->aConstraintUsage[iTopTerm].argvIndex = idx++;
3932-      pIdxInfo->aConstraintUsage[iTopTerm].omit = 1;
3933-    }
3934-    if( iPlan&SPELLFIX_IDXNUM_SCOPE ){
3935-      pIdxInfo->aConstraintUsage[iScopeTerm].argvIndex = idx++;
3936-      pIdxInfo->aConstraintUsage[iScopeTerm].omit = 1;
3937-    }
3938-    if( iPlan&SPELLFIX_IDXNUM_DIST ){
3939-      pIdxInfo->aConstraintUsage[iDistTerm].argvIndex = idx++;
3940-      pIdxInfo->aConstraintUsage[iDistTerm].omit = 1;
3941-    }
3942-    pIdxInfo->estimatedCost = 1e5;
3943-  }else if( (iPlan & SPELLFIX_IDXNUM_ROWID) ){
3944-    pIdxInfo->idxNum = SPELLFIX_IDXNUM_ROWID;
3945-    pIdxInfo->aConstraintUsage[iRowidTerm].argvIndex = 1;
3946-    pIdxInfo->aConstraintUsage[iRowidTerm].omit = 1;
3947-    pIdxInfo->estimatedCost = 5;
3948-  }else{
3949-    pIdxInfo->idxNum = 0;
3950-    pIdxInfo->estimatedCost = 1e50;
3951-  }
3952-  return SQLITE_OK;
3953+    return SQLITE_OK;
3954 }
3955 
3956 /*
3957 ** Open a new fuzzy-search cursor.
3958 */
3959-static int spellfix1Open(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
3960-  spellfix1_vtab *p = (spellfix1_vtab*)pVTab;
3961-  spellfix1_cursor *pCur;
3962-  pCur = sqlite3_malloc64( sizeof(*pCur) );
3963-  if( pCur==0 ) return SQLITE_NOMEM;
3964-  memset(pCur, 0, sizeof(*pCur));
3965-  pCur->pVTab = p;
3966-  *ppCursor = &pCur->base;
3967-  return SQLITE_OK;
3968+static int spellfix1Open(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor)
3969+{
3970+    spellfix1_vtab *p = (spellfix1_vtab*)pVTab;
3971+    spellfix1_cursor *pCur;
3972+    pCur = sqlite3_malloc64( sizeof(*pCur) );
3973+    if( pCur==0 ) return SQLITE_NOMEM;
3974+    memset(pCur, 0, sizeof(*pCur));
3975+    pCur->pVTab = p;
3976+    *ppCursor = &pCur->base;
3977+    return SQLITE_OK;
3978 }
3979 
3980 /*
3981 ** Adjust a distance measurement by the words rank in order to show
3982 ** preference to common words.
3983 */
3984-static int spellfix1Score(int iDistance, int iRank){
3985-  int iLog2;
3986-  for(iLog2=0; iRank>0; iLog2++, iRank>>=1){}
3987-  return iDistance + 32 - iLog2;
3988+static int spellfix1Score(int iDistance, int iRank)
3989+{
3990+    int iLog2;
3991+    for(iLog2=0; iRank>0; iLog2++, iRank>>=1) {}
3992+    return iDistance + 32 - iLog2;
3993 }
3994 
3995 /*
3996 ** Compare two spellfix1_row objects for sorting purposes in qsort() such
3997 ** that they sort in order of increasing distance.
3998 */
3999-static int SQLITE_CDECL spellfix1RowCompare(const void *A, const void *B){
4000-  const struct spellfix1_row *a = (const struct spellfix1_row*)A;
4001-  const struct spellfix1_row *b = (const struct spellfix1_row*)B;
4002-  return a->iScore - b->iScore;
4003+static int SQLITE_CDECL spellfix1RowCompare(const void *A, const void *B)
4004+{
4005+    const struct spellfix1_row *a = (const struct spellfix1_row*)A;
4006+    const struct spellfix1_row *b = (const struct spellfix1_row*)B;
4007+    return a->iScore - b->iScore;
4008 }
4009 
4010 /*
4011@@ -2364,159 +2435,160 @@ ** A structure used to pass information from spellfix1FilterForMatch()
4012 ** into spellfix1RunQuery().
4013 */
4014 typedef struct MatchQuery {
4015-  spellfix1_cursor *pCur;          /* The cursor being queried */
4016-  sqlite3_stmt *pStmt;             /* shadow table query statment */
4017-  char zHash[SPELLFIX_MX_HASH];    /* The current phonehash for zPattern */
4018-  const char *zPattern;            /* Transliterated input string */
4019-  int nPattern;                    /* Length of zPattern */
4020-  EditDist3FromString *pMatchStr3; /* Original unicode string */
4021-  EditDist3Config *pConfig3;       /* Edit-distance cost coefficients */
4022-  const EditDist3Lang *pLang;      /* The selected language coefficients */
4023-  int iLang;                       /* The language id */
4024-  int iScope;                      /* Default scope */
4025-  int iMaxDist;                    /* Maximum allowed edit distance, or -1 */
4026-  int rc;                          /* Error code */
4027-  int nRun;                  /* Number of prior runs for the same zPattern */
4028-  char azPrior[SPELLFIX_MX_RUN][SPELLFIX_MX_HASH];  /* Prior hashes */
4029+    spellfix1_cursor *pCur;          /* The cursor being queried */
4030+    sqlite3_stmt *pStmt;             /* shadow table query statment */
4031+    char zHash[SPELLFIX_MX_HASH];    /* The current phonehash for zPattern */
4032+    const char *zPattern;            /* Transliterated input string */
4033+    int nPattern;                    /* Length of zPattern */
4034+    EditDist3FromString *pMatchStr3; /* Original unicode string */
4035+    EditDist3Config *pConfig3;       /* Edit-distance cost coefficients */
4036+    const EditDist3Lang *pLang;      /* The selected language coefficients */
4037+    int iLang;                       /* The language id */
4038+    int iScope;                      /* Default scope */
4039+    int iMaxDist;                    /* Maximum allowed edit distance, or -1 */
4040+    int rc;                          /* Error code */
4041+    int nRun;                  /* Number of prior runs for the same zPattern */
4042+    char azPrior[SPELLFIX_MX_RUN][SPELLFIX_MX_HASH];  /* Prior hashes */
4043 } MatchQuery;
4044 
4045 /*
4046 ** Run a query looking for the best matches against zPattern using
4047 ** zHash as the character class seed hash.
4048 */
4049-static void spellfix1RunQuery(MatchQuery *p, const char *zQuery, int nQuery){
4050-  const char *zK1;
4051-  const char *zWord;
4052-  int iDist;
4053-  int iRank;
4054-  int iScore;
4055-  int iWorst = 0;
4056-  int idx;
4057-  int idxWorst = -1;
4058-  int i;
4059-  int iScope = p->iScope;
4060-  spellfix1_cursor *pCur = p->pCur;
4061-  sqlite3_stmt *pStmt = p->pStmt;
4062-  char zHash1[SPELLFIX_MX_HASH];
4063-  char zHash2[SPELLFIX_MX_HASH];
4064-  char *zClass;
4065-  int nClass;
4066-  int rc;
4067+static void spellfix1RunQuery(MatchQuery *p, const char *zQuery, int nQuery)
4068+{
4069+    const char *zK1;
4070+    const char *zWord;
4071+    int iDist;
4072+    int iRank;
4073+    int iScore;
4074+    int iWorst = 0;
4075+    int idx;
4076+    int idxWorst = -1;
4077+    int i;
4078+    int iScope = p->iScope;
4079+    spellfix1_cursor *pCur = p->pCur;
4080+    sqlite3_stmt *pStmt = p->pStmt;
4081+    char zHash1[SPELLFIX_MX_HASH];
4082+    char zHash2[SPELLFIX_MX_HASH];
4083+    char *zClass;
4084+    int nClass;
4085+    int rc;
4086 
4087-  if( pCur->a==0 || p->rc ) return;   /* Prior memory allocation failure */
4088-  zClass = (char*)phoneticHash((unsigned char*)zQuery, nQuery);
4089-  if( zClass==0 ){
4090-    p->rc = SQLITE_NOMEM;
4091-    return;
4092-  }
4093-  nClass = (int)strlen(zClass);
4094-  if( nClass>SPELLFIX_MX_HASH-2 ){
4095-    nClass = SPELLFIX_MX_HASH-2;
4096-    zClass[nClass] = 0;
4097-  }
4098-  if( nClass<=iScope ){
4099-    if( nClass>2 ){
4100-      iScope = nClass-1;
4101-    }else{
4102-      iScope = nClass;
4103+    if( pCur->a==0 || p->rc ) return;   /* Prior memory allocation failure */
4104+    zClass = (char*)phoneticHash((unsigned char*)zQuery, nQuery);
4105+    if( zClass==0 ) {
4106+        p->rc = SQLITE_NOMEM;
4107+        return;
4108     }
4109-  }
4110-  memcpy(zHash1, zClass, iScope);
4111-  sqlite3_free(zClass);
4112-  zHash1[iScope] = 0;
4113-  memcpy(zHash2, zHash1, iScope);
4114-  zHash2[iScope] = 'Z';
4115-  zHash2[iScope+1] = 0;
4116-#if SPELLFIX_MX_RUN>1
4117-  for(i=0; i<p->nRun; i++){
4118-    if( strcmp(p->azPrior[i], zHash1)==0 ) return;
4119-  }
4120-#endif
4121-  assert( p->nRun<SPELLFIX_MX_RUN );
4122-  memcpy(p->azPrior[p->nRun++], zHash1, iScope+1);
4123-  if( sqlite3_bind_text(pStmt, 1, zHash1, -1, SQLITE_STATIC)==SQLITE_NOMEM
4124-   || sqlite3_bind_text(pStmt, 2, zHash2, -1, SQLITE_STATIC)==SQLITE_NOMEM
4125-  ){
4126-    p->rc = SQLITE_NOMEM;
4127-    return;
4128-  }
4129+    nClass = (int)strlen(zClass);
4130+    if( nClass>SPELLFIX_MX_HASH-2 ) {
4131+        nClass = SPELLFIX_MX_HASH-2;
4132+        zClass[nClass] = 0;
4133+    }
4134+    if( nClass<=iScope ) {
4135+        if( nClass>2 ) {
4136+            iScope = nClass-1;
4137+        } else {
4138+            iScope = nClass;
4139+        }
4140+    }
4141+    memcpy(zHash1, zClass, iScope);
4142+    sqlite3_free(zClass);
4143+    zHash1[iScope] = 0;
4144+    memcpy(zHash2, zHash1, iScope);
4145+    zHash2[iScope] = 'Z';
4146+    zHash2[iScope+1] = 0;
4147 #if SPELLFIX_MX_RUN>1
4148-  for(i=0; i<pCur->nRow; i++){
4149-    if( pCur->a[i].iScore>iWorst ){
4150-      iWorst = pCur->a[i].iScore;
4151-      idxWorst = i;
4152+    for(i=0; i<p->nRun; i++) {
4153+        if( strcmp(p->azPrior[i], zHash1)==0 ) return;
4154     }
4155-  }
4156 #endif
4157-  while( sqlite3_step(pStmt)==SQLITE_ROW ){
4158-    int iMatchlen = -1;
4159-    iRank = sqlite3_column_int(pStmt, 2);
4160-    if( p->pMatchStr3 ){
4161-      int nWord = sqlite3_column_bytes(pStmt, 1);
4162-      zWord = (const char*)sqlite3_column_text(pStmt, 1);
4163-      iDist = editDist3Core(p->pMatchStr3, zWord, nWord, p->pLang, &iMatchlen);
4164-    }else{
4165-      zK1 = (const char*)sqlite3_column_text(pStmt, 3);
4166-      if( zK1==0 ) continue;
4167-      iDist = editdist1(p->zPattern, zK1, 0);
4168-    }
4169-    if( iDist<0 ){
4170-      p->rc = SQLITE_NOMEM;
4171-      break;
4172+    assert( p->nRun<SPELLFIX_MX_RUN );
4173+    memcpy(p->azPrior[p->nRun++], zHash1, iScope+1);
4174+    if( sqlite3_bind_text(pStmt, 1, zHash1, -1, SQLITE_STATIC)==SQLITE_NOMEM
4175+        || sqlite3_bind_text(pStmt, 2, zHash2, -1, SQLITE_STATIC)==SQLITE_NOMEM
4176+      ) {
4177+        p->rc = SQLITE_NOMEM;
4178+        return;
4179     }
4180-    pCur->nSearch++;
4181-    
4182-    /* If there is a "distance < $dist" or "distance <= $dist" constraint,
4183-    ** check if this row meets it. If not, jump back up to the top of the
4184-    ** loop to process the next row. Otherwise, if the row does match the
4185-    ** distance constraint, check if the pCur->a[] array is already full.
4186-    ** If it is and no explicit "top = ?" constraint was present in the
4187-    ** query, grow the array to ensure there is room for the new entry. */
4188-    assert( (p->iMaxDist>=0)==((pCur->idxNum & SPELLFIX_IDXNUM_DIST) ? 1 : 0) );
4189-    if( p->iMaxDist>=0 ){
4190-      if( iDist>p->iMaxDist ) continue;
4191-      if( pCur->nRow>=pCur->nAlloc && (pCur->idxNum & SPELLFIX_IDXNUM_TOP)==0 ){
4192-        spellfix1ResizeCursor(pCur, pCur->nAlloc*2 + 10);
4193-        if( pCur->a==0 ) break;
4194-      }
4195+#if SPELLFIX_MX_RUN>1
4196+    for(i=0; i<pCur->nRow; i++) {
4197+        if( pCur->a[i].iScore>iWorst ) {
4198+            iWorst = pCur->a[i].iScore;
4199+            idxWorst = i;
4200+        }
4201     }
4202+#endif
4203+    while( sqlite3_step(pStmt)==SQLITE_ROW ) {
4204+        int iMatchlen = -1;
4205+        iRank = sqlite3_column_int(pStmt, 2);
4206+        if( p->pMatchStr3 ) {
4207+            int nWord = sqlite3_column_bytes(pStmt, 1);
4208+            zWord = (const char*)sqlite3_column_text(pStmt, 1);
4209+            iDist = editDist3Core(p->pMatchStr3, zWord, nWord, p->pLang, &iMatchlen);
4210+        } else {
4211+            zK1 = (const char*)sqlite3_column_text(pStmt, 3);
4212+            if( zK1==0 ) continue;
4213+            iDist = editdist1(p->zPattern, zK1, 0);
4214+        }
4215+        if( iDist<0 ) {
4216+            p->rc = SQLITE_NOMEM;
4217+            break;
4218+        }
4219+        pCur->nSearch++;
4220 
4221-    iScore = spellfix1Score(iDist,iRank);
4222-    if( pCur->nRow<pCur->nAlloc ){
4223-      idx = pCur->nRow;
4224-    }else if( iScore<iWorst ){
4225-      idx = idxWorst;
4226-      sqlite3_free(pCur->a[idx].zWord);
4227-    }else{
4228-      continue;
4229-    }
4230+        /* If there is a "distance < $dist" or "distance <= $dist" constraint,
4231+        ** check if this row meets it. If not, jump back up to the top of the
4232+        ** loop to process the next row. Otherwise, if the row does match the
4233+        ** distance constraint, check if the pCur->a[] array is already full.
4234+        ** If it is and no explicit "top = ?" constraint was present in the
4235+        ** query, grow the array to ensure there is room for the new entry. */
4236+        assert( (p->iMaxDist>=0)==((pCur->idxNum & SPELLFIX_IDXNUM_DIST) ? 1 : 0) );
4237+        if( p->iMaxDist>=0 ) {
4238+            if( iDist>p->iMaxDist ) continue;
4239+            if( pCur->nRow>=pCur->nAlloc && (pCur->idxNum & SPELLFIX_IDXNUM_TOP)==0 ) {
4240+                spellfix1ResizeCursor(pCur, pCur->nAlloc*2 + 10);
4241+                if( pCur->a==0 ) break;
4242+            }
4243+        }
4244 
4245-    pCur->a[idx].zWord = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1));
4246-    if( pCur->a[idx].zWord==0 ){
4247-      p->rc = SQLITE_NOMEM;
4248-      break;
4249-    }
4250-    pCur->a[idx].iRowid = sqlite3_column_int64(pStmt, 0);
4251-    pCur->a[idx].iRank = iRank;
4252-    pCur->a[idx].iDistance = iDist;
4253-    pCur->a[idx].iScore = iScore;
4254-    pCur->a[idx].iMatchlen = iMatchlen;
4255-    memcpy(pCur->a[idx].zHash, zHash1, iScope+1);
4256-    if( pCur->nRow<pCur->nAlloc ) pCur->nRow++;
4257-    if( pCur->nRow==pCur->nAlloc ){
4258-      iWorst = pCur->a[0].iScore;
4259-      idxWorst = 0;
4260-      for(i=1; i<pCur->nRow; i++){
4261-        iScore = pCur->a[i].iScore;
4262-        if( iWorst<iScore ){
4263-          iWorst = iScore;
4264-          idxWorst = i;
4265+        iScore = spellfix1Score(iDist,iRank);
4266+        if( pCur->nRow<pCur->nAlloc ) {
4267+            idx = pCur->nRow;
4268+        } else if( iScore<iWorst ) {
4269+            idx = idxWorst;
4270+            sqlite3_free(pCur->a[idx].zWord);
4271+        } else {
4272+            continue;
4273         }
4274-      }
4275+
4276+        pCur->a[idx].zWord = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 1));
4277+        if( pCur->a[idx].zWord==0 ) {
4278+            p->rc = SQLITE_NOMEM;
4279+            break;
4280+        }
4281+        pCur->a[idx].iRowid = sqlite3_column_int64(pStmt, 0);
4282+        pCur->a[idx].iRank = iRank;
4283+        pCur->a[idx].iDistance = iDist;
4284+        pCur->a[idx].iScore = iScore;
4285+        pCur->a[idx].iMatchlen = iMatchlen;
4286+        memcpy(pCur->a[idx].zHash, zHash1, iScope+1);
4287+        if( pCur->nRow<pCur->nAlloc ) pCur->nRow++;
4288+        if( pCur->nRow==pCur->nAlloc ) {
4289+            iWorst = pCur->a[0].iScore;
4290+            idxWorst = 0;
4291+            for(i=1; i<pCur->nRow; i++) {
4292+                iScore = pCur->a[i].iScore;
4293+                if( iWorst<iScore ) {
4294+                    iWorst = iScore;
4295+                    idxWorst = i;
4296+                }
4297+            }
4298+        }
4299     }
4300-  }
4301-  rc = sqlite3_reset(pStmt);
4302-  if( rc ) p->rc = rc;
4303+    rc = sqlite3_reset(pStmt);
4304+    if( rc ) p->rc = rc;
4305 }
4306 
4307 /*
4308@@ -2524,154 +2596,160 @@ ** This version of the xFilter method work if the MATCH term is present
4309 ** and we are doing a scan.
4310 */
4311 static int spellfix1FilterForMatch(
4312-  spellfix1_cursor *pCur,
4313-  int argc,
4314-  sqlite3_value **argv
4315-){
4316-  int idxNum = pCur->idxNum;
4317-  const unsigned char *zMatchThis;   /* RHS of the MATCH operator */
4318-  EditDist3FromString *pMatchStr3 = 0; /* zMatchThis as an editdist string */
4319-  char *zPattern;                    /* Transliteration of zMatchThis */
4320-  int nPattern;                      /* Length of zPattern */
4321-  int iLimit = 20;                   /* Max number of rows of output */
4322-  int iScope = 3;                    /* Use this many characters of zClass */
4323-  int iLang = 0;                     /* Language code */
4324-  char *zSql;                        /* SQL of shadow table query */
4325-  sqlite3_stmt *pStmt = 0;           /* Shadow table query */
4326-  int rc;                            /* Result code */
4327-  int idx = 1;                       /* Next available filter parameter */
4328-  spellfix1_vtab *p = pCur->pVTab;   /* The virtual table that owns pCur */
4329-  MatchQuery x;                      /* For passing info to RunQuery() */
4330+    spellfix1_cursor *pCur,
4331+    int argc,
4332+    sqlite3_value **argv
4333+)
4334+{
4335+    int idxNum = pCur->idxNum;
4336+    const unsigned char *zMatchThis;   /* RHS of the MATCH operator */
4337+    EditDist3FromString *pMatchStr3 = 0; /* zMatchThis as an editdist string */
4338+    char *zPattern;                    /* Transliteration of zMatchThis */
4339+    int nPattern;                      /* Length of zPattern */
4340+    int iLimit = 20;                   /* Max number of rows of output */
4341+    int iScope = 3;                    /* Use this many characters of zClass */
4342+    int iLang = 0;                     /* Language code */
4343+    char *zSql;                        /* SQL of shadow table query */
4344+    sqlite3_stmt *pStmt = 0;           /* Shadow table query */
4345+    int rc;                            /* Result code */
4346+    int idx = 1;                       /* Next available filter parameter */
4347+    spellfix1_vtab *p = pCur->pVTab;   /* The virtual table that owns pCur */
4348+    MatchQuery x;                      /* For passing info to RunQuery() */
4349 
4350-  /* Load the cost table if we have not already done so */
4351-  if( p->zCostTable!=0 && p->pConfig3==0 ){
4352-    p->pConfig3 = sqlite3_malloc64( sizeof(p->pConfig3[0]) );
4353-    if( p->pConfig3==0 ) return SQLITE_NOMEM;
4354-    memset(p->pConfig3, 0, sizeof(p->pConfig3[0]));
4355-    rc = editDist3ConfigLoad(p->pConfig3, p->db, p->zCostTable);
4356-    if( rc ) return rc;
4357-  }
4358-  memset(&x, 0, sizeof(x));
4359-  x.iScope = 3;  /* Default scope if none specified by "WHERE scope=N" */
4360-  x.iMaxDist = -1;   /* Maximum allowed edit distance */
4361+    /* Load the cost table if we have not already done so */
4362+    if( p->zCostTable!=0 && p->pConfig3==0 ) {
4363+        p->pConfig3 = sqlite3_malloc64( sizeof(p->pConfig3[0]) );
4364+        if( p->pConfig3==0 ) return SQLITE_NOMEM;
4365+        memset(p->pConfig3, 0, sizeof(p->pConfig3[0]));
4366+        rc = editDist3ConfigLoad(p->pConfig3, p->db, p->zCostTable);
4367+        if( rc ) return rc;
4368+    }
4369+    memset(&x, 0, sizeof(x));
4370+    x.iScope = 3;  /* Default scope if none specified by "WHERE scope=N" */
4371+    x.iMaxDist = -1;   /* Maximum allowed edit distance */
4372 
4373-  if( idxNum&2 ){
4374-    iLang = sqlite3_value_int(argv[idx++]);
4375-  }
4376-  if( idxNum&4 ){
4377-    iLimit = sqlite3_value_int(argv[idx++]);
4378-    if( iLimit<1 ) iLimit = 1;
4379-  }
4380-  if( idxNum&8 ){
4381-    x.iScope = sqlite3_value_int(argv[idx++]);
4382-    if( x.iScope<1 ) x.iScope = 1;
4383-    if( x.iScope>SPELLFIX_MX_HASH-2 ) x.iScope = SPELLFIX_MX_HASH-2;
4384-  }
4385-  if( idxNum&(16|32) ){
4386-    x.iMaxDist = sqlite3_value_int(argv[idx++]);
4387-    if( idxNum&16 ) x.iMaxDist--;
4388-    if( x.iMaxDist<0 ) x.iMaxDist = 0;
4389-  }
4390-  spellfix1ResetCursor(pCur);
4391-  spellfix1ResizeCursor(pCur, iLimit);
4392-  zMatchThis = sqlite3_value_text(argv[0]);
4393-  if( zMatchThis==0 ) return SQLITE_OK;
4394-  if( p->pConfig3 ){
4395-    x.pLang = editDist3FindLang(p->pConfig3, iLang);
4396-    pMatchStr3 = editDist3FromStringNew(x.pLang, (const char*)zMatchThis, -1);
4397-    if( pMatchStr3==0 ){
4398-      x.rc = SQLITE_NOMEM;
4399-      goto filter_exit;
4400+    if( idxNum&2 ) {
4401+        iLang = sqlite3_value_int(argv[idx++]);
4402     }
4403-  }else{
4404-    x.pLang = 0;
4405-  }
4406-  zPattern = (char*)transliterate(zMatchThis, sqlite3_value_bytes(argv[0]));
4407-  sqlite3_free(pCur->zPattern);
4408-  pCur->zPattern = zPattern;
4409-  if( zPattern==0 ){
4410-    x.rc = SQLITE_NOMEM;
4411-    goto filter_exit;
4412-  }
4413-  nPattern = (int)strlen(zPattern);
4414-  if( zPattern[nPattern-1]=='*' ) nPattern--;
4415-  zSql = sqlite3_mprintf(
4416-     "SELECT id, word, rank, coalesce(k1,word)"
4417-     "  FROM \"%w\".\"%w_vocab\""
4418-     " WHERE langid=%d AND k2>=?1 AND k2<?2",
4419-     p->zDbName, p->zTableName, iLang
4420-  );
4421-  if( zSql==0 ){
4422-    x.rc = SQLITE_NOMEM;
4423-    pStmt = 0;
4424-    goto filter_exit;
4425-  }
4426-  rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
4427-  sqlite3_free(zSql);
4428-  pCur->iLang = iLang;
4429-  x.pCur = pCur;
4430-  x.pStmt = pStmt;
4431-  x.zPattern = zPattern;
4432-  x.nPattern = nPattern;
4433-  x.pMatchStr3 = pMatchStr3;
4434-  x.iLang = iLang;
4435-  x.rc = rc;
4436-  x.pConfig3 = p->pConfig3;
4437-  if( x.rc==SQLITE_OK ){
4438-    spellfix1RunQuery(&x, zPattern, nPattern);
4439-  }
4440+    if( idxNum&4 ) {
4441+        iLimit = sqlite3_value_int(argv[idx++]);
4442+        if( iLimit<1 ) iLimit = 1;
4443+    }
4444+    if( idxNum&8 ) {
4445+        x.iScope = sqlite3_value_int(argv[idx++]);
4446+        if( x.iScope<1 ) x.iScope = 1;
4447+        if( x.iScope>SPELLFIX_MX_HASH-2 ) x.iScope = SPELLFIX_MX_HASH-2;
4448+    }
4449+    if( idxNum&(16|32) ) {
4450+        x.iMaxDist = sqlite3_value_int(argv[idx++]);
4451+        if( idxNum&16 ) x.iMaxDist--;
4452+        if( x.iMaxDist<0 ) x.iMaxDist = 0;
4453+    }
4454+    spellfix1ResetCursor(pCur);
4455+    spellfix1ResizeCursor(pCur, iLimit);
4456+    zMatchThis = sqlite3_value_text(argv[0]);
4457+    if( zMatchThis==0 ) return SQLITE_OK;
4458+    if( p->pConfig3 ) {
4459+        x.pLang = editDist3FindLang(p->pConfig3, iLang);
4460+        pMatchStr3 = editDist3FromStringNew(x.pLang, (const char*)zMatchThis, -1);
4461+        if( pMatchStr3==0 ) {
4462+            x.rc = SQLITE_NOMEM;
4463+            goto filter_exit;
4464+        }
4465+    } else {
4466+        x.pLang = 0;
4467+    }
4468+    zPattern = (char*)transliterate(zMatchThis, sqlite3_value_bytes(argv[0]));
4469+    sqlite3_free(pCur->zPattern);
4470+    pCur->zPattern = zPattern;
4471+    if( zPattern==0 ) {
4472+        x.rc = SQLITE_NOMEM;
4473+        goto filter_exit;
4474+    }
4475+    nPattern = (int)strlen(zPattern);
4476+    if( zPattern[nPattern-1]=='*' ) nPattern--;
4477+    zSql = sqlite3_mprintf(
4478+               "SELECT id, word, rank, coalesce(k1,word)"
4479+               "  FROM \"%w\".\"%w_vocab\""
4480+               " WHERE langid=%d AND k2>=?1 AND k2<?2",
4481+               p->zDbName, p->zTableName, iLang
4482+           );
4483+    if( zSql==0 ) {
4484+        x.rc = SQLITE_NOMEM;
4485+        pStmt = 0;
4486+        goto filter_exit;
4487+    }
4488+    rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
4489+    sqlite3_free(zSql);
4490+    pCur->iLang = iLang;
4491+    x.pCur = pCur;
4492+    x.pStmt = pStmt;
4493+    x.zPattern = zPattern;
4494+    x.nPattern = nPattern;
4495+    x.pMatchStr3 = pMatchStr3;
4496+    x.iLang = iLang;
4497+    x.rc = rc;
4498+    x.pConfig3 = p->pConfig3;
4499+    if( x.rc==SQLITE_OK ) {
4500+        spellfix1RunQuery(&x, zPattern, nPattern);
4501+    }
4502 
4503-  if( pCur->a ){
4504-    qsort(pCur->a, pCur->nRow, sizeof(pCur->a[0]), spellfix1RowCompare);
4505-    pCur->iTop = iLimit;
4506-    pCur->iScope = iScope;
4507-  }else{
4508-    x.rc = SQLITE_NOMEM;
4509-  }
4510+    if( pCur->a ) {
4511+        qsort(pCur->a, pCur->nRow, sizeof(pCur->a[0]), spellfix1RowCompare);
4512+        pCur->iTop = iLimit;
4513+        pCur->iScope = iScope;
4514+    } else {
4515+        x.rc = SQLITE_NOMEM;
4516+    }
4517 
4518 filter_exit:
4519-  sqlite3_finalize(pStmt);
4520-  editDist3FromStringDelete(pMatchStr3);
4521-  return x.rc;
4522+    sqlite3_finalize(pStmt);
4523+    editDist3FromStringDelete(pMatchStr3);
4524+    return x.rc;
4525 }
4526 
4527 /*
4528 ** This version of xFilter handles a full-table scan case
4529 */
4530 static int spellfix1FilterForFullScan(
4531-  spellfix1_cursor *pCur,
4532-  int argc,
4533-  sqlite3_value **argv
4534-){
4535-  int rc = SQLITE_OK;
4536-  int idxNum = pCur->idxNum;
4537-  char *zSql;
4538-  spellfix1_vtab *pVTab = pCur->pVTab;
4539-  spellfix1ResetCursor(pCur);
4540-  assert( idxNum==0 || idxNum==64 );
4541-  zSql = sqlite3_mprintf(
4542-     "SELECT word, rank, NULL, langid, id FROM \"%w\".\"%w_vocab\"%s",
4543-     pVTab->zDbName, pVTab->zTableName,
4544-     ((idxNum & 64) ? " WHERE rowid=?" : "")
4545-  );
4546-  if( zSql==0 ) return SQLITE_NOMEM;
4547-  rc = sqlite3_prepare_v2(pVTab->db, zSql, -1, &pCur->pFullScan, 0);
4548-  sqlite3_free(zSql);
4549-  if( rc==SQLITE_OK && (idxNum & 64) ){
4550-    assert( argc==1 );
4551-    rc = sqlite3_bind_value(pCur->pFullScan, 1, argv[0]);
4552-  }
4553-  pCur->nRow = pCur->iRow = 0;
4554-  if( rc==SQLITE_OK ){
4555-    rc = sqlite3_step(pCur->pFullScan);
4556-    if( rc==SQLITE_ROW ){ pCur->iRow = -1; rc = SQLITE_OK; }
4557-    if( rc==SQLITE_DONE ){ rc = SQLITE_OK; }
4558-  }else{
4559-    pCur->iRow = 0;
4560-  }
4561-  return rc;
4562+    spellfix1_cursor *pCur,
4563+    int argc,
4564+    sqlite3_value **argv
4565+)
4566+{
4567+    int rc = SQLITE_OK;
4568+    int idxNum = pCur->idxNum;
4569+    char *zSql;
4570+    spellfix1_vtab *pVTab = pCur->pVTab;
4571+    spellfix1ResetCursor(pCur);
4572+    assert( idxNum==0 || idxNum==64 );
4573+    zSql = sqlite3_mprintf(
4574+               "SELECT word, rank, NULL, langid, id FROM \"%w\".\"%w_vocab\"%s",
4575+               pVTab->zDbName, pVTab->zTableName,
4576+               ((idxNum & 64) ? " WHERE rowid=?" : "")
4577+           );
4578+    if( zSql==0 ) return SQLITE_NOMEM;
4579+    rc = sqlite3_prepare_v2(pVTab->db, zSql, -1, &pCur->pFullScan, 0);
4580+    sqlite3_free(zSql);
4581+    if( rc==SQLITE_OK && (idxNum & 64) ) {
4582+        assert( argc==1 );
4583+        rc = sqlite3_bind_value(pCur->pFullScan, 1, argv[0]);
4584+    }
4585+    pCur->nRow = pCur->iRow = 0;
4586+    if( rc==SQLITE_OK ) {
4587+        rc = sqlite3_step(pCur->pFullScan);
4588+        if( rc==SQLITE_ROW ) {
4589+            pCur->iRow = -1;
4590+            rc = SQLITE_OK;
4591+        }
4592+        if( rc==SQLITE_DONE ) {
4593+            rc = SQLITE_OK;
4594+        }
4595+    } else {
4596+        pCur->iRow = 0;
4597+    }
4598+    return rc;
4599 }
4600-
4601 
4602 /*
4603 ** Called to "rewind" a cursor back to the beginning so that
4604@@ -2679,145 +2757,149 @@ ** it starts its output over again.  Always called at least once
4605 ** prior to any spellfix1Column, spellfix1Rowid, or spellfix1Eof call.
4606 */
4607 static int spellfix1Filter(
4608-  sqlite3_vtab_cursor *cur, 
4609-  int idxNum, const char *idxStr,
4610-  int argc, sqlite3_value **argv
4611-){
4612-  spellfix1_cursor *pCur = (spellfix1_cursor *)cur;
4613-  int rc;
4614-  pCur->idxNum = idxNum;
4615-  if( idxNum & 1 ){
4616-    rc = spellfix1FilterForMatch(pCur, argc, argv);
4617-  }else{
4618-    rc = spellfix1FilterForFullScan(pCur, argc, argv);
4619-  }
4620-  return rc;
4621+    sqlite3_vtab_cursor *cur,
4622+    int idxNum, const char *idxStr,
4623+    int argc, sqlite3_value **argv
4624+)
4625+{
4626+    spellfix1_cursor *pCur = (spellfix1_cursor *)cur;
4627+    int rc;
4628+    pCur->idxNum = idxNum;
4629+    if( idxNum & 1 ) {
4630+        rc = spellfix1FilterForMatch(pCur, argc, argv);
4631+    } else {
4632+        rc = spellfix1FilterForFullScan(pCur, argc, argv);
4633+    }
4634+    return rc;
4635 }
4636 
4637-
4638 /*
4639 ** Advance a cursor to its next row of output
4640 */
4641-static int spellfix1Next(sqlite3_vtab_cursor *cur){
4642-  spellfix1_cursor *pCur = (spellfix1_cursor *)cur;
4643-  int rc = SQLITE_OK;
4644-  if( pCur->iRow < pCur->nRow ){
4645-    if( pCur->pFullScan ){
4646-      rc = sqlite3_step(pCur->pFullScan);
4647-      if( rc!=SQLITE_ROW ) pCur->iRow = pCur->nRow;
4648-      if( rc==SQLITE_ROW || rc==SQLITE_DONE ) rc = SQLITE_OK;
4649-    }else{
4650-      pCur->iRow++;
4651+static int spellfix1Next(sqlite3_vtab_cursor *cur)
4652+{
4653+    spellfix1_cursor *pCur = (spellfix1_cursor *)cur;
4654+    int rc = SQLITE_OK;
4655+    if( pCur->iRow < pCur->nRow ) {
4656+        if( pCur->pFullScan ) {
4657+            rc = sqlite3_step(pCur->pFullScan);
4658+            if( rc!=SQLITE_ROW ) pCur->iRow = pCur->nRow;
4659+            if( rc==SQLITE_ROW || rc==SQLITE_DONE ) rc = SQLITE_OK;
4660+        } else {
4661+            pCur->iRow++;
4662+        }
4663     }
4664-  }
4665-  return rc;
4666+    return rc;
4667 }
4668 
4669 /*
4670 ** Return TRUE if we are at the end-of-file
4671 */
4672-static int spellfix1Eof(sqlite3_vtab_cursor *cur){
4673-  spellfix1_cursor *pCur = (spellfix1_cursor *)cur;
4674-  return pCur->iRow>=pCur->nRow;
4675+static int spellfix1Eof(sqlite3_vtab_cursor *cur)
4676+{
4677+    spellfix1_cursor *pCur = (spellfix1_cursor *)cur;
4678+    return pCur->iRow>=pCur->nRow;
4679 }
4680 
4681 /*
4682 ** Return columns from the current row.
4683 */
4684 static int spellfix1Column(
4685-  sqlite3_vtab_cursor *cur,
4686-  sqlite3_context *ctx,
4687-  int i
4688-){
4689-  spellfix1_cursor *pCur = (spellfix1_cursor*)cur;
4690-  if( pCur->pFullScan ){
4691-    if( i<=SPELLFIX_COL_LANGID ){
4692-      sqlite3_result_value(ctx, sqlite3_column_value(pCur->pFullScan, i));
4693-    }else{
4694-      sqlite3_result_null(ctx);
4695+    sqlite3_vtab_cursor *cur,
4696+    sqlite3_context *ctx,
4697+    int i
4698+)
4699+{
4700+    spellfix1_cursor *pCur = (spellfix1_cursor*)cur;
4701+    if( pCur->pFullScan ) {
4702+        if( i<=SPELLFIX_COL_LANGID ) {
4703+            sqlite3_result_value(ctx, sqlite3_column_value(pCur->pFullScan, i));
4704+        } else {
4705+            sqlite3_result_null(ctx);
4706+        }
4707+        return SQLITE_OK;
4708     }
4709-    return SQLITE_OK;
4710-  }
4711-  switch( i ){
4712+    switch( i ) {
4713     case SPELLFIX_COL_WORD: {
4714-      sqlite3_result_text(ctx, pCur->a[pCur->iRow].zWord, -1, SQLITE_STATIC);
4715-      break;
4716+        sqlite3_result_text(ctx, pCur->a[pCur->iRow].zWord, -1, SQLITE_STATIC);
4717+        break;
4718     }
4719     case SPELLFIX_COL_RANK: {
4720-      sqlite3_result_int(ctx, pCur->a[pCur->iRow].iRank);
4721-      break;
4722+        sqlite3_result_int(ctx, pCur->a[pCur->iRow].iRank);
4723+        break;
4724     }
4725     case SPELLFIX_COL_DISTANCE: {
4726-      sqlite3_result_int(ctx, pCur->a[pCur->iRow].iDistance);
4727-      break;
4728+        sqlite3_result_int(ctx, pCur->a[pCur->iRow].iDistance);
4729+        break;
4730     }
4731     case SPELLFIX_COL_LANGID: {
4732-      sqlite3_result_int(ctx, pCur->iLang);
4733-      break;
4734+        sqlite3_result_int(ctx, pCur->iLang);
4735+        break;
4736     }
4737     case SPELLFIX_COL_SCORE: {
4738-      sqlite3_result_int(ctx, pCur->a[pCur->iRow].iScore);
4739-      break;
4740+        sqlite3_result_int(ctx, pCur->a[pCur->iRow].iScore);
4741+        break;
4742     }
4743     case SPELLFIX_COL_MATCHLEN: {
4744-      int iMatchlen = pCur->a[pCur->iRow].iMatchlen;
4745-      if( iMatchlen<0 ){
4746-        int nPattern = (int)strlen(pCur->zPattern);
4747-        char *zWord = pCur->a[pCur->iRow].zWord;
4748-        int nWord = (int)strlen(zWord);
4749+        int iMatchlen = pCur->a[pCur->iRow].iMatchlen;
4750+        if( iMatchlen<0 ) {
4751+            int nPattern = (int)strlen(pCur->zPattern);
4752+            char *zWord = pCur->a[pCur->iRow].zWord;
4753+            int nWord = (int)strlen(zWord);
4754 
4755-        if( nPattern>0 && pCur->zPattern[nPattern-1]=='*' ){
4756-          char *zTranslit;
4757-          int res;
4758-          zTranslit = (char *)transliterate((unsigned char *)zWord, nWord);
4759-          if( !zTranslit ) return SQLITE_NOMEM;
4760-          res = editdist1(pCur->zPattern, zTranslit, &iMatchlen);
4761-          sqlite3_free(zTranslit);
4762-          if( res<0 ) return SQLITE_NOMEM;
4763-          iMatchlen = translen_to_charlen(zWord, nWord, iMatchlen);
4764-        }else{
4765-          iMatchlen = utf8Charlen(zWord, nWord);
4766+            if( nPattern>0 && pCur->zPattern[nPattern-1]=='*' ) {
4767+                char *zTranslit;
4768+                int res;
4769+                zTranslit = (char *)transliterate((unsigned char *)zWord, nWord);
4770+                if( !zTranslit ) return SQLITE_NOMEM;
4771+                res = editdist1(pCur->zPattern, zTranslit, &iMatchlen);
4772+                sqlite3_free(zTranslit);
4773+                if( res<0 ) return SQLITE_NOMEM;
4774+                iMatchlen = translen_to_charlen(zWord, nWord, iMatchlen);
4775+            } else {
4776+                iMatchlen = utf8Charlen(zWord, nWord);
4777+            }
4778         }
4779-      }
4780 
4781-      sqlite3_result_int(ctx, iMatchlen);
4782-      break;
4783+        sqlite3_result_int(ctx, iMatchlen);
4784+        break;
4785     }
4786     case SPELLFIX_COL_PHONEHASH: {
4787-      sqlite3_result_text(ctx, pCur->a[pCur->iRow].zHash, -1, SQLITE_STATIC);
4788-      break;
4789+        sqlite3_result_text(ctx, pCur->a[pCur->iRow].zHash, -1, SQLITE_STATIC);
4790+        break;
4791     }
4792     case SPELLFIX_COL_TOP: {
4793-      sqlite3_result_int(ctx, pCur->iTop);
4794-      break;
4795+        sqlite3_result_int(ctx, pCur->iTop);
4796+        break;
4797     }
4798     case SPELLFIX_COL_SCOPE: {
4799-      sqlite3_result_int(ctx, pCur->iScope);
4800-      break;
4801+        sqlite3_result_int(ctx, pCur->iScope);
4802+        break;
4803     }
4804     case SPELLFIX_COL_SRCHCNT: {
4805-      sqlite3_result_int(ctx, pCur->nSearch);
4806-      break;
4807+        sqlite3_result_int(ctx, pCur->nSearch);
4808+        break;
4809     }
4810     default: {
4811-      sqlite3_result_null(ctx);
4812-      break;
4813+        sqlite3_result_null(ctx);
4814+        break;
4815+    }
4816     }
4817-  }
4818-  return SQLITE_OK;
4819+    return SQLITE_OK;
4820 }
4821 
4822 /*
4823 ** The rowid.
4824 */
4825-static int spellfix1Rowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
4826-  spellfix1_cursor *pCur = (spellfix1_cursor*)cur;
4827-  if( pCur->pFullScan ){
4828-    *pRowid = sqlite3_column_int64(pCur->pFullScan, 4);
4829-  }else{
4830-    *pRowid = pCur->a[pCur->iRow].iRowid;
4831-  }
4832-  return SQLITE_OK;
4833+static int spellfix1Rowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid)
4834+{
4835+    spellfix1_cursor *pCur = (spellfix1_cursor*)cur;
4836+    if( pCur->pFullScan ) {
4837+        *pRowid = sqlite3_column_int64(pCur->pFullScan, 4);
4838+    } else {
4839+        *pRowid = pCur->a[pCur->iRow].iRowid;
4840+    }
4841+    return SQLITE_OK;
4842 }
4843 
4844 /*
4845@@ -2825,234 +2907,237 @@ ** This function is called by the xUpdate() method. It returns a string
4846 ** containing the conflict mode that xUpdate() should use for the current
4847 ** operation. One of: "ROLLBACK", "IGNORE", "ABORT" or "REPLACE".
4848 */
4849-static const char *spellfix1GetConflict(sqlite3 *db){
4850-  static const char *azConflict[] = {
4851-    /* Note: Instead of "FAIL" - "ABORT". */
4852-    "ROLLBACK", "IGNORE", "ABORT", "ABORT", "REPLACE"
4853-  };
4854-  int eConflict = sqlite3_vtab_on_conflict(db);
4855+static const char *spellfix1GetConflict(sqlite3 *db)
4856+{
4857+    static const char *azConflict[] = {
4858+        /* Note: Instead of "FAIL" - "ABORT". */
4859+        "ROLLBACK", "IGNORE", "ABORT", "ABORT", "REPLACE"
4860+    };
4861+    int eConflict = sqlite3_vtab_on_conflict(db);
4862 
4863-  assert( eConflict==SQLITE_ROLLBACK || eConflict==SQLITE_IGNORE
4864-       || eConflict==SQLITE_FAIL || eConflict==SQLITE_ABORT
4865-       || eConflict==SQLITE_REPLACE
4866-  );
4867-  assert( SQLITE_ROLLBACK==1 );
4868-  assert( SQLITE_IGNORE==2 );
4869-  assert( SQLITE_FAIL==3 );
4870-  assert( SQLITE_ABORT==4 );
4871-  assert( SQLITE_REPLACE==5 );
4872+    assert( eConflict==SQLITE_ROLLBACK || eConflict==SQLITE_IGNORE
4873+            || eConflict==SQLITE_FAIL || eConflict==SQLITE_ABORT
4874+            || eConflict==SQLITE_REPLACE
4875+          );
4876+    assert( SQLITE_ROLLBACK==1 );
4877+    assert( SQLITE_IGNORE==2 );
4878+    assert( SQLITE_FAIL==3 );
4879+    assert( SQLITE_ABORT==4 );
4880+    assert( SQLITE_REPLACE==5 );
4881 
4882-  return azConflict[eConflict-1];
4883+    return azConflict[eConflict-1];
4884 }
4885 
4886 /*
4887 ** The xUpdate() method.
4888 */
4889 static int spellfix1Update(
4890-  sqlite3_vtab *pVTab,
4891-  int argc,
4892-  sqlite3_value **argv,
4893-  sqlite_int64 *pRowid
4894-){
4895-  int rc = SQLITE_OK;
4896-  sqlite3_int64 rowid, newRowid;
4897-  spellfix1_vtab *p = (spellfix1_vtab*)pVTab;
4898-  sqlite3 *db = p->db;
4899+    sqlite3_vtab *pVTab,
4900+    int argc,
4901+    sqlite3_value **argv,
4902+    sqlite_int64 *pRowid
4903+)
4904+{
4905+    int rc = SQLITE_OK;
4906+    sqlite3_int64 rowid, newRowid;
4907+    spellfix1_vtab *p = (spellfix1_vtab*)pVTab;
4908+    sqlite3 *db = p->db;
4909 
4910-  if( argc==1 ){
4911-    /* A delete operation on the rowid given by argv[0] */
4912-    rowid = *pRowid = sqlite3_value_int64(argv[0]);
4913-    spellfix1DbExec(&rc, db, "DELETE FROM \"%w\".\"%w_vocab\" "
4914-                           " WHERE id=%lld",
4915-                  p->zDbName, p->zTableName, rowid);
4916-  }else{
4917-    const unsigned char *zWord = sqlite3_value_text(argv[SPELLFIX_COL_WORD+2]);
4918-    int nWord = sqlite3_value_bytes(argv[SPELLFIX_COL_WORD+2]);
4919-    int iLang = sqlite3_value_int(argv[SPELLFIX_COL_LANGID+2]);
4920-    int iRank = sqlite3_value_int(argv[SPELLFIX_COL_RANK+2]);
4921-    const unsigned char *zSoundslike =
4922-           sqlite3_value_text(argv[SPELLFIX_COL_SOUNDSLIKE+2]);
4923-    int nSoundslike = sqlite3_value_bytes(argv[SPELLFIX_COL_SOUNDSLIKE+2]);
4924-    char *zK1, *zK2;
4925-    int i;
4926-    char c;
4927-    const char *zConflict = spellfix1GetConflict(db);
4928+    if( argc==1 ) {
4929+        /* A delete operation on the rowid given by argv[0] */
4930+        rowid = *pRowid = sqlite3_value_int64(argv[0]);
4931+        spellfix1DbExec(&rc, db, "DELETE FROM \"%w\".\"%w_vocab\" "
4932+                        " WHERE id=%lld",
4933+                        p->zDbName, p->zTableName, rowid);
4934+    } else {
4935+        const unsigned char *zWord = sqlite3_value_text(argv[SPELLFIX_COL_WORD+2]);
4936+        int nWord = sqlite3_value_bytes(argv[SPELLFIX_COL_WORD+2]);
4937+        int iLang = sqlite3_value_int(argv[SPELLFIX_COL_LANGID+2]);
4938+        int iRank = sqlite3_value_int(argv[SPELLFIX_COL_RANK+2]);
4939+        const unsigned char *zSoundslike =
4940+            sqlite3_value_text(argv[SPELLFIX_COL_SOUNDSLIKE+2]);
4941+        int nSoundslike = sqlite3_value_bytes(argv[SPELLFIX_COL_SOUNDSLIKE+2]);
4942+        char *zK1, *zK2;
4943+        int i;
4944+        char c;
4945+        const char *zConflict = spellfix1GetConflict(db);
4946 
4947-    if( zWord==0 ){
4948-      /* Inserts of the form:  INSERT INTO table(command) VALUES('xyzzy');
4949-      ** cause zWord to be NULL, so we look at the "command" column to see
4950-      ** what special actions to take */
4951-      const char *zCmd = 
4952-         (const char*)sqlite3_value_text(argv[SPELLFIX_COL_COMMAND+2]);
4953-      if( zCmd==0 ){
4954-        pVTab->zErrMsg = sqlite3_mprintf("NOT NULL constraint failed: %s.word",
4955-                                         p->zTableName);
4956-        return SQLITE_CONSTRAINT_NOTNULL;
4957-      }
4958-      if( strcmp(zCmd,"reset")==0 ){
4959-        /* Reset the  edit cost table (if there is one). */
4960-        editDist3ConfigDelete(p->pConfig3);
4961-        p->pConfig3 = 0;
4962-        return SQLITE_OK;
4963-      }
4964-      if( strncmp(zCmd,"edit_cost_table=",16)==0 ){
4965-        editDist3ConfigDelete(p->pConfig3);
4966-        p->pConfig3 = 0;
4967-        sqlite3_free(p->zCostTable);
4968-        p->zCostTable = spellfix1Dequote(zCmd+16);
4969-        if( p->zCostTable==0 ) return SQLITE_NOMEM;
4970-        if( p->zCostTable[0]==0 || sqlite3_stricmp(p->zCostTable,"null")==0 ){
4971-          sqlite3_free(p->zCostTable);
4972-          p->zCostTable = 0;
4973+        if( zWord==0 ) {
4974+            /* Inserts of the form:  INSERT INTO table(command) VALUES('xyzzy');
4975+            ** cause zWord to be NULL, so we look at the "command" column to see
4976+            ** what special actions to take */
4977+            const char *zCmd =
4978+                (const char*)sqlite3_value_text(argv[SPELLFIX_COL_COMMAND+2]);
4979+            if( zCmd==0 ) {
4980+                pVTab->zErrMsg = sqlite3_mprintf("NOT NULL constraint failed: %s.word",
4981+                                                 p->zTableName);
4982+                return SQLITE_CONSTRAINT_NOTNULL;
4983+            }
4984+            if( strcmp(zCmd,"reset")==0 ) {
4985+                /* Reset the  edit cost table (if there is one). */
4986+                editDist3ConfigDelete(p->pConfig3);
4987+                p->pConfig3 = 0;
4988+                return SQLITE_OK;
4989+            }
4990+            if( strncmp(zCmd,"edit_cost_table=",16)==0 ) {
4991+                editDist3ConfigDelete(p->pConfig3);
4992+                p->pConfig3 = 0;
4993+                sqlite3_free(p->zCostTable);
4994+                p->zCostTable = spellfix1Dequote(zCmd+16);
4995+                if( p->zCostTable==0 ) return SQLITE_NOMEM;
4996+                if( p->zCostTable[0]==0 || sqlite3_stricmp(p->zCostTable,"null")==0 ) {
4997+                    sqlite3_free(p->zCostTable);
4998+                    p->zCostTable = 0;
4999+                }
5000+                return SQLITE_OK;
5001+            }
5002+            pVTab->zErrMsg = sqlite3_mprintf("unknown value for %s.command: \"%w\"",
5003+                                             p->zTableName, zCmd);
5004+            return SQLITE_ERROR;
5005         }
5006-        return SQLITE_OK;
5007-      }
5008-      pVTab->zErrMsg = sqlite3_mprintf("unknown value for %s.command: \"%w\"",
5009-                                       p->zTableName, zCmd);
5010-      return SQLITE_ERROR;
5011-    }
5012-    if( iRank<1 ) iRank = 1;
5013-    if( zSoundslike ){
5014-      zK1 = (char*)transliterate(zSoundslike, nSoundslike);
5015-    }else{
5016-      zK1 = (char*)transliterate(zWord, nWord);
5017-    }
5018-    if( zK1==0 ) return SQLITE_NOMEM;
5019-    for(i=0; (c = zK1[i])!=0; i++){
5020-       if( c>='A' && c<='Z' ) zK1[i] += 'a' - 'A';
5021-    }
5022-    zK2 = (char*)phoneticHash((const unsigned char*)zK1, i);
5023-    if( zK2==0 ){
5024-      sqlite3_free(zK1);
5025-      return SQLITE_NOMEM;
5026-    }
5027-    if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
5028-      if( sqlite3_value_type(argv[1])==SQLITE_NULL ){
5029-        spellfix1DbExec(&rc, db,
5030-               "INSERT INTO \"%w\".\"%w_vocab\"(rank,langid,word,k1,k2) "
5031-               "VALUES(%d,%d,%Q,nullif(%Q,%Q),%Q)",
5032-               p->zDbName, p->zTableName,
5033-               iRank, iLang, zWord, zK1, zWord, zK2
5034-        );
5035-      }else{
5036-        newRowid = sqlite3_value_int64(argv[1]);
5037-        spellfix1DbExec(&rc, db,
5038-            "INSERT OR %s INTO \"%w\".\"%w_vocab\"(id,rank,langid,word,k1,k2) "
5039-            "VALUES(%lld,%d,%d,%Q,nullif(%Q,%Q),%Q)",
5040-            zConflict, p->zDbName, p->zTableName,
5041-            newRowid, iRank, iLang, zWord, zK1, zWord, zK2
5042-        );
5043-      }
5044-      *pRowid = sqlite3_last_insert_rowid(db);
5045-    }else{
5046-      rowid = sqlite3_value_int64(argv[0]);
5047-      newRowid = *pRowid = sqlite3_value_int64(argv[1]);
5048-      spellfix1DbExec(&rc, db,
5049-             "UPDATE OR %s \"%w\".\"%w_vocab\" SET id=%lld, rank=%d, langid=%d,"
5050-             " word=%Q, k1=nullif(%Q,%Q), k2=%Q WHERE id=%lld",
5051-             zConflict, p->zDbName, p->zTableName, newRowid, iRank, iLang,
5052-             zWord, zK1, zWord, zK2, rowid
5053-      );
5054+        if( iRank<1 ) iRank = 1;
5055+        if( zSoundslike ) {
5056+            zK1 = (char*)transliterate(zSoundslike, nSoundslike);
5057+        } else {
5058+            zK1 = (char*)transliterate(zWord, nWord);
5059+        }
5060+        if( zK1==0 ) return SQLITE_NOMEM;
5061+        for(i=0; (c = zK1[i])!=0; i++) {
5062+            if( c>='A' && c<='Z' ) zK1[i] += 'a' - 'A';
5063+        }
5064+        zK2 = (char*)phoneticHash((const unsigned char*)zK1, i);
5065+        if( zK2==0 ) {
5066+            sqlite3_free(zK1);
5067+            return SQLITE_NOMEM;
5068+        }
5069+        if( sqlite3_value_type(argv[0])==SQLITE_NULL ) {
5070+            if( sqlite3_value_type(argv[1])==SQLITE_NULL ) {
5071+                spellfix1DbExec(&rc, db,
5072+                                "INSERT INTO \"%w\".\"%w_vocab\"(rank,langid,word,k1,k2) "
5073+                                "VALUES(%d,%d,%Q,nullif(%Q,%Q),%Q)",
5074+                                p->zDbName, p->zTableName,
5075+                                iRank, iLang, zWord, zK1, zWord, zK2
5076+                               );
5077+            } else {
5078+                newRowid = sqlite3_value_int64(argv[1]);
5079+                spellfix1DbExec(&rc, db,
5080+                                "INSERT OR %s INTO \"%w\".\"%w_vocab\"(id,rank,langid,word,k1,k2) "
5081+                                "VALUES(%lld,%d,%d,%Q,nullif(%Q,%Q),%Q)",
5082+                                zConflict, p->zDbName, p->zTableName,
5083+                                newRowid, iRank, iLang, zWord, zK1, zWord, zK2
5084+                               );
5085+            }
5086+            *pRowid = sqlite3_last_insert_rowid(db);
5087+        } else {
5088+            rowid = sqlite3_value_int64(argv[0]);
5089+            newRowid = *pRowid = sqlite3_value_int64(argv[1]);
5090+            spellfix1DbExec(&rc, db,
5091+                            "UPDATE OR %s \"%w\".\"%w_vocab\" SET id=%lld, rank=%d, langid=%d,"
5092+                            " word=%Q, k1=nullif(%Q,%Q), k2=%Q WHERE id=%lld",
5093+                            zConflict, p->zDbName, p->zTableName, newRowid, iRank, iLang,
5094+                            zWord, zK1, zWord, zK2, rowid
5095+                           );
5096+        }
5097+        sqlite3_free(zK1);
5098+        sqlite3_free(zK2);
5099     }
5100-    sqlite3_free(zK1);
5101-    sqlite3_free(zK2);
5102-  }
5103-  return rc;
5104+    return rc;
5105 }
5106 
5107 /*
5108 ** Rename the spellfix1 table.
5109 */
5110-static int spellfix1Rename(sqlite3_vtab *pVTab, const char *zNew){
5111-  spellfix1_vtab *p = (spellfix1_vtab*)pVTab;
5112-  sqlite3 *db = p->db;
5113-  int rc = SQLITE_OK;
5114-  char *zNewName = sqlite3_mprintf("%s", zNew);
5115-  if( zNewName==0 ){
5116-    return SQLITE_NOMEM;
5117-  }
5118-  spellfix1DbExec(&rc, db, 
5119-     "ALTER TABLE \"%w\".\"%w_vocab\" RENAME TO \"%w_vocab\"",
5120-     p->zDbName, p->zTableName, zNewName
5121-  );
5122-  if( rc==SQLITE_OK ){
5123-    sqlite3_free(p->zTableName);
5124-    p->zTableName = zNewName;
5125-  }else{
5126-    sqlite3_free(zNewName);
5127-  }
5128-  return rc;
5129+static int spellfix1Rename(sqlite3_vtab *pVTab, const char *zNew)
5130+{
5131+    spellfix1_vtab *p = (spellfix1_vtab*)pVTab;
5132+    sqlite3 *db = p->db;
5133+    int rc = SQLITE_OK;
5134+    char *zNewName = sqlite3_mprintf("%s", zNew);
5135+    if( zNewName==0 ) {
5136+        return SQLITE_NOMEM;
5137+    }
5138+    spellfix1DbExec(&rc, db,
5139+                    "ALTER TABLE \"%w\".\"%w_vocab\" RENAME TO \"%w_vocab\"",
5140+                    p->zDbName, p->zTableName, zNewName
5141+                   );
5142+    if( rc==SQLITE_OK ) {
5143+        sqlite3_free(p->zTableName);
5144+        p->zTableName = zNewName;
5145+    } else {
5146+        sqlite3_free(zNewName);
5147+    }
5148+    return rc;
5149 }
5150 
5151-
5152 /*
5153 ** A virtual table module that provides fuzzy search.
5154 */
5155 static sqlite3_module spellfix1Module = {
5156-  0,                       /* iVersion */
5157-  spellfix1Create,         /* xCreate - handle CREATE VIRTUAL TABLE */
5158-  spellfix1Connect,        /* xConnect - reconnected to an existing table */
5159-  spellfix1BestIndex,      /* xBestIndex - figure out how to do a query */
5160-  spellfix1Disconnect,     /* xDisconnect - close a connection */
5161-  spellfix1Destroy,        /* xDestroy - handle DROP TABLE */
5162-  spellfix1Open,           /* xOpen - open a cursor */
5163-  spellfix1Close,          /* xClose - close a cursor */
5164-  spellfix1Filter,         /* xFilter - configure scan constraints */
5165-  spellfix1Next,           /* xNext - advance a cursor */
5166-  spellfix1Eof,            /* xEof - check for end of scan */
5167-  spellfix1Column,         /* xColumn - read data */
5168-  spellfix1Rowid,          /* xRowid - read data */
5169-  spellfix1Update,         /* xUpdate */
5170-  0,                       /* xBegin */
5171-  0,                       /* xSync */
5172-  0,                       /* xCommit */
5173-  0,                       /* xRollback */
5174-  0,                       /* xFindMethod */
5175-  spellfix1Rename,         /* xRename */
5176-  0,                       /* xSavepoint */
5177-  0,                       /* xRelease */
5178-  0,                       /* xRollbackTo */
5179-  0,                       /* xShadowName */
5180-  0                        /* xIntegrity */
5181+    0,                       /* iVersion */
5182+    spellfix1Create,         /* xCreate - handle CREATE VIRTUAL TABLE */
5183+    spellfix1Connect,        /* xConnect - reconnected to an existing table */
5184+    spellfix1BestIndex,      /* xBestIndex - figure out how to do a query */
5185+    spellfix1Disconnect,     /* xDisconnect - close a connection */
5186+    spellfix1Destroy,        /* xDestroy - handle DROP TABLE */
5187+    spellfix1Open,           /* xOpen - open a cursor */
5188+    spellfix1Close,          /* xClose - close a cursor */
5189+    spellfix1Filter,         /* xFilter - configure scan constraints */
5190+    spellfix1Next,           /* xNext - advance a cursor */
5191+    spellfix1Eof,            /* xEof - check for end of scan */
5192+    spellfix1Column,         /* xColumn - read data */
5193+    spellfix1Rowid,          /* xRowid - read data */
5194+    spellfix1Update,         /* xUpdate */
5195+    0,                       /* xBegin */
5196+    0,                       /* xSync */
5197+    0,                       /* xCommit */
5198+    0,                       /* xRollback */
5199+    0,                       /* xFindMethod */
5200+    spellfix1Rename,         /* xRename */
5201+    0,                       /* xSavepoint */
5202+    0,                       /* xRelease */
5203+    0,                       /* xRollbackTo */
5204+    0,                       /* xShadowName */
5205+    0                        /* xIntegrity */
5206 };
5207 
5208 /*
5209 ** Register the various functions and the virtual table.
5210 */
5211-static int spellfix1Register(sqlite3 *db){
5212-  int rc = SQLITE_OK;
5213-  int i;
5214-  rc = sqlite3_create_function(db, "spellfix1_translit", 1,
5215-                               SQLITE_UTF8|SQLITE_DETERMINISTIC, 0,
5216-                                transliterateSqlFunc, 0, 0);
5217-  if( rc==SQLITE_OK ){
5218-    rc = sqlite3_create_function(db, "spellfix1_editdist", 2,
5219+static int spellfix1Register(sqlite3 *db)
5220+{
5221+    int rc = SQLITE_OK;
5222+    int i;
5223+    rc = sqlite3_create_function(db, "spellfix1_translit", 1,
5224                                  SQLITE_UTF8|SQLITE_DETERMINISTIC, 0,
5225-                                  editdistSqlFunc, 0, 0);
5226-  }
5227-  if( rc==SQLITE_OK ){
5228-    rc = sqlite3_create_function(db, "spellfix1_phonehash", 1,
5229-                                 SQLITE_UTF8|SQLITE_DETERMINISTIC, 0,
5230-                                  phoneticHashSqlFunc, 0, 0);
5231-  }
5232-  if( rc==SQLITE_OK ){
5233-    rc = sqlite3_create_function(db, "spellfix1_scriptcode", 1,
5234-                                  SQLITE_UTF8|SQLITE_DETERMINISTIC, 0,
5235-                                  scriptCodeSqlFunc, 0, 0);
5236-  }
5237-  if( rc==SQLITE_OK ){
5238-    rc = sqlite3_create_module(db, "spellfix1", &spellfix1Module, 0);
5239-  }
5240-  if( rc==SQLITE_OK ){
5241-    rc = editDist3Install(db);
5242-  }
5243+                                 transliterateSqlFunc, 0, 0);
5244+    if( rc==SQLITE_OK ) {
5245+        rc = sqlite3_create_function(db, "spellfix1_editdist", 2,
5246+                                     SQLITE_UTF8|SQLITE_DETERMINISTIC, 0,
5247+                                     editdistSqlFunc, 0, 0);
5248+    }
5249+    if( rc==SQLITE_OK ) {
5250+        rc = sqlite3_create_function(db, "spellfix1_phonehash", 1,
5251+                                     SQLITE_UTF8|SQLITE_DETERMINISTIC, 0,
5252+                                     phoneticHashSqlFunc, 0, 0);
5253+    }
5254+    if( rc==SQLITE_OK ) {
5255+        rc = sqlite3_create_function(db, "spellfix1_scriptcode", 1,
5256+                                     SQLITE_UTF8|SQLITE_DETERMINISTIC, 0,
5257+                                     scriptCodeSqlFunc, 0, 0);
5258+    }
5259+    if( rc==SQLITE_OK ) {
5260+        rc = sqlite3_create_module(db, "spellfix1", &spellfix1Module, 0);
5261+    }
5262+    if( rc==SQLITE_OK ) {
5263+        rc = editDist3Install(db);
5264+    }
5265 
5266-  /* Verify sanity of the translit[] table */
5267-  for(i=0; i<sizeof(translit)/sizeof(translit[0])-1; i++){
5268-    assert( translit[i].cFrom<translit[i+1].cFrom );
5269-  }
5270+    /* Verify sanity of the translit[] table */
5271+    for(i=0; i<sizeof(translit)/sizeof(translit[0])-1; i++) {
5272+        assert( translit[i].cFrom<translit[i+1].cFrom );
5273+    }
5274 
5275-  return rc;
5276+    return rc;
5277 }
5278 
5279 #endif /* SQLITE_OMIT_VIRTUALTABLE */
5280@@ -3064,13 +3149,14 @@ #ifdef _WIN32
5281 __declspec(dllexport)
5282 #endif
5283 int sqlite3_spellfix_init(
5284-  sqlite3 *db, 
5285-  char **pzErrMsg, 
5286-  const sqlite3_api_routines *pApi
5287-){
5288-  SQLITE_EXTENSION_INIT2(pApi);
5289+    sqlite3 *db,
5290+    char **pzErrMsg,
5291+    const sqlite3_api_routines *pApi
5292+)
5293+{
5294+    SQLITE_EXTENSION_INIT2(pApi);
5295 #ifndef SQLITE_OMIT_VIRTUALTABLE
5296-  return spellfix1Register(db);
5297+    return spellfix1Register(db);
5298 #endif
5299-  return SQLITE_OK;
5300+    return SQLITE_OK;
5301 }
5302diff --git a/importer/main.c b/importer/main.c
5303index d03774569333e62028a03a3789df97878026daf6..b83e85086c5fac3b57c0fb27dfd4e7fd041282c8 100644
5304--- a/importer/main.c
5305+++ b/importer/main.c
5306@@ -7,27 +7,27 @@ #include "../lib/data.h"
5307 
5308 int run(const char *db, const char *txt);
5309 
5310-int main(int argc, char** argv) {
5311+int main(int argc, char** argv)
5312+{
5313     int opt;
5314     char* txt = NULL;
5315     char* db = NULL;
5316 
5317     while ((opt = getopt(argc, argv, "t:d:h")) != -1) {
5318         switch(opt) {
5319-            case 't':
5320-                txt = copy_achar(optarg);
5321-                break;
5322-            case 'd':
5323-                db = copy_achar(optarg);
5324-                break;
5325-            case 'h':
5326-                  // fall through
5327-            default:
5328-                printf("Usage: %s", argv[0]);
5329-                goto end;
5330+        case 't':
5331+            txt = copy_achar(optarg);
5332+            break;
5333+        case 'd':
5334+            db = copy_achar(optarg);
5335+            break;
5336+        case 'h':
5337+        // fall through
5338+        default:
5339+            printf("Usage: %s", argv[0]);
5340+            goto end;
5341         }
5342     }
5343-
5344 
5345     int r = run(db, txt);
5346 
5347@@ -40,7 +40,8 @@
5348     return r;
5349 }
5350 
5351-int run(const char *db, const char *txt) {
5352+int run(const char *db, const char *txt)
5353+{
5354     char * line = NULL;
5355     size_t len = 0;
5356     int count = 0;
5357@@ -66,7 +67,7 @@
5358         insert(data, line, read-1);
5359         count++;
5360 
5361-        if ((count % 321) == 0){
5362+        if ((count % 321) == 0) {
5363             float t = ((float)count/(float)total)*100;
5364             printf("\rLoading data [%03.0f%%] %d/%d", t, count, total);
5365         }
5366diff --git a/lib/data.c b/lib/data.c
5367index 7ebf597ca8ab317c76ac1960882f19669994d18e..e94e0a777c5de6b40530247fecb6942c985e803d 100644
5368--- a/lib/data.c
5369+++ b/lib/data.c
5370@@ -8,7 +8,8 @@ const char *insert_into = "INSERT INTO words (LINE) VALUES($VVV);";
5371 const char *select_words = "SELECT Id, Line FROM words WHERE line like $VVV LIMIT 10;";
5372 const char *create_table =  "CREATE TABLE IF NOT EXISTS words (ID INTEGER PRIMARY KEY AUTOINCREMENT, LINE TEXT NOT NULL);";
5373 
5374-Data* new_data(const char* con) {
5375+Data* new_data(const char* con)
5376+{
5377     Data* data = (Data*)malloc(sizeof(Data));
5378 
5379     int v = sqlite3_open(con, &(data->db));
5380@@ -27,13 +28,15 @@
5381     return data;
5382 }
5383 
5384-void free_data(Data* data) {
5385+void free_data(Data* data)
5386+{
5387     sqlite3_close(data->db);
5388     free(data);
5389 }
5390 
5391-void insert(Data* data, char* line, int len) {
5392-    sqlite3_stmt *stmt; 
5393+void insert(Data* data, char* line, int len)
5394+{
5395+    sqlite3_stmt *stmt;
5396     int r = sqlite3_prepare_v2(data->db, insert_into, -1, &stmt, NULL);
5397 
5398     if (r != SQLITE_OK) {
5399@@ -55,8 +58,9 @@
5400     sqlite3_finalize(stmt);
5401 }
5402 
5403-void bootstrap(Data* data) {
5404-    sqlite3_stmt *stmt; 
5405+void bootstrap(Data* data)
5406+{
5407+    sqlite3_stmt *stmt;
5408     int r = sqlite3_prepare_v2(data->db, create_table, -1, &stmt, NULL);
5409 
5410     if (r != SQLITE_OK) {
5411@@ -76,8 +80,9 @@
5412     sqlite3_finalize(stmt);
5413 }
5414 
5415-LIST* data_select(Data* data, char *sch, int len) {
5416-    sqlite3_stmt *stmt; 
5417+LIST* data_select(Data* data, char *sch, int len)
5418+{
5419+    sqlite3_stmt *stmt;
5420     int r = sqlite3_prepare_v2(data->db, select_words, -1, &stmt, NULL);
5421 
5422     if (r != SQLITE_OK) {
5423@@ -112,6 +117,7 @@
5424     return list;
5425 }
5426 
5427-void print_result_code(int code) {
5428+void print_result_code(int code)
5429+{
5430     printf(sqlite3_errstr(code));
5431 }
5432diff --git a/lib/data.h b/lib/data.h
5433index 56edd34841971064ac48a0a3acae93ce5d7690aa..fcde55ada917c1c87850044c1bb79b859d6762bf 100644
5434--- a/lib/data.h
5435+++ b/lib/data.h
5436@@ -5,7 +5,8 @@
5437 /*
5438  * This word into the dictionary
5439  */
5440-typedef struct word {
5441+typedef struct word
5442+{
5443     int Id;
5444     const unsigned char *Line;
5445 } Word;
5446@@ -13,16 +14,15 @@
5447 /*
5448  * This is database connection.
5449  */
5450-typedef struct data {
5451+typedef struct data
5452+{
5453     sqlite3 *db;
5454 } Data;
5455-
5456 
5457 /*
5458  * create a new data struct from sqlite filename.
5459  */
5460 Data* new_data(const char*);
5461-
5462 
5463 void free_data(Data*);
5464 
5465diff --git a/lib/list.c b/lib/list.c
5466index fc0fddfd3e82dc239d36563fd7953e5522aa1ff0..52feb767f49eaf205b9926a20c946d0dd570a959 100644
5467--- a/lib/list.c
5468+++ b/lib/list.c
5469@@ -4,8 +4,7 @@
5470 LIST* list_add(LIST* list, void* item)
5471 {
5472 
5473-    if (list == NULL)
5474-    {
5475+    if (list == NULL) {
5476         list = (LIST*)malloc(sizeof(LIST));
5477         list->size = 0;
5478         list->list = (void**)malloc(sizeof(0));
5479@@ -35,20 +34,21 @@
5480     return list;
5481 }
5482 
5483-void list_free(LIST* list) {
5484-    for (unsigned int x = 0; x < list->size; x++) 
5485+void list_free(LIST* list)
5486+{
5487+    for (unsigned int x = 0; x < list->size; x++)
5488         free(list->list[x]);
5489 
5490     free(list->list);
5491     free(list);
5492 }
5493 
5494-
5495-void *list_get(LIST *list, unsigned int index) {
5496+void *list_get(LIST *list, unsigned int index)
5497+{
5498     if (list == NULL)
5499         return NULL;
5500 
5501-    if (index < list->size) 
5502+    if (index < list->size)
5503         return list->list[index];
5504 
5505     return NULL;
5506diff --git a/lib/list.h b/lib/list.h
5507index dd28722a34ace46877267b9eea10edb154148bdf..18bc423838286fcccb949e25e7d164714022a852 100644
5508--- a/lib/list.h
5509+++ b/lib/list.h
5510@@ -2,7 +2,8 @@ #pragma once
5511 #include <stdlib.h>
5512 
5513 #define LIST_SIZE_FACTOR 1.5
5514-struct list {
5515+struct list
5516+{
5517     unsigned int size;
5518     unsigned int allocated_size;
5519     void** list;
5520diff --git a/lib/ui.c b/lib/ui.c
5521index 1a285a00e407566b783917c1541883301ab838c7..3eae2017ce609363744cc85f4b98c797b63e35fc 100644
5522--- a/lib/ui.c
5523+++ b/lib/ui.c
5524@@ -9,7 +9,8 @@ #include "ui.h"
5525 
5526 const char *uload = "█";
5527 
5528-PROGRESS_BAR* new_progress_bar(WINDOW* scr, float total) {
5529+PROGRESS_BAR* new_progress_bar(WINDOW* scr, float total)
5530+{
5531     PROGRESS_BAR *bar = (PROGRESS_BAR*)malloc(sizeof(PROGRESS_BAR));
5532     bar->scr = scr;
5533     bar->total = total;
5534@@ -17,7 +18,8 @@     bar->current = 0;
5535     return bar;
5536 }
5537 
5538-void bar_step(PROGRESS_BAR* bar, float step){
5539+void bar_step(PROGRESS_BAR* bar, float step)
5540+{
5541     bar->current += step;
5542 
5543     int x, y;
5544@@ -42,13 +44,12 @@
5545     wmove(bar->scr, hy+1, hx - len);
5546     wprintw(bar->scr, "%.0f/%.0f", bar->current, bar->total);
5547 
5548-
5549     wmove(bar->scr,0,0);
5550     wrefresh(bar->scr);
5551 }
5552 
5553-
5554-TEXT_BOX* new_text_box(WINDOW* scr, int length) {
5555+TEXT_BOX* new_text_box(WINDOW* scr, int length)
5556+{
5557     TEXT_BOX *text = (TEXT_BOX*)malloc(sizeof(TEXT_BOX));
5558     text->scr = scr;
5559     text->length = length;
5560@@ -58,22 +59,23 @@     memset(text->text, '\0', length);
5561     return text;
5562 }
5563 
5564-void get_char(TEXT_BOX* text, void (*sch)(char*, int)) {
5565-    while(1){
5566+void get_char(TEXT_BOX* text, void (*sch)(char*, int))
5567+{
5568+    while(1) {
5569         wchar_t c;
5570         get_wch((wint_t*)&c);
5571 
5572         switch(c) {
5573-            case KEY_BACKSPACE:
5574-                if (text->current > 0) {
5575-                    text->text[text->current--] = '\0';
5576-                }
5577-                break;
5578-            default:
5579-                if (text->current < (text->length-2)) {
5580-                    text->text[text->current] = c;
5581-                    text->text[++text->current] = '\0';
5582-                }
5583+        case KEY_BACKSPACE:
5584+            if (text->current > 0) {
5585+                text->text[text->current--] = '\0';
5586+            }
5587+            break;
5588+        default:
5589+            if (text->current < (text->length-2)) {
5590+                text->text[text->current] = c;
5591+                text->text[++text->current] = '\0';
5592+            }
5593         }
5594 
5595         char str[text->length];
5596diff --git a/lib/ui.h b/lib/ui.h
5597index 90b352ff9f0cd7dcc853c3e6695fb9ce74d2b10a..12ee2f4932a6fccf18ea2d71a7694baee3e4ea88 100644
5598--- a/lib/ui.h
5599+++ b/lib/ui.h
5600@@ -1,7 +1,8 @@
5601 #pragma once
5602 #include <ncurses.h>
5603 
5604-typedef struct progress_bar {
5605+typedef struct progress_bar
5606+{
5607     float total;
5608     float current;
5609     WINDOW *scr;
5610@@ -10,8 +11,8 @@
5611 PROGRESS_BAR* new_progress_bar(WINDOW*, float);
5612 void bar_step(PROGRESS_BAR*, float);
5613 
5614-
5615-typedef struct text_box {
5616+typedef struct text_box
5617+{
5618     wchar_t *text;
5619     int length;
5620     int current;
5621@@ -20,4 +21,3 @@ } TEXT_BOX;
5622 
5623 TEXT_BOX* new_text_box(WINDOW*, int);
5624 void get_char(TEXT_BOX* text, void (*sch)(char*, int));
5625-
5626diff --git a/lib/util.c b/lib/util.c
5627index 6720082ac9e4f530f85d26e47416487702fac414..895ca89566c23aea5ca38733825ab012448f1f4f 100644
5628--- a/lib/util.c
5629+++ b/lib/util.c
5630@@ -6,7 +6,8 @@ #include "util.h"
5631 
5632 #define BUF_SIZE 100
5633 
5634-char* copy_achar(const char* src) {
5635+char* copy_achar(const char* src)
5636+{
5637     int len = strlen(src) + 1;
5638     char* dest = (char*)malloc(sizeof(char)*len);
5639     strcpy(dest, src);
5640@@ -14,8 +15,8 @@
5641     return dest;
5642 }
5643 
5644-
5645-int load_or_save_db(sqlite3 *pInMemory, const char *zFilename, int isSave){
5646+int load_or_save_db(sqlite3 *pInMemory, const char *zFilename, int isSave)
5647+{
5648     int rc;                   /* Function return code */
5649     sqlite3 *pFile;           /* Database connection opened on zFilename */
5650     sqlite3_backup *pBackup;  /* Backup object used to copy data */
5651@@ -23,12 +24,12 @@     sqlite3 *pTo;             /* Database to copy to (pFile or pInMemory) */
5652     sqlite3 *pFrom;           /* Database to copy from (pFile or pInMemory) */
5653 
5654     rc = sqlite3_open(zFilename, &pFile);
5655-    if( rc==SQLITE_OK ){
5656+    if( rc==SQLITE_OK ) {
5657         pFrom = (isSave ? pInMemory : pFile);
5658         pTo   = (isSave ? pFile     : pInMemory);
5659 
5660         pBackup = sqlite3_backup_init(pTo, "main", pFrom, "main");
5661-        if( pBackup ){
5662+        if( pBackup ) {
5663             (void)sqlite3_backup_step(pBackup, -1);
5664             (void)sqlite3_backup_finish(pBackup);
5665         }
5666@@ -39,11 +40,11 @@     (void)sqlite3_close(pFile);
5667     return rc;
5668 }
5669 
5670-unsigned int count_file_lines(FILE *file) {
5671+unsigned int count_file_lines(FILE *file)
5672+{
5673     char buf[BUF_SIZE];
5674     unsigned int counter = 0;
5675-    for(;;)
5676-    {
5677+    for(;;) {
5678         size_t res = fread(buf, 1, BUF_SIZE, file);
5679         if (ferror(file))
5680             return -1;
5681diff --git a/lib/util.h b/lib/util.h
5682index c03dbae7654b1ac748acd438ed6ab0f4975a2427..33c61ed8429051c14b8d82b102c2fbaa0d85570f 100644
5683--- a/lib/util.h
5684+++ b/lib/util.h
5685@@ -8,8 +8,6 @@  * Copy of a char to a newly created string of the same size.
5686  */
5687 char* copy_achar(const char*);
5688 
5689-
5690 int load_or_save_db(sqlite3 *pInMemory, const char *zFilename, int isSave);
5691-
5692 
5693 unsigned int count_file_lines(FILE *file);