--- emacsclient.c.orig Tue Sep 9 09:21:31 2003 +++ emacsclient.c Wed Sep 10 15:39:34 2003 @@ -67,6 +67,9 @@ is not running. --alternate-editor. */ const char * alternate_editor = NULL; +/* If non-NULL, the filename of the UNIX socket */ +const char * socket_name = NULL; + void print_help_and_exit (); struct option longopts[] = @@ -76,6 +79,7 @@ { "help", no_argument, NULL, 'H' }, { "version", no_argument, NULL, 'V' }, { "alternate-editor", required_argument, NULL, 'a' }, + { "socket-name", required_argument, NULL, 's' }, { "display", required_argument, NULL, 'd' }, { 0, 0, 0, 0 } }; @@ -91,7 +95,7 @@ while (1) { int opt = getopt_long (argc, argv, - "VHnea:d:", longopts, 0); + "VHnea:s:d:", longopts, 0); if (opt == EOF) break; @@ -109,6 +113,10 @@ alternate_editor = optarg; break; + case 's': + socket_name = optarg; + break; + case 'd': display = optarg; break; @@ -152,6 +160,8 @@ -n, --no-wait Don't wait for the server to return\n\ -e, --eval Evaluate the FILE arguments as ELisp expressions\n\ -d, --display=DISPLAY Visit the file in the given display\n\ +-s, --socket-name=FILENAME\n\ + Set the filename of the UNIX socket for communication\n\ -a, --alternate-editor=EDITOR\n\ Editor to fallback to if the server is not running\n\ \n\ @@ -300,7 +310,7 @@ /* Process options. */ decode_options (argc, argv); - if (argc - optind < 1) + if ((argc - optind < 1) && !eval) { fprintf (stderr, "%s: file name or argument required\n", progname); fprintf (stderr, "Try `%s --help' for more information\n", progname); @@ -347,7 +357,22 @@ { int sock_status = 0; - sprintf (server.sun_path, "/tmp/emacs%d-%s/server", (int) geteuid (), system_name); + if (socket_name) + { + if (strlen (socket_name) > sizeof server.sun_path ) + { + fprintf (stderr, "Invalid socket name (%s): the socket name is too long (max. %d)\n", socket_name, sizeof server.sun_path); + exit (1); + } + else + { + sprintf (server.sun_path, "%s", socket_name); + } + } + else + { + sprintf (server.sun_path, "/tmp/emacs%d-%s/server", (int) geteuid (), system_name); + } /* See if the socket exists, and if it's owned by us. */ sock_status = socket_status (server.sun_path); @@ -457,22 +482,33 @@ if (display) fprintf (out, "-display %s ", quote_file_name (display)); - for (i = optind; i < argc; i++) + if ((argc - optind > 0)) { - if (eval) - ; /* Don't prepend any cwd or anything like that. */ - else if (*argv[i] == '+') + for (i = optind; i < argc; i++) { - char *p = argv[i] + 1; - while (isdigit ((unsigned char) *p) || *p == ':') p++; - if (*p != 0) + if (eval) + ; /* Don't prepend any cwd or anything like that. */ + else if (*argv[i] == '+') + { + char *p = argv[i] + 1; + while (isdigit ((unsigned char) *p) || *p == ':') p++; + if (*p != 0) + fprintf (out, "%s/", quote_file_name (cwd)); + } + else if (*argv[i] != '/') fprintf (out, "%s/", quote_file_name (cwd)); - } - else if (*argv[i] != '/') - fprintf (out, "%s/", quote_file_name (cwd)); - fprintf (out, "%s ", quote_file_name (argv[i])); + fprintf (out, "%s ", quote_file_name (argv[i])); + } + } + else + { + while ((str = fgets (string, BUFSIZ, stdin))) + { + fprintf (out, "%s ", quote_file_name (str)); + } } + fprintf (out, "\n"); fflush (out);