1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-14 10:09:48 +00:00

Add the "wordexp" shell built-in command which will be used to implement

the POSIX wordexp() function.
This commit is contained in:
Tim J. Robbins 2002-12-26 14:28:54 +00:00
parent 326b4d74c4
commit 2c25061f18
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=108286
3 changed files with 24 additions and 0 deletions

View File

@ -93,3 +93,4 @@ aliascmd alias
ulimitcmd ulimit ulimitcmd ulimit
testcmd test [ testcmd test [
bindcmd bind bindcmd bind
wordexpcmd wordexp

View File

@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
/* /*
* Routines to expand arguments to commands. We have to deal with * Routines to expand arguments to commands. We have to deal with
@ -1521,3 +1522,24 @@ cvtnum(int num, char *buf)
STPUTC(*p++, buf); STPUTC(*p++, buf);
return 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);
}

View File

@ -65,3 +65,4 @@ void expari(int);
int patmatch(char *, char *, int); int patmatch(char *, char *, int);
void rmescapes(char *); void rmescapes(char *);
int casematch(union node *, char *); int casematch(union node *, char *);
int wordexpcmd(int, char **);