Skip to content

cli: Clean up formatting in do_cli() #14531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 114 additions & 114 deletions sapi/cli/php_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,11 @@ static int do_cli(int argc, char **argv) /* {{{ */
volatile int request_started = 0;
char *php_optarg = NULL, *orig_optarg = NULL;
int php_optind = 1, orig_optind = 1;
char *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL;
char *arg_free=NULL, **arg_excp=&arg_free;
char *script_file=NULL, *translated_path = NULL;
char *exec_direct = NULL, *exec_run = NULL, *exec_begin = NULL, *exec_end = NULL;
char *arg_free = NULL, **arg_excp = &arg_free;
char *script_file = NULL, *translated_path = NULL;
bool interactive = false;
const char *param_error=NULL;
const char *param_error = NULL;
bool hide_argv = false;
int num_repeats = 1;
pid_t pid = getpid();
Expand All @@ -615,7 +615,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
switch (c) {

case 'i': /* php info & quit */
if (php_request_startup()==FAILURE) {
if (php_request_startup() == FAILURE) {
goto err;
}
request_started = 1;
Expand Down Expand Up @@ -651,7 +651,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
goto out;

case 'm': /* list compiled in modules */
if (php_request_startup()==FAILURE) {
if (php_request_startup() == FAILURE) {
goto err;
}
request_started = 1;
Expand Down Expand Up @@ -706,7 +706,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
param_error = param_mode_conflict;
break;
}
context.mode=PHP_CLI_MODE_PROCESS_STDIN;
context.mode = PHP_CLI_MODE_PROCESS_STDIN;
script_file = php_optarg;
break;

Expand All @@ -725,7 +725,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
if (context.mode != PHP_CLI_MODE_STANDARD) {
break;
}
context.mode=PHP_CLI_MODE_LINT;
context.mode = PHP_CLI_MODE_LINT;
/* We want to set the error exit status if at least one lint failed.
* If all were successful we set the exit status to 0.
* We already set EG(exit_status) here such that only failures set the exit status. */
Expand All @@ -746,8 +746,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
param_error = param_mode_conflict;
break;
}
context.mode=PHP_CLI_MODE_CLI_DIRECT;
exec_direct=php_optarg;
context.mode = PHP_CLI_MODE_CLI_DIRECT;
exec_direct = php_optarg;
break;

case 'R':
Expand All @@ -760,8 +760,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
param_error = param_mode_conflict;
break;
}
context.mode=PHP_CLI_MODE_PROCESS_STDIN;
exec_run=php_optarg;
context.mode = PHP_CLI_MODE_PROCESS_STDIN;
exec_run = php_optarg;
break;

case 'B':
Expand All @@ -774,8 +774,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
param_error = param_mode_conflict;
break;
}
context.mode=PHP_CLI_MODE_PROCESS_STDIN;
exec_begin=php_optarg;
context.mode = PHP_CLI_MODE_PROCESS_STDIN;
exec_begin = php_optarg;
break;

case 'E':
Expand All @@ -788,24 +788,24 @@ static int do_cli(int argc, char **argv) /* {{{ */
param_error = param_mode_conflict;
break;
}
context.mode=PHP_CLI_MODE_PROCESS_STDIN;
exec_end=php_optarg;
context.mode = PHP_CLI_MODE_PROCESS_STDIN;
exec_end = php_optarg;
break;

case 's': /* generate highlighted HTML from source */
if (context.mode == PHP_CLI_MODE_CLI_DIRECT || context.mode == PHP_CLI_MODE_PROCESS_STDIN) {
param_error = "Source highlighting only works for files.\n";
break;
}
context.mode=PHP_CLI_MODE_HIGHLIGHT;
context.mode = PHP_CLI_MODE_HIGHLIGHT;
break;

case 'w':
if (context.mode == PHP_CLI_MODE_CLI_DIRECT || context.mode == PHP_CLI_MODE_PROCESS_STDIN) {
param_error = "Source stripping only works for files.\n";
break;
}
context.mode=PHP_CLI_MODE_STRIP;
context.mode = PHP_CLI_MODE_STRIP;
break;

