summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/what/what.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/usr.bin/what/what.c b/usr.bin/what/what.c
index 98c8122d4c4..03d47176078 100644
--- a/usr.bin/what/what.c
+++ b/usr.bin/what/what.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: what.c,v 1.2 1996/06/26 05:42:52 deraadt Exp $ */
+/* $OpenBSD: what.c,v 1.3 1996/06/26 06:40:11 deraadt Exp $ */
/* $NetBSD: what.c,v 1.4 1994/12/20 16:01:03 jtc Exp $ */
/*
@@ -44,12 +44,15 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)what.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: what.c,v 1.2 1996/06/26 05:42:52 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: what.c,v 1.3 1996/06/26 06:40:11 deraadt Exp $";
#endif /* not lint */
+#include <sys/types.h>
+#include <sys/utsname.h>
#include <stdio.h>
+#include <ctype.h>
-void search __P((void));
+void search __P((char *));
/*
* what
@@ -60,26 +63,45 @@ main(argc, argv)
int argc;
char **argv;
{
+ struct utsname utsn;
+ char match[256];
+
+ if (uname(&utsn) == -1)
+ err(1, "uname");
+ strncpy(match, utsn.sysname, sizeof match);
+
if (!*++argv)
- search();
+ search(match);
else do {
if (!freopen(*argv, "r", stdin)) {
perror(*argv);
exit(1);
}
printf("%s\n", *argv);
- search();
+ search(match);
} while(*++argv);
exit(0);
}
void
-search()
+search(match)
+ char *match;
{
register int c;
+ int i;
while ((c = getchar()) != EOF) {
-loop: if (c != '@')
+loop: if (c == '$') {
+ for (i = 0; match[i]; i++)
+ if ((c = getchar()) != match[i])
+ goto loop;
+ printf("$%s", match);
+ while (isprint(c = getchar()))
+ putchar(c);
+ putchar('\n');
+ goto loop;
+ }
+ if (c != '@')
continue;
if ((c = getchar()) != '(')
goto loop;