summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>1997-02-06 23:24:52 +0000
committerchristos <christos@NetBSD.org>1997-02-06 23:24:52 +0000
commit680690d33cd23e1071c1929a1e86b7eaaa214a84 (patch)
treeec737ce3cfe3ca0c6e98635b91e53ec9a2f75541 /bin
parent5851e327c5b01ec10c79eafb560be6eaac17e299 (diff)
add type builtin.
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/builtins.def3
-rw-r--r--bin/sh/exec.c79
-rw-r--r--bin/sh/exec.h3
-rw-r--r--bin/sh/sh.110
4 files changed, 90 insertions, 5 deletions
diff --git a/bin/sh/builtins.def b/bin/sh/builtins.def
index de129bb873c..f81c33f9087 100644
--- a/bin/sh/builtins.def
+++ b/bin/sh/builtins.def
@@ -1,5 +1,5 @@
#!/bin/sh -
-# $NetBSD: builtins.def,v 1.12 1995/05/11 21:28:48 christos Exp $
+# $NetBSD: builtins.def,v 1.13 1997/02/06 23:24:52 christos Exp $
#
# Copyright (c) 1991, 1993
# The Regents of the University of California. All rights reserved.
@@ -82,6 +82,7 @@ setvarcmd setvar
shiftcmd shift
trapcmd trap
truecmd : true
+typecmd type
umaskcmd umask
unaliascmd unalias
unsetcmd unset
diff --git a/bin/sh/exec.c b/bin/sh/exec.c
index b30146d136b..bf07586c9aa 100644
--- a/bin/sh/exec.c
+++ b/bin/sh/exec.c
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.21 1997/01/11 02:04:31 tls Exp $ */
+/* $NetBSD: exec.c,v 1.22 1997/02/06 23:24:52 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95";
#else
-static char rcsid[] = "$NetBSD: exec.c,v 1.21 1997/01/11 02:04:31 tls Exp $";
+static char rcsid[] = "$NetBSD: exec.c,v 1.22 1997/02/06 23:24:52 christos Exp $";
#endif
#endif /* not lint */
@@ -79,6 +79,7 @@ static char rcsid[] = "$NetBSD: exec.c,v 1.21 1997/01/11 02:04:31 tls Exp $";
#include "mystring.h"
#include "show.h"
#include "jobs.h"
+#include "alias.h"
#define CMDTABLESIZE 31 /* should be prime */
@@ -843,3 +844,77 @@ unsetfunc(name)
}
return (1);
}
+
+/*
+ * Locate and print what a word is...
+ */
+
+int
+typecmd(argc, argv)
+ int argc;
+ char **argv;
+{
+ struct cmdentry entry;
+ struct tblentry *cmdp;
+ char **pp;
+ struct alias *ap;
+ int i;
+ int error = 0;
+ extern char *const parsekwd[];
+
+ for (i = 1; i < argc; i++) {
+ out1str(argv[i]);
+ /* First look at the keywords */
+ for (pp = (char **)parsekwd; *pp; pp++)
+ if (**pp == *argv[i] && equal(*pp, argv[i]))
+ break;
+
+ if (*pp) {
+ out1str(" is a shell keyword\n");
+ continue;
+ }
+
+ /* Then look at the aliases */
+ if ((ap = lookupalias(argv[i], 1)) != NULL) {
+ out1fmt(" is an alias for %s\n", ap->val);
+ continue;
+ }
+
+ /* Then check if it is a tracked alias */
+ if ((cmdp = cmdlookup(argv[i], 0)) != NULL) {
+ entry.cmdtype = cmdp->cmdtype;
+ entry.u = cmdp->param;
+ }
+ else {
+ /* Finally use brute force */
+ find_command(argv[i], &entry, 0, pathval());
+ }
+
+ switch (entry.cmdtype) {
+ case CMDNORMAL: {
+ int j = entry.u.index;
+ char *path = pathval(), *name;
+ do {
+ name = padvance(&path, argv[i]);
+ stunalloc(name);
+ } while (--j >= 0);
+ out1fmt(" is%s %s\n",
+ cmdp ? " a tracked alias for" : "", name);
+ break;
+ }
+ case CMDFUNCTION:
+ out1str(" is a shell function\n");
+ break;
+
+ case CMDBUILTIN:
+ out1str(" is a shell builtin\n");
+ break;
+
+ default:
+ out1str(" not found\n");
+ error |= 127;
+ break;
+ }
+ }
+ return error;
+}
diff --git a/bin/sh/exec.h b/bin/sh/exec.h
index 536c4431a2c..9c03616e868 100644
--- a/bin/sh/exec.h
+++ b/bin/sh/exec.h
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.h,v 1.11 1996/10/16 14:35:45 christos Exp $ */
+/* $NetBSD: exec.h,v 1.12 1997/02/06 23:24:53 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -69,3 +69,4 @@ void getcmdentry __P((char *, struct cmdentry *));
void addcmdentry __P((char *, struct cmdentry *));
void defun __P((char *, union node *));
int unsetfunc __P((char *));
+int typecmd __P((int, char **));
diff --git a/bin/sh/sh.1 b/bin/sh/sh.1
index 9a37d31b808..5f534485760 100644
--- a/bin/sh/sh.1
+++ b/bin/sh/sh.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: sh.1,v 1.17 1996/10/16 15:20:01 christos Exp $
+.\" $NetBSD: sh.1,v 1.18 1997/02/06 23:24:54 christos Exp $
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -1337,6 +1337,14 @@ resets trapped (but not ignored) signals to the
default action. The trap command has no effect on
signals that were ignored on entry to the shell.
.TP
+type [name]...
+Interpret each name as a command and print the
+resolution of the command search. Possible resolutions are:
+shell keyword, alias, shell builtin, command, tracked alias
+and not found. For aliases the alias expansion is printed;
+for commands and tracked aliases the complete pathname of
+the command is printed.
+.TP
umask [ mask ]
Set the value of umask (see umask(2)) to the specified
octal value. If the argument is omitted, the