--- cli_input.c	Tue Sep 19 13:23:03 2000
+++ cli_input.c.new	Tue Sep 19 13:22:51 2000
@@ -133,6 +133,11 @@
 {
   char *command;
   char *arg;
+  char buf[1024] = "",
+       buf2[1024] = "",
+       buf3[1024] = "",
+       *ci, *cc = 0, found_bt=0;
+  FILE *p = NULL;
   int cnum;
   int i;
   int len;
@@ -141,44 +146,89 @@
 	return 0;
   }
   
-  len=strlen(a);
+	/* WE REALLY REALLY SHOULD BE USING snprintf() here, but i'm not
+	   sure if it's available on windows machines */
+#ifndef WIN32
+	snprintf(buf, sizeof(buf), "%s",a);
+	do	{
+		found_bt = 0;
+		for (ci=buf; *ci; ci++)	{
+			if (*ci=='`'&&(ci-buf==0||*(ci-1)!='\\'))	{
+				for (cc=ci+1; *cc; cc++)	{
+					if (*cc=='`'&&*(cc-1)!='\\')	{
+						found_bt = 1;
+						break;
+					}
+				}
+				if (!found_bt)	{
+					printf("Error: unterminated backtick at \"%s\".\n",ci);
+					return 0;
+				} 
+				
+				fprintf(stderr,"DEBUG: execing \"%s\".\n", ci+1);
+				*ci = 0; *cc = 0;
+				p = popen(ci+1, "r");
+				if (!p)	{
+					printf("Error: could not open pipe \"%s\".\n", ci+1);
+					return 0;
+				}
+				/* get the output of the cmd.. this is arguably the
+				   wrong behavior -- we might want to be uusing only
+				   the first line, or all of them.. etc etc */
+				while (fgets(buf3,sizeof(buf3),p));
+				if (strlen(buf3)&&buf3[strlen(buf3)-1]=='\n')
+					buf3[strlen(buf3)-1]=0;
+				pclose(p);
+
+				fprintf(stderr,"DEBUG: replacing \"%s\" with \"%s\".\n",
+				       ci+1, buf3);
+
+				snprintf(buf2, sizeof(buf2), "%s%s%s", buf, buf3, cc+1);
+				fprintf(stderr,"DEBUG: final string = \"%s\"\n", buf2);
+				strncpy(buf, buf2, sizeof(buf));
+				break;
+			}
+		}
+	} while (found_bt);
+#endif
 
   /* Start by assuming there's nothing */
+  len=strlen(buf);
   command=0;
   arg=0;
 
   /* skip initial space */
-  for (i=0; i<len && isspace(a[i]); i++) { }
+  for (i=0; i<len && isspace(buf[i]); i++) { }
   if (i==len) {
 	/* It's all space -- no command or arg */
   } else {
 	/* got a command, at least */
-    command=&a[i];
+    command=&buf[i];
 	/* Scan past command */
-    for (;i<len && !isspace(a[i]);i++) { }
+    for (;i<len && !isspace(buf[i]);i++) { }
     if (i==len) {
 	  /* nothing after command */
       arg=0;
     } else {
 	  /* space after command, but what about an arg? */
-      a[i++]=0;
+      buf[i++]=0;
 	  /* skip space */
-      for (;i<len && isspace(a[i]);i++) { }
+      for (;i<len && isspace(buf[i]);i++) { }
       if (i==len) {
         /* nope, no arg */
 		arg=0;
 	  } else {
         /* yes, there's an argument */
-		arg=&a[i];
+		arg=&buf[i];
       }
     }
   }
   
   if (arg) {
     /* delete trailing space after arg */
-    for (i=len;i>0 && isspace(a[i]);i--) { }
+    for (i=len;i>0 && isspace(buf[i]);i--) { }
     if (i!=len)
-	  a[i+1]=0;
+	  buf[i+1]=0;
   }
   
   if (command) {

