Home | History | Annotate | Download | only in sqlite
      1 History uses fts3 with an icu-based segmenter.  These changes allow
      2 building a sqlite3 binary which can read those files.
      3 
      4 Index: src/shell.c
      5 ===================================================================
      6 --- src/shell.c	2009-09-04 13:37:43.000000000 -0700
      7 +++ src/shell.c	2009-09-15 11:32:08.000000000 -0700
      8 @@ -3007,6 +3007,14 @@
      9    int i;
     10    int rc = 0;
     11  
     12 +  /* Begin evanm patch. */
     13 +  extern int sqlite_shell_init_icu();
     14 +  if( !sqlite_shell_init_icu() ){
     15 +    fprintf(stderr, "%s: warning: couldn't find icudt38.dll; "
     16 +                    "queries against ICU FTS tables will fail.\n", argv[0]);
     17 +  }
     18 +  /* End evanm patch. */
     19 +
     20    Argv0 = argv[0];
     21    main_init(&data);
     22    stdin_is_interactive = isatty(0);
     23 diff --git src/shell_icu_linux.c src/shell_icu_linux.c
     24 new file mode 100644
     25 index 0000000..4ad0e42
     26 --- /dev/null
     27 +++ src/shell_icu_linux.c
     28 @@ -0,0 +1,27 @@
     29 +/* Copyright 2007 Google Inc. All Rights Reserved.
     30 +**/
     31 +
     32 +#include <limits.h>
     33 +#include <unistd.h>
     34 +#include "unicode/putil.h"
     35 +#include "unicode/udata.h"
     36 +
     37 +/*
     38 +** This function attempts to load the ICU data tables from a data file.
     39 +** Returns 0 on failure, nonzero on success.
     40 +** This a hack job of icu_utils.cc:Initialize().  It's Chrome-specific code.
     41 +*/
     42 +int sqlite_shell_init_icu() {
     43 +  char bin_dir[PATH_MAX + 1];
     44 +  int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX);
     45 +  if (bin_dir_size < 0 || bin_dir_size > PATH_MAX)
     46 +    return 0;
     47 +  bin_dir[bin_dir_size] = 0;;
     48 +
     49 +  u_setDataDirectory(bin_dir);
     50 +  // Only look for the packaged data file;
     51 +  // the default behavior is to look for individual files.
     52 +  UErrorCode err = U_ZERO_ERROR;
     53 +  udata_setFileAccess(UDATA_ONLY_PACKAGES, &err);
     54 +  return err == U_ZERO_ERROR;
     55 +}
     56 Index: src/shell_icu_win.c
     57 ===================================================================
     58 --- src/shell_icu_win.c	1969-12-31 16:00:00.000000000 -0800
     59 +++ src/shell_icu_win.c	2011-03-03 14:29:11.000000000 -0700
     60 @@ -0,0 +1,32 @@
     61 +/* Copyright 2011 Google Inc. All Rights Reserved.
     62 +**/
     63 +
     64 +#include <windows.h>
     65 +#include "unicode/udata.h"
     66 +
     67 +/*
     68 +** This function attempts to load the ICU data tables from a DLL.
     69 +** Returns 0 on failure, nonzero on success.
     70 +** This a hack job of icu_utils.cc:Initialize().  It's Chrome-specific code.
     71 +*/
     72 +
     73 +#define ICU_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat"
     74 +int sqlite_shell_init_icu() {
     75 +  HMODULE module;
     76 +  FARPROC addr;
     77 +  UErrorCode err;
     78 +
     79 +  // Chrome dropped U_ICU_VERSION_SHORT from the icu data dll name.
     80 +  module = LoadLibrary(L"icudt.dll");
     81 +  if (!module)
     82 +    return 0;
     83 +
     84 +  addr = GetProcAddress(module, ICU_DATA_SYMBOL);
     85 +  if (!addr)
     86 +    return 0;
     87 +
     88 +  err = U_ZERO_ERROR;
     89 +  udata_setCommonData(addr, &err);
     90 +
     91 +  return 1;
     92 +}
     93