summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/builtins.def1
-rw-r--r--bin/sh/expand.c54
-rw-r--r--bin/sh/parser.c33
-rw-r--r--bin/sh/parser.h1
4 files changed, 89 insertions, 0 deletions
diff --git a/bin/sh/builtins.def b/bin/sh/builtins.def
index 1cbeea9..8807347 100644
--- a/bin/sh/builtins.def
+++ b/bin/sh/builtins.def
@@ -65,6 +65,7 @@ exportcmd -s export -s readonly
#exprcmd expr
falsecmd false
fgcmd -j fg
+freebsd_wordexpcmd freebsd_wordexp
getoptscmd getopts
hashcmd hash
histcmd -h fc
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index 84e342d..1d86698 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -1660,3 +1660,57 @@ wordexpcmd(int argc, char **argv)
outbin(argv[i], strlen(argv[i]) + 1, out1);
return (0);
}
+
+/*
+ * Do most of the work for wordexp(3), new version.
+ */
+
+int
+freebsd_wordexpcmd(int argc __unused, char **argv __unused)
+{
+ struct arglist arglist;
+ union node *args, *n;
+ struct strlist *sp;
+ size_t count, len;
+ int ch;
+ int protected = 0;
+ int fd = -1;
+
+ while ((ch = nextopt("f:p")) != '\0') {
+ switch (ch) {
+ case 'f':
+ fd = number(shoptarg);
+ break;
+ case 'p':
+ protected = 1;
+ break;
+ }
+ }
+ if (*argptr != NULL)
+ error("wrong number of arguments");
+ if (fd < 0)
+ error("missing fd");
+ INTOFF;
+ setinputfd(fd, 1);
+ INTON;
+ args = parsewordexp();
+ popfile(); /* will also close fd */
+ if (protected)
+ for (n = args; n != NULL; n = n->narg.next) {
+ if (n->narg.backquote != NULL) {
+ outcslow('C', out1);
+ error("command substitution disabled");
+ }
+ }
+ outcslow(' ', out1);
+ arglist.lastp = &arglist.list;
+ for (n = args; n != NULL; n = n->narg.next)
+ expandarg(n, &arglist, EXP_FULL | EXP_TILDE);
+ *arglist.lastp = NULL;
+ for (sp = arglist.list, count = len = 0; sp; sp = sp->next)
+ count++, len += strlen(sp->text);
+ out1fmt("%016zx %016zx", count, len);
+ for (sp = arglist.list; sp; sp = sp->next)
+ outbin(sp->text, strlen(sp->text) + 1, out1);
+ return (0);
+}
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index b577a8a..cb4f1ec0 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -229,6 +229,39 @@ parsecmd(int interact)
}
+/*
+ * Read and parse words for wordexp.
+ * Returns a list of NARG nodes; NULL if there are no words.
+ */
+union node *
+parsewordexp(void)
+{
+ union node *n, *first = NULL, **pnext;
+ int t;
+
+ /* This assumes the parser is not re-entered,
+ * which could happen if we add command substitution on PS1/PS2.
+ */
+ parser_temp_free_all();
+ heredoclist = NULL;
+
+ tokpushback = 0;
+ checkkwd = 0;
+ doprompt = 0;
+ setprompt(0);
+ needprompt = 0;
+ pnext = &first;
+ while ((t = readtoken()) != TEOF) {
+ if (t != TWORD)
+ synexpect(TWORD);
+ n = makename();
+ *pnext = n;
+ pnext = &n->narg.next;
+ }
+ return first;
+}
+
+
static union node *
list(int nlflag)
{
diff --git a/bin/sh/parser.h b/bin/sh/parser.h
index 5982594..0c3cd88 100644
--- a/bin/sh/parser.h
+++ b/bin/sh/parser.h
@@ -76,6 +76,7 @@ extern const char *const parsekwd[];
union node *parsecmd(int);
+union node *parsewordexp(void);
void forcealias(void);
void fixredir(union node *, const char *, int);
int goodname(const char *);
OpenPOWER on IntegriCloud