Skip to content
Open
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
15 changes: 7 additions & 8 deletions gnu/getopt/GetoptDemo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import gnu.getopt.LongOpt;
import gnu.getopt.Getopt;
package gnu.getopt;

/*
* This sample code was written by Aaron M. Renn and is a demonstration
Expand All @@ -17,12 +16,12 @@ public class GetoptDemo
int c;
String arg;
LongOpt[] longopts = new LongOpt[3];
//
//
StringBuffer sb = new StringBuffer();
longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
longopts[1] = new LongOpt("outputdir", LongOpt.REQUIRED_ARGUMENT, sb, 'o');
longopts[1] = new LongOpt("outputdir", LongOpt.REQUIRED_ARGUMENT, sb, 'o');
longopts[2] = new LongOpt("maximum", LongOpt.OPTIONAL_ARGUMENT, null, 2);
//
//
Getopt g = new Getopt("testprog", argv, "-:bc::d:hW;", longopts);
g.setOpterr(false); // We'll do our own error handling
//
Expand All @@ -48,7 +47,7 @@ public class GetoptDemo
System.out.println("I know this, but pretend I didn't");
System.out.println("We picked option " +
longopts[g.getLongind()].getName() +
" with value " +
" with value " +
((arg != null) ? arg : "null"));
break;
//
Expand All @@ -59,7 +58,7 @@ public class GetoptDemo
case 'c':
case 'd':
arg = g.getOptarg();
System.out.println("You picked option '" + (char)c +
System.out.println("You picked option '" + (char)c +
"' with argument " +
((arg != null) ? arg : "null"));
break;
Expand All @@ -79,7 +78,7 @@ public class GetoptDemo
break;
//
case '?':
System.out.println("The option '" + (char)g.getOptopt() +
System.out.println("The option '" + (char)g.getOptopt() +
"' is not valid");
break;
//
Expand Down