[Swift-commit] r4248 - in trunk: libexec src/org/griphyn/vdl/engine src/org/griphyn/vdl/karajan/lib/swiftscript tests/functions
wozniak at ci.uchicago.edu
wozniak at ci.uchicago.edu
Sun Apr 3 15:53:12 CDT 2011
Author: wozniak
Date: 2011-04-03 15:53:12 -0500 (Sun, 03 Apr 2011)
New Revision: 4248
Added:
trunk/tests/functions/500-exists.check.sh
trunk/tests/functions/500-exists.clean.sh
trunk/tests/functions/500-exists.setup.sh
trunk/tests/functions/500-exists.swift
Modified:
trunk/libexec/vdl-lib.xml
trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
Log:
New @exist_file() and test
Modified: trunk/libexec/vdl-lib.xml
===================================================================
--- trunk/libexec/vdl-lib.xml 2011-04-03 20:42:16 UTC (rev 4247)
+++ trunk/libexec/vdl-lib.xml 2011-04-03 20:53:12 UTC (rev 4248)
@@ -7,6 +7,7 @@
<export name="readdata2"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.ReadData2"/></export>
<export name="writedata"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.WriteData"/></export>
<export name="strcat"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
+ <export name="exists_file"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="strcut"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="strstr"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
<export name="strsplit"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.Misc"/></export>
Modified: trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java 2011-04-03 20:42:16 UTC (rev 4247)
+++ trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java 2011-04-03 20:53:12 UTC (rev 4248)
@@ -7,7 +7,7 @@
public class ProcedureSignature {
-
+
private String name;
private ArrayList inputArgs;
private ArrayList outputArgs;
@@ -20,7 +20,7 @@
/* Procedure is user defined. */
static public final int INVOCATION_USERDEFINED = 601;
-
+
public ProcedureSignature(String name) {
this.name = name;
inputArgs = new ArrayList();
@@ -29,64 +29,64 @@
anyNumOfOutputArgs = false;
invocationMode = INVOCATION_USERDEFINED;
}
-
+
public String getName() {
return name;
}
-
+
public void addInputArg(FormalArgumentSignature inputArg) {
inputArgs.add(inputArg);
}
-
+
public void addOutputArg(FormalArgumentSignature outputArg) {
outputArgs.add(outputArg);
}
-
+
public void setAnyNumOfInputArgs() {
anyNumOfInputArgs = true;
}
-
+
public void setAnyNumOfOutputArgs() {
anyNumOfOutputArgs = true;
}
-
- public boolean getAnyNumOdInputArgs() {
+
+ public boolean getAnyNumOfInputArgs() {
return anyNumOfInputArgs;
}
-
- public boolean getAnyNumOdOutputArgs() {
+
+ public boolean getAnyNumOfOutputArgs() {
return anyNumOfOutputArgs;
}
-
+
public int sizeOfInputArray() {
return inputArgs.size();
}
-
+
public int sizeOfOutputArray() {
return outputArgs.size();
}
-
- private static final FormalArgumentSignature[] FORMAL_ARGUMENT_SIGNATURE_ARRAY =
+
+ private static final FormalArgumentSignature[] FORMAL_ARGUMENT_SIGNATURE_ARRAY =
new FormalArgumentSignature[0];
-
+
public FormalArgumentSignature[] getInputArray() {
- return (FormalArgumentSignature[])
+ return (FormalArgumentSignature[])
inputArgs.toArray(FORMAL_ARGUMENT_SIGNATURE_ARRAY);
}
-
+
public FormalArgumentSignature[] getOutputArray() {
- return (FormalArgumentSignature[])
+ return (FormalArgumentSignature[])
outputArgs.toArray(FORMAL_ARGUMENT_SIGNATURE_ARRAY);
}
-
+
public FormalArgumentSignature getInputArray(int i) {
return (FormalArgumentSignature) inputArgs.get(i);
}
-
+
public FormalArgumentSignature getOutputArray(int i) {
return (FormalArgumentSignature) outputArgs.get(i);
}
-
+
public void setInputArgs(FormalParameter[] fp) {
for (int i = 0; i < fp.length; i++) {
FormalArgumentSignature fas = new FormalArgumentSignature(fp[i].getType().getLocalPart(),
@@ -95,7 +95,7 @@
this.addInputArg(fas);
}
}
-
+
public void setOutputArgs(FormalParameter[] fp) {
for (int i = 0; i < fp.length; i++) {
FormalArgumentSignature fas = new FormalArgumentSignature(fp[i].getType().getLocalPart(),
@@ -113,26 +113,26 @@
public int getInvocationMode() {
return this.invocationMode;
}
-
+
public static HashMap makeProcedureSignatures() {
HashMap proceduresMap = new HashMap();
-
+
ProcedureSignature readData = new ProcedureSignature("readData");
FormalArgumentSignature rdInputArg = new FormalArgumentSignature(true);
readData.addInputArg(rdInputArg);
FormalArgumentSignature rdOutputArg = new FormalArgumentSignature(true);
- readData.addOutputArg(rdOutputArg);
+ readData.addOutputArg(rdOutputArg);
readData.setInvocationMode(INVOCATION_INTERNAL);
proceduresMap.put("readData", readData);
-
+
ProcedureSignature readData2 = new ProcedureSignature("readData2");
FormalArgumentSignature rd2InputArg = new FormalArgumentSignature(true);
readData2.addInputArg(rd2InputArg);
FormalArgumentSignature rd2OutputArg = new FormalArgumentSignature(true);
- readData2.addOutputArg(rd2OutputArg);
+ readData2.addOutputArg(rd2OutputArg);
readData2.setInvocationMode(INVOCATION_INTERNAL);
proceduresMap.put("readData2", readData2);
-
+
ProcedureSignature trace = new ProcedureSignature("trace");
trace.setAnyNumOfInputArgs();
trace.setInvocationMode(INVOCATION_INTERNAL);
@@ -142,55 +142,55 @@
tracef.setAnyNumOfInputArgs();
tracef.setInvocationMode(INVOCATION_INTERNAL);
proceduresMap.put("tracef", tracef);
-
+
ProcedureSignature fprintf = new ProcedureSignature("ftracef");
fprintf.setAnyNumOfInputArgs();
fprintf.setInvocationMode(INVOCATION_INTERNAL);
proceduresMap.put("fprintf", fprintf);
-
+
ProcedureSignature assrt = new ProcedureSignature("assert");
assrt.setAnyNumOfInputArgs();
assrt.setInvocationMode(INVOCATION_INTERNAL);
proceduresMap.put("assert", assrt);
-
+
ProcedureSignature writeData = new ProcedureSignature("writeData");
FormalArgumentSignature wdInputArg = new FormalArgumentSignature(true);
writeData.addInputArg(wdInputArg);
FormalArgumentSignature wdOutputArg = new FormalArgumentSignature(true);
- writeData.addOutputArg(wdOutputArg);
+ writeData.addOutputArg(wdOutputArg);
writeData.setInvocationMode(INVOCATION_INTERNAL);
proceduresMap.put("writeData", writeData);
-
+
return proceduresMap;
}
-
+
public static HashMap makeFunctionSignatures () {
HashMap functionsMap = new HashMap();
-
+
ProcedureSignature arg = new ProcedureSignature("arg");
FormalArgumentSignature argIn1 = new FormalArgumentSignature("string");
arg.addInputArg(argIn1);
- FormalArgumentSignature argIn2 = new FormalArgumentSignature("string");
+ FormalArgumentSignature argIn2 = new FormalArgumentSignature("string");
argIn2.setOptional(true);
arg.addInputArg(argIn2);
FormalArgumentSignature argOut1 = new FormalArgumentSignature("string");
arg.addOutputArg(argOut1);
functionsMap.put(arg.getName(), arg);
-
+
ProcedureSignature extractint = new ProcedureSignature("extractint");
FormalArgumentSignature extractintIn1 = new FormalArgumentSignature(true); /* file can be specified as any type */
extractint.addInputArg(extractintIn1);
FormalArgumentSignature extractintOut1 = new FormalArgumentSignature("int");
extractint.addOutputArg(extractintOut1);
functionsMap.put(extractint.getName(), extractint);
-
+
ProcedureSignature filename = new ProcedureSignature("filename");
FormalArgumentSignature filenameIn1 = new FormalArgumentSignature(true); /* file can be specified as any type */
filename.addInputArg(filenameIn1);
FormalArgumentSignature filenameOut1 = new FormalArgumentSignature("string");
filename.addOutputArg(filenameOut1);
functionsMap.put(filename.getName(), filename);
-
+
ProcedureSignature filenames = new ProcedureSignature("filenames");
FormalArgumentSignature filenamesIn1 = new FormalArgumentSignature(true); /* file can be specified as any type */
filenames.addInputArg(filenamesIn1);
@@ -204,14 +204,14 @@
FormalArgumentSignature dirnameOut1 = new FormalArgumentSignature("string");
dirname.addOutputArg(dirnameOut1);
functionsMap.put(dirname.getName(), dirname);
-
+
ProcedureSignature length = new ProcedureSignature("length");
FormalArgumentSignature lengthIn1 = new FormalArgumentSignature(true);
length.addInputArg(lengthIn1);
FormalArgumentSignature lengthOut1 = new FormalArgumentSignature("int");
length.addOutputArg(lengthOut1);
functionsMap.put(length.getName(), length);
-
+
ProcedureSignature regexp = new ProcedureSignature("regexp");
FormalArgumentSignature regexpIn1 = new FormalArgumentSignature("string");
regexp.addInputArg(regexpIn1);
@@ -222,19 +222,19 @@
FormalArgumentSignature regexpOut1 = new FormalArgumentSignature("string");
regexp.addOutputArg(regexpOut1);
functionsMap.put(regexp.getName(), regexp);
-
+
ProcedureSignature strcat = new ProcedureSignature("strcat");
strcat.setAnyNumOfInputArgs();
FormalArgumentSignature strcatOut1 = new FormalArgumentSignature("string");
strcat.addOutputArg(strcatOut1);
functionsMap.put(strcat.getName(), strcat);
-
+
ProcedureSignature sprintf = new ProcedureSignature("sprintf");
- sprintf.setAnyNumOfInputArgs();
- FormalArgumentSignature sprintfOut1 = new FormalArgumentSignature("string");
- sprintf.addOutputArg(sprintfOut1);
- functionsMap.put(sprintf.getName(), sprintf);
-
+ sprintf.setAnyNumOfInputArgs();
+ FormalArgumentSignature sprintfOut1 = new FormalArgumentSignature("string");
+ sprintf.addOutputArg(sprintfOut1);
+ functionsMap.put(sprintf.getName(), sprintf);
+
ProcedureSignature strcut = new ProcedureSignature("strcut");
FormalArgumentSignature strcutIn1 = new FormalArgumentSignature("string");
strcut.addInputArg(strcutIn1);
@@ -252,7 +252,7 @@
FormalArgumentSignature strstrOut1 = new FormalArgumentSignature("int");
strstr.addOutputArg(strstrOut1);
functionsMap.put(strstr.getName(), strstr);
-
+
ProcedureSignature strsplit = new ProcedureSignature("strsplit");
FormalArgumentSignature strsplitIn1 = new FormalArgumentSignature("string");
strsplit.addInputArg(strsplitIn1);
@@ -261,7 +261,7 @@
FormalArgumentSignature strsplitOut1 = new FormalArgumentSignature("string[]");
strsplit.addOutputArg(strsplitOut1);
functionsMap.put(strsplit.getName(), strsplit);
-
+
ProcedureSignature toint = new ProcedureSignature("toint");
FormalArgumentSignature tointIn1 = new FormalArgumentSignature(true);
toint.addInputArg(tointIn1);
@@ -275,7 +275,7 @@
FormalArgumentSignature tofloatOut1 = new FormalArgumentSignature("float");
tofloat.addOutputArg(tofloatOut1);
functionsMap.put(tofloat.getName(), tofloat);
-
+
ProcedureSignature format = new ProcedureSignature("format");
FormalArgumentSignature formatIn1 = new FormalArgumentSignature("float");
FormalArgumentSignature formatIn2 = new FormalArgumentSignature("int");
@@ -284,7 +284,7 @@
FormalArgumentSignature formatOut = new FormalArgumentSignature("string");
format.addOutputArg(formatOut);
functionsMap.put(format.getName(), format);
-
+
ProcedureSignature pad = new ProcedureSignature("pad");
FormalArgumentSignature padIn1 = new FormalArgumentSignature("int");
FormalArgumentSignature padIn2 = new FormalArgumentSignature("int");
@@ -293,23 +293,29 @@
FormalArgumentSignature padOut = new FormalArgumentSignature("string");
pad.addOutputArg(padOut);
functionsMap.put(pad.getName(), pad);
-
+
ProcedureSignature tostring = new ProcedureSignature("tostring");
FormalArgumentSignature tostringIn1 = new FormalArgumentSignature(true);
tostring.addInputArg(tostringIn1);
FormalArgumentSignature tostringOut1 = new FormalArgumentSignature("string");
tostring.addOutputArg(tostringOut1);
functionsMap.put(tostring.getName(), tostring);
-
+
ProcedureSignature java = new ProcedureSignature("java");
java.setAnyNumOfInputArgs();
FormalArgumentSignature output = new FormalArgumentSignature("java");
java.addOutputArg(output);
functionsMap.put(java.getName(), java);
-
+
+ ProcedureSignature exists_file = new ProcedureSignature("exists_file");
+ exists_file.setAnyNumOfInputArgs();
+ FormalArgumentSignature exists_fileOut1 = new FormalArgumentSignature("boolean");
+ exists_file.addOutputArg(exists_fileOut1);
+ functionsMap.put(exists_file.getName(), exists_file);
+
return functionsMap;
}
-
+
public String toString() {
return outputArgs + " " + name + inputArgs;
}
Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2011-04-03 20:42:16 UTC (rev 4247)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/Misc.java 2011-04-03 20:53:12 UTC (rev 4248)
@@ -19,7 +19,6 @@
import org.griphyn.vdl.mapping.Path;
import org.griphyn.vdl.mapping.RootArrayDataNode;
import org.griphyn.vdl.mapping.RootDataNode;
-import org.griphyn.vdl.type.NoSuchTypeException;
import org.griphyn.vdl.type.Types;
import org.griphyn.vdl.util.VDL2Config;
@@ -38,9 +37,10 @@
static {
setArguments("swiftscript_trace", new Arg[] { Arg.VARGS });
- setArguments("swiftscript_strcat", new Arg[] { Arg.VARGS });
+ setArguments("swiftscript_strcat", new Arg[] { Arg.VARGS });
+ setArguments("swiftscript_exists_file", new Arg[] { Arg.VARGS });
setArguments("swiftscript_strcut", new Arg[] { PA_INPUT, PA_PATTERN });
- setArguments("swiftscript_strstr", new Arg[] { PA_INPUT, PA_PATTERN });
+ setArguments("swiftscript_strstr", new Arg[] { PA_INPUT, PA_PATTERN });
setArguments("swiftscript_strsplit", new Arg[] { PA_INPUT, PA_PATTERN });
setArguments("swiftscript_regexp", new Arg[] { PA_INPUT, PA_PATTERN, PA_TRANSFORM });
setArguments("swiftscript_toint", new Arg[] { PA_INPUT });
@@ -50,11 +50,12 @@
setArguments("swiftscript_tostring", new Arg[] { PA_INPUT });
setArguments("swiftscript_dirname", new Arg[] { Arg.VARGS });
setArguments("swiftscript_length", new Arg[] { Arg.VARGS });
+ setArguments("swiftscript_exists", new Arg[] { Arg.VARGS });
}
- private static final Logger traceLogger =
+ private static final Logger traceLogger =
Logger.getLogger("org.globus.swift.trace");
- public DSHandle swiftscript_trace(VariableStack stack)
+ public DSHandle swiftscript_trace(VariableStack stack)
throws ExecutionException {
DSHandle[] args = SwiftArg.VARGS.asDSHandleArray(stack);
@@ -70,9 +71,10 @@
traceLogger.warn(buf);
return null;
}
-
- public DSHandle swiftscript_strcat(VariableStack stack)
+
+ public DSHandle swiftscript_strcat(VariableStack stack)
throws ExecutionException {
+ logger.debug(stack);
Object[] args = SwiftArg.VARGS.asArray(stack);
int provid = VDLFunction.nextProvenanceID();
StringBuffer buf = new StringBuffer();
@@ -96,9 +98,47 @@
return handle;
}
- public DSHandle swiftscript_strcut(VariableStack stack)
+ public DSHandle swiftscript_exists_file(VariableStack stack)
throws ExecutionException {
+ logger.debug(stack);
+ Object[] args = SwiftArg.VARGS.asArray(stack);
int provid = VDLFunction.nextProvenanceID();
+
+ if (args.length != 1)
+ throw new ExecutionException
+ ("Wrong number of arguments to @exists_file()");
+
+ String filename = TypeUtil.toString(args[0]);
+
+ DSHandle handle = new RootDataNode(Types.BOOLEAN);
+ AbsFile file = new AbsFile(filename);
+ logger.debug("exists_file: " + file);
+ handle.setValue(file.exists());
+ handle.closeShallow();
+
+ try {
+ if(VDL2Config.getConfig().getProvenanceLog()) {
+ DSHandle[] provArgs =
+ SwiftArg.VARGS.asDSHandleArray(stack);
+ for (int i = 0; i < provArgs.length; i++) {
+ VDLFunction.logProvenanceParameter
+ (provid, provArgs[i], ""+i);
+ }
+ VDLFunction.logProvenanceResult
+ (provid, handle, "exists_file");
+ }
+ } catch (IOException ioe) {
+ throw new ExecutionException
+ ("When logging provenance for exists_file",
+ ioe);
+ }
+
+ return handle;
+ }
+
+ public DSHandle swiftscript_strcut(VariableStack stack)
+ throws ExecutionException {
+ int provid = VDLFunction.nextProvenanceID();
String inputString = TypeUtil.toString(PA_INPUT.getValue(stack));
String pattern = TypeUtil.toString(PA_PATTERN.getValue(stack));
if (logger.isDebugEnabled()) {
@@ -129,13 +169,13 @@
VDLFunction.logProvenanceParameter(provid, PA_PATTERN.getRawValue(stack), "pattern");
return handle;
}
-
- public DSHandle swiftscript_strstr(VariableStack stack)
+
+ public DSHandle swiftscript_strstr(VariableStack stack)
throws ExecutionException {
String inputString = TypeUtil.toString(PA_INPUT.getValue(stack));
String pattern = TypeUtil.toString(PA_PATTERN.getValue(stack));
if (logger.isDebugEnabled()) {
- logger.debug("strstr will search '" + inputString +
+ logger.debug("strstr will search '" + inputString +
"' for pattern '" + pattern + "'");
}
int result = inputString.indexOf(pattern);
@@ -144,10 +184,10 @@
handle.closeShallow();
return handle;
}
-
- public DSHandle swiftscript_strsplit(VariableStack stack)
+
+ public DSHandle swiftscript_strsplit(VariableStack stack)
throws ExecutionException, InvalidPathException {
-
+
String str = TypeUtil.toString(PA_INPUT.getValue(stack));
String pattern = TypeUtil.toString(PA_PATTERN.getValue(stack));
@@ -166,7 +206,7 @@
return handle;
}
- public DSHandle swiftscript_regexp(VariableStack stack)
+ public DSHandle swiftscript_regexp(VariableStack stack)
throws ExecutionException {
String inputString = TypeUtil.toString(PA_INPUT.getValue(stack));
String pattern = TypeUtil.toString(PA_PATTERN.getValue(stack));
@@ -203,7 +243,7 @@
return handle;
}
- public DSHandle swiftscript_toint(VariableStack stack)
+ public DSHandle swiftscript_toint(VariableStack stack)
throws ExecutionException {
String inputString = TypeUtil.toString(PA_INPUT.getValue(stack));
int i = inputString.indexOf(".");
@@ -212,7 +252,7 @@
inputString = inputString.substring(0, i);
}
DSHandle handle = new RootDataNode(Types.INT);
-
+
try
{
handle.setValue(new Double(inputString));
@@ -222,18 +262,18 @@
throw new ExecutionException(stack, "Could not convert value \""+inputString+"\" to type int");
}
handle.closeShallow();
-
+
int provid=VDLFunction.nextProvenanceID();
VDLFunction.logProvenanceResult(provid, handle, "toint");
VDLFunction.logProvenanceParameter(provid, PA_INPUT.getRawValue(stack), "string");
return handle;
}
- public DSHandle swiftscript_tofloat(VariableStack stack)
+ public DSHandle swiftscript_tofloat(VariableStack stack)
throws ExecutionException {
String inputString = TypeUtil.toString(PA_INPUT.getValue(stack));
DSHandle handle = new RootDataNode(Types.FLOAT);
-
+
try
{
handle.setValue(new Double(inputString));
@@ -248,52 +288,52 @@
VDLFunction.logProvenanceParameter(provid, PA_INPUT.getRawValue(stack), "string");
return handle;
}
-
+
/*
* Takes in a float and formats to desired precision and returns a string
*/
- public DSHandle swiftscript_format(VariableStack stack)
+ public DSHandle swiftscript_format(VariableStack stack)
throws ExecutionException {
String inputString = TypeUtil.toString(PA_INPUT.getValue(stack));
String inputFormat = TypeUtil.toString(PA_TRANSFORM.getValue(stack));
DSHandle handle = new RootDataNode(Types.STRING);
-
+
String output = String.format("%."+inputFormat+"f", Double.parseDouble(inputString));
handle.setValue(output);
handle.closeShallow();
-
+
int provid=VDLFunction.nextProvenanceID();
VDLFunction.logProvenanceResult(provid, handle, "format");
VDLFunction.logProvenanceParameter(provid, PA_INPUT.getRawValue(stack), "float");
VDLFunction.logProvenanceParameter(provid, PA_TRANSFORM.getRawValue(stack), "float");
return handle;
}
-
+
/*
* Takes in an int and pads zeros to the left and returns a string
*/
- public DSHandle swiftscript_pad(VariableStack stack)
+ public DSHandle swiftscript_pad(VariableStack stack)
throws ExecutionException {
String inputString = TypeUtil.toString(PA_INPUT.getValue(stack));
String inputFormat = TypeUtil.toString(PA_TRANSFORM.getValue(stack));
- DSHandle handle = new RootDataNode(Types.STRING);
-
+ DSHandle handle = new RootDataNode(Types.STRING);
+
int num_length = inputString.length();
int zeros_to_pad = Integer.parseInt(inputFormat);
zeros_to_pad += num_length;
-
- String output = String.format("%0"+zeros_to_pad+"d",
+
+ String output = String.format("%0"+zeros_to_pad+"d",
Integer.parseInt(inputString));
handle.setValue(output);
handle.closeShallow();
-
+
int provid=VDLFunction.nextProvenanceID();
VDLFunction.logProvenanceResult(provid, handle, "pad");
VDLFunction.logProvenanceParameter(provid, PA_INPUT.getRawValue(stack), "int");
VDLFunction.logProvenanceParameter(provid, PA_TRANSFORM.getRawValue(stack), "int");
return handle;
}
-
+
public DSHandle swiftscript_tostring(VariableStack stack)
throws ExecutionException {
Object input = PA_INPUT.getValue(stack);
@@ -303,7 +343,7 @@
return handle;
}
- public DSHandle swiftscript_dirname(VariableStack stack)
+ public DSHandle swiftscript_dirname(VariableStack stack)
throws ExecutionException {
DSHandle handle;
try
@@ -311,7 +351,7 @@
DSHandle[] args = SwiftArg.VARGS.asDSHandleArray(stack);
DSHandle arg = args[0];
String[] input = VDLFunction.filename(arg);
- String name = input[0];
+ String name = input[0];
String result = new AbsFile(name).getDir();
handle = new RootDataNode(Types.STRING);
handle.setValue(result);
@@ -323,39 +363,54 @@
}
return handle;
}
-
+
/*
- * This is copied from swiftscript_dirname.
+ * This is copied from swiftscript_dirname.
* Both the functions could be changed to be more readable.
* Returns length of an array.
- * Good for debugging because array needs to be closed
+ * Good for debugging because array needs to be closed
* before the length is determined
*/
- public DSHandle swiftscript_length(VariableStack stack)
+ public DSHandle swiftscript_length(VariableStack stack)
throws ExecutionException {
DSHandle handle;
- DSHandle[] args = SwiftArg.VARGS.asDSHandleArray( stack );
+ DSHandle[] args = SwiftArg.VARGS.asDSHandleArray(stack);
DSHandle arg = args[0];
ArrayDataNode adn = (ArrayDataNode)arg;
-
+
if( !( adn.isClosed() ) )
{
throw new FutureNotYetAvailable
(VDLFunction.addFutureListener(stack, adn));
}
-
+
int result = adn.size();
handle = new RootDataNode(Types.INT);
handle.setValue(result);
handle.closeShallow();
-
+
return handle;
}
+
+ public DSHandle swiftscript_existsfile(VariableStack stack)
+ throws ExecutionException {
+ logger.debug(stack);
+ DSHandle result = null;
+ Object[] args = SwiftArg.VARGS.asArray(stack);
+ String arg = (String) args[0];
+ AbsFile file = new AbsFile(arg);
+ boolean b = file.exists();
+ result = new RootDataNode(Types.BOOLEAN);
+ result.setValue(b);
+ result.closeShallow();
+
+ return result;
+ }
}
/*
* Local Variables:
- * c-basic-offset: 8
+ * c-basic-offset: 4
* End:
*
* vim: ft=c ts=8 sts=4 sw=4 expandtab
Added: trunk/tests/functions/500-exists.check.sh
===================================================================
--- trunk/tests/functions/500-exists.check.sh (rev 0)
+++ trunk/tests/functions/500-exists.check.sh 2011-04-03 20:53:12 UTC (rev 4248)
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+set -x
+
+# FILES=( $( ls 400-fprintf-*.out ) )
+# (( ${#FILES[@]} == 3 )) || exit 1
+
+# grep hello 400-fprintf-1.out || exit 1
+
+# LINES=$( wc -l 400-fprintf-2.out | cut -d ' ' -f 1 )
+# (( ${LINES} == 3 )) || exit 1
+
+# grep "hello: 32" 400-fprintf-3.out || exit 1
+
+exit 0
Property changes on: trunk/tests/functions/500-exists.check.sh
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/tests/functions/500-exists.clean.sh
===================================================================
--- trunk/tests/functions/500-exists.clean.sh (rev 0)
+++ trunk/tests/functions/500-exists.clean.sh 2011-04-03 20:53:12 UTC (rev 4248)
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+# rm -v file.txt || exit 1
+
+exit 0
Property changes on: trunk/tests/functions/500-exists.clean.sh
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/tests/functions/500-exists.setup.sh
===================================================================
--- trunk/tests/functions/500-exists.setup.sh (rev 0)
+++ trunk/tests/functions/500-exists.setup.sh 2011-04-03 20:53:12 UTC (rev 4248)
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+touch file.txt
+rm -fv file-missing.txt
+
+exit 0
Property changes on: trunk/tests/functions/500-exists.setup.sh
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/tests/functions/500-exists.swift
===================================================================
--- trunk/tests/functions/500-exists.swift (rev 0)
+++ trunk/tests/functions/500-exists.swift 2011-04-03 20:53:12 UTC (rev 4248)
@@ -0,0 +1,11 @@
+
+string s1 = "file.txt";
+string s2 = "file-missing.txt";
+
+boolean b1, b2;
+
+b1 = @exists_file(s1);
+b2 = @exists_file(s2);
+
+tracef("%s: %p\n%s: %p\n",
+ s1, b1, s2, b2);
More information about the Swift-commit
mailing list