]> granicus.if.org Git - php/commitdiff
embed code in .phpdbginit
authorkrakjoe <joe.watkins@live.co.uk>
Fri, 15 Nov 2013 14:53:40 +0000 (14:53 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Fri, 15 Nov 2013 14:53:40 +0000 (14:53 +0000)
.phpdbginit
phpdbg_prompt.c
phpdbg_prompt.h

index 5e7bffbf1d9a013ee3ff948d70ec8bc92256c8ea..3e44053b20a7f3fb1918ad6fe13429f1fe631abd 100644 (file)
@@ -13,3 +13,6 @@
 # b m my::method
 # e my.php
 # c
+php:
+    
+end;
index 3d693afa58947e2ee9bc81e364684fddf0a2e453..ed5b61f0e2a778a6fe0a8efe6b49de3d440bf3fa 100644 (file)
@@ -73,10 +73,71 @@ static const phpdbg_command_t phpdbg_prompt_commands[] = {
 
 ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
 
+int phpdbg_confirm(char *message TSRMLS_DC)
+{
+    char cmd[PHPDBG_MAX_CMD];
+    
+    zend_bool confirmed = 0, 
+              result = 0;
+    
+    phpdbg_writeln(message);
+        
+    do {
+        phpdbg_error("Confirm (y or n) ?");
+
+        if ((fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL)) {
+            switch (cmd[0]) {
+                case 'y':
+                case 'Y': {
+                    result = 1;
+                    confirmed = 1;
+                } break;
+                
+                case 'n':
+                case 'N': {
+                    confirmed = 1;
+                } break;
+            }
+        }
+    } while (!confirmed);
+
+    return result;
+}
+
+void phpdbg_sigint_handler(int signum)
+{
+    TSRMLS_FETCH();
+    
+    phpdbg_writeln(EMPTY);
+    
+    signal(signum, SIG_IGN);
+    
+    if (EG(in_execution)) {
+        if (phpdbg_confirm(
+                "Do you really want to quit while executing ?" TSRMLS_CC)) {
+            PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
+            
+            zend_bailout();
+        } else {
+            signal(
+                SIGINT, phpdbg_sigint_handler);
+            phpdbg_interactive(TSRMLS_C);
+        }
+    } else {
+        phpdbg_notice("Interrupted ...");
+        
+        PHPDBG_G(flags) = PHPDBG_IS_QUITTING;
+        
+        zend_bailout();
+    }
+}
+
 void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC) /* {{{ */
 {
     zend_bool init_default = 0;
     
+    signal(SIGINT, phpdbg_sigint_handler);
+    
     if (!init_file && use_default) {
         struct stat sb;
         
@@ -90,9 +151,13 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TS
     if (init_file) {
         FILE *fp = fopen(init_file, "r");
         if (fp) {
+            int line = 1;
+            
             char cmd[PHPDBG_MAX_CMD];
             size_t cmd_len = 0L;
-            int line = 1;
+            char *code = NULL;
+            size_t code_len = 0L;
+            zend_bool in_code = 0;
             
             while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) {
                 cmd_len = strlen(cmd)-1;
@@ -103,15 +168,56 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TS
                        cmd[cmd_len] = '\0';
 
                        if (*cmd && cmd_len > 0L && cmd[0] != '#') {
-                           switch (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
-                               case FAILURE:
-                                   phpdbg_error(
-                                       "Unrecognized command in %s:%d: %s!", init_file, line, cmd);
-                               break;
+                           if (cmd_len == 2) {
+                               if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) {
+                                   in_code = 1;
+                                   goto next_line;
+                               } else {
+                                   if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) {
+                                       in_code = 0;
+                                       code[code_len] = '\0';
+                                       {
+                                           zend_eval_stringl(
+                                               code, code_len, NULL, "phpdbginit code" TSRMLS_CC);
+                                       }
+                                       free(code);
+                                       code = NULL;
+                                       goto next_line;
+                                   }
+                               }
+                           }
+                           
+                           if (in_code) {
+                               if (code == NULL) {
+                                   code = malloc(cmd_len);
+                               } else code = realloc(code, code_len + cmd_len);
+                               
+                               if (code) {
+                                   memcpy(
+                                       &code[code_len], cmd, cmd_len);
+                                   code_len += cmd_len;
+                               }
+                               goto next_line;
+                           }
+                           
+                           switch (cmd[0]) {
+                               
+                               default: switch (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
+                                   case FAILURE:
+                                       phpdbg_error(
+                                           "Unrecognized command in %s:%d: %s!", init_file, line, cmd);
+                                   break;
+                               }
                            }
                        }
+next_line:
                        line++;
             }
+            
+            if (code) {
+                free(code);
+            }
+            
             fclose(fp);
         } else {
             phpdbg_error(
index 690d767693496ce07f6f431a905607d0fcb3a3f4..3937940bba88e0b56d76aab4321fcd655a1c1eee 100644 (file)
@@ -63,6 +63,7 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le
 
 void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC);
 void phpdbg_welcome(zend_bool cleaning TSRMLS_DC);
+int phpdbg_confirm(char *message TSRMLS_DC);
 int phpdbg_interactive(TSRMLS_D);
 void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags TSRMLS_DC);
 void phpdbg_clean(zend_bool full TSRMLS_DC);