+/* This sets the len and o to indicate how far it is into the
+ * opt_table's names field. */
+static struct opt_table *opt_find_long_extra(const char *arg,
+ const char **optarg,
+ unsigned int *len,
+ const char **o)
+{
+ unsigned i;
+
+ *optarg = NULL;
+ for (*o = first_lopt(&i, len);
+ *o;
+ *o = next_lopt(*o, &i, len)) {
+ if (strncmp(arg, *o, *len) != 0)
+ continue;
+ if (arg[*len] == '=')
+ *optarg = arg + *len + 1;
+ else if (arg[*len] != '\0')
+ continue;
+ return &opt_table[i];
+
+ }
+ return NULL;
+}
+
+struct opt_table *opt_find_long(const char *arg, const char **optarg)
+{
+ unsigned len;
+ const char *o;
+
+ return opt_find_long_extra(arg, optarg ? optarg : &o, &len, &o);
+}
+
+static struct opt_table *opt_find_short_extra(char arg, const char **o)
+{
+ unsigned i;
+ for (*o = first_sopt(&i); *o; *o = next_sopt(*o, &i)) {
+ if (arg == **o)
+ return &opt_table[i];
+ }
+ return NULL;
+}
+
+struct opt_table *opt_find_short(char arg)
+{
+ const char *o;
+ return opt_find_short_extra(arg, &o);
+}
+