- Added long-option feature to getopt().
- Made getopt() available on win32 systems.
Patch by: David Soria Parra <dsp@php.net>
[DOC]: These changes will be available from 5.3+
if test "$PHP_CLI" != "no"; then
PHP_CLI_TARGET="\$(SAPI_CLI_PATH)"
PHP_INSTALL_CLI_TARGET="install-cli"
- PHP_ADD_SOURCES(sapi/cli, php_cli.c php_cli_readline.c getopt.c,, cli)
+ PHP_ADD_SOURCES(sapi/cli, php_cli.c php_cli_readline.c,, cli)
PHP_INSTALLED_SAPIS="cli $PHP_SAPI"
else
PHP_INSTALLED_SAPIS="$PHP_SAPI"
php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c \
network.c php_open_temporary_file.c php_logos.c \
- output.c )
+ output.c getopt.c)
PHP_ADD_SOURCES(main/streams, streams.c cast.c memory.c filter.c \
plain_wrapper.c userspace.c transports.c xp_socket.c mmap.c \
#include "php_math.h"
#include "php_http.h"
#include "php_incomplete_class.h"
+#include "php_getopt.h"
#include "ext/standard/info.h"
#include "ext/session/php_session.h"
#include "zend_operators.h"
# include <sys/loadavg.h>
#endif
-#ifdef HARTMUT_0
-#include <getopt.h>
-#endif
-
#ifdef PHP_WIN32
# include "win32/unistd.h"
#endif
#include "SAPI.h"
#include "php_ticks.h"
-
#ifdef ZTS
PHPAPI int basic_globals_id;
#else
ZEND_END_ARG_INFO()
#endif
-#ifdef HAVE_GETOPT
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_getopt, 0, 0, 1)
ZEND_ARG_INFO(0, options)
ZEND_ARG_INFO(0, opts) /* ARRAY_INFO(0, opts, 1) */
ZEND_END_ARG_INFO()
-#endif
static
ZEND_BEGIN_ARG_INFO(arginfo_flush, 0)
PHP_FE(iptcembed, arginfo_iptcembed)
PHP_FE(getimagesize, arginfo_getimagesize)
PHP_FE(image_type_to_mime_type, arginfo_image_type_to_mime_type)
- PHP_FE(image_type_to_extension, arginfo_image_type_to_extension)
+ PHP_FE(image_type_to_extension, arginfo_image_type_to_extension)
PHP_FE(phpinfo, arginfo_phpinfo)
PHP_FE(phpversion, arginfo_phpversion)
#endif
#ifdef HAVE_STRFMON
- PHP_FE(money_format, arginfo_money_format)
+ PHP_FE(money_format, arginfo_money_format)
#endif
PHP_FE(substr, arginfo_substr)
PHP_FE(putenv, arginfo_putenv)
#endif
-#ifdef HAVE_GETOPT
PHP_FE(getopt, arginfo_getopt)
-#endif
#ifdef HAVE_GETLOADAVG
PHP_FE(sys_getloadavg, arginfo_sys_getloadavg)
PHP_FE(unregister_tick_function, arginfo_unregister_tick_function)
PHP_FE(highlight_file, arginfo_highlight_file)
- PHP_FALIAS(show_source, highlight_file, arginfo_highlight_file)
+ PHP_FALIAS(show_source, highlight_file, arginfo_highlight_file)
PHP_FE(highlight_string, arginfo_highlight_string)
PHP_FE(php_strip_whitespace, arginfo_php_strip_whitespace)
PHP_FE(setcookie, arginfo_setcookie)
PHP_FE(setrawcookie, arginfo_setrawcookie)
PHP_FE(header, arginfo_header)
- PHP_FE(headers_sent, arginfo_headers_sent)
+ PHP_FE(headers_sent, arginfo_headers_sent)
PHP_FE(headers_list, arginfo_headers_list)
PHP_FE(connection_aborted, arginfo_connection_aborted)
PHP_FALIAS(checkdnsrr, dns_check_record, arginfo_dns_check_record)
# if HAVE_DN_SKIPNAME && HAVE_DN_EXPAND
PHP_FE(dns_get_mx, arginfo_dns_get_mx)
- PHP_FALIAS(getmxrr, dns_get_mx, arginfo_dns_get_mx)
+ PHP_FALIAS(getmxrr, dns_get_mx, arginfo_dns_get_mx)
# endif
# if HAVE_DNS_FUNCS
PHP_FE(dns_get_record, arginfo_dns_get_record)
/* functions from type.c */
PHP_FE(intval, arginfo_intval)
PHP_FE(floatval, arginfo_floatval)
- PHP_FALIAS(doubleval, floatval, arginfo_floatval)
+ PHP_FALIAS(doubleval, floatval, arginfo_floatval)
PHP_FE(strval, arginfo_strval)
PHP_FE(gettype, arginfo_gettype)
PHP_FE(settype, arginfo_settype)
/* aliases from array.c */
PHP_FALIAS(pos, current, arginfo_current)
- PHP_FALIAS(sizeof, count, arginfo_count)
+ PHP_FALIAS(sizeof, count, arginfo_count)
PHP_FALIAS(key_exists, array_key_exists, arginfo_array_key_exists)
/* functions from assert.c */
PHP_FE(ftok, arginfo_ftok)
#endif
- PHP_FE(str_rot13, arginfo_str_rot13)
- PHP_FE(stream_get_filters, arginfo_stream_get_filters)
- PHP_FE(stream_filter_register, arginfo_stream_filter_register)
+ PHP_FE(str_rot13, arginfo_str_rot13)
+ PHP_FE(stream_get_filters, arginfo_stream_get_filters)
+ PHP_FE(stream_filter_register, arginfo_stream_filter_register)
PHP_FE(stream_bucket_make_writeable, arginfo_stream_bucket_make_writeable)
PHP_FE(stream_bucket_prepend, arginfo_stream_bucket_prepend)
PHP_FE(stream_bucket_append, arginfo_stream_bucket_append)
/* }}} */
#endif
-#ifdef HAVE_GETOPT
/* {{{ free_argv()
Free the memory allocated to an argv array. */
static void free_argv(char **argv, int argc)
}
/* }}} */
-#ifdef HARTMUT_0
/* {{{ free_longopts()
Free the memory allocated to an longopt array. */
-static void free_longopts(struct option *longopts)
+static void free_longopts(opt_struct *longopts)
{
- struct option *p;
+ opt_struct *p;
if (longopts) {
- for (p = longopts; p->name; p++) {
- efree((char *)(p->name));
+ for (p = longopts; p && p->opt_char != '-'; p++) {
+ if (p->opt_name != NULL) {
+ efree((char *)(p->opt_name));
+ }
}
+ }
+}
+/* }}} */
- efree(longopts);
+/* {{{ parse_opts()
+ Convert the typical getopt input characters to the php_getopt struct array */
+static int parse_opts(char * opts, opt_struct ** result)
+{
+ opt_struct * paras = NULL;
+ int i, count = 0;
+
+ for (i = 0; i < strlen(opts); i++) {
+ if ((opts[i] >= 65 && opts[i] <= 90) ||
+ (opts[i] >= 97 && opts[i] <= 122)
+ ) {
+ count++;
+ }
}
+
+ paras = safe_emalloc(sizeof(opt_struct), count, 0);
+ memset(paras, 0, sizeof(opt_struct) * count);
+ *result = paras;
+ while ( (*opts >= 65 && *opts <= 90) ||
+ (*opts >= 97 && *opts <= 122)
+ ) {
+ paras->opt_char = *opts;
+ paras->need_param = (*(++opts) == ':') ? 1 : 0;
+ paras->opt_name = NULL;
+ if (paras->need_param == 1) {
+ opts++;
+ }
+ paras++;
+ }
+ return count;
}
/* }}} */
-#endif
/* {{{ proto array getopt(string options [, array longopts]) U
Get options from the command line argument list */
char *options = NULL, **argv = NULL;
char opt[2] = { '\0' };
char *optname;
- int argc = 0, options_len = 0, o;
+ int argc = 0, options_len = 0, len, o;
+ char *php_optarg = NULL;
+ int php_optind = 1;
zval *val, **args = NULL, *p_longopts = NULL;
int optname_len = 0;
-#ifdef HARTMUT_0
- struct option *longopts = NULL;
- int longindex = 0;
-#endif
+ opt_struct *opts, *orig_opts;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &options, &options_len, &p_longopts) == FAILURE) {
RETURN_FALSE;
RETURN_FALSE;
}
+ len = parse_opts(options, &opts);
+
if (p_longopts) {
-#ifdef HARTMUT_0
- int len, c = zend_hash_num_elements(Z_ARRVAL_P(p_longopts));
- struct option *p;
+ int count;
zval **arg;
- char *name;
- longopts = (struct option *)ecalloc(c+1, sizeof(struct option));
+ count = zend_hash_num_elements(Z_ARRVAL_P(p_longopts));
+
+ /* the first <len> slots are filled by the one short ops
+ * we now extend our array and jump to the new added structs */
+ opts = (opt_struct *) erealloc(opts, sizeof(opt_struct) * (len + count + 1));
+ orig_opts = opts;
+ opts += len;
+
+ memset(opts, 0, count * sizeof(opt_struct));
- if (!longopts) {
+ if (!opts) {
RETURN_FALSE;
}
/* Reset the array indexes. */
zend_hash_internal_pointer_reset(Z_ARRVAL_P(p_longopts));
- p = longopts;
/* Iterate over the hash to construct the argv array. */
while (zend_hash_get_current_data(Z_ARRVAL_P(p_longopts), (void **)&arg) == SUCCESS) {
-
- p->has_arg = 0;
- name = estrdup(Z_STRVAL_PP(arg));
- len = strlen(name);
- if ((len > 0) && (name[len-1] == ':')) {
- p->has_arg++;
- name[len-1] = '\0';
- if ((len > 1) && (name[len-2] == ':')) {
- p->has_arg++;
- name[len-2] = '\0';
+ opts->need_param = 0;
+ opts->opt_name = estrdup(Z_STRVAL_PP(arg));
+ len = strlen(opts->opt_name);
+ if ((len > 0) && (opts->opt_name[len-1] == ':')) {
+ opts->need_param++;
+ opts->opt_name[len-1] = '\0';
+ if ((len > 1) && (opts->opt_name[len-2] == ':')) {
+ opts->need_param++;
+ opts->opt_name[len-2] = '\0';
}
}
-
- p->name = name;
- p->flag = NULL;
- p->val = 0;
-
+ opts->opt_char = 0;
+ opts++;
zend_hash_move_forward(Z_ARRVAL_P(p_longopts));
- p++;
}
-#else
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "No support for long options in this build");
-#endif
+ } else {
+ opts = (opt_struct*) erealloc(opts, sizeof(opt_struct) * (len + 1));
+ orig_opts = opts;
+ opts += len;
}
+ /* php_getopt want to identify the last param */
+ opts->opt_char = '-';
+ opts->need_param = 0;
+ opts->opt_name = NULL;
+
/* Initialize the return value as an array. */
array_init(return_value);
- /* Disable getopt()'s error messages. */
- opterr = 0;
-
- /* Force reinitialization of getopt() (via optind reset) on every call. */
- optind = 1;
+ /* after our pointer arithmetic jump back to the first element */
+ opts = orig_opts;
- /* Invoke getopt(3) on the argument array. */
-#ifdef HARTMUT_0
- while ((o = getopt_long(argc, argv, options, longopts, &longindex)) != -1) {
-#else
- while ((o = getopt(argc, argv, options)) != -1) {
-#endif
+ while ((o = php_getopt(argc, argv, opts, &php_optarg, &php_optind, 0, 1)) != -1) {
/* Skip unknown arguments. */
if (o == '?') {
continue;
/* Prepare the option character and the argument string. */
if (o == 0) {
-#ifdef HARTMUT_0
- optname = (char *)longopts[longindex].name;
-#else
- /* o == 0 shall never happen so this only fixes a compiler warning */
- optname = NULL;
-#endif
+ optname = opts[php_optidx].opt_name;
} else {
if (o == 1) {
o = '-';
}
MAKE_STD_ZVAL(val);
- if (optarg != NULL) {
+ if (php_optarg != NULL) {
/* keep the arg as binary, since the encoding is not known */
- ZVAL_STRING(val, optarg, 1);
+ ZVAL_STRING(val, php_optarg, 1);
} else {
ZVAL_FALSE(val);
}
zend_hash_add(HASH_OF(return_value), optname, strlen(optname)+1, (void *)&val, sizeof(zval *), NULL);
}
}
+
+ php_optarg = NULL;
}
+ free_longopts(orig_opts);
+ efree(orig_opts);
free_argv(argv, argc);
-#ifdef HARTMUT_0
- free_longopts(longopts);
-#endif
}
/* }}} */
-#endif
/* {{{ proto void flush(void) U
Flush the output buffer */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
return;
}
-
+
str = zend_ini_string("include_path", sizeof("include_path"), 0);
-
+
if (str == NULL) {
RETURN_FALSE;
}
}
if (hash_key->nKeyLength) {
- php_prefix_varname(&new_key, prefix, hash_key->arKey, hash_key->nKeyLength-1, hash_key->type, 0 TSRMLS_CC);
+ php_prefix_varname(&new_key, prefix, hash_key->arKey, hash_key->nKeyLength - 1, hash_key->type, 0 TSRMLS_CC);
} else {
zval num;
ZVAL_LONG(&num, hash_key->h);
AC_MSG_RESULT(no)
fi
-dnl getopt long options disabled for now
-dnl as we can't be sure that we get the right getopt.h here
-dnl using the standard AC_CHECK macros
-dnl AC_CHECK_HEADERS(getopt.h)
-dnl AC_CHECK_FUNCS(getopt_long getopt_long_only)
-
if test "$PHP_SAPI" = "cgi" || test "$PHP_SAPI" = "cli" || test "$PHP_SAPI" = "embed"; then
AC_DEFINE(ENABLE_CHROOT_FUNC, 1, [Whether to enable chroot() function])
fi
#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)
+static int php_opt_error(int argc, char * const *argv, int oint, int optchr, int err, int show_err) /* {{{ */
{
if (show_err)
{
}
return('?');
}
+/* }}} */
+
+PHPAPI int php_optidx = -1;
-int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err)
+PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err, int arg_start) /* {{{ */
{
static int optchr = 0;
static int dash = 0; /* have already seen the - */
- int arg_start = 2;
- int opts_idx = -1;
+ php_optidx = -1;
if (*optind >= argc) {
return(EOF);
}
while (1) {
- opts_idx++;
- if (opts[opts_idx].opt_char == '-') {
+ php_optidx++;
+ if (opts[php_optidx].opt_char == '-') {
(*optind)++;
return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
- } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) {
+ } else if (opts[php_optidx].opt_name && !strcmp(&argv[*optind][2], opts[php_optidx].opt_name)) {
break;
}
}
optchr = 0;
dash = 0;
- arg_start = 2 + strlen(opts[opts_idx].opt_name);
+ arg_start = 2 + strlen(opts[php_optidx].opt_name);
} else {
if (!dash) {
dash = 1;
}
arg_start = 1 + optchr;
}
- if (opts_idx < 0) {
+ if (php_optidx < 0) {
while (1) {
- opts_idx++;
- if (opts[opts_idx].opt_char == '-') {
+ php_optidx++;
+ if (opts[php_optidx].opt_char == '-') {
int errind = *optind;
int errchr = optchr;
-
+
if (!argv[*optind][optchr+1]) {
dash = 0;
(*optind)++;
arg_start++;
}
return(php_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err));
- } else if (argv[*optind][optchr] == opts[opts_idx].opt_char) {
+ } else if (argv[*optind][optchr] == opts[php_optidx].opt_char) {
break;
}
}
}
- if (opts[opts_idx].need_param) {
+ if (opts[php_optidx].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]) {
+ if (!argv[*optind][arg_start]) {
(*optind)++;
if (*optind == argc) {
return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
*optarg = &argv[*optind][arg_start];
(*optind)++;
}
- return opts[opts_idx].opt_char;
+ return opts[php_optidx].opt_char;
} else {
/* multiple options specified as one (exclude long opts) */
if (arg_start >= 2 && !((argv[*optind][0] == '-') && (argv[*optind][1] == '-'))) {
} else {
(*optind)++;
}
- return opts[opts_idx].opt_char;
+ return opts[php_optidx].opt_char;
}
assert(0);
return(0); /* never reached */
}
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
/* $Id$ */
+#ifndef PHP_GETOPT_H
+#define PHP_GETOPT_H
+
#include "php.h"
#ifdef NETWARE
#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.
- */
+ * 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;
+ char opt_char;
+ int need_param;
+ char * opt_name;
} opt_struct;
-int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err);
+BEGIN_EXTERN_C()
+/* holds the index of the latest fetched element from the opts array */
+PHPAPI int php_optidx;
+PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err, int arg_start);
+END_EXTERN_C()
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
}
}
- while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
+ while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
switch (c) {
case 'c':
if (cgi_sapi_module.php_ini_path_override) {
}
zend_first_try {
- while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1)) != -1) {
+ while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1, 2)) != -1) {
switch (c) {
case 'h':
case '?':
goto out;
}
- while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
+ while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
switch (c) {
case 'a': /* interactive mode */
ARG_ENABLE('cgi', 'Build CGI version of PHP', 'yes');
if (PHP_CGI == "yes") {
- SAPI('cgi', 'cgi_main.c getopt.c fastcgi.c', 'php-cgi.exe');
+ SAPI('cgi', 'cgi_main.c ..\\..\\main\\getopt.c fastcgi.c', 'php-cgi.exe');
ADD_FLAG('LIBS_CGI', 'ws2_32.lib kernel32.lib advapi32.lib');
}
PHP_SUBST(SAPI_CGI_PATH)
INSTALL_IT="@echo \"Installing PHP CGI binary: \$(INSTALL_ROOT)\$(bindir)/\"; \$(INSTALL) -m 0755 \$(SAPI_CGI_PATH) \$(INSTALL_ROOT)\$(bindir)/\$(program_prefix)php-cgi\$(program_suffix)\$(EXEEXT)"
- PHP_SELECT_SAPI(cgi, program, fastcgi.c cgi_main.c getopt.c, , '$(SAPI_CGI_PATH)')
+ PHP_SELECT_SAPI(cgi, program, fastcgi.c cgi_main.c, , '$(SAPI_CGI_PATH)')
case $host_alias in
*aix*)
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');
+ SAPI('cli', '..\\..\\main\\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");
}
}
if (PHP_CLI_WIN32 == "yes") {
- SAPI('cli_win32', 'getopt.c cli_win32.c php_cli_readline.c', 'php-win.exe');
+ SAPI('cli_win32', '..\\..\\main\\getopt.c cli_win32.c php_cli_readline.c', 'php-win.exe');
}
+++ /dev/null
-/*
- +----------------------------------------------------------------------+
- | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2007 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 */
- if (argv[*optind][2] == '\0') {
- (*optind)++;
- return(EOF);
- }
-
- while (1) {
- opts_idx++;
- if (opts[opts_idx].opt_char == '-') {
- (*optind)++;
- return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
- } else if (opts[opts_idx].opt_name && !strcmp(&argv[*optind][2], opts[opts_idx].opt_name)) {
- break;
- }
- }
- optchr = 0;
- dash = 0;
- arg_start = 2 + strlen(opts[opts_idx].opt_name);
- } else {
- 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));
- }
- arg_start = 1 + optchr;
- }
- 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++;
- arg_start++;
- }
- 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 {
- /* multiple options specified as one (exclude long opts) */
- if (arg_start >= 2 && !((argv[*optind][0] == '-') && (argv[*optind][1] == '-'))) {
- if (!argv[*optind][optchr+1])
- {
- dash = 0;
- (*optind)++;
- } else {
- optchr++;
- }
- } else {
- (*optind)++;
- }
- return opts[opts_idx].opt_char;
- }
- assert(0);
- return(0); /* never reached */
-}
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) {
+ while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2))!=-1) {
switch (c) {
case 'c':
if (cli_sapi_module.php_ini_path_override) {
goto err;
}
- while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
+ while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
switch (c) {
case 'h': /* help & quit */
php_optind = orig_optind;
php_optarg = orig_optarg;
- while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
+ while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
switch (c) {
case 'a': /* interactive mode */
+++ /dev/null
-/*
- +----------------------------------------------------------------------+
- | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2007 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);
ADD_SOURCES("main", "main.c snprintf.c spprintf.c fopen_wrappers.c \
php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c network.c \
- php_open_temporary_file.c php_logos.c output.c internal_functions.c php_sprintf.c");
+ php_open_temporary_file.c php_logos.c output.c internal_functions.c php_sprintf.c \
+ getopt.c");
ADD_SOURCES("main/streams", "streams.c cast.c memory.c filter.c plain_wrapper.c \
userspace.c transports.c xp_socket.c mmap.c unicode_filter.c glob_wrapper.c");