mirror of
https://github.com/php-win-ext/pecl-expect.git
synced 2026-03-24 13:02:07 +01:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41baa86ee3 | ||
|
|
c206870203 | ||
|
|
1ac4b57036 | ||
|
|
f2d7fbb1d1 | ||
|
|
d7abe0572c | ||
|
|
e33a147aef | ||
|
|
17d7c347b8 | ||
|
|
549a25aae3 |
39
expect.c
39
expect.c
@@ -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 @@ PHP_FUNCTION(expect_popen)
|
||||
|
||||
|
||||
/* {{{
|
||||
* proto mixed expect_expectl (resource stream, array expect_cases)
|
||||
* proto mixed expect_expectl (resource stream, array expect_cases [, array match])
|
||||
*/
|
||||
PHP_FUNCTION(expect_expectl)
|
||||
{
|
||||
struct exp_case *ecases, *ec;
|
||||
zval *z_stream, *z_cases, **z_case, **z_value;
|
||||
struct exp_case *ecases, *ec, matchedcase;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -255,6 +255,33 @@ PHP_FUNCTION(expect_expectl)
|
||||
|
||||
key = exp_expectv (fd, ecases);
|
||||
|
||||
int exp_match_len = exp_match_end - exp_match;
|
||||
if (z_match && exp_match && exp_match_len > 0) {
|
||||
char *tmp = (char *)emalloc (sizeof(char) * (exp_match_len + 1));
|
||||
strlcpy (tmp, exp_match, exp_match_len + 1);
|
||||
zval_dtor (z_match);
|
||||
array_init(z_match);
|
||||
add_index_string(z_match, 0, tmp, 1);
|
||||
/* Get case that was matched */
|
||||
matchedcase = ecases[key];
|
||||
/* If there are subpattern matches ... */
|
||||
if (matchedcase.re->startp != NULL) {
|
||||
int i;
|
||||
/* iterate across all possible 9 subpatterns (a limitation of libexpect)
|
||||
and add matching substring to matches array */
|
||||
for (i = 1; i <= 9; i++) {
|
||||
if (matchedcase.re->startp[i] != NULL) {
|
||||
int sub_match_len = matchedcase.re->endp[i] - matchedcase.re->startp[i];
|
||||
char *sub_match = (char *)emalloc (sizeof(char) * (sub_match_len + 1));
|
||||
strlcpy (sub_match, matchedcase.re->startp[i], sub_match_len + 1);
|
||||
add_next_index_string(z_match, sub_match, 1);
|
||||
efree (sub_match);
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -14,10 +14,11 @@
|
||||
</maintainers>
|
||||
|
||||
<release>
|
||||
<version>0.2</version>
|
||||
<date>2005-11-12</date>
|
||||
<version>0.2.2</version>
|
||||
<date>2006-07-05</date>
|
||||
<state>beta</state>
|
||||
<notes>Fixed #5941</notes>
|
||||
<notes>Fix segfault on scenario with EXP_TIMEOUT.
|
||||
</notes>
|
||||
</release>
|
||||
|
||||
<filelist>
|
||||
|
||||
Reference in New Issue
Block a user