--Ruby_Ridge-+qJ6SaWl2p
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I was playing with gnuclient and discovered that gnuclient only
writes out the first line of output:
$ gnuclient -batch -eval '(print "foobar\nbletch\n")'
==> foobar
I tracked it down to the use of read_line() in the output-producing
cases of gnuclient; read_line only reads up to the first "\n" and
stops, even if there's more output. The attached patch provides a
fix which incidentally allows an aribtrary amount of data (not just
GSERV_BUFSZ) to be received by gnuclient.
--Ruby_Ridge-+qJ6SaWl2p
Content-Type: text/plain
Content-Description: Patch to gnuclient.c
Content-Disposition: attachment;
filename="gnuclient.patch"
Content-Transfer-Encoding: 7bit
--- gnuclient.c.orig Sun May 24 07:40:19 1998
+++ gnuclient.c Fri Jun 5 20:29:54 1998
@@ -268,6 +268,42 @@
return new;
}
+/* read possibly multiline result from -batch */
+char*
+read_result (int s)
+{
+ char *temp=NULL;
+ char *result=NULL;
+ int length;
+ long offset=0;
+ long result_length=GSERV_BUFSZ;
+
+ result = malloc (result_length+1);
+
+ while ((length=read(s,result+offset,1)>0) &&
+ result[offset] != EOT_CHR)
+ {
+ offset += length;
+ if (offset >= result_length)
+ /* copy and reallocate */
+ {
+ result[offset] = '\0';
+ temp = strdup (result);
+
+ result_length += GSERV_BUFSZ;
+ result = realloc (result, result_length+1);
+
+ strcpy (result, temp);
+
+ free (temp);
+ } /* if */
+ } /* while */
+
+ result[offset] = '\0';
+
+ return result;
+}
+
int
main (int argc, char *argv[])
{
@@ -303,7 +339,7 @@
#endif /* SYSV_IPC */
char *tty = NULL;
char buffer[GSERV_BUFSZ + 1]; /* buffer to read pid */
- char result[GSERV_BUFSZ + 1];
+ char *result = NULL;
int i;
#ifdef INTERNET_DOMAIN_SOCKETS
@@ -441,7 +477,6 @@
exit (1);
}
- *result = '\0';
if (eval_function || eval_form || load_library)
{
#if defined(INTERNET_DOMAIN_SOCKETS)
@@ -469,11 +504,7 @@
}
send_string (s, "))");
send_string (s, EOT_STR);
- if (read_line (s, result) == 0)
- {
- fprintf (stderr, "%s: Could not read\n", progname);
- exit (1);
- }
+ result = read_result(s);
} /* eval_function || eval_form || load_library */
else if (batch)
{
@@ -495,11 +526,7 @@
}
send_string(s,"))");
send_string (s, EOT_STR);
- if (read_line (s, result) == 0)
- {
- fprintf (stderr, "%s: Could not read\n", progname);
- exit (1);
- }
+ result = read_result (s);
}
if (!batch)
@@ -520,12 +547,14 @@
send_string (s, "(gnuserv-eval '(emacs-pid))");
send_string (s, EOT_STR);
+ /* SOM: throwing away output here */
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
@@ -648,8 +677,13 @@
#endif /* !SYSV_IPC */
} /* not batch */
- if (batch && !quick)
- printf ("%s\n", result);
+ if (batch && !quick && result)
+ printf ("%s", result);
+
+ if (result != NULL)
+ {
+ free (result);
+ }
return 0;
--Ruby_Ridge-+qJ6SaWl2p
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Cheers,
--
Sam Mikes
smikes(a)alumni.hmc.edu
--Ruby_Ridge-+qJ6SaWl2p--
Show replies by date