@@ -307,7 +307,7 @@ static PHPDBG_COMMAND(break) /* {{{ */
307307 char * line_pos = NULL ;
308308 char * func_pos = NULL ;
309309
310- if (! expr_len ) {
310+ if (expr_len <= 0L ) {
311311 printf (
312312 "[No expression found]\n" );
313313 return FAILURE ;
@@ -456,7 +456,11 @@ static PHPDBG_COMMAND(help) /* {{{ */
456456{
457457 printf ("[Welcome to phpdbg, the interactive PHP debugger, v%s]\n" , PHPDBG_VERSION );
458458
459- if (!expr_len ) {
459+ if (expr_len > 0L ) {
460+ if (phpdbg_do_cmd (phpdbg_help_commands , (char * )expr , expr_len TSRMLS_CC ) == FAILURE ) {
461+ printf ("failed to find help command: %s/%d\n" , expr , expr_len );
462+ }
463+ } else {
460464 const phpdbg_command_t * prompt_command = phpdbg_prompt_commands ;
461465 const phpdbg_command_t * help_command = phpdbg_help_commands ;
462466
@@ -473,11 +477,8 @@ static PHPDBG_COMMAND(help) /* {{{ */
473477 printf ("\t%s\t%s\n" , help_command -> name , help_command -> tip );
474478 ++ help_command ;
475479 }
476- } else {
477- if (phpdbg_do_cmd (phpdbg_help_commands , (char * )expr , expr_len TSRMLS_CC ) == FAILURE ) {
478- printf ("failed to find help command: %s\n" , expr );
479- }
480480 }
481+
481482 printf ("[Please report bugs to <%s>]\n" , PHPDBG_ISSUES );
482483
483484 return SUCCESS ;
@@ -571,19 +572,39 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le
571572
572573int phpdbg_interactive (TSRMLS_D ) /* {{{ */
573574{
574- char cmd [PHPDBG_MAX_CMD ];
575-
576- printf ("phpdbg> " );
577-
575+ size_t cmd_len ;
576+
577+ #ifndef HAVE_LIBREADLINE
578+ char cmd [PHPDBG_MAX_CMD ];
579+
580+ phpdbg_interactive_enter :
581+ printf ("phpdbg> " );
582+
578583 while (!(PHPDBG_G (flags ) & PHPDBG_IS_QUITTING ) &&
579584 fgets (cmd , PHPDBG_MAX_CMD , stdin ) != NULL ) {
580- size_t cmd_len = strlen (cmd ) - 1 ;
585+ cmd_len = strlen (cmd ) - 1 ;
586+ #else
587+ char * cmd = NULL ;
581588
582- if (cmd [cmd_len ] == '\n' ) {
583- cmd [cmd_len ] = 0 ;
584- }
589+ phpdbg_interactive_enter :
590+ while (!(PHPDBG_G (flags ) & PHPDBG_IS_QUITTING )) {
591+ cmd = readline ("phpdbg> " );
592+
593+ cmd_len = strlen (cmd );
594+ #endif
595+
596+ /* trim space from end of input */
597+ while (isspace (cmd [cmd_len - 1 ]))
598+ cmd_len -- ;
599+
600+ /* ensure string is null terminated */
601+ cmd [cmd_len ] = '\0' ;
585602
586- if (cmd_len ) {
603+ if (cmd && cmd_len > 0L ) {
604+ #ifdef HAVE_LIBREADLINE
605+ add_history (cmd );
606+ #endif
607+
587608 switch (phpdbg_do_cmd (phpdbg_prompt_commands , cmd , cmd_len TSRMLS_CC )) {
588609 case FAILURE :
589610 if (!(PHPDBG_G (flags ) & PHPDBG_IS_QUITTING )) {
@@ -598,18 +619,15 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
598619 }
599620 return PHPDBG_NEXT ;
600621 }
601-
602-
603622 }
604623 } else if (PHPDBG_G (last )) {
605624 PHPDBG_G (last )-> handler (
606625 PHPDBG_G (last_params ), PHPDBG_G (last_params_len ) TSRMLS_CC );
607626 }
608627
609628 if (!(PHPDBG_G (flags ) & PHPDBG_IS_QUITTING )) {
610- printf ( "phpdbg> " ) ;
629+ goto phpdbg_interactive_enter ;
611630 }
612-
613631 }
614632
615633 return SUCCESS ;
0 commit comments