comparison lib-src/emacsclient.c @ 52635:9963e9da5850

(quote_file_name): Print the result instead of returning it. Fix the return type accordingly. (main): Under --eval, don't fail if left with additional arguments after decoding options. Quote file names.
author Eli Zaretskii <eliz@gnu.org>
date Sun, 28 Sep 2003 08:24:56 +0000
parents cd53bfef4ab1
children 5c74e66d6c36
comparison
equal deleted inserted replaced
52634:bb955cc088f9 52635:9963e9da5850
167 \n\ 167 \n\
168 Report bugs to bug-gnu-emacs@gnu.org.\n", progname); 168 Report bugs to bug-gnu-emacs@gnu.org.\n", progname);
169 exit (0); 169 exit (0);
170 } 170 }
171 171
172 /* Return a copy of NAME, inserting a & 172 /* Inserting a &
173 before each &, each space, each newline, and any initial -. 173 before each &, each space, each newline, and any initial -.
174 Change spaces to underscores, too, so that the 174 Change spaces to underscores, too, so that the
175 return value never contains a space. */ 175 return value never contains a space. */
176 176
177 char * 177 void
178 quote_file_name (name) 178 quote_file_name (name, stream)
179 char *name; 179 char *name;
180 FILE *stream;
180 { 181 {
181 char *copy = (char *) malloc (strlen (name) * 2 + 1); 182 char *copy = (char *) malloc (strlen (name) * 2 + 1);
182 char *p, *q; 183 char *p, *q;
183 184
184 p = name; 185 p = name;
204 *q++ = *p++; 205 *q++ = *p++;
205 } 206 }
206 } 207 }
207 *q++ = 0; 208 *q++ = 0;
208 209
209 return copy; 210 fprintf (stream, copy);
211
212 free (copy);
210 } 213 }
211 214
212 /* Like malloc but get fatal error if memory is exhausted. */ 215 /* Like malloc but get fatal error if memory is exhausted. */
213 216
214 long * 217 long *
308 progname = argv[0]; 311 progname = argv[0];
309 312
310 /* Process options. */ 313 /* Process options. */
311 decode_options (argc, argv); 314 decode_options (argc, argv);
312 315
313 if (argc - optind < 1) 316 if ((argc - optind < 1) && !eval)
314 { 317 {
315 fprintf (stderr, "%s: file name or argument required\n", progname); 318 fprintf (stderr, "%s: file name or argument required\n", progname);
316 fprintf (stderr, "Try `%s --help' for more information\n", progname); 319 fprintf (stderr, "Try `%s --help' for more information\n", progname);
317 exit (1); 320 exit (1);
318 } 321 }
474 477
475 if (eval) 478 if (eval)
476 fprintf (out, "-eval "); 479 fprintf (out, "-eval ");
477 480
478 if (display) 481 if (display)
479 fprintf (out, "-display %s ", quote_file_name (display)); 482 {
480 483 fprintf (out, "-display ");
481 for (i = optind; i < argc; i++) 484 quote_file_name (display, out);
482 { 485 fprintf (out, " ");
483 if (eval) 486 }
484 ; /* Don't prepend any cwd or anything like that. */ 487
485 else if (*argv[i] == '+') 488 if ((argc - optind > 0))
489 {
490 for (i = optind; i < argc; i++)
486 { 491 {
487 char *p = argv[i] + 1; 492 if (eval)
488 while (isdigit ((unsigned char) *p) || *p == ':') p++; 493 ; /* Don't prepend any cwd or anything like that. */
489 if (*p != 0) 494 else if (*argv[i] == '+')
490 fprintf (out, "%s/", quote_file_name (cwd)); 495 {
496 char *p = argv[i] + 1;
497 while (isdigit ((unsigned char) *p) || *p == ':') p++;
498 if (*p != 0)
499 {
500 quote_file_name (cwd, out);
501 fprintf (out, "/");
502 }
503 }
504 else if (*argv[i] != '/')
505 {
506 quote_file_name (cwd, out);
507 fprintf (out, "/");
508 }
509
510 quote_file_name (argv[i], out);
511 fprintf (out, " ");
491 } 512 }
492 else if (*argv[i] != '/') 513 }
493 fprintf (out, "%s/", quote_file_name (cwd)); 514 else
494 515 {
495 fprintf (out, "%s ", quote_file_name (argv[i])); 516 while ((str = fgets (string, BUFSIZ, stdin)))
496 } 517 {
518 quote_file_name (str, out);
519 }
520 fprintf (out, " ");
521 }
522
497 fprintf (out, "\n"); 523 fprintf (out, "\n");
498 fflush (out); 524 fflush (out);
499 525
500 /* Maybe wait for an answer. */ 526 /* Maybe wait for an answer. */
501 if (nowait) 527 if (nowait)