diff options
author | SVN Migration <svn@php.net> | 2006-10-15 21:09:28 +0000 |
---|---|---|
committer | SVN Migration <svn@php.net> | 2006-10-15 21:09:28 +0000 |
commit | 88ec761548b66f58acc1a86cdd0fc164ca925476 (patch) | |
tree | d0af978fa00d83bb1d82c613f66477fbd6bb18aa /sapi/cli | |
parent | 268984b4787e797db6054313fc9ba3b9e845306e (diff) | |
download | php-git-PECL_OPENSSL.tar.gz |
This commit was manufactured by cvs2svn to create branch 'PECL_OPENSSL'.PECL_OPENSSL
Diffstat (limited to 'sapi/cli')
-rw-r--r-- | sapi/cli/CREDITS | 2 | ||||
-rw-r--r-- | sapi/cli/Makefile.frag | 11 | ||||
-rw-r--r-- | sapi/cli/README | 20 | ||||
-rw-r--r-- | sapi/cli/TODO | 2 | ||||
-rw-r--r-- | sapi/cli/cli_win32.c | 2 | ||||
-rw-r--r-- | sapi/cli/config.m4 | 42 | ||||
-rw-r--r-- | sapi/cli/config.w32 | 20 | ||||
-rw-r--r-- | sapi/cli/getopt.c | 156 | ||||
-rw-r--r-- | sapi/cli/php.1.in | 406 | ||||
-rw-r--r-- | sapi/cli/php_cli.c | 1297 | ||||
-rw-r--r-- | sapi/cli/php_cli_readline.c | 449 | ||||
-rw-r--r-- | sapi/cli/php_cli_readline.h | 25 | ||||
-rw-r--r-- | sapi/cli/php_getopt.h | 39 |
13 files changed, 0 insertions, 2471 deletions
diff --git a/sapi/cli/CREDITS b/sapi/cli/CREDITS deleted file mode 100644 index 5f3b0fbe39..0000000000 --- a/sapi/cli/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -CLI -Edin Kadribasic, Marcus Boerger, Johannes Schlueter diff --git a/sapi/cli/Makefile.frag b/sapi/cli/Makefile.frag deleted file mode 100644 index 6903ca1fc0..0000000000 --- a/sapi/cli/Makefile.frag +++ /dev/null @@ -1,11 +0,0 @@ -cli: $(SAPI_CLI_PATH) - -$(SAPI_CLI_PATH): $(PHP_GLOBAL_OBJS) $(PHP_CLI_OBJS) - $(BUILD_CLI) - -install-cli: $(SAPI_CLI_PATH) - @echo "Installing PHP CLI binary: $(INSTALL_ROOT)$(bindir)/" - @$(INSTALL_CLI) - @echo "Installing PHP CLI man page: $(INSTALL_ROOT)$(mandir)/man1/" - @$(mkinstalldirs) $(INSTALL_ROOT)$(mandir)/man1 - @$(INSTALL_DATA) $(builddir)/php.1 $(INSTALL_ROOT)$(mandir)/man1/$(program_prefix)php$(program_suffix).1 diff --git a/sapi/cli/README b/sapi/cli/README deleted file mode 100644 index 9e519e9bd0..0000000000 --- a/sapi/cli/README +++ /dev/null @@ -1,20 +0,0 @@ -The CLI (command line interface) SAPI has been introduced -with a goal of making PHP better at supporting the creation of -stand alone applications. - -It is based on CGI SAPI with all CGI specific things removed. - -The main differences between the two: - -* CLI is started up in quiet mode by default. - (-q switch kept for compatibility) -* It does not change the working directory to that of the script. - (-C switch kept for compatibility) -* Plain text error message -* $argc and $argv registered irrespective of register_globals - and register_argc_argv php.ini settings. -* implicit_flush always on -* -r option which allows execution of PHP code directly from - the command line (e.g. php -r 'echo md5("test");' ) -* Other more sophisticated command line switches (see: man php) -* max_execution_time is set to unlimited, overriding php.ini setting. diff --git a/sapi/cli/TODO b/sapi/cli/TODO deleted file mode 100644 index 22e6689001..0000000000 --- a/sapi/cli/TODO +++ /dev/null @@ -1,2 +0,0 @@ -TODO: - diff --git a/sapi/cli/cli_win32.c b/sapi/cli/cli_win32.c deleted file mode 100644 index 4407fd088f..0000000000 --- a/sapi/cli/cli_win32.c +++ /dev/null @@ -1,2 +0,0 @@ -#define PHP_CLI_WIN32_NO_CONSOLE 1 -#include "php_cli.c" diff --git a/sapi/cli/config.m4 b/sapi/cli/config.m4 deleted file mode 100644 index c31ddd1209..0000000000 --- a/sapi/cli/config.m4 +++ /dev/null @@ -1,42 +0,0 @@ -dnl -dnl $Id$ -dnl - -AC_MSG_CHECKING(for CLI build) - -AC_ARG_ENABLE(cli, -[ --disable-cli Disable building CLI version of PHP - (this forces --without-pear)], -[ - PHP_SAPI_CLI=$enableval -],[ - PHP_SAPI_CLI=yes -]) - -if test "$PHP_SAPI_CLI" != "no"; then - PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/cli/Makefile.frag,$abs_srcdir/sapi/cli,sapi/cli) - SAPI_CLI_PATH=sapi/cli/php - PHP_SUBST(SAPI_CLI_PATH) - - case $host_alias in - *aix*) - BUILD_CLI="echo '\#! .' > php.sym && echo >>php.sym && nm -BCpg \`echo \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) | sed 's/\([A-Za-z0-9_]*\)\.lo/\1.o/g'\` | \$(AWK) '{ if (((\$\$2 == \"T\") || (\$\$2 == \"D\") || (\$\$2 == \"B\")) && (substr(\$\$3,1,1) != \".\")) { print \$\$3 } }' | sort -u >> php.sym && \$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) -Wl,-brtl -Wl,-bE:php.sym \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)" - ;; - *darwin*) - BUILD_CLI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_CLI_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)" - ;; - *netware*) - BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -Lnetware -lphp5lib -o \$(SAPI_CLI_PATH)" - ;; - *) - BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)" - ;; - esac - INSTALL_CLI="\$(mkinstalldirs) \$(INSTALL_ROOT)\$(bindir); \$(INSTALL) -m 0755 \$(SAPI_CLI_PATH) \$(INSTALL_ROOT)\$(bindir)/\$(program_prefix)php\$(program_suffix)\$(EXEEXT)" - - PHP_SUBST(BUILD_CLI) - PHP_SUBST(INSTALL_CLI) - PHP_OUTPUT(sapi/cli/php.1) -fi - -AC_MSG_RESULT($PHP_SAPI_CLI) diff --git a/sapi/cli/config.w32 b/sapi/cli/config.w32 deleted file mode 100644 index 98ca1d0cc3..0000000000 --- a/sapi/cli/config.w32 +++ /dev/null @@ -1,20 +0,0 @@ -// vim:ft=javascript -// $Id$ - -ARG_ENABLE('cli', 'Build CLI version of PHP', 'yes'); -ARG_ENABLE('crt-debug', 'Extra CRT debugging', 'no'); -ARG_ENABLE('cli-win32', 'Build console-less CLI version of PHP', 'no'); - -if (PHP_CLI == "yes") { - SAPI('cli', 'getopt.c php_cli.c php_cli_readline.c', 'php.exe'); - if (PHP_CRT_DEBUG == "yes") { - ADD_FLAG("CFLAGS_CLI", "/D PHP_WIN32_DEBUG_HEAP"); - } - ADD_FLAG("LDFLAGS_CLI", "/stack:8388608"); -} - -if (PHP_CLI_WIN32 == "yes") { - SAPI('cli_win32', 'getopt.c cli_win32.c php_cli_readline.c', 'php-win.exe'); - ADD_FLAG("LDFLAGS_CLI_WIN32", "/stack:8388608"); -} - diff --git a/sapi/cli/getopt.c b/sapi/cli/getopt.c deleted file mode 100644 index 4969cf52c5..0000000000 --- a/sapi/cli/getopt.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 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: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include <stdio.h> -#include <string.h> -#include <assert.h> -#include <stdlib.h> -#include "php_getopt.h" -#define OPTERRCOLON (1) -#define OPTERRNF (2) -#define OPTERRARG (3) - - -static int php_opt_error(int argc, char * const *argv, int oint, int optchr, int err, int show_err) -{ - if (show_err) - { - fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1); - switch(err) - { - case OPTERRCOLON: - fprintf(stderr, ": in flags\n"); - break; - case OPTERRNF: - fprintf(stderr, "option not found %c\n", argv[oint][optchr]); - break; - case OPTERRARG: - fprintf(stderr, "no argument for option %c\n", argv[oint][optchr]); - break; - default: - fprintf(stderr, "unknown\n"); - break; - } - } - return('?'); -} - -int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err) -{ - static int optchr = 0; - static int dash = 0; /* have already seen the - */ - int arg_start = 2; - - int opts_idx = -1; - - if (*optind >= argc) { - return(EOF); - } - if (!dash) { - if ((argv[*optind][0] != '-')) { - return(EOF); - } else { - if (!argv[*optind][1]) - { - /* - * use to specify stdin. Need to let pgm process this and - * the following args - */ - return(EOF); - } - } - } - if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) { - /* '--' indicates end of args if not followed by a known long option name */ - while (1) { - opts_idx++; - if (opts[opts_idx].opt_char == '-') { - (*optind)++; - return(EOF); - } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) { - break; - } - } - optchr = 0; - dash = 1; - arg_start = 2 + strlen(opts[opts_idx].opt_name); - } - if (!dash) { - dash = 1; - optchr = 1; - } - - /* Check if the guy tries to do a -: kind of flag */ - if (argv[*optind][optchr] == ':') { - dash = 0; - (*optind)++; - return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err)); - } - if (opts_idx < 0) { - while (1) { - opts_idx++; - if (opts[opts_idx].opt_char == '-') { - int errind = *optind; - int errchr = optchr; - - if (!argv[*optind][optchr+1]) { - dash = 0; - (*optind)++; - } else { - optchr++; - } - return(php_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err)); - } else if (argv[*optind][optchr] == opts[opts_idx].opt_char) { - break; - } - } - } - if (opts[opts_idx].need_param) { - /* Check for cases where the value of the argument - is in the form -<arg> <val> or in the form -<arg><val> */ - dash = 0; - if(!argv[*optind][arg_start]) { - (*optind)++; - if (*optind == argc) { - return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err)); - } - *optarg = argv[(*optind)++]; - } else { - *optarg = &argv[*optind][arg_start]; - (*optind)++; - } - return opts[opts_idx].opt_char; - } else { - if (arg_start == 2) { - if (!argv[*optind][optchr+1]) - { - dash = 0; - (*optind)++; - } else { - optchr++; - } - } else { - (*optind)++; - } - return opts[opts_idx].opt_char; - } - assert(0); - return(0); /* never reached */ -} diff --git a/sapi/cli/php.1.in b/sapi/cli/php.1.in deleted file mode 100644 index 4c86dec40b..0000000000 --- a/sapi/cli/php.1.in +++ /dev/null @@ -1,406 +0,0 @@ -.TH PHP 1 "2006" "The PHP Group" "Scripting Language" -.SH NAME -.TP 15 -php \- PHP Command Line Interface 'CLI' -.SH SYNOPSIS -.B php -[options] [ -.B \-f\fP ] -.IR file -[[\-\-] -.IR args.\|.\|. ] -.LP -.B php -[options] -.B \-r -.IR code -[[\-\-] -.IR args.\|.\|. ] -.LP -.B php -[options] [\-B -.IR code ] -.B \-R -.IR code -[\-E -.IR code ] -[[\-\-] -.IR args.\|.\|. ] -.LP -.B php -[options] [\-B -.IR code ] -.B \-F -.IR file -[\-E -.IR code ] -[[\-\-] -.IR args.\|.\|. ] -.LP -.B php -[options] \-\- [ -.IR args.\|.\|. ] -.LP -\fBphp \fP[options] \fB\-a\fP -.LP -.SH DESCRIPTION -\fBPHP\fP is a widely\-used general\-purpose scripting language that is especially suited for -Web development and can be embedded into HTML. This is the command line interface -that enables you to do the following: -.P -You can parse and execute files by using parameter \-f followed by the name of the -.IR file -to be executed. -.LP -Using parameter \-r you can directly execute PHP -.IR code -simply as you would do inside a -.B \.php -file when using the -.B eval() -function. -.LP -It is also possible to process the standard input line by line using either -the parameter \-R or \-F. In this mode each separate input line causes the -.IR code -specified by \-R or the -.IR file -specified by \-F to be executed. -You can access the input line by \fB$argn\fP. While processing the input lines -.B $argi -contains the number of the actual line being processed. Further more -the paramters \-B and \-E can be used to execute -.IR code -(see \-r) before and -after all input lines have been processed respectively. Notice that the -input is read from -.B STDIN -and therefore reading from -.B STDIN -explicitly changes the next input line or skips input lines. -.LP -If none of \-r \-f \-B \-R \-F or \-E is present but a single parameter is given -then this parameter is taken as the filename to parse and execute (same as -with \-f). If no parameter is present then the standard input is read and -executed. -.SH OPTIONS -.TP 15 -.PD 0 -.B \-\-interactive -.TP -.PD 1 -.B \-a -Run PHP interactively. This lets you enter snippets of PHP code that directly -get executed. When readline support is enabled you can edit the lines and also -have history support. -.TP -.PD 0 -.B \-\-php\-ini \fIpath\fP|\fIfile\fP -.TP -.PD 1 -.B \-c \fIpath\fP|\fIfile\fP -Look for -.B php.ini -file in the directory -.IR path -or use the specified -.IR file -.TP -.PD 0 -.B \-\-no\-php\-ini -.TP -.PD 1 -.B \-n -No -.B php.ini -file will be used -.TP -.PD 0 -.B \-\-define \fIfoo\fP[=\fIbar\fP] -.TP -.PD 1 -.B \-d \fIfoo\fP[=\fIbar\fP] -Define INI entry -.IR foo -with value -.IR bar -.TP -.B \-e -Generate extended information for debugger/profiler -.TP -.PD 0 -.B \-\-file \fIfile\fP -.TP -.PD 1 -.B \-f \fIfile\fP -Parse and execute -.IR file -.TP -.PD 0 -.B \-\-global \fIname\fP -.TP -.PD 1 -.B \-g \fIname\fP -Make variable -.IR name -global in script. -.TP -.PD 0 -.B \-\-help -.TP -.PD 1 -.B \-h -This help -.TP -.PD 0 -.B \-\-hide\-args -.TP -.PD 1 -.B \-H -Hide script name (\fIfile\fP) and parameters (\fIargs\.\.\.\fP) from external -tools. For example you may want to use this when a php script is started as -a daemon and the command line contains sensitive data such as passwords. -.TP -.PD 0 -.B \-\-info -.TP -.PD 1 -.B \-i -PHP information and configuration -.TP -.PD 0 -.B \-\-syntax\-check -.TP -.PD 1 -.B \-l -Syntax check only (lint) -.TP -.PD 0 -.B \-\-modules -.TP -.PD 1 -.B \-m -Show compiled in modules -.TP -.PD 0 -.B \-\-run \fIcode\fP -.TP -.PD 1 -.B \-r \fIcode\fP -Run PHP -.IR code -without using script tags -.B '<?..?>' -.TP -.PD 0 -.B \-\-process\-begin \fIcode\fP -.TP -.PD 1 -.B \-B \fIcode\fP -Run PHP -.IR code -before processing input lines -.TP -.PD 0 -.B \-\-process\-code \fIcode\fP -.TP -.PD 1 -.B \-R \fIcode\fP -Run PHP -.IR code -for every input line -.TP -.PD 0 -.B \-\-process\-file \fIfile\fP -.TP -.PD 1 -.B \-F \fIfile\fP -Parse and execute -.IR file -for every input line -.TP -.PD 0 -.B \-\-process\-end \fIcode\fP -.TP -.PD 1 -.B \-E \fIcode\fP -Run PHP -.IR code -after processing all input lines -.TP -.PD 0 -.B \-\-syntax\-highlight -.TP -.PD 1 -.B \-s -Display colour syntax highlighted source -.TP -.PD 0 -.B \-\-version -.TP -.PD 1 -.B \-v -Version number -.TP -.PD 0 -.B \-\-stripped -.TP -.PD 1 -.B \-w -Display source with stripped comments and whitespace -.TP -.PD 0 -.B \-\-zend\-extension \fIfile\fP -.TP -.PD 1 -.B \-z \fIfile\fP -Load Zend extension -.IR file -.TP -.IR args.\|.\|. -Arguments passed to script. Use -.B '\-\-' -.IR args -when first argument starts with -.B '\-' -or script is read from stdin -.TP -.PD 0 -.B \-\-rfunction -.IR name -.TP -.PD 1 -.B \-\-rf -.IR name -Shows information about function -.B name -.TP -.PD 0 -.B \-\-rclass -.IR name -.TP -.PD 1 -.B \-\-rc -.IR name -Shows information about class -.B name -.TP -.PD 0 -.B \-\-rextension -.IR name -.TP -.PD 1 -.B \-\-re -.IR name -Shows information about extension -.B name -.SH FILES -.TP 15 -.B php\-cli.ini -The configuration file for the CLI version of PHP. -.TP -.B php.ini -The standard configuration file will only be used when -.B php\-cli.ini -cannot be found. -.SH EXAMPLES -.TP 5 -\fIphp -r 'echo "Hello World\\n";'\fP -This command simply writes the text "Hello World" to standard out. -.TP -\fIphp \-r 'print_r(gd_info());'\fP -This shows the configuration of your gd extension. You can use this -to easily check which image formats you can use. If you have any -dynamic modules you may want to use the same ini file that php uses -when executed from your webserver. There are more extensions which -have such a function. For dba use: -.RS -\fIphp \-r 'print_r(dba_handlers(1));'\fP -.RE -.TP -\fIphp \-R 'echo strip_tags($argn)."\\n";'\fP -This PHP command strips off the HTML tags line by line and outputs the -result. To see how it works you can first look at the following PHP command -\'\fIphp \-d html_errors=1 \-i\fP\' which uses PHP to output HTML formatted -configuration information. If you then combine those two -\'\fIphp \.\.\.|php \.\.\.\fP\' you'll see what happens. -.TP -\fIphp \-E 'echo "Lines: $argi\\n";'\fP -Using this PHP command you can count the lines being input. -.TP -\fIphp \-R '@$l+=count(file($argn));' \-E 'echo "Lines:$l\\n";'\fP -In this example PHP expects each input line beeing a file. It counts all lines -of the files specified by each input line and shows the summarized result. -You may combine this with tools like find and change the php scriptlet. -.TP -\fIphp \-R 'echo "$argn\\n"; fgets(STDIN);'\fP -Since you have access to STDIN from within \-B \-R \-F and \-E you can skip -certain input lines with your code. But note that in such cases $argi only -counts the lines being processed by php itself. Having read this you will -guess what the above program does: skipping every second input line. -.SH TIPS -You can use a shebang line to automatically invoke php -from scripts. Only the CLI version of PHP will ignore -such a first line as shown below: -.P -.PD 0 -.RS -#!/bin/php -.P -<?php -.P - // your script -.P -?> -.RE -.PD 1 -.P -.SH SEE ALSO -For a more or less complete description of PHP look here: -.PD 0 -.P -.B http://www.php.net/manual/ -.PD 1 -.P -A nice introduction to PHP by Stig Bakken can be found here: -.PD 0 -.P -.B http://www.zend.com/zend/art/intro.php -.PD 1 -.SH BUGS -You can view the list of known bugs or report any new bug you -found at: -.PD 0 -.P -.B http://bugs.php.net -.PD 1 -.SH AUTHORS -The PHP Group: Thies C. Arntzen, Stig Bakken, Andi Gutmans, Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski. -.P -Additional work for the CLI sapi was done by Edin Kadribasic and Marcus Boerger. -.P -A List of active developers can be found here: -.PD 0 -.P -.B http://www.php.net/credits.php -.PD 1 -.P -And last but not least PHP was developed with the help of a huge amount of -contributors all around the world. -.SH VERSION INFORMATION -This manpage describes \fBphp\fP, version @PHP_VERSION@. -.SH COPYRIGHT -Copyright \(co 1997\-2006 The PHP Group -.LP -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: -.PD 0 -.P -.B http://www.php.net/license/3_01.txt -.PD 1 -.P -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 -.B license@php.net -so we can mail you a copy immediately. diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c deleted file mode 100644 index f8a81080e2..0000000000 --- a/sapi/cli/php_cli.c +++ /dev/null @@ -1,1297 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 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> | - | Marcus Boerger <helly@php.net> | - | Johannes Schlueter <johannes@php.net> | - | Parts based on CGI SAPI Module by | - | Rasmus Lerdorf, Stig Bakken and Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_globals.h" -#include "php_variables.h" -#include "zend_hash.h" -#include "zend_modules.h" -#include "zend_interfaces.h" - -#ifdef HAVE_REFLECTION -#include "ext/reflection/php_reflection.h" -#endif - -#include "SAPI.h" - -#include <stdio.h> -#include "php.h" -#ifdef PHP_WIN32 -#include "win32/time.h" -#include "win32/signal.h" -#include <process.h> -#endif -#if HAVE_SYS_TIME_H -#include <sys/time.h> -#endif -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#if HAVE_SIGNAL_H -#include <signal.h> -#endif -#if HAVE_SETLOCALE -#include <locale.h> -#endif -#include "zend.h" -#include "zend_extensions.h" -#include "php_ini.h" -#include "php_globals.h" -#include "php_main.h" -#include "fopen_wrappers.h" -#include "ext/standard/php_standard.h" -#ifdef PHP_WIN32 -#include <io.h> -#include <fcntl.h> -#include "win32/php_registry.h" -#endif - -#if HAVE_SIGNAL_H -#include <signal.h> -#endif - -#ifdef __riscos__ -#include <unixlib/local.h> -#endif - -#if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) -#include <readline/readline.h> -#if !HAVE_LIBEDIT -#include <readline/history.h> -#endif -#include "php_cli_readline.h" -#endif /* HAVE_LIBREADLINE || HAVE_LIBEDIT */ - -#include "zend_compile.h" -#include "zend_execute.h" -#include "zend_highlight.h" -#include "zend_indent.h" -#include "zend_exceptions.h" - -#include "php_getopt.h" - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -#define PHP_MODE_STANDARD 1 -#define PHP_MODE_HIGHLIGHT 2 -#define PHP_MODE_INDENT 3 -#define PHP_MODE_LINT 4 -#define PHP_MODE_STRIP 5 -#define PHP_MODE_CLI_DIRECT 6 -#define PHP_MODE_PROCESS_STDIN 7 -#define PHP_MODE_REFLECTION_FUNCTION 8 -#define PHP_MODE_REFLECTION_CLASS 9 -#define PHP_MODE_REFLECTION_EXTENSION 10 - -#define 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" - - -static char *php_optarg = NULL; -static int php_optind = 1; -#if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) -static char php_last_char = '\0'; -#endif - -static const opt_struct OPTIONS[] = { - {'a', 0, "interactive"}, - {'B', 1, "process-begin"}, - {'C', 0, "no-chdir"}, /* for compatibility with CGI (do not chdir to script directory) */ - {'c', 1, "php-ini"}, - {'d', 1, "define"}, - {'E', 1, "process-end"}, - {'e', 0, "profile-info"}, - {'F', 1, "process-file"}, - {'f', 1, "file"}, - {'h', 0, "help"}, - {'i', 0, "info"}, - {'l', 0, "syntax-check"}, - {'m', 0, "modules"}, - {'n', 0, "no-php-ini"}, - {'q', 0, "no-header"}, /* for compatibility with CGI (do not generate HTTP headers) */ - {'R', 1, "process-code"}, - {'H', 0, "hide-args"}, - {'r', 1, "run"}, - {'s', 0, "syntax-highlight"}, - {'s', 0, "syntax-highlighting"}, - {'w', 0, "strip"}, - {'?', 0, "usage"},/* help alias (both '?' and 'usage') */ - {'v', 0, "version"}, - {'z', 1, "zend-extension"}, -#ifdef HAVE_REFLECTION - {10, 1, "rf"}, - {10, 1, "rfunction"}, - {11, 1, "rc"}, - {11, 1, "rclass"}, - {12, 1, "re"}, - {12, 1, "rextension"}, -#endif - {'-', 0, NULL} /* end of args */ -}; - -static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC) -{ - php_printf("%s\n", module->name); - return 0; -} - -static int module_name_cmp(const void *a, const void *b TSRMLS_DC) -{ - Bucket *f = *((Bucket **) a); - Bucket *s = *((Bucket **) b); - - return strcasecmp(((zend_module_entry *)f->pData)->name, - ((zend_module_entry *)s->pData)->name); -} - -static void print_modules(TSRMLS_D) -{ - HashTable sorted_registry; - zend_module_entry tmp; - - zend_hash_init(&sorted_registry, 50, NULL, NULL, 1); - zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry)); - zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC); - zend_hash_apply_with_argument(&sorted_registry, (apply_func_arg_t) print_module_info, NULL TSRMLS_CC); - zend_hash_destroy(&sorted_registry); -} - -static int print_extension_info(zend_extension *ext, void *arg TSRMLS_DC) -{ - php_printf("%s\n", ext->name); - return 0; -} - -static int extension_name_cmp(const zend_llist_element **f, - const zend_llist_element **s TSRMLS_DC) -{ - return strcmp(((zend_extension *)(*f)->data)->name, - ((zend_extension *)(*s)->data)->name); -} - -static void print_extensions(TSRMLS_D) -{ - zend_llist sorted_exts; - - zend_llist_copy(&sorted_exts, &zend_extensions); - sorted_exts.dtor = NULL; - zend_llist_sort(&sorted_exts, extension_name_cmp TSRMLS_CC); - zend_llist_apply_with_argument(&sorted_exts, (llist_apply_with_arg_func_t) print_extension_info, NULL TSRMLS_CC); - zend_llist_destroy(&sorted_exts); -} - -#ifndef STDOUT_FILENO -#define STDOUT_FILENO 1 -#endif - -static inline size_t sapi_cli_single_write(const char *str, uint str_length) -{ -#ifdef PHP_WRITE_STDOUT - 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 int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC) -{ - const char *ptr = str; - uint remaining = str_length; - size_t ret; - -#if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) - if (!str_length) { - return 0; - } - php_last_char = str[str_length-1]; -#endif - - while (remaining > 0) - { - ret = sapi_cli_single_write(ptr, remaining); - if (!ret) { -#ifdef PHP_CLI_WIN32_NO_CONSOLE - break; -#else - php_handle_aborted_connection(); -#endif - } - ptr += ret; - remaining -= ret; - } - - return str_length; -} - - -static void sapi_cli_flush(void *server_context) -{ - /* Ignore EBADF here, it's caused by the fact that STDIN/STDOUT/STDERR streams - * are/could be closed before fflush() is called. - */ - if (fflush(stdout)==EOF && errno!=EBADF) { -#ifndef PHP_CLI_WIN32_NO_CONSOLE - php_handle_aborted_connection(); -#endif - } -} - -static char *php_self = ""; -static char *script_filename = ""; - -static void sapi_cli_register_variables(zval *track_vars_array TSRMLS_DC) -{ - /* In CGI mode, we consider the environment to be a part of the server - * variables - */ - php_import_environment_variables(track_vars_array TSRMLS_CC); - - /* Build the special-case PHP_SELF variable for the CLI version */ - php_register_variable("PHP_SELF", php_self, track_vars_array TSRMLS_CC); - php_register_variable("SCRIPT_NAME", php_self, track_vars_array TSRMLS_CC); - /* filenames are empty for stdin */ - php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array TSRMLS_CC); - php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array TSRMLS_CC); - /* just make it available */ - php_register_variable("DOCUMENT_ROOT", "", track_vars_array TSRMLS_CC); -} - - -static void sapi_cli_log_message(char *message) -{ - fprintf(stderr, "%s\n", message); -} - -static int sapi_cli_deactivate(TSRMLS_D) -{ - fflush(stdout); - if(SG(request_info).argv0) { - free(SG(request_info).argv0); - SG(request_info).argv0 = NULL; - } - return SUCCESS; -} - -static char* sapi_cli_read_cookies(TSRMLS_D) -{ - return NULL; -} - -static int sapi_cli_header_handler(sapi_header_struct *h, sapi_headers_struct *s TSRMLS_DC) -{ - /* free allocated header line */ - efree(h->header); - /* avoid pushing headers into SAPI headers list */ - return 0; -} - -static int sapi_cli_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) -{ - /* We do nothing here, this function is needed to prevent that the fallback - * header handling is called. */ - return SAPI_HEADER_SENT_SUCCESSFULLY; -} - -static void sapi_cli_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC) -{ -} - - -static int php_cli_startup(sapi_module_struct *sapi_module) -{ - if (php_module_startup(sapi_module, NULL, 0)==FAILURE) { - return FAILURE; - } - return SUCCESS; -} - - -/* {{{ sapi_cli_ini_defaults */ - -/* overwriteable ini defaults must be set in sapi_cli_ini_defaults() */ -#define INI_DEFAULT(name,value)\ - ZVAL_STRING(tmp, value, 0);\ - zend_hash_update(configuration_hash, name, sizeof(name), tmp, sizeof(zval), (void**)&entry);\ - Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry)) - -static void sapi_cli_ini_defaults(HashTable *configuration_hash) -{ - zval *tmp, *entry; - - MAKE_STD_ZVAL(tmp); - - INI_DEFAULT("report_zend_debug", "0"); - INI_DEFAULT("display_errors", "1"); - - FREE_ZVAL(tmp); -} -/* }}} */ - -/* {{{ sapi_module_struct cli_sapi_module - */ -static sapi_module_struct cli_sapi_module = { - "cli", /* name */ - "Command Line Interface", /* pretty name */ - - php_cli_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ - - NULL, /* activate */ - sapi_cli_deactivate, /* deactivate */ - - sapi_cli_ub_write, /* unbuffered write */ - sapi_cli_flush, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ - - php_error, /* error handler */ - - sapi_cli_header_handler, /* header handler */ - sapi_cli_send_headers, /* send headers handler */ - sapi_cli_send_header, /* send header handler */ - - NULL, /* read POST data */ - sapi_cli_read_cookies, /* read Cookies */ - - sapi_cli_register_variables, /* register server variables */ - sapi_cli_log_message, /* Log message */ - NULL, /* Get request time */ - - STANDARD_SAPI_MODULE_PROPERTIES -}; -/* }}} */ - -/* {{{ php_cli_usage - */ -static void php_cli_usage(char *argv0) -{ - char *prog; - - prog = strrchr(argv0, '/'); - if (prog) { - prog++; - } else { - prog = "php"; - } - - php_printf( "Usage: %s [options] [-f] <file> [--] [args...]\n" - " %s [options] -r <code> [--] [args...]\n" - " %s [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]\n" - " %s [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]\n" - " %s [options] -- [args...]\n" - " %s [options] -a\n" - "\n" -#if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) - " -a Run as interactive shell\n" -#else - " -a Run interactively\n" -#endif - " -c <path>|<file> Look for php.ini file in this directory\n" - " -n No php.ini file will be used\n" - " -d foo[=bar] Define INI entry foo with value 'bar'\n" - " -e Generate extended information for debugger/profiler\n" - " -f <file> Parse and execute <file>.\n" - " -h This help\n" - " -i PHP information\n" - " -l Syntax check only (lint)\n" - " -m Show compiled in modules\n" - " -r <code> Run PHP <code> without using script tags <?..?>\n" - " -B <begin_code> Run PHP <begin_code> before processing input lines\n" - " -R <code> Run PHP <code> for every input line\n" - " -F <file> Parse and execute <file> for every input line\n" - " -E <end_code> Run PHP <end_code> after processing all input lines\n" - " -H Hide any passed arguments from external tools.\n" - " -s Display colour syntax highlighted source.\n" - " -v Version number\n" - " -w Display source with stripped comments and whitespace.\n" - " -z <file> Load Zend extension <file>.\n" - "\n" - " args... Arguments passed to script. Use -- args when first argument\n" - " starts with - or script is read from stdin\n" - "\n" -#if (HAVE_REFLECTION) - " --rf <name> Show information about function <name>.\n" - " --rc <name> Show information about class <name>.\n" - " --re <name> Show information about extension <name>.\n" - "\n" -#endif - , prog, prog, prog, prog, prog, prog); -} -/* }}} */ - -static php_stream *s_in_process = NULL; - -static void cli_register_file_handles(TSRMLS_D) -{ - zval *zin, *zout, *zerr; - php_stream *s_in, *s_out, *s_err; - php_stream_context *sc_in=NULL, *sc_out=NULL, *sc_err=NULL; - zend_constant ic, oc, ec; - - MAKE_STD_ZVAL(zin); - MAKE_STD_ZVAL(zout); - MAKE_STD_ZVAL(zerr); - - s_in = php_stream_open_wrapper_ex("php://stdin", "rb", 0, NULL, sc_in); - s_out = php_stream_open_wrapper_ex("php://stdout", "wb", 0, NULL, sc_out); - s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err); - - if (s_in==NULL || s_out==NULL || s_err==NULL) { - return; - } - - s_in_process = s_in; - - php_stream_to_zval(s_in, zin); - php_stream_to_zval(s_out, zout); - php_stream_to_zval(s_err, zerr); - - ic.value = *zin; - ic.flags = CONST_CS; - ic.name = zend_strndup(ZEND_STRL("STDIN")); - ic.name_len = sizeof("STDIN"); - ic.module_number = 0; - zend_register_constant(&ic TSRMLS_CC); - - oc.value = *zout; - oc.flags = CONST_CS; - oc.name = zend_strndup(ZEND_STRL("STDOUT")); - oc.name_len = sizeof("STDOUT"); - oc.module_number = 0; - zend_register_constant(&oc TSRMLS_CC); - - ec.value = *zerr; - ec.flags = CONST_CS; - ec.name = zend_strndup(ZEND_STRL("STDERR")); - ec.name_len = sizeof("STDERR"); - ec.module_number = 0; - zend_register_constant(&ec TSRMLS_CC); - - FREE_ZVAL(zin); - FREE_ZVAL(zout); - FREE_ZVAL(zerr); -} - -static const char *param_mode_conflict = "Either execute direct code, process stdin or use a file.\n"; - -/* {{{ cli_seek_file_begin - */ -static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno TSRMLS_DC) -{ - int c; - - *lineno = 1; - - if (!(file_handle->handle.fp = VCWD_FOPEN(script_file, "rb"))) { - php_printf("Could not open input file: %s\n", script_file); - return FAILURE; - } - file_handle->filename = script_file; - /* #!php support */ - c = fgetc(file_handle->handle.fp); - if (c == '#') { - while (c != '\n' && c != '\r') { - c = fgetc(file_handle->handle.fp); /* skip to end of line */ - } - /* handle situations where line is terminated by \r\n */ - if (c == '\r') { - if (fgetc(file_handle->handle.fp) != '\n') { - long pos = ftell(file_handle->handle.fp); - fseek(file_handle->handle.fp, pos - 1, SEEK_SET); - } - } - *lineno = 2; - } else { - rewind(file_handle->handle.fp); - } - return SUCCESS; -} -/* }}} */ - -/* {{{ main - */ -#ifdef PHP_CLI_WIN32_NO_CONSOLE -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) -#else -int main(int argc, char *argv[]) -#endif -{ - int exit_status = SUCCESS; - int c; - zend_file_handle file_handle; -/* temporary locals */ - int behavior=PHP_MODE_STANDARD; -#ifdef HAVE_REFLECTION - char *reflection_what = NULL; -#endif - int orig_optind=php_optind; - char *orig_optarg=php_optarg; - char *arg_free=NULL, **arg_excp=&arg_free; - char *script_file=NULL; - int interactive=0; - int module_started = 0; - int request_started = 0; - int lineno = 0; - char *exec_direct=NULL, *exec_run=NULL, *exec_begin=NULL, *exec_end=NULL; - const char *param_error=NULL; - int hide_argv = 0; -/* end of temporary locals */ -#ifdef ZTS - zend_compiler_globals *compiler_globals; - zend_executor_globals *executor_globals; - php_core_globals *core_globals; - sapi_globals_struct *sapi_globals; - void ***tsrm_ls; -#endif -#ifdef PHP_CLI_WIN32_NO_CONSOLE - int argc = __argc; - char **argv = __argv; -#endif - int ini_entries_len = 0; - -#if defined(PHP_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP) - { - int tmp_flag; - - _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); - - tmp_flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); - tmp_flag |= _CRTDBG_DELAY_FREE_MEM_DF; - tmp_flag |= _CRTDBG_LEAK_CHECK_DF; - - _CrtSetDbgFlag(tmp_flag); - } -#endif - -#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); -#endif - - cli_sapi_module.php_ini_path_override = NULL; - cli_sapi_module.ini_defaults = sapi_cli_ini_defaults; - cli_sapi_module.phpinfo_as_text = 1; - sapi_startup(&cli_sapi_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 - - ini_entries_len = strlen(HARDCODED_INI); - cli_sapi_module.ini_entries = malloc(ini_entries_len+2); - memcpy(cli_sapi_module.ini_entries, HARDCODED_INI, ini_entries_len+1); - cli_sapi_module.ini_entries[ini_entries_len+1] = 0; - - while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0))!=-1) { - switch (c) { - case 'c': - cli_sapi_module.php_ini_path_override = strdup(php_optarg); - break; - case 'n': - cli_sapi_module.php_ini_ignore = 1; - break; - case 'd': { - /* define ini entries on command line */ - int len = strlen(php_optarg); - char *val; - - if ((val = strchr(php_optarg, '='))) { - val++; - if (!isalnum(*val) && *val != '"' && *val != '\'' && *val != '\0') { - cli_sapi_module.ini_entries = realloc(cli_sapi_module.ini_entries, ini_entries_len + len + sizeof("\"\"\n\0")); - memcpy(cli_sapi_module.ini_entries + ini_entries_len, php_optarg, (val - php_optarg)); - ini_entries_len += (val - php_optarg); - memcpy(cli_sapi_module.ini_entries + ini_entries_len, "\"", 1); - ini_entries_len++; - memcpy(cli_sapi_module.ini_entries + ini_entries_len, val, len - (val - php_optarg)); - ini_entries_len += len - (val - php_optarg); - memcpy(cli_sapi_module.ini_entries + ini_entries_len, "\"\n\0", sizeof("\"\n\0")); - ini_entries_len += sizeof("\n\0\"") - 2; - } else { - cli_sapi_module.ini_entries = realloc(cli_sapi_module.ini_entries, ini_entries_len + len + sizeof("\n\0")); - memcpy(cli_sapi_module.ini_entries + ini_entries_len, php_optarg, len); - memcpy(cli_sapi_module.ini_entries + ini_entries_len + len, "\n\0", sizeof("\n\0")); - ini_entries_len += len + sizeof("\n\0") - 2; - } - } else { - cli_sapi_module.ini_entries = realloc(cli_sapi_module.ini_entries, ini_entries_len + len + sizeof("=1\n\0")); - memcpy(cli_sapi_module.ini_entries + ini_entries_len, php_optarg, len); - memcpy(cli_sapi_module.ini_entries + ini_entries_len + len, "=1\n\0", sizeof("=1\n\0")); - ini_entries_len += len + sizeof("=1\n\0") - 2; - } - break; - } - } - } - php_optind = orig_optind; - php_optarg = orig_optarg; - - cli_sapi_module.executable_location = argv[0]; - -#ifdef ZTS - compiler_globals = ts_resource(compiler_globals_id); - executor_globals = ts_resource(executor_globals_id); - core_globals = ts_resource(core_globals_id); - sapi_globals = ts_resource(sapi_globals_id); - tsrm_ls = ts_resource(0); -#endif - - /* startup after we get the above ini override se we get things right */ - if (php_module_startup(&cli_sapi_module, NULL, 0)==FAILURE) { - /* there is no way to see if we must call zend_ini_deactivate() - * since we cannot check if EG(ini_directives) has been initialised - * because the executor's constructor does not set initialize it. - * Apart from that there seems no need for zend_ini_deactivate() yet. - * So we goto out_err.*/ - exit_status = 1; - goto out_err; - } - module_started = 1; - - zend_first_try { - CG(in_compilation) = 0; /* not initialized but needed for several options */ - EG(uninitialized_zval_ptr) = NULL; - - if (cli_sapi_module.php_ini_path_override && cli_sapi_module.php_ini_ignore) { - PUTS("You cannot use both -n and -c switch. Use -h for help.\n"); - exit_status=1; - goto out_err; - } - - while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) { - switch (c) { - - case 'h': /* help & quit */ - case '?': - if (php_request_startup(TSRMLS_C)==FAILURE) { - goto err; - } - request_started = 1; - php_cli_usage(argv[0]); - php_end_ob_buffers(1 TSRMLS_CC); - exit_status=0; - goto out; - - case 'i': /* php info & quit */ - if (php_request_startup(TSRMLS_C)==FAILURE) { - goto err; - } - request_started = 1; - php_print_info(0xFFFFFFFF TSRMLS_CC); - php_end_ob_buffers(1 TSRMLS_CC); - exit_status=0; - goto out; - - case 'm': /* list compiled in modules */ - if (php_request_startup(TSRMLS_C)==FAILURE) { - goto err; - } - request_started = 1; - php_printf("[PHP Modules]\n"); - print_modules(TSRMLS_C); - php_printf("\n[Zend Modules]\n"); - print_extensions(TSRMLS_C); - php_printf("\n"); - php_end_ob_buffers(1 TSRMLS_CC); - exit_status=0; - goto out; - - case 'v': /* show php version & quit */ - if (php_request_startup(TSRMLS_C) == FAILURE) { - goto err; - } - - request_started = 1; - php_printf("PHP %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2006 The PHP Group\n%s", - PHP_VERSION, sapi_module.name, __DATE__, __TIME__, -#if ZEND_DEBUG && defined(HAVE_GCOV) - "(DEBUG GCOV)", -#elif ZEND_DEBUG - "(DEBUG)", -#elif defined(HAVE_GCOV) - "(GCOV)", -#else - "", -#endif - get_zend_version() - ); - php_end_ob_buffers(1 TSRMLS_CC); - exit_status=0; - goto out; - - default: - break; - } - } - - /* Set some CLI defaults */ - SG(options) |= SAPI_OPTION_NO_CHDIR; - - php_optind = orig_optind; - php_optarg = orig_optarg; - while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) { - switch (c) { - - case 'a': /* interactive mode */ - if (!interactive) { - if (behavior != PHP_MODE_STANDARD) { - param_error = param_mode_conflict; - break; - } - - interactive=1; - } - break; - - case 'C': /* don't chdir to the script directory */ - /* This is default so NOP */ - break; - - case 'e': /* enable extended info output */ - CG(extended_info) = 1; - break; - - case 'F': - if (behavior == PHP_MODE_PROCESS_STDIN) { - if (exec_run || script_file) { - param_error = "You can use -R or -F only once.\n"; - break; - } - } else if (behavior != PHP_MODE_STANDARD) { - param_error = param_mode_conflict; - break; - } - behavior=PHP_MODE_PROCESS_STDIN; - script_file = php_optarg; - break; - - case 'f': /* parse file */ - if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) { - param_error = param_mode_conflict; - break; - } else if (script_file) { - param_error = "You can use -f only once.\n"; - break; - } - script_file = php_optarg; - break; - - case 'l': /* syntax check mode */ - if (behavior != PHP_MODE_STANDARD) { - break; - } - behavior=PHP_MODE_LINT; - break; - -#if 0 /* not yet operational, see also below ... */ - case '': /* generate indented source mode*/ - if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) { - param_error = "Source indenting only works for files.\n"; - break; - } - behavior=PHP_MODE_INDENT; - break; -#endif - - case 'q': /* do not generate HTTP headers */ - /* This is default so NOP */ - break; - - case 'r': /* run code from command line */ - if (behavior == PHP_MODE_CLI_DIRECT) { - if (exec_direct || script_file) { - param_error = "You can use -r only once.\n"; - break; - } - } else if (behavior != PHP_MODE_STANDARD || interactive) { - param_error = param_mode_conflict; - break; - } - behavior=PHP_MODE_CLI_DIRECT; - exec_direct=php_optarg; - break; - - case 'R': - if (behavior == PHP_MODE_PROCESS_STDIN) { - if (exec_run || script_file) { - param_error = "You can use -R or -F only once.\n"; - break; - } - } else if (behavior != PHP_MODE_STANDARD) { - param_error = param_mode_conflict; - break; - } - behavior=PHP_MODE_PROCESS_STDIN; - exec_run=php_optarg; - break; - - case 'B': - if (behavior == PHP_MODE_PROCESS_STDIN) { - if (exec_begin) { - param_error = "You can use -B only once.\n"; - break; - } - } else if (behavior != PHP_MODE_STANDARD || interactive) { - param_error = param_mode_conflict; - break; - } - behavior=PHP_MODE_PROCESS_STDIN; - exec_begin=php_optarg; - break; - - case 'E': - if (behavior == PHP_MODE_PROCESS_STDIN) { - if (exec_end) { - param_error = "You can use -E only once.\n"; - break; - } - } else if (behavior != PHP_MODE_STANDARD || interactive) { - param_error = param_mode_conflict; - break; - } - behavior=PHP_MODE_PROCESS_STDIN; - exec_end=php_optarg; - break; - - case 's': /* generate highlighted HTML from source */ - if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) { - param_error = "Source highlighting only works for files.\n"; - break; - } - behavior=PHP_MODE_HIGHLIGHT; - break; - - case 'w': - if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) { - param_error = "Source stripping only works for files.\n"; - break; - } - behavior=PHP_MODE_STRIP; - break; - - case 'z': /* load extension file */ - zend_load_extension(php_optarg); - break; - case 'H': - hide_argv = 1; - break; - -#ifdef HAVE_REFLECTION - case 10: - behavior=PHP_MODE_REFLECTION_FUNCTION; - reflection_what = php_optarg; - break; - case 11: - behavior=PHP_MODE_REFLECTION_CLASS; - reflection_what = php_optarg; - break; - case 12: - behavior=PHP_MODE_REFLECTION_EXTENSION; - reflection_what = php_optarg; - break; -#endif - default: - break; - } - } - - if (param_error) { - PUTS(param_error); - exit_status=1; - goto err; - } - - if (interactive) { -#if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) - printf("Interactive shell\n\n"); -#else - printf("Interactive mode enabled\n\n"); -#endif - fflush(stdout); - } - - CG(interactive) = interactive; - - /* 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 - && behavior!=PHP_MODE_CLI_DIRECT - && behavior!=PHP_MODE_PROCESS_STDIN - && strcmp(argv[php_optind-1],"--")) - { - script_file=argv[php_optind]; - php_optind++; - } - if (script_file) { - if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) { - goto err; - } - script_filename = script_file; - } else { - /* We could handle PHP_MODE_PROCESS_STDIN in a different manner */ - /* here but this would make things only more complicated. And it */ - /* is consitent with the way -R works where the stdin file handle*/ - /* is also accessible. */ - file_handle.filename = "-"; - file_handle.handle.fp = stdin; - } - file_handle.type = ZEND_HANDLE_FP; - file_handle.opened_path = NULL; - file_handle.free_filename = 0; - php_self = file_handle.filename; - - /* 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).path_translated = file_handle.filename; - argv[php_optind-1] = file_handle.filename; - SG(request_info).argv=argv+php_optind-1; - - if (php_request_startup(TSRMLS_C)==FAILURE) { - *arg_excp = arg_free; - fclose(file_handle.handle.fp); - PUTS("Could not startup.\n"); - goto err; - } - request_started = 1; - CG(start_lineno) = lineno; - *arg_excp = arg_free; /* reconstuct argv */ - - if (hide_argv) { - int i; - for (i = 1; i < argc; i++) { - memset(argv[i], 0, strlen(argv[i])); - } - } - - zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC); - - PG(during_request_startup) = 0; - switch (behavior) { - case PHP_MODE_STANDARD: - if (strcmp(file_handle.filename, "-")) { - cli_register_file_handles(TSRMLS_C); - } - -#if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) - if (interactive) { - char *line; - size_t size = 4096, pos = 0, len; - char *code = emalloc(size); - char *prompt = "php > "; - char *history_file; - - if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) { - zend_file_handle *prepend_file_p; - zend_file_handle prepend_file = {0}; - - prepend_file.filename = PG(auto_prepend_file); - prepend_file.opened_path = NULL; - prepend_file.free_filename = 0; - prepend_file.type = ZEND_HANDLE_FILENAME; - prepend_file_p = &prepend_file; - - zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 1, prepend_file_p); - } - - history_file = tilde_expand("~/.php_history"); - rl_attempted_completion_function = cli_code_completion; - rl_special_prefixes = "$"; - read_history(history_file); - - EG(exit_status) = 0; - while ((line = readline(prompt)) != NULL) { - if (strcmp(line, "exit") == 0 || strcmp(line, "quit") == 0) { - free(line); - break; - } - - if (!pos && !*line) { - free(line); - continue; - } - - len = strlen(line); - if (pos + len + 2 > size) { - size = pos + len + 2; - code = erealloc(code, size); - } - memcpy(&code[pos], line, len); - pos += len; - code[pos] = '\n'; - code[++pos] = '\0'; - - if (*line) { - add_history(line); - } - - free(line); - - if (!cli_is_valid_code(code, pos, &prompt TSRMLS_CC)) { - continue; - } - - zend_eval_string(code, NULL, "php shell code" TSRMLS_CC); - pos = 0; - - if (php_last_char != '\0' && php_last_char != '\n') { - sapi_cli_single_write("\n", 1); - } - - if (EG(exception)) { - zend_exception_error(EG(exception) TSRMLS_CC); - } - - php_last_char = '\0'; - } - write_history(history_file); - free(history_file); - efree(code); - exit_status = EG(exit_status); - break; - } -#endif /* HAVE_LIBREADLINE || HAVE_LIBEDIT */ - php_execute_script(&file_handle TSRMLS_CC); - exit_status = EG(exit_status); - break; - case PHP_MODE_LINT: - exit_status = php_lint_script(&file_handle TSRMLS_CC); - if (exit_status==SUCCESS) { - zend_printf("No syntax errors detected in %s\n", file_handle.filename); - } else { - zend_printf("Errors parsing %s\n", file_handle.filename); - } - break; - case PHP_MODE_STRIP: - if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) { - zend_strip(TSRMLS_C); - } - goto out; - break; - case PHP_MODE_HIGHLIGHT: - { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) { - php_get_highlight_struct(&syntax_highlighter_ini); - zend_highlight(&syntax_highlighter_ini TSRMLS_CC); - } - goto out; - } - break; -#if 0 - /* Zeev might want to do something with this one day */ - case PHP_MODE_INDENT: - open_file_for_scanning(&file_handle TSRMLS_CC); - zend_indent(); - fclose(file_handle.handle.fp); - goto out; - break; -#endif - case PHP_MODE_CLI_DIRECT: - cli_register_file_handles(TSRMLS_C); - if (zend_eval_string_ex(exec_direct, NULL, "Command line code", 1 TSRMLS_CC) == FAILURE) { - exit_status=254; - } - break; - - case PHP_MODE_PROCESS_STDIN: - { - char *input; - size_t len, index = 0; - zval *argn, *argi; - - cli_register_file_handles(TSRMLS_C); - - if (exec_begin && zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1 TSRMLS_CC) == FAILURE) { - exit_status=254; - } - ALLOC_ZVAL(argi); - Z_TYPE_P(argi) = IS_LONG; - Z_LVAL_P(argi) = index; - INIT_PZVAL(argi); - zend_hash_update(&EG(symbol_table), "argi", sizeof("argi"), &argi, sizeof(zval *), NULL); - while (exit_status == SUCCESS && (input=php_stream_gets(s_in_process, NULL, 0)) != NULL) { - len = strlen(input); - while (len-- && (input[len]=='\n' || input[len]=='\r')) { - input[len] = '\0'; - } - ALLOC_ZVAL(argn); - Z_TYPE_P(argn) = IS_STRING; - Z_STRLEN_P(argn) = ++len; - Z_STRVAL_P(argn) = estrndup(input, len); - INIT_PZVAL(argn); - zend_hash_update(&EG(symbol_table), "argn", sizeof("argn"), &argn, sizeof(zval *), NULL); - Z_LVAL_P(argi) = ++index; - if (exec_run) { - if (zend_eval_string_ex(exec_run, NULL, "Command line run code", 1 TSRMLS_CC) == FAILURE) { - exit_status=254; - } - } else { - if (script_file) { - if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) { - exit_status = 1; - } else { - CG(start_lineno) = lineno; - php_execute_script(&file_handle TSRMLS_CC); - exit_status = EG(exit_status); - } - } - } - efree(input); - } - if (exec_end && zend_eval_string_ex(exec_end, NULL, "Command line end code", 1 TSRMLS_CC) == FAILURE) { - exit_status=254; - } - - break; -#ifdef HAVE_REFLECTION - case PHP_MODE_REFLECTION_FUNCTION: - case PHP_MODE_REFLECTION_CLASS: - case PHP_MODE_REFLECTION_EXTENSION: - { - zend_class_entry *pce = NULL; - zval *arg, *ref; - zend_execute_data execute_data; - - switch (behavior) { - case PHP_MODE_REFLECTION_FUNCTION: - if (strstr(reflection_what, "::")) { - pce = reflection_method_ptr; - } else { - pce = reflection_function_ptr; - } - break; - case PHP_MODE_REFLECTION_CLASS: - pce = reflection_class_ptr; - break; - case PHP_MODE_REFLECTION_EXTENSION: - pce = reflection_extension_ptr; - break; - } - - MAKE_STD_ZVAL(arg); - ZVAL_STRING(arg, reflection_what, 1); - ALLOC_ZVAL(ref); - object_init_ex(ref, pce); - INIT_PZVAL(ref); - - memset(&execute_data, 0, sizeof(zend_execute_data)); - EG(current_execute_data) = &execute_data; - EX(function_state).function = pce->constructor; - zend_call_method_with_1_params(&ref, pce, &pce->constructor, "__construct", NULL, arg); - - if (EG(exception)) { - zval *msg = zend_read_property(zend_exception_get_default(TSRMLS_C), EG(exception), "message", sizeof("message")-1, 0 TSRMLS_CC); - zend_printf("Exception: %s\n", Z_STRVAL_P(msg)); - zval_ptr_dtor(&EG(exception)); - EG(exception) = NULL; - } else { - zend_call_method_with_1_params(NULL, reflection_ptr, NULL, "export", NULL, ref); - } - zval_ptr_dtor(&ref); - zval_ptr_dtor(&arg); - - break; - } -#endif /* reflection */ - } - } - - } zend_end_try(); - -out: - if (request_started) { - php_request_shutdown((void *) 0); - } - if (exit_status == 0) { - exit_status = EG(exit_status); - } -out_err: - if (cli_sapi_module.php_ini_path_override) { - free(cli_sapi_module.php_ini_path_override); - } - if (cli_sapi_module.ini_entries) { - free(cli_sapi_module.ini_entries); - } - - if (module_started) { - php_module_shutdown(TSRMLS_C); - } - sapi_shutdown(); -#ifdef ZTS - tsrm_shutdown(); -#endif - - exit(exit_status); - -err: - sapi_deactivate(TSRMLS_C); - zend_ini_deactivate(TSRMLS_C); - exit_status = 1; - goto out_err; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/cli/php_cli_readline.c b/sapi/cli/php_cli_readline.c deleted file mode 100644 index 4f9f029911..0000000000 --- a/sapi/cli/php_cli_readline.c +++ /dev/null @@ -1,449 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 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: Marcus Boerger <helly@php.net> | - | Johannes Schlueter <johannes@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" - -#if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) - -#ifndef HAVE_RL_COMPLETION_MATCHES -#define rl_completion_matches completion_matches -#endif - -#include "php_globals.h" -#include "php_variables.h" -#include "zend_hash.h" -#include "zend_modules.h" - -#include "SAPI.h" - -#if HAVE_SETLOCALE -#include <locale.h> -#endif -#include "zend.h" -#include "zend_extensions.h" -#include "php_ini.h" -#include "php_globals.h" -#include "php_main.h" -#include "fopen_wrappers.h" -#include "ext/standard/php_standard.h" - -#ifdef __riscos__ -#include <unixlib/local.h> -#endif - -#include <readline/readline.h> -#if !HAVE_LIBEDIT -#include <readline/history.h> -#endif - -#include "zend_compile.h" -#include "zend_execute.h" -#include "zend_highlight.h" -#include "zend_indent.h" - -/* {{{ cli_is_valid_code - */ -typedef enum { - body, - sstring, - dstring, - sstring_esc, - dstring_esc, - comment_line, - comment_block, - heredoc_start, - heredoc, - outside, -} php_code_type; - -int cli_is_valid_code(char *code, int len, char **prompt TSRMLS_DC) -{ - int valid_end = 1, last_valid_end; - int brackets_count = 0; - int brace_count = 0; - int i; - php_code_type code_type = body; - char *heredoc_tag; - int heredoc_len; - - for (i = 0; i < len; ++i) { - switch(code_type) { - default: - switch(code[i]) { - case '{': - brackets_count++; - valid_end = 0; - break; - case '}': - if (brackets_count > 0) { - brackets_count--; - } - valid_end = brackets_count ? 0 : 1; - break; - case '(': - brace_count++; - valid_end = 0; - break; - case ')': - if (brace_count > 0) { - brace_count--; - } - valid_end = 0; - break; - case ';': - valid_end = brace_count == 0 && brackets_count == 0; - break; - case ' ': - case '\r': - case '\n': - case '\t': - break; - case '\'': - code_type = sstring; - break; - case '"': - code_type = dstring; - break; - case '#': - code_type = comment_line; - break; - case '/': - if (code[i+1] == '/') { - i++; - code_type = comment_line; - break; - } - if (code[i+1] == '*') { - last_valid_end = valid_end; - valid_end = 0; - code_type = comment_block; - i++; - break; - } - valid_end = 0; - break; - case '%': - if (!CG(asp_tags)) { - valid_end = 0; - break; - } - /* no break */ - case '?': - if (code[i+1] == '>') { - i++; - code_type = outside; - break; - } - valid_end = 0; - break; - case '<': - valid_end = 0; - if (i + 2 < len && code[i+1] == '<' && code[i+2] == '<') { - i += 2; - code_type = heredoc_start; - heredoc_len = 0; - } - break; - default: - valid_end = 0; - break; - } - break; - case sstring: - if (code[i] == '\\') { - code_type = sstring_esc; - } else { - if (code[i] == '\'') { - code_type = body; - } - } - break; - case sstring_esc: - code_type = sstring; - break; - case dstring: - if (code[i] == '\\') { - code_type = dstring_esc; - } else { - if (code[i] == '"') { - code_type = body; - } - } - break; - case dstring_esc: - code_type = dstring; - break; - case comment_line: - if (code[i] == '\n') { - code_type = body; - } - break; - case comment_block: - if (code[i-1] == '*' && code[i] == '/') { - code_type = body; - valid_end = last_valid_end; - } - break; - case heredoc_start: - switch(code[i]) { - case ' ': - case '\t': - break; - case '\r': - case '\n': - code_type = heredoc; - break; - default: - if (!heredoc_len) { - heredoc_tag = code+i; - } - heredoc_len++; - break; - } - break; - case heredoc: - if (code[i - (heredoc_len + 1)] == '\n' && !strncmp(code + i - heredoc_len, heredoc_tag, heredoc_len) && code[i] == '\n') { - code_type = body; - } else if (code[i - (heredoc_len + 2)] == '\n' && !strncmp(code + i - heredoc_len - 1, heredoc_tag, heredoc_len) && code[i-1] == ';' && code[i] == '\n') { - code_type = body; - valid_end = 1; - } - break; - case outside: - if ((CG(short_tags) && !strncmp(code+i-1, "<?", 2)) - || (CG(asp_tags) && !strncmp(code+i-1, "<%", 2)) - || (i > 3 && !strncmp(code+i-4, "<?php", 5)) - ) { - code_type = body; - } - break; - } - } - - switch (code_type) { - default: - if (brace_count) { - *prompt = "php ( "; - } else if (brackets_count) { - *prompt = "php { "; - } else { - *prompt = "php > "; - } - break; - case sstring: - case sstring_esc: - *prompt = "php ' "; - break; - case dstring: - case dstring_esc: - *prompt = "php \" "; - break; - case comment_block: - *prompt = "/* > "; - break; - case heredoc: - *prompt = "<<< > "; - break; - case outside: - *prompt = " > "; - break; - } - - if (!valid_end || brackets_count) { - return 0; - } else { - return 1; - } -} -/* }}} */ - -static char *cli_completion_generator_ht(const char *text, int textlen, int *state, HashTable *ht, void **pData TSRMLS_DC) /* {{{ */ -{ - char *name; - ulong number; - - if (!(*state % 2)) { - zend_hash_internal_pointer_reset(ht); - (*state)++; - } - while(zend_hash_has_more_elements(ht) == SUCCESS) { - zend_hash_get_current_key(ht, &name, &number, 0); - if (!textlen || !strncmp(name, text, textlen)) { - if (pData) { - zend_hash_get_current_data(ht, pData); - } - zend_hash_move_forward(ht); - return name; - } - if (zend_hash_move_forward(ht) == FAILURE) { - break; - } - } - (*state)++; - return NULL; -} /* }}} */ - -static char *cli_completion_generator_var(const char *text, int textlen, int *state TSRMLS_DC) /* {{{ */ -{ - char *retval, *tmp; - - tmp = retval = cli_completion_generator_ht(text + 1, textlen - 1, state, EG(active_symbol_table), NULL TSRMLS_CC); - if (retval) { - retval = malloc(strlen(tmp) + 2); - retval[0] = '$'; - strcpy(&retval[1], tmp); - rl_completion_append_character = '\0'; - } - return retval; -} /* }}} */ - -static char *cli_completion_generator_func(const char *text, int textlen, int *state, HashTable *ht TSRMLS_DC) /* {{{ */ -{ - zend_function *func; - char *retval = cli_completion_generator_ht(text, textlen, state, ht, (void**)&func TSRMLS_CC); - if (retval) { - rl_completion_append_character = '('; - retval = strdup(func->common.function_name); - } - - return retval; -} /* }}} */ - -static char *cli_completion_generator_class(const char *text, int textlen, int *state TSRMLS_DC) /* {{{ */ -{ - zend_class_entry **pce; - char *retval = cli_completion_generator_ht(text, textlen, state, EG(class_table), (void**)&pce TSRMLS_CC); - if (retval) { - rl_completion_append_character = '\0'; - retval = strdup((*pce)->name); - } - - return retval; -} /* }}} */ - -static char *cli_completion_generator_define(const char *text, int textlen, int *state, HashTable *ht TSRMLS_DC) /* {{{ */ -{ - zend_class_entry **pce; - char *retval = cli_completion_generator_ht(text, textlen, state, ht, (void**)&pce TSRMLS_CC); - if (retval) { - rl_completion_append_character = '\0'; - retval = strdup(retval); - } - - return retval; -} /* }}} */ - -static int cli_completion_state; - -static char *cli_completion_generator(const char *text, int index) /* {{{ */ -{ -/* -TODO: -- constants -- maybe array keys -- language constructs and other things outside a hashtable (echo, try, function, class, ...) -- object/class members - -- future: respect scope ("php > function foo() { $[tab]" should only expand to local variables...) -*/ - char *retval; - int textlen = strlen(text); - TSRMLS_FETCH(); - - if (!index) { - cli_completion_state = 0; - } - if (text[0] == '$') { - retval = cli_completion_generator_var(text, textlen, &cli_completion_state TSRMLS_CC); - } else { - char *lc_text, *class_name, *class_name_end; - int class_name_len; - zend_class_entry **pce = NULL; - - class_name_end = strstr(text, "::"); - if (class_name_end) { - class_name_len = class_name_end - text; - class_name = zend_str_tolower_dup(text, class_name_len); - class_name[class_name_len] = '\0'; /* not done automatically */ - if (zend_lookup_class(class_name, class_name_len, &pce TSRMLS_CC)==FAILURE) { - efree(class_name); - return NULL; - } - lc_text = zend_str_tolower_dup(class_name_end + 2, textlen - 2 - class_name_len); - textlen -= (class_name_len + 2); - } else { - lc_text = zend_str_tolower_dup(text, textlen); - } - - switch (cli_completion_state) { - case 0: - case 1: - retval = cli_completion_generator_func(lc_text, textlen, &cli_completion_state, pce ? &(*pce)->function_table : EG(function_table) TSRMLS_CC); - if (retval) { - break; - } - case 2: - case 3: - retval = cli_completion_generator_define(text, textlen, &cli_completion_state, pce ? &(*pce)->constants_table : EG(zend_constants) TSRMLS_CC); - if (retval || pce) { - break; - } - case 4: - case 5: - retval = cli_completion_generator_class(lc_text, textlen, &cli_completion_state TSRMLS_CC); - break; - default: - break; - } - efree(lc_text); - if (class_name_end) { - efree(class_name); - } - if (pce && retval) { - char *tmp = malloc(class_name_len + 2 + strlen(retval) + 1); - - sprintf(tmp, "%s::%s", (*pce)->name, retval); - free(retval); - retval = tmp; - } - } - - return retval; -} /* }}} */ - -/* {{{ cli_code_completion - */ -char **cli_code_completion(const char *text, int start, int end) -{ - return rl_completion_matches(text, cli_completion_generator); -} -/* }}} */ - -#endif /* HAVE_LIBREADLINE || HAVE_LIBEDIT */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/sapi/cli/php_cli_readline.h b/sapi/cli/php_cli_readline.h deleted file mode 100644 index bf51068684..0000000000 --- a/sapi/cli/php_cli_readline.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 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: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" - -int cli_is_valid_code(char *code, int len, char **prompt TSRMLS_DC); - -char **cli_code_completion(const char *text, int start, int end); diff --git a/sapi/cli/php_getopt.h b/sapi/cli/php_getopt.h deleted file mode 100644 index 75a226eac4..0000000000 --- a/sapi/cli/php_getopt.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 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: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" - -#ifdef NETWARE -/* -As NetWare LibC has optind and optarg macros defined in unistd.h our local variables were getting mistakenly preprocessed so undeffing optind and optarg -*/ -#undef optarg -#undef optind -#endif -/* Define structure for one recognized option (both single char and long name). - * If short_open is '-' this is the last option. - */ -typedef struct _opt_struct { - const char opt_char; - const int need_param; - const char * opt_name; -} opt_struct; - -int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err); |