Changeset 5488:31c9e9727d42
- Timestamp:
- 2008-08-19 13:44:26 (3 months ago)
- Author:
- Aron Griffis <agriffis@…>
- Branch:
- HEAD
- Message:
-
Handle -- correctly with or without -a, closes #3097
Prefix optstring with "+" to force POSIX behavior on GNU getopt, and thereby
prevent reordering argv. This allows us to correctly handle mixed addresses,
attachments, options and the double-dash to signal end-of-options.
Signed-off-by: Aron Griffis <agriffis@…>
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r5449
|
r5488
|
|
| 546 | 546 | extern char *optarg; |
| 547 | 547 | extern int optind; |
| 548 | | int attach_sep = 0; |
| | 548 | int double_dash = argc, nargc = 1; |
| 549 | 549 | |
| 550 | 550 | /* sanity check against stupid administrators */ |
| … |
… |
|
| 574 | 574 | memset (QuadOptions, 0, sizeof (QuadOptions)); |
| 575 | 575 | |
| 576 | | for (i = 1; i < argc; i++) |
| 577 | | if (!strcmp(argv[i], "--")) |
| | 576 | for (optind = 1; optind < double_dash; ) |
| | 577 | { |
| | 578 | /* We're getopt'ing POSIXLY, so we'll be here every time getopt() |
| | 579 | * encounters a non-option. That could be a file to attach |
| | 580 | * (all non-options between -a and --) or it could be an address |
| | 581 | * (which gets collapsed to the front of argv). |
| | 582 | */ |
| | 583 | for (; optind < argc; optind++) |
| | 584 | { |
| | 585 | if (argv[optind][0] == '-') |
| 578 | 586 | { |
| 579 | | attach_sep = i; |
| 580 | | break; |
| | 587 | if (argv[optind][1] == '-' && argv[optind][2] == '\0') |
| | 588 | double_dash = optind; /* quit outer loop after getopt */ |
| | 589 | break; /* drop through to getopt */ |
| 581 | 590 | } |
| 582 | 591 | |
| 583 | | while ((i = getopt (argc, argv, "A:a:b:F:f:c:Dd:e:H:s:i:hm:npQ:RvxyzZ")) != EOF) |
| | 592 | /* non-option, either an attachment or address */ |
| | 593 | if (attach) |
| | 594 | attach = mutt_add_list (attach, argv[optind]); |
| | 595 | else |
| | 596 | argv[nargc++] = argv[optind]; |
| | 597 | } |
| | 598 | |
| | 599 | if ((i = getopt (argc, argv, "+A:a:b:F:f:c:Dd:e:H:s:i:hm:npQ:RvxyzZ")) != EOF) |
| 584 | 600 | switch (i) |
| 585 | 601 | { |
| … |
… |
|
| 685 | 701 | mutt_usage (); |
| 686 | 702 | } |
| | 703 | } |
| | 704 | |
| | 705 | /* collapse remaining argv */ |
| | 706 | while (optind < argc) |
| | 707 | argv[nargc++] = argv[optind++]; |
| | 708 | optind = 1; |
| | 709 | argc = nargc; |
| 687 | 710 | |
| 688 | 711 | switch (version) |
| … |
… |
|
| 752 | 775 | return rv; |
| 753 | 776 | } |
| 754 | | |
| 755 | | /* if an -a option is present, all non-option arguments before -- are considered attachments */ |
| 756 | | if (attach) |
| 757 | | for (; optind <= attach_sep; optind++) |
| 758 | | attach = mutt_add_list (attach, argv[optind]); |
| 759 | 777 | |
| 760 | 778 | if (newMagic) |