From xemacs-m  Tue May 27 19:27:38 1997
Received: from jagor.srce.hr (hniksic@jagor.srce.hr [161.53.2.130])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id TAA19280
	for <xemacs-beta@xemacs.org>; Tue, 27 May 1997 19:27:37 -0500 (CDT)
Received: (from hniksic@localhost)
          by jagor.srce.hr (8.8.5/8.8.4)
	  id CAA06831; Wed, 28 May 1997 02:27:37 +0200 (MET DST)
To: XEmacs Developers <xemacs-beta@xemacs.org>
Subject: [patch] Gnuserv update
X-Attribution: Hrv
X-Face: Mie8:rOV<\c/~z{s.X4A{!?vY7{drJ([U]0O=W/<W*SMo/Mv:58:*_y~ki>xDi&N7XG
        KV^$k0m3Oe/)'e%3=$PCR&3ITUXH,cK>]bci&<qQ>Ff%x_>1`T(+M2Gg/fgndU%k*ft
        [(7._6e0n-V%|%'[c|q:;}td$#INd+;?!-V=c8Pqf}3J
X-Zippy-Says: 
   Send your questions to ``ASK ZIPPY'', Box 40474, San Francisco, CA
   94140, USA
From: Hrvoje Niksic <hniksic@srce.hr>
Date: 28 May 1997 02:27:36 +0200
Message-ID: <kig206so2yv.fsf@jagor.srce.hr>
Lines: 317
X-Mailer: Gnus v5.4.52/XEmacs 20.2

Here is an update against the 20.3-b2 sources.  My work on gnuserv.el
is mostly finished -- no major new features are planned (at least not
now).  I'd still like to clean gnu{client,serv,slib}.c, but I don't
know if I'll have the time (or will) to work on it.  The way things
are currently, everything works well, except when connecting from a
remote host; that case is simply untested.  Maybe works, maybe not.

Jan Vroonhof has promised to update the manual pages (not too much
work), so somewhere by 20.3-b4 we should have a final gnuserv.el.
Also, I'd like gnuserv.el to be moved from packages/ to utils/
directory, since it's now supported by us (Jan and me), rather than
being an independent package.  FSF support is definitely gone, and I
don't plan to resurrect it.

Patch follows:

--- lib-src/gnuclient.c.orig	Tue May 27 22:20:45 1997
+++ lib-src/gnuclient.c	Tue May 27 22:28:09 1997
@@ -56,6 +56,7 @@
 #endif /* HAVE_UNISTD_H */
 #include <signal.h>
 
+int read_line(int, char *);
 
 #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
     !defined(INTERNET_DOMAIN_SOCKETS)
@@ -91,7 +92,7 @@
 
   connect_type = make_connection (NULL, (u_short) 0, &s);
 
-  sprintf(buffer,"(gnuserv-eval '(resume-pid-console %d))", getpid());
+  sprintf(buffer,"(gnuserv-eval '(resume-pid-console %d))", (int)getpid());
   send_string(s, buffer);
 
 #ifdef SYSV_IPC
@@ -252,6 +253,15 @@
   over = 1;								   \
 } while (0)
 
+/* A strdup immitation. */
+static char *
+my_strdup (CONST char *s)
+{
+  char *new = malloc (strlen (s) + 1);
+  if (new)
+    strcpy (new, s);
+  return new;
+}
 
 int
 main (int argc, char *argv[])
@@ -268,12 +278,11 @@
   int view = 0;			/* view only. */
   int nofiles = 0;
   int errflg = 0;		/* option error */
-  int c;			/* char from getopt */
   int s;			/* socket / msqid to server */
   int connect_type;		/* CONN_UNIX, CONN_INTERNET, or
 				 * CONN_IPC */
   int suppress_windows_system = 0;
-  char *display;
+  char *display = NULL;
 #ifdef INTERNET_DOMAIN_SOCKETS
   char *hostarg = NULL;		/* remote hostname */
   char *remotearg;
@@ -305,14 +314,25 @@
   display = getenv ("DISPLAY");
   if (!display)
     suppress_windows_system = 1;
+  else
+    display = my_strdup (display);
 
   for (i = 1; argv[i] && !errflg; i++)
     {
       if (*argv[i] != '-')
 	break;
-      if (!strcmp (argv[i], "-batch"))
+      else if (*argv[i] == '-'
+	       && (*(argv[i] + 1) == '\0'
+		   || (*(argv[i] + 1) == '-' && *(argv[i] + 2) == '\0')))
+	{
+	  /* `-' or `--' */
+	  ++i;
+	  break;
+	}
+
+      if (!strcmp (argv[i], "-batch") || !strcmp (argv[i], "--batch"))
 	batch = 1;
-      else if (!strcmp (argv[i], "-eval"))
+      else if (!strcmp (argv[i], "-eval") || !strcmp (argv[i], "--eval"))
 	{
 	  if (!argv[++i])
 	    {
@@ -322,15 +342,19 @@
 	    }
 	  eval_form = argv[i];
 	}
-      else if (!strcmp (argv[i], "-display"))
+      else if (!strcmp (argv[i], "-display") || !strcmp (argv[i], "--display"))
 	{
 	  suppress_windows_system = 0;
 	  if (!argv[++i])
 	    {
-	      fprintf (stderr, "%s: `-display' must be followed by an argument\n",
+	      fprintf (stderr,
+		       "%s: `-display' must be followed by an argument\n",
 		       progname);
 	      exit (1);
 	    }
+	  if (display)
+	    free (display);
+	  /* no need to strdup. */
 	  display = argv[i];
 	}
       else if (!strcmp (argv[i], "-nw"))
@@ -396,6 +420,13 @@
 	       progname);
       exit (1);
     }
+  if (suppress_windows_system && hostarg)
+    {
+      fprintf (stderr, "%s: Remote editing is available only on X\n",
+	       progname);
+      exit (1);
+    }
+
   *result = '\0';
   if (eval_function || eval_form || load_library)
     {
@@ -446,32 +477,30 @@
 	      fprintf (stderr, "%s: Not connected to a tty", progname);
 	      exit (1);
 	    }
-	}
-
 #if defined(INTERNET_DOMAIN_SOCKETS)
-      connect_type = make_connection (hostarg, port, &s);
+	  connect_type = make_connection (hostarg, port, &s);
 #else
-      connect_type = make_connection (NULL, (u_short) 0, &s);
+	  connect_type = make_connection (NULL, (u_short) 0, &s);
 #endif
+	  send_string (s, "(gnuserv-eval '(emacs-pid))");
+	  send_string (s, EOT_STR);
 
-      send_string (s, "(gnuserv-eval '(emacs-pid))");
-      send_string (s, EOT_STR);
-
-      if (read_line (s, buffer) == 0)
-	{
-	  fprintf (stderr, "%s: Could not establish emacs procces id\n",
-		   progname);
-	  exit (1);
-	}
+	  if (read_line (s, buffer) == 0)
+	    {
+	      fprintf (stderr, "%s: Could not establish Emacs procces id\n",
+		       progname);
+	      exit (1);
+	    }
       /* Don't do disconnect_from_server becasue we have already read
 	 data, and disconnect doesn't do anything else. */
 #ifndef INTERNET_DOMAIN_SOCKETS
-      if (connect_type == (int) CONN_IPC)
-	disconnect_from_ipc_server (s, msgp, FALSE);
+	  if (connect_type == (int) CONN_IPC)
+	    disconnect_from_ipc_server (s, msgp, FALSE);
 #endif /* !SYSV_IPC */
 
-      emacs_pid = (pid_t)atol(buffer);
-      initialize_signals();
+	  emacs_pid = (pid_t)atol(buffer);
+	  initialize_signals();
+	} /* suppress_windows_system */
 
 #if defined(INTERNET_DOMAIN_SOCKETS)
       connect_type = make_connection (hostarg, port, &s);
@@ -528,7 +557,7 @@
 	      exit (1);
 	    }
 	  sprintf (command, "(gnuserv-edit-files '(tty %s %s %d) '(",
-		   clean_string (tty), clean_string (term), getpid ());
+		   clean_string (tty), clean_string (term), (int)getpid ());
 	}
       else /* !suppress_windows_system */
 	{
@@ -557,8 +586,7 @@
 	  path = malloc (strlen (remotepath) + strlen (fullpath) + 1);
 	  sprintf (path, "%s%s", remotepath, fullpath);
 #else
-	  path = malloc (strlen (fullpath));
-	  strcpy (path, fullpath);
+	  path = my_strdup (fullpath);
 #endif
 	  sprintf (command, "(%d . %s)", starting_line, clean_string (path));
 	  send_string (s, command);
--- lib-src/gnudoit.orig	Tue May 27 22:20:50 1997
+++ lib-src/gnudoit	Tue May 27 22:21:30 1997
@@ -1,11 +1,36 @@
 #! /bin/sh
 
+# This file is part of XEmacs.
+
+# Copyright (C) 1997  Free Software Foundation, Inc.
+
+# XEmacs is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2, or (at your option) any
+# later version.
+
+# XEmacs is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with XEmacs; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+if [ x"$1" = x-q ]
+then
+    quick=-q
+    shift
+fi
+
 if [ $# -eq 0 ]
 then
-   echo "$0: arguments expected" >&2
-   exit 1
+    echo "$0: arguments expected" >&2
+    exit 1
 fi
 
 # I use "$*" instead of "$@" intentionally -- I don't want to have the
 # arguments split.
-gnuclient -batch -eval "$*"
+exec gnuclient $quick -batch -eval "$*"
--- lib-src/Makefile.in.in.orig	Tue May 27 22:27:12 1997
+++ lib-src/Makefile.in.in	Tue May 27 22:27:24 1997
@@ -106,7 +106,7 @@
 /* Things that a user might actually run,
    which should be installed in bindir. */
 INSTALLABLES = etags ctags b2m gnuclient
-INSTALLABLE_SCRIPTS = rcs-checkin pstogif install-sid send-pr
+INSTALLABLE_SCRIPTS = rcs-checkin pstogif install-sid send-pr gnudoit
 
 /* Things that Emacs runs internally, or during the build process,
    which should not be installed in bindir. */
--- lisp/packages/gnuserv.el.orig	Wed May 28 02:22:12 1997
+++ lisp/packages/gnuserv.el	Wed May 28 02:22:15 1997
@@ -1,9 +1,11 @@
 ;;; gnuserv.el --- Lisp interface code between Emacs and gnuserv
 ;; Copyright (C) 1989-1997 Free Software Foundation, Inc.
 
-;; Version: 3.2
+;; Version: 3.3
 ;; Author: Andy Norman (ange@hplb.hpl.hp.com), originally based on server.el
 ;;         Hrvoje Niksic <hniksic@srce.hr>
+;; Maintainer: Jan Vroonhof <vroonhof@math.ethz.ch>,
+;;             Hrvoje Niksic <hniksic@srce.hr>
 ;; Keywords: environment, processes, terminals
 
 ;; This file is part of XEmacs.
@@ -45,11 +47,12 @@
 ;; TTY, this TTY will be attached as a new device to the running
 ;; XEmacs, and will be removed once you are done with the buffer.
 
-;; To evaluate a Lisp form in a running Emacs, use the `gnudoit'
-;; utility.  For example `gnudoit "(+ 2 3)"' will print `5', whereas
-;; `gnudoit "(gnus)"' will fire up your favorite newsreader.  Like
-;; gnuclient, `gnudoit' requires the server to be started prior to
-;; using it.
+;; To evaluate a Lisp form in a running Emacs, use the `-eval'
+;; argument of gnuclient.  To simplify this, we provide the `gnudoit'
+;; shell script.  For example `gnudoit "(+ 2 3)"' will print `5',
+;; whereas `gnudoit "(gnus)"' will fire up your favorite newsreader.
+;; Like gnuclient, `gnudoit' requires the server to be started prior
+;; to using it.
 
 ;; For more information you can refer to man pages of gnuclient,
 ;; gnudoit and gnuserv, distributed with XEmacs.
@@ -317,7 +320,7 @@
   "Process gnuserv client requests to execute Emacs commands."
   (setq gnuserv-string (concat gnuserv-string string))
   ;; C-d means end of request.
-  (when (string-match "\C-d$" gnuserv-string)
+  (when (string-match "\C-d\\'" gnuserv-string)
     (cond ((string-match "^[0-9]+" gnuserv-string) ; client request id
 	   (let ((header (read-from-string gnuserv-string)))
 	     ;; Set the client we are talking to.
@@ -627,7 +630,7 @@
      ;; return its first buffer.
      ((setq client
 	    (car (member-if-not 'null gnuserv-clients
-				:key 'gnuserv-buffers)))
+				:key 'gnuclient-buffers)))
       (car (gnuclient-buffers client)))
      ;; Oh, give up.
      (t nil))))
@@ -674,8 +677,7 @@
     (condition-case ()
 	(delete-process gnuserv-process)
       (error nil))
-    (setq gnuserv-process nil)
-    (message "Killed server")))
+    (setq gnuserv-process nil)))
 
 ;; Actually start the process.  Kills all the clients before-hand.
 (defun gnuserv-start-1 (&optional leave-dead)


-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
* Q: What is an experienced Emacs user?
* A: A person who wishes that the terminal had pedals.

