+ *
+ * If long_only and the ARGV-element has the form "-f", where f is
+ * a valid short option, don't consider it an abbreviated form of
+ * a long option that starts with f. Otherwise there would be no
+ * way to give the -f short option.
+ *
+ * On the other hand, if there's a long option "fubar" and
+ * the ARGV-element is "-fu", do consider that an abbreviation of
+ * the long option, just like "--fu", and not "-f" with arg "u".
+ *
+ * This distinction seems to be the most useful approach. */
+
+ if (longopts != NULL &&
+ (argv[GNoptind][1] == '-' ||
+ (long_only &&
+ (argv[GNoptind][2] || !my_index (optstring, argv[GNoptind][1])))))
+ {
+ char *nameend;
+ const struct GNoption *p;
+ const struct GNoption *pfound = NULL;
+ int exact = 0;
+ int ambig = 0;
+ int indfound = -1;
+ int option_index;
+
+ for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
+ /* Do nothing. */ ;
+
+ /* Test all long options for either exact match
+ * or abbreviated matches. */
+ for (p = longopts, option_index = 0; p->name; p++, option_index++)
+ if (!strncmp (p->name, nextchar, nameend - nextchar))
+ {
+ if ((unsigned int) (nameend - nextchar) ==
+ (unsigned int) strlen (p->name))
+ {
+ /* Exact match found. */
+ pfound = p;
+ indfound = option_index;
+ exact = 1;
+ break;
+ }
+ else if (pfound == NULL)
+ {
+ /* First nonexact match found. */
+ pfound = p;
+ indfound = option_index;
+ }
+ else
+ /* Second or later nonexact match found. */
+ ambig = 1;
+ }