@@ -307,7 +307,7 @@ static PHPDBG_COMMAND(break) /* {{{ */
307
307
char * line_pos = NULL ;
308
308
char * func_pos = NULL ;
309
309
310
- if (! expr_len ) {
310
+ if (expr_len <= 0L ) {
311
311
printf (
312
312
"[No expression found]\n" );
313
313
return FAILURE ;
@@ -456,7 +456,11 @@ static PHPDBG_COMMAND(help) /* {{{ */
456
456
{
457
457
printf ("[Welcome to phpdbg, the interactive PHP debugger, v%s]\n" , PHPDBG_VERSION );
458
458
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 {
460
464
const phpdbg_command_t * prompt_command = phpdbg_prompt_commands ;
461
465
const phpdbg_command_t * help_command = phpdbg_help_commands ;
462
466
@@ -473,11 +477,8 @@ static PHPDBG_COMMAND(help) /* {{{ */
473
477
printf ("\t%s\t%s\n" , help_command -> name , help_command -> tip );
474
478
++ help_command ;
475
479
}
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
- }
480
480
}
481
+
481
482
printf ("[Please report bugs to <%s>]\n" , PHPDBG_ISSUES );
482
483
483
484
return SUCCESS ;
@@ -571,19 +572,39 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le
571
572
572
573
int phpdbg_interactive (TSRMLS_D ) /* {{{ */
573
574
{
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
+
578
583
while (!(PHPDBG_G (flags ) & PHPDBG_IS_QUITTING ) &&
579
584
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 ;
581
588
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' ;
585
602
586
- if (cmd_len ) {
603
+ if (cmd && cmd_len > 0L ) {
604
+ #ifdef HAVE_LIBREADLINE
605
+ add_history (cmd );
606
+ #endif
607
+
587
608
switch (phpdbg_do_cmd (phpdbg_prompt_commands , cmd , cmd_len TSRMLS_CC )) {
588
609
case FAILURE :
589
610
if (!(PHPDBG_G (flags ) & PHPDBG_IS_QUITTING )) {
@@ -598,18 +619,15 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
598
619
}
599
620
return PHPDBG_NEXT ;
600
621
}
601
-
602
-
603
622
}
604
623
} else if (PHPDBG_G (last )) {
605
624
PHPDBG_G (last )-> handler (
606
625
PHPDBG_G (last_params ), PHPDBG_G (last_params_len ) TSRMLS_CC );
607
626
}
608
627
609
628
if (!(PHPDBG_G (flags ) & PHPDBG_IS_QUITTING )) {
610
- printf ( "phpdbg> " ) ;
629
+ goto phpdbg_interactive_enter ;
611
630
}
612
-
613
631
}
614
632
615
633
return SUCCESS ;
0 commit comments