01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05:
06: package com.sun.portal.search.util;
07:
08: import java.io.*;
09:
10: public class TestGetopt {
11:
12: public static void main(String[] args) { // test the class
13: System.out.println("---------- test 1 ------------");
14:
15: String flags = "ab?c:d:xy";
16: String[] argv = { "-ab", "-c", "carg", "-xy", "-cCARG", "--",
17: "-a" };
18: Getopt getopt = new Getopt(argv, flags);
19:
20: int c;
21: while (getopt.optInd < argv.length) {
22: c = getopt.getopt();
23: System.out.println((char) c + " " + getopt.optArg + "("
24: + getopt.optInd + ")");
25: }
26: System.out.println("final optInd (" + getopt.optInd + ")");
27:
28: System.out.println("------------ test 2 ------------");
29:
30: String[] argv1 = { "-ab", "carg", "kjh" };
31: getopt = new Getopt(argv1, flags);
32: getopt.optInd = 0;
33: while ((c = getopt.getopt()) != -1) {
34: System.out.println((char) c + " " + getopt.optArg + "("
35: + getopt.optInd + ")");
36: }
37: System.out.println("final optInd (" + getopt.optInd + ")");
38:
39: System.out.println("------------ test 3 ------------");
40:
41: String[] argv2 = { "-ab", "-d", "-x", "carg", "kjh" };
42: getopt = new Getopt(argv2, flags);
43: getopt.optInd = 0;
44: while ((c = getopt.getopt()) != -1) {
45: System.out.println((char) c + " " + getopt.optArg + "("
46: + getopt.optInd + ")");
47: }
48: System.out.println("final optInd (" + getopt.optInd + ")");
49:
50: System.out.println("------------ test 4 ------------");
51:
52: String[] argv3 = { "-ab", "-w", "-x", "carg", "kjh" };
53: getopt = new Getopt(argv3, flags);
54: getopt.optInd = 0;
55: while ((c = getopt.getopt()) != -1) {
56: System.out.println((char) c + " " + getopt.optArg + "("
57: + getopt.optInd + ")");
58: }
59: System.out.println("final optInd (" + getopt.optInd + ")");
60:
61: }
62: }
|