]> granicus.if.org Git - php/commitdiff
changes to accomodate win32 build
authorVlad Krupin <vlad@php.net>
Wed, 13 Aug 2003 18:59:44 +0000 (18:59 +0000)
committerVlad Krupin <vlad@php.net>
Wed, 13 Aug 2003 18:59:44 +0000 (18:59 +0000)
# I am not sure whether reading from registry, like I do now is a good
# idea, but nobody on php-dev has offered any opinion for or against that

ext/pspell/pspell.c

index ec7b8d9bd65318d88f8ae5112b2040f61e05d3cb..e07b10675e5ae962b3f7e5e9717c23d3bc608197 100644 (file)
 #define PSPELL_SPEED_MASK_INTERNAL 3L
 #define PSPELL_RUN_TOGETHER 8L
 
+/* Largest ignored word can be 999 characters (this seems sane enough), 
+ * and it takes 3 bytes to represent that (see pspell_config_ignore)
+ */
+#define PSPELL_LARGEST_WORD 3
+
 /* {{{ pspell_functions[]
  */
 function_entry pspell_functions[] = {
@@ -117,6 +122,14 @@ PHP_FUNCTION(pspell_new)
        int argc;
        int ind;
 
+#ifdef PHP_WIN32
+       TCHAR aspell_dir[200];
+       TCHAR data_dir[220];
+       TCHAR dict_dir[220];
+       HKEY hkey;
+       DWORD dwType,dwLen;
+#endif
+
        PspellCanHaveError *ret;
        PspellManager *manager;
        PspellConfig *config;
@@ -127,6 +140,24 @@ PHP_FUNCTION(pspell_new)
        }
 
        config = new_pspell_config();
+
+#ifdef PHP_WIN32
+       /* If aspell was installed using installer, we should have a key
+        * pointing to the location of the dictionaries
+        */
+       if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) {
+               RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
+               RegCloseKey(hkey);
+               strcpy(data_dir, aspell_dir);
+               strcat(data_dir, "\\data");
+               strcpy(dict_dir, aspell_dir);
+               strcat(dict_dir, "\\dict");
+
+               pspell_config_replace(config, "data-dir", data_dir);
+               pspell_config_replace(config, "dict-dir", dict_dir);
+       }
+#endif
+
        convert_to_string_ex(language);
        pspell_config_replace(config, "language-tag", Z_STRVAL_PP(language));
 
@@ -194,6 +225,14 @@ PHP_FUNCTION(pspell_new_personal)
        int argc;
        int ind;
 
+#ifdef PHP_WIN32
+       TCHAR aspell_dir[200];
+       TCHAR data_dir[220];
+       TCHAR dict_dir[220];
+       HKEY hkey;
+       DWORD dwType,dwLen;
+#endif
+
        PspellCanHaveError *ret;
        PspellManager *manager;
        PspellConfig *config;
@@ -205,6 +244,23 @@ PHP_FUNCTION(pspell_new_personal)
 
        config = new_pspell_config();
 
+#ifdef PHP_WIN32
+       /* If aspell was installed using installer, we should have a key
+        * pointing to the location of the dictionaries
+        */
+       if(0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) {
+               RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
+               RegCloseKey(hkey);
+               strcpy(data_dir, aspell_dir);
+               strcat(data_dir, "\\data");
+               strcpy(dict_dir, aspell_dir);
+               strcat(dict_dir, "\\dict");
+
+               pspell_config_replace(config, "data-dir", data_dir);
+               pspell_config_replace(config, "dict-dir", dict_dir);
+       }
+#endif
+
        convert_to_string_ex(personal);
 
        if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(personal), NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
@@ -272,7 +328,6 @@ PHP_FUNCTION(pspell_new_personal)
        
        manager = to_pspell_manager(ret);
        ind = zend_list_insert(manager, le_pspell);
-
        RETURN_LONG(ind);
 }
 /* }}} */
@@ -681,8 +736,8 @@ PHP_FUNCTION(pspell_config_ignore)
        int argc;
 
        /* Hack. But I cannot imagine any word being more than 999 characters long */
-       int loc = 3;
-       char ignore_str[loc + 1];       
+       int loc = PSPELL_LARGEST_WORD;
+       char ignore_str[PSPELL_LARGEST_WORD + 1];       
        long ignore = 0L;
 
        PspellConfig *config;