Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions ConsoleMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.devkev.devscript.raw;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLDecoder;

import com.devkev.gui.Window;

/**@author Philipp Gersch
* @version 1.8.2 (stable)
* Valid arguments are: <br>-e or --execute [some code] - Executes the String<br>
* -f or --file [path] - Reads the file and executes the code from it.<br>
* If no argument was passed, the default Editor GUI will open.*/
public class ConsoleMain {

/*Argument schema: -f <string> -e <string> --nogui </>
* When nogui is not given, the gui program will start with the given script from the command line
* */

public static void main(String[] args) throws IOException {
boolean initGUI = true;
String scriptToExecute = null;
String filePath = null;
//ALL arguments need to be checked

for(int i = 0; i < args.length; i++) {
if((args[i].equals("-e") || args[i].equals("--execute")) && scriptToExecute == null) {
if(i + 1 < args.length) {
if(!isArgument(args[i+1])) {
scriptToExecute = args[i+1];
i++; //Skip the next iteration
continue;
}
}
throw new IllegalArgumentException("Expecting string after " + args[i] + " [script_to_execute]");
} else if((args[i].equals("-f") || args[i].equals("--file")) && filePath == null) {
if(i + 1 < args.length) {
if(!isArgument(args[i+1])) {
filePath = args[i+1];
i++;
continue;
}
}
throw new IllegalArgumentException("Expecting string after " + args[i] + " [path_to_file]");
} else if(args[i].equals("--nogui")) {
initGUI = false;
continue;
}
throw new IllegalArgumentException("Unknown argument " + args[i] + "Valid arguments are:\n-f or --file\tOpens the file in the editor (If --nogui is set, the file is executed)\n-e or --execute\tOpens the script with the editor (If --nogui is set, the script is executed)\n--nogui\tOpens the command line editor");
}

System.out.println("InitGUI? " + initGUI + "\n" + "Script zo execute? " + scriptToExecute + "\nFilePath? " + filePath);
return;
//Apply rules

// Process p = new Process(true);
// p.addSystemOutput();
// p.setInput(System.in);
//
// if(args.length == 0) {
// if(ConsoleMain.class.getResourceAsStream("/Editor.txt") == null) {
// System.err.println("Editor file is missing at: " + URLDecoder.decode(ConsoleMain.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8"));
// return;
// }
// BufferedReader reader = new BufferedReader(new InputStreamReader(ConsoleMain.class.getResourceAsStream("/Editor.txt")));
// String code = "";
// String line = reader.readLine();
// while(line != null) {
// code += line;
// line = reader.readLine();
// }
// reader.close();
// p.execute(code, false);
// return;
// }
//
// if(args[0].equals("-e") || args[0].equals("--execute")) {
// if(args.length < 2) {
// System.err.println("Argument " + args[0] + " expects an executable script, e.g.: -e \"println \"Hello World;\"\"");
// System.exit(-1);
// }
// p.execute(args[1], true);
// } else if(args[0].equals("-f") || args[0].equals("--file")) {
// if(args.length < 2) {
// System.err.println("Argument " + args[0] + " expects a path to a text file containing the script");
// System.exit(-1);
// }
// p.execute(new File(args[1]), true);
// } else if(args[0].equals("--gui") || args[0].equals("-g")) {
// new Window();
// }
}

private static boolean isArgument(String arg) {
return arg.equals("-f") || arg.equals("--file") || arg.equals("-e") || arg.equals("--execute") || arg.equals("--nogui");
}
}
10 changes: 10 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ NOTICE:
Another future plan: Command: "include <abs|rel> <pathToFile>" a command to include external compiled libraries "plug in style".
Added in 1.8.0 with the command: import "path_to_jar";

1.9.0:
- This big Update gives you an Editor GUI! It runs, if you run the program without arguments. However, if you specify arguments inside the
command line this will happen: -e or --execute: Loads this script into the editor. -f or --file Loads the file into the editor.
To launch the jar file without a GUI, you need to put an --nogui argument.
Example: java -jar devscript_1.9.0.jar --file "path_to_file" --nogui -> Executes the file inside the command line
java -jar devscript_1.9.0.jar --execute "println foo;" -> Opens the editor window with "println foo;" as the content.
- Easier input setting. Before 1.9.0, it is very complicated to implement a custom InputStream. This update provides an abstract
com.devscript.raw.ApplicationInput class, to make it easier to create inputs other than the System.in: process.setInput(new ApplicationInput() {...});
-

1.8.3:
- New Command: use [STRING]; This command replaces the location of the command with code from the given string as the first argument.
This command is especially useful, if you want to include code from a separate file without creating a whole new library.
Expand Down
52 changes: 52 additions & 0 deletions com/devkev/devscript/raw/ApplicationInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.devkev.devscript.raw;

import java.io.IOException;
import java.io.InputStream;

