Changeset 257 for trunk/ext

Show
Ignore:
Timestamp:
07/03/2007 11:46:43 (17 months ago)
Author:
indeyets
Message:

started implementing emitter (doesnt work now, wait for several more commits)

Location:
trunk/ext/php
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/php/php_syck.h

    r254 r257  
    2020 
    2121#ifndef PHP_SYCK_H 
    22 #define PHP_SYCK_H 
     22# define PHP_SYCK_H 
    2323 
    2424extern zend_module_entry syck_module_entry; 
    25 #define phpext_syck_ptr &syck_module_entry 
     25# define phpext_syck_ptr &syck_module_entry 
    2626 
    27 #ifdef PHP_WIN32 
    28 #define PHP_SYCK_API __declspec(dllexport) 
    29 #else 
    30 #define PHP_SYCK_API 
    31 #endif 
     27# ifdef PHP_WIN32 
     28#  define PHP_SYCK_API __declspec(dllexport) 
     29# else 
     30#  define PHP_SYCK_API 
     31# endif 
    3232 
    33 #ifdef ZTS 
    34 #include "TSRM.h" 
    35 #endif 
     33# ifdef ZTS 
     34#  include "TSRM.h" 
     35# endif 
    3636 
    3737PHP_MINIT_FUNCTION(syck); 
     
    3939 
    4040PHP_FUNCTION(syck_load); 
     41PHP_FUNCTION(syck_dump); 
    4142 
    4243/*  
    43         Declare any global variables you may need between the BEGIN 
     44        Declare any global variables you may need between the BEGIN 
    4445        and END macros here:      
    4546 
     
    4849        char *global_string; 
    4950ZEND_END_MODULE_GLOBALS(syck) 
    50 */ 
    51  
    52 /* In every utility function you add that needs to use variables  
    53    in php_syck_globals, call TSRM_FETCH(); after declaring other  
    54    variables used by that function, or better yet, pass in TSRMLS_CC 
    55    after the last function argument and declare your utility function 
    56    with TSRMLS_DC after the last declared argument.  Always refer to 
    57    the globals in your function as SYCK_G(variable).  You are  
    58    encouraged to rename these macros something shorter, see 
    59    examples in any other php module directory. 
    60 */ 
    6151 
    6252#ifdef ZTS 
    63 #define SYCK_G(v) TSRMG(syck_globals_id, zend_syck_globals *, v) 
     53# define SYCK_G(v) TSRMG(syck_globals_id, zend_syck_globals *, v) 
    6454#else 
    65 #define SYCK_G(v) (syck_globals.v) 
     55# define SYCK_G(v) (syck_globals.v) 
    6656#endif 
     57*/ 
    6758 
    6859#endif  /* PHP_SYCK_H */ 
  • trunk/ext/php/phpext.c

    r255 r257  
    2121#include "php_syck.h" 
    2222 
    23 #define PHP_SYCK_VERSION "0.2" 
     23#define PHP_SYCK_VERSION "0.3" 
    2424 
    2525/** 
     
    6161static double inline nanphp()   { return zero() / zero(); } 
    6262 
     63typedef struct { 
     64        char *output; 
     65        size_t output_size; 
     66        zval **stack; 
     67        unsigned char level; 
     68} php_syck_emitter_xtra; 
     69 
     70psex_add_output(php_syck_emitter_xtra *ptr) 
     71{ 
     72         
     73} 
     74 
    6375 
    6476function_entry syck_functions[] = { 
    6577        PHP_FE(syck_load, NULL) 
     78        PHP_FE(syck_dump, NULL) 
    6679        {NULL, NULL, NULL}      /* Must be the last line in syck_functions[] */ 
    6780}; 
     
    222235} 
    223236 
     237void php_syck_emitter_handler(SyckEmitter *e, st_data_t data) 
     238{ 
     239         
     240} 
     241 
     242void php_syck_output_handler(SyckEmitter *e, char *str, long len) 
     243{ 
     244         
     245} 
    224246 
    225247/* {{{ proto object syck_load(string arg) 
     
    261283 
    262284        syck_free_parser(parser); 
     285} 
     286/* }}} */ 
     287 
     288 
     289/* {{{ proto object syck_load(string arg) 
     290   Convert PHP object into YAML string */ 
     291PHP_FUNCTION(syck_dump) 
     292{ 
     293        SyckEmitter *emitter; 
     294        emitter_extra *extra; 
     295        zval *ptr; 
     296 
     297        if (ZEND_NUM_ARGS() != 1) { 
     298                WRONG_PARAM_COUNT; 
     299        } 
     300 
     301        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &ptr) == FAILURE) { 
     302                return; 
     303        } 
     304 
     305        emitter = syck_new_emitter(); 
     306        emitter->bonus = emalloc(sizeof(emitter_extra)); 
     307        emitter->bonus.output = emalloc(8192); 
     308        emitter->bonus.output_size = 8192; 
     309 
     310        syck_emitter_handler(emitter, php_syck_emitter_handler); 
     311        syck_output_handler(emitter, php_syck_output_handler); 
     312 
     313        syck_emit(emitter, 0); 
     314        syck_emitter_flush(emitter, 0); 
     315 
     316        efree(emitter->bonus); 
     317        syck_free_emitter(emitter); 
    263318} 
    264319/* }}} */