Bring Hunspell google.patch up to date

A few changes in our version of Hunspell have been made without updating
google.patch file. This CL brings google.patch file up to date and documents in
README.chromium how to get the base version of Hunspell that we are using.

BUG=167192

Review URL: https://codereview.chromium.org/11639053

git-svn-id: http://src.chromium.org/svn/trunk/deps/third_party/hunspell@174316 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
diff --git a/README.chromium b/README.chromium
index dbb05bd..040d36f 100644
--- a/README.chromium
+++ b/README.chromium
@@ -5,6 +5,10 @@
 License File: COPYING
 Security Critical: yes
 
+Checkout command:
+cvs -z3 -d:pserver:anonymous@hunspell.cvs.sourceforge.net:/cvsroot/hunspell co \
+    -D "23 Mar 2012" -P hunspell
+
 Description:
 This is a partial copy of Hunspell 1.3.2 with the following changes:
 * Remove '#include "config.h"' from src/hunspell/hunspell.hxx
diff --git a/google.patch b/google.patch
index 922f23b..b1ef4c9 100644
--- a/google.patch
+++ b/google.patch
@@ -4,7 +4,7 @@
 retrieving revision 1.41
 diff -u -r1.41 affixmgr.cxx
 --- src/hunspell/affixmgr.cxx	16 Dec 2011 09:15:34 -0000	1.41
-+++ src/hunspell/affixmgr.cxx	23 Mar 2012 05:56:23 -0000
++++ src/hunspell/affixmgr.cxx	20 Dec 2012 23:40:03 -0000
 @@ -14,8 +14,14 @@
  
  #include "csutil.hxx"
@@ -195,7 +195,7 @@
 retrieving revision 1.15
 diff -u -r1.15 affixmgr.hxx
 --- src/hunspell/affixmgr.hxx	13 Oct 2011 13:41:54 -0000	1.15
-+++ src/hunspell/affixmgr.hxx	23 Mar 2012 05:56:23 -0000
++++ src/hunspell/affixmgr.hxx	20 Dec 2012 23:40:03 -0000
 @@ -18,6 +18,40 @@
  class PfxEntry;
  class SfxEntry;
@@ -280,7 +280,7 @@
 retrieving revision 1.5
 diff -u -r1.5 filemgr.cxx
 --- src/hunspell/filemgr.cxx	23 Jun 2011 09:21:50 -0000	1.5
-+++ src/hunspell/filemgr.cxx	23 Mar 2012 05:56:23 -0000
++++ src/hunspell/filemgr.cxx	20 Dec 2012 23:40:03 -0000
 @@ -7,6 +7,32 @@
  
  #include "filemgr.hxx"
@@ -325,7 +325,7 @@
 retrieving revision 1.3
 diff -u -r1.3 filemgr.hxx
 --- src/hunspell/filemgr.hxx	15 Apr 2010 11:22:08 -0000	1.3
-+++ src/hunspell/filemgr.hxx	23 Mar 2012 05:56:23 -0000
++++ src/hunspell/filemgr.hxx	20 Dec 2012 23:40:03 -0000
 @@ -7,6 +7,30 @@
  #include "hunzip.hxx"
  #include <stdio.h>
@@ -368,7 +368,7 @@
 retrieving revision 1.12
 diff -u -r1.12 hashmgr.cxx
 --- src/hunspell/hashmgr.cxx	23 Jun 2011 09:21:50 -0000	1.12
-+++ src/hunspell/hashmgr.cxx	23 Mar 2012 05:56:23 -0000
++++ src/hunspell/hashmgr.cxx	20 Dec 2012 23:40:03 -0000
 @@ -12,8 +12,14 @@
  
  // build a hash table from a munched word list
@@ -491,7 +491,28 @@
      return 0;
  }     
  
