2 // FILE: Flags.java Version 0.9.8
3 // (C) 2001 Frank R. Schaefer
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 //////////////////////////////////////////////////////////////////////////////////////
20 import java.lang.String;
23 public static void main(String args []) {
24 GetPot cl = new GetPot(args, "Flags");
25 if( cl.size() == 1 || cl.search("--help", "-h") ) print_help();
27 // does first argument contain 'x', 'X', 'c', 'C', 'k', or 'K' ?
28 boolean first_f = cl.argument_contains(1, "xX");
29 boolean second_f = cl.argument_contains(1, "cCkK");
31 // is there any option starting with '-' containing 'a', 'b', or 'c' ?
32 boolean abc_f = cl.options_contain("abc");
34 System.out.println("first flag = " + first_f);
35 System.out.println("second flag = " + second_f);
36 System.out.println("a, b, or c found = " + abc_f );
40 static void print_help() {
42 System.out.println("Example using flags:");
43 System.out.println("USAGE:");
44 System.out.println("--help, -h get some help about this program.");
46 System.out.println("The first argument will be checked if it contains 'x' or 'X'.");
47 System.out.println("If so the first flag will be set. The second flag will be set if");
48 System.out.println("the first argument contains a 'c', 'C', 'k', or a 'K'.");
50 System.out.println("The 'abc' flag is set when any argument starting with '-' contains an");
51 System.out.println("'a', 'b' or a 'c'.");