1818#include <stdlib.h>
1919#include "php_getopt.h"
2020
21- #define OPTERRCOLON (1)
22- #define OPTERRNF (2)
23- #define OPTERRARG (3)
21+ #define OPTERRCOLON 1
22+ #define OPTERRNF 2
23+ #define OPTERRARG 3
2424
2525// Print error message to stderr and return -2 to distinguish it from '?' command line option.
2626static int php_opt_error (int argc , char * const * argv , int optint , int optchr , int err , int show_err ) /* {{{ */
2727{
28- if (show_err )
29- {
28+ if (show_err ) {
3029 fprintf (stderr , "Error in argument %d, char %d: " , optint , optchr + 1 );
3130 switch (err )
3231 {
@@ -61,28 +60,26 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
6160 * optarg = NULL ;
6261 }
6362
64- if (prev_optarg && prev_optarg != optarg ) {
63+ if (prev_optarg && prev_optarg != optarg ) {
6564 /* reset the state */
6665 optchr = 0 ;
6766 dash = 0 ;
6867 }
6968 prev_optarg = optarg ;
7069
7170 if (* optind >= argc ) {
72- return ( EOF ) ;
71+ return EOF ;
7372 }
7473 if (!dash ) {
75- if ((argv [* optind ][0 ] != '-' )) {
76- return (EOF );
77- } else {
78- if (!argv [* optind ][1 ])
79- {
80- /*
81- * use to specify stdin. Need to let pgm process this and
82- * the following args
83- */
84- return (EOF );
85- }
74+ if (argv [* optind ][0 ] != '-' ) {
75+ return EOF ;
76+ }
77+ if (!argv [* optind ][1 ]) {
78+ /*
79+ * use to specify stdin. Need to let pgm process this and
80+ * the following args
81+ */
82+ return EOF ;
8683 }
8784 }
8885 if ((argv [* optind ][0 ] == '-' ) && (argv [* optind ][1 ] == '-' )) {
@@ -92,7 +89,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
9289 /* '--' indicates end of args if not followed by a known long option name */
9390 if (argv [* optind ][2 ] == '\0' ) {
9491 (* optind )++ ;
95- return ( EOF ) ;
92+ return EOF ;
9693 }
9794
9895 arg_start = 2 ;
@@ -109,7 +106,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
109106 php_optidx ++ ;
110107 if (opts [php_optidx ].opt_char == '-' ) {
111108 (* optind )++ ;
112- return ( php_opt_error (argc , argv , * optind - 1 , optchr , OPTERRARG , show_err ) );
109+ return php_opt_error (argc , argv , * optind - 1 , optchr , OPTERRARG , show_err );
113110 } else if (opts [php_optidx ].opt_name && !strncmp (& argv [* optind ][2 ], opts [php_optidx ].opt_name , arg_end ) && arg_end == strlen (opts [php_optidx ].opt_name )) {
114111 break ;
115112 }
@@ -127,7 +124,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
127124 if (argv [* optind ][optchr ] == ':' ) {
128125 dash = 0 ;
129126 (* optind )++ ;
130- return ( php_opt_error (argc , argv , * optind - 1 , optchr , OPTERRCOLON , show_err ) );
127+ return php_opt_error (argc , argv , * optind - 1 , optchr , OPTERRCOLON , show_err );
131128 }
132129 arg_start = 1 + optchr ;
133130 }
@@ -145,7 +142,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
145142 optchr ++ ;
146143 arg_start ++ ;
147144 }
148- return ( php_opt_error (argc , argv , errind , errchr , OPTERRNF , show_err ) );
145+ return php_opt_error (argc , argv , errind , errchr , OPTERRNF , show_err );
149146 } else if (argv [* optind ][optchr ] == opts [php_optidx ].opt_char ) {
150147 break ;
151148 }
@@ -160,7 +157,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
160157 if (* optind == argc ) {
161158 /* Was the value required or is it optional? */
162159 if (opts [php_optidx ].need_param == 1 ) {
163- return ( php_opt_error (argc , argv , * optind - 1 , optchr , OPTERRARG , show_err ) );
160+ return php_opt_error (argc , argv , * optind - 1 , optchr , OPTERRARG , show_err );
164161 }
165162 /* Optional value is not supported with -<arg> <val> style */
166163 } else if (opts [php_optidx ].need_param == 1 ) {
@@ -178,8 +175,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
178175 } else {
179176 /* multiple options specified as one (exclude long opts) */
180177 if (arg_start >= 2 && !((argv [* optind ][0 ] == '-' ) && (argv [* optind ][1 ] == '-' ))) {
181- if (!argv [* optind ][optchr + 1 ])
182- {
178+ if (!argv [* optind ][optchr + 1 ]) {
183179 dash = 0 ;
184180 (* optind )++ ;
185181 } else {
@@ -191,6 +187,6 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
191187 return opts [php_optidx ].opt_char ;
192188 }
193189 assert (0 );
194- return ( 0 ) ; /* never reached */
190+ return 0 ; /* never reached */
195191}
196192/* }}} */
0 commit comments