-@@ -339,6 +407,44 @@
+@@ -256,6 +324,12 @@
+ // remove word (personal dictionary function for standalone applications)
+ int HashMgr::remove(const char * word)
+ {
++#ifdef HUNSPELL_CHROME_CLIENT
++    std::map<base::StringPiece, int>::iterator iter =
++        custom_word_to_affix_id_map_.find(word);
++    if (iter != custom_word_to_affix_id_map_.end())
++        custom_word_to_affix_id_map_.erase(iter);
++#else
+     struct hentry * dp = lookup(word);
+     while (dp) {
+         if (dp->alen == 0 || !TESTAFF(dp->astr, forbiddenword, dp->alen)) {
+@@ -270,6 +344,7 @@
+         }
+         dp = dp->next_homonym;
+     }
++#endif
+     return 0;
+ }
+ 
+@@ -339,6 +414,44 @@
  // initialize: col=-1; hp = NULL; hp = walk_hashtable(&col, hp);
  struct hentry * HashMgr::walk_hashtable(int &col, struct hentry * hp) const
  {  
@@ -536,7 +557,7 @@
    if (hp && hp->next != NULL) return hp->next;
    for (col++; col < tablesize; col++) {
      if (tableptr[col]) return tableptr[col];
-@@ -346,11 +452,13 @@
+@@ -346,11 +459,13 @@
    // null at end and reset to start
    col = -1;
    return NULL;
@@ -550,7 +571,7 @@
    int al;
    char * ap;
    char * dp;
-@@ -471,6 +579,7 @@
+@@ -471,6 +586,7 @@
    }
  
    delete dict;
@@ -558,7 +579,7 @@
    return 0;
  }
  
-@@ -479,6 +588,9 @@
+@@ -479,6 +595,9 @@
  
  int HashMgr::hash(const char * word) const
  {
@@ -568,7 +589,7 @@
      long  hv = 0;
      for (int i=0; i < 4  &&  *word != 0; i++)
          hv = (hv << 8) | (*word++);
-@@ -487,6 +599,7 @@
+@@ -487,6 +606,7 @@
        hv ^= (*word++);
      }
      return (unsigned long) hv % tablesize;
@@ -576,7 +597,7 @@
  }
  
  int HashMgr::decode_flags(unsigned short ** result, char * flags, FileMgr * af) {
-@@ -607,7 +720,12 @@
+@@ -607,7 +727,12 @@
    int firstline = 1;
   
    // open the affix file
@@ -589,7 +610,7 @@
    if (!afflst) {
      HUNSPELL_WARNING(stderr, "Error - could not open affix description file %s\n",affpath);
      return 1;
-@@ -802,6 +920,121 @@
+@@ -802,6 +927,121 @@
     return 0;
  }
  
@@ -717,7 +738,7 @@
 retrieving revision 1.3
 diff -u -r1.3 hashmgr.hxx
 --- src/hunspell/hashmgr.hxx	15 Apr 2010 11:22:08 -0000	1.3
-+++ src/hunspell/hashmgr.hxx	23 Mar 2012 05:56:23 -0000
++++ src/hunspell/hashmgr.hxx	20 Dec 2012 23:40:03 -0000
 @@ -8,10 +8,25 @@
  #include "htypes.hxx"
  #include "filemgr.hxx"
@@ -815,7 +836,7 @@
 retrieving revision 1.3
 diff -u -r1.3 htypes.hxx
 --- src/hunspell/htypes.hxx	6 Sep 2010 07:58:53 -0000	1.3
-+++ src/hunspell/htypes.hxx	23 Mar 2012 05:56:23 -0000
++++ src/hunspell/htypes.hxx	20 Dec 2012 23:40:03 -0000
 @@ -1,6 +1,16 @@
  #ifndef _HTYPES_HXX_
  #define _HTYPES_HXX_
@@ -839,9 +860,16 @@
 retrieving revision 1.29
 diff -u -r1.29 hunspell.cxx
 --- src/hunspell/hunspell.cxx	23 Jun 2011 09:21:50 -0000	1.29
-+++ src/hunspell/hunspell.cxx	23 Mar 2012 05:56:24 -0000
-@@ -12,15 +12,30 @@
++++ src/hunspell/hunspell.cxx	20 Dec 2012 23:40:03 -0000
+@@ -7,20 +7,37 @@
+ 
+ #include "hunspell.hxx"
+ #include "hunspell.h"
++#ifndef HUNSPELL_CHROME_CLIENT
+ #ifndef MOZILLA_CLIENT
+ #    include "config.h"
  #endif
++#endif
  #include "csutil.hxx"
  
 +#ifdef HUNSPELL_CHROME_CLIENT
@@ -871,7 +899,7 @@
      /* first set up the hash manager */
      pHMgr[0] = new HashMgr(dpath, affpath, key);
      if (pHMgr[0]) maxdic = 1;
-@@ -28,6 +43,7 @@
+@@ -28,6 +45,7 @@
      /* next set up the affix manager */
      /* it needs access to the hash manager lookup methods */
      pAMgr = new AffixMgr(affpath, pHMgr, &maxdic, key);
@@ -879,7 +907,19 @@
  
      /* get the preferred try string and the dictionary */
      /* encoding from the Affix Manager for that dictionary */
-@@ -59,10 +75,16 @@
+@@ -41,7 +59,11 @@
+     wordbreak = pAMgr->get_breaktable();
+ 
+     /* and finally set up the suggestion manager */
++#ifdef HUNSPELL_CHROME_CLIENT
++    pSMgr = new SuggestMgr(bdict_reader, try_string, MAXSUGGESTION, pAMgr);
++#else
+     pSMgr = new SuggestMgr(try_string, MAXSUGGESTION, pAMgr);
++#endif
+     if (try_string) free(try_string);
+ }
+ 
+@@ -59,10 +81,16 @@
      csconv= NULL;
      if (encoding) free(encoding);
      encoding = NULL;
