# HG changeset patch # User Richard M. Stallman # Date 785277917 0 # Node ID fdc1155b891c428bb862af239b9eaa030058e383 # Parent 55f7d03ce918e53e9b78d7b5cf577d0adf18bcda (sort_args): New function. (main): Call sort_args. Check for -d/-display after -nw, -batch, -help. Accept --display, with arg attached or separate. diff -r 55f7d03ce918 -r fdc1155b891c src/emacs.c --- a/src/emacs.c Sat Nov 19 20:42:26 1994 +0000 +++ b/src/emacs.c Sat Nov 19 20:45:17 1994 +0000 @@ -136,6 +136,8 @@ /* Save argv and argc. */ char **initial_argv; int initial_argc; + +static void sort_args (); /* Signal code for the fatal signal that was received */ int fatal_error_code; @@ -341,6 +343,7 @@ Too bad we can't just use getopt for all of this, but we don't have enough information to do it right. */ + static int argmatch (argv, sstr, lstr, minlen, valptr, skipptr) char **argv; @@ -404,6 +407,8 @@ extern int errno; extern sys_nerr; + sort_args (argc, argv); + /* Map in shared memory, if we are using that. */ #ifdef HAVE_SHM if (argmatch (argv, "-nl", "--no-shared-memory", 6, NULL, &skip_args)) @@ -429,22 +434,6 @@ printf ("malloc jumpstart failed!\n"); #endif /* NeXT */ -#ifdef HAVE_X_WINDOWS - /* Stupid kludge to catch command-line display spec. We can't - handle this argument entirely in window system dependent code - because we don't even know which window system dependent code - to run until we've recognized this argument. */ - { - int i; - - /* We don't check for a long option --display here, since the X code - won't be able to recognize that form anyway. */ - for (i = 1; (i < argc && ! display_arg); i++) - if (!strcmp (argv[i], "-d") || !strcmp (argv[i], "-display")) - display_arg = 1; - } -#endif - #ifdef VMS /* If -map specified, map the data file in */ { @@ -572,6 +561,46 @@ exit (0); } +#ifdef HAVE_X_WINDOWS + /* Stupid kludge to catch command-line display spec. We can't + handle this argument entirely in window system dependent code + because we don't even know which window system dependent code + to run until we've recognized this argument. */ + { + char *displayname; + int i; + int count_before = skip_args; + + if (argmatch (argv, "-d", "--display", 3, &displayname, &skip_args)) + display_arg = 1; + else if (argmatch (argv, "-display", 0, 3, &displayname, &skip_args)) + display_arg = 1; + + /* If we have the form --display=NAME, + convert it into -d name. + This requires inserting a new element into argv. */ + if (displayname != 0 && skip_args - count_before == 1) + { + char **new = (char **) xmalloc (sizeof (char *) * (argc + 2)); + int j; + + for (j = 0; j < count_before + 1; j++) + new[j] = argv[j]; + new[count_before + 1] = "-d"; + new[count_before + 2] = displayname; + for (j = count_before + 2; j = 0 (the table index of the match) if just one match so far. */ + if (argv[from][1] == '-') + { + match = -1; + thislen = strlen (argv[from]); + equals = index (argv[from], '='); + if (equals != 0) + thislen = equals - argv[from]; + + for (i = 0; i < sizeof (standard_args) / sizeof (standard_args[0]); i++) + if (!strncmp (argv[from], standard_args[i].longname, thislen)) + { + if (match == -1) + match = i; + else + match = -2; + } + + /* If we found exactly one match, use that. */ + if (match >= 0) + { + options[from] = standard_args[match].nargs; + priority[from] = standard_args[match].priority; + /* If --OPTION=VALUE syntax is used, + this option uses just one argv element. */ + if (equals != 0) + options[from] = 0; + from += options[from]; + } + } + done: ; + } + } + + /* Copy the arguments, in order of decreasing priority, to NEW. */ + new[0] = argv[0]; + while (to < argc) + { + int best = -1; + int best_priority = -2; + + /* Find the highest priority remaining option. + If several have equal priority, take the first of them. */ + for (from = 1; from < argc; from++) + { + if (argv[from] != 0 && priority[from] > best_priority) + { + best_priority = priority[from]; + best = from; + } + /* Skip option arguments--they are tied to the options. */ + if (options[from] > 0) + from += options[from]; + } + + if (best < 0) + abort (); + + /* Copy the highest priority remaining option, with its args, to NEW. */ + new[to++] = argv[best]; + for (i = 0; i < options[best]; i++) + new[to++] = argv[best + i + 1]; + + /* Clear out this option in ARGV. */ + argv[best] = 0; + for (i = 0; i < options[best]; i++) + argv[best + i + 1] = 0; + } + + bcopy (new, argv, sizeof (char *) * (argc + 1)); +} + DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P", "Exit the Emacs job and kill it.\n\ If ARG is an integer, return ARG as the exit program code.\n\