diff --git a/init.bat b/init.bat
index 7b8d375..82052b4 100644
--- a/init.bat
+++ b/init.bat
@@ -1,6 +1,6 @@
@echo off
cls
-set JTERM_VERSION=0.5.1
+set JTERM_VERSION=0.5.0
prompt dev~JTerm/
diff --git a/pom.xml b/pom.xml
index eca9223..47c4a63 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
sergix
jterm
- 0.5.1
+ 0.5.0
jar
JTerm is a cross-platform terminal designed for simple use and to run batch files. JTerm is hosted on GitHub by Sergix and NCSGeek.
diff --git a/src/main/java/jterm/Dir.java b/src/main/java/jterm/Dir.java
index 3f04467..889e3a8 100644
--- a/src/main/java/jterm/Dir.java
+++ b/src/main/java/jterm/Dir.java
@@ -27,27 +27,57 @@ public class Dir
/*
* Dir() void
*
- * Constructor for calling methods.
+ * Constructor for calling Process() function.
*/
- public Dir(ArrayList options) { }
+ public Dir() { }
/*
* Process() void
*
* Process the input.
*
- * ArrayList options - command options
+ * String options - command options
*/
- public static void Process(ArrayList options)
+ public static void Process(String options)
{
- // Display help information
- System.out.println("Directory Commands\n\nls\tcd\nchdir\tpwd\nmd");
+ ArrayList optionsArray = JTerm.GetAsArray(options);
+ if (optionsArray.toArray().length == 0)
+ optionsArray.add(0, "help");
+
+ String command = optionsArray.get(0);
+ optionsArray.remove(0);
+
+ switch (command)
+ {
+ case "ls": // @pmorgan3
+ PrintDir(optionsArray);
+ break;
+
+ case "cd":
+ case "chdir":
+ ChangeDir(optionsArray);
+ break;
+
+ case "pwd":
+ PrintWorkingDir(optionsArray);
+ break;
+
+ case "md":
+ NewDir(optionsArray);
+ break;
+
+ case "help":
+ default:
+ System.out.println("Directory Commands\n\nls\tcd\nchdir\tpwd\nmd\thelp");
+ return;
+
+ }
}
/*
- * Ls() void (@pmorgan3)
+ * PrintDir() void
*
* Prints the contents of a specified directory
* to a file.
@@ -65,15 +95,13 @@ public static void Process(ArrayList options)
*
* Examples
*
- * Ls(options);
+ * PrintDir(options);
* => [Contents of "dir/"]
* => F RW myFile.txt 2 KB
*/
- public static void Ls(ArrayList options) throws NullPointerException
+ public static void PrintDir(ArrayList options) throws NullPointerException
{
- System.out.println(options);
-
String path = JTerm.currentDirectory;
boolean printFull = true;
@@ -126,7 +154,7 @@ else if (option.equals("-h"))
/*
- * Cd() void
+ * ChangeDir() void
*
* Changes the working directory to the specified
* input.
@@ -138,7 +166,7 @@ else if (option.equals("-h"))
*
* ArrayList options - command options
*/
- public static void Cd(ArrayList options)
+ public static void ChangeDir(ArrayList options)
{
String newDirectory = "";
@@ -195,25 +223,10 @@ else if ((!dir.exists() || !dir.isDirectory()) && (!newDir.exists() || !newDir.i
// It does exist, and it is a directory, so just change the global working directory variable to the input
JTerm.currentDirectory = newDirectory;
-
- }
-
- /*
- * Chdir() void
- *
- * Identical to 'cd'; calls Cd().
- *
- * ArrayList options - command options
- */
- public static void Chdir(ArrayList options)
- {
-
- Cd(options);
-
}
/*
- * Pwd() void
+ * PrintWorkingDir() void
*
* Prints the working directory to the console.
*
@@ -222,7 +235,7 @@ public static void Chdir(ArrayList options)
*
* ArrayList options - command options
*/
- public static void Pwd(ArrayList options)
+ public static void PrintWorkingDir(ArrayList options)
{
for (String option: options)
@@ -242,7 +255,7 @@ public static void Pwd(ArrayList options)
}
/*
- * Md() void
+ * NewDir() void
*
* Creates a new directory.
*
@@ -251,7 +264,7 @@ public static void Pwd(ArrayList options)
*
* ArrayList options - command options
*/
- public static void Md(ArrayList options)
+ public static void NewDir(ArrayList options)
{
String name = "";
@@ -274,7 +287,6 @@ public static void Md(ArrayList options)
File dir = new File(name);
dir.mkdir();
-
}
}
diff --git a/src/main/java/jterm/Echo.java b/src/main/java/jterm/Echo.java
index 1019eae..a1af325 100644
--- a/src/main/java/jterm/Echo.java
+++ b/src/main/java/jterm/Echo.java
@@ -28,9 +28,35 @@ public class Echo
*
* Constructor for calling Process() function.
*/
- public Echo(ArrayList options)
+ public Echo() { }
+
+ /*
+ * Process() void
+ *
+ * Process the input.
+ *
+ * String options - command options
+ */
+ public static void Process (String options)
{
+ EchoInput(JTerm.GetAsArray(options));
+
+ }
+
+ /*
+ * EchoInput() void
+ *
+ * Echoes the input recieved to the console.
+ *
+ * ArrayList options - command options
+ *
+ * -h
+ * Prints help information.
+ */
+ public static void EchoInput(ArrayList options)
+ {
+
String output = "";
for (String option: options)
@@ -46,9 +72,9 @@ public Echo(ArrayList options)
}
- output = output.trim();
+ output = output.substring(0, output.length() - 1);
System.out.println(output);
-
+
}
}
diff --git a/src/main/java/jterm/Exec.java b/src/main/java/jterm/Exec.java
index b7f3f97..ff3493d 100644
--- a/src/main/java/jterm/Exec.java
+++ b/src/main/java/jterm/Exec.java
@@ -28,20 +28,20 @@ public class Exec
*
* Constructor for calling Process() function.
*/
- public Exec(ArrayList options) { }
+ public Exec() { }
/*
* Process() void
*
* Process the input.
*
- * ArrayList options - command options
+ * String options - command options
*/
- public static void Process(ArrayList options)
+ public static void Process(String options)
{
-
- // Default to Run(); nothing to process
- Run(options);
+
+ ArrayList optionsArray = JTerm.GetAsArray(options);
+ Run(optionsArray);
}
diff --git a/src/main/java/jterm/Exit.java b/src/main/java/jterm/Exit.java
index 07986c8..395fc24 100644
--- a/src/main/java/jterm/Exit.java
+++ b/src/main/java/jterm/Exit.java
@@ -28,8 +28,32 @@ public class Exit
*
* Constructor for calling Process() function.
*/
- public Exit(ArrayList options) {
+ public Exit() { }
+
+ /*
+ * Process() void
+ *
+ * Process the input.
+ *
+ * String options - command options
+ */
+ public static void Process(String options)
+ {
+
+ ExitApp(JTerm.GetAsArray(options));
+ }
+
+ /*
+ * ExitApp() void
+ *
+ * Exits the application through a system call.
+ *
+ * ArrayList options - command options
+ */
+ public static void ExitApp(ArrayList options)
+ {
+
System.exit(0);
}
diff --git a/src/main/java/jterm/Files.java b/src/main/java/jterm/Files.java
index bf2bac0..d549a86 100644
--- a/src/main/java/jterm/Files.java
+++ b/src/main/java/jterm/Files.java
@@ -31,7 +31,7 @@ public class Files
*
* Constructor for calling Process() function.
*/
- public Files(ArrayList options) { }
+ public Files() { }
/*
* Process() void
@@ -40,15 +40,42 @@ public Files(ArrayList options) { }
*
* String options - command options
*/
- public static void Process(String options)
+ public static void Process (String options)
{
+ ArrayList optionsArray = JTerm.GetAsArray(options);
+ if (optionsArray.toArray().length == 0)
+ optionsArray.add(0, "help");
+
+ String command = optionsArray.get(0);
+ optionsArray.remove(0);
+
+ switch (command)
+ {
+ case "write":
+ WriteFile(optionsArray);
+ break;
+
+ case "delete":
+ case "del":
+ case "rm": // @pmorgan3
+ Delete(optionsArray);
+ break;
- System.out.println("File Commands\n\nwrite\tdelete\ndel\trm\nread\thelp");
+ case "read":
+ ReadFile(optionsArray);
+ break;
+
+ case "help":
+ default:
+ System.out.println("File Commands\n\nwrite\tdelete\ndel\trm\nread\thelp");
+ return;
+
+ }
}
/*
- * Write() void
+ * WriteFile() void
*
* Get input and write it to a file.
* Changelog (#65)
@@ -58,7 +85,7 @@ public static void Process(String options)
* -h
* Prints help information
*/
- public static void Write(ArrayList options)
+ public static void WriteFile(ArrayList options)
{
String filename = "";
@@ -162,35 +189,7 @@ public static void Delete(ArrayList options)
}
/*
- * Rm() void (@pmorgan3)
- *
- * Identical to 'delete'; calls Delete().
- *
- * ArrayList options - command options
- */
- public static void Rm(ArrayList options)
- {
-
- Delete(options);
-
- }
-
- /*
- * Del() void (@pmorgan3)
- *
- * Identical to 'delete'; calls Delete().
- *
- * ArrayList options - command options
- */
- public static void Del(ArrayList options)
- {
-
- Delete(options);
-
- }
-
- /*
- * Read() void
+ * ReadFile() void
* Changelog (#68)
*
* Reads the specified files and outputs the contents
@@ -203,7 +202,7 @@ public static void Del(ArrayList options)
*
* Credit to @d4nntheman
*/
- public static void Read(ArrayList options)
+ public static void ReadFile(ArrayList options)
{
String filename = "";
diff --git a/src/main/java/jterm/Help.java b/src/main/java/jterm/Help.java
index 8c5b606..cb02eca 100644
--- a/src/main/java/jterm/Help.java
+++ b/src/main/java/jterm/Help.java
@@ -28,9 +28,32 @@ public class Help
*
* Constructor for calling Process() function.
*/
- public Help(ArrayList options)
+ public Help() { }
+
+ /*
+ * Process() void
+ *
+ * Process the input.
+ *
+ * String options - command options
+ */
+ public static void Process(String options)
{
+ PrintHelp(JTerm.GetAsArray(options));
+
+ }
+
+ /*
+ * PrintHelp() void
+ *
+ * Prints help information about JTerm.
+ *
+ * ArrayList options - command options
+ */
+ public static void PrintHelp(ArrayList options)
+ {
+
System.out.println("JTerm v" + JTerm.version);
}
diff --git a/src/main/java/jterm/JTerm.java b/src/main/java/jterm/JTerm.java
index f6dab64..6773462 100644
--- a/src/main/java/jterm/JTerm.java
+++ b/src/main/java/jterm/JTerm.java
@@ -20,16 +20,15 @@
import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;
+import java.util.Hashtable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.Constructor;
-import java.util.Arrays;
public class JTerm
{
// Global version variable
- static String version = "0.5.1";
+ static String version = "0.4.1";
// Global directory variable (use "cd" command to change)
// Default value "./" is equal to the default directory set when the program starts
@@ -136,9 +135,6 @@ public static boolean Parse(String options)
ArrayList optionsArray = GetAsArray(options);
- // Default to process/help command if function is not found
- String method = "Process";
-
// Get the first string in the options array, which is the command,
// and capitalize the first letter of the command
String original = optionsArray.get(0).toLowerCase(), command = original;
@@ -146,35 +142,20 @@ public static boolean Parse(String options)
classChar = classChar.toUpperCase();
command = command.substring(1);
command = "main.java.jterm." + classChar + command;
- optionsArray.remove(0);
- // Get the method name
- if (optionsArray.toArray().length >= 1)
- method = optionsArray.get(0);
-
- classChar = method.substring(0, 1);
- classChar = classChar.toUpperCase();
- method = method.substring(1);
- method = classChar + method;
+ // When we pass the options, we don't want the command name included
+ optionsArray.remove(0);
try
{
// Get the class of the command
- Class> clazz = Class.forName(command);
- Constructor> constructor = clazz.getConstructor(ArrayList.class);
- Object obj = constructor.newInstance(optionsArray);
-
- ArrayList methods = new ArrayList(Arrays.asList(obj.getClass().getDeclaredMethods()));
-
- // Invoke the correct method of the class to run, but only if it contains that method
- Method m = obj.getClass().getMethod(method, ArrayList.class);
- if(methods.contains(m))
- {
- optionsArray.remove(0);
- m.invoke(options.getClass(), new Object[] {optionsArray});
-
- }
-
+ Class c = Class.forName(command);
+ Object o = c.newInstance();
+
+ // Invoke the "Process" method of the class to run
+ Method m = o.getClass().getMethod("Process", String.class);
+ m.invoke(options.getClass(), new Object[] {GetAsString(optionsArray)});
+
}
// Exceptions
@@ -198,7 +179,7 @@ public static boolean Parse(String options)
}
catch (NoSuchMethodException nsme)
{
- //System.out.println(nsme);
+ System.out.println(nsme);
}
catch (InvocationTargetException ite)
diff --git a/src/main/java/jterm/Pause.java b/src/main/java/jterm/Pause.java
index 66afc14..586646f 100644
--- a/src/main/java/jterm/Pause.java
+++ b/src/main/java/jterm/Pause.java
@@ -11,13 +11,39 @@ public class Pause
*
* Constructor for calling Process() function.
*/
- public Pause(ArrayList options) {
+ public Pause() { }
+
+ /*
+ * Process() void
+ *
+ * Process the input.
+ *
+ * String options - command options
+ */
+ public static void Process (String options)
+ {
+
+ ArrayList optionsArray = JTerm.GetAsArray(options);
+ EnterPause(optionsArray);
+
+ }
+
+ /*
+ * EnterPause() void
+ *
+ * Pauses the interpreter until the Enter
+ * key is hit.
+ *
+ * ArrayList options - command options
+ */
+ public static void EnterPause(ArrayList options)
+ {
- if (options.size() == 0)
+ if (options.size() == 1)
System.out.print("Press enter to continue...");
else
- System.out.print(Exec.GetRest(options, 0));
+ System.out.print(Exec.GetRest(options, 1));
try
{
diff --git a/src/main/java/jterm/Ping.java b/src/main/java/jterm/Ping.java
index eebee85..690493b 100644
--- a/src/main/java/jterm/Ping.java
+++ b/src/main/java/jterm/Ping.java
@@ -18,10 +18,35 @@ public class Ping
*
* Constructor for calling Process() function.
*/
- public Ping(ArrayList options)
+ public Ping() { }
+
+ /*
+ * Process() void
+ *
+ * Process the input.
+ *
+ * String options - command options
+ */
+ public static void Process (String options)
{
- String host = "google.com", port = "80";
+ ArrayList optionsArray = JTerm.GetAsArray(options);
+ PingHost(optionsArray);
+
+ }
+
+ /*
+ * PingHost() void
+ *
+ * Attempts to connect to the specified host
+ * through the port provided.
+ *
+ * ArrayList options - command options
+ */
+ public static void PingHost(ArrayList options)
+ {
+
+ String host = "google.com", port = "80";
boolean portNext = false;
for (String option: options)
@@ -58,8 +83,8 @@ else if (option.equals("-p"))
// Either timeout or unreachable or failed DNS lookup
System.out.println("Ping Failed");
- }
-
+ }
+
}
}
diff --git a/src/main/java/jterm/Ps.java b/src/main/java/jterm/Ps.java
index 223b125..c8bf614 100644
--- a/src/main/java/jterm/Ps.java
+++ b/src/main/java/jterm/Ps.java
@@ -19,9 +19,35 @@ public class Ps
*
* Constructor for calling Process() function.
*/
- public Ps(ArrayList options)
+ public Ps() { }
+
+ /*
+ * Process() void
+ *
+ * Process the input.
+ *
+ * String options - command options
+ */
+ public static void Process(String options)
{
+ ArrayList optionsArray = JTerm.GetAsArray(options);
+ View(optionsArray);
+
+ }
+
+ /*
+ * View() void
+ *
+ * Views all processes running on the host
+ * system.
+ *
+ * String[] args - arguments passed from the
+ * console
+ */
+ public static void View(ArrayList options)
+ {
+
for (String option: options)
{
if (option.equals("-h"))
diff --git a/src/main/java/jterm/Set.java b/src/main/java/jterm/Set.java
index 1347270..0ba3046 100644
--- a/src/main/java/jterm/Set.java
+++ b/src/main/java/jterm/Set.java
@@ -31,40 +31,55 @@ public class Set
*
* Constructor for calling Process() function.
*/
- public Set(ArrayList options)
+ public Set() { }
+
+ /*
+ * Process() void
+ *
+ * Process the input.
+ *
+ * String options - command options
+ */
+ public static void Process(String options)
{
- // Print the value of all current variables
- if (options.size() == 0)
- {
- String element = "";
-
- // For each key...
- for (Enumeration e = vars.keys(); e.hasMoreElements();)
+ ArrayList optionsArray = JTerm.GetAsArray(options);
+ NewVar(optionsArray);
- // ...print in the format of "key=value"
- System.out.println((element = e.nextElement()) + "=" + vars.get(element));
+ }
+
+ /*
+ * NewVar() void
+ *
+ * Creates a new variable that is stored in
+ * the global vars hashtable.
+ *
+ * ArrayList options - command options
+ */
+ public static void NewVar(ArrayList options)
+ {
+ // Print the value of all current variables
+ if (options.size() == 1)
+ {
+ PrintVars();
return;
}
// Get the variable name
- String key = options.get(0);
+ String key = options.get(1);
// The name can't include spaces
- if (options.toArray().length > 2)
- {
- if ( !options.get(1).equals("=") )
- return;
-
- }
- else
+ if ( !options.get(2).equals("=") )
return;
// If the type is a window, create a new one
- if (options.get(2).equals("window"))
- {
+ if (options.get(3).equals("window"))
+ {
+ // Remove the 'set' word from the options list
+ options.remove(0);
+
// Pass the rest of the options to create a new Window
Window newWindow = new Window(options);
@@ -80,8 +95,26 @@ public Set(ArrayList options)
}
// Put the variable contents into the global hashtable
- vars.put(key, Exec.GetRest(options, 2));
+ vars.put(key, Exec.GetRest(options, 3));
+
+ }
+ /*
+ * PrintVars() void
+ *
+ * Prints the values of all variables
+ * currently stored.
+ */
+ public static void PrintVars()
+ {
+
+ String element = "";
+
+ // For each key...
+ for (Enumeration e = vars.keys(); e.hasMoreElements();)
+ // ...print in the format of "key=value"
+ System.out.println((element = e.nextElement()) + "=" + vars.get(element));
+
}
}
\ No newline at end of file
diff --git a/src/main/java/jterm/Window.java b/src/main/java/jterm/Window.java
index 6c74323..fc3095b 100644
--- a/src/main/java/jterm/Window.java
+++ b/src/main/java/jterm/Window.java
@@ -32,18 +32,24 @@ public class Window
private String title = null;
private boolean visible = false;
+ /*
+ * Window() void
+ *
+ * Constructor for calling Process() function.
+ */
+ public Window() { }
+
/*
* Process() void
*
* Process the input.
*
- * ArrayList options - command options
+ * String options - command options
*/
- public static void Process(ArrayList options)
+ public static void Process(String options)
{
- // Default to Window(); nothing to process
- new Window(options);
+ new Window(JTerm.GetAsArray(options));
}
@@ -72,7 +78,7 @@ public static void Process(ArrayList options)
* be resized
*
*/
- public Window(ArrayList options)
+ Window(ArrayList options)
{
int width = 500, height = 500;
diff --git a/target/classes/main/java/jterm/Client.class b/target/classes/main/java/jterm/Client.class
index c223fdd..22405a4 100644
Binary files a/target/classes/main/java/jterm/Client.class and b/target/classes/main/java/jterm/Client.class differ
diff --git a/target/classes/main/java/jterm/Dir.class b/target/classes/main/java/jterm/Dir.class
index e433501..e81c238 100644
Binary files a/target/classes/main/java/jterm/Dir.class and b/target/classes/main/java/jterm/Dir.class differ
diff --git a/target/classes/main/java/jterm/Echo.class b/target/classes/main/java/jterm/Echo.class
index e6cae77..5edef72 100644
Binary files a/target/classes/main/java/jterm/Echo.class and b/target/classes/main/java/jterm/Echo.class differ
diff --git a/target/classes/main/java/jterm/Exec.class b/target/classes/main/java/jterm/Exec.class
index 86e44c0..7213eb9 100644
Binary files a/target/classes/main/java/jterm/Exec.class and b/target/classes/main/java/jterm/Exec.class differ
diff --git a/target/classes/main/java/jterm/Files.class b/target/classes/main/java/jterm/Files.class
index 88f3859..466e466 100644
Binary files a/target/classes/main/java/jterm/Files.class and b/target/classes/main/java/jterm/Files.class differ
diff --git a/target/classes/main/java/jterm/Server$1.class b/target/classes/main/java/jterm/Server$1.class
index 3be937f..2077598 100644
Binary files a/target/classes/main/java/jterm/Server$1.class and b/target/classes/main/java/jterm/Server$1.class differ
diff --git a/target/classes/main/java/jterm/Server.class b/target/classes/main/java/jterm/Server.class
index 1313516..53b60ea 100644
Binary files a/target/classes/main/java/jterm/Server.class and b/target/classes/main/java/jterm/Server.class differ
diff --git a/target/classes/main/java/jterm/Window.class b/target/classes/main/java/jterm/Window.class
index 77de926..a40e3ed 100644
Binary files a/target/classes/main/java/jterm/Window.class and b/target/classes/main/java/jterm/Window.class differ