@@ -896,7 +936,7 @@
  // load extra dictionaries
  int Hunspell::add_dic(const char * dpath, const char * key) {
      if (maxdic == MAXDIC || !affixpath) return 1;
-@@ -70,6 +92,7 @@
+@@ -70,6 +98,7 @@
      if (pHMgr[maxdic]) maxdic++; else return 1;
      return 0;
  }
@@ -904,7 +944,7 @@
  
  // make a copy of src at destination while removing all leading
  // blanks and removing any trailing periods after recording
-@@ -322,6 +345,9 @@
+@@ -322,6 +351,9 @@
  
  int Hunspell::spell(const char * word, int * info, char ** root)
  {
@@ -914,7 +954,7 @@
    struct hentry * rv=NULL;
    // need larger vector. For example, Turkish capital letter I converted a
    // 2-byte UTF-8 character (dotless i) by mkallsmall.
-@@ -586,6 +612,13 @@
+@@ -586,6 +618,13 @@
    if (!len)
        return NULL;
  
@@ -928,7 +968,7 @@
    // word reversing wrapper for complex prefixes
    if (complexprefixes) {
      if (word != w2) {
-@@ -675,6 +708,9 @@
+@@ -675,6 +714,9 @@
  
  int Hunspell::suggest(char*** slst, const char * word)
  {
@@ -938,7 +978,7 @@
    int onlycmpdsug = 0;
    char cw[MAXWORDUTF8LEN];
    char wspace[MAXWORDUTF8LEN];
-@@ -1921,13 +1957,21 @@
+@@ -1921,13 +1963,21 @@
  
  Hunhandle *Hunspell_create(const char * affpath, const char * dpath)
  {
@@ -966,7 +1006,7 @@
 retrieving revision 1.6
 diff -u -r1.6 hunspell.hxx
 --- src/hunspell/hunspell.hxx	21 Jan 2011 17:30:41 -0000	1.6
-+++ src/hunspell/hunspell.hxx	23 Mar 2012 05:56:24 -0000
++++ src/hunspell/hunspell.hxx	20 Dec 2012 23:40:03 -0000
 @@ -5,6 +5,10 @@
  #include "suggestmgr.hxx"
  #include "langnum.hxx"
@@ -1023,7 +1063,7 @@
 retrieving revision 1.2
 diff -u -r1.2 replist.hxx
 --- src/hunspell/replist.hxx	15 Apr 2010 11:22:09 -0000	1.2
-+++ src/hunspell/replist.hxx	23 Mar 2012 05:56:24 -0000
++++ src/hunspell/replist.hxx	20 Dec 2012 23:40:03 -0000
 @@ -2,6 +2,12 @@
  #ifndef _REPLIST_HXX_
  #define _REPLIST_HXX_
@@ -1043,8 +1083,8 @@
 retrieving revision 1.24
 diff -u -r1.24 suggestmgr.cxx
 --- src/hunspell/suggestmgr.cxx	14 Feb 2011 21:47:24 -0000	1.24
-+++ src/hunspell/suggestmgr.cxx	23 Mar 2012 05:56:24 -0000
-@@ -12,6 +12,98 @@
++++ src/hunspell/suggestmgr.cxx	20 Dec 2012 23:40:03 -0000
+@@ -12,9 +12,110 @@
  
  const w_char W_VLINE = { '\0', '|' };
  
@@ -1140,10 +1180,80 @@
 +}  // namespace
 +#endif
 +
++
++#ifdef HUNSPELL_CHROME_CLIENT
++SuggestMgr::SuggestMgr(hunspell::BDictReader* reader,
++                       const char * tryme, int maxn, 
++                       AffixMgr * aptr)
++{
++  bdict_reader = reader;
++#else
  SuggestMgr::SuggestMgr(const char * tryme, int maxn, 
                         AffixMgr * aptr)
  {
-@@ -1057,6 +1149,9 @@
++#endif
+ 
+   // register affix manager and check in string of chars to 
+   // try when building candidate suggestions
+@@ -407,6 +508,49 @@
+   int lenr, lenp;
+   int wl = strlen(word);
+   if (wl < 2 || ! pAMgr) return ns;
++  
++#ifdef HUNSPELL_CHROME_CLIENT
++  const char *pattern, *pattern2;
++  hunspell::ReplacementIterator iterator = bdict_reader->GetReplacementIterator();
++  while (iterator.GetNext(&pattern, &pattern2)) {
++      r = word;
++      lenr = strlen(pattern2);
++      lenp = strlen(pattern);
++      
++      // search every occurence of the pattern in the word
++      while ((r=strstr(r, pattern)) != NULL) {
++          strcpy(candidate, word);
++          if (r-word + lenr + strlen(r+lenp) >= MAXLNLEN) break;
++          strcpy(candidate+(r-word), pattern2);
++          strcpy(candidate+(r-word)+lenr, r+lenp);
++          ns = testsug(wlst, candidate, wl-lenp+lenr, ns, cpdsuggest, NULL, NULL);
++          if (ns == -1) return -1;
++          // check REP suggestions with space
++          char * sp = strchr(candidate, ' ');
++          if (sp) {
++            char * prev = candidate;
++            while (sp) {
++              *sp = '\0';
++              if (checkword(prev, strlen(prev), 0, NULL, NULL)) {
++                int oldns = ns;
++                *sp = ' ';
++                ns = testsug(wlst, sp + 1, strlen(sp + 1), ns, cpdsuggest, NULL, NULL);
++                if (ns == -1) return -1;
++                if (oldns < ns) {
++                  free(wlst[ns - 1]);
++                  wlst[ns - 1] = mystrdup(candidate);
++                  if (!wlst[ns - 1]) return -1;
++                }
++              }
++              *sp = ' ';
++              prev = sp + 1;
++              sp = strchr(prev, ' ');
++            }
++          }
++          r++; // search for the next letter
++    }
++  }
++#else
+   int numrep = pAMgr->get_numrep();
+   struct replentry* reptable = pAMgr->get_reptable();
+   if (reptable==NULL) return ns;
+@@ -448,6 +592,7 @@
+           r++; // search for the next letter
+       }
+    }
++#endif
+    return ns;
+ }
+ 
+@@ -1057,6 +1202,9 @@
  
    struct hentry* hp = NULL;
    int col = -1;
@@ -1153,7 +1263,7 @@
    phonetable * ph = (pAMgr) ? pAMgr->get_phonetable() : NULL;
    char target[MAXSWUTF8L];
    char candidate[MAXSWUTF8L];
-@@ -1115,7 +1210,11 @@
+@@ -1115,7 +1263,11 @@
  
      if (sc > scores[lp]) {
        scores[lp] = sc;  
@@ -1165,3 +1275,33 @@
        lval = sc;
        for (j=0; j < MAX_ROOTS; j++)
          if (scores[j] < lval) {
+Index: src/hunspell/suggestmgr.hxx
+===================================================================
+RCS file: /cvsroot/hunspell/hunspell/src/hunspell/suggestmgr.hxx,v
+retrieving revision 1.5
+diff -u -r1.5 suggestmgr.hxx
+--- src/hunspell/suggestmgr.hxx	21 Jan 2011 22:10:24 -0000	1.5
++++ src/hunspell/suggestmgr.hxx	20 Dec 2012 23:40:03 -0000
+@@ -52,7 +52,11 @@
+ 
+ 
+ public:
++#ifdef HUNSPELL_CHROME_CLIENT
++  SuggestMgr(hunspell::BDictReader* reader, const char * tryme, int maxn, AffixMgr *aptr);
++#else
+   SuggestMgr(const char * tryme, int maxn, AffixMgr *aptr);
++#endif
+   ~SuggestMgr();
+ 
+   int suggest(char*** slst, const char * word, int nsug, int * onlycmpdsug);
+@@ -66,6 +70,10 @@
+   char * suggest_morph_for_spelling_error(const char * word);
+ 
+ private:
++#ifdef HUNSPELL_CHROME_CLIENT
++   // Not owned by us, owned by the Hunspell object.
++   hunspell::BDictReader* bdict_reader;
++#endif
+    int testsug(char** wlst, const char * candidate, int wl, int ns, int cpdsuggest,
+      int * timer, clock_t * timelimit);
+    int checkword(const char *, int, int, int *, clock_t *);