@@ -117,8 +117,31 @@ static pid_t pgroup;
117
117
#define PHP_MODE_LINT 4
118
118
#define PHP_MODE_STRIP 5
119
119
120
- extern char * ap_php_optarg ;
121
- extern int ap_php_optind ;
120
+ static char * optarg = NULL ;
121
+ static int optind = 1 ;
122
+
123
+ static const opt_struct OPTIONS [] = {
124
+ {'a' , 0 , "interactive" },
125
+ {'C' , 0 , "no-chdir" },
126
+ {'c' , 1 , "php-ini" },
127
+ {'d' , 1 , "define" },
128
+ {'e' , 0 , "profile-info" },
129
+ {'f' , 1 , "file" },
130
+ {'g' , 1 , "global" },
131
+ {'h' , 0 , "help" },
132
+ {'i' , 0 , "info" },
133
+ {'l' , 0 , "syntax-check" },
134
+ {'m' , 0 , "modules" },
135
+ {'n' , 0 , "no-php-ini" },
136
+ {'q' , 0 , "no-header" },
137
+ {'s' , 0 , "syntax-highlight" },
138
+ {'s' , 0 , "syntax-highlighting" },
139
+ {'w' , 0 , "strip" },
140
+ {'?' , 0 , "usage" },/* help alias (both '?' and 'usage') */
141
+ {'v' , 0 , "version" },
142
+ {'z' , 1 , "zend-extension" },
143
+ {'-' , 0 , NULL } /* end of args */
144
+ };
122
145
123
146
#if ENABLE_PATHINFO_CHECK
124
147
/* true global. this is retreived once only, even for fastcgi */
@@ -138,8 +161,6 @@ long fix_pathinfo=1;
138
161
#define TRANSLATE_SLASHES (path )
139
162
#endif
140
163
141
- #define OPTSTRING "abCc:d:ef:g:hilmnqsw?vz:"
142
-
143
164
static int print_module_info (zend_module_entry * module , void * arg TSRMLS_DC )
144
165
{
145
166
php_printf ("%s\n" , module -> name );
@@ -515,7 +536,7 @@ static void php_cgi_usage(char *argv0)
515
536
prog = "php" ;
516
537
}
517
538
518
- php_printf ("Usage: %s [-q] [-h] [-s [-v] [-i] [-f <file>] \n"
539
+ php_printf ("Usage: %s [-q] [-h] [-s] [-v] [-i] [-f <file>]\n"
519
540
" %s <file> [args...]\n"
520
541
" -a Run interactively\n"
521
542
#if PHP_FASTCGI
@@ -881,8 +902,8 @@ int main(int argc, char *argv[])
881
902
/* temporary locals */
882
903
int behavior = PHP_MODE_STANDARD ;
883
904
int no_headers = 0 ;
884
- int orig_optind = ap_php_optind ;
885
- char * orig_optarg = ap_php_optarg ;
905
+ int orig_optind = optind ;
906
+ char * orig_optarg = optarg ;
886
907
char * script_file = NULL ;
887
908
zend_llist global_vars ;
888
909
int interactive = 0 ;
@@ -958,10 +979,10 @@ int main(int argc, char *argv[])
958
979
/* allow ini override for fastcgi */
959
980
#endif
960
981
) {
961
- while ((c = ap_php_getopt (argc , argv , OPTSTRING ))!= -1 ) {
982
+ while ((c = php_getopt (argc , argv , OPTIONS , & optarg , & optind , 0 ))!= -1 ) {
962
983
switch (c ) {
963
984
case 'c' :
964
- cgi_sapi_module .php_ini_path_override = strdup (ap_php_optarg );
985
+ cgi_sapi_module .php_ini_path_override = strdup (optarg );
965
986
break ;
966
987
case 'n' :
967
988
cgi_sapi_module .php_ini_ignore = 1 ;
@@ -971,14 +992,14 @@ int main(int argc, char *argv[])
971
992
we are being started as an 'external' fastcgi
972
993
server by accepting a bindpath parameter. */
973
994
case 'b' :
974
- if (!fastcgi ) bindpath = strdup (ap_php_optarg );
995
+ if (!fastcgi ) bindpath = strdup (optarg );
975
996
break ;
976
997
#endif
977
998
}
978
999
979
1000
}
980
- ap_php_optind = orig_optind ;
981
- ap_php_optarg = orig_optarg ;
1001
+ optind = orig_optind ;
1002
+ optarg = orig_optarg ;
982
1003
}
983
1004
984
1005
#ifdef ZTS
@@ -1172,8 +1193,9 @@ consult the installation file that came with this distribution, or visit \n\
1172
1193
&& !fastcgi
1173
1194
#endif
1174
1195
) {
1175
- while ((c = ap_php_getopt (argc , argv , OPTSTRING ))!= -1 ) {
1196
+ while ((c = php_getopt (argc , argv , OPTIONS , & optarg , & optind , 1 ))!= -1 ) {
1176
1197
switch (c ) {
1198
+ case 'h' :
1177
1199
case '?' :
1178
1200
no_headers = 1 ;
1179
1201
php_output_startup ();
@@ -1185,8 +1207,8 @@ consult the installation file that came with this distribution, or visit \n\
1185
1207
break ;
1186
1208
}
1187
1209
}
1188
- ap_php_optind = orig_optind ;
1189
- ap_php_optarg = orig_optarg ;
1210
+ optind = orig_optind ;
1211
+ optarg = orig_optarg ;
1190
1212
}
1191
1213
1192
1214
#if PHP_FASTCGI
@@ -1236,7 +1258,7 @@ consult the installation file that came with this distribution, or visit \n\
1236
1258
exit (1 );
1237
1259
}
1238
1260
1239
- while ((c = ap_php_getopt (argc , argv , OPTSTRING )) != -1 ) {
1261
+ while ((c = php_getopt (argc , argv , OPTIONS , & optarg , & optind , 0 )) != -1 ) {
1240
1262
switch (c ) {
1241
1263
1242
1264
case 'a' : /* interactive mode */
@@ -1248,37 +1270,26 @@ consult the installation file that came with this distribution, or visit \n\
1248
1270
SG (options ) |= SAPI_OPTION_NO_CHDIR ;
1249
1271
break ;
1250
1272
case 'd' : /* define ini entries on command line */
1251
- define_command_line_ini_entry (ap_php_optarg );
1273
+ define_command_line_ini_entry (optarg );
1252
1274
break ;
1253
1275
1254
1276
case 'e' : /* enable extended info output */
1255
1277
CG (extended_info ) = 1 ;
1256
1278
break ;
1257
1279
1258
1280
case 'f' : /* parse file */
1259
- script_file = estrdup (ap_php_optarg );
1281
+ script_file = estrdup (optarg );
1260
1282
no_headers = 1 ;
1261
1283
break ;
1262
1284
1263
1285
case 'g' : /* define global variables on command line */
1264
1286
{
1265
- char * arg = estrdup (ap_php_optarg );
1287
+ char * arg = estrdup (optarg );
1266
1288
1267
1289
zend_llist_add_element (& global_vars , & arg );
1268
1290
}
1269
1291
break ;
1270
1292
1271
- case 'h' : /* help & quit */
1272
- case '?' :
1273
- no_headers = 1 ;
1274
- php_output_startup ();
1275
- php_output_activate (TSRMLS_C );
1276
- SG (headers_sent ) = 1 ;
1277
- php_cgi_usage (argv [0 ]);
1278
- php_end_ob_buffers (1 TSRMLS_CC );
1279
- exit (1 );
1280
- break ;
1281
-
1282
1293
case 'i' : /* php info & quit */
1283
1294
if (php_request_startup (TSRMLS_C )== FAILURE ) {
1284
1295
php_module_shutdown (TSRMLS_C );
@@ -1345,7 +1356,7 @@ consult the installation file that came with this distribution, or visit \n\
1345
1356
break ;
1346
1357
1347
1358
case 'z' : /* load extension file */
1348
- zend_load_extension (ap_php_optarg );
1359
+ zend_load_extension (optarg );
1349
1360
break ;
1350
1361
1351
1362
default :
@@ -1358,19 +1369,19 @@ consult the installation file that came with this distribution, or visit \n\
1358
1369
if (script_file ) {
1359
1370
len += strlen (script_file ) + 1 ;
1360
1371
}
1361
- for (i = ap_php_optind ; i < argc ; i ++ ) {
1372
+ for (i = optind ; i < argc ; i ++ ) {
1362
1373
len += strlen (argv [i ]) + 1 ;
1363
1374
}
1364
1375
1365
1376
s = malloc (len + 1 ); /* leak - but only for command line version, so ok */
1366
1377
* s = '\0' ; /* we are pretending it came from the environment */
1367
1378
if (script_file ) {
1368
1379
strcpy (s , script_file );
1369
- if (ap_php_optind < argc ) {
1380
+ if (optind < argc ) {
1370
1381
strcat (s , "+" );
1371
1382
}
1372
1383
}
1373
- for (i = ap_php_optind , len = 0 ; i < argc ; i ++ ) {
1384
+ for (i = optind , len = 0 ; i < argc ; i ++ ) {
1374
1385
strcat (s , argv [i ]);
1375
1386
if (i < (argc - 1 )) {
1376
1387
strcat (s , "+" );
@@ -1389,9 +1400,9 @@ consult the installation file that came with this distribution, or visit \n\
1389
1400
SG (request_info ).no_headers = 1 ;
1390
1401
}
1391
1402
1392
- if (!SG (request_info ).path_translated && argc > ap_php_optind ) {
1403
+ if (!SG (request_info ).path_translated && argc > optind ) {
1393
1404
/* file is on command line, but not in -f opt */
1394
- SG (request_info ).path_translated = estrdup (argv [ap_php_optind ]);
1405
+ SG (request_info ).path_translated = estrdup (argv [optind ]);
1395
1406
}
1396
1407
} /* end !cgi && !fastcgi */
1397
1408
0 commit comments