Skip to content

Commit 10a6f0b

Browse files
authored
cli: Clean up formatting in do_cli() (#14531)
* cli: Add spaces around operators in do_cli() * cli: Unify `switch()` body indentation in `do_cli()`
1 parent 6c9d443 commit 10a6f0b

File tree

1 file changed

+114
-114
lines changed

1 file changed

+114
-114
lines changed

sapi/cli/php_cli.c

Lines changed: 114 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,11 @@ static int do_cli(int argc, char **argv) /* {{{ */
596596
volatile int request_started = 0;
597597
char *php_optarg = NULL, *orig_optarg = NULL;
598598
int php_optind = 1, orig_optind = 1;
599-
char *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL;
600-
char *arg_free=NULL, **arg_excp=&arg_free;
601-
char *script_file=NULL, *translated_path = NULL;
599+
char *exec_direct = NULL, *exec_run = NULL, *exec_begin = NULL, *exec_end = NULL;
600+
char *arg_free = NULL, **arg_excp = &arg_free;
601+
char *script_file = NULL, *translated_path = NULL;
602602
bool interactive = false;
603-
const char *param_error=NULL;
603+
const char *param_error = NULL;
604604
bool hide_argv = false;
605605
int num_repeats = 1;
606606
pid_t pid = getpid();
@@ -615,7 +615,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
615615
switch (c) {
616616

617617
case 'i': /* php info & quit */
618-
if (php_request_startup()==FAILURE) {
618+
if (php_request_startup() == FAILURE) {
619619
goto err;
620620
}
621621
request_started = 1;
@@ -651,7 +651,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
651651
goto out;
652652

653653
case 'm': /* list compiled in modules */
654-
if (php_request_startup()==FAILURE) {
654+
if (php_request_startup() == FAILURE) {
655655
goto err;
656656
}
657657
request_started = 1;
@@ -706,7 +706,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
706706
param_error = param_mode_conflict;
707707
break;
708708
}
709-
context.mode=PHP_CLI_MODE_PROCESS_STDIN;
709+
context.mode = PHP_CLI_MODE_PROCESS_STDIN;
710710
script_file = php_optarg;
711711
break;
712712

@@ -725,7 +725,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
725725
if (context.mode != PHP_CLI_MODE_STANDARD) {
726726
break;
727727
}
728-
context.mode=PHP_CLI_MODE_LINT;
728+
context.mode = PHP_CLI_MODE_LINT;
729729
/* We want to set the error exit status if at least one lint failed.
730730
* If all were successful we set the exit status to 0.
731731
* We already set EG(exit_status) here such that only failures set the exit status. */
@@ -746,8 +746,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
746746
param_error = param_mode_conflict;
747747
break;
748748
}
749-
context.mode=PHP_CLI_MODE_CLI_DIRECT;
750-
exec_direct=php_optarg;
749+
context.mode = PHP_CLI_MODE_CLI_DIRECT;
750+
exec_direct = php_optarg;
751751
break;
752752

753753
case 'R':
@@ -760,8 +760,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
760760
param_error = param_mode_conflict;
761761
break;
762762
}
763-
context.mode=PHP_CLI_MODE_PROCESS_STDIN;
764-
exec_run=php_optarg;
763+
context.mode = PHP_CLI_MODE_PROCESS_STDIN;
764+
exec_run = php_optarg;
765765
break;
766766

767767
case 'B':
@@ -774,8 +774,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
774774
param_error = param_mode_conflict;
775775
break;
776776
}
777-
context.mode=PHP_CLI_MODE_PROCESS_STDIN;
778-
exec_begin=php_optarg;
777+
context.mode = PHP_CLI_MODE_PROCESS_STDIN;
778+
exec_begin = php_optarg;
779779
break;
780780

781781
case 'E':
@@ -788,24 +788,24 @@ static int do_cli(int argc, char **argv) /* {{{ */
788788
param_error = param_mode_conflict;
789789
break;
790790
}
791-
context.mode=PHP_CLI_MODE_PROCESS_STDIN;
792-
exec_end=php_optarg;
791+
context.mode = PHP_CLI_MODE_PROCESS_STDIN;
792+
exec_end = php_optarg;
793793
break;
794794

795795
case 's': /* generate highlighted HTML from source */
796796
if (context.mode == PHP_CLI_MODE_CLI_DIRECT || context.mode == PHP_CLI_MODE_PROCESS_STDIN) {
797797
param_error = "Source highlighting only works for files.\n";
798798
break;
799799
}
800-
context.mode=PHP_CLI_MODE_HIGHLIGHT;
800+
context.mode = PHP_CLI_MODE_HIGHLIGHT;
801801
break;
802802

