home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / EmacsTeX / EL2 / Source / emacs_client.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  2.9 KB  |  124 lines

  1.  
  2. /* Modified 9/26/90 by Simson L. Garfinkel
  3.  * To make server into NeXT Workspace Listener
  4.  *
  5.  */
  6.  
  7. #define NEXT
  8.  
  9. /* Client process that communicates with GNU Emacs acting as server.
  10.    Copyright (C) 1986, 1987 Free Software Foundation, Inc.
  11.  
  12. This file is part of GNU Emacs.
  13.  
  14. GNU Emacs is distributed in the hope that it will be useful,
  15. but without any warranty.  No author or distributor
  16. accepts responsibility to anyone for the consequences of using it
  17. or for whether it serves any particular purpose or works at all,
  18. unless he says so in writing.
  19.  
  20. Everyone is granted permission to copy, modify and redistribute
  21. GNU Emacs, but only under the conditions described in the
  22. document "GNU Emacs copying permission notice".   An exact copy
  23. of the document is supposed to have been given to you along with
  24. GNU Emacs so that you can know how you may redistribute it all.
  25. It should be in a file named COPYING.  Among other things, the
  26. copyright notice and this notice must be preserved on all copies.  */
  27.  
  28.  
  29. #define NO_SHORTNAMES
  30.  
  31. #ifdef NEXT
  32. #import <libc.h>
  33. #import <sys/un.h>
  34. #define exit(n) return(n)            /* 'cause I'm a function now */
  35. #endif
  36.  
  37.  
  38. int    call_emacsserver(int argc,char **argv)
  39. {
  40.     int s, i;
  41.     FILE *out;
  42.     struct sockaddr_un server;
  43.     char *homedir, *cwd;
  44.     char string[BUFSIZ];
  45.  
  46.   char *getenv (), *getwd ();
  47.  
  48.   if (argc < 2)
  49.     {
  50.       printf ("Usage: %s [filename]\n", argv[0]);
  51.       exit (1);
  52.     }
  53.  
  54.   /* 
  55.    * Open up an AF_UNIX socket in this person's home directory
  56.    */
  57.  
  58.   if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
  59.     {
  60.       perror ("socket");
  61.       exit (1);
  62.     }
  63.   server.sun_family = AF_UNIX;
  64.   if ((homedir = getenv ("HOME")) == NULL)
  65.     {
  66.       fprintf (stderr, "No home directory\n");
  67.       exit (1);
  68.     }
  69.   strcpy (server.sun_path, homedir);
  70.   strcat (server.sun_path, "/.emacs_server");
  71.   if (connect (s, (struct sockaddr *)&server,strlen (server.sun_path) + 2) < 0)
  72.     {
  73.       perror ("connect");
  74.       fprintf(stderr,"filename: %s\n",server.sun_path);
  75.       fprintf(stderr,"be sure that these lines are in your .emacs file:\n");
  76.       fprintf(stderr,"    (load-library \"server\")\n");
  77.       fprintf(stderr,"    (start-server)\n");
  78.       exit (1);
  79.     }
  80.   if ((out = fdopen (s, "r+")) == NULL)
  81.     {
  82.       perror ("fdopen");
  83.       exit (1);
  84.     }
  85.  
  86.   cwd = getwd (string);
  87.   if (cwd == 0)
  88.     abort ();
  89.  
  90.   for (i = 1; i < argc; i++)
  91.     {
  92.       if (*argv[i] == '+')
  93.     {
  94.       char *p = argv[i] + 1;
  95.       while (*p >= '0' && *p <= '9') p++;
  96.       if (*p != 0)
  97.         fprintf (out, "%s/", cwd);
  98.     }
  99.       else if (*argv[i] != '/')
  100.     fprintf (out, "%s/", cwd);
  101.       fprintf (out, "%s ", argv[i]);
  102.     }
  103.   fprintf (out, "\n");
  104.   fflush (out);
  105.  
  106. #ifndef NEXT                    /* We don't do this */
  107.  
  108.   printf ("Waiting for Emacs...");
  109.   fflush (stdout);
  110.  
  111.   rewind (out); /* re-read the output */
  112.   str = fgets (string, BUFSIZ, out); 
  113.  
  114.   /* Now, wait for an answer and print any messages.  */
  115.   
  116.   while (str = fgets (string, BUFSIZ, out))
  117.     printf ("%s", str);
  118.   
  119. #endif
  120.  
  121.   exit (0);
  122. }
  123.  
  124.