print (decompiled) body of function for hash -v (well, as well as can be done anyway...)
authorMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Fri, 17 Jul 1992 04:56:20 +0000 (20:56 -0800)
committerMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Fri, 17 Jul 1992 04:56:20 +0000 (20:56 -0800)
SCCS-vsn: bin/sh/jobs.h 5.3
SCCS-vsn: bin/sh/jobs.c 5.5
SCCS-vsn: bin/sh/exec.c 5.6

usr/src/bin/sh/exec.c
usr/src/bin/sh/jobs.c
usr/src/bin/sh/jobs.h

index 6e2e88d..898d614 100644 (file)
@@ -91,7 +91,7 @@ STATIC int builtinloc = -1;           /* index in path of %builtin, or -1 */
 #ifdef __STDC__
 STATIC void tryexec(char *, char **, char **);
 STATIC void execinterp(char **, char **);
 #ifdef __STDC__
 STATIC void tryexec(char *, char **, char **);
 STATIC void execinterp(char **, char **);
-STATIC void printentry(struct tblentry *);
+STATIC void printentry(struct tblentry *, int);
 STATIC void clearcmdentry(int);
 STATIC struct tblentry *cmdlookup(char *, int);
 STATIC void delete_cmd_entry(void);
 STATIC void clearcmdentry(int);
 STATIC struct tblentry *cmdlookup(char *, int);
 STATIC void delete_cmd_entry(void);
