-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from sychoo/command-line-arguments
Resolved issue #326, supported command line arguments, added example program
- Loading branch information
Showing
5 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// program to print the 0th command line argument and all the | ||
// command line arguments given by the user delimited by comma | ||
|
||
require cmdArgs | ||
require stdout | ||
|
||
stdout.print("The 0th indexed command line argument is: ") | ||
stdout.print("\"" + cmdArgs.get(0) + "\"\n") | ||
|
||
stdout.print("The last command line argument is: ") | ||
stdout.print("\"" + cmdArgs.get(cmdArgs.size() - 1) + "\"\n") | ||
|
||
stdout.print("All command line arguments are: ") | ||
stdout.print("\"") | ||
cmdArgs.print() | ||
stdout.print("\"\n") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module def cmdArgs(java: Java) | ||
import java:wyvern.stdlib.support.CommandLineUtils.utils | ||
import java:wyvern.stdlib.support.Stdio.stdio | ||
|
||
def printCmdLineArgs(index: Int): Unit | ||
if (index != size() - 1) | ||
stdio.print(utils.get(index)) | ||
stdio.print(", ") | ||
printCmdLineArgs(index + 1) | ||
else | ||
stdio.print(utils.get(size() - 1)) | ||
|
||
def print(): Unit | ||
printCmdLineArgs(0) | ||
|
||
def size(): Int | ||
utils.size() | ||
|
||
def get(index: Int): String | ||
utils.get(index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package wyvern.stdlib.support; | ||
|
||
public class CommandLineUtils { | ||
private static DynArrayList argumentList; // array list of command line arguments. | ||
public static final CommandLineUtils utils = new CommandLineUtils(); | ||
|
||
public CommandLineUtils() { | ||
} | ||
|
||
public String get(int index) { | ||
return (String) argumentList.get(index); | ||
} | ||
|
||
public int size() { | ||
return argumentList.size(); | ||
} | ||
|
||
public void setArgumentList(String[] arguments) { | ||
this.argumentList = new DynArrayList(); | ||
for (String str : arguments) { | ||
argumentList.add(str); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters