/[emacs]/emacs/lib-src/emacsclient.c
ViewVC logotype

Diff of /emacs/lib-src/emacsclient.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.50.4.1 by miles, Fri Apr 4 06:19:54 2003 UTC revision 1.50.4.2 by miles, Tue Oct 14 23:59:13 2003 UTC
# Line 67  char *display = NULL; Line 67  char *display = NULL;
67     is not running.  --alternate-editor.   */     is not running.  --alternate-editor.   */
68  const char * alternate_editor = NULL;  const char * alternate_editor = NULL;
69    
70    /* If non-NULL, the filename of the UNIX socket.  */
71    char *socket_name = NULL;
72    
73  void print_help_and_exit ();  void print_help_and_exit ();
74    
75  struct option longopts[] =  struct option longopts[] =
# Line 76  struct option longopts[] = Line 79  struct option longopts[] =
79    { "help",     no_argument,       NULL, 'H' },    { "help",     no_argument,       NULL, 'H' },
80    { "version",  no_argument,       NULL, 'V' },    { "version",  no_argument,       NULL, 'V' },
81    { "alternate-editor", required_argument, NULL, 'a' },    { "alternate-editor", required_argument, NULL, 'a' },
82      { "socket-name",      required_argument, NULL, 's' },
83    { "display",  required_argument, NULL, 'd' },    { "display",  required_argument, NULL, 'd' },
84    { 0, 0, 0, 0 }    { 0, 0, 0, 0 }
85  };  };
# Line 91  decode_options (argc, argv) Line 95  decode_options (argc, argv)
95    while (1)    while (1)
96      {      {
97        int opt = getopt_long (argc, argv,        int opt = getopt_long (argc, argv,
98                               "VHnea:d:", longopts, 0);                               "VHnea:s:d:", longopts, 0);
99    
100        if (opt == EOF)        if (opt == EOF)
101          break;          break;
# Line 109  decode_options (argc, argv) Line 113  decode_options (argc, argv)
113            alternate_editor = optarg;            alternate_editor = optarg;
114            break;            break;
115    
116            case 's':
117              socket_name = optarg;
118              break;
119    
120          case 'd':          case 'd':
121            display = optarg;            display = optarg;
122            break;            break;
# Line 152  The following OPTIONS are accepted:\n\ Line 160  The following OPTIONS are accepted:\n\
160  -n, --no-wait           Don't wait for the server to return\n\  -n, --no-wait           Don't wait for the server to return\n\
161  -e, --eval              Evaluate the FILE arguments as ELisp expressions\n\  -e, --eval              Evaluate the FILE arguments as ELisp expressions\n\
162  -d, --display=DISPLAY   Visit the file in the given display\n\  -d, --display=DISPLAY   Visit the file in the given display\n\
163    -s, --socket-name=FILENAME\n\
164                            Set the filename of the UNIX socket for communication\n\
165  -a, --alternate-editor=EDITOR\n\  -a, --alternate-editor=EDITOR\n\
166                          Editor to fallback to if the server is not running\n\                          Editor to fallback to if the server is not running\n\
167  \n\  \n\
# Line 159  Report bugs to bug-gnu-emacs@gnu.org.\n" Line 169  Report bugs to bug-gnu-emacs@gnu.org.\n"
169    exit (0);    exit (0);
170  }  }
171    
172  /* Return a copy of NAME, inserting a &  /* In NAME, insert a & before each &, each space, each newline, and
173     before each &, each space, each newline, and any initial -.     any initial -.  Change spaces to underscores, too, so that the
    Change spaces to underscores, too, so that the  
174     return value never contains a space.  */     return value never contains a space.  */
175    
176  char *  void
177  quote_file_name (name)  quote_file_name (name, stream)
178       char *name;       char *name;
179         FILE *stream;
180  {  {
181    char *copy = (char *) malloc (strlen (name) * 2 + 1);    char *copy = (char *) malloc (strlen (name) * 2 + 1);
182    char *p, *q;    char *p, *q;
# Line 196  quote_file_name (name) Line 206  quote_file_name (name)
206      }      }
207    *q++ = 0;    *q++ = 0;
208    
209    return copy;    fprintf (stream, copy);
210    
211      free (copy);
212  }  }
213    
214  /* Like malloc but get fatal error if memory is exhausted.  */  /* Like malloc but get fatal error if memory is exhausted.  */
# Line 300  main (argc, argv) Line 312  main (argc, argv)
312    /* Process options.  */    /* Process options.  */
313    decode_options (argc, argv);    decode_options (argc, argv);
314    
315    if (argc - optind < 1)    if ((argc - optind < 1) && !eval)
316      {      {
317        fprintf (stderr, "%s: file name or argument required\n", progname);        fprintf (stderr, "%s: file name or argument required\n", progname);
318        fprintf (stderr, "Try `%s --help' for more information\n", progname);        fprintf (stderr, "Try `%s --help' for more information\n", progname);
# Line 347  main (argc, argv) Line 359  main (argc, argv)
359    {    {
360      int sock_status = 0;      int sock_status = 0;
361    
362      sprintf (server.sun_path, "/tmp/esrv%d-%s", (int) geteuid (), system_name);      if (! socket_name)
363          {
364            socket_name = alloca (system_name_length + 100);
365            sprintf (socket_name, "/tmp/emacs%d-%s/server",
366                     (int) geteuid (), system_name);
367          }
368    
369        if (strlen (socket_name) < sizeof (server.sun_path))
370          strcpy (server.sun_path, socket_name);
371        else
372          fprintf (stderr, "%s: socket-name %s too long",
373                   argv[0], socket_name);
374    
375      /* See if the socket exists, and if it's owned by us. */      /* See if the socket exists, and if it's owned by us. */
376      sock_status = socket_status (server.sun_path);      sock_status = socket_status (server.sun_path);
# Line 438  To start the server in Emacs, type \"M-x Line 461  To start the server in Emacs, type \"M-x
461    if (cwd == 0)    if (cwd == 0)
462      {      {
463        /* getwd puts message in STRING if it fails.  */        /* getwd puts message in STRING if it fails.  */
464        fprintf (stderr, "%s: %s (%s)\n", argv[0],  
465  #ifdef HAVE_GETCWD  #ifdef HAVE_GETCWD
466                 "Cannot get current working directory",        fprintf (stderr, "%s: %s (%s)\n", argv[0],
467                   "Cannot get current working directory", strerror (errno));
468  #else  #else
469                 string,        fprintf (stderr, "%s: %s (%s)\n", argv[0], string, strerror (errno));
470  #endif  #endif
                strerror (errno));  
471        fail (argc, argv);        fail (argc, argv);
472      }      }
473    
# Line 455  To start the server in Emacs, type \"M-x Line 478  To start the server in Emacs, type \"M-x
478      fprintf (out, "-eval ");      fprintf (out, "-eval ");
479    
480    if (display)    if (display)
481      fprintf (out, "-display %s ", quote_file_name (display));      {
482          fprintf (out, "-display ");
483          quote_file_name (display, out);
484          fprintf (out, " ");
485        }
486    
487    for (i = optind; i < argc; i++)    if ((argc - optind > 0))
488      {      {
489        if (eval)        for (i = optind; i < argc; i++)
         ; /* Don't prepend any cwd or anything like that.  */  
       else if (*argv[i] == '+')  
490          {          {
491            char *p = argv[i] + 1;            if (eval)
492            while (isdigit ((unsigned char) *p) || *p == ':') p++;              ; /* Don't prepend any cwd or anything like that.  */
493            if (*p != 0)            else if (*argv[i] == '+')
494              fprintf (out, "%s/", quote_file_name (cwd));              {
495          }                char *p = argv[i] + 1;
496        else if (*argv[i] != '/')                while (isdigit ((unsigned char) *p) || *p == ':') p++;
497          fprintf (out, "%s/", quote_file_name (cwd));                if (*p != 0)
498                    {
499                      quote_file_name (cwd, out);
500                      fprintf (out, "/");
501                    }
502                }
503              else if (*argv[i] != '/')
504                {
505                  quote_file_name (cwd, out);
506                  fprintf (out, "/");
507                }
508    
509        fprintf (out, "%s ", quote_file_name (argv[i]));            quote_file_name (argv[i], out);
510              fprintf (out, " ");
511            }
512      }      }
513      else
514        {
515          while ((str = fgets (string, BUFSIZ, stdin)))
516            {
517              quote_file_name (str, out);
518            }
519          fprintf (out, " ");
520        }
521      
522    fprintf (out, "\n");    fprintf (out, "\n");
523    fflush (out);    fflush (out);
524    
# Line 519  strerror (errnum) Line 565  strerror (errnum)
565  }  }
566    
567  #endif /* ! HAVE_STRERROR */  #endif /* ! HAVE_STRERROR */
568    
569    /* arch-tag: f39bb9c4-73eb-477e-896d-50832e2ca9a7
570       (do not change this comment) */

Legend:
Removed from v.1.50.4.1  
changed lines
  Added in v.1.50.4.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26