@@ -118,7 +118,7 @@ void phpdbg_clear_param(phpdbg_param_t *param TSRMLS_DC) /* {{{ */
118
118
119
119
} /* }}} */
120
120
121
- static inline phpdbg_input_t * * phpdbg_read_argv (char * buffer , int * argc TSRMLS_DC ) /* {{{ */
121
+ phpdbg_input_t * * phpdbg_read_argv (char * buffer , int * argc TSRMLS_DC ) /* {{{ */
122
122
{
123
123
char * p ;
124
124
char b [PHPDBG_MAX_CMD ];
@@ -208,37 +208,39 @@ static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_D
208
208
return argv ;
209
209
} /* }}} */
210
210
211
- phpdbg_input_t * phpdbg_read_input (TSRMLS_D ) /* {{{ */
211
+ phpdbg_input_t * phpdbg_read_input (char * buffered TSRMLS_DC ) /* {{{ */
212
212
{
213
- if (!( PHPDBG_G ( flags ) & PHPDBG_IS_QUITTING )) {
214
- phpdbg_input_t * buffer = NULL ;
215
- size_t cmd_len = 0L ;
213
+ phpdbg_input_t * buffer = NULL ;
214
+ size_t cmd_len = 0L ;
215
+ char * cmd = NULL ;
216
216
217
+ if (!(PHPDBG_G (flags ) & PHPDBG_IS_QUITTING )) {
218
+ if (buffered == NULL ) {
217
219
#ifndef HAVE_LIBREADLINE
218
- char * cmd = NULL ;
219
- char buf [PHPDBG_MAX_CMD ];
220
- if (!phpdbg_write (PROMPT ) ||
221
- !fgets (buf , PHPDBG_MAX_CMD , stdin )) {
222
- /* the user has gone away */
223
- phpdbg_error ("Failed to read console !" );
224
- PHPDBG_G (flags ) |= PHPDBG_IS_QUITTING ;
225
- zend_bailout ();
226
- return NULL ;
227
- }
220
+ char buf [PHPDBG_MAX_CMD ];
221
+ if (!phpdbg_write (PROMPT ) ||
222
+ !fgets (buf , PHPDBG_MAX_CMD , stdin )) {
223
+ /* the user has gone away */
224
+ phpdbg_error ("Failed to read console !" );
225
+ PHPDBG_G (flags ) |= PHPDBG_IS_QUITTING ;
226
+ zend_bailout ();
227
+ return NULL ;
228
+ }
228
229
229
- cmd = buf ;
230
+ cmd = buf ;
230
231
#else
231
- char * cmd = readline (PROMPT );
232
- if (!cmd ) {
233
- /* the user has gone away */
234
- phpdbg_error ("Failed to read console !" );
235
- PHPDBG_G (flags ) |= PHPDBG_IS_QUITTING ;
236
- zend_bailout ();
237
- return NULL ;
238
- }
232
+ cmd = readline (PROMPT );
233
+ if (!cmd ) {
234
+ /* the user has gone away */
235
+ phpdbg_error ("Failed to read console !" );
236
+ PHPDBG_G (flags ) |= PHPDBG_IS_QUITTING ;
237
+ zend_bailout ();
238
+ return NULL ;
239
+ }
239
240
240
- add_history (cmd );
241
+ add_history (cmd );
241
242
#endif
243
+ } else cmd = buffered ;
242
244
243
245
/* allocate and sanitize buffer */
244
246
buffer = (phpdbg_input_t * ) emalloc (sizeof (phpdbg_input_t ));
@@ -273,7 +275,7 @@ phpdbg_input_t *phpdbg_read_input(TSRMLS_D) /* {{{ */
273
275
}
274
276
275
277
#ifdef HAVE_LIBREADLINE
276
- if (cmd ) {
278
+ if (! buffered && cmd ) {
277
279
free (cmd );
278
280
}
279
281
#endif
@@ -307,7 +309,7 @@ void phpdbg_destroy_input(phpdbg_input_t **input TSRMLS_DC) /*{{{ */
307
309
}
308
310
} /* }}} */
309
311
310
- int phpdbg_do_cmd_ex (const phpdbg_command_t * command , phpdbg_input_t * input TSRMLS_DC ) /* {{{ */
312
+ int phpdbg_do_cmd (const phpdbg_command_t * command , phpdbg_input_t * input TSRMLS_DC ) /* {{{ */
311
313
{
312
314
int rc = FAILURE ;
313
315
@@ -334,13 +336,13 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM
334
336
"trying sub commands in \"%s\" for \"%s\" with %d arguments" ,
335
337
command -> name , sub .argv [0 ]-> string , sub .argc - 1 );
336
338
337
- return phpdbg_do_cmd_ex (command -> subs , & sub TSRMLS_CC );
339
+ return phpdbg_do_cmd (command -> subs , & sub TSRMLS_CC );
338
340
} else {
339
341
phpdbg_parse_param (
340
342
input -> argv [1 ]-> string ,
341
343
input -> argv [1 ]-> length ,
342
344
& param TSRMLS_CC );
343
- }
345
+ }
344
346
}
345
347
346
348
phpdbg_debug (
@@ -376,51 +378,3 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM
376
378
return rc ;
377
379
} /* }}} */
378
380
379
- int phpdbg_do_cmd (const phpdbg_command_t * command , char * cmd_line , size_t cmd_len TSRMLS_DC ) /* {{{ */
380
- {
381
- int rc = FAILURE ;
382
- char * expr = NULL ;
383
- #ifndef _WIN32
384
- const char * cmd = strtok_r (cmd_line , " " , & expr );
385
- #else
386
- const char * cmd = strtok_s (cmd_line , " " , & expr );
387
- #endif
388
- size_t expr_len = (cmd != NULL ) ? strlen (cmd ) : 0 ;
389
-
390
- while (command && command -> name && command -> handler ) {
391
- if ((command -> name_len == expr_len && memcmp (cmd , command -> name , expr_len ) == 0 )
392
- || (expr_len == 1 && command -> alias && command -> alias == cmd_line [0 ])) {
393
- phpdbg_param_t param ;
394
- phpdbg_parse_param (
395
- expr ,
396
- (cmd_len - expr_len ) ? (((cmd_len - expr_len ) - sizeof (" " ))+ 1 ) : 0 ,
397
- & param TSRMLS_CC );
398
-
399
- if (command -> subs && param .type == STR_PARAM ) {
400
- if (phpdbg_do_cmd (command -> subs , param .str , param .len TSRMLS_CC ) == SUCCESS ) {
401
- rc = SUCCESS ;
402
- goto done ;
403
- }
404
- }
405
-
406
- if (command -> arg_type == REQUIRED_ARG && param .type == EMPTY_PARAM ) {
407
- phpdbg_error ("This command requires argument!" );
408
- rc = FAILURE ;
409
- } else if (command -> arg_type == NO_ARG && param .type != EMPTY_PARAM ) {
410
- phpdbg_error ("This command does not expect argument!" );
411
- rc = FAILURE ;
412
- } else {
413
- PHPDBG_G (lcmd ) = (phpdbg_command_t * ) command ;
414
- phpdbg_clear_param (
415
- & PHPDBG_G (lparam ) TSRMLS_CC );
416
- PHPDBG_G (lparam ) = param ;
417
- rc = command -> handler (& param TSRMLS_CC );
418
- }
419
- break ;
420
- }
421
- ++ command ;
422
- }
423
-
424
- done :
425
- return rc ;
426
- } /* }}} */
0 commit comments