diff options
| author | Richard M. Stallman | 1994-11-19 20:45:17 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-11-19 20:45:17 +0000 |
| commit | 081bef73a23a1107958a84321fff74359692e229 (patch) | |
| tree | 9ec02b6367d17b7c961da1d09d61a9da15de914d /src | |
| parent | 3f53ddd000f8fa5363fc31f30e0ce36dd9ad9adb (diff) | |
| download | emacs-081bef73a23a1107958a84321fff74359692e229.tar.gz emacs-081bef73a23a1107958a84321fff74359692e229.zip | |
(sort_args): New function.
(main): Call sort_args.
Check for -d/-display after -nw, -batch, -help.
Accept --display, with arg attached or separate.
Diffstat (limited to 'src')
| -rw-r--r-- | src/emacs.c | 237 |
1 files changed, 221 insertions, 16 deletions
diff --git a/src/emacs.c b/src/emacs.c index 2e9a81a9091..bfc83b87087 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -136,6 +136,8 @@ int noninteractive1; | |||
| 136 | /* Save argv and argc. */ | 136 | /* Save argv and argc. */ |
| 137 | char **initial_argv; | 137 | char **initial_argv; |
| 138 | int initial_argc; | 138 | int initial_argc; |
| 139 | |||
| 140 | static void sort_args (); | ||
| 139 | 141 | ||
| 140 | /* Signal code for the fatal signal that was received */ | 142 | /* Signal code for the fatal signal that was received */ |
| 141 | int fatal_error_code; | 143 | int fatal_error_code; |
| @@ -341,6 +343,7 @@ __main () | |||
| 341 | 343 | ||
| 342 | Too bad we can't just use getopt for all of this, but we don't have | 344 | Too bad we can't just use getopt for all of this, but we don't have |
| 343 | enough information to do it right. */ | 345 | enough information to do it right. */ |
| 346 | |||
| 344 | static int | 347 | static int |
| 345 | argmatch (argv, sstr, lstr, minlen, valptr, skipptr) | 348 | argmatch (argv, sstr, lstr, minlen, valptr, skipptr) |
| 346 | char **argv; | 349 | char **argv; |
| @@ -404,6 +407,8 @@ main (argc, argv, envp) | |||
| 404 | extern int errno; | 407 | extern int errno; |
| 405 | extern sys_nerr; | 408 | extern sys_nerr; |
| 406 | 409 | ||
| 410 | sort_args (argc, argv); | ||
| 411 | |||
| 407 | /* Map in shared memory, if we are using that. */ | 412 | /* Map in shared memory, if we are using that. */ |
| 408 | #ifdef HAVE_SHM | 413 | #ifdef HAVE_SHM |
| 409 | if (argmatch (argv, "-nl", "--no-shared-memory", 6, NULL, &skip_args)) | 414 | if (argmatch (argv, "-nl", "--no-shared-memory", 6, NULL, &skip_args)) |
| @@ -429,22 +434,6 @@ main (argc, argv, envp) | |||
| 429 | printf ("malloc jumpstart failed!\n"); | 434 | printf ("malloc jumpstart failed!\n"); |
| 430 | #endif /* NeXT */ | 435 | #endif /* NeXT */ |
| 431 | 436 | ||
| 432 | #ifdef HAVE_X_WINDOWS | ||
| 433 | /* Stupid kludge to catch command-line display spec. We can't | ||
| 434 | handle this argument entirely in window system dependent code | ||
| 435 | because we don't even know which window system dependent code | ||
| 436 | to run until we've recognized this argument. */ | ||
| 437 | { | ||
| 438 | int i; | ||
| 439 | |||
| 440 | /* We don't check for a long option --display here, since the X code | ||
| 441 | won't be able to recognize that form anyway. */ | ||
| 442 | for (i = 1; (i < argc && ! display_arg); i++) | ||
| 443 | if (!strcmp (argv[i], "-d") || !strcmp (argv[i], "-display")) | ||
| 444 | display_arg = 1; | ||
| 445 | } | ||
| 446 | #endif | ||
| 447 | |||
| 448 | #ifdef VMS | 437 | #ifdef VMS |
| 449 | /* If -map specified, map the data file in */ | 438 | /* If -map specified, map the data file in */ |
| 450 | { | 439 | { |
| @@ -572,6 +561,46 @@ Usage: %s [-t term] [--terminal term] [-nw] [--no-windows] [--batch]\n\ | |||
| 572 | exit (0); | 561 | exit (0); |
| 573 | } | 562 | } |
| 574 | 563 | ||
| 564 | #ifdef HAVE_X_WINDOWS | ||
| 565 | /* Stupid kludge to catch command-line display spec. We can't | ||
| 566 | handle this argument entirely in window system dependent code | ||
| 567 | because we don't even know which window system dependent code | ||
| 568 | to run until we've recognized this argument. */ | ||
| 569 | { | ||
| 570 | char *displayname; | ||
| 571 | int i; | ||
| 572 | int count_before = skip_args; | ||
| 573 | |||
| 574 | if (argmatch (argv, "-d", "--display", 3, &displayname, &skip_args)) | ||
| 575 | display_arg = 1; | ||
| 576 | else if (argmatch (argv, "-display", 0, 3, &displayname, &skip_args)) | ||
| 577 | display_arg = 1; | ||
| 578 | |||
| 579 | /* If we have the form --display=NAME, | ||
| 580 | convert it into -d name. | ||
| 581 | This requires inserting a new element into argv. */ | ||
| 582 | if (displayname != 0 && skip_args - count_before == 1) | ||
| 583 | { | ||
| 584 | char **new = (char **) xmalloc (sizeof (char *) * (argc + 2)); | ||
| 585 | int j; | ||
| 586 | |||
| 587 | for (j = 0; j < count_before + 1; j++) | ||
| 588 | new[j] = argv[j]; | ||
| 589 | new[count_before + 1] = "-d"; | ||
| 590 | new[count_before + 2] = displayname; | ||
| 591 | for (j = count_before + 2; j <argc; j++) | ||
| 592 | new[j + 1] = argv[j]; | ||
| 593 | argv = new; | ||
| 594 | argc++; | ||
| 595 | } | ||
| 596 | else if (displayname != 0 && argv[count_before + 1][1] == '-') | ||
| 597 | argv[count_before] = "-d"; | ||
| 598 | |||
| 599 | /* Don't actually discard this arg. */ | ||
| 600 | skip_args = count_before; | ||
| 601 | } | ||
| 602 | #endif | ||
| 603 | |||
| 575 | if (! noninteractive) | 604 | if (! noninteractive) |
| 576 | { | 605 | { |
| 577 | #ifdef BSD_PGRPS | 606 | #ifdef BSD_PGRPS |
| @@ -852,6 +881,182 @@ Usage: %s [-t term] [--terminal term] [-nw] [--no-windows] [--batch]\n\ | |||
| 852 | /* NOTREACHED */ | 881 | /* NOTREACHED */ |
| 853 | } | 882 | } |
| 854 | 883 | ||
| 884 | /* Sort the args so we can find the most important ones | ||
| 885 | at the beginning of argv. */ | ||
| 886 | |||
| 887 | /* First, here's a table of all the standard options. */ | ||
| 888 | |||
| 889 | struct standard_args | ||
| 890 | { | ||
| 891 | char *name; | ||
| 892 | char *longname; | ||
| 893 | int priority; | ||
| 894 | int nargs; | ||
| 895 | }; | ||
| 896 | |||
| 897 | struct standard_args standard_args[] = | ||
| 898 | { | ||
| 899 | { "-nl", "--no-shared-memory", 100, 0 }, | ||
| 900 | { "-map", "--map-data", 100, 0 }, | ||
| 901 | { "-t", "--terminal", 90, 1 }, | ||
| 902 | { "-d", "--display", 80, 1 }, | ||
| 903 | { "-display", 0, 80, 1 }, | ||
| 904 | { "-nw", "--no-windows", 70, 0 }, | ||
| 905 | { "-batch", "--batch", 60, 0 }, | ||
| 906 | { "-q", "--no-init-file", 50, 0 }, | ||
| 907 | { "-no-init-file", 0, 50, 0 }, | ||
| 908 | { "-no-site-file", "--no-site-file", 40, 0 }, | ||
| 909 | { "-u", "--user", 30, 1 }, | ||
| 910 | { "-user", 0, 30, 1 }, | ||
| 911 | { "-debug-init", "--debug-init", 20, 0 }, | ||
| 912 | { "-l", "--load", 10, 1 }, | ||
| 913 | { "-load", 0, 10, 1 }, | ||
| 914 | { "-f", "--funcall", 10, 1 }, | ||
| 915 | { "-funcall", 0, 10, 1 }, | ||
| 916 | { "-insert", "--insert", 10, 1 }, | ||
| 917 | { "-bg", "--background-color", 10, 1 }, | ||
| 918 | { "-background", 0, 10, 1 }, | ||
| 919 | { "-fg", "--foreground-color", 10, 1 }, | ||
| 920 | { "-foreground", 0, 10, 1 }, | ||
| 921 | { "-bd", "--border-color", 10, 1 }, | ||
| 922 | { "-bw", "--border-width", 10, 1 }, | ||
| 923 | { "-ib", "--internal-border", 10, 1 }, | ||
| 924 | { "-ms", "--mouse-color", 10, 1 }, | ||
| 925 | { "-cr", "--cursor-color", 10, 1 }, | ||
| 926 | { "-fn", "--font", 10, 1 }, | ||
| 927 | { "-font", 0, 10, 1 }, | ||
| 928 | { "-g", "--geometry", 10, 1 }, | ||
| 929 | { "-geometry", 0, 10, 1 }, | ||
| 930 | { "-T", "--title", 10, 1 }, | ||
| 931 | { "-i", "--icon-type", 10, 1 }, | ||
| 932 | { "-itype", 0, 10, 1 }, | ||
| 933 | { "-name", "--name", 10, 1 }, | ||
| 934 | { "-xrm", "--xrm", 10, 1 }, | ||
| 935 | { "-r", "--reverse-video", 0, 0 }, | ||
| 936 | { "-rv", 0, 0, 0 }, | ||
| 937 | { "-reverse", 0, 0, 0 }, | ||
| 938 | { "-vb", "--vertical-scroll-bars", 0, 0 }, | ||
| 939 | { "-iconic", "--iconic", 0, 0 }, | ||
| 940 | { "-kill", "--kill", 0, 0 }, | ||
| 941 | }; | ||
| 942 | |||
| 943 | /* Reorder the elements of ARGV (assumed to have ARGC elements) | ||
| 944 | so that the highest priority ones come first. | ||
| 945 | Do not change the order of elements of equal priority. | ||
| 946 | If an option takes an argument, keep it and its argument together. */ | ||
| 947 | |||
| 948 | static void | ||
| 949 | sort_args (argc, argv) | ||
| 950 | int argc; | ||
| 951 | char **argv; | ||
| 952 | { | ||
| 953 | char **new = (char **) xmalloc (sizeof (char *) * argc); | ||
| 954 | /* For each element of argv, | ||
| 955 | the corresponding element of options is: | ||
| 956 | 0 for an option that takes no arguments, | ||
| 957 | 1 for an option that takes one argument, etc. | ||
| 958 | -1 for an ordinary non-option argument. */ | ||
| 959 | char *options = (char *) xmalloc (argc); | ||
| 960 | int *priority = (int *) xmalloc (sizeof (int) * argc); | ||
| 961 | int to = 1; | ||
| 962 | int from; | ||
| 963 | int i; | ||
| 964 | |||
| 965 | /* Categorize all the options, | ||
| 966 | and figure out which argv elts are option arguments. */ | ||
| 967 | for (from = 1; from < argc; from++) | ||
| 968 | { | ||
| 969 | options[from] = -1; | ||
| 970 | priority[from] = -1; | ||
| 971 | if (argv[from][0] == '-') | ||
| 972 | { | ||
| 973 | int match, thislen; | ||
| 974 | char *equals; | ||
| 975 | |||
| 976 | /* Look for a match with a known old-fashioned option. */ | ||
| 977 | for (i = 0; i < sizeof (standard_args) / sizeof (standard_args[0]); i++) | ||
| 978 | if (!strcmp (argv[from], standard_args[i].name)) | ||
| 979 | { | ||
| 980 | options[from] = standard_args[i].nargs; | ||
| 981 | priority[from] = standard_args[i].priority; | ||
| 982 | from += standard_args[i].nargs; | ||
| 983 | goto done; | ||
| 984 | } | ||
| 985 | |||
| 986 | /* Look for a match with a known long option. | ||
| 987 | MATCH is -1 if no match so far, -2 if two or more matches so far, | ||
| 988 | >= 0 (the table index of the match) if just one match so far. */ | ||
| 989 | if (argv[from][1] == '-') | ||
| 990 | { | ||
| 991 | match = -1; | ||
| 992 | thislen = strlen (argv[from]); | ||
| 993 | equals = index (argv[from], '='); | ||
| 994 | if (equals != 0) | ||
| 995 | thislen = equals - argv[from]; | ||
| 996 | |||
| 997 | for (i = 0; i < sizeof (standard_args) / sizeof (standard_args[0]); i++) | ||
| 998 | if (!strncmp (argv[from], standard_args[i].longname, thislen)) | ||
| 999 | { | ||
| 1000 | if (match == -1) | ||
| 1001 | match = i; | ||
| 1002 | else | ||
| 1003 | match = -2; | ||
| 1004 | } | ||
| 1005 | |||
| 1006 | /* If we found exactly one match, use that. */ | ||
| 1007 | if (match >= 0) | ||
| 1008 | { | ||
| 1009 | options[from] = standard_args[match].nargs; | ||
| 1010 | priority[from] = standard_args[match].priority; | ||
| 1011 | /* If --OPTION=VALUE syntax is used, | ||
| 1012 | this option uses just one argv element. */ | ||
| 1013 | if (equals != 0) | ||
| 1014 | options[from] = 0; | ||
| 1015 | from += options[from]; | ||
| 1016 | } | ||
| 1017 | } | ||
| 1018 | done: ; | ||
| 1019 | } | ||
| 1020 | } | ||
| 1021 | |||
| 1022 | /* Copy the arguments, in order of decreasing priority, to NEW. */ | ||
| 1023 | new[0] = argv[0]; | ||
| 1024 | while (to < argc) | ||
| 1025 | { | ||
| 1026 | int best = -1; | ||
| 1027 | int best_priority = -2; | ||
| 1028 | |||
| 1029 | /* Find the highest priority remaining option. | ||
| 1030 | If several have equal priority, take the first of them. */ | ||
| 1031 | for (from = 1; from < argc; from++) | ||
| 1032 | { | ||
| 1033 | if (argv[from] != 0 && priority[from] > best_priority) | ||
| 1034 | { | ||
| 1035 | best_priority = priority[from]; | ||
| 1036 | best = from; | ||
| 1037 | } | ||
| 1038 | /* Skip option arguments--they are tied to the options. */ | ||
| 1039 | if (options[from] > 0) | ||
| 1040 | from += options[from]; | ||
| 1041 | } | ||
| 1042 | |||
| 1043 | if (best < 0) | ||
| 1044 | abort (); | ||
| 1045 | |||
| 1046 | /* Copy the highest priority remaining option, with its args, to NEW. */ | ||
| 1047 | new[to++] = argv[best]; | ||
| 1048 | for (i = 0; i < options[best]; i++) | ||
| 1049 | new[to++] = argv[best + i + 1]; | ||
| 1050 | |||
| 1051 | /* Clear out this option in ARGV. */ | ||
| 1052 | argv[best] = 0; | ||
| 1053 | for (i = 0; i < options[best]; i++) | ||
| 1054 | argv[best + i + 1] = 0; | ||
| 1055 | } | ||
| 1056 | |||
| 1057 | bcopy (new, argv, sizeof (char *) * (argc + 1)); | ||
| 1058 | } | ||
| 1059 | |||
| 855 | DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P", | 1060 | DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P", |
| 856 | "Exit the Emacs job and kill it.\n\ | 1061 | "Exit the Emacs job and kill it.\n\ |
| 857 | If ARG is an integer, return ARG as the exit program code.\n\ | 1062 | If ARG is an integer, return ARG as the exit program code.\n\ |