summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorferrieux <ferrieux@users.sourceforge.net>2013-07-07 15:43:52 (GMT)
committerferrieux <ferrieux@users.sourceforge.net>2013-07-07 15:43:52 (GMT)
commitbc18d2757ecec54daca0bb88ed0db7e5c0bec34c (patch)
treef2356ed567ec3b4e01a09ff0dd6f25b00c178889
parent2dd82db7ae9e5978aeb64744956d20f14f0d99aa (diff)
downloadtcl-tip_improve_exec.zip
tcl-tip_improve_exec.tar.gz
tcl-tip_improve_exec.tar.bz2
First part of upcoming TIP - Improving [exec]'s syntax : the syntax extension (not the new redirects)tip_improve_exec
-rw-r--r--generic/tclPipe.c91
-rw-r--r--tests/exec.test8
2 files changed, 78 insertions, 21 deletions
diff --git a/generic/tclPipe.c b/generic/tclPipe.c
index 83fb818..85ac5bb 100644
--- a/generic/tclPipe.c
+++ b/generic/tclPipe.c
@@ -502,6 +502,9 @@ TclCreatePipeline(
TclFile pipeIn;
TclFile curInFile, curOutFile, curErrFile;
Tcl_Channel channel;
+ int newSyntax = 0;
+ int subArgc;
+ const char **subArgv = NULL;
if (inPipePtr != NULL) {
*inPipePtr = NULL;
@@ -537,11 +540,20 @@ TclCreatePipeline(
cmdCount = 1;
needCmd = 1;
for (i = 0; i < argc; i++) {
+ if (newSyntax && needCmd) {
+ needCmd = 0;
+ continue;
+ }
errorToOutput = 0;
skip = 0;
p = argv[i];
switch (*p++) {
case '|':
+ if ((i == 0) && (*p == '\0')) {
+ newSyntax = 1;
+ lastBar = 0;
+ continue;
+ }
if (*p == '&') {
p++;
}
@@ -707,11 +719,23 @@ TclCreatePipeline(
break;
default:
- /*
- * Got a command word, not a redirection.
- */
- needCmd = 0;
+ if (newSyntax) {
+ Tcl_SetObjResult(interp,
+ Tcl_ObjPrintf(
+ "Unsupported redirection \"%s\"",
+ argv[i]));
+ Tcl_SetErrorCode(interp, "TCL", "OPERATION", "EXEC",
+ "PIPESYNTAX", NULL);
+ goto error;
+ } else {
+
+ /*
+ * Got a command word, not a redirection.
+ */
+
+ needCmd = 0;
+ }
break;
}
@@ -859,17 +883,32 @@ TclCreatePipeline(
curInFile = inputFile;
+ lastArg = argc; /* compiler warning */
+
for (i = 0; i < argc; i = lastArg + 1) {
int result, joinThisError;
Tcl_Pid pid;
const char *oldName;
- /*
- * Convert the program name into native form.
- */
-
- if (Tcl_TranslateFileName(interp, argv[i], &execBuffer) == NULL) {
- goto error;
+ if (newSyntax) {
+ if (i == 0) {
+ lastArg = i;
+ continue;
+ }
+ if (Tcl_SplitList(interp, argv[i], &subArgc, &subArgv) != TCL_OK) {
+ goto error;
+ }
+ if (Tcl_TranslateFileName(interp, subArgv[0], &execBuffer) == NULL) {
+ goto error;
+ }
+ } else {
+ /*
+ * Convert the program name into native form.
+ */
+
+ if (Tcl_TranslateFileName(interp, argv[i], &execBuffer) == NULL) {
+ goto error;
+ }
}
/*
@@ -913,16 +952,24 @@ TclCreatePipeline(
curErrFile = errorFile;
}
- /*
- * Restore argv[i], since a caller wouldn't expect the contents of
- * argv to be modified.
- */
-
- oldName = argv[i];
- argv[i] = Tcl_DStringValue(&execBuffer);
- result = TclpCreateProcess(interp, lastArg - i, argv + i,
- curInFile, curOutFile, curErrFile, &pid);
- argv[i] = oldName;
+ if (newSyntax) {
+ subArgv[0] = Tcl_DStringValue(&execBuffer);
+ result = TclpCreateProcess(interp, subArgc, subArgv,
+ curInFile, curOutFile, curErrFile, &pid);
+ ckfree(subArgv);
+ subArgv = NULL;
+ } else {
+ /*
+ * Restore argv[i], since a caller wouldn't expect the contents of
+ * argv to be modified.
+ */
+
+ oldName = argv[i];
+ argv[i] = Tcl_DStringValue(&execBuffer);
+ result = TclpCreateProcess(interp, lastArg - i, argv + i,
+ curInFile, curOutFile, curErrFile, &pid);
+ argv[i] = oldName;
+ }
if (result != TCL_OK) {
goto error;
}
@@ -1010,6 +1057,10 @@ TclCreatePipeline(
}
ckfree(pidPtr);
}
+ if (subArgv != NULL) {
+ ckfree(subArgv);
+ subArgv = NULL;
+ }
numPids = -1;
goto cleanup;
}
diff --git a/tests/exec.test b/tests/exec.test
index 871c0c5..39363ad 100644
--- a/tests/exec.test
+++ b/tests/exec.test
@@ -372,7 +372,7 @@ test exec-10.1 {errors in exec invocation} -constraints {exec} -body {
exec
} -returnCodes error -result {wrong # args: should be "exec ?-switch ...? arg ?arg ...?"}
test exec-10.2 {errors in exec invocation} -constraints {exec} -body {
- exec | cat
+ exec |& cat
} -returnCodes error -result {illegal use of | or |& in command}
test exec-10.3 {errors in exec invocation} -constraints {exec} -body {
exec cat |
@@ -682,6 +682,12 @@ test exec-19.1 {exec >> uses O_APPEND} -constraints {exec unix} -setup {
} -cleanup {
removeFile $tmpfile
} -result 14
+
+# New Syntax
+test exec-20.1 {New exec syntax with sublists} {exec} {
+ exec | {echo >}
+} >
+
# ----------------------------------------------------------------------
# cleanup