public abstract class ApplicationInput extends InputStream {

private volatile boolean inputReqested = false;

private String data = "";
private int index = 0;

@Override
public int read() throws IOException {
if(!inputReqested) {
inputReqested = true;
awaitInput();
synchronized (this) {
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
index++;
if(index < data.length() && !data.isEmpty()) {
return data.getBytes()[index-1];
} else {
inputReqested = false;
data = "";
index = 0;
return -1;
}
}

/**This function is called, before */
public abstract void awaitInput();

public synchronized boolean inputRequested() {
return inputReqested;
}

public void flush(String data) {
if(inputReqested) {
this.data = data == null ? "" : data;
synchronized (this) {
notify();
}
}
}
}
6 changes: 6 additions & 0 deletions com/devkev/devscript/raw/ApplicationListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.devkev.devscript.raw;

public interface ApplicationListener {
/**Exit codes are: <br>{@link Block#DONE}<br> {@link Block#ERROR}*/
public void done(int exitCode);
}
134 changes: 67 additions & 67 deletions com/devkev/devscript/raw/Array.java
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
package com.devkev.devscript.raw;

import java.util.ArrayList;

import com.devkev.devscript.raw.ApplicationBuilder.Type;

public class Array { //For dataContainers
private final ArrayList<Object> indexes = new ArrayList<Object>(2);
public DataType arrayType;

public Array(Object... indexes) {
for(Object d : indexes) this.indexes.add(d);
updateArraytype();
}

public Array() {
updateArraytype();
}

public void push(Object container) {
indexes.add(container);
updateArraytype();
}

public void push(Object container, int index) {
indexes.add(index, container);
updateArraytype();
}

public void pop(int index) {
indexes.remove(index);
updateArraytype();
}

public void pop(Object container) {
indexes.remove(container);
updateArraytype();
}

public ArrayList<Object> getIndexes() {
return indexes;
}

public void updateArraytype() {
Type type = Type.NULL;
for(int j = 0; j < indexes.size(); j++) {
DataType containerType = ApplicationBuilder.toDataType(indexes.get(j));
if(j > 0) {
DataType indexType = ApplicationBuilder.toDataType(indexes.get(j-1));
if(indexType.type != containerType.type && type != Type.ANY) {
type = Type.ANY;
break;
}
} else if(j == 0) {
type = containerType.type;
}
}
arrayType = new DataType(type, true);
}

public String toString() {
String s = "ARRAY:{";
for(int i = 0; i < indexes.size()-1; i++) s += indexes.get(i) + ",";
if(indexes.size() > 0) s += indexes.get(indexes.size()-1);
return s + "}";
}
}
package com.devkev.devscript.raw;
import java.util.ArrayList;
import com.devkev.devscript.raw.ApplicationBuilder.Type;
public class Array { //For dataContainers
private final ArrayList<Object> indexes = new ArrayList<Object>(2);
public DataType arrayType;
public Array(Object... indexes) {
for(Object d : indexes) this.indexes.add(d);
updateArraytype();
}
public Array() {
updateArraytype();
}
public void push(Object container) {
indexes.add(container);
updateArraytype();
}
public void push(Object container, int index) {
indexes.add(index, container);
updateArraytype();
}
public void pop(int index) {
indexes.remove(index);
updateArraytype();
}
public void pop(Object container) {
indexes.remove(container);
updateArraytype();
}
public ArrayList<Object> getIndexes() {
return indexes;
}
public void updateArraytype() {
Type type = Type.NULL;
for(int j = 0; j < indexes.size(); j++) {
DataType containerType = ApplicationBuilder.toDataType(indexes.get(j));
if(j > 0) {
DataType indexType = ApplicationBuilder.toDataType(indexes.get(j-1));
if(indexType.type != containerType.type && type != Type.ANY) {
type = Type.ANY;
break;
}
} else if(j == 0) {
type = containerType.type;
}
}
arrayType = new DataType(type, true);
}
public String toString() {
String s = "ARRAY:{";
for(int i = 0; i < indexes.size()-1; i++) s += indexes.get(i) + ",";
if(indexes.size() > 0) s += indexes.get(indexes.size()-1);
return s + "}";
}
}
5 changes: 4 additions & 1 deletion com/devkev/devscript/raw/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

public class Block { //So stupid...

public static final byte DONE = 0;
public static final byte ERROR = 1;

public final StringBuilder blockCode;
public int executeIndex = 0; //The current char index, that is executed or compiled. 0 < ExecuteIndex < blockCode.length()
String currentCommand = "";
Expand All @@ -20,7 +23,7 @@ public class Block { //So stupid...

public boolean loop = false;
ArrayList<Command> cached = new ArrayList<Command>(0);

int exitCode = DONE;

Block(StringBuilder blockCode, Block parent) {
this.blockCode = blockCode;
Expand Down
Loading