Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: default command function



Thus spake "Gregory D. Fast" <gdfast@xxxxxxxx>:
>Is there a better way to do this?  My patch against 3.0.5 follows.

Oops.  That was the ugly patch.  This one is a lot cleaner (they both
work, though).

--
Greg Fast


--- zsh-3.0.5/Src/exec.c	Thu Sep 25 20:42:16 1997
+++ zsh-3.0.5-gdf/Src/exec.c	Mon Feb 23 12:53:38 1998
@@ -1,5 +1,5 @@
 /*
- * $Id: exec.c,v 2.93 1996/10/15 20:16:35 hzoli Exp $
+ * $Id: exec.c,v 1.8 1998/02/23 18:53:18 gdfast Exp gdfast $
  *
  * exec.c - command execution
  *
@@ -347,8 +347,38 @@
 	}
     if (eno)
 	zerr("%e: %s", arg0, eno);
-    else
-	zerr("command not found: %s", arg0, 0);
+#ifdef DEFAULT_CMD
+    else {
+      /* if cmd is unknown and function _default_cmd() is defined, 
+       * call _default_cmd() with the faulty cmdline as its args 
+       */
+      char *cmdarg = "_default_cmd";
+      List f; /* Shfunc to execute */
+      LinkNode top; 
+      char * cxx;
+      LinkList fargs = newlinklist();
+
+      addlinknode(fargs, (void *) cmdarg); /* make $0 "_default_cmd" */
+      /* args is global */
+      top = firstnode(args); /* keep track of where to stop rolling args */
+      do {
+	cxx = (char *) peekfirst(args);
+	addlinknode(fargs, (void *) cxx);
+	if (args->first->next==NULL) {
+	  break; /* don't roll if there's nowhere to roll to */
+	}
+	rolllist(args, args->first->next);
+      } while (args->first!=top);
+      if ( (f=getshfunc(cmdarg)) ) {
+	doshfunc(f, fargs, 0, 1);
+      } else {
+	zerr("command not found and no _default_cmd(): %s", arg0, 0);
+      }
+    }
+#else /* no DEFAULT_CMD */
+    else 
+      zerr("command not found: %s", arg0, 0);
+#endif /* DEFAULT_CMD */
     _exit(1);
 }
 



Messages sorted by: Reverse Date, Date, Thread, Author