+ if (opt == EOF)
+ break;
+
+ alternate_editor = getenv ("ALTERNATE_EDITOR");
+
+ switch (opt)
+ {
+ case 0:
+ /* If getopt returns 0, then it has already processed a
+ long-named option. We should do nothing. */
+ break;
+
+ case 'a':
+ alternate_editor = optarg;
+ break;
+
+ case 'd':
+ display = optarg;
+ break;
+
+ case 'n':
+ nowait = 1;
+ break;
+
+ case 'e':
+ eval = 1;
+ break;
+
+ case 'V':
+ fprintf (stderr, "emacsclient %s\n", VERSION);
+ exit (1);
+ break;
+
+ case 'H':
+ default:
+ print_help_and_exit ();
+ }
+ }
+}
+
+void
+print_help_and_exit ()
+{
+ fprintf (stderr,
+ "Usage: %s [OPTIONS] FILE...\n\
+Tell the Emacs server to visit the specified files.\n\
+Every FILE can be either just a FILENAME or [+LINE[:COLUMN]] FILENAME.\n\
+The following OPTIONS are accepted:\n\
+-V, --version Just print a version info and return\n\
+-H, --help Print this usage information message\n\
+-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\
+-a, --alternate-editor=EDITOR\n\
+ Editor to fallback to if the server is not running\n\
+Report bugs to bug-gnu-emacs@gnu.org.\n", progname);
+ exit (1);
+}
+
+/* Return a copy of NAME, inserting a &
+ before each &, each space, each newline, and any initial -.
+ Change spaces to underscores, too, so that the
+ return value never contains a space. */
+
+char *
+quote_file_name (name)
+ char *name;
+{
+ char *copy = (char *) malloc (strlen (name) * 2 + 1);
+ char *p, *q;
+
+ p = name;
+ q = copy;
+ while (*p)
+ {
+ if (*p == ' ')
+ {
+ *q++ = '&';
+ *q++ = '_';
+ p++;
+ }
+ else if (*p == '\n')
+ {
+ *q++ = '&';
+ *q++ = 'n';
+ p++;
+ }
+ else
+ {
+ if (*p == '&' || (*p == '-' && p == name))
+ *q++ = '&';
+ *q++ = *p++;
+ }
+ }
+ *q++ = 0;
+
+ return copy;
+}
+
+/* Like malloc but get fatal error if memory is exhausted. */
+
+long *
+xmalloc (size)
+ unsigned int size;
+{
+ long *result = (long *) malloc (size);
+ if (result == NULL)
+ {
+ perror ("malloc");
+ exit (1);
+ }
+ return result;
+}
+\f
+/*
+ Try to run a different command, or --if no alternate editor is
+ defined-- exit with an errorcode.
+*/
+void
+fail (argc, argv)
+ int argc;
+ char **argv;
+{
+ if (alternate_editor)
+ {
+ int i = optind - 1;
+ execvp (alternate_editor, argv + i);
+ return;
+ }
+ else
+ {
+ exit (1);
+ }
+}
+
+
+\f
+#if !defined (HAVE_SOCKETS) || defined (NO_SOCKETS_IN_FILE_SYSTEM)
+
+int