diff options
| author | Paul Eggert | 2011-05-27 09:58:43 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-05-27 09:58:43 -0700 |
| commit | 842b28a0658be1d3afdf0dbda876c4c354d3672c (patch) | |
| tree | 724d281966fb3f0aa6b6644a48ce42253a0765a4 /lib | |
| parent | a9f737eef69ffe03dd045df555300ae6b41d0edf (diff) | |
| download | emacs-842b28a0658be1d3afdf0dbda876c4c354d3672c.tar.gz emacs-842b28a0658be1d3afdf0dbda876c4c354d3672c.zip | |
* doc/misc/texinfo.tex, lib/getopt.c, lib/intprops.h: Merge from gnulib.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/getopt.c | 83 | ||||
| -rw-r--r-- | lib/intprops.h | 8 |
2 files changed, 70 insertions, 21 deletions
diff --git a/lib/getopt.c b/lib/getopt.c index c8b301363f1..ee96d972d95 100644 --- a/lib/getopt.c +++ b/lib/getopt.c | |||
| @@ -479,8 +479,14 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 479 | || !strchr (optstring, argv[d->optind][1]))))) | 479 | || !strchr (optstring, argv[d->optind][1]))))) |
| 480 | { | 480 | { |
| 481 | char *nameend; | 481 | char *nameend; |
| 482 | unsigned int namelen; | ||
| 482 | const struct option *p; | 483 | const struct option *p; |
| 483 | const struct option *pfound = NULL; | 484 | const struct option *pfound = NULL; |
| 485 | struct option_list | ||
| 486 | { | ||
| 487 | const struct option *p; | ||
| 488 | struct option_list *next; | ||
| 489 | } *ambig_list = NULL; | ||
| 484 | int exact = 0; | 490 | int exact = 0; |
| 485 | int ambig = 0; | 491 | int ambig = 0; |
| 486 | int indfound = -1; | 492 | int indfound = -1; |
| @@ -488,14 +494,14 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 488 | 494 | ||
| 489 | for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++) | 495 | for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++) |
| 490 | /* Do nothing. */ ; | 496 | /* Do nothing. */ ; |
| 497 | namelen = nameend - d->__nextchar; | ||
| 491 | 498 | ||
| 492 | /* Test all long options for either exact match | 499 | /* Test all long options for either exact match |
| 493 | or abbreviated matches. */ | 500 | or abbreviated matches. */ |
| 494 | for (p = longopts, option_index = 0; p->name; p++, option_index++) | 501 | for (p = longopts, option_index = 0; p->name; p++, option_index++) |
| 495 | if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar)) | 502 | if (!strncmp (p->name, d->__nextchar, namelen)) |
| 496 | { | 503 | { |
| 497 | if ((unsigned int) (nameend - d->__nextchar) | 504 | if (namelen == (unsigned int) strlen (p->name)) |
| 498 | == (unsigned int) strlen (p->name)) | ||
| 499 | { | 505 | { |
| 500 | /* Exact match found. */ | 506 | /* Exact match found. */ |
| 501 | pfound = p; | 507 | pfound = p; |
| @@ -513,35 +519,71 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 513 | || pfound->has_arg != p->has_arg | 519 | || pfound->has_arg != p->has_arg |
| 514 | || pfound->flag != p->flag | 520 | || pfound->flag != p->flag |
| 515 | || pfound->val != p->val) | 521 | || pfound->val != p->val) |
| 516 | /* Second or later nonexact match found. */ | 522 | { |
| 517 | ambig = 1; | 523 | /* Second or later nonexact match found. */ |
| 524 | struct option_list *newp = malloc (sizeof (*newp)); | ||
| 525 | newp->p = p; | ||
| 526 | newp->next = ambig_list; | ||
| 527 | ambig_list = newp; | ||
| 528 | } | ||
| 518 | } | 529 | } |
| 519 | 530 | ||
| 520 | if (ambig && !exact) | 531 | if (ambig_list != NULL && !exact) |
| 521 | { | 532 | { |
| 522 | if (print_errors) | 533 | if (print_errors) |
| 523 | { | 534 | { |
| 535 | struct option_list first; | ||
| 536 | first.p = pfound; | ||
| 537 | first.next = ambig_list; | ||
| 538 | ambig_list = &first; | ||
| 539 | |||
| 524 | #if defined _LIBC && defined USE_IN_LIBIO | 540 | #if defined _LIBC && defined USE_IN_LIBIO |
| 525 | char *buf; | 541 | char *buf = NULL; |
| 542 | size_t buflen = 0; | ||
| 526 | 543 | ||
| 527 | if (__asprintf (&buf, _("%s: option '%s' is ambiguous\n"), | 544 | FILE *fp = open_memstream (&buf, &buflen); |
| 528 | argv[0], argv[d->optind]) >= 0) | 545 | if (fp != NULL) |
| 529 | { | 546 | { |
| 530 | _IO_flockfile (stderr); | 547 | fprintf (fp, |
| 548 | _("%s: option '%s' is ambiguous; possibilities:"), | ||
| 549 | argv[0], argv[d->optind]); | ||
| 531 | 550 | ||
| 532 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; | 551 | do |
| 533 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; | 552 | { |
| 553 | fprintf (fp, " '--%s'", ambig_list->p->name); | ||
| 554 | ambig_list = ambig_list->next; | ||
| 555 | } | ||
| 556 | while (ambig_list != NULL); | ||
| 534 | 557 | ||
| 535 | __fxprintf (NULL, "%s", buf); | 558 | fputc_unlocked ('\n', fp); |
| 536 | 559 | ||
| 537 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; | 560 | if (__builtin_expect (fclose (fp) != EOF, 1)) |
| 538 | _IO_funlockfile (stderr); | 561 | { |
| 562 | _IO_flockfile (stderr); | ||
| 539 | 563 | ||
| 540 | free (buf); | 564 | int old_flags2 = ((_IO_FILE *) stderr)->_flags2; |
| 565 | ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; | ||
| 566 | |||
| 567 | __fxprintf (NULL, "%s", buf); | ||
| 568 | |||
| 569 | ((_IO_FILE *) stderr)->_flags2 = old_flags2; | ||
| 570 | _IO_funlockfile (stderr); | ||
| 571 | |||
| 572 | free (buf); | ||
| 573 | } | ||
| 541 | } | 574 | } |
| 542 | #else | 575 | #else |
| 543 | fprintf (stderr, _("%s: option '%s' is ambiguous\n"), | 576 | fprintf (stderr, |
| 577 | _("%s: option '%s' is ambiguous; possibilities:"), | ||
| 544 | argv[0], argv[d->optind]); | 578 | argv[0], argv[d->optind]); |
| 579 | do | ||
| 580 | { | ||
| 581 | fprintf (stderr, " '--%s'", ambig_list->p->name); | ||
| 582 | ambig_list = ambig_list->next; | ||
| 583 | } | ||
| 584 | while (ambig_list != NULL); | ||
| 585 | |||
| 586 | fputc ('\n', stderr); | ||
| 545 | #endif | 587 | #endif |
| 546 | } | 588 | } |
| 547 | d->__nextchar += strlen (d->__nextchar); | 589 | d->__nextchar += strlen (d->__nextchar); |
| @@ -550,6 +592,13 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 550 | return '?'; | 592 | return '?'; |
| 551 | } | 593 | } |
| 552 | 594 | ||
| 595 | while (ambig_list != NULL) | ||
| 596 | { | ||
| 597 | struct option_list *pn = ambig_list->next; | ||
| 598 | free (ambig_list); | ||
| 599 | ambig_list = pn; | ||
| 600 | } | ||
| 601 | |||
| 553 | if (pfound != NULL) | 602 | if (pfound != NULL) |
| 554 | { | 603 | { |
| 555 | option_index = indfound; | 604 | option_index = indfound; |
diff --git a/lib/intprops.h b/lib/intprops.h index 293204ab43a..d722648555b 100644 --- a/lib/intprops.h +++ b/lib/intprops.h | |||
| @@ -25,11 +25,11 @@ | |||
| 25 | /* Return a integer value, converted to the same type as the integer | 25 | /* Return a integer value, converted to the same type as the integer |
| 26 | expression E after integer type promotion. V is the unconverted value. | 26 | expression E after integer type promotion. V is the unconverted value. |
| 27 | E should not have side effects. */ | 27 | E should not have side effects. */ |
| 28 | #define _GL_INT_CONVERT(e, v) ((e) - (e) + (v)) | 28 | #define _GL_INT_CONVERT(e, v) (0 * (e) + (v)) |
| 29 | 29 | ||
| 30 | /* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see | 30 | /* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see |
| 31 | <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00406.html>. */ | 31 | <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00406.html>. */ |
| 32 | #define _GL_INT_NEGATE_CONVERT(e, v) ((e) - (e) - (v)) | 32 | #define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v)) |
| 33 | 33 | ||
| 34 | /* The extra casts in the following macros work around compiler bugs, | 34 | /* The extra casts in the following macros work around compiler bugs, |
| 35 | e.g., in Cray C 5.0.3.0. */ | 35 | e.g., in Cray C 5.0.3.0. */ |
| @@ -314,7 +314,7 @@ | |||
| 314 | Arguments should be free of side effects. */ | 314 | Arguments should be free of side effects. */ |
| 315 | #define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ | 315 | #define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ |
| 316 | op_result_overflow (a, b, \ | 316 | op_result_overflow (a, b, \ |
| 317 | _GL_INT_MINIMUM ((b) - (b) + (a)), \ | 317 | _GL_INT_MINIMUM (0 * (b) + (a)), \ |
| 318 | _GL_INT_MAXIMUM ((b) - (b) + (a))) | 318 | _GL_INT_MAXIMUM (0 * (b) + (a))) |
| 319 | 319 | ||
| 320 | #endif /* _GL_INTPROPS_H */ | 320 | #endif /* _GL_INTPROPS_H */ |