nlopess         Tue Apr 25 14:54:33 2006 UTC

  Modified files:              
    /php-src/ext/tidy   tidy.c 
  Log:
  fix a bunch of tests in unicode mode by fixing the config array transverser
  also fix the compiler warnings
  # Andrey: is it possible to have a zend_convert_unicode_to_ascii() function 
please? it would make this code much simpler
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/tidy/tidy.c?r1=1.81&r2=1.82&diff_format=u
Index: php-src/ext/tidy/tidy.c
diff -u php-src/ext/tidy/tidy.c:1.81 php-src/ext/tidy/tidy.c:1.82
--- php-src/ext/tidy/tidy.c:1.81        Tue Apr 25 12:41:59 2006
+++ php-src/ext/tidy/tidy.c     Tue Apr 25 14:54:33 2006
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: tidy.c,v 1.81 2006/04/25 12:41:59 nlopess Exp $ */
+/* $Id: tidy.c,v 1.82 2006/04/25 14:54:33 nlopess Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -90,9 +90,13 @@
         } else { \
             convert_to_string_ex(&_val); \
             TIDY_OPEN_BASEDIR_CHECK(Z_STRVAL_P(_val)); \
-            if (tidyLoadConfig(_doc, Z_STRVAL_P(_val)) < 0) { \
+            switch (tidyLoadConfig(_doc, Z_STRVAL_P(_val))) { \
+              case -1: \
                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not load 
configuration file '%s'", Z_STRVAL_P(_val)); \
-                RETURN_FALSE; \
+                break; \
+              case 1: \
+                php_error_docref(NULL TSRMLS_CC, E_NOTICE, "There were errors 
while parsing the configuration file '%s'", Z_STRVAL_P(_val)); \
+                break; \
             } \
         } \
     }
@@ -462,16 +466,7 @@
        /* We can't use TIDY_APPLY_CONFIG_ZVAL() here, it uses RETURN_FALSE */
 
        if (ZEND_NUM_ARGS() > 1) {
-               if(Z_TYPE_P(config) == IS_ARRAY) {
-                       _php_tidy_apply_config_array(doc, HASH_OF(config) 
TSRMLS_CC);
-               } else {
-                       convert_to_string_ex(&config);
-                       TIDY_OPEN_BASEDIR_CHECK(Z_STRVAL_P(config));
-                       if (tidyLoadConfig(doc, Z_STRVAL_P(config)) < 0) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"Could not load configuration file '%s'", Z_STRVAL_P(config));
-                               RETVAL_FALSE;
-                       }
-               }
+               TIDY_APPLY_CONFIG_ZVAL(doc, config);
        }
 
        if(enc_len) {
@@ -522,7 +517,7 @@
        if (!(stream = php_stream_open_wrapper(filename, "rb", 
(use_include_path ? USE_PATH : 0), NULL))) {
                return NULL;
        }
-       if ((*len = (int) php_stream_copy_to_mem(stream, &data, 
PHP_STREAM_COPY_ALL, 0)) == 0) {
+       if ((*len = (int) php_stream_copy_to_mem(stream, (void**)&data, 
PHP_STREAM_COPY_ALL, 0)) == 0) {
                data = estrdup("");
                *len = 0;
        }
@@ -889,26 +884,51 @@
 
 static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options 
TSRMLS_DC)
 {
-       char *opt_name = NULL;
+       zstr opt_name;
        zval **opt_val;
        ulong opt_indx;
-       
+       uint opt_name_len;
+       UConverter *conv = NULL;
+       UErrorCode status = U_ZERO_ERROR;
+       zend_bool clear_str;
+
+       zend_set_converter_encoding(&conv, "ASCII");
+
        for (zend_hash_internal_pointer_reset(ht_options);
                 zend_hash_get_current_data(ht_options, (void **)&opt_val) == 
SUCCESS;
                 zend_hash_move_forward(ht_options)) {
                
-               if(zend_hash_get_current_key(ht_options, &opt_name, &opt_indx, 
FALSE) == FAILURE) {
+               switch (zend_hash_get_current_key_ex(ht_options, &opt_name, 
&opt_name_len, &opt_indx, FALSE, NULL)) {
+                       case HASH_KEY_IS_STRING:
+                       clear_str = 0;
+                       break;
+
+                       case HASH_KEY_IS_UNICODE:
+                       zend_convert_from_unicode(conv, &(opt_name.s), 
&opt_name_len, opt_name.u, opt_name_len, &status);
+                       if (U_FAILURE(status)) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"Could not convert key from the option array");
+                               ucnv_close(conv);
+                               return FAILURE;
+                       }
+                       clear_str = 1;
+                       break;
+
+                       case HASH_KEY_IS_LONG:
+                       continue; /* ignore numeric keys */
+
+                       default:
                        php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not 
retrieve key from option array");
+                       ucnv_close(conv);
                        return FAILURE;
                }
 
-               if(opt_name) {
-                       _php_tidy_set_tidy_opt(doc, opt_name, *opt_val 
TSRMLS_CC);
-                       opt_name = NULL;
+               _php_tidy_set_tidy_opt(doc, opt_name.s, *opt_val TSRMLS_CC);
+               if (clear_str) {
+                       efree(opt_name.s);
                }
-                                       
        }
-       
+
+       ucnv_close(conv);
        return SUCCESS;
 }
 
@@ -985,7 +1005,7 @@
        php_info_print_table_start();
        php_info_print_table_header(2, "Tidy support", "enabled");
        php_info_print_table_row(2, "libTidy Release", (char 
*)tidyReleaseDate());
-       php_info_print_table_row(2, "Extension Version", 
PHP_TIDY_MODULE_VERSION " ($Id: tidy.c,v 1.81 2006/04/25 12:41:59 nlopess Exp 
$)");
+       php_info_print_table_row(2, "Extension Version", 
PHP_TIDY_MODULE_VERSION " ($Id: tidy.c,v 1.82 2006/04/25 14:54:33 nlopess Exp 
$)");
        php_info_print_table_end();
 
        DISPLAY_INI_ENTRIES();

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to