mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00

This patch removes the so called local variables defined per file basis for certain editors to properly show tab width, and similar settings. These are mainly used by Vim and Emacs editors yet with recent changes the once working definitions don't work anymore in Vim without custom plugins or additional configuration. Neither are these settings synced across the PHP code base. A simpler and better approach is EditorConfig and fixing code using some code style fixing tools in the future instead. This patch also removes the so called modelines for Vim. Modelines allow Vim editor specifically to set some editor configuration such as syntax highlighting, indentation style and tab width to be set in the first line or the last 5 lines per file basis. Since the php test files have syntax highlighting already set in most editors properly and EditorConfig takes care of the indentation settings, this patch removes these as well for the Vim 6.0 and newer versions. With the removal of local variables for certain editors such as Emacs and Vim, the footer is also probably not needed anymore when creating extensions using ext_skel.php script. Additionally, Vim modelines for setting php syntax and some editor settings has been removed from some *.phpt files. All these are mostly not relevant for phpt files neither work properly in the middle of the file.
235 lines
6.1 KiB
C
235 lines
6.1 KiB
C
/*
|
|
+----------------------------------------------------------------------+
|
|
| PHP Version 7 |
|
|
+----------------------------------------------------------------------+
|
|
| Copyright (c) The PHP Group |
|
|
+----------------------------------------------------------------------+
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
| available through the world-wide-web at the following url: |
|
|
| http://www.php.net/license/3_01.txt |
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
+----------------------------------------------------------------------+
|
|
| Author: Edin Kadribasic <edink@php.net> |
|
|
+----------------------------------------------------------------------+
|
|
*/
|
|
|
|
#include "php_embed.h"
|
|
#include "ext/standard/php_standard.h"
|
|
|
|
#ifdef PHP_WIN32
|
|
#include <io.h>
|
|
#include <fcntl.h>
|
|
#endif
|
|
|
|
const char HARDCODED_INI[] =
|
|
"html_errors=0\n"
|
|
"register_argc_argv=1\n"
|
|
"implicit_flush=1\n"
|
|
"output_buffering=0\n"
|
|
"max_execution_time=0\n"
|
|
"max_input_time=-1\n\0";
|
|
|
|
#if defined(PHP_WIN32) && defined(ZTS)
|
|
ZEND_TSRMLS_CACHE_DEFINE()
|
|
#endif
|
|
|
|
static char* php_embed_read_cookies(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static int php_embed_deactivate(void)
|
|
{
|
|
fflush(stdout);
|
|
return SUCCESS;
|
|
}
|
|
|
|
static inline size_t php_embed_single_write(const char *str, size_t str_length)
|
|
{
|
|
#ifdef PHP_WRITE_STDOUT
|
|
zend_long ret;
|
|
|
|
ret = write(STDOUT_FILENO, str, str_length);
|
|
if (ret <= 0) return 0;
|
|
return ret;
|
|
#else
|
|
size_t ret;
|
|
|
|
ret = fwrite(str, 1, MIN(str_length, 16384), stdout);
|
|
return ret;
|
|
#endif
|
|
}
|
|
|
|
|
|
static size_t php_embed_ub_write(const char *str, size_t str_length)
|
|
{
|
|
const char *ptr = str;
|
|
size_t remaining = str_length;
|
|
size_t ret;
|
|
|
|
while (remaining > 0) {
|
|
ret = php_embed_single_write(ptr, remaining);
|
|
if (!ret) {
|
|
php_handle_aborted_connection();
|
|
}
|
|
ptr += ret;
|
|
remaining -= ret;
|
|
}
|
|
|
|
return str_length;
|
|
}
|
|
|
|
static void php_embed_flush(void *server_context)
|
|
{
|
|
if (fflush(stdout)==EOF) {
|
|
php_handle_aborted_connection();
|
|
}
|
|
}
|
|
|
|
static void php_embed_send_header(sapi_header_struct *sapi_header, void *server_context)
|
|
{
|
|
}
|
|
|
|
static void php_embed_log_message(char *message, int syslog_type_int)
|
|
{
|
|
fprintf (stderr, "%s\n", message);
|
|
}
|
|
|
|
static void php_embed_register_variables(zval *track_vars_array)
|
|
{
|
|
php_import_environment_variables(track_vars_array);
|
|
}
|
|
|
|
static int php_embed_startup(sapi_module_struct *sapi_module)
|
|
{
|
|
if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
|
|
return FAILURE;
|
|
}
|
|
return SUCCESS;
|
|
}
|
|
|
|
EMBED_SAPI_API sapi_module_struct php_embed_module = {
|
|
"embed", /* name */
|
|
"PHP Embedded Library", /* pretty name */
|
|
|
|
php_embed_startup, /* startup */
|
|
php_module_shutdown_wrapper, /* shutdown */
|
|
|
|
NULL, /* activate */
|
|
php_embed_deactivate, /* deactivate */
|
|
|
|
php_embed_ub_write, /* unbuffered write */
|
|
php_embed_flush, /* flush */
|
|
NULL, /* get uid */
|
|
NULL, /* getenv */
|
|
|
|
php_error, /* error handler */
|
|
|
|
NULL, /* header handler */
|
|
NULL, /* send headers handler */
|
|
php_embed_send_header, /* send header handler */
|
|
|
|
NULL, /* read POST data */
|
|
php_embed_read_cookies, /* read Cookies */
|
|
|
|
php_embed_register_variables, /* register server variables */
|
|
php_embed_log_message, /* Log message */
|
|
NULL, /* Get request time */
|
|
NULL, /* Child terminate */
|
|
|
|
STANDARD_SAPI_MODULE_PROPERTIES
|
|
};
|
|
/* }}} */
|
|
|
|
/* {{{ arginfo ext/standard/dl.c */
|
|
ZEND_BEGIN_ARG_INFO(arginfo_dl, 0)
|
|
ZEND_ARG_INFO(0, extension_filename)
|
|
ZEND_END_ARG_INFO()
|
|
/* }}} */
|
|
|
|
static const zend_function_entry additional_functions[] = {
|
|
ZEND_FE(dl, arginfo_dl)
|
|
{NULL, NULL, NULL}
|
|
};
|
|
|
|
EMBED_SAPI_API int php_embed_init(int argc, char **argv)
|
|
{
|
|
zend_llist global_vars;
|
|
|
|
#ifdef HAVE_SIGNAL_H
|
|
#if defined(SIGPIPE) && defined(SIG_IGN)
|
|
signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
|
|
that sockets created via fsockopen()
|
|
don't kill PHP if the remote site
|
|
closes it. in apache|apxs mode apache
|
|
does that for us! thies@thieso.net
|
|
20000419 */
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef ZTS
|
|
tsrm_startup(1, 1, 0, NULL);
|
|
(void)ts_resource(0);
|
|
ZEND_TSRMLS_CACHE_UPDATE();
|
|
#endif
|
|
|
|
zend_signal_startup();
|
|
|
|
sapi_startup(&php_embed_module);
|
|
|
|
#ifdef PHP_WIN32
|
|
_fmode = _O_BINARY; /*sets default for file streams to binary */
|
|
setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */
|
|
setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */
|
|
setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
|
|
#endif
|
|
|
|
php_embed_module.ini_entries = malloc(sizeof(HARDCODED_INI));
|
|
memcpy(php_embed_module.ini_entries, HARDCODED_INI, sizeof(HARDCODED_INI));
|
|
|
|
php_embed_module.additional_functions = additional_functions;
|
|
|
|
if (argv) {
|
|
php_embed_module.executable_location = argv[0];
|
|
}
|
|
|
|
if (php_embed_module.startup(&php_embed_module)==FAILURE) {
|
|
return FAILURE;
|
|
}
|
|
|
|
zend_llist_init(&global_vars, sizeof(char *), NULL, 0);
|
|
|
|
/* Set some Embedded PHP defaults */
|
|
SG(options) |= SAPI_OPTION_NO_CHDIR;
|
|
SG(request_info).argc=argc;
|
|
SG(request_info).argv=argv;
|
|
|
|
if (php_request_startup()==FAILURE) {
|
|
php_module_shutdown();
|
|
return FAILURE;
|
|
}
|
|
|
|
SG(headers_sent) = 1;
|
|
SG(request_info).no_headers = 1;
|
|
php_register_variable("PHP_SELF", "-", NULL);
|
|
|
|
return SUCCESS;
|
|
}
|
|
|
|
EMBED_SAPI_API void php_embed_shutdown(void)
|
|
{
|
|
php_request_shutdown((void *) 0);
|
|
php_module_shutdown();
|
|
sapi_shutdown();
|
|
#ifdef ZTS
|
|
tsrm_shutdown();
|
|
TSRMLS_CACHE_RESET();
|
|
#endif
|
|
if (php_embed_module.ini_entries) {
|
|
free(php_embed_module.ini_entries);
|
|
php_embed_module.ini_entries = NULL;
|
|
}
|
|
}
|