Skip to content

Commit

Permalink
Added func delall command
Browse files Browse the repository at this point in the history
Deletes all user defined functions
  • Loading branch information
frossm committed Nov 15, 2021
1 parent a7dc729 commit 00bd9b5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,23 @@ Simply add the value of the requested constant to the top of the stack / line1
## User Defined Functions
RPNCalc can record your commands and save them as a user defined function. You can then run this function on demand. So create your stack as you envision it being used in the future. Then enable recording, process the stack as you like, then stop the recording. Give a name to your user defined function and it will be saved. Then, you can build or import a stack, then run your function against it. These functions are stored in the preferences system much like the stacks and memory slots. `list func` will show a list of functions and their steps.

The following commands are not recorded.
- frac
- list
- debug
- ver
- h or ?
- record
- function
- cx or x or exit

|Command|Description|
|-------|-----------|
|record on|Turn on recording. Most commands and numbers entered after record is enabled will be saved. There are some that are excluded from being recorded|
|record off| Turn off recording. The user will be prompted to enter in a name for this function and that name will be used to run it in the future. If you do not enter in a name the recording is canceled and nothing will be saved|
|func del NAME|Delete a saved function. The name must match the one given when saved. A list of functions can be viewed with `list func`|
|func run|Execute the saved user defined function with the current stack as the starting point|
|func del NAME|Delete a saved function. The name must match the one given when saved. A list of functions can be viewed with `list func`. Undo will not recover a deleted function|
|func delall|Delete all saved user defined functions. Please note that undo will not recover deleted functions|

**Example:**
- `c` Clear the stack
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.fross</groupId>
<artifactId>rpncalc</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
<packaging>jar</packaging>

<name>rpncalc</name>
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: rpncalc
version: '3.2.0'
version: '3.2.1'
summary: The command line Reverse Polish Notation (RPN) calculator
description: |
RPNCalc is an easy to use command line based Reverse Polish
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/fross/rpncalc/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ public static void Display() {
Output.printColorln(Ansi.Color.YELLOW, "\nUser Defined Functions:");
Output.printColorln(Ansi.Color.WHITE, " record on Turn on command recording");
Output.printColorln(Ansi.Color.WHITE, " record off Disable recording");
Output.printColorln(Ansi.Color.WHITE, " func del NAME Delete named user defined function");
Output.printColorln(Ansi.Color.WHITE, " func run NAME Run the named user function on current stack");

Output.printColorln(Ansi.Color.WHITE, " func del NAME Delete named user defined function");
Output.printColorln(Ansi.Color.WHITE, " func delall Delete all user defined functions");


Output.printColorln(Ansi.Color.YELLOW, "\nOperational Commands:");
Output.printColorln(Ansi.Color.WHITE, " list stacks Show the list of saved stacks");
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/org/fross/rpncalc/UserFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,29 @@ public static void cmdFunction(String args) {
String command[] = args.toLowerCase().trim().split("\\s", 2);

try {
if (command[0].startsWith("del")) {
if (command[0].equals("del")) {
try {
FunctionDelete(command[1]);
} catch (ArrayIndexOutOfBoundsException ex) {
Output.printColorln(Ansi.Color.RED, "ERROR: 'function del' requires a valid function name to delete");
return;
}
} else if (command[0].startsWith("run")) {

} else if (command[0].equals("delall")) {
Preferences p = Preferences.userRoot().node(UserFunctions.PREFS_PATH_FUNCTIONS);

// Loop through each function (child of the root) and delete it
try {
for (String functionName : p.childrenNames()) {
Output.debugPrint("Removing function: " + functionName);
FunctionDelete(functionName);
}
} catch (BackingStoreException e) {
Output.printColorln(Ansi.Color.RED, "Error: Could not remove the user defined functions");
return;
}

} else if (command[0].equals("run")) {
try {
FunctionRun(command[1]);
} catch (ArrayIndexOutOfBoundsException ex) {
Expand Down Expand Up @@ -114,7 +129,7 @@ public static boolean RecordingEnabled() {
*/
public static void RecordCommand(String arg) {
// Ignore the following commands from recording
String[] ignore = { "list", "debug", "ver", "h", "?", "record", "function", "cx", "x", "exit" };
String[] ignore = { "frac", "list", "debug", "ver", "h", "?", "record", "function", "cx", "x", "exit" };

// If the command starts with an ignored item, just return before adding it to the recording
for (int i = 0; i < ignore.length; i++) {
Expand Down

0 comments on commit 00bd9b5

Please sign in to comment.