diff options
| author | Richard M. Stallman | 1996-09-02 00:05:56 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-09-02 00:05:56 +0000 |
| commit | 5212210c8f8708e4e565745bf19bc480cbcfaaac (patch) | |
| tree | 0b79584f8c15af9b9036c01176d1c69d45084936 | |
| parent | 349e3f8210c75471e2c30c351827608c7b0242be (diff) | |
| download | emacs-5212210c8f8708e4e565745bf19bc480cbcfaaac.tar.gz emacs-5212210c8f8708e4e565745bf19bc480cbcfaaac.zip | |
(quote_file_name): New function.
(main, both versions): Use quote_file_name.
(decode_options): Don't return a value.
(main, both versions): Use optind.
Don't check for -nowait here.
| -rw-r--r-- | lib-src/emacsclient.c | 99 |
1 files changed, 58 insertions, 41 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 20ba5217a5f..12c6b66040c 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -56,9 +56,9 @@ struct option longopts[] = | |||
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | /* Decode the options from argv and argc. | 58 | /* Decode the options from argv and argc. |
| 59 | Return the number of remaining arguments. */ | 59 | The global variable `optind' will say how many arguments we used up. */ |
| 60 | 60 | ||
| 61 | int | 61 | void |
| 62 | decode_options (argc, argv) | 62 | decode_options (argc, argv) |
| 63 | int argc; | 63 | int argc; |
| 64 | char **argv; | 64 | char **argv; |
| @@ -92,8 +92,6 @@ decode_options (argc, argv) | |||
| 92 | print_help_and_exit (); | 92 | print_help_and_exit (); |
| 93 | } | 93 | } |
| 94 | } | 94 | } |
| 95 | |||
| 96 | return argc; | ||
| 97 | } | 95 | } |
| 98 | 96 | ||
| 99 | print_help_and_exit () | 97 | print_help_and_exit () |
| @@ -105,6 +103,39 @@ print_help_and_exit () | |||
| 105 | "Report bugs to bug-gnu-emacs@prep.ai.mit.edu.\n"); | 103 | "Report bugs to bug-gnu-emacs@prep.ai.mit.edu.\n"); |
| 106 | exit (1); | 104 | exit (1); |
| 107 | } | 105 | } |
| 106 | |||
| 107 | /* Return a copy of NAME, inserting a \ | ||
| 108 | before each \, each -, and each space. | ||
| 109 | Change spaces to underscores, too, so that the | ||
| 110 | return value never contains a space. */ | ||
| 111 | |||
| 112 | char * | ||
| 113 | quote_file_name (name) | ||
| 114 | char *name; | ||
| 115 | { | ||
| 116 | char *copy = (char *) malloc (strlen (name) * 2 + 1); | ||
| 117 | char *p, *q; | ||
| 118 | |||
| 119 | p = name; | ||
| 120 | q = copy; | ||
| 121 | while (*p) | ||
| 122 | { | ||
| 123 | if (*p == ' ') | ||
| 124 | { | ||
| 125 | *q++ = '\\'; | ||
| 126 | *q++ = '_'; | ||
| 127 | p++; | ||
| 128 | } | ||
| 129 | else | ||
| 130 | { | ||
| 131 | if (*p == '\\' || *p == '-') | ||
| 132 | *q++ = '\\'; | ||
| 133 | *q++ = *p++; | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | return copy; | ||
| 138 | } | ||
| 108 | 139 | ||
| 109 | #if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC) | 140 | #if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC) |
| 110 | 141 | ||
| @@ -143,18 +174,13 @@ main (argc, argv) | |||
| 143 | struct sockaddr_un server; | 174 | struct sockaddr_un server; |
| 144 | char *homedir, *cwd, *str; | 175 | char *homedir, *cwd, *str; |
| 145 | char string[BUFSIZ]; | 176 | char string[BUFSIZ]; |
| 146 | int args_left; | ||
| 147 | 177 | ||
| 148 | progname = argv[0]; | 178 | progname = argv[0]; |
| 149 | 179 | ||
| 150 | /* Process options. */ | 180 | /* Process options. */ |
| 151 | args_left = decode_options (argc, argv); | 181 | decode_options (argc, argv); |
| 152 | 182 | ||
| 153 | /* Advance argv and decrement argc for the options that were skipped. */ | 183 | if (argc - optind < 1) |
| 154 | argv += argc - args_left; | ||
| 155 | argc = args_left; | ||
| 156 | |||
| 157 | if (argc < 2) | ||
| 158 | print_help_and_exit (); | 184 | print_help_and_exit (); |
| 159 | 185 | ||
| 160 | /* | 186 | /* |
| @@ -244,19 +270,11 @@ main (argc, argv) | |||
| 244 | exit (1); | 270 | exit (1); |
| 245 | } | 271 | } |
| 246 | 272 | ||
| 247 | for (i = 1; i < argc; i++) | 273 | if (nowait) |
| 248 | { | 274 | fprintf (out, "-nowait "); |
| 249 | /* If -nowait or --nowait option is used, | ||
| 250 | report it to the server. */ | ||
| 251 | if (!strcmp (argv[i], "-nowait") | ||
| 252 | || (!strncmp (argv[i], "--nowait", strlen (argv[i])) | ||
| 253 | && strlen (argv[i]) >= 3)) | ||
| 254 | { | ||
| 255 | fprintf (out, "-nowait "); | ||
| 256 | nowait = 1; | ||
| 257 | continue; | ||
| 258 | } | ||
| 259 | 275 | ||
| 276 | for (i = optind; i < argc; i++) | ||
| 277 | { | ||
| 260 | if (*argv[i] == '+') | 278 | if (*argv[i] == '+') |
| 261 | { | 279 | { |
| 262 | char *p = argv[i] + 1; | 280 | char *p = argv[i] + 1; |
| @@ -266,7 +284,8 @@ main (argc, argv) | |||
| 266 | } | 284 | } |
| 267 | else if (*argv[i] != '/') | 285 | else if (*argv[i] != '/') |
| 268 | fprintf (out, "%s/", cwd); | 286 | fprintf (out, "%s/", cwd); |
| 269 | fprintf (out, "%s ", argv[i]); | 287 | |
| 288 | fprintf (out, "%s ", quote_file_name (argv[i])); | ||
| 270 | } | 289 | } |
| 271 | fprintf (out, "\n"); | 290 | fprintf (out, "\n"); |
| 272 | fflush (out); | 291 | fflush (out); |
| @@ -321,13 +340,9 @@ main (argc, argv) | |||
| 321 | progname = argv[0]; | 340 | progname = argv[0]; |
| 322 | 341 | ||
| 323 | /* Process options. */ | 342 | /* Process options. */ |
| 324 | args_left = decode_options (argc, argv); | 343 | decode_options (argc, argv); |
| 325 | |||
| 326 | /* Advance argv and decrement argc for the options that were skipped. */ | ||
| 327 | argv += argc - args_left; | ||
| 328 | argc = args_left; | ||
| 329 | 344 | ||
| 330 | if (argc < 2) | 345 | if (argc - optind < 1) |
| 331 | print_help_and_exit (); | 346 | print_help_and_exit (); |
| 332 | 347 | ||
| 333 | /* | 348 | /* |
| @@ -381,22 +396,22 @@ main (argc, argv) | |||
| 381 | 396 | ||
| 382 | msgp->mtext[0] = 0; | 397 | msgp->mtext[0] = 0; |
| 383 | used = 0; | 398 | used = 0; |
| 384 | argc--; argv++; | 399 | |
| 400 | if (nowait) | ||
| 401 | { | ||
| 402 | strcat (msgp->mtext, "-nowait "); | ||
| 403 | used += 8; | ||
| 404 | } | ||
| 405 | |||
| 406 | argc -= optind; | ||
| 407 | argv += optind; | ||
| 408 | |||
| 385 | while (argc) | 409 | while (argc) |
| 386 | { | 410 | { |
| 387 | int need_cwd = 0; | 411 | int need_cwd = 0; |
| 388 | char *modified_arg = argv[0]; | 412 | char *modified_arg = argv[0]; |
| 389 | 413 | ||
| 390 | /* If -nowait or --nowait option is used, | 414 | if (*modified_arg == '+') |
| 391 | report it to the server. */ | ||
| 392 | if (!strcmp (modified_arg, "-nowait") | ||
| 393 | || (!strncmp (modified_arg, "--nowait", strlen (modified_arg)) | ||
| 394 | && strlen (modified_arg) >= 3)) | ||
| 395 | { | ||
| 396 | modified_arg = "-nowait"; | ||
| 397 | nowait = 1; | ||
| 398 | } | ||
| 399 | else if (*modified_arg == '+') | ||
| 400 | { | 415 | { |
| 401 | char *p = modified_arg + 1; | 416 | char *p = modified_arg + 1; |
| 402 | while (*p >= '0' && *p <= '9') p++; | 417 | while (*p >= '0' && *p <= '9') p++; |
| @@ -406,6 +421,8 @@ main (argc, argv) | |||
| 406 | else if (*modified_arg != '/') | 421 | else if (*modified_arg != '/') |
| 407 | need_cwd = 1; | 422 | need_cwd = 1; |
| 408 | 423 | ||
| 424 | modified_arg = quote_file_name (modified_arg); | ||
| 425 | |||
| 409 | if (need_cwd) | 426 | if (need_cwd) |
| 410 | used += strlen (cwd); | 427 | used += strlen (cwd); |
| 411 | used += strlen (modified_arg) + 1; | 428 | used += strlen (modified_arg) + 1; |