2 import java.lang.String;
6 public static void main(String args []) {
10 GetPot cl = disjoint gp1 new GetPot(args, "Flags");
11 if( cl.size() == 1 || cl.search("--help", "-h") ) print_help();
13 // does first argument contain 'x', 'X', 'c', 'C', 'k', or 'K' ?
14 boolean first_f = cl.argument_contains(1, "xX");
15 boolean second_f = cl.argument_contains(1, "cCkK");
17 // is there any option starting with '-' containing 'a', 'b', or 'c' ?
18 boolean abc_f = cl.options_contain("abc");
20 System.printString("first flag = " + first_f);
21 System.printString("second flag = " + second_f);
22 System.printString("a, b, or c found = " + abc_f );
26 cl = disjoint gp2 new GetPot(args, "DirectFollow");
28 if( cl.size() == 1 || cl.search("--help", "-h") ) print_help("DirectFollow");
30 // Specify, that in case the cursor reaches the end of argument list,
31 // it is not automatically reset to the start. This way the search
32 // functions do not wrap around. Instead, they notify an 'not fount'
33 // in case the option was not in between 'cursor' and the argv.end().
37 // check out 'String' versions
38 String User = cl.direct_follow("You", "-U");
39 String User2 = cl.direct_follow("Karl", "-U");
40 String User3 = cl.direct_follow("Heinz", "-U");
42 // check out 'double' versions
44 double Value = cl.direct_follow(3.14, "-V");
45 double Value2 = cl.direct_follow(9.81, "-V");
46 double Value3 = cl.direct_follow(1.62, "-V");
48 // check out 'integer' versions
50 int Number = cl.direct_follow(12, "-NUM");
51 int Number2 = cl.direct_follow(43, "-NUM");
52 int Number3 = cl.direct_follow(64, "-NUM");
54 something(User, User2, User3, Value, Value2, Value3, Number, Number2, Number3);
62 cl = disjoint gp3 new GetPot(args, "Filter");
63 GetPot ifpot = disjoint gp4 new GetPot("example.pot");
65 // (1) search for multiple options with the same meaning
66 if( cl.search("--help", "-h", "--hilfe", "--sos") ) {
67 String Msg = "Example program treating the prefix filtering.\n\n" +
68 " Using the function .set_prefix(section) only arguments, options \n" +
69 " variables are considered in the given 'section'\n\n" +
70 "--help, -h, --hilfe, --sos \n" +
73 " demonstrates how pseudo function calls can be accomplished.\n\n" +
74 "please refer to the file 'example.pot' as input file.\n";
75 System.printString(Msg);
79 // -- note that the prefix is not considered as a flag
80 // -- the index in 'argument contains' indicates the position
81 // of the argument inside the namespace given by prefix
82 ifpot.set_prefix("group/");
84 System.printString(" -- flags in options / arguments");
85 first_f = ifpot.argument_contains(1, "xX");
86 second_f = ifpot.argument_contains(1, "cCkK");
87 abc_f = ifpot.options_contain("abc");
88 System.printString(" Flags in first argument in [flags]\n");
89 System.printString(" x or X in arg 1 = " + first_f);
90 System.printString(" c, C, k or K in arg 1 = " + second_f);
91 System.printString(" a,b, or c in options = " + abc_f);
92 System.printString("");
93 System.printString(" -- search(), next() and follow()");
94 System.printString("");
95 System.printString(" found \"--rudimental\" = " + ifpot.search("--rudimental"));
97 int Tmp1 = ifpot.next(-1);
98 int Tmp2 = ifpot.next(-1);
99 System.printString(" followed by " + Tmp1 + " " + Tmp2);
101 String Tmp3 = ifpot.follow("nothing", "--rudimental");
102 int Tmp4 = ifpot.next(-1);
103 System.printString(" rudimental = " + Tmp3 + ", " + Tmp4 + "\n");
106 System.printString("");
107 System.printString(" -- variables in section [user-variables]");
108 System.printString("");
109 ifpot.set_prefix("user-variables/");
111 String variable_names[] = ifpot.get_variable_names();
112 for(int i=0; i < variable_names.length ; i++) {
113 String name = variable_names[i];
114 System.printString(" " + name + " \t= ");
115 System.printString(""+ifpot.call(name, 1e37, 0));
116 System.printString("[" + ifpot.call(name, "[1]", 1) + "]\n");
118 System.printString("");
120 // -- pseudo function calls
121 if( cl.search("--nice") ) {
122 System.printString(" -- pseudo function call feature");
123 System.printString("");
124 ifpot.set_prefix("pseudo-function-calls/");
125 ifpot.init_multiple_occurrence();
127 ifpot.search("LE-DEBUT");
128 while( 1 + 1 == 2 ) {
129 String Next = ifpot.next("(no-func)");
131 if( Next.compareTo("(no-func)") == 0 ) break;
132 else if( Next.compareTo("rectangle") == 0) {
133 int size_x = ifpot.next(10);
134 int size_y = ifpot.next(10);
135 System.printString("\n");
136 for(int y=0; y < size_y; y++) {
137 for(int x=0; x < size_x; x++) {
138 System.printString("*");
140 System.printString("\n");
143 else if( Next.compareTo("circle") == 0) {
144 int radius = ifpot.next(4);
145 System.printString("\n");
146 for(int y=0; y < radius*2 + 1; y++) {
147 for(int x=0; x < radius*2 + 1; x++)
148 if( Sqr(x-radius) + Sqr(y-radius) <= Sqr(radius)
149 && Sqr(x-radius) + Sqr(y-radius) >= Sqr(radius)/4. )
150 System.printString(".");
152 System.printString(" ");
153 System.printString("\n");
156 else if( Next.compareTo("smiley") == 0 ) {
157 String Mood = ifpot.next("happy");
158 if( Mood.compareTo("sad") == 0 ) System.printString(":( ");
159 else System.printString(":) ");
161 else if( Next.compareTo("new-line") == 0 ) {
162 int No = ifpot.next(1);
163 for(int i=0; i<No ;i++)
164 System.printString("\n");
169 System.printString("(use the --nice command line flag for graphical output)");
171 System.printString("");
178 static void something(String User, String User2, String User3,
179 double Value, double Value2, double Value3,
180 int Number, int Number2, int Number3) {
181 System.printString("Users = " + User + ", " + User2 + ", " + User3);
182 System.printString("Values = " + Value + ", " + Value2 + ", " + Value3);
183 System.printString("Numbers = " + Number + ", " + Number2 + ", " + Number3);
187 static double Sqr(double x) { return x*x; }
190 static void print_help() {
191 System.printString("help!");
195 static void print_help(String s) {
196 System.printString("help!");