@@ -313,14 +313,6 @@ hashcmd(argc, argv)  char **argv; {
        struct cmdentry entry;
        char *name;
 
        struct cmdentry entry;
        char *name;
 
-       if (argc <= 1) {
-               for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
-                       for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
-                               printentry(cmdp);
-                       }
-               }
-               return 0;
-       }
        verbose = 0;
        while ((c = nextopt("rv")) != '\0') {
                if (c == 'r') {
        verbose = 0;
        while ((c = nextopt("rv")) != '\0') {
                if (c == 'r') {
@@ -329,6 +321,14 @@ hashcmd(argc, argv)  char **argv; {
                        verbose++;
                }
        }
                        verbose++;
                }
        }
+       if (*argptr == NULL) {
+               for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
+                       for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
+                               printentry(cmdp, verbose);
+                       }
+               }
+               return 0;
+       }
        while ((name = *argptr) != NULL) {
                if ((cmdp = cmdlookup(name, 0)) != NULL
                 && (cmdp->cmdtype == CMDNORMAL
        while ((name = *argptr) != NULL) {
                if ((cmdp = cmdlookup(name, 0)) != NULL
                 && (cmdp->cmdtype == CMDNORMAL
@@ -338,7 +338,7 @@ hashcmd(argc, argv)  char **argv; {
                if (verbose) {
                        if (entry.cmdtype != CMDUNKNOWN) {      /* if no error msg */
                                cmdp = cmdlookup(name, 0);
                if (verbose) {
                        if (entry.cmdtype != CMDUNKNOWN) {      /* if no error msg */
                                cmdp = cmdlookup(name, 0);
-                               printentry(cmdp);
+                               printentry(cmdp, verbose);
                        }
                        flushall();
                }
                        }
                        flushall();
                }
@@ -349,8 +349,9 @@ hashcmd(argc, argv)  char **argv; {
 
 
 STATIC void
 
 
 STATIC void
-printentry(cmdp)
+printentry(cmdp, verbose)
        struct tblentry *cmdp;
        struct tblentry *cmdp;
+       int verbose;
        {
        int index;
        char *path;
        {
        int index;
        char *path;
@@ -368,6 +369,14 @@ printentry(cmdp)
                out1fmt("builtin %s", cmdp->cmdname);
        } else if (cmdp->cmdtype == CMDFUNCTION) {
                out1fmt("function %s", cmdp->cmdname);
                out1fmt("builtin %s", cmdp->cmdname);
        } else if (cmdp->cmdtype == CMDFUNCTION) {
                out1fmt("function %s", cmdp->cmdname);
+               if (verbose) {
+                       INTOFF;
+                       name = commandtext(cmdp->param.func);
+                       out1c(' ');
+                       out1str(name);
+                       ckfree(name);
+                       INTON;
+               }
 #ifdef DEBUG
        } else {
                error("internal error: cmdtype %d", cmdp->cmdtype);
 #ifdef DEBUG
        } else {
                error("internal error: cmdtype %d", cmdp->cmdtype);
index 801c5ce..da202f4 100644 (file)
@@ -5,11 +5,37 @@
  * This code is derived from software contributed to Berkeley by
  * Kenneth Almquist.
  *
  * This code is derived from software contributed to Berkeley by
  * Kenneth Almquist.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)jobs.c     5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)jobs.c     5.4 (Berkeley) 7/15/92";
 #endif /* not lint */
 
 #include "shell.h"
 #endif /* not lint */
 
 #include "shell.h"
@@ -57,7 +83,6 @@ STATIC void freejob(struct job *);
 STATIC int procrunning(int);
 STATIC int dowait(int, struct job *);
 STATIC int waitproc(int, int *);
 STATIC int procrunning(int);
 STATIC int dowait(int, struct job *);
 STATIC int waitproc(int, int *);
-STATIC char *commandtext(union node *);
 #else
 STATIC void restartjob();
 STATIC struct job *getjob();
 #else
 STATIC void restartjob();
 STATIC struct job *getjob();
@@ -65,7 +90,6 @@ STATIC void freejob();
 STATIC int procrunning();
 STATIC int dowait();
 STATIC int waitproc();
 STATIC int procrunning();
 STATIC int dowait();
 STATIC int waitproc();
-STATIC char *commandtext();
 #endif
 
 
 #endif
 
 
@@ -834,15 +858,16 @@ stoppedjobs()
 STATIC char *cmdnextc;
 STATIC int cmdnleft;
 STATIC void cmdtxt(), cmdputs();
 STATIC char *cmdnextc;
 STATIC int cmdnleft;
 STATIC void cmdtxt(), cmdputs();
+#define MAXCMDTEXT     200
 
 
-STATIC char *
+char *
 commandtext(n)
        union node *n;
        {
        char *name;
 
 commandtext(n)
        union node *n;
        {
        char *name;
 
-       cmdnextc = name = ckmalloc(50);
-       cmdnleft = 50 - 4;
+       cmdnextc = name = ckmalloc(MAXCMDTEXT);
+       cmdnleft = MAXCMDTEXT - 4;
        cmdtxt(n);
        *cmdnextc = '\0';
        return name;
        cmdtxt(n);
        *cmdnextc = '\0';
        return name;
index 5b705c2..8d9dd59 100644 (file)
@@ -7,7 +7,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)jobs.h      5.2 (Berkeley) %G%
+ *     @(#)jobs.h      5.3 (Berkeley) %G%
  */
 
 /* Mode argument to forkshell.  Don't change FORK_FG or FORK_BG. */
  */
 
 /* Mode argument to forkshell.  Don't change FORK_FG or FORK_BG. */
@@ -58,12 +58,14 @@ void showjobs(int);
 struct job *makejob(union node *, int);
 int forkshell(struct job *, union node *, int);
 int waitforjob(struct job *);
 struct job *makejob(union node *, int);
 int forkshell(struct job *, union node *, int);
 int waitforjob(struct job *);
+char *commandtext(union node *);
 #else
 void setjobctl();
 void showjobs();
 struct job *makejob();
 int forkshell();
 int waitforjob();
 #else
 void setjobctl();
 void showjobs();
 struct job *makejob();
 int forkshell();
 int waitforjob();
+char *commandtext();
 #endif
 
 #if ! JOBS
 #endif
 
 #if ! JOBS