diff options
| author | Richard M. Stallman | 1998-06-23 14:42:40 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-06-23 14:42:40 +0000 |
| commit | 956e3c7e0ba945a2ea6b10acc6059946c2a8be14 (patch) | |
| tree | b119eef629c7cf2a103cbb57cac8da4b433d0e58 /src | |
| parent | 6287be55b2c535dffaddbe88f13b9b45798bb821 (diff) | |
| download | emacs-956e3c7e0ba945a2ea6b10acc6059946c2a8be14.tar.gz emacs-956e3c7e0ba945a2ea6b10acc6059946c2a8be14.zip | |
(sort_args): Discard duplicate options with no args.
(main): With duplicate -d options, use the last one. Likewise for -t.
Check -d last, by checking for -nl earlier on.
Diffstat (limited to 'src')
| -rw-r--r-- | src/emacs.c | 197 |
1 files changed, 117 insertions, 80 deletions
diff --git a/src/emacs.c b/src/emacs.c index 671c6eb4b62..f84cb223a1b 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -557,6 +557,7 @@ main (argc, argv, envp) | |||
| 557 | #ifdef HAVE_SETRLIMIT | 557 | #ifdef HAVE_SETRLIMIT |
| 558 | struct rlimit rlim; | 558 | struct rlimit rlim; |
| 559 | #endif | 559 | #endif |
| 560 | int no_loadup = 0; | ||
| 560 | 561 | ||
| 561 | #ifdef LINUX_SBRK_BUG | 562 | #ifdef LINUX_SBRK_BUG |
| 562 | __sbrk (1); | 563 | __sbrk (1); |
| @@ -578,6 +579,8 @@ main (argc, argv, envp) | |||
| 578 | #endif | 579 | #endif |
| 579 | 580 | ||
| 580 | sort_args (argc, argv); | 581 | sort_args (argc, argv); |
| 582 | argc = 0; | ||
| 583 | while (argv[argc]) argc++; | ||
| 581 | 584 | ||
| 582 | if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args) | 585 | if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args) |
| 583 | /* We don't know the version number unless this is a dumped Emacs. | 586 | /* We don't know the version number unless this is a dumped Emacs. |
| @@ -748,32 +751,36 @@ main (argc, argv, envp) | |||
| 748 | inhibit_window_system = 0; | 751 | inhibit_window_system = 0; |
| 749 | 752 | ||
| 750 | /* Handle the -t switch, which specifies filename to use as terminal */ | 753 | /* Handle the -t switch, which specifies filename to use as terminal */ |
| 751 | { | 754 | while (1) |
| 752 | char *term; | 755 | { |
| 753 | if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args)) | 756 | char *term; |
| 754 | { | 757 | if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args)) |
| 755 | int result; | 758 | { |
| 756 | close (0); | 759 | int result; |
| 757 | close (1); | 760 | close (0); |
| 758 | result = open (term, O_RDWR, 2 ); | 761 | close (1); |
| 759 | if (result < 0) | 762 | result = open (term, O_RDWR, 2 ); |
| 760 | { | 763 | if (result < 0) |
| 761 | char *errstring = strerror (errno); | 764 | { |
| 762 | fprintf (stderr, "emacs: %s: %s\n", term, errstring); | 765 | char *errstring = strerror (errno); |
| 763 | exit (1); | 766 | fprintf (stderr, "emacs: %s: %s\n", term, errstring); |
| 764 | } | 767 | exit (1); |
| 765 | dup (0); | 768 | } |
| 766 | if (! isatty (0)) | 769 | dup (0); |
| 767 | { | 770 | if (! isatty (0)) |
| 768 | fprintf (stderr, "emacs: %s: not a tty\n", term); | 771 | { |
| 769 | exit (1); | 772 | fprintf (stderr, "emacs: %s: not a tty\n", term); |
| 770 | } | 773 | exit (1); |
| 771 | fprintf (stderr, "Using %s\n", term); | 774 | } |
| 775 | fprintf (stderr, "Using %s\n", term); | ||
| 772 | #ifdef HAVE_WINDOW_SYSTEM | 776 | #ifdef HAVE_WINDOW_SYSTEM |
| 773 | inhibit_window_system = 1; /* -t => -nw */ | 777 | inhibit_window_system = 1; /* -t => -nw */ |
| 774 | #endif | 778 | #endif |
| 775 | } | 779 | } |
| 776 | } | 780 | else |
| 781 | break; | ||
| 782 | } | ||
| 783 | |||
| 777 | if (argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args)) | 784 | if (argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args)) |
| 778 | inhibit_window_system = 1; | 785 | inhibit_window_system = 1; |
| 779 | 786 | ||
| @@ -796,48 +803,6 @@ the Bugs section of the Emacs manual or the file BUGS.\n", argv[0]); | |||
| 796 | exit (0); | 803 | exit (0); |
| 797 | } | 804 | } |
| 798 | 805 | ||
| 799 | #ifdef HAVE_X_WINDOWS | ||
| 800 | /* Stupid kludge to catch command-line display spec. We can't | ||
| 801 | handle this argument entirely in window system dependent code | ||
| 802 | because we don't even know which window system dependent code | ||
| 803 | to run until we've recognized this argument. */ | ||
| 804 | { | ||
| 805 | char *displayname = 0; | ||
| 806 | int i; | ||
| 807 | int count_before = skip_args; | ||
| 808 | |||
| 809 | if (argmatch (argv, argc, "-d", "--display", 3, &displayname, &skip_args)) | ||
| 810 | display_arg = 1; | ||
| 811 | else if (argmatch (argv, argc, "-display", 0, 3, &displayname, &skip_args)) | ||
| 812 | display_arg = 1; | ||
| 813 | |||
| 814 | /* If we have the form --display=NAME, | ||
| 815 | convert it into -d name. | ||
| 816 | This requires inserting a new element into argv. */ | ||
| 817 | if (displayname != 0 && skip_args - count_before == 1) | ||
| 818 | { | ||
| 819 | char **new = (char **) xmalloc (sizeof (char *) * (argc + 2)); | ||
| 820 | int j; | ||
| 821 | |||
| 822 | for (j = 0; j < count_before + 1; j++) | ||
| 823 | new[j] = argv[j]; | ||
| 824 | new[count_before + 1] = "-d"; | ||
| 825 | new[count_before + 2] = displayname; | ||
| 826 | for (j = count_before + 2; j <argc; j++) | ||
| 827 | new[j + 1] = argv[j]; | ||
| 828 | argv = new; | ||
| 829 | argc++; | ||
| 830 | } | ||
| 831 | /* Change --display to -d, when its arg is separate. */ | ||
| 832 | else if (displayname != 0 && skip_args > count_before | ||
| 833 | && argv[count_before + 1][1] == '-') | ||
| 834 | argv[count_before + 1] = "-d"; | ||
| 835 | |||
| 836 | /* Don't actually discard this arg. */ | ||
| 837 | skip_args = count_before; | ||
| 838 | } | ||
| 839 | #endif | ||
| 840 | |||
| 841 | if (! noninteractive) | 806 | if (! noninteractive) |
| 842 | { | 807 | { |
| 843 | #ifdef BSD_PGRPS | 808 | #ifdef BSD_PGRPS |
| @@ -1037,6 +1002,66 @@ the Bugs section of the Emacs manual or the file BUGS.\n", argv[0]); | |||
| 1037 | } | 1002 | } |
| 1038 | } | 1003 | } |
| 1039 | 1004 | ||
| 1005 | no_loadup | ||
| 1006 | = !argmatch (argv, argc, "-nl", "--no-loadup", 6, NULL, &skip_args); | ||
| 1007 | |||
| 1008 | |||
| 1009 | #ifdef HAVE_X_WINDOWS | ||
| 1010 | /* Stupid kludge to catch command-line display spec. We can't | ||
| 1011 | handle this argument entirely in window system dependent code | ||
| 1012 | because we don't even know which window system dependent code | ||
| 1013 | to run until we've recognized this argument. */ | ||
| 1014 | { | ||
| 1015 | char *displayname = 0; | ||
| 1016 | int i; | ||
| 1017 | int count_before = skip_args; | ||
| 1018 | |||
| 1019 | /* Skip any number of -d options, but only use the last one. */ | ||
| 1020 | while (1) | ||
| 1021 | { | ||
| 1022 | int count_before_this = skip_args; | ||
| 1023 | |||
| 1024 | if (argmatch (argv, argc, "-d", "--display", 3, &displayname, &skip_args)) | ||
| 1025 | display_arg = 1; | ||
| 1026 | else if (argmatch (argv, argc, "-display", 0, 3, &displayname, &skip_args)) | ||
| 1027 | display_arg = 1; | ||
| 1028 | else | ||
| 1029 | break; | ||
| 1030 | |||
| 1031 | count_before = count_before_this; | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | /* If we have the form --display=NAME, | ||
| 1035 | convert it into -d name. | ||
| 1036 | This requires inserting a new element into argv. */ | ||
| 1037 | if (displayname != 0 && skip_args - count_before == 1) | ||
| 1038 | { | ||
| 1039 | char **new = (char **) xmalloc (sizeof (char *) * (argc + 2)); | ||
| 1040 | int j; | ||
| 1041 | |||
| 1042 | for (j = 0; j < count_before + 1; j++) | ||
| 1043 | new[j] = argv[j]; | ||
| 1044 | new[count_before + 1] = "-d"; | ||
| 1045 | new[count_before + 2] = displayname; | ||
| 1046 | for (j = count_before + 2; j <argc; j++) | ||
| 1047 | new[j + 1] = argv[j]; | ||
| 1048 | argv = new; | ||
| 1049 | argc++; | ||
| 1050 | } | ||
| 1051 | /* Change --display to -d, when its arg is separate. */ | ||
| 1052 | else if (displayname != 0 && skip_args > count_before | ||
| 1053 | && argv[count_before + 1][1] == '-') | ||
| 1054 | argv[count_before + 1] = "-d"; | ||
| 1055 | |||
| 1056 | /* Don't actually discard this arg. */ | ||
| 1057 | skip_args = count_before; | ||
| 1058 | } | ||
| 1059 | #endif | ||
| 1060 | |||
| 1061 | /* argmatch must not be used after here, | ||
| 1062 | except when bulding temacs | ||
| 1063 | because the -d argument has not been skipped in skip_args. */ | ||
| 1064 | |||
| 1040 | #ifdef MSDOS | 1065 | #ifdef MSDOS |
| 1041 | /* Call early 'cause init_environment needs it. */ | 1066 | /* Call early 'cause init_environment needs it. */ |
| 1042 | init_dosfns (); | 1067 | init_dosfns (); |
| @@ -1219,7 +1244,7 @@ the Bugs section of the Emacs manual or the file BUGS.\n", argv[0]); | |||
| 1219 | Fcons (build_string (file), Qnil)); | 1244 | Fcons (build_string (file), Qnil)); |
| 1220 | #ifdef CANNOT_DUMP | 1245 | #ifdef CANNOT_DUMP |
| 1221 | /* Unless next switch is -nl, load "loadup.el" first thing. */ | 1246 | /* Unless next switch is -nl, load "loadup.el" first thing. */ |
| 1222 | if (!argmatch (argv, argc, "-nl", "--no-loadup", 6, NULL, &skip_args)) | 1247 | if (! no_loadup) |
| 1223 | Vtop_level = Fcons (intern ("load"), | 1248 | Vtop_level = Fcons (intern ("load"), |
| 1224 | Fcons (build_string ("loadup.el"), Qnil)); | 1249 | Fcons (build_string ("loadup.el"), Qnil)); |
| 1225 | #endif /* CANNOT_DUMP */ | 1250 | #endif /* CANNOT_DUMP */ |
| @@ -1310,15 +1335,16 @@ struct standard_args standard_args[] = | |||
| 1310 | { "-nw", "--no-windows", 110, 0 }, | 1335 | { "-nw", "--no-windows", 110, 0 }, |
| 1311 | { "-batch", "--batch", 100, 0 }, | 1336 | { "-batch", "--batch", 100, 0 }, |
| 1312 | { "-help", "--help", 90, 0 }, | 1337 | { "-help", "--help", 90, 0 }, |
| 1313 | { "-d", "--display", 80, 1 }, | 1338 | { "-no-unibyte", "--no-unibyte", 83, 0 }, |
| 1314 | { "-display", 0, 80, 1 }, | 1339 | { "-multibyte", "--multibyte", 82, 0 }, |
| 1315 | { "-no-unibyte", "--no-unibyte", 71, 0 }, | 1340 | { "-unibyte", "--unibyte", 81, 0 }, |
| 1316 | { "-multibyte", "--multibyte", 71, 0 }, | 1341 | { "-no-multibyte", "--no-multibyte", 80, 0 }, |
| 1317 | { "-unibyte", "--unibyte", 70, 0 }, | ||
| 1318 | { "-no-multibyte", "--no-multibyte", 70, 0 }, | ||
| 1319 | #ifdef CANNOT_DUMP | 1342 | #ifdef CANNOT_DUMP |
| 1320 | { "-nl", "--no-loadup", 60, 0 }, | 1343 | { "-nl", "--no-loadup", 70, 0 }, |
| 1321 | #endif | 1344 | #endif |
| 1345 | /* -d must come last before the options handled in startup.el. */ | ||
| 1346 | { "-d", "--display", 60, 1 }, | ||
| 1347 | { "-display", 0, 60, 1 }, | ||
| 1322 | /* Now for the options handled in startup.el. */ | 1348 | /* Now for the options handled in startup.el. */ |
| 1323 | { "-q", "--no-init-file", 50, 0 }, | 1349 | { "-q", "--no-init-file", 50, 0 }, |
| 1324 | { "-no-init-file", 0, 50, 0 }, | 1350 | { "-no-init-file", 0, 50, 0 }, |
| @@ -1370,7 +1396,10 @@ struct standard_args standard_args[] = | |||
| 1370 | /* Reorder the elements of ARGV (assumed to have ARGC elements) | 1396 | /* Reorder the elements of ARGV (assumed to have ARGC elements) |
| 1371 | so that the highest priority ones come first. | 1397 | so that the highest priority ones come first. |
| 1372 | Do not change the order of elements of equal priority. | 1398 | Do not change the order of elements of equal priority. |
| 1373 | If an option takes an argument, keep it and its argument together. */ | 1399 | If an option takes an argument, keep it and its argument together. |
| 1400 | |||
| 1401 | If an option that takes no argument appears more | ||
| 1402 | than once, eliminate all but one copy of it. */ | ||
| 1374 | 1403 | ||
| 1375 | static void | 1404 | static void |
| 1376 | sort_args (argc, argv) | 1405 | sort_args (argc, argv) |
| @@ -1386,6 +1415,7 @@ sort_args (argc, argv) | |||
| 1386 | int *options = (int *) xmalloc (sizeof (int) * argc); | 1415 | int *options = (int *) xmalloc (sizeof (int) * argc); |
| 1387 | int *priority = (int *) xmalloc (sizeof (int) * argc); | 1416 | int *priority = (int *) xmalloc (sizeof (int) * argc); |
| 1388 | int to = 1; | 1417 | int to = 1; |
| 1418 | int incoming_used = 1; | ||
| 1389 | int from; | 1419 | int from; |
| 1390 | int i; | 1420 | int i; |
| 1391 | int end_of_options = argc; | 1421 | int end_of_options = argc; |
| @@ -1469,7 +1499,7 @@ sort_args (argc, argv) | |||
| 1469 | 1499 | ||
| 1470 | /* Copy the arguments, in order of decreasing priority, to NEW. */ | 1500 | /* Copy the arguments, in order of decreasing priority, to NEW. */ |
| 1471 | new[0] = argv[0]; | 1501 | new[0] = argv[0]; |
| 1472 | while (to < argc) | 1502 | while (incoming_used < argc) |
| 1473 | { | 1503 | { |
| 1474 | int best = -1; | 1504 | int best = -1; |
| 1475 | int best_priority = -9999; | 1505 | int best_priority = -9999; |
| @@ -1491,10 +1521,17 @@ sort_args (argc, argv) | |||
| 1491 | if (best < 0) | 1521 | if (best < 0) |
| 1492 | abort (); | 1522 | abort (); |
| 1493 | 1523 | ||
| 1494 | /* Copy the highest priority remaining option, with its args, to NEW. */ | 1524 | /* Copy the highest priority remaining option, with its args, to NEW. |
| 1495 | new[to++] = argv[best]; | 1525 | Unless it is a duplicate of the previous one. */ |
| 1496 | for (i = 0; i < options[best]; i++) | 1526 | if (! (options[best] == 0 |
| 1497 | new[to++] = argv[best + i + 1]; | 1527 | && ! strcmp (new[to - 1], argv[best]))) |
| 1528 | { | ||
| 1529 | new[to++] = argv[best]; | ||
| 1530 | for (i = 0; i < options[best]; i++) | ||
| 1531 | new[to++] = argv[best + i + 1]; | ||
| 1532 | } | ||
| 1533 | |||
| 1534 | incoming_used += 1 + (options[best] > 0 ? options[best] : 0); | ||
| 1498 | 1535 | ||
| 1499 | /* Clear out this option in ARGV. */ | 1536 | /* Clear out this option in ARGV. */ |
| 1500 | argv[best] = 0; | 1537 | argv[best] = 0; |