diff options
| author | Gerd Moellmann | 2000-01-12 13:38:54 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-01-12 13:38:54 +0000 |
| commit | 97e3214d1d007713ea24f7fc2b81ea6994ef2d60 (patch) | |
| tree | e430e65a7958ba04b3ac234a2f573d4fa1b02a35 /lib-src | |
| parent | 99c6d63bb2f002da2a450dc6c1014c3e5fdc8577 (diff) | |
| download | emacs-97e3214d1d007713ea24f7fc2b81ea6994ef2d60.tar.gz emacs-97e3214d1d007713ea24f7fc2b81ea6994ef2d60.zip | |
Add option -a EDITOR and environment variable
ALTERNATE_EDITOR. Exec this editor if we fail to contact Emacs.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/emacsclient.c | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 11946ff2ec0..01ae0356797 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -52,9 +52,13 @@ struct option longopts[] = | |||
| 52 | { "no-wait", no_argument, NULL, 'n' }, | 52 | { "no-wait", no_argument, NULL, 'n' }, |
| 53 | { "help", no_argument, NULL, 'H' }, | 53 | { "help", no_argument, NULL, 'H' }, |
| 54 | { "version", no_argument, NULL, 'V' }, | 54 | { "version", no_argument, NULL, 'V' }, |
| 55 | { "alternate-editor",required_argument, NULL, 'a' }, | ||
| 55 | { 0 } | 56 | { 0 } |
| 56 | }; | 57 | }; |
| 57 | 58 | ||
| 59 | |||
| 60 | const char * alternate_editor = NULL; | ||
| 61 | |||
| 58 | /* Decode the options from argv and argc. | 62 | /* Decode the options from argv and argc. |
| 59 | The global variable `optind' will say how many arguments we used up. */ | 63 | The global variable `optind' will say how many arguments we used up. */ |
| 60 | 64 | ||
| @@ -66,18 +70,24 @@ decode_options (argc, argv) | |||
| 66 | while (1) | 70 | while (1) |
| 67 | { | 71 | { |
| 68 | int opt = getopt_long (argc, argv, | 72 | int opt = getopt_long (argc, argv, |
| 69 | "VHn", longopts, 0); | 73 | "VHna:", longopts, 0); |
| 70 | 74 | ||
| 71 | if (opt == EOF) | 75 | if (opt == EOF) |
| 72 | break; | 76 | break; |
| 73 | 77 | ||
| 78 | alternate_editor = getenv ("ALTERNATE_EDITOR"); | ||
| 79 | |||
| 74 | switch (opt) | 80 | switch (opt) |
| 75 | { | 81 | { |
| 76 | case 0: | 82 | case 0: |
| 77 | /* If getopt returns 0, then it has already processed a | 83 | /* If getopt returns 0, then it has already processed a |
| 78 | long-named option. We should do nothing. */ | 84 | long-named option. We should do nothing. */ |
| 79 | break; | 85 | break; |
| 80 | 86 | ||
| 87 | case 'a': | ||
| 88 | alternate_editor = optarg; | ||
| 89 | break; | ||
| 90 | |||
| 81 | case 'n': | 91 | case 'n': |
| 82 | nowait = 1; | 92 | nowait = 1; |
| 83 | break; | 93 | break; |
| @@ -98,7 +108,7 @@ void | |||
| 98 | print_help_and_exit () | 108 | print_help_and_exit () |
| 99 | { | 109 | { |
| 100 | fprintf (stderr, | 110 | fprintf (stderr, |
| 101 | "Usage: %s [-n] [--no-wait] [+LINENUMBER] FILENAME\n", | 111 | "Usage: %s [-a ALTERNATE-EDITOR] [-n] [--no-wait] [+LINENUMBER] FILENAME\n", |
| 102 | progname); | 112 | progname); |
| 103 | fprintf (stderr, | 113 | fprintf (stderr, |
| 104 | "Or %s --version\n", | 114 | "Or %s --version\n", |
| @@ -139,6 +149,7 @@ quote_file_name (name) | |||
| 139 | } | 149 | } |
| 140 | *q++ = 0; | 150 | *q++ = 0; |
| 141 | 151 | ||
| 152 | |||
| 142 | return copy; | 153 | return copy; |
| 143 | } | 154 | } |
| 144 | 155 | ||
| @@ -157,6 +168,28 @@ xmalloc (size) | |||
| 157 | return result; | 168 | return result; |
| 158 | } | 169 | } |
| 159 | 170 | ||
| 171 | /* | ||
| 172 | Try to run a different command, or --if no alternate editor is | ||
| 173 | defined-- exit with an errorcode. | ||
| 174 | */ | ||
| 175 | fail (argc, argv) | ||
| 176 | int argc; | ||
| 177 | char **argv; | ||
| 178 | { | ||
| 179 | if (alternate_editor) | ||
| 180 | { | ||
| 181 | int i = optind -1 ; | ||
| 182 | execvp (alternate_editor, argv + i); | ||
| 183 | } | ||
| 184 | else | ||
| 185 | { | ||
| 186 | exit (1); | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | |||
| 191 | |||
| 192 | |||
| 160 | #if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC) | 193 | #if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC) |
| 161 | 194 | ||
| 162 | main (argc, argv) | 195 | main (argc, argv) |
| @@ -166,7 +199,8 @@ main (argc, argv) | |||
| 166 | fprintf (stderr, "%s: Sorry, the Emacs server is supported only\n", | 199 | fprintf (stderr, "%s: Sorry, the Emacs server is supported only\n", |
| 167 | argv[0]); | 200 | argv[0]); |
| 168 | fprintf (stderr, "on systems with Berkeley sockets or System V IPC.\n"); | 201 | fprintf (stderr, "on systems with Berkeley sockets or System V IPC.\n"); |
| 169 | exit (1); | 202 | |
| 203 | fail (argc, argv); | ||
| 170 | } | 204 | } |
| 171 | 205 | ||
| 172 | #else /* HAVE_SOCKETS or HAVE_SYSVIPC */ | 206 | #else /* HAVE_SOCKETS or HAVE_SYSVIPC */ |
| @@ -212,8 +246,9 @@ main (argc, argv) | |||
| 212 | { | 246 | { |
| 213 | fprintf (stderr, "%s: ", argv[0]); | 247 | fprintf (stderr, "%s: ", argv[0]); |
| 214 | perror ("socket"); | 248 | perror ("socket"); |
| 215 | exit (1); | 249 | fail (argc, argv); |
| 216 | } | 250 | } |
| 251 | |||
| 217 | server.sun_family = AF_UNIX; | 252 | server.sun_family = AF_UNIX; |
| 218 | 253 | ||
| 219 | { | 254 | { |
| @@ -249,19 +284,19 @@ main (argc, argv) | |||
| 249 | else | 284 | else |
| 250 | fprintf (stderr, "%s: can't stat %s: %s\n", | 285 | fprintf (stderr, "%s: can't stat %s: %s\n", |
| 251 | argv[0], server.sun_path, strerror (errno)); | 286 | argv[0], server.sun_path, strerror (errno)); |
| 252 | exit (1); | 287 | fail (argc, argv); |
| 253 | } | 288 | } |
| 254 | if (statbfr.st_uid != geteuid ()) | 289 | if (statbfr.st_uid != geteuid ()) |
| 255 | { | 290 | { |
| 256 | fprintf (stderr, "%s: Invalid socket owner\n", argv[0]); | 291 | fprintf (stderr, "%s: Invalid socket owner\n", argv[0]); |
| 257 | exit (1); | 292 | fail (argc, argv); |
| 258 | } | 293 | } |
| 259 | } | 294 | } |
| 260 | #else | 295 | #else |
| 261 | if ((homedir = getenv ("HOME")) == NULL) | 296 | if ((homedir = getenv ("HOME")) == NULL) |
| 262 | { | 297 | { |
| 263 | fprintf (stderr, "%s: No home directory\n", argv[0]); | 298 | fprintf (stderr, "%s: No home directory\n", argv[0]); |
| 264 | exit (1); | 299 | fail (argc, argv); |
| 265 | } | 300 | } |
| 266 | strcpy (server.sun_path, homedir); | 301 | strcpy (server.sun_path, homedir); |
| 267 | strcat (server.sun_path, "/.emacs-server-"); | 302 | strcat (server.sun_path, "/.emacs-server-"); |
| @@ -273,7 +308,7 @@ main (argc, argv) | |||
| 273 | { | 308 | { |
| 274 | fprintf (stderr, "%s: ", argv[0]); | 309 | fprintf (stderr, "%s: ", argv[0]); |
| 275 | perror ("connect"); | 310 | perror ("connect"); |
| 276 | exit (1); | 311 | fail (argc, argv); |
| 277 | } | 312 | } |
| 278 | 313 | ||
| 279 | /* We use the stream OUT to send our command to the server. */ | 314 | /* We use the stream OUT to send our command to the server. */ |
| @@ -281,7 +316,7 @@ main (argc, argv) | |||
| 281 | { | 316 | { |
| 282 | fprintf (stderr, "%s: ", argv[0]); | 317 | fprintf (stderr, "%s: ", argv[0]); |
| 283 | perror ("fdopen"); | 318 | perror ("fdopen"); |
| 284 | exit (1); | 319 | fail (argc, argv); |
| 285 | } | 320 | } |
| 286 | 321 | ||
| 287 | /* We use the stream IN to read the response. | 322 | /* We use the stream IN to read the response. |
| @@ -293,7 +328,7 @@ main (argc, argv) | |||
| 293 | { | 328 | { |
| 294 | fprintf (stderr, "%s: ", argv[0]); | 329 | fprintf (stderr, "%s: ", argv[0]); |
| 295 | perror ("fdopen"); | 330 | perror ("fdopen"); |
| 296 | exit (1); | 331 | fail (argc, argv); |
| 297 | } | 332 | } |
| 298 | 333 | ||
| 299 | #ifdef BSD_SYSTEM | 334 | #ifdef BSD_SYSTEM |
| @@ -311,7 +346,7 @@ main (argc, argv) | |||
| 311 | "Cannot get current working directory", | 346 | "Cannot get current working directory", |
| 312 | #endif | 347 | #endif |
| 313 | strerror (errno)); | 348 | strerror (errno)); |
| 314 | exit (1); | 349 | fail (argc, argv); |
| 315 | } | 350 | } |
| 316 | 351 | ||
| 317 | if (nowait) | 352 | if (nowait) |
| @@ -442,7 +477,7 @@ main (argc, argv) | |||
| 442 | fprintf (stderr, "%s: Cannot get current working directory: %s\n", | 477 | fprintf (stderr, "%s: Cannot get current working directory: %s\n", |
| 443 | argv[0], strerror (errno)); | 478 | argv[0], strerror (errno)); |
| 444 | #endif | 479 | #endif |
| 445 | exit (1); | 480 | fail (argc, argv); |
| 446 | } | 481 | } |
| 447 | 482 | ||
| 448 | msgp->mtext[0] = 0; | 483 | msgp->mtext[0] = 0; |
| @@ -498,7 +533,7 @@ main (argc, argv) | |||
| 498 | if (strlen (msgp->mtext) >= 512) | 533 | if (strlen (msgp->mtext) >= 512) |
| 499 | { | 534 | { |
| 500 | fprintf (stderr, "%s: args too long for msgsnd\n", progname); | 535 | fprintf (stderr, "%s: args too long for msgsnd\n", progname); |
| 501 | exit (1); | 536 | fail (argc, argv); |
| 502 | } | 537 | } |
| 503 | #endif | 538 | #endif |
| 504 | msgp->mtype = 1; | 539 | msgp->mtype = 1; |
| @@ -506,7 +541,7 @@ main (argc, argv) | |||
| 506 | { | 541 | { |
| 507 | fprintf (stderr, "%s: ", progname); | 542 | fprintf (stderr, "%s: ", progname); |
| 508 | perror ("msgsnd"); | 543 | perror ("msgsnd"); |
| 509 | exit (1); | 544 | fail (argc, argv); |
| 510 | } | 545 | } |
| 511 | 546 | ||
| 512 | /* Maybe wait for an answer. */ | 547 | /* Maybe wait for an answer. */ |