8 Commits
0.2 ... 0.2.2

Author SHA1 Message Date
michael
41baa86ee3 New package with bugfix.
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@215802 c90b9560-bf6c-de11-be94-00142212c4b1
2006-07-05 14:53:16 +00:00
michael
c206870203 Fix segfault on scenario with EXP_TIMEOUT.
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@215801 c90b9560-bf6c-de11-be94-00142212c4b1
2006-07-05 14:51:56 +00:00
michael
1ac4b57036 New package.
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@215725 c90b9560-bf6c-de11-be94-00142212c4b1
2006-07-04 08:33:55 +00:00
michael
f2d7fbb1d1 Return array of match substrings (according to the parentheses), instead of returning the whole string.
The whole match string can be found in array[0]. (thanks to Michael A.Logdon-Porter for this patch)


git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@215723 c90b9560-bf6c-de11-be94-00142212c4b1
2006-07-04 08:09:57 +00:00
michael
d7abe0572c Follow convention of using strlcpy(), instead of strncpy.
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@215677 c90b9560-bf6c-de11-be94-00142212c4b1
2006-07-02 08:45:16 +00:00
michael
e33a147aef Add null-termination to the result, if the orignal string doesn't have it.
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@215644 c90b9560-bf6c-de11-be94-00142212c4b1
2006-07-01 10:10:16 +00:00
michael
17d7c347b8 conform to C standard of variable declaration
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@207572 c90b9560-bf6c-de11-be94-00142212c4b1
2006-02-20 15:29:03 +00:00
michael
549a25aae3 added third parameter to expect_expectl that will return the exact match occurred
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@207506 c90b9560-bf6c-de11-be94-00142212c4b1
2006-02-19 14:56:25 +00:00
2 changed files with 37 additions and 9 deletions

View File

@@ -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;

View File

@@ -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>