#include "zend_indent.h"
-#if MSVC5 || !defined(HAVE_GETOPT)
#include "php_getopt.h"
-#endif
PHPAPI extern char *php_ini_path;
#define PHP_MODE_HIGHLIGHT 2
#define PHP_MODE_INDENT 3
-PHPAPI extern char *optarg;
-PHPAPI extern int optind;
+PHPAPI extern char *ap_php_optarg;
+PHPAPI extern int ap_php_optind;
static int sapi_cgibin_ub_write(const char *str, uint str_length)
int behavior=PHP_MODE_STANDARD;
int no_headers=0;
int free_path_translated=0;
- int orig_optind=optind;
- char *orig_optarg=optarg;
+ int orig_optind=ap_php_optind;
+ char *orig_optarg=ap_php_optarg;
#if SUPPORT_INTERACTIVE
int interactive=0;
#endif
}
if (!cgi) {
- while ((c=getopt(argc, argv, "c:d:qvisnaeh?vf:"))!=-1) {
+ while ((c=ap_php_getopt(argc, argv, "c:d:qvisnaeh?vf:"))!=-1) {
switch (c) {
case 'c':
- php_ini_path = strdup(optarg); /* intentional leak */
+ php_ini_path = strdup(ap_php_optarg); /* intentional leak */
break;
}
}
- optind = orig_optind;
- optarg = orig_optarg;
+ ap_php_optind = orig_optind;
+ ap_php_optarg = orig_optarg;
}
if (!cgi) { /* never execute the arguments if you are a CGI */
request_info.php_argv0 = NULL;
- while ((c = getopt(argc, argv, "c:d:qvisnaeh?vf:")) != -1) {
+ while ((c = ap_php_getopt(argc, argv, "c:d:qvisnaeh?vf:")) != -1) {
switch (c) {
case 'f':
if (!cgi_started){
SG(headers_sent) = 1;
}
cgi_started=1;
- SG(request_info).path_translated = estrdup(optarg);
+ SG(request_info).path_translated = estrdup(ap_php_optarg);
free_path_translated=1;
/* break missing intentionally */
case 'q':
exit(1);
break;
case 'd':
- define_command_line_ini_entry(optarg);
+ define_command_line_ini_entry(ap_php_optarg);
break;
default:
break;
if (!cgi) {
if (!SG(request_info).query_string) {
- for (i = optind, len = 0; i < argc; i++)
+ for (i = ap_php_optind, len = 0; i < argc; i++)
len += strlen(argv[i]) + 1;
s = malloc(len + 1); /* leak - but only for command line version, so ok */
*s = '\0'; /* we are pretending it came from the environment */
- for (i = optind, len = 0; i < argc; i++) {
+ for (i = ap_php_optind, len = 0; i < argc; i++) {
strcat(s, argv[i]);
if (i < (argc - 1))
strcat(s, "+");
}
SG(request_info).query_string = s;
}
- if (!SG(request_info).path_translated && argc > optind)
- SG(request_info).path_translated = argv[optind];
+ if (!SG(request_info).path_translated && argc > ap_php_optind)
+ SG(request_info).path_translated = argv[ap_php_optind];
}
/* If for some reason the CGI interface is not setting the
PATH_TRANSLATED correctly, SG(request_info).path_translated is NULL.
/* Borrowed from Apache NT Port */
-#if !APACHE
-
#include <stdio.h>
#include <string.h>
#include <assert.h>
#define OPTERRARG (3)
-PHPAPI char *optarg;
-PHPAPI int optind = 1;
-static int opterr = 1;
-static int optopt;
+PHPAPI char *ap_php_optarg;
+PHPAPI int ap_php_optind = 1;
+static int ap_php_opterr = 1;
+static int ap_php_optopt;
static int
-optiserr(int argc, char * const *argv, int oint, const char *optstr,
+ap_php_optiserr(int argc, char * const *argv, int oint, const char *optstr,
int optchr, int err)
{
- if (opterr)
+ if (ap_php_opterr)
{
fprintf(stderr, "Error in argument %d, char %d: ", oint, optchr+1);
switch(err)
break;
}
}
- optopt = argv[oint][optchr];
+ ap_php_optopt = argv[oint][optchr];
return('?');
}
-PHPAPI int getopt(int argc, char* const *argv, const char *optstr)
+PHPAPI int ap_php_getopt(int argc, char* const *argv, const char *optstr)
{
static int optchr = 0;
static int dash = 0; /* have already seen the - */
char *cp;
- if (optind >= argc)
+ if (ap_php_optind >= argc)
return(EOF);
- if (!dash && (argv[optind][0] != '-'))
+ if (!dash && (argv[ap_php_optind][0] != '-'))
return(EOF);
- if (!dash && (argv[optind][0] == '-') && !argv[optind][1])
+ if (!dash && (argv[ap_php_optind][0] == '-') && !argv[ap_php_optind][1])
{
/*
* use to specify stdin. Need to let pgm process this and
*/
return(EOF);
}
- if ((argv[optind][0] == '-') && (argv[optind][1] == '-'))
+ if ((argv[ap_php_optind][0] == '-') && (argv[ap_php_optind][1] == '-'))
{
/* -- indicates end of args */
- optind++;
+ ap_php_optind++;
return(EOF);
}
if (!dash)
{
- assert((argv[optind][0] == '-') && argv[optind][1]);
+ assert((argv[ap_php_optind][0] == '-') && argv[ap_php_optind][1]);
dash = 1;
optchr = 1;
}
/* Check if the guy tries to do a -: kind of flag */
assert(dash);
- if (argv[optind][optchr] == ':')
+ if (argv[ap_php_optind][optchr] == ':')
{
dash = 0;
- optind++;
- return(optiserr(argc, argv, optind-1, optstr, optchr, OPTERRCOLON));
+ ap_php_optind++;
+ return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRCOLON));
}
- if (!(cp = strchr(optstr, argv[optind][optchr])))
+ if (!(cp = strchr(optstr, argv[ap_php_optind][optchr])))
{
- int errind = optind;
+ int errind = ap_php_optind;
int errchr = optchr;
- if (!argv[optind][optchr+1])
+ if (!argv[ap_php_optind][optchr+1])
{
dash = 0;
- optind++;
+ ap_php_optind++;
}
else
optchr++;
- return(optiserr(argc, argv, errind, optstr, errchr, OPTERRNF));
+ return(ap_php_optiserr(argc, argv, errind, optstr, errchr, OPTERRNF));
}
if (cp[1] == ':')
{
dash = 0;
- optind++;
- if (optind == argc)
- return(optiserr(argc, argv, optind-1, optstr, optchr, OPTERRARG));
- optarg = argv[optind++];
+ ap_php_optind++;
+ if (ap_php_optind == argc)
+ return(ap_php_optiserr(argc, argv, ap_php_optind-1, optstr, optchr, OPTERRARG));
+ ap_php_optarg = argv[ap_php_optind++];
return(*cp);
}
else
{
- if (!argv[optind][optchr+1])
+ if (!argv[ap_php_optind][optchr+1])
{
dash = 0;
- optind++;
+ ap_php_optind++;
}
else
optchr++;
return(0);
}
-#endif /* !APACHE */
-
#ifdef TESTGETOPT
int
main (int argc, char **argv)
{
int c;
- extern char *optarg;
- extern int optind;
+ extern char *ap_php_optarg;
+ extern int ap_php_optind;
int aflg = 0;
int bflg = 0;
int errflg = 0;
char *ofile = NULL;
- while ((c = getopt(argc, argv, "abo:")) != EOF)
+ while ((c = ap_php_getopt(argc, argv, "abo:")) != EOF)
switch (c) {
case 'a':
if (bflg)
bflg++;
break;
case 'o':
- ofile = optarg;
+ ofile = ap_php_optarg;
(void)printf("ofile = %s\n", ofile);
break;
case '?':
"usage: cmd [-a|-b] [-o <filename>] files...\n");
exit (2);
}
- for ( ; optind < argc; optind++)
- (void)printf("%s\n", argv[optind]);
+ for ( ; ap_php_optind < argc; ap_php_optind++)
+ (void)printf("%s\n", argv[ap_php_optind]);
return 0;
}