Skip to content

Commit 00ff09f

Browse files
committed
Set Class
View changelog entry Sergix#74 for details.
1 parent 5f3989d commit 00ff09f

File tree

17 files changed

+179
-108
lines changed

17 files changed

+179
-108
lines changed

.classpath

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
55
<attributes>
66
<attribute name="maven.pomderived" value="true"/>
77
</attributes>

.settings/org.eclipse.jdt.core.prefs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
eclipse.preferences.version=1
2-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3-
org.eclipse.jdt.core.compiler.compliance=1.8
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
3+
org.eclipse.jdt.core.compiler.compliance=1.7
44
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5-
org.eclipse.jdt.core.compiler.source=1.8
5+
org.eclipse.jdt.core.compiler.source=1.7

changelog.txt

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
(#74)[9/8/2017-16:46 0.4.0 Sergix]
2+
Moved all the "set" command code into its own class, Set.
3+
- vars: global program hashtable containing all variables
4+
- NewVar(options): creates a new variable
5+
- PrintVars(): prints all variables currently stored
6+
Slight improvements in efficiency in the Set command.
7+
Set can also now be called from the regular prompt, and not just from exec files.
8+
The next update to JTerm will probably result in a patch (v0.4.1) unless something significant is added.
9+
Pushed updates to Git.
10+
111
(#73)[9/8/2017-13:00 0.4.0 Sergix]
212
Fixed an issue with the importing of the commons library in the POM.
313
Pushed updates to Git.

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
<artifactId>maven-compiler-plugin</artifactId>
2424
<version>3.1</version>
2525
<configuration>
26-
<source>1.8</source>
27-
<target>1.8</target>
26+
<source>1.7</source>
27+
<target>1.7</target>
2828
</configuration>
2929
</plugin>
3030
<plugin>

src/main/java/jterm/Exec.java

+49-89
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@
1818

1919
import java.io.*;
2020
import java.util.ArrayList;
21-
import java.util.Enumeration;
2221
import java.util.Hashtable;
2322
import java.util.Scanner;
2423

2524
public class Exec
2625
{
2726

28-
private static Hashtable<String, String> vars = new Hashtable<>();
29-
30-
// var name, window object
31-
private static Hashtable<String, Window> windows = new Hashtable<>();
32-
3327
public static boolean Run(ArrayList<String> options)
3428
{
3529

@@ -114,41 +108,7 @@ public static void Parse(String directive)
114108
}
115109

116110
switch (command)
117-
{
118-
case "set":
119-
if (options.size() == 1)
120-
{
121-
String element = "";
122-
for (Enumeration<String> e = vars.keys(); e.hasMoreElements();)
123-
System.out.println((element = e.nextElement()) + "=" + vars.get(element));
124-
125-
break;
126-
127-
}
128-
129-
String key = options.get(1);
130-
if ( !options.get(2).equals("=") )
131-
{
132-
tokenizer.close();
133-
return;
134-
135-
}
136-
137-
if (options.get(3).equals("window"))
138-
{
139-
for (int i = 0; i < 4; i++)
140-
options.remove(0);
141-
142-
Window newWindow = new Window(options);
143-
vars.put(key, Integer.toString(newWindow.GetId()));
144-
windows.put(key, newWindow);
145-
break;
146-
147-
}
148-
149-
vars.put(key, GetRest(options, 3));
150-
break;
151-
111+
{
152112
case "pause":
153113
if (options.size() == 1)
154114
System.out.print("Press enter to continue...");
@@ -197,67 +157,67 @@ public static void Parse(String directive)
197157
break;
198158

199159
default:
200-
for (;;)
201-
if ( vars.containsKey(options.get(0)) )
202-
{
203-
int value;
204-
//
205-
// TODO
206-
// Create arithmetic operations that passes the value
207-
// to whatever it is needed for
208-
//
209-
if ( !options.get(1).equals("=") || !vars.containsKey(options.get(2)) || !vars.containsKey(options.get(4)) )
210-
break;
160+
// for (;;)
161+
// if ( vars.containsKey(options.get(0)) )
162+
// {
163+
// int value;
164+
// //
165+
// // TODO
166+
// // Create arithmetic operations that passes the value
167+
// // to whatever it is needed for
168+
// //
169+
// if ( !options.get(1).equals("=") || !vars.containsKey(options.get(2)) || !vars.containsKey(options.get(4)) )
170+
// break;
211171

212-
switch(options.get(3))
213-
{
214-
case "+":
215-
value = Integer.parseInt( vars.get(options.get(2)) ) + Integer.parseInt( vars.get(options.get(4)) );
216-
break;
172+
// switch(options.get(3))
173+
// {
174+
// case "+":
175+
// value = Integer.parseInt( vars.get(options.get(2)) ) + Integer.parseInt( vars.get(options.get(4)) );
176+
// break;
217177

218-
case "-":
219-
value = Integer.parseInt( vars.get(options.get(2)) ) - Integer.parseInt( vars.get(options.get(4)) );
220-
break;
178+
// case "-":
179+
// value = Integer.parseInt( vars.get(options.get(2)) ) - Integer.parseInt( vars.get(options.get(4)) );
180+
// break;
221181

222-
case "*":
223-
value = Integer.parseInt( vars.get(options.get(2)) ) * Integer.parseInt( vars.get(options.get(4)) );
224-
break;
182+
// case "*":
183+
// value = Integer.parseInt( vars.get(options.get(2)) ) * Integer.parseInt( vars.get(options.get(4)) );
184+
// break;
225185

226-
case "/":
227-
value = Integer.parseInt( vars.get(options.get(2)) ) / Integer.parseInt( vars.get(options.get(4)) );
228-
break;
186+
// case "/":
187+
// value = Integer.parseInt( vars.get(options.get(2)) ) / Integer.parseInt( vars.get(options.get(4)) );
188+
// break;
229189

230-
default:
231-
tokenizer.close();
232-
return;
190+
// default:
191+
// tokenizer.close();
192+
// return;
233193

234-
}
194+
// }
235195

236-
vars.replace(options.get(0), String.valueOf(value));
196+
// //vars.replace(options.get(0), String.valueOf(value));
237197

238-
tokenizer.close();
239-
return;
198+
// tokenizer.close();
199+
// return;
240200

241-
}
242-
else if ( windows.containsKey(options.get(0)) )
243-
{
244-
switch(options.get(1))
245-
{
246-
case "visible":
247-
windows.get(options.get(0)).ToggleVisible();
248-
break;
201+
// }
202+
// else if ( windows.containsKey(options.get(0)) )
203+
// {
204+
// switch(options.get(1))
205+
// {
206+
// case "visible":
207+
// windows.get(options.get(0)).ToggleVisible();
208+
// break;
249209

250-
case "title":
251-
windows.get(options.get(0)).GetFrame().setTitle(GetRest(options, 2));
252-
break;
210+
// case "title":
211+
// windows.get(options.get(0)).GetFrame().setTitle(GetRest(options, 2));
212+
// break;
253213

254-
default:
255-
break;
214+
// default:
215+
// break;
256216

257-
}
217+
// }
258218

259-
}
260-
else
219+
// }
220+
// else
261221
JTerm.Parse(options);
262222

263223
tokenizer.close();

src/main/java/jterm/Files.java

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import java.io.IOException;
2424
import java.util.ArrayList;
2525

26-
import main.java.jterm.JTerm;
27-
2826
public class Files
2927
{
3028

src/main/java/jterm/JTerm.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.*;
2222
import java.util.ArrayList;
2323
import java.util.Hashtable;
24+
2425
public class JTerm
2526
{
2627

@@ -227,7 +228,11 @@ public static boolean Parse(ArrayList<String> options)
227228

228229
case "ping":
229230
Ping.PingHost(options);
230-
break;
231+
break;
232+
233+
case "set":
234+
Set.NewVar(options);
235+
break;
231236

232237
default:
233238
// Create a new array that contains the command and check if it is an executable

src/main/java/jterm/Set.java

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* JTerm - a cross-platform terminal
3+
* Copyright (C) 2017 Sergix, NCSGeek
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package main.java.jterm;
18+
19+
import java.util.Hashtable;
20+
import java.util.Enumeration;
21+
import java.util.ArrayList;
22+
23+
public class Set
24+
{
25+
26+
// Global variable hashtable
27+
public static Hashtable<String, String> vars = new Hashtable<String, String>();
28+
29+
/*
30+
* NewVar() void
31+
*
32+
* Creates a new variable that is stored in
33+
* the global vars hashtable.
34+
*
35+
* ArrayList<String> options - command options
36+
*/
37+
public static void NewVar(ArrayList<String> options)
38+
{
39+
40+
// Print the value of all current variables
41+
if (options.size() == 1)
42+
{
43+
PrintVars();
44+
return;
45+
46+
}
47+
48+
// Get the variable name
49+
String key = options.get(1);
50+
51+
// The name can't include spaces
52+
if ( !options.get(2).equals("=") )
53+
return;
54+
55+
// If the type is a window, create a new one
56+
if (options.get(3).equals("window"))
57+
{
58+
// Remove the 'set' word from the options list
59+
options.remove(0);
60+
61+
// Pass the rest of the options to create a new Window
62+
Window newWindow = new Window(options);
63+
64+
// Put the window ID into the vars hashtable
65+
// associated with its key
66+
vars.put(key, Integer.toString(newWindow.GetId()));
67+
68+
// Add the window to the global list
69+
Window.windows.add(newWindow);
70+
71+
return;
72+
73+
}
74+
75+
// Put the variable contents into the global hashtable
76+
vars.put(key, Exec.GetRest(options, 3));
77+
78+
}
79+
80+
/*
81+
* PrintVars() void
82+
*
83+
* Prints the values of all variables
84+
* currently stored.
85+
*/
86+
public static void PrintVars()
87+
{
88+
89+
String element = "";
90+
91+
// For each key...
92+
for (Enumeration<String> e = vars.keys(); e.hasMoreElements();)
93+
// ...print in the format of "key=value"
94+
System.out.println((element = e.nextElement()) + "=" + vars.get(element));
95+
96+
}
97+
98+
}
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
-2.31 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Window.java
2-
C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Echo.java
3-
C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Server.java
4-
C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Exec.java
5-
C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Ping.java
6-
C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Client.java
7-
C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Files.java
8-
C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Ps.java
9-
C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Dir.java
10-
C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\JTerm.java
1+
/mnt/c/Users/Sergi/Development/GitHub/JTerm/src/main/java/jterm/Exec.java
2+
/mnt/c/Users/Sergi/Development/GitHub/JTerm/src/main/java/jterm/JTerm.java
3+
/mnt/c/Users/Sergi/Development/GitHub/JTerm/src/main/java/jterm/Window.java
4+
/mnt/c/Users/Sergi/Development/GitHub/JTerm/src/main/java/jterm/Echo.java
5+
/mnt/c/Users/Sergi/Development/GitHub/JTerm/src/main/java/jterm/Dir.java
6+
/mnt/c/Users/Sergi/Development/GitHub/JTerm/src/main/java/jterm/Server.java
7+
/mnt/c/Users/Sergi/Development/GitHub/JTerm/src/main/java/jterm/Files.java
8+
/mnt/c/Users/Sergi/Development/GitHub/JTerm/src/main/java/jterm/Client.java
9+
/mnt/c/Users/Sergi/Development/GitHub/JTerm/src/main/java/jterm/Ps.java
10+
/mnt/c/Users/Sergi/Development/GitHub/JTerm/src/main/java/jterm/Ping.java

0 commit comments

Comments
 (0)