- /*
- * If the user specified "-" and '-' isn't listed in
- * options, return -1 (non-option) as per POSIX.
- * Otherwise, it is an unknown option character (or ':').
- */
- if (optchar == (int)'-' && *i_place_ == '\0')
- return (-1);
- if (!*i_place_)
- ++i_optind_;
- if (I_PRINT_ERROR_)
- i_warnx_(i_illoptchar_, optchar);
- i_optopt_ = optchar;
- return (I_BADCH_);
- }
- if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
- /* -W long-option */
- if (*i_place_) { /* no space */
- /* NOTHING */;
- } else if (++i_optind_ >= nargc) { /* no arg */
- i_place_ = I_EMSG_;
- if (I_PRINT_ERROR_)
- i_warnx_(i_recargchar_, optchar);
- i_optopt_ = optchar;
- return (I_BADARG_);
- } else { /* white space */
- i_place_ = nargv[i_optind_];
- }
- optchar = i_parse_long_options__(nargv, options, long_options,
- idx, 0);
- i_place_ = I_EMSG_;
- return (optchar);
- }
- if (*++oli != ':') { /* doesn't take argument */
- if (!*i_place_)
- ++i_optind_;
- } else { /* takes (optional) argument */
- i_optarg_ = NULL;
- if (*i_place_) /* no white space */
- i_optarg_ = i_place_;
- else if (oli[1] != ':') { /* arg not optional */
- if (++i_optind_ >= nargc) { /* no arg */
- i_place_ = I_EMSG_;
- if (I_PRINT_ERROR_)
- i_warnx_(i_recargchar_, optchar);
- i_optopt_ = optchar;
- return (I_BADARG_);
- } else {
- i_optarg_ = nargv[i_optind_];
- }
- }
- i_place_ = I_EMSG_;
- ++i_optind_;
- }
- /* dump back option letter */
- return (optchar);
- }
-
- int
- i_getsubopt_(char **optionp, char * const *tokens, char **valuep)
- {
- int cnt;
- char *p;
-
- i_suboptarg_ = *valuep = NULL;
-
- if (!optionp || !*optionp)
- return(-1);
-
- /* skip leading white-space, commas */
- for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
-
- if (!*p) {
- *optionp = p;
- return(-1);
- }
-
- /* save the start of the token, and skip the rest of the token. */
- for (i_suboptarg_ = p;
- *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';);
-
- if (*p) {
- /*
- * If there's an equals sign, set the value pointer, and
- * skip over the value part of the token. Terminate the
- * token.
- */
- if (*p == '=') {
- *p = '\0';
- for (*valuep = ++p;
- *p && *p != ',' && *p != ' ' && *p != '\t'; ++p);
- if (*p)
- *p++ = '\0';
- } else {
- *p++ = '\0';
- }
- /* Skip any whitespace or commas after this token. */
- for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
- }
-
- /* set optionp for next round. */
- *optionp = p;
-
- for (cnt = 0; *tokens; ++tokens, ++cnt)
- if (!strcmp(i_suboptarg_, *tokens))
- return(cnt);
- return(-1);
- }
-
- int
- i_getopt_(int argc, char * const *argv, const char *optstring)
- {
- #ifdef GETOPT_PERMUTE_ARGS
- return (i_getopt_internal_(argc, argv, optstring, NULL, NULL,
- I_FLAG_PERMUTE_));
- #else
- return (i_getopt_internal_(argc, argv, optstring, NULL, NULL, 0));
- #endif
- }
-
- int
- i_getopt_long_(int argc, char * const *argv, const char *optstring,
- const struct option *longopts, int *longindex)
- {
- #ifdef GETOPT_LONG_PERMUTE_ARGS
- return (i_getopt_internal_(argc, argv, optstring, longopts, longindex,
- I_FLAG_PERMUTE_));
- #else
- return (i_getopt_internal_(argc, argv, optstring, longopts, longindex, 0));
- #endif
-
- }
-
- int
- i_getopt_long_only_(int argc, char * const *argv, const char *optstring,
- const struct option *longopts, int *longindex)
- {
- #ifdef GETOPT_LONG_ONLY_PERMUTE_ARGS
- return (i_getopt_internal_(argc, argv, optstring, longopts, longindex,
- I_FLAG_PERMUTE_ | I_FLAG_LONGONLY_));
- #else
- return (i_getopt_internal_(argc, argv, optstring, longopts, longindex,
- I_FLAG_LONGONLY_));
- #endif
- }
+ /*
+ * If the user specified "-" and '-' isn't listed in
+ * options, return -1 (non-option) as per POSIX.
+ * Otherwise, it is an unknown option character (or ':').
+ */
+ if (optchar == (int) '-' && *i_place_ == '\0')
+ return (-1);
+ if (!*i_place_)
+ ++i_optind_;
+ if (I_PRINT_ERROR_)
+ i_warnx_(i_illoptchar_, optchar);
+ i_optopt_ = optchar;
+ return (I_BADCH_);
+ }
+ if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
+ /* -W long-option */
+ if (*i_place_) { /* no space */
+ /* NOTHING */
+ ;
+ } else if (++i_optind_ >= nargc) { /* no arg */
+ i_place_ = I_EMSG_;
+ if (I_PRINT_ERROR_)
+ i_warnx_(i_recargchar_, optchar);
+ i_optopt_ = optchar;
+ return (I_BADARG_);
+ } else { /* white space */
+ i_place_ = nargv[i_optind_];
+ }
+ optchar = i_parse_long_options__(nargv, options, long_options,
+ idx, 0);
+ i_place_ = I_EMSG_;
+ return (optchar);
+ }
+ if (*++oli != ':') { /* doesn't take argument */
+ if (!*i_place_)
+ ++i_optind_;
+ } else { /* takes (optional) argument */
+ i_optarg_ = NULL;
+ if (*i_place_){ /* no white space */
+ i_optarg_ = i_place_;
+ } else if (oli[1] != ':'){ /* arg not optional */
+ if (++i_optind_ >= nargc) { /* no arg */
+ i_place_ = I_EMSG_;
+ if (I_PRINT_ERROR_)
+ i_warnx_(i_recargchar_, optchar);
+ i_optopt_ = optchar;
+ return (I_BADARG_);
+ } else {
+ i_optarg_ = nargv[i_optind_];
+ }
+ }
+ i_place_ = I_EMSG_;
+ ++i_optind_;
+ }
+ /* dump back option letter */
+ return (optchar);
+}
+
+int
+i_getsubopt_(char **optionp, char * const *tokens, char **valuep)
+{
+ int cnt;
+ char *p;
+
+ i_suboptarg_ = *valuep = NULL;
+
+ if (!optionp || !*optionp)
+ return (-1);
+
+ /* skip leading white-space, commas */
+ for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p) ;
+
+ if (!*p) {
+ *optionp = p;
+ return (-1);
+ }
+
+ /* save the start of the token, and skip the rest of the token. */
+ for (i_suboptarg_ = p;
+ *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';) ;
+
+ if (*p) {
+ /*
+ * If there's an equals sign, set the value pointer, and
+ * skip over the value part of the token. Terminate the
+ * token.
+ */
+ if (*p == '=') {
+ *p = '\0';
+ for (*valuep = ++p;
+ *p && *p != ',' && *p != ' ' && *p != '\t'; ++p) ;
+ if (*p)
+ *p++ = '\0';
+ } else {
+ *p++ = '\0';
+ }
+ /* Skip any whitespace or commas after this token. */
+ for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p) ;
+ }
+
+ /* set optionp for next round. */
+ *optionp = p;
+
+ for (cnt = 0; *tokens; ++tokens, ++cnt)
+ if (!strcmp(i_suboptarg_, *tokens))
+ return (cnt);
+ return (-1);
+}
+
+int
+i_getopt_(int argc, char * const *argv, const char *optstring)
+{
+#ifdef GETOPT_PERMUTE_ARGS
+ return (i_getopt_internal_(argc, argv, optstring, NULL, NULL,
+ I_FLAG_PERMUTE_));
+#else
+ return (i_getopt_internal_(argc, argv, optstring, NULL, NULL, 0));
+#endif
+}
+
+int
+i_getopt_long_(int argc, char * const *argv, const char *optstring,
+ const struct option *longopts, int *longindex)
+{
+#ifdef GETOPT_LONG_PERMUTE_ARGS
+ return (i_getopt_internal_(argc, argv, optstring, longopts, longindex,
+ I_FLAG_PERMUTE_));
+#else
+ return (i_getopt_internal_(argc, argv, optstring, longopts, longindex, 0
+ ));
+#endif
+}
+
+int
+i_getopt_long_only_(int argc, char * const *argv, const char *optstring,
+ const struct option *longopts, int *longindex)
+{
+#ifdef GETOPT_LONG_ONLY_PERMUTE_ARGS
+ return (i_getopt_internal_(argc, argv, optstring, longopts, longindex,
+ I_FLAG_PERMUTE_ | I_FLAG_LONGONLY_));
+#else
+ return (i_getopt_internal_(argc, argv, optstring, longopts, longindex,
+ I_FLAG_LONGONLY_));
+#endif
+}