Skip to content
Snippets Groups Projects
Commit de266513 authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

Update on CLI for TTool

parent 2d9703ef
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@
<module fileurl="file://$PROJECT_DIR$/tiftranslator/src/main/tiftranslator.iml" filepath="$PROJECT_DIR$/tiftranslator/src/main/tiftranslator.iml" />
<module fileurl="file://$PROJECT_DIR$/tmltranslator/src/main/tmltranslator.iml" filepath="$PROJECT_DIR$/tmltranslator/src/main/tmltranslator.iml" />
<module fileurl="file://$PROJECT_DIR$/ttool/src/main/ttool.iml" filepath="$PROJECT_DIR$/ttool/src/main/ttool.iml" />
<module fileurl="file://$PROJECT_DIR$/ttool-cli/ttool-cli.iml" filepath="$PROJECT_DIR$/ttool-cli/ttool-cli.iml" />
<module fileurl="file://$PROJECT_DIR$/webcrawler/client/src/main/webcrawler-client.iml" filepath="$PROJECT_DIR$/webcrawler/client/src/main/webcrawler-client.iml" />
<module fileurl="file://$PROJECT_DIR$/webcrawler/server/src/main/webcrawler-server.iml" filepath="$PROJECT_DIR$/webcrawler/server/src/main/webcrawler-server.iml" />
</modules>
......
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package cli;
import java.util.BitSet;
import java.util.*;
/**
* Class Action
* Creation: 05/10/2018
* Version 2.0 05/10/2018
*
* @author Ludovic APVRILLE
*/
public class Action extends Command {
private final String[] SUB_COMMANDS = {"open"};
public Action() {
}
public String[] getListOfSubCommands() {
return SUB_COMMANDS;
}
public String getCommand() {
return "action";
}
public String getShortCommand() {
return "a";
}
public boolean executeCommand(String command, InterpreterOutputInterface output) {
return true;
}
}
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package cli;
import java.util.BitSet;
import java.util.*;
/**
* Class Command
* Creation: 05/10/2018
* Version 2.0 05/10/2018
*
* @author Ludovic APVRILLE
*/
public abstract class Command {
public abstract String[] getListOfSubCommands();
public abstract String getCommand();
public abstract String getShortCommand();
public abstract boolean executeCommand(String command, InterpreterOutputInterface output);
}
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package cli;
import myutil.Conversion;
import java.util.*;
/**
* Class Interpreter
* Creation: 05/10/2018
* Version 2.0 05/10/2018
*
* @author Ludovic APVRILLE
*/
public class Interpreter {
private final static Command[] commands = {new Action()};
private String script;
private HashMap<String, String> variables;
InterpreterOutputInterface printInterface;
public Interpreter(String script, InterpreterOutputInterface printInterface) {
this.script = script;
this.printInterface = printInterface;
variables = new HashMap<>();
}
public void interpret() {
Scanner scanner = new Scanner(script);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
// Replace all double space by one unique space
line = Conversion.replaceAllString(line, " ", " ");
// Replace variable value in the current line
String lineWithNoVariable = removeVariablesIn(line);
// Analyze current line
}
scanner.close();
printInterface.print("All done. See you soon.");
printInterface.exit(1);
}
private String removeVariablesIn(String input) {
String ret = "";
String initialLine = input;
int index;
while((index = input.indexOf("$")) > -1) {
ret = ret + input.substring(0, index);
input = input.substring(index+1, input.length());
int indexSpace = input.indexOf(" ");
String varName;
if (indexSpace == -1) {
varName = input;
input = "";
} else {
varName = input.substring(0, indexSpace);
input = input.substring(indexSpace+1, input.length());
}
// Identifying variable
String value = variables.get(varName);
if (value == null) {
printInterface.printError("Unknown variable name:" + varName + " in " + initialLine);
printInterface.exit(-1);
}
}
ret = ret + input;
return ret;
}
}
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package cli;
import java.util.BitSet;
import java.util.*;
/**
* Class InterpreterOutputInterface
* Creation: 05/10/2018
* Version 2.0 05/10/2018
*
* @author Ludovic APVRILLE
*/
public interface InterpreterOutputInterface {
public void print(String s);
public void printError(String s);
public void exit(int status);
}
PREFIX = [$(COLOR)GRAPHMINIMIZE$(RESET)]
PREFIX = [$(COLOR)TTOOLCLI$(RESET)]
MANIFEST = $(GRAPHMINIMIZE_DIR)/manifest.txt
MANIFEST = $(TTOOLCLI_DIR)/manifest.txt
DEPEND = $(patsubst %,$(TTOOL_BUILD)/%,$(shell cat $(MANIFEST) | grep Class-Path | cut -d: -f2))
......
......@@ -41,6 +41,9 @@
import myutil.*;
import ui.*;
import cli.*;
import java.io.*;
......@@ -53,18 +56,18 @@ import ui.*;
* @author Ludovic APVRILLE
* @version 1.10 05/10/2018
*/
public class TToolCLI {
public class TToolCLI implements InterpreterOutputInterface {
public static void printCopyright() {
System.out.println("TToolCLI: (C) Telecom ParisTech, Ludovic APVRILLE ludovic.apvrille, andrea.enrici@telecom-paristech.fr");
System.out.println("GraphMinimize is released under a CECILL License. See http://www.cecill.info/index.en.html");
System.out.println("ttool-cli: (C) Telecom ParisTech, Ludovic APVRILLE ludovic.apvrille, andrea.enrici@telecom-paristech.fr");
System.out.println("ttool-cli is released under a CECILL License. See http://www.cecill.info/index.en.html");
System.out.println("For more information on TTool related technologies, please consult http://ttool.telecom-paristech.fr/");
System.out.println("Enjoy!!!\n");
}
public static void printUsage() {
System.out.println("TToolCLI: usage");
System.out.println("ttool-cli");
System.out.println("ttool-cli: usage");
System.out.println("ttool-cli <script file>");
}
public static boolean checkArgs(String[] args) {
......@@ -85,6 +88,8 @@ public class TToolCLI {
return args[args.length - 1];
}
public static void main(String[] args) {
String[] tmp;
......@@ -95,14 +100,43 @@ public class TToolCLI {
return;
}
int nbOfOptions = 0;
if (hasDebug(args)) {
TraceManager.devPolicy = TraceManager.TO_CONSOLE;
} else {
TraceManager.devPolicy = TraceManager.TO_DEVNULL;
}
TToolCLI cli = new TToolCLI();
cli.print("Loading script:" + getInputFile(args));
// Load script file
File f = new File(getInputFile(args));
if (!FileUtils.checkFileForOpen(f)) {
cli.printError("File " + f.getAbsolutePath() + " could not be opened.");
cli.exit(-1);
}
String script = FileUtils.loadFileData(f);
// Call Interpreter
Interpreter interpret = new Interpreter(script, (InterpreterOutputInterface)cli);
interpret.interpret();
}
// InterpreterOutputInterface
public void print(String s) {
System.out.println(s);
}
public void printError(String s) {
System.out.println("\t*Fatal error*:" + s);
}
} // Class GraphShow
public void exit(int status) {
System.out.println("Exiting. Bye.");
System.exit(status);
}
} // Class TToolCLI
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment