diff options
| author | Reuben Thomas | 2017-08-07 21:58:55 +0100 |
|---|---|---|
| committer | Reuben Thomas | 2017-08-07 21:58:55 +0100 |
| commit | 89187e93d220ac5e2177c7c769ae6a0e9966d0f5 (patch) | |
| tree | 84122686488546bbdbb28410f4dc9cae37ce552e /lib-src | |
| parent | 28f1fe97daa13e13714e6c43c9a6fbb0c0e99a26 (diff) | |
| download | emacs-89187e93d220ac5e2177c7c769ae6a0e9966d0f5.tar.gz emacs-89187e93d220ac5e2177c7c769ae6a0e9966d0f5.zip | |
Revert "Add support for arguments in ALTERNATE_EDITOR to emacsclient"
This reverts commit 28f1fe97daa13e13714e6c43c9a6fbb0c0e99a26.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/emacsclient.c | 73 |
1 files changed, 18 insertions, 55 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 32b8c034ae7..f1d4e8976da 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -110,9 +110,6 @@ char *w32_getenv (const char *); | |||
| 110 | /* Name used to invoke this program. */ | 110 | /* Name used to invoke this program. */ |
| 111 | const char *progname; | 111 | const char *progname; |
| 112 | 112 | ||
| 113 | /* The first argument to main. */ | ||
| 114 | int main_argc; | ||
| 115 | |||
| 116 | /* The second argument to main. */ | 113 | /* The second argument to main. */ |
| 117 | char **main_argv; | 114 | char **main_argv; |
| 118 | 115 | ||
| @@ -204,35 +201,6 @@ xmalloc (size_t size) | |||
| 204 | return result; | 201 | return result; |
| 205 | } | 202 | } |
| 206 | 203 | ||
| 207 | /* Like realloc but get fatal error if memory is exhausted. */ | ||
| 208 | |||
| 209 | static void * | ||
| 210 | xrealloc (void *ptr, size_t size) | ||
| 211 | { | ||
| 212 | void *result = realloc (ptr, size); | ||
| 213 | if (result == NULL) | ||
| 214 | { | ||
| 215 | perror ("realloc"); | ||
| 216 | exit (EXIT_FAILURE); | ||
| 217 | } | ||
| 218 | return result; | ||
| 219 | } | ||
| 220 | |||
| 221 | /* Like strdup but get a fatal error if memory is exhausted. */ | ||
| 222 | char *xstrdup (const char *); | ||
| 223 | |||
| 224 | char * | ||
| 225 | xstrdup (const char *s) | ||
| 226 | { | ||
| 227 | char *result = strdup (s); | ||
| 228 | if (result == NULL) | ||
| 229 | { | ||
| 230 | perror ("strdup"); | ||
| 231 | exit (EXIT_FAILURE); | ||
| 232 | } | ||
| 233 | return result; | ||
| 234 | } | ||
| 235 | |||
| 236 | /* From sysdep.c */ | 204 | /* From sysdep.c */ |
| 237 | #if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME) | 205 | #if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME) |
| 238 | 206 | ||
| @@ -296,6 +264,21 @@ get_current_dir_name (void) | |||
| 296 | 264 | ||
| 297 | #ifdef WINDOWSNT | 265 | #ifdef WINDOWSNT |
| 298 | 266 | ||
| 267 | /* Like strdup but get a fatal error if memory is exhausted. */ | ||
| 268 | char *xstrdup (const char *); | ||
| 269 | |||
| 270 | char * | ||
| 271 | xstrdup (const char *s) | ||
| 272 | { | ||
| 273 | char *result = strdup (s); | ||
| 274 | if (result == NULL) | ||
| 275 | { | ||
| 276 | perror ("strdup"); | ||
| 277 | exit (EXIT_FAILURE); | ||
| 278 | } | ||
| 279 | return result; | ||
| 280 | } | ||
| 281 | |||
| 299 | #define REG_ROOT "SOFTWARE\\GNU\\Emacs" | 282 | #define REG_ROOT "SOFTWARE\\GNU\\Emacs" |
| 300 | 283 | ||
| 301 | char *w32_get_resource (HKEY, const char *, LPDWORD); | 284 | char *w32_get_resource (HKEY, const char *, LPDWORD); |
| @@ -690,7 +673,7 @@ Report bugs with M-x report-emacs-bug.\n"); | |||
| 690 | } | 673 | } |
| 691 | 674 | ||
| 692 | /* Try to run a different command, or --if no alternate editor is | 675 | /* Try to run a different command, or --if no alternate editor is |
| 693 | defined-- exit with an decoderde. | 676 | defined-- exit with an errorcode. |
| 694 | Uses argv, but gets it from the global variable main_argv. */ | 677 | Uses argv, but gets it from the global variable main_argv. */ |
| 695 | 678 | ||
| 696 | static _Noreturn void | 679 | static _Noreturn void |
| @@ -698,27 +681,9 @@ fail (void) | |||
| 698 | { | 681 | { |
| 699 | if (alternate_editor) | 682 | if (alternate_editor) |
| 700 | { | 683 | { |
| 701 | size_t extra_args_size = (main_argc - optind + 1) * sizeof (char *); | 684 | int i = optind - 1; |
| 702 | size_t new_argv_size = extra_args_size; | ||
| 703 | char **new_argv = NULL; | ||
| 704 | /* Needed because strtok overwrites its input. */ | ||
| 705 | char *s = xstrdup (alternate_editor); | ||
| 706 | unsigned toks = 0; | ||
| 707 | char *tok = strtok(s, " "); | ||
| 708 | |||
| 709 | /* Unpack alternate_editor's space-separated tokens into new_argv. */ | ||
| 710 | do | ||
| 711 | { | ||
| 712 | toks++; | ||
| 713 | new_argv = xrealloc (new_argv, new_argv_size + toks * sizeof (char *)); | ||
| 714 | new_argv[toks - 1] = tok; | ||
| 715 | } | ||
| 716 | while ((tok = strtok (NULL, " "))); | ||
| 717 | |||
| 718 | /* Append main_argv arguments to new_argv. */ | ||
| 719 | memcpy (&new_argv[toks], main_argv + optind, extra_args_size); | ||
| 720 | 685 | ||
| 721 | execvp (s, new_argv); | 686 | execvp (alternate_editor, main_argv + i); |
| 722 | message (true, "%s: error executing alternate editor \"%s\"\n", | 687 | message (true, "%s: error executing alternate editor \"%s\"\n", |
| 723 | progname, alternate_editor); | 688 | progname, alternate_editor); |
| 724 | } | 689 | } |
| @@ -731,7 +696,6 @@ fail (void) | |||
| 731 | int | 696 | int |
| 732 | main (int argc, char **argv) | 697 | main (int argc, char **argv) |
| 733 | { | 698 | { |
| 734 | main_argc = argc; | ||
| 735 | main_argv = argv; | 699 | main_argv = argv; |
| 736 | progname = argv[0]; | 700 | progname = argv[0]; |
| 737 | message (true, "%s: Sorry, the Emacs server is supported only\n" | 701 | message (true, "%s: Sorry, the Emacs server is supported only\n" |
| @@ -1665,7 +1629,6 @@ main (int argc, char **argv) | |||
| 1665 | int start_daemon_if_needed; | 1629 | int start_daemon_if_needed; |
| 1666 | int exit_status = EXIT_SUCCESS; | 1630 | int exit_status = EXIT_SUCCESS; |
| 1667 | 1631 | ||
| 1668 | main_argc = argc; | ||
| 1669 | main_argv = argv; | 1632 | main_argv = argv; |
| 1670 | progname = argv[0]; | 1633 | progname = argv[0]; |
| 1671 | 1634 | ||