803803
case 'w':
804804
if (context.mode == PHP_CLI_MODE_CLI_DIRECT || context.mode == PHP_CLI_MODE_PROCESS_STDIN) {
805805
param_error = "Source stripping only works for files.\n";
806806
break;
807807
}
808-
context.mode=PHP_CLI_MODE_STRIP;
808+
context.mode = PHP_CLI_MODE_STRIP;
809809
break;
810810

811811
case 'z': /* load extension file */
@@ -815,23 +815,23 @@ static int do_cli(int argc, char **argv) /* {{{ */
815815
hide_argv = true;
816816
break;
817817
case 10:
818-
context.mode=PHP_CLI_MODE_REFLECTION_FUNCTION;
818+
context.mode = PHP_CLI_MODE_REFLECTION_FUNCTION;
819819
reflection_what = php_optarg;
820820
break;
821821
case 11:
822-
context.mode=PHP_CLI_MODE_REFLECTION_CLASS;
822+
context.mode = PHP_CLI_MODE_REFLECTION_CLASS;
823823
reflection_what = php_optarg;
824824
break;
825825
case 12:
826-
context.mode=PHP_CLI_MODE_REFLECTION_EXTENSION;
826+
context.mode = PHP_CLI_MODE_REFLECTION_EXTENSION;
827827
reflection_what = php_optarg;
828828
break;
829829
case 13:
830-
context.mode=PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION;
830+
context.mode = PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION;
831831
reflection_what = php_optarg;
832832
break;
833833
case 14:
834-
context.mode=PHP_CLI_MODE_REFLECTION_EXT_INFO;
834+
context.mode = PHP_CLI_MODE_REFLECTION_EXT_INFO;
835835
reflection_what = php_optarg;
836836
break;
837837
case 15:
@@ -858,8 +858,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
858858
is essential to mitigate buggy console info. */
859859
interactive = php_win32_console_is_own() &&
860860
!(script_file ||
861-
argc > php_optind && context.mode!=PHP_CLI_MODE_CLI_DIRECT &&
862-
context.mode!=PHP_CLI_MODE_PROCESS_STDIN &&
861+
argc > php_optind && context.mode != PHP_CLI_MODE_CLI_DIRECT &&
862+
context.mode != PHP_CLI_MODE_PROCESS_STDIN &&
863863
strcmp(argv[php_optind-1],"--")
864864
);
865865
}
@@ -879,11 +879,11 @@ static int do_cli(int argc, char **argv) /* {{{ */
879879
/* only set script_file if not set already and not in direct mode and not at end of parameter list */
880880
if (argc > php_optind
881881
&& !script_file
882-
&& context.mode!=PHP_CLI_MODE_CLI_DIRECT
883-
&& context.mode!=PHP_CLI_MODE_PROCESS_STDIN
884-
&& strcmp(argv[php_optind-1],"--"))
882+
&& context.mode != PHP_CLI_MODE_CLI_DIRECT
883+
&& context.mode != PHP_CLI_MODE_PROCESS_STDIN
884+
&& strcmp(argv[php_optind - 1],"--"))
885885
{
886-
script_file=argv[php_optind];
886+
script_file = argv[php_optind];
887887
php_optind++;
888888
}
889889
if (script_file) {
@@ -913,15 +913,15 @@ static int do_cli(int argc, char **argv) /* {{{ */
913913

914914
/* before registering argv to module exchange the *new* argv[0] */
915915
/* we can achieve this without allocating more memory */
916-
SG(request_info).argc=argc-php_optind+1;
917-
arg_excp = argv+php_optind-1;
918-
arg_free = argv[php_optind-1];
916+
SG(request_info).argc = argc - php_optind + 1;
917+
arg_excp = argv + php_optind - 1;
918+
arg_free = argv[php_optind - 1];
919919
SG(request_info).path_translated = translated_path ? translated_path : php_self;
920-
argv[php_optind-1] = php_self;
921-
SG(request_info).argv=argv+php_optind-1;
920+
argv[php_optind - 1] = php_self;
921+
SG(request_info).argv = argv + php_optind - 1;
922922
SG(server_context) = &context;
923923

924-
if (php_request_startup()==FAILURE) {
924+
if (php_request_startup() == FAILURE) {
925925
*arg_excp = arg_free;
926926
PUTS("Could not startup.\n");
927927
goto err;
@@ -965,7 +965,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
965965
}
966966
break;
967967
case PHP_CLI_MODE_STRIP:
968-
if (open_file_for_scanning(&file_handle)==SUCCESS) {
968+
if (open_file_for_scanning(&file_handle) == SUCCESS) {
969969
zend_strip();
970970
}
971971
goto out;
@@ -974,7 +974,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
974974
{
975975
zend_syntax_highlighter_ini syntax_highlighter_ini;
976976

977-
if (open_file_for_scanning(&file_handle)==SUCCESS) {
977+
if (open_file_for_scanning(&file_handle) == SUCCESS) {
978978
php_get_highlight_struct(&syntax_highlighter_ini);
979979
zend_highlight(&syntax_highlighter_ini);
980980
}
@@ -1002,7 +1002,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
10021002
if (exec_begin) {
10031003
zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1);
10041004
}
1005-
while (EG(exit_status) == SUCCESS && (input=php_stream_gets(s_in_process, NULL, 0)) != NULL) {
1005+
while (EG(exit_status) == SUCCESS && (input = php_stream_gets(s_in_process, NULL, 0)) != NULL) {
10061006
len = strlen(input);
10071007
while (len > 0 && len-- && (input[len]=='\n' || input[len]=='\r')) {
10081008
input[len] = '\0';
@@ -1032,89 +1032,89 @@ static int do_cli(int argc, char **argv) /* {{{ */
10321032
break;
10331033
}
10341034

1035-
case PHP_CLI_MODE_REFLECTION_FUNCTION:
1036-
case PHP_CLI_MODE_REFLECTION_CLASS:
1037-
case PHP_CLI_MODE_REFLECTION_EXTENSION:
1038-
case PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION:
1039-
{
1040-
zend_class_entry *pce = NULL;
1041-
zval arg, ref;
1042-
zend_execute_data execute_data;
1043-
1044-
switch (context.mode) {
1045-
default:
1046-
break;
1047-
case PHP_CLI_MODE_REFLECTION_FUNCTION:
1048-
if (strstr(reflection_what, "::")) {
1049-
pce = reflection_method_ptr;
1050-
} else {
1051-
pce = reflection_function_ptr;
1052-
}
1053-
break;
1054-
case PHP_CLI_MODE_REFLECTION_CLASS:
1055-
pce = reflection_class_ptr;
1056-
break;
1057-
case PHP_CLI_MODE_REFLECTION_EXTENSION:
1058-
pce = reflection_extension_ptr;
1059-
break;
1060-
case PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION:
1061-
pce = reflection_zend_extension_ptr;
1062-
break;
1063-
}
1035+
case PHP_CLI_MODE_REFLECTION_FUNCTION:
1036+
case PHP_CLI_MODE_REFLECTION_CLASS:
1037+
case PHP_CLI_MODE_REFLECTION_EXTENSION:
1038+
case PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION:
1039+
{
1040+
zend_class_entry *pce = NULL;
1041+
zval arg, ref;
1042+
zend_execute_data execute_data;
10641043

1065-
ZVAL_STRING(&arg, reflection_what);
1066-
object_init_ex(&ref, pce);
1044+
switch (context.mode) {
1045+
default:
1046+
break;
1047+
case PHP_CLI_MODE_REFLECTION_FUNCTION:
1048+
if (strstr(reflection_what, "::")) {
1049+
pce = reflection_method_ptr;
1050+
} else {
1051+
pce = reflection_function_ptr;
1052+
}
1053+
break;
1054+
case PHP_CLI_MODE_REFLECTION_CLASS:
1055+
pce = reflection_class_ptr;
1056+
break;
1057+
case PHP_CLI_MODE_REFLECTION_EXTENSION:
1058+
pce = reflection_extension_ptr;
1059+
break;
1060+
case PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION:
1061+
pce = reflection_zend_extension_ptr;
1062+
break;
1063+
}
10671064

1068-
memset(&execute_data, 0, sizeof(zend_execute_data));
1069-
EG(current_execute_data) = &execute_data;
1070-
zend_call_known_instance_method_with_1_params(
1071-
pce->constructor, Z_OBJ(ref), NULL, &arg);
1065+
ZVAL_STRING(&arg, reflection_what);
1066+
object_init_ex(&ref, pce);
1067+
1068+
memset(&execute_data, 0, sizeof(zend_execute_data));
1069+
EG(current_execute_data) = &execute_data;
1070+
zend_call_known_instance_method_with_1_params(
1071+
pce->constructor, Z_OBJ(ref), NULL, &arg);
1072+
1073+
if (EG(exception)) {
1074+
zval rv;
1075+
zval *msg = zend_read_property_ex(zend_ce_exception, EG(exception), ZSTR_KNOWN(ZEND_STR_MESSAGE), /* silent */ false, &rv);
1076+
zend_printf("Exception: %s\n", Z_STRVAL_P(msg));
1077+
zend_object_release(EG(exception));
1078+
EG(exception) = NULL;
1079+
EG(exit_status) = 1;
1080+
} else {
1081+
zend_print_zval(&ref, 0);
1082+
zend_write("\n", 1);
1083+
}
1084+
zval_ptr_dtor(&ref);
1085+
zval_ptr_dtor(&arg);
10721086

1073-
if (EG(exception)) {
1074-
zval rv;
1075-
zval *msg = zend_read_property_ex(zend_ce_exception, EG(exception), ZSTR_KNOWN(ZEND_STR_MESSAGE), /* silent */ false, &rv);
1076-
zend_printf("Exception: %s\n", Z_STRVAL_P(msg));
1077-
zend_object_release(EG(exception));
1078-
EG(exception) = NULL;
1079-
EG(exit_status) = 1;
1080-
} else {
1081-
zend_print_zval(&ref, 0);
1082-
zend_write("\n", 1);
1083-
}
1084-
zval_ptr_dtor(&ref);
1085-
zval_ptr_dtor(&arg);
1087+
break;
1088+
}
1089+
case PHP_CLI_MODE_REFLECTION_EXT_INFO:
1090+
{
1091+
size_t len = strlen(reflection_what);
1092+
char *lcname = zend_str_tolower_dup(reflection_what, len);
1093+
zend_module_entry *module;
10861094

1087-
break;
1088-
}
1089-
case PHP_CLI_MODE_REFLECTION_EXT_INFO:
1090-
{
1091-
size_t len = strlen(reflection_what);
1092-
char *lcname = zend_str_tolower_dup(reflection_what, len);
1093-
zend_module_entry *module;
1094-
1095-
if ((module = zend_hash_str_find_ptr(&module_registry, lcname, len)) == NULL) {
1096-
if (!strcmp(reflection_what, "main")) {
1097-
display_ini_entries(NULL);
1098-
} else {
1099-
zend_printf("Extension '%s' not present.\n", reflection_what);
1100-
EG(exit_status) = 1;
1101-
}
1095+
if ((module = zend_hash_str_find_ptr(&module_registry, lcname, len)) == NULL) {
1096+
if (!strcmp(reflection_what, "main")) {
1097+
display_ini_entries(NULL);
11021098
} else {
1103-
php_info_print_module(module);
1099+
zend_printf("Extension '%s' not present.\n", reflection_what);
1100+
EG(exit_status) = 1;
11041101
}
1105-
1106-
efree(lcname);
1107-
break;
1102+
} else {
1103+
php_info_print_module(module);
11081104
}
11091105

1110-
case PHP_CLI_MODE_SHOW_INI_CONFIG:
1111-
{
1112-
zend_printf("Configuration File (php.ini) Path: %s\n", PHP_CONFIG_FILE_PATH);
1113-
zend_printf("Loaded Configuration File: %s\n", php_ini_opened_path ? php_ini_opened_path : "(none)");
1114-
zend_printf("Scan for additional .ini files in: %s\n", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
1115-
zend_printf("Additional .ini files parsed: %s\n", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
1116-
break;
1117-
}
1106+
efree(lcname);
1107+
break;
1108+
}
1109+
1110+
case PHP_CLI_MODE_SHOW_INI_CONFIG:
1111+
{
1112+
zend_printf("Configuration File (php.ini) Path: %s\n", PHP_CONFIG_FILE_PATH);
1113+
zend_printf("Loaded Configuration File: %s\n", php_ini_opened_path ? php_ini_opened_path : "(none)");
1114+
zend_printf("Scan for additional .ini files in: %s\n", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
1115+
zend_printf("Additional .ini files parsed: %s\n", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
1116+
break;
1117+
}
11181118
}
11191119
} zend_end_try();
11201120

@@ -1130,7 +1130,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
11301130
free(translated_path);
11311131
translated_path = NULL;
11321132
}
1133-
if (context.mode == PHP_CLI_MODE_LINT && argc > php_optind && strcmp(argv[php_optind],"--")) {
1133+
if (context.mode == PHP_CLI_MODE_LINT && argc > php_optind && strcmp(argv[php_optind], "--")) {
11341134
script_file = NULL;
11351135
goto do_repeat;
11361136
}

0 commit comments

Comments
 (0)