case 'z': /* load extension file */
Expand All @@ -815,23 +815,23 @@ static int do_cli(int argc, char **argv) /* {{{ */
hide_argv = true;
break;
case 10:
context.mode=PHP_CLI_MODE_REFLECTION_FUNCTION;
context.mode = PHP_CLI_MODE_REFLECTION_FUNCTION;
reflection_what = php_optarg;
break;
case 11:
context.mode=PHP_CLI_MODE_REFLECTION_CLASS;
context.mode = PHP_CLI_MODE_REFLECTION_CLASS;
reflection_what = php_optarg;
break;
case 12:
context.mode=PHP_CLI_MODE_REFLECTION_EXTENSION;
context.mode = PHP_CLI_MODE_REFLECTION_EXTENSION;
reflection_what = php_optarg;
break;
case 13:
context.mode=PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION;
context.mode = PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION;
reflection_what = php_optarg;
break;
case 14:
context.mode=PHP_CLI_MODE_REFLECTION_EXT_INFO;
context.mode = PHP_CLI_MODE_REFLECTION_EXT_INFO;
reflection_what = php_optarg;
break;
case 15:
Expand All @@ -858,8 +858,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
is essential to mitigate buggy console info. */
interactive = php_win32_console_is_own() &&
!(script_file ||
argc > php_optind && context.mode!=PHP_CLI_MODE_CLI_DIRECT &&
context.mode!=PHP_CLI_MODE_PROCESS_STDIN &&
argc > php_optind && context.mode != PHP_CLI_MODE_CLI_DIRECT &&
context.mode != PHP_CLI_MODE_PROCESS_STDIN &&
strcmp(argv[php_optind-1],"--")
);
}
Expand All @@ -879,11 +879,11 @@ static int do_cli(int argc, char **argv) /* {{{ */
/* only set script_file if not set already and not in direct mode and not at end of parameter list */
if (argc > php_optind
&& !script_file
&& context.mode!=PHP_CLI_MODE_CLI_DIRECT
&& context.mode!=PHP_CLI_MODE_PROCESS_STDIN
&& strcmp(argv[php_optind-1],"--"))
&& context.mode != PHP_CLI_MODE_CLI_DIRECT
&& context.mode != PHP_CLI_MODE_PROCESS_STDIN
&& strcmp(argv[php_optind - 1],"--"))
{
script_file=argv[php_optind];
script_file = argv[php_optind];
php_optind++;
}
if (script_file) {
Expand Down Expand Up @@ -913,15 +913,15 @@ static int do_cli(int argc, char **argv) /* {{{ */

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

if (php_request_startup()==FAILURE) {
if (php_request_startup() == FAILURE) {
*arg_excp = arg_free;
PUTS("Could not startup.\n");
goto err;
Expand Down Expand Up @@ -965,7 +965,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
}
break;
case PHP_CLI_MODE_STRIP:
if (open_file_for_scanning(&file_handle)==SUCCESS) {
if (open_file_for_scanning(&file_handle) == SUCCESS) {
zend_strip();
}
goto out;
Expand All @@ -974,7 +974,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
{
zend_syntax_highlighter_ini syntax_highlighter_ini;

if (open_file_for_scanning(&file_handle)==SUCCESS) {
if (open_file_for_scanning(&file_handle) == SUCCESS) {
php_get_highlight_struct(&syntax_highlighter_ini);
zend_highlight(&syntax_highlighter_ini);
}
Expand Down Expand Up @@ -1002,7 +1002,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
if (exec_begin) {
zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1);
}
while (EG(exit_status) == SUCCESS && (input=php_stream_gets(s_in_process, NULL, 0)) != NULL) {
while (EG(exit_status) == SUCCESS && (input = php_stream_gets(s_in_process, NULL, 0)) != NULL) {
len = strlen(input);
while (len > 0 && len-- && (input[len]=='\n' || input[len]=='\r')) {
input[len] = '\0';
Expand Down Expand Up @@ -1032,89 +1032,89 @@ static int do_cli(int argc, char **argv) /* {{{ */
break;
}

case PHP_CLI_MODE_REFLECTION_FUNCTION:
case PHP_CLI_MODE_REFLECTION_CLASS:
case PHP_CLI_MODE_REFLECTION_EXTENSION:
case PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION:
{
zend_class_entry *pce = NULL;
zval arg, ref;
zend_execute_data execute_data;

switch (context.mode) {
default:
break;
case PHP_CLI_MODE_REFLECTION_FUNCTION:
if (strstr(reflection_what, "::")) {
pce = reflection_method_ptr;
} else {
pce = reflection_function_ptr;
}
break;
case PHP_CLI_MODE_REFLECTION_CLASS:
pce = reflection_class_ptr;
break;
case PHP_CLI_MODE_REFLECTION_EXTENSION:
pce = reflection_extension_ptr;
break;
case PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION:
pce = reflection_zend_extension_ptr;
break;
}
case PHP_CLI_MODE_REFLECTION_FUNCTION:
case PHP_CLI_MODE_REFLECTION_CLASS:
case PHP_CLI_MODE_REFLECTION_EXTENSION:
case PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION:
{
zend_class_entry *pce = NULL;
zval arg, ref;
zend_execute_data execute_data;

ZVAL_STRING(&arg, reflection_what);
object_init_ex(&ref, pce);
switch (context.mode) {
default:
break;
case PHP_CLI_MODE_REFLECTION_FUNCTION:
if (strstr(reflection_what, "::")) {
pce = reflection_method_ptr;
} else {
pce = reflection_function_ptr;
}
break;
case PHP_CLI_MODE_REFLECTION_CLASS:
pce = reflection_class_ptr;
break;
case PHP_CLI_MODE_REFLECTION_EXTENSION:
pce = reflection_extension_ptr;
break;
case PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION:
pce = reflection_zend_extension_ptr;
break;
}

memset(&execute_data, 0, sizeof(zend_execute_data));
EG(current_execute_data) = &execute_data;
zend_call_known_instance_method_with_1_params(
pce->constructor, Z_OBJ(ref), NULL, &arg);
ZVAL_STRING(&arg, reflection_what);
object_init_ex(&ref, pce);

memset(&execute_data, 0, sizeof(zend_execute_data));
EG(current_execute_data) = &execute_data;
zend_call_known_instance_method_with_1_params(
pce->constructor, Z_OBJ(ref), NULL, &arg);

if (EG(exception)) {
zval rv;
zval *msg = zend_read_property_ex(zend_ce_exception, EG(exception), ZSTR_KNOWN(ZEND_STR_MESSAGE), /* silent */ false, &rv);
zend_printf("Exception: %s\n", Z_STRVAL_P(msg));
zend_object_release(EG(exception));
EG(exception) = NULL;
EG(exit_status) = 1;
} else {
zend_print_zval(&ref, 0);
zend_write("\n", 1);
}
zval_ptr_dtor(&ref);
zval_ptr_dtor(&arg);

if (EG(exception)) {
zval rv;
zval *msg = zend_read_property_ex(zend_ce_exception, EG(exception), ZSTR_KNOWN(ZEND_STR_MESSAGE), /* silent */ false, &rv);
zend_printf("Exception: %s\n", Z_STRVAL_P(msg));
zend_object_release(EG(exception));
EG(exception) = NULL;
EG(exit_status) = 1;
} else {
zend_print_zval(&ref, 0);
zend_write("\n", 1);
}
zval_ptr_dtor(&ref);
zval_ptr_dtor(&arg);
break;
}
case PHP_CLI_MODE_REFLECTION_EXT_INFO:
{
size_t len = strlen(reflection_what);
char *lcname = zend_str_tolower_dup(reflection_what, len);
zend_module_entry *module;

break;
}
case PHP_CLI_MODE_REFLECTION_EXT_INFO:
{
size_t len = strlen(reflection_what);
char *lcname = zend_str_tolower_dup(reflection_what, len);
zend_module_entry *module;

if ((module = zend_hash_str_find_ptr(&module_registry, lcname, len)) == NULL) {
if (!strcmp(reflection_what, "main")) {
display_ini_entries(NULL);
} else {
zend_printf("Extension '%s' not present.\n", reflection_what);
EG(exit_status) = 1;
}
if ((module = zend_hash_str_find_ptr(&module_registry, lcname, len)) == NULL) {
if (!strcmp(reflection_what, "main")) {
display_ini_entries(NULL);
} else {
php_info_print_module(module);
zend_printf("Extension '%s' not present.\n", reflection_what);
EG(exit_status) = 1;
}

efree(lcname);
break;
} else {
php_info_print_module(module);
}

case PHP_CLI_MODE_SHOW_INI_CONFIG:
{
zend_printf("Configuration File (php.ini) Path: %s\n", PHP_CONFIG_FILE_PATH);
zend_printf("Loaded Configuration File: %s\n", php_ini_opened_path ? php_ini_opened_path : "(none)");
zend_printf("Scan for additional .ini files in: %s\n", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
zend_printf("Additional .ini files parsed: %s\n", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
break;
}
efree(lcname);
break;
}

case PHP_CLI_MODE_SHOW_INI_CONFIG:
{
zend_printf("Configuration File (php.ini) Path: %s\n", PHP_CONFIG_FILE_PATH);
zend_printf("Loaded Configuration File: %s\n", php_ini_opened_path ? php_ini_opened_path : "(none)");
zend_printf("Scan for additional .ini files in: %s\n", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
zend_printf("Additional .ini files parsed: %s\n", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
break;
}
}
} zend_end_try();

Expand All @@ -1130,7 +1130,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
free(translated_path);
translated_path = NULL;
}
if (context.mode == PHP_CLI_MODE_LINT && argc > php_optind && strcmp(argv[php_optind],"--")) {
if (context.mode == PHP_CLI_MODE_LINT && argc > php_optind && strcmp(argv[php_optind], "--")) {
script_file = NULL;
goto do_repeat;
}
Expand Down