]> granicus.if.org Git - php/commitdiff
switches in list.c, be consistent in all command handlers
authorkrakjoe <joe.watkins@live.co.uk>
Sat, 16 Nov 2013 22:58:30 +0000 (22:58 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Sat, 16 Nov 2013 22:58:30 +0000 (22:58 +0000)
phpdbg_list.c
phpdbg_prompt.c

index 04f137dcd5d7016f5ec14f1d338ee495feb42a3d..7074fb215465065b2d85f99c92bd0700e0ce55b8 100644 (file)
@@ -90,12 +90,13 @@ PHPDBG_LIST(lines) /* {{{ */
 
 PHPDBG_LIST(func) /* {{{ */
 {
-    if (param->type == STR_PARAM) {
-        i_phpdbg_list_func(
-            param->str, param->len TSRMLS_CC);
-    } else {
-        phpdbg_error(
-            "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
+    switch (param->type) {
+        case STR_PARAM:
+            i_phpdbg_list_func(
+                param->str, param->len TSRMLS_CC);
+        break;
+        
+        phpdbg_default_switch_case();
     }
     
     return SUCCESS;
@@ -103,28 +104,29 @@ PHPDBG_LIST(func) /* {{{ */
 
 PHPDBG_LIST(method) /* {{{ */
 {
-    if (param->type == METHOD_PARAM) {
-        zend_class_entry **ce;
+    switch (param->type) {
+        case METHOD_PARAM: {
+            zend_class_entry **ce;
         
-        if (zend_lookup_class(param->method.class, strlen(param->method.class), &ce TSRMLS_CC) == SUCCESS) {
-            zend_function *function;
-            char *lcname = zend_str_tolower_dup(
-                param->method.name, strlen(param->method.name));
-            
-            if (zend_hash_find(&(*ce)->function_table, lcname, strlen(lcname)+1, (void**) &function) == SUCCESS) {
-                phpdbg_list_function(
-                    function TSRMLS_CC);
+            if (zend_lookup_class(param->method.class, strlen(param->method.class), &ce TSRMLS_CC) == SUCCESS) {
+                zend_function *function;
+                char *lcname = zend_str_tolower_dup(
+                    param->method.name, strlen(param->method.name));
+                
+                if (zend_hash_find(&(*ce)->function_table, lcname, strlen(lcname)+1, (void**) &function) == SUCCESS) {
+                    phpdbg_list_function(
+                        function TSRMLS_CC);
+                } else {
+                    phpdbg_error("Could not find ::%s in %s", param->method.name, param->method.class);
+                }
+                
+                efree(lcname);
             } else {
-                phpdbg_error("Could not find ::%s in %s", param->method.name, param->method.class);
+                phpdbg_error("Could not find the class %s", param->method.class);
             }
-            
-            efree(lcname);
-        } else {
-            phpdbg_error("Could not find the class %s", param->method.class);
-        }
-    } else {
-        phpdbg_error(
-            "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
+        } break;
+        
+        phpdbg_default_switch_case();
     }
     
     return SUCCESS;
@@ -132,29 +134,30 @@ PHPDBG_LIST(method) /* {{{ */
 
 PHPDBG_LIST(class) /* {{{ */
 {
-    if (param->type == STR_PARAM) {
-        zend_class_entry **ce;
+    switch (param->type) {
+        case STR_PARAM: {
+            zend_class_entry **ce;
         
-        if (zend_lookup_class(param->str, param->len, &ce TSRMLS_CC) == SUCCESS) {
-            if ((*ce)->type == ZEND_USER_CLASS) {
-                if ((*ce)->info.user.filename) {
-                    phpdbg_list_file(
-                        (*ce)->info.user.filename,
-                        (*ce)->info.user.line_end - (*ce)->info.user.line_start + 1,
-                        (*ce)->info.user.line_start TSRMLS_CC
-                    );
+            if (zend_lookup_class(param->str, param->len, &ce TSRMLS_CC) == SUCCESS) {
+                if ((*ce)->type == ZEND_USER_CLASS) {
+                    if ((*ce)->info.user.filename) {
+                        phpdbg_list_file(
+                            (*ce)->info.user.filename,
+                            (*ce)->info.user.line_end - (*ce)->info.user.line_start + 1,
+                            (*ce)->info.user.line_start TSRMLS_CC
+                        );
+                    } else {
+                        phpdbg_error("The source of the requested class (%s) cannot be found", (*ce)->name);
+                    }
                 } else {
-                    phpdbg_error("The source of the requested class (%s) cannot be found", (*ce)->name);
+                    phpdbg_error("The class requested (%s) is not user defined", (*ce)->name);
                 }
             } else {
-                phpdbg_error("The class requested (%s) is not user defined", (*ce)->name);
+                phpdbg_error("The requested class (%s) could not be found", param->str);
             }
-        } else {
-            phpdbg_error("The requested class (%s) could not be found", param->str);
-        }
-    } else {
-        phpdbg_error(
-            "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
+        } break;
+        
+        phpdbg_default_switch_case();
     }
     
     return SUCCESS;
@@ -184,10 +187,7 @@ void phpdbg_list_dispatch(phpdbg_param_t *param TSRMLS_DC) /* {{{ */
                    phpdbg_do_list_method(param TSRMLS_CC);
                break;
                
-               default:
-            phpdbg_error(
-                "Unsupported parameter type (%s) for function", phpdbg_get_param_type(param TSRMLS_CC));
-                       break;
+               phpdbg_default_switch_case();
     }
 } /* }}} */
 
index 91caf4525ee659a3f84b29adcc416c02262fdb8b..393485e0da50358aa05542e8d7d378e43d92ea46 100644 (file)
@@ -190,43 +190,45 @@ void phpdbg_welcome(zend_bool cleaning TSRMLS_DC) /* {{{ */
 
 static PHPDBG_COMMAND(exec) /* {{{ */
 {
-       if (param->type == STR_PARAM) {
-        struct stat sb;
-        
-        if (VCWD_STAT(param->str, &sb) != FAILURE) {
-            if (sb.st_mode & S_IFREG|S_IFLNK) {
-                if (PHPDBG_G(exec)) {
-                       phpdbg_notice("Unsetting old execution context: %s", PHPDBG_G(exec));
-                       efree(PHPDBG_G(exec));
-                       PHPDBG_G(exec) = NULL;
-                }
-
-                if (PHPDBG_G(ops)) {
-                       phpdbg_notice("Destroying compiled opcodes");
-                       phpdbg_clean(0 TSRMLS_CC);
-                }
-
-                PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC);
-
-                if (!PHPDBG_G(exec)) {
-                       phpdbg_error("Cannot get real file path");
-                       return FAILURE;
+    switch (param->type) {
+        case STR_PARAM: {
+            struct stat sb;
+
+            if (VCWD_STAT(param->str, &sb) != FAILURE) {
+                if (sb.st_mode & S_IFREG|S_IFLNK) {
+                    if (PHPDBG_G(exec)) {
+                           phpdbg_notice("Unsetting old execution context: %s", PHPDBG_G(exec));
+                           efree(PHPDBG_G(exec));
+                           PHPDBG_G(exec) = NULL;
+                    }
+
+                    if (PHPDBG_G(ops)) {
+                           phpdbg_notice("Destroying compiled opcodes");
+                           phpdbg_clean(0 TSRMLS_CC);
+                    }
+
+                    PHPDBG_G(exec) = phpdbg_resolve_path(param->str TSRMLS_CC);
+
+                    if (!PHPDBG_G(exec)) {
+                           phpdbg_error("Cannot get real file path");
+                           return FAILURE;
+                    }
+
+                    PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec));
+
+                    phpdbg_notice("Set execution context: %s", PHPDBG_G(exec));
+                    
+                } else {
+                    phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str);
                 }
-
-                PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec));
-
-                phpdbg_notice("Set execution context: %s", PHPDBG_G(exec));
-                
             } else {
-                phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str);
+                phpdbg_error("Cannot stat %s, ensure the file exists", param->str);
             }
-        } else {
-            phpdbg_error("Cannot stat %s, ensure the file exists", param->str);
-        }
-    } else {
-        phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
+        } break;
+        
+        phpdbg_default_switch_case();
     }
-       
+
        return SUCCESS;
 } /* }}} */
 
@@ -274,18 +276,21 @@ static PHPDBG_COMMAND(compile) /* {{{ */
 
 static PHPDBG_COMMAND(step) /* {{{ */
 {
-       if (param->type == EMPTY_PARAM || param->type == NUMERIC_PARAM) {
-           if (param->type == NUMERIC_PARAM && param->num) {
-               PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
-           } else {
-               PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING;
-           }
-
-           phpdbg_notice("Stepping %s",
-               (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
-       } else {
-           phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
-       }
+    switch (param->type) {
+        case EMPTY_PARAM:
+        case NUMERIC_PARAM: {
+            if (param->type == NUMERIC_PARAM && param->num) {
+                   PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
+               } else {
+                   PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING;
+               }
+
+               phpdbg_notice("Stepping %s",
+                   (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
+        } break;
+        
+        phpdbg_default_switch_case();
+    }
 
        return SUCCESS;
 } /* }}} */
@@ -352,33 +357,33 @@ static PHPDBG_COMMAND(run) /* {{{ */
 
 static PHPDBG_COMMAND(eval) /* {{{ */
 {
-       if (param->type == STR_PARAM) { 
-        zend_bool stepping = (PHPDBG_G(flags) & PHPDBG_IS_STEPPING);
-        zval retval;
-
-        PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING;
-
-        /* disable stepping while eval() in progress */
-        PHPDBG_G(flags) |= PHPDBG_IN_EVAL;
-        if (zend_eval_stringl(param->str, param->len,
-               &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
-               zend_print_zval_r(
-                   &retval, 0 TSRMLS_CC);
-               phpdbg_writeln(EMPTY);
-               zval_dtor(&retval);
-        }
-        PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL;
+    switch (param->type) {
+        case STR_PARAM: {
+            zend_bool stepping = (PHPDBG_G(flags) & PHPDBG_IS_STEPPING);
+            zval retval;
+
+            PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING;
+
+            /* disable stepping while eval() in progress */
+            PHPDBG_G(flags) |= PHPDBG_IN_EVAL;
+            if (zend_eval_stringl(param->str, param->len,
+                   &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
+                   zend_print_zval_r(
+                       &retval, 0 TSRMLS_CC);
+                   phpdbg_writeln(EMPTY);
+                   zval_dtor(&retval);
+            }
+            PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL;
 
-        /* switch stepping back on */
-        if (stepping) {
-               PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
-        }
-    } else {
-        phpdbg_error(
-            "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
-        return FAILURE;
+            /* switch stepping back on */
+            if (stepping) {
+                   PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
+            }
+        } break;
+        
+        phpdbg_default_switch_case();
     }
-       
+
        return SUCCESS;
 } /* }}} */
 
@@ -412,16 +417,12 @@ static PHPDBG_COMMAND(back) /* {{{ */
 
                phpdbg_writeln(EMPTY);
                zval_dtor(&zbacktrace);
-               
-               return SUCCESS;
         } break;
-        
-        default: {
-            phpdbg_error(
-                   "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
-               return FAILURE;
-        }
+
+        phpdbg_default_switch_case();
     }
+    
+    return SUCCESS;
 } /* }}} */
 
 static PHPDBG_COMMAND(print) /* {{{ */
@@ -493,10 +494,7 @@ static PHPDBG_COMMAND(break) /* {{{ */
                        phpdbg_set_breakpoint_symbol(param->str TSRMLS_CC);
                        break;
                        
-               default:
-                   phpdbg_error(
-                       "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
-                       return FAILURE;
+               phpdbg_default_switch_case();
        }
 
        return SUCCESS;
@@ -583,42 +581,41 @@ static PHPDBG_COMMAND(aliases) /* {{{ */
 
 static PHPDBG_COMMAND(oplog) /* {{{ */
 {
-    if (param->type == EMPTY_PARAM || 
-        ((param->type == NUMERIC_PARAM) && !param->num)) {
-        if (PHPDBG_G(oplog)) {
-            phpdbg_notice("Disabling oplog");
-            fclose(
-                PHPDBG_G(oplog));
-            return SUCCESS;
-        } else {
-            phpdbg_error("No oplog currently open");
-            return FAILURE;
-        }
-    } else {
-        if (param->type == STR_PARAM) {
-            /* open oplog */
+    switch (param->type) {
+        case EMPTY_PARAM:
+        case NUMERIC_PARAM:
+            if ((param->type != NUMERIC_PARAM) || !param->num) {
+                if (PHPDBG_G(oplog)) {
+                    phpdbg_notice("Disabling oplog");
+                    fclose(
+                        PHPDBG_G(oplog));
+                } else {
+                    phpdbg_error("No oplog currently open");
+                }
+            }
+        break;
+        
+        case STR_PARAM: {
+             /* open oplog */
             FILE *old = PHPDBG_G(oplog);
 
             PHPDBG_G(oplog) = fopen(param->str, "w+");
             if (!PHPDBG_G(oplog)) {
                 phpdbg_error("Failed to open %s for oplog", param->str);
                 PHPDBG_G(oplog) = old;
-                return FAILURE;
             } else {
                 if (old) {
                     phpdbg_notice("Closing previously open oplog");
                     fclose(old);
                 }
                 phpdbg_notice("Successfully opened oplog %s", param->str);
-
-                return SUCCESS;
             }
-        } else {
-            phpdbg_error(
-                "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC));
-            return FAILURE;
-        }
+        } break;
+        
+        phpdbg_default_switch_case();
     }
+    
+    return SUCCESS;
 } /* }}} */
 
 static PHPDBG_COMMAND(help) /* {{{ */