summaryrefslogtreecommitdiff
path: root/sapi/cgi/cgi_main.c
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2003-02-16 01:23:11 +0000
committerMarcus Boerger <helly@php.net>2003-02-16 01:23:11 +0000
commitd4fd1c07b1dfac42061d96c3a7aae9f0b91d218d (patch)
treee8986edb10020c657cf7c692af02b5be53d13bd6 /sapi/cgi/cgi_main.c
parent824baa0384e301712ff222a60b0049a06b0bdbd4 (diff)
downloadphp-git-d4fd1c07b1dfac42061d96c3a7aae9f0b91d218d.tar.gz
- Allow long option names
- Update CLI's manpage @Added support for long options in CLI & CGI (e.g. --version). (Marcus) # In contrast to the preliminary patch this should work now completely. # If all long option names are accepted we may even think about MFHing.
Diffstat (limited to 'sapi/cgi/cgi_main.c')
-rw-r--r--sapi/cgi/cgi_main.c83
1 files changed, 47 insertions, 36 deletions
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index 593b7b87d5..207d8e2949 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -117,8 +117,31 @@ static pid_t pgroup;
#define PHP_MODE_LINT 4
#define PHP_MODE_STRIP 5
-extern char *ap_php_optarg;
-extern int ap_php_optind;
+static char *optarg = NULL;
+static int optind = 1;
+
+static const opt_struct OPTIONS[] = {
+ {'a', 0, "interactive"},
+ {'C', 0, "no-chdir"},
+ {'c', 1, "php-ini"},
+ {'d', 1, "define"},
+ {'e', 0, "profile-info"},
+ {'f', 1, "file"},
+ {'g', 1, "global"},
+ {'h', 0, "help"},
+ {'i', 0, "info"},
+ {'l', 0, "syntax-check"},
+ {'m', 0, "modules"},
+ {'n', 0, "no-php-ini"},
+ {'q', 0, "no-header"},
+ {'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"},
+ {'-', 0, NULL} /* end of args */
+};
#if ENABLE_PATHINFO_CHECK
/* true global. this is retreived once only, even for fastcgi */
@@ -138,8 +161,6 @@ long fix_pathinfo=1;
#define TRANSLATE_SLASHES(path)
#endif
-#define OPTSTRING "abCc:d:ef:g:hilmnqsw?vz:"
-
static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
{
php_printf("%s\n", module->name);
@@ -515,7 +536,7 @@ static void php_cgi_usage(char *argv0)
prog = "php";
}
- php_printf("Usage: %s [-q] [-h] [-s [-v] [-i] [-f <file>] \n"
+ php_printf("Usage: %s [-q] [-h] [-s] [-v] [-i] [-f <file>]\n"
" %s <file> [args...]\n"
" -a Run interactively\n"
#if PHP_FASTCGI
@@ -881,8 +902,8 @@ int main(int argc, char *argv[])
/* temporary locals */
int behavior=PHP_MODE_STANDARD;
int no_headers=0;
- int orig_optind=ap_php_optind;
- char *orig_optarg=ap_php_optarg;
+ int orig_optind=optind;
+ char *orig_optarg=optarg;
char *script_file=NULL;
zend_llist global_vars;
int interactive=0;
@@ -958,10 +979,10 @@ int main(int argc, char *argv[])
/* allow ini override for fastcgi */
#endif
) {
- while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
+ while ((c=php_getopt(argc, argv, OPTIONS, &optarg, &optind, 0))!=-1) {
switch (c) {
case 'c':
- cgi_sapi_module.php_ini_path_override = strdup(ap_php_optarg);
+ cgi_sapi_module.php_ini_path_override = strdup(optarg);
break;
case 'n':
cgi_sapi_module.php_ini_ignore = 1;
@@ -971,14 +992,14 @@ int main(int argc, char *argv[])
we are being started as an 'external' fastcgi
server by accepting a bindpath parameter. */
case 'b':
- if (!fastcgi) bindpath= strdup(ap_php_optarg);
+ if (!fastcgi) bindpath= strdup(optarg);
break;
#endif
}
}
- ap_php_optind = orig_optind;
- ap_php_optarg = orig_optarg;
+ optind = orig_optind;
+ optarg = orig_optarg;
}
#ifdef ZTS
@@ -1172,8 +1193,9 @@ consult the installation file that came with this distribution, or visit \n\
&& !fastcgi
#endif
) {
- while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) {
+ while ((c=php_getopt(argc, argv, OPTIONS, &optarg, &optind, 1))!=-1) {
switch (c) {
+ case 'h':
case '?':
no_headers = 1;
php_output_startup();
@@ -1185,8 +1207,8 @@ consult the installation file that came with this distribution, or visit \n\
break;
}
}
- ap_php_optind = orig_optind;
- ap_php_optarg = orig_optarg;
+ optind = orig_optind;
+ optarg = orig_optarg;
}
#if PHP_FASTCGI
@@ -1236,7 +1258,7 @@ consult the installation file that came with this distribution, or visit \n\
exit(1);
}
- while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) {
+ while ((c = php_getopt(argc, argv, OPTIONS, &optarg, &optind, 0)) != -1) {
switch (c) {
case 'a': /* interactive mode */
@@ -1248,7 +1270,7 @@ consult the installation file that came with this distribution, or visit \n\
SG(options) |= SAPI_OPTION_NO_CHDIR;
break;
case 'd': /* define ini entries on command line */
- define_command_line_ini_entry(ap_php_optarg);
+ define_command_line_ini_entry(optarg);
break;
case 'e': /* enable extended info output */
@@ -1256,29 +1278,18 @@ consult the installation file that came with this distribution, or visit \n\
break;
case 'f': /* parse file */
- script_file = estrdup(ap_php_optarg);
+ script_file = estrdup(optarg);
no_headers = 1;
break;
case 'g': /* define global variables on command line */
{
- char *arg = estrdup(ap_php_optarg);
+ char *arg = estrdup(optarg);
zend_llist_add_element(&global_vars, &arg);
}
break;
- case 'h': /* help & quit */
- case '?':
- no_headers = 1;
- php_output_startup();
- php_output_activate(TSRMLS_C);
- SG(headers_sent) = 1;
- php_cgi_usage(argv[0]);
- php_end_ob_buffers(1 TSRMLS_CC);
- exit(1);
- break;
-
case 'i': /* php info & quit */
if (php_request_startup(TSRMLS_C)==FAILURE) {
php_module_shutdown(TSRMLS_C);
@@ -1345,7 +1356,7 @@ consult the installation file that came with this distribution, or visit \n\
break;
case 'z': /* load extension file */
- zend_load_extension(ap_php_optarg);
+ zend_load_extension(optarg);
break;
default:
@@ -1358,7 +1369,7 @@ consult the installation file that came with this distribution, or visit \n\
if (script_file) {
len += strlen(script_file) + 1;
}
- for (i = ap_php_optind; i < argc; i++) {
+ for (i = optind; i < argc; i++) {
len += strlen(argv[i]) + 1;
}
@@ -1366,11 +1377,11 @@ consult the installation file that came with this distribution, or visit \n\
*s = '\0'; /* we are pretending it came from the environment */
if (script_file) {
strcpy(s, script_file);
- if (ap_php_optind<argc) {
+ if (optind<argc) {
strcat(s, "+");
}
}
- for (i = ap_php_optind, len = 0; i < argc; i++) {
+ for (i = optind, len = 0; i < argc; i++) {
strcat(s, argv[i]);
if (i < (argc - 1)) {
strcat(s, "+");
@@ -1389,9 +1400,9 @@ consult the installation file that came with this distribution, or visit \n\
SG(request_info).no_headers = 1;
}
- if (!SG(request_info).path_translated && argc > ap_php_optind) {
+ if (!SG(request_info).path_translated && argc > optind) {
/* file is on command line, but not in -f opt */
- SG(request_info).path_translated = estrdup(argv[ap_php_optind]);
+ SG(request_info).path_translated = estrdup(argv[optind]);
}
} /* end !cgi && !fastcgi */