cvs: pecl /expect expect.c

From: Date: Sun, 19 Feb 2006 14:56:25 +0000
Subject: cvs: pecl /expect expect.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-5207@lists.php.net to get a copy of this message
michael Sun Feb 19 14:56:25 2006 UTC Modified files: /pecl/expect expect.c Log: added third parameter to expect_expectl that will return the exact match occurred http://cvs.php.net/viewcvs.cgi/pecl/expect/expect.c?r1=1.9&r2=1.10&diff_format=u Index: pecl/expect/expect.c diff -u pecl/expect/expect.c:1.9 pecl/expect/expect.c:1.10 --- pecl/expect/expect.c:1.9 Sat Nov 12 09:38:03 2005 +++ pecl/expect/expect.c Sun Feb 19 14:56:25 2006 @@ -23,7 +23,7 @@ /* {{{ expect_functions[] */ function_entry expect_functions[] = { PHP_FE(expect_popen, NULL) - PHP_FE(expect_expectl, NULL) + PHP_FE(expect_expectl, third_arg_force_ref) { NULL, NULL, NULL } }; /* }}} */ @@ -170,19 +170,19 @@ /* {{{ - * proto mixed expect_expectl (resource stream, array expect_cases) + * proto mixed expect_expectl (resource stream, array expect_cases [, string match]) */ PHP_FUNCTION(expect_expectl) { struct exp_case *ecases, *ec; - zval *z_stream, *z_cases, **z_case, **z_value; + zval *z_stream, *z_cases, *z_match=NULL, **z_case, **z_value; php_stream *stream; int fd, argc; ulong key; - if (ZEND_NUM_ARGS() != 2) { WRONG_PARAM_COUNT; } + if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "ra", &z_stream, &z_cases) == FAILURE) { + if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "ra|z", &z_stream, &z_cases, &z_match) == FAILURE) { return; } @@ -253,8 +253,18 @@ } ec->type = exp_end; + struct exp_case *ec1 = ecases; key = exp_expectv (fd, ecases); + int exp_match_len = exp_match_end - exp_match; + if (z_match && exp_match && exp_match_len > 0) { + zval_dtor (z_match); + char *tmp = (char *)emalloc (sizeof(char) * (exp_match_end - exp_match + 1)); + strncpy (tmp, exp_match, exp_match_len); + ZVAL_STRING (z_match, tmp, 1); + efree (tmp); + } + if (zend_hash_index_find (Z_ARRVAL_P(z_cases), key, (void **)&z_case) == SUCCESS) { if (zend_hash_index_find(Z_ARRVAL_PP(z_case), 1, (void **)&z_value) == SUCCESS) { *return_value = **z_value;

« previous php.pecl.cvs (#5207) next »