Added support for nested quotes in arguments when calling external commands from Cooja

This commit is contained in:
Niclas Finne 2012-08-22 14:13:31 +02:00
parent 24dba740e2
commit c425e51911

View File

@ -43,7 +43,6 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
@ -89,11 +88,15 @@ public class CompileContiki {
final MessageList compilationOutput,
boolean synchronous)
throws Exception {
Pattern p = Pattern.compile("([^\\s\"']|\"[^\"]*\"|'[^']*')+");
Pattern p = Pattern.compile("([^\\s\"']+|\"[^\"]*\"|'[^']*')");
Matcher m = p.matcher(command);
ArrayList<String> commandList = new ArrayList<String>();
while(m.find()) {
commandList.add(m.group().replaceAll("['\"]",""));
String arg = m.group();
if (arg.length() > 1 && (arg.charAt(0) == '"' || arg.charAt(0) == '\'')) {
arg = arg.substring(1, arg.length() - 1);
}
commandList.add(arg);
}
return compile(commandList.toArray(new String[commandList.size()]), env, outputFile, directory, onSuccess, onFailure, compilationOutput, synchronous);
}