diff --git a/src/main/java/cli/Action.java b/src/main/java/cli/Action.java index a2e60eb9acd47e0a126b2c2ddd25553880e62d9c..3534629d592c78bf2b5b9e5731ec8dcbac01c882 100644 --- a/src/main/java/cli/Action.java +++ b/src/main/java/cli/Action.java @@ -77,7 +77,7 @@ public class Action extends Command { private final static String NAVIGATE_LEFT_PANEL = "navigate-left-panel"; - private final static String GENERIC = "generic"; + public Action() { @@ -364,22 +364,6 @@ public class Action extends Command { } }; - // Navigation - Command navigateLeftPanel = new Command() { - public String getCommand() { return NAVIGATE_LEFT_PANEL; } - public String getShortCommand() { return "nlf"; } - public String getDescription() { return "Select the edition panel on the left"; } - - public String executeCommand(String command, Interpreter interpreter) { - if (!interpreter.isTToolStarted()) { - return Interpreter.TTOOL_NOT_STARTED; - } - - interpreter.mgui.selectPanelOnTheLeft(); - return null; - } - }; - Command movePanelToTheLeftPanel = new Command() { public String getCommand() { return NAVIGATE_PANEL_TO_LEFT; } public String getShortCommand() { return "nptf"; } @@ -396,21 +380,7 @@ public class Action extends Command { } }; - Command generic = new Command() { - public String getCommand() { return GENERIC; } - public String getShortCommand() { return "g"; } - public String getDescription() { return "Apply a generic function of TTool"; } - - public String executeCommand(String command, Interpreter interpreter) { - if (!interpreter.isTToolStarted()) { - return Interpreter.TTOOL_NOT_STARTED; - } - - ActionPerformer.actionPerformed(interpreter.mgui, null, command.trim(), null); - - return null; - } - }; + Command generic = new Generic(); addAndSortSubcommand(start); @@ -422,9 +392,7 @@ public class Action extends Command { addAndSortSubcommand(diplodocusOneTraceSimulation); addAndSortSubcommand(diplodocusGenerateTML); addAndSortSubcommand(diplodocusUPPAAL); - - addAndSortSubcommand(navigateLeftPanel); - + addAndSortSubcommand(movePanelToTheLeftPanel); addAndSortSubcommand(generic); } diff --git a/src/main/java/cli/Command.java b/src/main/java/cli/Command.java index a675e09bd9b4dcf2a754341ad2664601919bf2d1..ebefcca76e80d390e06a0bcbc6115812ce3b2455 100644 --- a/src/main/java/cli/Command.java +++ b/src/main/java/cli/Command.java @@ -63,8 +63,8 @@ public class Command implements CommandInterface { } public String getCommand() { return "default"; - } + public String getShortCommand() { return getCommand(); } @@ -117,6 +117,7 @@ public class Command implements CommandInterface { return ""; } + public String getHelp(int level) { String dec = getLevelString(level); /*String h = ""; @@ -139,6 +140,8 @@ public class Command implements CommandInterface { return b.toString(); } + + public String getLevelString(int level) { String ret = ""; while(level > 0) { @@ -174,9 +177,6 @@ public class Command implements CommandInterface { } public void addAndSortSubcommand(Command c) { - /*if (subcommands.size() == 0) { - subcommands.add(c); - }*/ int index = 0; for (Command cmd: subcommands) { @@ -188,4 +188,24 @@ public class Command implements CommandInterface { subcommands.add(index, c); } + public Command getSubCommandByName(String cmd) { + String comm = cmd; + + int index = cmd.indexOf(" "); + + if (index > 0) { + comm = cmd.substring(0, index); + } + + for (Command c: subcommands) { + if ((c.getShortCommand().compareTo(cmd) == 0) || (c.getCommand().compareTo(cmd) == 0)) { + if (index == -1) { + return c; + } + return c.getSubCommandByName(cmd.substring(index+1, cmd.length()).trim()); + } + } + return null; + } + } diff --git a/src/main/java/cli/Generic.java b/src/main/java/cli/Generic.java new file mode 100644 index 0000000000000000000000000000000000000000..72cbb6f9ad12e64f5096baf1fedc5cb1ecf32d90 --- /dev/null +++ b/src/main/java/cli/Generic.java @@ -0,0 +1,98 @@ +/* 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 common.ConfigurationTTool; +import common.SpecConfigTTool; +import launcher.RTLLauncher; +import myutil.FileUtils; +import myutil.PluginManager; +import myutil.TraceManager; +import tmltranslator.*; +import tmltranslator.dsez3engine.InputInstance; +import tmltranslator.dsez3engine.OptimizationModel; +import tmltranslator.dsez3engine.OptimizationResult; +import ui.ActionPerformer; +import ui.MainGUI; +import ui.TGComponent; +import ui.TURTLEPanel; +import ui.util.IconManager; + +import java.io.File; +import java.util.BitSet; +import java.util.*; + +/** + * Class Generic + * Creation: 12/04/2019 + * Version 2.0 12/04/2019 + * + * @author Ludovic APVRILLE + */ +public class Generic extends Command { + private final static String GENERIC = "generic"; + + public Generic() { + + } + + public String getCommand() { return GENERIC; } + public String getShortCommand() { return "g"; } + public String getDescription() { return "Apply a generic function of TTool"; } + + + public String executeCommand(String command, Interpreter interpreter) { + if (!interpreter.isTToolStarted()) { + return Interpreter.TTOOL_NOT_STARTED; + } + + ActionPerformer.actionPerformed(interpreter.mgui, null, command.trim(), null); + + return null; + } + + + + + public void fillSubCommands() { + } + + +} diff --git a/src/main/java/cli/Help.java b/src/main/java/cli/Help.java index ca7f2bdbc415314224b8122f982e4fca4917400a..f7d42e8aaeff9dc19f4f55a83b45ba7a25d97f99 100644 --- a/src/main/java/cli/Help.java +++ b/src/main/java/cli/Help.java @@ -101,7 +101,7 @@ public class Help extends Command { } - Command c = interpreter.getCommandByName(command); + Command c = interpreter.getSubCommandByName(command); if (c == null) { return Interpreter.BAD_COMMAND_NAME; @@ -109,6 +109,7 @@ public class Help extends Command { interpreter.print(c.getHelp(1)); + return null; } @@ -116,4 +117,6 @@ public class Help extends Command { public void fillSubCommands() { } + + } diff --git a/src/main/java/cli/Interpreter.java b/src/main/java/cli/Interpreter.java index b8e46380d628e48a443e649bc039f732dc29c9fa..7f2603e7fc1949596a64e5dd4adbaabcc173afd7 100644 --- a/src/main/java/cli/Interpreter.java +++ b/src/main/java/cli/Interpreter.java @@ -1,26 +1,26 @@ /* 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, @@ -31,7 +31,7 @@ * 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. */ @@ -39,18 +39,15 @@ package cli; -import common.ConfigurationTTool; -import common.SpecConfigTTool; -import launcher.RTLLauncher; import myutil.Conversion; -import myutil.PluginManager; +import myutil.Terminal; +import myutil.TerminalProviderInterface; import myutil.TraceManager; -import ui.*; -import ui.util.IconManager; -import java.io.*; -import myutil.*; +import ui.MainGUI; -import java.util.*; +import java.util.HashMap; +import java.util.Scanner; +import java.util.Vector; /** * Class Interpreter @@ -59,7 +56,7 @@ import java.util.*; * * @author Ludovic APVRILLE */ -public class Interpreter implements Runnable, TerminalProviderInterface { +public class Interpreter implements Runnable, TerminalProviderInterface { public final static Command[] commands = {new Action(), new Help(), new History(), new Print(), new Quit(), new TestSpecific(), new TML(), new Set(), new Wait()}; @@ -68,12 +65,12 @@ public class Interpreter implements Runnable, TerminalProviderInterface { public final static String UNKNOWN = "Unknown command"; public final static String BAD = "Badly formatted expression"; public final static String BAD_WAIT_VALUE = "Must provide a int value > 0"; - public final static String BAD_VAR_VALUE ="Unvalid value for variable"; - public final static String BAD_VAR_NAME ="Unvalid variable name"; - public final static String UNKNOWN_NEXT_COMMAND ="Invalid action: "; - public final static String TTOOL_NOT_STARTED ="TTool is not yet started. Cannot execute command."; - public final static String TTOOL_ALREADY_STARTED ="TTool is already started. Cannot execute command."; - public final static String BAD_COMMAND_NAME ="The provided command is invalid"; + public final static String BAD_VAR_VALUE = "Unvalid value for variable"; + public final static String BAD_VAR_NAME = "Unvalid variable name"; + public final static String UNKNOWN_NEXT_COMMAND = "Invalid action: "; + public final static String TTOOL_NOT_STARTED = "TTool is not yet started. Cannot execute command."; + public final static String TTOOL_ALREADY_STARTED = "TTool is already started. Cannot execute command."; + public final static String BAD_COMMAND_NAME = "The provided command is invalid"; private String script; @@ -129,7 +126,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface { while (scanner.hasNextLine()) { String line = scanner.nextLine(); executeLine(line, cptLine, false); - cptLine ++; + cptLine++; printPrompt(cptLine); } } @@ -144,7 +141,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface { currentLine = 0; while (scanner.hasNextLine()) { String line = scanner.nextLine(); - currentLine ++; + currentLine++; executeLine(line, currentLine, true); } @@ -183,9 +180,9 @@ public class Interpreter implements Runnable, TerminalProviderInterface { } //TraceManager.addDev("Handling line: " + lineWithNoVariable); - String [] commandInfo = lineWithNoVariable.split(" "); + String[] commandInfo = lineWithNoVariable.split(" "); - if ((commandInfo == null) || (commandInfo.length < 1)){ + if ((commandInfo == null) || (commandInfo.length < 1)) { System.out.println("Empty command"); if (exitOnError) { System.exit(-1); @@ -193,18 +190,17 @@ public class Interpreter implements Runnable, TerminalProviderInterface { } - // Analyze current line error = ""; - for(Command c: commands) { + for (Command c : commands) { if (commandInfo[0].compareTo(c.getCommand()) == 0) { - error = c.executeCommand( lineWithNoVariable.substring(c.getCommand().length(), + error = c.executeCommand(lineWithNoVariable.substring(c.getCommand().length(), lineWithNoVariable.length()).trim(), this); TraceManager.addDev("Command executed"); break; } if (commandInfo[0].compareTo(c.getShortCommand()) == 0) { - error = c.executeCommand( lineWithNoVariable.substring(c.getShortCommand().length(), + error = c.executeCommand(lineWithNoVariable.substring(c.getShortCommand().length(), lineWithNoVariable.length()).trim(), this); TraceManager.addDev("Short Command executed"); break; @@ -233,9 +229,9 @@ public class Interpreter implements Runnable, TerminalProviderInterface { String initialLine = input; int index; - while((index = input.indexOf("$")) > -1) { + while ((index = input.indexOf("$")) > -1) { ret = ret + input.substring(0, index); - input = input.substring(index+1, input.length()); + input = input.substring(index + 1, input.length()); int indexSpace = input.indexOf(" "); String varName; if (indexSpace == -1) { @@ -243,7 +239,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface { input = ""; } else { varName = input.substring(0, indexSpace); - input = input.substring(indexSpace+1, input.length()); + input = input.substring(indexSpace + 1, input.length()); } // Identifying variable @@ -282,10 +278,21 @@ public class Interpreter implements Runnable, TerminalProviderInterface { return show; } - public Command getCommandByName(String cmd) { - for (Command c: commands) { - if ((c.getShortCommand().compareTo(cmd) == 0) || (c.getCommand().compareTo(cmd) == 0)) { - return c; + public Command getSubCommandByName(String cmd) { + String comm = cmd; + + int index = cmd.indexOf(" "); + + if (index > 0) { + comm = cmd.substring(0, index); + } + + for (Command c : commands) { + if ((c.getShortCommand().compareTo(comm) == 0) || (c.getCommand().compareTo(comm) == 0)) { + if (index == -1) { + return c; + } + return c.getSubCommandByName(cmd.substring(index+1, cmd.length()).trim()); } } return null; @@ -293,7 +300,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface { public String getHelp() { StringBuffer buf = new StringBuffer(""); - for(Command c:commands) { + for (Command c : commands) { buf.append(c.getHelp(0) + "\n"); } return buf.toString(); @@ -306,7 +313,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface { // History public String printAllFormerCommands() { StringBuffer sb = new StringBuffer(""); - for(int i=0; i<formerCommands.size(); i++) { + for (int i = 0; i < formerCommands.size(); i++) { sb.append("" + i + "\t" + formerCommands.get(i) + "\n"); } print(sb.toString()); @@ -338,13 +345,13 @@ public class Interpreter implements Runnable, TerminalProviderInterface { // From the split, determine commands already entered and completes it Vector<Command> listOfCommands = findCommands(split, 0); - if (listOfCommands.size()== 0) { + if (listOfCommands.size() == 0) { return false; } - for(Command c: listOfCommands) { - System.out.println(""+c.getCommand()); - return true; + for (Command c : listOfCommands) { + System.out.println("" + c.getCommand()); + return true; } return true; @@ -364,9 +371,9 @@ public class Interpreter implements Runnable, TerminalProviderInterface { Vector<Command> couldBe = new Vector<>(); // Search of all compatible commands starting with s - for (Command c: commands) { + for (Command c : commands) { if (c.getShortCommand().startsWith(s) || c.getCommand().startsWith(s)) { - Vector<Command> others = c.findCommands(split, index+1); + Vector<Command> others = c.findCommands(split, index + 1); if (others != null) { couldBe.addAll(others); }