📄 getopttest.java
字号:
import com.darwinsys.util.GetOpt;/** Some test cases for GetOpt. * @author Ian F. Darwin, ian@darwinsys.com * @version $Id: GetOptTest.java,v 1.4 2001/04/15 17:50:56 ian Exp $ */public class GetOptTest { public static void main(String[] args) { process(goodArgChars, goodArgs); process(badArgChars, goodArgs); process(badArgChars, badArgs); } static String goodArgChars = "o:h"; static String goodArgs[] = { "-h", "-o", "outfile", "infile" }; static String badArgChars = "f1o"; static String badArgs[] = { "-h", "-o", "outfile", "infile" }; /** Private function, for testing. */ private static void process(String argChars, String[] args) { System.out.println("** START ** " + argChars + '(' + args.length + ')'); GetOpt go = new GetOpt(argChars); char c; int errs = 0; while ((c =go.getopt(args)) != 0) { if (c == '?') { System.out.print("Bad option"); ++errs; } else { System.out.print("Found " + c); if (go.optarg() != null) System.out.print("; Option " + go.optarg()); } System.out.println(); } // Process any filename-like arguments. for (int i=go.getOptInd(); i<args.length; i++) System.out.println("Filename-like arg " + args[i]); if (errs != 0) { System.out.println("At least one user error found"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -