Bug 1310835 - Look for spellcheck dictionaries in DICPATH. r=smaug
authorJookia <166291@gmail.com>
Tue, 01 Nov 2016 08:10:50 +1100
changeset 351333 b9cd3d1a34e0e122d4c25b3b2d1936d7980a84cb
parent 351332 900466e640ca1bb85d1f01a20ee42645e03d2c7f
child 351334 69147f2ddca85498c7de033fae81634a93a8b861
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1310835
milestone52.0a1
Bug 1310835 - Look for spellcheck dictionaries in DICPATH. r=smaug Other applications allow loading dictionaries from DICPATH, so look there too. A double-pass is required since dictionaries overwrite each other, and DICPATH intends them to be overridden right-to-left like any PATH on Unix-like systems.
extensions/spellcheck/hunspell/glue/mozHunspell.cpp
--- a/extensions/spellcheck/hunspell/glue/mozHunspell.cpp
+++ b/extensions/spellcheck/hunspell/glue/mozHunspell.cpp
@@ -353,16 +353,39 @@ mozHunspell::LoadDictionaryList(bool aNo
                      NS_GET_IID(nsIFile), getter_AddRefs(appDir));
     bool equals;
     if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(appDir->Equals(greDir, &equals)) && !equals) {
       appDir->AppendNative(NS_LITERAL_CSTRING("dictionaries"));
       LoadDictionariesFromDir(appDir);
     }
   }
 
+  // find dictionaries in DICPATH
+  char* dicEnv = PR_GetEnv("DICPATH");
+  if (dicEnv) {
+    // do a two-pass dance so dictionaries are loaded right-to-left as preference
+    nsTArray<nsCOMPtr<nsIFile>> dirs;
+    nsAutoCString env(dicEnv); // assume dicEnv is UTF-8
+
+    char* currPath = nullptr;
+    char* nextPaths = env.BeginWriting();
+    while ((currPath = NS_strtok(":", &nextPaths))) {
+      nsCOMPtr<nsIFile> dir;
+      rv = NS_NewNativeLocalFile(nsCString(currPath), true, getter_AddRefs(dir));
+      if (NS_SUCCEEDED(rv)) {
+        dirs.AppendElement(dir);
+      }
+    }
+
+    // load them in reverse order so they override each other properly
+    for (int32_t i = dirs.Length() - 1; i >= 0; i--) {
+      LoadDictionariesFromDir(dirs[i]);
+    }
+  }
+
   // find dictionaries from extensions requiring restart
   nsCOMPtr<nsISimpleEnumerator> dictDirs;
   rv = dirSvc->Get(DICTIONARY_SEARCH_DIRECTORY_LIST,
                    NS_GET_IID(nsISimpleEnumerator), getter_AddRefs(dictDirs));
   if (NS_FAILED(rv))
     return;
 
   bool hasMore;