diff options
author | tjr <tjr@FreeBSD.org> | 2002-12-26 14:28:54 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2002-12-26 14:28:54 +0000 |
commit | 3b9687df3d4851848f5e9ba0830f6c463fed6538 (patch) | |
tree | 33198111d52d850381eae7addd1a81f3c76e2923 /bin | |
parent | 89d815a706976c9d22c30011a3f1df19220d4026 (diff) | |
download | FreeBSD-src-3b9687df3d4851848f5e9ba0830f6c463fed6538.zip FreeBSD-src-3b9687df3d4851848f5e9ba0830f6c463fed6538.tar.gz |
Add the "wordexp" shell built-in command which will be used to implement
the POSIX wordexp() function.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/sh/builtins.def | 1 | ||||
-rw-r--r-- | bin/sh/expand.c | 22 | ||||
-rw-r--r-- | bin/sh/expand.h | 1 |
3 files changed, 24 insertions, 0 deletions
diff --git a/bin/sh/builtins.def b/bin/sh/builtins.def index 233e25f..a5d4542 100644 --- a/bin/sh/builtins.def +++ b/bin/sh/builtins.def @@ -93,3 +93,4 @@ aliascmd alias ulimitcmd ulimit testcmd test [ bindcmd bind +wordexpcmd wordexp diff --git a/bin/sh/expand.c b/bin/sh/expand.c index 73cedc0..d6d34c4 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); #include <stdlib.h> #include <limits.h> #include <stdio.h> +#include <string.h> /* * Routines to expand arguments to commands. We have to deal with @@ -1521,3 +1522,24 @@ cvtnum(int num, char *buf) STPUTC(*p++, buf); return buf; } + +/* + * Do most of the work for wordexp(3). + */ + +int +wordexpcmd(int argc, char **argv) +{ + size_t len; + int i; + + out1fmt("%08x", argc - 1); + for (i = 1, len = 0; i < argc; i++) + len += strlen(argv[i]); + out1fmt("%08x", (int)len); + for (i = 1; i < argc; i++) { + out1str(argv[i]); + out1c('\0'); + } + return (0); +} diff --git a/bin/sh/expand.h b/bin/sh/expand.h index 0fbd52a..9343bf3 100644 --- a/bin/sh/expand.h +++ b/bin/sh/expand.h @@ -65,3 +65,4 @@ void expari(int); int patmatch(char *, char *, int); void rmescapes(char *); int casematch(union node *, char *); +int wordexpcmd(int, char **); |