--- /dev/null
+import GetPot.*;
+import java.lang.String;
+
+public class Example {
+
+ public static void main(String args []) {
+
+
+
+ GetPot cl = disjoint gp1 new GetPot(args, "Flags");
+ if( cl.size() == 1 || cl.search("--help", "-h") ) print_help();
+
+ // does first argument contain 'x', 'X', 'c', 'C', 'k', or 'K' ?
+ boolean first_f = cl.argument_contains(1, "xX");
+ boolean second_f = cl.argument_contains(1, "cCkK");
+
+ // is there any option starting with '-' containing 'a', 'b', or 'c' ?
+ boolean abc_f = cl.options_contain("abc");
+
+ System.printString("first flag = " + first_f);
+ System.printString("second flag = " + second_f);
+ System.printString("a, b, or c found = " + abc_f );
+
+
+
+ cl = disjoint gp2 new GetPot(args, "DirectFollow");
+
+ if( cl.size() == 1 || cl.search("--help", "-h") ) print_help("DirectFollow");
+
+ // Specify, that in case the cursor reaches the end of argument list,
+ // it is not automatically reset to the start. This way the search
+ // functions do not wrap around. Instead, they notify an 'not fount'
+ // in case the option was not in between 'cursor' and the argv.end().
+ cl.reset_cursor();
+ cl.disable_loop();
+
+ // check out 'String' versions
+ String User = cl.direct_follow("You", "-U");
+ String User2 = cl.direct_follow("Karl", "-U");
+ String User3 = cl.direct_follow("Heinz", "-U");
+
+ // check out 'double' versions
+ cl.reset_cursor();
+ double Value = cl.direct_follow(3.14, "-V");
+ double Value2 = cl.direct_follow(9.81, "-V");
+ double Value3 = cl.direct_follow(1.62, "-V");
+
+ // check out 'integer' versions
+ cl.reset_cursor();
+ int Number = cl.direct_follow(12, "-NUM");
+ int Number2 = cl.direct_follow(43, "-NUM");
+ int Number3 = cl.direct_follow(64, "-NUM");
+
+ something(User, User2, User3, Value, Value2, Value3, Number, Number2, Number3);
+
+
+
+
+
+
+
+ cl = disjoint gp3 new GetPot(args, "Filter");
+ GetPot ifpot = disjoint gp4 new GetPot("example.pot");
+
+ // (1) search for multiple options with the same meaning
+ if( cl.search("--help", "-h", "--hilfe", "--sos") ) {
+ String Msg = "Example program treating the prefix filtering.\n\n" +
+ " Using the function .set_prefix(section) only arguments, options \n" +
+ " variables are considered in the given 'section'\n\n" +
+ "--help, -h, --hilfe, --sos \n" +
+ " this page.\n" +
+ "--nice \n" +
+ " demonstrates how pseudo function calls can be accomplished.\n\n" +
+ "please refer to the file 'example.pot' as input file.\n";
+ System.printString(Msg);
+ System.exit(0);
+ }
+
+ // -- note that the prefix is not considered as a flag
+ // -- the index in 'argument contains' indicates the position
+ // of the argument inside the namespace given by prefix
+ ifpot.set_prefix("group/");
+
+ System.printString(" -- flags in options / arguments");
+ first_f = ifpot.argument_contains(1, "xX");
+ second_f = ifpot.argument_contains(1, "cCkK");
+ abc_f = ifpot.options_contain("abc");
+ System.printString(" Flags in first argument in [flags]\n");
+ System.printString(" x or X in arg 1 = " + first_f);
+ System.printString(" c, C, k or K in arg 1 = " + second_f);
+ System.printString(" a,b, or c in options = " + abc_f);
+ System.printString("");
+ System.printString(" -- search(), next() and follow()");
+ System.printString("");
+ System.printString(" found \"--rudimental\" = " + ifpot.search("--rudimental"));
+
+ int Tmp1 = ifpot.next(-1);
+ int Tmp2 = ifpot.next(-1);
+ System.printString(" followed by " + Tmp1 + " " + Tmp2);
+
+ String Tmp3 = ifpot.follow("nothing", "--rudimental");
+ int Tmp4 = ifpot.next(-1);
+ System.printString(" rudimental = " + Tmp3 + ", " + Tmp4 + "\n");
+
+ // -- variables
+ System.printString("");
+ System.printString(" -- variables in section [user-variables]");
+ System.printString("");
+ ifpot.set_prefix("user-variables/");
+
+ String variable_names[] = ifpot.get_variable_names();
+ for(int i=0; i < variable_names.length ; i++) {
+ String name = variable_names[i];
+ System.printString(" " + name + " \t= ");
+ System.printString(""+ifpot.call(name, 1e37, 0));
+ System.printString("[" + ifpot.call(name, "[1]", 1) + "]\n");
+ }
+ System.printString("");
+
+ // -- pseudo function calls
+ if( cl.search("--nice") ) {
+ System.printString(" -- pseudo function call feature");
+ System.printString("");
+ ifpot.set_prefix("pseudo-function-calls/");
+ ifpot.init_multiple_occurrence();
+
+ ifpot.search("LE-DEBUT");
+ while( 1 + 1 == 2 ) {
+ String Next = ifpot.next("(no-func)");
+
+ if( Next.compareTo("(no-func)") == 0 ) break;
+ else if( Next.compareTo("rectangle") == 0) {
+ int size_x = ifpot.next(10);
+ int size_y = ifpot.next(10);
+ System.printString("\n");
+ for(int y=0; y < size_y; y++) {
+ for(int x=0; x < size_x; x++) {
+ System.printString("*");
+ }
+ System.printString("\n");
+ }
+ }
+ else if( Next.compareTo("circle") == 0) {
+ int radius = ifpot.next(4);
+ System.printString("\n");
+ for(int y=0; y < radius*2 + 1; y++) {
+ for(int x=0; x < radius*2 + 1; x++)
+ if( Sqr(x-radius) + Sqr(y-radius) <= Sqr(radius)
+ && Sqr(x-radius) + Sqr(y-radius) >= Sqr(radius)/4. )
+ System.printString(".");
+ else
+ System.printString(" ");
+ System.printString("\n");
+ }
+ }
+ else if( Next.compareTo("smiley") == 0 ) {
+ String Mood = ifpot.next("happy");
+ if( Mood.compareTo("sad") == 0 ) System.printString(":( ");
+ else System.printString(":) ");
+ }
+ else if( Next.compareTo("new-line") == 0 ) {
+ int No = ifpot.next(1);
+ for(int i=0; i<No ;i++)
+ System.printString("\n");
+ }
+ }
+ }
+ else {
+ System.printString("(use the --nice command line flag for graphical output)");
+ }
+ System.printString("");
+ }
+
+
+
+
+
+ static void something(String User, String User2, String User3,
+ double Value, double Value2, double Value3,
+ int Number, int Number2, int Number3) {
+ System.printString("Users = " + User + ", " + User2 + ", " + User3);
+ System.printString("Values = " + Value + ", " + Value2 + ", " + Value3);
+ System.printString("Numbers = " + Number + ", " + Number2 + ", " + Number3);
+ }
+
+
+ static double Sqr(double x) { return x*x; }
+
+
+ static void print_help() {
+ System.printString("help!");
+ System.exit(0);
+ }
+
+ static void print_help(String s) {
+ System.printString("help!");
+ System.exit(0);
+ }
+}
+
+
+
--- /dev/null
+import java.io.*;
+import java.lang.String.*;
+import java.lang.Object.*;
+import java.lang.NumberFormatException;
+import java.lang.Integer;
+import java.lang.Double;
+import java.util.*;
+
+
+// variable structure
+public class variable {
+ // (*) constructor
+ variable(String Name, String Value) {
+ name = Name;
+ take(Value);
+ }
+ variable() {
+ name = "";
+ value = new String[1];
+ value[0] = "";
+ original = "";
+ }
+ // (*) get a specific element in the string vector
+ String get_element(int Idx) {
+ if( Idx < 0 || Idx > value.length ) return new String("");
+ else return value[Idx];
+ }
+
+ void take(String Value) {
+ original = Value;
+ StringTokenizer st = new StringTokenizer(Value);
+ value = new String[st.countTokens()];
+ for(int i =0; st.hasMoreTokens(); i++ )
+ value[i] = st.nextToken();
+ }
+ // (*) data memebers
+ String name; // identifier of variable
+ String value[]; // value of variable stored in vector
+ String original; // value of variable as given on command line
+}
+
+
+public class GetPot {
+ String prefix; // prefix indicating section for search
+ String section; // section for dollar bracket parsing
+ Vector argv; // String[]
+ Vector section_list;
+ int cursor;
+ Vector idx_nominus; // int[]
+ int nominus_cursor;
+ boolean search_loop_f;
+ boolean search_failed_f;
+ Vector variables; // class variable
+
+
+ // (*) constructor
+ GetPot(String argv_[], String applicationName) {
+ prefix = "";
+ cursor = 0;
+ nominus_cursor = -1;
+ search_loop_f = true;
+ search_failed_f = false;
+
+ Vector __argv = new Vector();
+ idx_nominus = new Vector();
+ variables = new Vector();
+ section_list = new Vector();
+
+ // in java the argv[0] does not contain the application name
+ // => append application name to argv vector by hand
+
+ for(int i=0; i < argv_.length ; i++) {
+ String copied_str = new String(argv_[i]);
+ __argv.addElement(copied_str);
+ }
+
+ argv = new Vector();
+ __argv.insertElementAt(applicationName, 0);
+ __parse_argument_vector(__argv);
+ }
+
+ GetPot(String FileName) {
+ prefix = "";
+ cursor = 0;
+ nominus_cursor = -1;
+ search_loop_f = true;
+ search_failed_f = false;
+
+ Vector __argv = new Vector();
+ idx_nominus = new Vector();
+ variables = new Vector();
+ section_list = new Vector();
+
+ __argv = read_in_file(FileName);
+
+ argv = new Vector();
+ __argv.insertElementAt(FileName, 0);
+ __parse_argument_vector(__argv);
+ }
+
+ void __parse_argument_vector(Vector _argv) {
+ // build internal database
+ // 1) array with no-minus arguments (usually used as filenames)
+ // 2) section label treatment
+ // 3) variable assignments:
+ // 'variable name' '=' number | string
+ int i=0;
+ section = "";
+ Vector section_stack = new Vector();
+ if( _argv.size() < 1 ) return;
+
+
+ for( ; i < _argv.size(); i++) {
+ String arg = (String)_argv.elementAt(i);
+
+ if( i == 0 ) {
+ argv.addElement(arg);
+ // continue;
+ } else if( arg.length() == 0) {
+ // continue;
+ } else {
+
+ // -- [section] labels
+ if( arg.length() > 1 && arg.charAt(0) == '[' && arg.charAt(arg.length()-1) == ']' ) {
+ String name = DBE_expand_string(arg.substring(1, arg.length()-1));
+ // String name = arg.substring(1, arg.length()-1);
+ section = process_section_label(name, section_stack);
+ // new section --> append to list of sections
+ if( section_list.indexOf(section) == -1 )
+ if( section.length() != 0 ) section_list.addElement(section);
+ argv.addElement(arg);
+ }
+ else {
+ arg = section + DBE_expand_string(arg);
+ argv.addElement(arg);
+ }
+
+ // 1) separate array for nominus arguments
+ if( arg.charAt(0) != '-' )
+ idx_nominus.addElement(new Integer(i));
+
+ // 2) variables: does _argv[i] contain a '=' operator ?
+ int k = arg.indexOf('=');
+ if( k > 0 ) {
+ variable Var = find_variable(arg.substring(0,k));
+ if( Var.name.compareTo("") == 0 )
+ variables.addElement(disjoint arg new variable(arg.substring(0,k),
+ arg.substring(k+1)));
+ else
+ Var.take(arg.substring(k+1));
+ }
+ }
+ }
+ }
+ // file parsing
+ Vector read_in_file(String filename) {
+ Vector Empty = new Vector();
+
+ FileInputStream i = new FileInputStream(filename);
+ //if( i.available() == 0 ) return Empty;
+ // argv[0] == the filename of the file that was read in
+ return read_in_stream(new PushbackInputStream(i));
+ }
+
+ Vector read_in_stream(PushbackInputStream istr) {
+ Vector brute_tokens = new Vector();
+ String token;
+ Vector arglist = new Vector();
+
+ boolean vcontinue = true;
+ while( 1 + 1 == 2 && vcontinue ) {
+ if( __skip_whitespace(istr) == -1 ) {
+ //break;
+ vcontinue = false;
+ } else {
+ token = __get_next_token(istr);
+ if( token.length() == 0 ) {
+ //break;
+ vcontinue = false;
+ } else {
+ brute_tokens.addElement(token);
+ }
+ }
+ }
+
+ // for(int i=0; i<brute_tokens.size() ; i++)
+ // System.printString((String)(brute_tokens.elementAt(i)));
+
+ // -- reduce expressions of token1'='token2 to a single
+ // string 'token1=token2'
+ // -- copy everything into 'result'
+ // -- arguments preceded by something like '[' name ']' (section)
+ // produce a second copy of each argument with a prefix '[name]argument'
+ int i1 = 0;
+ int i2 = 1;
+ int i3 = 2;
+ String section = new String("");
+
+ while( i1 < brute_tokens.size() ) {
+ String SRef = (String)brute_tokens.elementAt(i1);
+ // 1) concatinate 'abcdef' '=' 'efgasdef' to 'abcdef=efgasdef'
+ // note: java.lang.String: substring(a,b) = from a to b-1
+ // C++ string: substr(a,b) = from a to a + b
+ if( i2 < brute_tokens.size() && ((String)brute_tokens.elementAt(i2)).charAt(0) == '=' ) {
+ if( i3 >= brute_tokens.size() )
+ arglist.addElement((String)brute_tokens.elementAt(i1)
+ + (String)brute_tokens.elementAt(i2));
+ else
+ arglist.addElement((String)brute_tokens.elementAt(i1)
+ + (String)brute_tokens.elementAt(i2)
+ + (String)brute_tokens.elementAt(i3));
+
+ i1 = i3+1; i2 = i3+2; i3 = i3+3;
+ //continue;
+ }
+ else {
+ arglist.addElement(SRef);
+ i1=i2; i2=i3; i3++;
+ }
+ }
+ return arglist;
+ }
+
+
+ int __skip_whitespace(PushbackInputStream istr) {
+
+ while( 1 + 1 == 2 ) {
+ int tmp = istr.read(); // read first character out of stream
+ if( tmp == -1 ) return -1;
+ while( (char)tmp == ' ' || (char)tmp == '\t' || (char)tmp == '\n' )
+ { tmp = istr.read(); if( tmp == -1 ) return -1; }
+
+ // found a non whitespace
+ if( (char)tmp == '#' ) {
+ // comment => skip until end of line
+ do { tmp = istr.read(); if( tmp == -1 ) return -1; }
+ while( (char)tmp != '\n' );
+
+ istr.unread(tmp);
+ //continue;
+ }
+ else {
+ // go back to last mark
+ istr.unread(tmp);
+ return 1;
+ }
+ }
+ return 1;
+ }
+
+ String __get_next_token(PushbackInputStream istr) {
+ // get next concatinates string token. consider quotes that embrace
+ // whitespaces
+
+ String token = new String("");
+ int tmp0 = 0;
+ int tmp = 0;
+ int last_letter = 0;
+ while(1+1 == 2) {
+ last_letter = tmp; tmp0 = istr.read(); tmp = tmp0;
+ if( tmp == -1
+ || ((tmp == ' ' || tmp == '\t' || tmp == '\n') && last_letter != '\\') ) {
+ return token;
+ }
+ else if( tmp == '\'' && last_letter != '\\' ) {
+ // QUOTES: un-backslashed quotes => it's a string
+ token += __get_string(istr);
+ //continue;
+ }
+ else if( tmp == '{' && last_letter == '$') {
+ token += '{' + __get_until_closing_bracket(istr);
+ //continue;
+ }
+ else if( tmp == '$' && last_letter == '\\') {
+ token += tmp; tmp = 0; // so that last_letter will become = 0, not '$';
+ //continue;
+ }
+ else if( tmp == '\\' && last_letter != '\\')
+ //continue; // don't append un-backslashed backslashes
+ token += tmp;
+ }
+
+ return "";
+ }
+
+ String __get_string(PushbackInputStream istr) {
+ // parse input until next matching '
+
+ String str = new String("");
+ int tmp0 = 0;
+ int tmp = 0;
+ int last_letter = 0;
+ while(1 + 1 == 2) {
+ last_letter = tmp; tmp0 = istr.read(); tmp = tmp0;
+ if( tmp0 == -1 ) return str;
+ // un-backslashed quotes => it's the end of the string
+ else if( tmp == '\'' && last_letter != '\\') return str;
+ else if( tmp == '\\' && last_letter != '\\') {
+ //continue; // don't append
+
+ } else {
+ str += tmp;
+ }
+ }
+ // return str;
+ return "";
+ }
+
+ String __get_until_closing_bracket(PushbackInputStream istr) {
+
+ // parse input until next matching }
+ String str = new String("");
+ int tmp0 = 0;
+ int tmp = 0;
+ int last_letter = 0;
+ int brackets = 1;
+ while(1 + 1 == 2) {
+ last_letter = tmp; tmp0 = istr.read(); tmp = tmp0;
+ boolean vcontinue = false;
+ if( tmp == -1 ) return str;
+ else if( tmp == '{' && last_letter == '$') brackets += 1;
+ else if( tmp == '}') {
+ brackets -= 1;
+ // un-backslashed brackets => it's the end of the string
+ if( brackets == 0) return str + '}';
+ else if( tmp == '\\' && last_letter != '\\') {
+ //continue; // do not append an unbackslashed backslash
+ vcontinue = true;
+ }
+ }
+ if( !vcontinue ) {
+ str += tmp;
+ }
+ }
+ return "";
+ }
+
+ String process_section_label(String label,
+ Vector section_stack) {
+ String sname = label;
+ // 1) subsection of actual section ('./' prefix)
+ if( sname.length() >= 2 && sname.substring(0, 2).compareTo("./") == 0) {
+ sname = sname.substring(2, sname.length());
+ }
+ // 2) subsection of parent section ('../' prefix)
+ else if( sname.length() >= 3 && sname.substring(0, 3).compareTo("../") == 0) {
+ do {
+ if( section_stack.size() != 0 )
+ section_stack.removeElementAt(section_stack.size()-1);
+ sname = sname.substring(3, sname.length());
+ } while( sname.substring(0, 3).compareTo("../") == 0 );
+ }
+ // 3) subsection of the root-section
+ else {
+ // a root section
+ section_stack.removeAllElements();
+ }
+
+ if( sname.compareTo("") != 0 ) {
+ // parse section name for 'slashes'
+ int i=0;
+ while( i < sname.length() ) {
+ if( sname.charAt(i) == '/' ) {
+ section_stack.addElement(sname.substring(0,i));
+ if( i+1 < sname.length()-1 )
+ sname = sname.substring(i+1, sname.length());
+ i = 0;
+ }
+ else
+ i++;
+ }
+ section_stack.addElement(sname);
+ }
+ // else: "[]" => back to root section
+
+ String section = new String("");
+ if( section_stack.size() != 0 )
+ for(int i=0; i< section_stack.size() ; i++)
+ section += (String)(section_stack.elementAt(i)) + "/";
+ return section;
+ }
+ // (*) helper functions
+ int __convert_to_type(String S, int Default) {
+ int start_i = 0;
+ if( S.length() >= 2 && S.substring(0,2).compareTo("0x") == 0 ) start_i = 2;
+ else if( S.length() >=3 && S.substring(0,3).compareTo("-0x") == 0) start_i = 3;
+ else {
+ // a normal integer, not a hex number
+ return Integer.parseInt(S);
+ }
+
+ // a hexadecimal number
+ int number = 0;
+ int i=start_i;
+ boolean vcontinue = true;
+ while( i<S.length() && vcontinue ) {
+ int c = (int)S.charAt(i);
+ int digit = 0;
+ if( c >= '0' && c <= '9') digit = c - '0';
+ else if( c >= 'a' && c <= 'f') digit = c - 'a';
+ else if( c >= 'A' && c <= 'F') digit = c - 'a';
+ else {
+ //break;
+ vcontinue = false;
+ }
+ if( !vcontinue ) {
+ number *= 16;
+ number += digit;
+ }
+ i++;
+ }
+ if( start_i == 2 ) return number;
+ else return -number;
+ }
+
+ double __convert_to_type(String S, double Default) {
+ return (double)Integer.parseInt(S);
+ }
+
+ void set_prefix(String Prefix) { prefix = Prefix; }
+
+ String __get_remaining_string(String String, String Start) {
+ // Checks if 'String' begins with 'Start' and returns the remaining String.
+ // Returns None if String does not begin with Start.
+
+ // note: java.lang.String: substring(a,b) = from a to b-1
+ // C++ string: substr(a,b) = from a to a + b
+ if( Start.compareTo("") == 0 ) return String;
+ if( String.indexOf(Start) == 0 ) return String.substring(Start.length(), String.length());
+ else return "";
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) cursor oriented functions
+ //.............................................................................
+ //
+ void disable_loop() { search_loop_f = false; }
+ void enable_loop() { search_loop_f = true; }
+ void reset_cursor() { search_failed_f = false; cursor = 0; }
+
+ void init_multiple_occurrence()
+ { disable_loop(); reset_cursor(); }
+
+ // -- search for a certain argument and set cursor to position
+ boolean search(String Option) {
+ int OldCursor = cursor;
+ String SearchTerm = prefix + Option;
+
+ if( OldCursor >= argv.size() ) OldCursor = argv.size() - 1;
+ search_failed_f = true;
+
+ // (*) first loop from cursor position until end
+ for(int c = cursor; c < argv.size(); c++) {
+ if( ((String)argv.elementAt(c)).compareTo(SearchTerm) == 0 )
+ { cursor = c; search_failed_f = false; return true; }
+ }
+ if( ! search_loop_f ) return false;
+
+ // (*) second loop from 0 to old cursor position
+ for(int c = 1; c < OldCursor; c++) {
+ if( ((String)argv.elementAt(c)).compareTo(SearchTerm) == 0 )
+ { cursor = c; search_failed_f = false; return true; }
+ }
+ // in case nothing is found the cursor stays where it was
+ return false;
+ }
+
+
+ boolean search(String P[]) {
+ for(int i=0; i<P.length; i++)
+ if( search(P[i]) == true ) return true;
+ return false;
+ }
+
+ boolean search(String P1, String P2) {
+ if( search(P1) == true ) return true;
+ else if( search(P2) == true ) return true;
+ else return false;
+ }
+
+ boolean search(String P1, String P2, String P3) {
+ if( search(P1, P2) == true ) return true;
+ else if( search(P3) == true ) return true;
+ else return false;
+ }
+
+ boolean search(String P1, String P2, String P3, String P4) {
+ if( search(P1, P2, P3) == true ) return true;
+ else if( search(P4) == true ) return true;
+ else return false;
+ }
+
+ boolean search(String P1, String P2, String P3, String P4,
+ String P5) {
+ if( search(P1, P2, P3, P4) == true ) return true;
+ else if( search(P5) == true ) return true;
+ else return false;
+ }
+
+ boolean search(String P1, String P2, String P3, String P4,
+ String P5, String P6) {
+ if( search(P1, P2, P3, P4, P5) == true ) return true;
+ else if( search(P6) == true ) return true;
+ else return false;
+ }
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) No operator overloading in java
+ // => give them the 'python names'
+ String getitem(int idx) {
+ if( idx < argv.size() ) return (String)argv.elementAt(idx) ;
+ else return new String("");
+ }
+
+ int get(int Idx, int Default) {
+ if( Idx >= argv.size() ) return Default;
+ return __convert_to_type((String)argv.elementAt(Idx), Default);
+ }
+
+ double get(int Idx, double Default) {
+ if( Idx >= argv.size() ) return Default;
+ return __convert_to_type((String)argv.elementAt(Idx), Default);
+ }
+
+ String get(int Idx, String Default) {
+ if( Idx >= argv.size() ) return Default;
+ else return (String)argv.elementAt(Idx);
+ }
+
+ int size() { return argv.size(); }
+ // -- next() function group
+ int next(int Default) {
+ if( search_failed_f ) return Default;
+ cursor++;
+ if( cursor >= argv.size() )
+ { cursor = argv.size(); return Default; }
+
+ if( prefix.compareTo("") == 0)
+ return __convert_to_type((String)argv.elementAt(cursor), Default);
+
+ String Remain = __get_remaining_string((String)argv.elementAt(cursor), prefix);
+
+ if( Remain.compareTo("") != 0 ) {
+ return __convert_to_type(Remain, Default);
+ } else {
+ return Default;
+ }
+ }
+
+ double next(double Default) {
+ if( search_failed_f ) return Default;
+ cursor++;
+ if( cursor >= argv.size() )
+ { cursor = argv.size(); return Default; }
+
+ if( prefix.compareTo("") == 0)
+ return __convert_to_type((String)argv.elementAt(cursor), Default);
+
+ String Remain = __get_remaining_string((String)argv.elementAt(cursor), prefix);
+
+ if( Remain.compareTo("") != 0 ) {
+ return __convert_to_type(Remain, Default);
+ } else {
+ return Default;
+ }
+ }
+
+ String next(String Default) {
+ if( search_failed_f ) return Default;
+ cursor++;
+ if( cursor >= argv.size() )
+ { cursor = argv.size(); return Default; }
+
+ if( prefix.compareTo("") == 0)
+ return (String)argv.elementAt(cursor);
+
+ String Remain = __get_remaining_string((String)argv.elementAt(cursor), prefix);
+
+ if( Remain.compareTo("") != 0 ) {
+ return Remain;
+ } else {
+ return Default;
+ }
+ }
+ // -- follow() function group
+ // distinct option to be searched for
+ int follow(int Default, String A1) {
+ if( search(A1) == false ) return Default;
+ return next(Default);
+ }
+ int follow(int Default, String A[]) {
+ if( search(A) == false ) return Default;
+ return next(Default);
+ }
+ int follow(int Default, String A1, String A2) {
+ if( search(A1, A2) == false ) return Default;
+ return next(Default);
+ }
+ int follow(int Default, String A1, String A2, String A3) {
+ if( search(A1, A2, A3) == false ) return Default;
+ return next(Default);
+ }
+ int follow(int Default, String A1, String A2, String A3, String A4) {
+ if( search(A1, A2, A3, A4) == false ) return Default;
+ return next(Default);
+ }
+ int follow(int Default, String A1, String A2, String A3, String A4,
+ String A5) {
+ if( search(A1, A2, A3, A4, A5) == false ) return Default;
+ return next(Default);
+ }
+ int follow(int Default, String A1, String A2, String A3, String A4,
+ String A5, String A6) {
+ if( search(A1, A2, A3, A4, A5, A6) == false ) return Default;
+ return next(Default);
+ }
+
+ ///////// double
+ double follow(double Default, String A1) {
+ if( search(A1) == false ) return Default;
+ return next(Default);
+ }
+ double follow(double Default, String A[]) {
+ if( search(A) == false ) return Default;
+ return next(Default);
+ }
+ double follow(double Default, String A1, String A2) {
+ if( search(A1, A2) == false ) return Default;
+ return next(Default);
+ }
+ double follow(double Default, String A1, String A2, String A3) {
+ if( search(A1, A2, A3) == false ) return Default;
+ return next(Default);
+ }
+ double follow(double Default, String A1, String A2, String A3, String A4) {
+ if( search(A1, A2, A3, A4) == false ) return Default;
+ return next(Default);
+ }
+ double follow(double Default, String A1, String A2, String A3, String A4,
+ String A5) {
+ if( search(A1, A2, A3, A4, A5) == false ) return Default;
+ return next(Default);
+ }
+ double follow(double Default, String A1, String A2, String A3, String A4,
+ String A5, String A6) {
+ if( search(A1, A2, A3, A4, A5, A6) == false ) return Default;
+ return next(Default);
+ }
+ ///////// String ...
+ String follow(String Default, String A1) {
+ if( search(A1) == false ) return Default;
+ return next(Default);
+ }
+ String follow(String Default, String A[]) {
+ if( search(A) == false ) return Default;
+ return next(Default);
+ }
+ String follow(String Default, String A1, String A2) {
+ if( search(A1, A2) == false ) return Default;
+ return next(Default);
+ }
+ String follow(String Default, String A1, String A2, String A3) {
+ if( search(A1, A2, A3) == false ) return Default;
+ return next(Default);
+ }
+ String follow(String Default, String A1, String A2, String A3, String A4) {
+ if( search(A1, A2, A3, A4) == false ) return Default;
+ return next(Default);
+ }
+ String follow(String Default, String A1, String A2, String A3, String A4,
+ String A5) {
+ if( search(A1, A2, A3, A4, A5) == false ) return Default;
+ return next(Default);
+ }
+ String follow(String Default, String A1, String A2, String A3, String A4,
+ String A5, String A6) {
+ if( search(A1, A2, A3, A4, A5, A6) == false ) return Default;
+ return next(Default);
+ }
+ // (*) directly followed arguments
+ int direct_follow(int Default, String Option) {
+ String FollowStr = match_starting_string(Option);
+ if( FollowStr.compareTo("") == 0 ) return Default;
+
+ int Value = __convert_to_type(FollowStr, Default);
+ if( ++cursor >= argv.size() ) cursor = argv.size();
+ return Value;
+ }
+
+ double direct_follow(double Default, String Option) {
+ String FollowStr = match_starting_string(Option);
+ if( FollowStr.compareTo("") == 0 ) return Default;
+ double Value = __convert_to_type(FollowStr, Default);
+ if( ++cursor >= argv.size() ) cursor = argv.size();
+ return Value;
+ }
+
+ String direct_follow(String Default, String Option) {
+ String FollowStr = match_starting_string(Option);
+ if( FollowStr.compareTo("") == 0) return Default;
+ if( ++cursor >= argv.size() ) cursor = argv.size();
+ return FollowStr;
+ }
+
+ String match_starting_string(String StartString) {
+ // pointer to the place where the string after
+ // the match inside the found argument starts.
+ // 0 no argument matches the starting string.
+ int N = StartString.length();
+ int OldCursor = cursor;
+ if( OldCursor >= argv.size() ) OldCursor = argv.size() - 1;
+ search_failed_f = true;
+
+ // (*) first loop from cursor position until end
+ for(int c = cursor; c < argv.size(); c++) {
+ String Arg = (String)argv.elementAt(c);
+ if( Arg.length() >= N && Arg.substring(0,N).compareTo(StartString) == 0) {
+ cursor = c; search_failed_f = false;
+ return ((String)argv.elementAt(c)).substring(N);
+ }
+ }
+
+ if( search_loop_f == false ) return "";
+
+ // (*) second loop from 0 to old cursor position
+ for(int c = 1; c < OldCursor; c++) {
+ String Arg = (String)argv.elementAt(c);
+ if( Arg.length() >= N && Arg.substring(0,N).compareTo(StartString)==0 ) {
+ cursor = c; search_failed_f = false;
+ return ((String)argv.elementAt(c)).substring(N);
+ }
+ }
+ return "";
+ }
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) search for flags
+ //.............................................................................
+ //
+ boolean options_contain(String FlagList) {
+ // go through all arguments that start with a '-', but not more than one
+ for(int i = 0; i<argv.size() ; i++) {
+ String str;
+ if( prefix.compareTo("") != 0 ) str = __get_remaining_string((String)argv.elementAt(i), prefix);
+ else str = (String)argv.elementAt(i);
+
+ if( str.length() > 1 && str.charAt(0) == '-' && str.charAt(1) != '-' )
+ if( check_flags(str, FlagList) ) return true;
+ }
+ return false;
+ }
+
+ boolean argument_contains(int Idx, String FlagList) {
+ if( Idx >= argv.size() || Idx < 0) return false;
+
+ if( prefix.compareTo("") == 0 )
+ return check_flags((String)argv.elementAt(Idx), FlagList);
+
+ // if a prefix is set, then the argument index is the index
+ // inside the 'namespace'
+ // => only check list of arguments that start with prefix
+ int no_matches = 0;
+ for(int i=0; i < argv.size(); i++) {
+ String Remain = __get_remaining_string((String)argv.elementAt(i), prefix);
+ if( Remain.compareTo("") != 0 ) {
+ no_matches += 1;
+ if( no_matches == Idx)
+ return check_flags(Remain, FlagList);
+ }
+ }
+ // no argument in this namespace
+ return false;
+
+ }
+
+ boolean check_flags(String Str, String FlagList) {
+ for(int i=0; i != FlagList.length() ; i++)
+ if( Str.indexOf(FlagList.charAt(i)) != -1 )
+ // one of the flags was found in given string
+ return true;
+ return false;
+ }
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) nominus arguments
+ String[] nominus_vector() {
+ String nv[] = new String[idx_nominus.size()];
+ int i=0;
+ for( ; i < idx_nominus.size(); i++) {
+ Integer e = (Integer)idx_nominus.elementAt(i);
+ nv[i] = (String)argv.elementAt(e.intValue());
+ }
+ return nv;
+ }
+
+ String next_nominus() {
+ if( nominus_cursor >= idx_nominus.size()-1 ) return "";
+ int C = ++nominus_cursor;
+ return (String)argv.elementAt(((Integer)idx_nominus.elementAt(C)).intValue());
+ }
+
+ void reset_nominus_cursor()
+ { nominus_cursor = -1; }
+
+ boolean search_failed()
+ { return search_failed_f; }
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) variables
+ // (no operator overloading, => functions with 'python names' for
+ // operators
+ int call(String VarName, int Default) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0 ) return Default;
+ return __convert_to_type(sv.original, Default);
+ }
+
+ double call(String VarName, double Default) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0) return Default;
+ return __convert_to_type(sv.original, Default);
+ }
+
+ String call(String VarName, String Default) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0) return Default;
+ return sv.original;
+ }
+
+ int call(String VarName, int Default, int Idx) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0) return Default;
+ String element = sv.get_element(Idx);
+ if( element.compareTo("") == 0) return Default;
+ return __convert_to_type(element, Default);
+ }
+
+ double call(String VarName, double Default, int Idx) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0) return Default;
+ String element = sv.get_element(Idx);
+ if( element.compareTo("") == 0) return Default;
+ return __convert_to_type(element, Default);
+ }
+
+ String call(String VarName, String Default, int Idx) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0) return Default;
+ String element = sv.get_element(Idx);
+ if( element.compareTo("") == 0) return Default;
+ return element;
+ }
+
+ int vector_variable_size(String VarName) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0) return 0;
+ return sv.value.length;
+ }
+
+ variable find_variable(String NameX) {
+ String Name = prefix + NameX;
+ for( int i = 0; i < variables.size(); ++i ) {
+ variable v = (variable)variables.elementAt(i);
+ if( v.name.compareTo(Name) == 0 ) return v;
+ }
+ return disjoint empty new variable("","");
+ }
+
+ String[] get_variable_names() {
+ Vector result = new Vector();
+ int length = 0;
+ for( int i = 0; i < variables.size(); ++i ) {
+ String Name = ((variable)variables.elementAt(i)).name;
+ String Tmp = __get_remaining_string(Name, prefix);
+ if( Tmp != "") {
+ result.addElement(new String(Tmp));
+ length++;
+ }
+ }
+ String end[] = new String[length];
+ for( int i = 0; i < result.size(); ++i ) {
+ String Name = (String)result.elementAt(i);
+ end[i] = Name;
+ }
+ return end;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) ouput (basically for debugging reasons)
+ //.............................................................................
+ //
+ void print() {
+ System.printString("argc = " + argv.size() + "\n");
+ for(int i=0; i<argv.size() ; i++)
+ System.printString(""+argv.elementAt(i));
+ return;
+ }
+
+ // (*) dollar bracket expressions (DBEs) ------------------------------------
+ //
+ // 1) Entry Function: dbe_expand_string()
+ // Takes a string such as
+ //
+ // "${+ ${x} ${y}} Subject-${& ${section} ${subsection}}: ${title}"
+ //
+ // calls DBE_expand_string() for each of the expressions
+ //
+ // ${+ ${x} ${y}}
+ // ${& ${section} ${subsection}}
+ // ${Title}
+ //
+ // and returns the string
+ //
+ // "4711 Subject-1.01: Mit den Clowns kamen die Schwaene"
+ //
+ // assuming that
+ // x = "4699"
+ // y = "12"
+ // section = "1."
+ // subsection = "01"
+ // title = "Mit den Clowns kamen die Schwaene"
+ //
+ // 2) DBE_expand():
+ //
+ // checks for the command, i.e. the 'sign' that follows '${'
+ // divides the argument list into sub-expressions using
+ // DBE_get_expr_list()
+ //
+ // ${+ ${x} ${y}} -> "${x}" "${y}"
+ // ${& ${section} ${subsection}} -> "${section}" "${subsection}"
+ // ${Title} -> Nothing, variable expansion
+ //
+ // 3) DBE_expression_list():
+ //
+ // builds a vector of unbracketed whitespace separated strings, i.e.
+ //
+ // " ${Number}.a ${: Das Marmorbild} AB-${& Author= ${Eichendorf}-1870}"
+ //
+ // is split into a vector
+ //
+ // [0] ${Number}.a
+ // [1] ${: Das Marmorbild}
+ // [2] AB-${& Author= ${Eichendorf}}-1870
+ //
+ // Each sub-expression is expanded using expand().
+ //---------------------------------------------------------------------------
+ String DBE_expand_string(String str) {
+ // Parses for closing operators '${ }' and expands them letting
+ // white spaces and other letters as they are.
+ String new_string = "";
+ int open_brackets = 0;
+ int first = 0;
+ for(int i = 0; i<str.length(); i++) {
+ if( i < str.length() - 2 && str.substring(i, i+2).compareTo("${") == 0 ) {
+ if( open_brackets == 0 ) first = i+2;
+ open_brackets++;
+ }
+ else if( str.charAt(i) == '}' && open_brackets > 0) {
+ open_brackets -= 1;
+ if( open_brackets == 0 ) {
+ String Replacement = DBE_expand(str.substring(first, i));
+ new_string += Replacement;
+ }
+ }
+ else if( open_brackets == 0 )
+ new_string += str.charAt(i);
+ }
+ return new_string;
+ }
+
+ Vector DBE_get_expr_list(String str_, int ExpectedNumber) {
+ // ensures that the resulting vector has the expected number
+ // of arguments, but they may contain an error message
+
+ String str = str_;
+ // Separates expressions by non-bracketed whitespaces, expands them
+ // and puts them into a list.
+ int i=0;
+
+ // (1) eat initial whitespaces
+ boolean vcontinue = true;
+ while( i < str.length() && vcontinue ) {
+ char tmp = str.charAt(i);
+ if( tmp != ' ' && tmp != '\t' && tmp != '\n' ) {
+ //break;
+ vcontinue = false;
+ }
+ i++;
+ }
+
+ Vector expr_list = new Vector();
+ int open_brackets = 0;
+ Vector start_idx = new Vector();
+ int start_new_string = i;
+ int l = str.length();
+
+ // (2) search for ${ } expressions ...
+ while( i < l ) {
+ char letter = str.charAt(i);
+ // whitespace -> end of expression
+ if( (letter == ' ' || letter == '\t' || letter == '\n') && open_brackets == 0) {
+ expr_list.addElement(str.substring(start_new_string, i));
+ boolean no_breakout_f = true;
+ i++;
+ while( i < l && no_breakout_f ) {
+ char tmp = str.charAt(i);
+ if( tmp != ' ' && tmp != '\t' && tmp != '\n' ) {
+ no_breakout_f = false;
+ start_new_string = i;
+ //break;
+ }
+ i++;
+ }
+ if( no_breakout_f == true ) {
+ // end of expression list
+ if( expr_list.size() < ExpectedNumber ) {
+ String pre_tmp = "<< ${ }: missing arguments>>";
+ for(int ni = expr_list.size(); ni < ExpectedNumber; ni++)
+ expr_list.addElement(pre_tmp);
+ }
+ return expr_list;
+ }
+ }
+
+ // dollar-bracket expression
+ if( str.length() >= i+2 && str.substring(i, i+2).compareTo("${") == 0 ) {
+ open_brackets++;
+ start_idx.addElement(new Integer(i+2));
+ }
+ else if( letter == '}' && open_brackets > 0) {
+ int start = ((Integer)start_idx.elementAt(start_idx.size()-1)).intValue();
+ start_idx.removeElementAt(start_idx.size()-1);
+ String Replacement = DBE_expand(str.substring(start, i));
+ if( start - 3 < 0)
+ str = Replacement + str.substring(i+1);
+ else
+ str = str.substring(0, start-2) + Replacement + str.substring(i+1);
+ l = str.length();
+ i = start + Replacement.length() - 3;
+ open_brackets--;
+ }
+ i++;
+ }
+
+ // end of expression list
+ expr_list.addElement(str.substring(start_new_string, i));
+
+ if( expr_list.size() < ExpectedNumber ) {
+ String pre_tmp = "<< ${ }: missing arguments>>";
+ for(int ni = expr_list.size(); ni < ExpectedNumber; ni++)
+ expr_list.addElement(pre_tmp);
+ }
+ return expr_list;
+ }
+
+ variable DBE_get_variable(String VarName) {
+ variable ev = disjoint dbe new variable();
+ String secure_Prefix = prefix;
+
+ prefix = section;
+ // (1) first search in currently active section
+ variable var = find_variable(VarName);
+ if( var.name != "" ) { prefix = secure_Prefix; return var; }
+
+ // (2) search in root name space
+ prefix = "";
+ var = find_variable(VarName);
+ if( var.name != "" ) { prefix = secure_Prefix; return var; }
+
+ prefix = secure_Prefix;
+
+ // error occured => variable name == ""
+ ev.name = "";
+ ev.original = "<<${ } variable '" + VarName + "' undefined>>";
+ return ev;
+ }
+
+ String DBE_expand(String expr) {
+ // ${: } pure text
+ if( expr.charAt(0) == ':' )
+ return expr.substring(1);
+
+ // ${& expr expr ... } text concatination
+ else if( expr.charAt(0) == '&' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 1);
+ String result = "";
+ for( int i = 0; i < A.size(); ++i ) {
+ String add = (String)A.elementAt(i);
+ result += add;
+ }
+ return result;
+ }
+
+ // ${<-> expr expr expr} text replacement
+ else if( expr.length() >= 3 && expr.substring(0, 3).compareTo("<->") == 0) {
+ Vector A = DBE_get_expr_list(expr.substring(3), 3);
+ String Arg0 = (String)A.elementAt(0);
+ String Arg1 = (String)A.elementAt(1);
+ String Arg2 = (String)A.elementAt(2);
+ int L = Arg1.length();
+
+ boolean vcontinue = true;
+ while( 1 + 1 == 2 && vcontinue ) {
+ int tmp = Arg0.indexOf(Arg1);
+ if( tmp == -1 ) {
+ //break;
+ vcontinue = false;
+ } else
+ if( tmp == 0 ) Arg0 = Arg2 + Arg0.substring(L);
+ else Arg0 = Arg0.substring(0, tmp) + Arg2 + Arg0.substring(L+tmp);
+ }
+ return Arg0;
+ }
+ // ${+ ...}, ${- ...}, ${* ...}, ${/ ...} expressions
+ else if( expr.charAt(0) == '+' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 2);
+
+ double result = 0.0;
+
+ for( int i = 0; i < A.size(); ++i ) {
+ String add = (String)A.elementAt(i);
+ result += __convert_to_type(add, 0.0);
+ }
+
+ return String.valueOf(result);
+ }
+ else if( expr.charAt(0) == '-' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 2);
+
+ double result = __convert_to_type((String)A.elementAt(0), 0.0);
+ for( int i = 1; i < A.size(); ++i ) {
+ String sub = (String)A.elementAt(i);
+ result -= __convert_to_type(sub, 0.0);
+ }
+ return String.valueOf(result);
+ }
+ else if( expr.charAt(0) == '*' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 2);
+
+ double result = 1.0;
+ for( int i = 0; i < A.size(); ++i ) {
+ String mul = (String)A.elementAt(i);
+ result *= __convert_to_type(mul, 0.0);
+ }
+
+ return String.valueOf(result);
+ }
+ else if( expr.charAt(0) == '/' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 2);
+
+ double result = __convert_to_type((String)A.elementAt(0), 0.0);
+ if( result == 0 ) return "0.0";
+ for( int i = 0; i < A.size(); ++i ) {
+ double Q = __convert_to_type((String)A.elementAt(i), 0.0);
+ if( Q == 0.0) return "0.0";
+ result /= Q;
+ }
+ return String.valueOf(result);
+ }
+
+ // ${^ ... } power expressions
+ else if( expr.charAt(0) == '^' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 2);
+
+ double result = __convert_to_type((String)A.elementAt(0), 0.0);
+ for( int i = 0; i < A.size(); ++i ) {
+ double p = __convert_to_type((String)A.elementAt(i), 0.0);
+ result = Math.pow(result, p);
+ }
+
+ return String.valueOf(result);
+ }
+
+ // ${== } ${<= } ${>= } comparisons (return the number of the first 'match'
+ else if(expr.length() >= 2 &&
+ (expr.substring(0,2).compareTo("==") == 0 ||
+ expr.substring(0,2).compareTo(">=") == 0 ||
+ expr.substring(0,2).compareTo("<=") == 0 ||
+ expr.charAt(0) == '>' ||
+ expr.charAt(0) == '<') ) {
+ // differentiate between two and one sign operators
+ int op = 0;
+ // EQ = 0 GEQ = 1 LEQ = 2 GT = 3 LT = 4
+ if ( expr.substring(0, 2).compareTo("==") == 0 ) op = 0;
+ else if ( expr.substring(0, 2).compareTo(">=") == 0 ) op = 1;
+ else if ( expr.substring(0, 2).compareTo("<=") == 0 ) op = 2;
+ else if ( expr.charAt(0) == '>' ) op = 3;
+ else op = 4;
+
+ Vector a = new Vector();
+ if ( op >= 3 ) a = DBE_get_expr_list(expr.substring(1), 2);
+ else a = DBE_get_expr_list(expr.substring(2), 2);
+
+
+ String x_orig = (String)a.elementAt(0);
+ double x = __convert_to_type(x_orig, 1e37);
+
+ for( int i = 1; i < a.size(); ++i ) {
+ String y_orig = (String)a.elementAt(i);
+ double y = __convert_to_type(y_orig, 1e37);
+
+ // set the strings as reference if something wasn't a number
+ if ( x == 1e37 || y == 1e37 ) {
+ // it's a string comparison
+ int comparison = x_orig.compareTo(y_orig);
+
+ if( ( op == 0 && comparison == 0)
+ || (op == 1 && comparison >= 0)
+ || (op == 2 && comparison <= 0)
+ || (op == 3 && comparison > 0)
+ || (op == 4 && comparison < 0) ) {
+ return (new Integer(i)).toString();
+ }
+ }
+ else {
+ // it's a number comparison
+ if( (op == 0 && x == y) || (op == 1 && x >= y) ||
+ (op == 2 && x <= y) || (op == 3 && x > y) ||
+ (op == 4 && x < y) ) {
+ return (new Integer(i)).toString();
+ }
+ }
+ }
+ // nothing fulfills the condition => return 0
+ return "0";
+ }
+ // ${?? expr expr} select
+ else if( expr.length() >= 2 && expr.substring(0, 2).compareTo("??") == 0) {
+ Vector a = DBE_get_expr_list(expr.substring(2), 2);
+ double x = __convert_to_type((String)a.elementAt(0), 1e37);
+ // last element is always the default argument
+ if( x == 1e37 || x < 0 || x >= a.size() - 1 )
+ return (String)a.elementAt(a.size()-1);
+
+ // round x to closest integer
+ int rx = (int)Math.rint(x);
+ return (String)a.elementAt(rx);
+ }
+ // ${? expr expr expr} if then else conditions
+ else if( expr.charAt(0) == '?' ) {
+ Vector a = DBE_get_expr_list(expr.substring(1), 2);
+ if( __convert_to_type((String)a.elementAt(0), 0.0) == 1.0 )
+ return (String)a.elementAt(1);
+ else if( a.size() > 2 )
+ return (String)a.elementAt(2);
+ }
+ // ${! expr} maxro expansion
+ else if( expr.charAt(0) == '!' ) {
+ variable Var = DBE_get_variable(expr.substring(1));
+ // error
+ if( Var.name == "" ) return Var.original;
+
+ Vector A = DBE_get_expr_list(Var.original, 2);
+ return (String)A.elementAt(0);
+ }
+ // ${@: } - string subscription
+ else if( expr.length() >=2 && expr.substring(0,2).compareTo("@:") == 0 ) {
+ Vector A = DBE_get_expr_list(expr.substring(2), 2);
+ double x = __convert_to_type((String)A.elementAt(1), 1e37);
+
+ // last element is always the default argument
+ if( x == 1e37 || x < 0 || x >= (double)((String)A.elementAt(0)).length() - 1)
+ return "<<1st index out of range>>";
+
+ if( A.size() > 2 ) {
+ double y = __convert_to_type((String)A.elementAt(2), 1e37);
+ if ( y != 1e37 && y > 0 && y <= (double)((String)A.elementAt(0)).length() - 1 && y > x ) {
+ // note: java.lang.String: substring(a,b) = from a to b - 1
+ // C++ string: substr(a,b) = from a to a + b
+ int rx1 = (int)Math.rint(x);
+ int rx2 = (int)Math.rint(y + 1.0);
+ return ((String)A.elementAt(0)).substring(rx1, rx2);
+ }
+ else if( y == -1 ) {
+ int rx = (int)Math.rint(x);
+ return ((String)A.elementAt(0)).substring(rx);
+ }
+ return "<<2nd index out of range>>";
+ }
+ else {
+ String tmp = (String)A.elementAt(0);
+ int rx = (int)Math.rint(x);
+ return (String)tmp.substring(rx, rx+1);
+ }
+ }
+ // ${@ } - vector subscription
+ else if( expr.charAt(0) == '@' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 2);
+ variable Var = DBE_get_variable((String)A.elementAt(0));
+ // error
+ if( Var.name == "" ) {
+ // make a copy of the string if an error occured
+ // (since the error variable is a static variable inside get_variable())
+ return Var.original;
+ }
+
+ double x = __convert_to_type((String)A.elementAt(1), 1e37);
+
+ // last element is always the default argument
+ if (x == 1e37 || x < 0 || x >= Var.value.length )
+ return "<<1st index out of range>>";
+
+ if ( A.size() > 2) {
+ double y = __convert_to_type((String)A.elementAt(2), 1e37);
+ int begin = (int)Math.rint(x);
+ int end = 0;
+ if ( y != 1e37 && y > 0 && y <= Var.value.length && y > x)
+ end = (int)Math.rint(y + 1.0);
+ else if( y == -1 )
+ end = Var.value.length;
+ else
+ return "<<2nd index out of range>>";
+
+ String result = Var.get_element(begin);
+ for(int i = begin+1; i < end; i++)
+ result += " " + Var.get_element(i);
+ return result;
+ }
+ else {
+ int tmp = (int)Math.rint(x);
+ return Var.get_element(tmp);
+ }
+ }
+ Vector A = DBE_get_expr_list(expr, 1);
+ variable B = DBE_get_variable((String)A.elementAt(0));
+
+ // make a copy of the string if an error occured
+ // (since the error variable is a static variable inside get_variable())
+ if( B.name == "" ) return (String)B.original;
+ else return B.original;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) unidentified flying objects
+ //.............................................................................
+ //
+ String[] string_vector_to_string_array(Vector Vec) {
+ String[] result = new String[Vec.size()];
+ for(int i =0; i < Vec.size(); i++ )
+ result[i] = (String)Vec.elementAt(i);
+ return result;
+ }
+
+ int __search_string_array(String[] Arr, String Str) {
+ for(int i=0; i < Arr.length ; i++)
+ if( Str.compareTo(Arr[i]) == 0 ) return i;
+ return -1;
+ }
+
+ String[] unidentified_arguments(String KnownArguments[]) {
+ Vector ufos = new Vector();
+ if( argv.size() == 0 )
+ return string_vector_to_string_array(ufos);
+
+ // forget about first element (application name)
+ for( int i = 1; i < argv.size(); ++i ) {
+ String it = (String)argv.elementAt(i);
+ // -- argument belongs to prefixed section ?
+ String arg = __get_remaining_string(it, prefix);
+ if( arg == "" ) {
+ //continue;
+ } else
+
+ // -- check if argument is known
+ if( __search_string_array(KnownArguments, arg) == -1 )
+ ufos.addElement(it);
+ }
+ return string_vector_to_string_array(ufos);
+ }
+
+
+ String[] unidentified_options(String KnownOptions[]) {
+ Vector ufos = new Vector();
+
+ if( argv.size() == 0 )
+ return string_vector_to_string_array(ufos);
+
+ // forget about first element (application name)
+ for( int i = 1; i < argv.size(); ++i ) {
+ String it = (String)argv.elementAt(i);
+ // -- argument belongs to prefixed section ?
+ String arg = __get_remaining_string(it, prefix);
+ if( arg == "" ) {
+ //continue;
+ } else
+ // -- argument == option ?
+ if( arg.length() < 1 || arg.charAt(0) != '-' ) {
+ //continue;
+ } else
+ // -- check if argument is known
+ if( __search_string_array(KnownOptions, arg) == -1 )
+ ufos.addElement(it);
+ }
+ return string_vector_to_string_array(ufos);
+ }
+
+ String unidentified_flags(String KnownFlagList) {
+ return unidentified_flags(KnownFlagList, -1);
+ }
+
+ String unidentified_flags(String KFL, int ArgumentNumber) {
+ // Two modes:
+ // ArgumentNumber >= 0 check specific argument
+ // ArgumentNumber == -1 check all options starting with one '-'
+ // for flags
+
+ String ufos = "";
+ Vector known_arguments;
+
+ // (2) iteration over '-' arguments (options)
+ if( ArgumentNumber == -1 ) {
+ // iterate over all arguments
+ if( argv.size() == 0 ) return ufos;
+ // forget about first element (application name)
+ for( int j = 1; j < argv.size(); ++j ) {
+ String it = (String)argv.elementAt(j);
+ // -- argument belongs to prefixed section ?
+ String arg = __get_remaining_string(it, prefix);
+ if( arg == "" ) {
+ //continue;
+ } else
+
+ // does arguments start with '-' (but not '--')
+ if ( arg.length() < 2 ) {
+ //continue;
+ }
+ else if( arg.charAt(0) != '-' ) {
+ //continue;
+ }
+ else if( arg.charAt(1) == '-' ) {
+ //continue;
+ } else {
+ // -- check out if flags inside option are contained in KnownFlagList
+ for(int i=1; i<arg.length() ; i++) {
+ char flag1 = arg.charAt(i);
+ if( KFL.indexOf(flag1) == -1 ) ufos += flag1;
+ }
+ }
+ }
+ }
+ else {
+ int no_matches = 0;
+ // -- only check arguments that start with prefix
+ if( argv.size() == 0 ) return ufos;
+ // forget about first element (application name)
+ for( int j = 1; j < argv.size(); ++j ) {
+ String it = (String)argv.elementAt(j);
+ String Remain = __get_remaining_string(it, prefix);
+ if( Remain != "") {
+ no_matches += 1;
+ if( no_matches == ArgumentNumber) {
+ // -- the right argument number inside the section is found
+ // => check it for flags
+ for(int i=0; i<Remain.length() ; i++) {
+ char flag1 = Remain.charAt(i);
+ if( KFL.indexOf(flag1) == -1 ) ufos += flag1;
+ }
+ }
+ }
+ }
+ }
+ return ufos;
+ }
+
+
+ String[] unidentified_variables(String[] Knowns) {
+ Vector ufos = new Vector();
+
+ for( int i = 0; i < variables.size(); ++i ) {
+ variable it = (variable)variables.elementAt(i);
+ // -- variable belongs to prefixed section ?
+ String var_name = __get_remaining_string(it.name, prefix);
+ if( var_name == "" ) {
+ //continue;
+ } else
+
+ // -- check if variable is known
+ if( __search_string_array(Knowns, var_name) == -1 )
+ ufos.addElement(it.name);
+ }
+ return string_vector_to_string_array(ufos);
+ }
+
+
+ String[] unidentified_sections(String[] Knowns) {
+ Vector ufos = new Vector();
+
+ for( int i = 0; i < section_list.size(); ++i ) {
+ String it = (String)section_list.elementAt(i);
+ // -- section a subsection of prefix ?
+ String sec_name = __get_remaining_string(it, prefix);
+ if( sec_name == "" ) {
+ //continue;
+ } else
+
+ // -- section is known ?
+ if( __search_string_array(Knowns, sec_name) == -1 )
+ ufos.addElement(it);
+ }
+ return string_vector_to_string_array(ufos);
+ }
+
+
+ String[] unidentified_nominuses(String[] KnownNominuses) {
+ Vector ufos = new Vector();
+
+ // iterate over all arguments
+ if( argv.size() == 0 )
+ return string_vector_to_string_array(ufos);
+ // forget about first element (application name)
+ for( int j = 1; j < argv.size(); ++j ) {
+ String it = (String)argv.elementAt(j);
+ // -- argument belongs to prefixed section ?
+ String arg = __get_remaining_string(it, prefix);
+ if( arg == "" ) {
+ //continue;
+ } else
+
+ if( arg.length() < 1 ) {
+ //continue;
+ } else
+ // option ? --> not a nomius
+ if( arg.charAt(0) == '-' ) {
+ //continue;
+ } else
+ // section ? --> not a real nominus
+ if( arg.charAt(0) == '[' && arg.charAt(arg.length()-1) == ']' ) {
+ //continue;
+ }
+ // variable definition ? --> not a real nominus
+ boolean continue_f = false;
+ int i=0;
+ while( i<arg.length() && !continue_f ) {
+ if( arg.charAt(i) == '=' ) {
+ continue_f = true;
+ }
+ i++;
+ }
+ if( continue_f ) {
+ //continue;
+ } else
+
+ // real nominuses are compared with the given list
+ if( __search_string_array(KnownNominuses, arg) == -1 )
+ ufos.addElement(it);
+ }
+ return string_vector_to_string_array(ufos);
+ }
+}
--- /dev/null
+# -*- getpot -*- GetPot mode activation for emacs
+#
+# Example input file to be parsed by 'GetPot'
+#
+# (C) 2001 Frank R. Schaefer
+# License Terms: GNU LGPL
+############################################################################
+
+# (*) --------------------------------------------------------------------------
+# examples dealing with input file parsing (input-file.py/.cpp/.java etc.)
+#-------------------------------------------------------------------------------
+clicks = 231 # [1/s]
+acceleration = 1.231 # [m/s^2]
+
+[vehicle]
+wheel-base = 2.65 # [m]
+initial-xyz = '100. 0.1 5.0' # [m]
+
+
+ [./tires] # i.e. vehicle/tires/
+ # Coefficients for Pacejka's Magic Formula
+ # Reference: Bakker, Nyborg, Pacejka:
+ # "Modelling for Use in Vehicle Dynamics Studies",
+ # SAE Technical Paper Series 870421, 1988
+ B = 3.7976 # [1]
+ C = 1.25 # [1]
+ E = -0.5 # [1]
+ D = 64322.404 # [N]
+
+ [../chassis] # i.e. vehicle/chassis/
+ Roh = 1.21 # [kg/m^3] density of air
+ S = 5.14 # [m^2] reference surface
+ Cd = 0.45 # [1] air drag coefficient
+
+ [./doors] # i.e. vehicle/chassis/doors/
+ number = 777
+ locks = 'in place'
+
+# back to the root name space
+[]
+webpage = http://getpot.sourceforge.net/index.html
+
+# some words about quotes and backslashes
+# (1) whitespace requires quotes
+user = 'Alfons Haeberle'
+# (2) backslashed quote => quote
+latex-formula = '\\kappa\' = \\frac{d}{d s} \\kappa'
+# (3) double backslash in quotes = backslash
+dos-file = 'C:\\Program Files\\Applications'
+
+# (*) --------------------------------------------------------------------------
+# examples using the prefix filter (filter.py/.cpp/.java etc.)
+#-------------------------------------------------------------------------------
+[group]
+# playing with pseudo command line arguments:
+# note that
+# '-x', '3134' and '--rudimental'
+# will be known as
+# 'flags/-x', 'flags/3234' and 'flags/rudimental'.
+#
+# Therefore 3134, for example, is **NOT** a number as long,
+# as no prefix filter "flags/" is set.
+-x 3134
+--rudimental 12 777
+
+[other]
+# this section will be skipped by the 'next' function when the prefix
+# is set
+nonsense
+
+
+[user-variables]
+# This section contains variables that the user defined himself.
+# The GetPot interpreter uses 'get_variable_names()' in order to
+# get to know their names.
+preview-coefficient = '12 cm'
+lateral-side-distance = '2.1 m/s'
+control-interval = '0.1 s'
+compensation-ratio = '0.4e34 rad/(m*s)'
+
+[pseudo-function-calls]
+# The following code shows how GetPot can be used to emulate
+# trivial function calls. Please, note that no syntax checking
+# can be provided by this method.
+LE-DEBUT
+smiley sad
+new-line 1
+# draw rectangle width = 40, height = 10
+rectangle 40 10
+new-line 1
+smiley happy
+# draw circle radius = 15
+circle 15
+new-line 1
+smiley happy
+new-line 2
+LA-FIN
+
--- /dev/null
+MAIN_CLASS=Example
+
+PROGRAM=test
+SOURCE_FILES=*.java
+
+BUILDSCRIPT=~/research/Robust/src/buildscript
+BSFLAGS= -mainclass $(MAIN_CLASS) -justanalyze -ownership -ownallocdepth 1 -ownwritedots final -enable-assertions
+
+all: $(PROGRAM).bin
+
+view: PNGs
+ eog *.png &
+
+PNGs: DOTs
+ d2p *COMPLETE*.dot
+
+DOTs: $(PROGRAM).bin
+
+$(PROGRAM).bin: $(SOURCE_FILES)
+ $(BUILDSCRIPT) $(BSFLAGS) -o $(PROGRAM) $(SOURCE_FILES)
+
+clean:
+ rm -f $(PROGRAM).bin
+ rm -fr tmpbuilddirectory
+ rm -f *~
+ rm -f *.dot
+ rm -f *.png
+ rm -f aliases.txt
--- /dev/null
+// -*- java -*-
+// FILE: DirectFollow.java
+// (C) 2001 Frank R. Schaefer
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//////////////////////////////////////////////////////////////////////////////////////
+import GetPot.*;
+import java.lang.String;
+
+public class DirectFollow {
+ public static void main(String args []) {
+ GetPot cl = new GetPot(args, "DirectFollow");
+
+ if( cl.size() == 1 || cl.search("--help", "-h") ) print_help("DirectFollow");
+
+ // Specify, that in case the cursor reaches the end of argument list,
+ // it is not automatically reset to the start. This way the search
+ // functions do not wrap around. Instead, they notify an 'not fount'
+ // in case the option was not in between 'cursor' and the argv.end().
+ cl.reset_cursor();
+ cl.disable_loop();
+
+ // check out 'String' versions
+ String User = cl.direct_follow("You", "-U");
+ String User2 = cl.direct_follow("Karl", "-U");
+ String User3 = cl.direct_follow("Heinz", "-U");
+
+ // check out 'double' versions
+ cl.reset_cursor();
+ double Value = cl.direct_follow(3.14, "-V");
+ double Value2 = cl.direct_follow(9.81, "-V");
+ double Value3 = cl.direct_follow(1.62, "-V");
+
+ // check out 'integer' versions
+ cl.reset_cursor();
+ int Number = cl.direct_follow(12, "-NUM");
+ int Number2 = cl.direct_follow(43, "-NUM");
+ int Number3 = cl.direct_follow(64, "-NUM");
+
+ something(User, User2, User3, Value, Value2, Value3, Number, Number2, Number3);
+ }
+
+ static void something(String User, String User2, String User3,
+ double Value, double Value2, double Value3,
+ int Number, int Number2, int Number3) {
+ System.out.println("Users = " + User + ", " + User2 + ", " + User3);
+ System.out.println("Values = " + Value + ", " + Value2 + ", " + Value3);
+ System.out.println("Numbers = " + Number + ", " + Number2 + ", " + Number3);
+ }
+
+ static void print_help(String Application) {
+ System.out.println();
+ System.out.println("Example to use direct_follow()-functions:");
+ System.out.println("USAGE:");
+ System.out.println("--help, -h get some help about this program.");
+ System.out.println();
+ System.out.println("-Ustring specify user name as string");
+ System.out.println("-Vx specify a value given as x");
+ System.out.println("-NUMx specify number given as x");
+ System.out.println();
+ System.out.println("a total amount of three of each is expected.");
+ System.out.println();
+ System.exit(0);
+ }
+}
--- /dev/null
+// -*- java -*-
+// FILE: Expand.java
+// (C) 2002 Frank R. Schaefer
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//////////////////////////////////////////////////////////////////////////////////
+
+import GetPot.*;
+import java.lang.String;
+
+public class Expand {
+ public static void main(String args []) {
+ GetPot cl = new GetPot(args, "Get");
+ GetPot ifpot = new GetPot("expand.pot");
+
+ if( cl.search("--internal-information", "-i") ) {
+ ifpot.print();
+ System.exit(0);
+ }
+
+ // (*) help display
+ if( cl.search("--help", "-h", "--hilfe", "--sos") || cl.search("--ok") == false ) {
+ String msg = "Example how to use GetPot to parse input files.\n\n" +
+ "USAGE:\n" +
+ "--ok\n" +
+ " run the input file parsing.\n" +
+ "--help, -h, --hilfe, --sos\n" +
+ " get some help about this program.\n\n" +
+ "--internal-information, -i\n" +
+ " show contents of database that was created by file parser.\n" +
+ "--infile string\n" +
+ " input file name (default: example.pot)";
+ my_print(msg);
+ System.exit(0);
+ }
+
+ // (*) example usage
+ my_print("[1.1]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "nobody"));
+
+ ifpot.set_prefix("1.2/");
+ my_print("[1.2]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "(nothing)"));
+ my_print("Information 1: ", ifpot.call("info1", "(nothing)"));
+
+ ifpot.set_prefix("1.3/");
+ my_print("[1.3]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "(nothing)"));
+ my_print("Information 1: ", ifpot.call("info1", "(nothing)"));
+
+ ifpot.set_prefix("1.4/");
+ my_print("[1.4]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "(nothing)"));
+ my_print("Information 1: ", ifpot.call("info1", "(nothing)"));
+
+ ifpot.set_prefix("2.1/");
+ my_print("[2.1]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "(nothing)"));
+ my_print("Information 1: ", ifpot.call("info1", "(nothing)"));
+ my_print("Information 2: ", ifpot.call("info2", "(nothing)"));
+
+ ifpot.set_prefix("2.2/");
+ my_print("[2.2]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "(nothing)"));
+ my_print("Information 1: ", ifpot.call("info1", "(nothing)"));
+
+ ifpot.set_prefix("2.3/");
+ my_print("[2.3]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "(nothing)"));
+ my_print("Information 1: ", ifpot.call("info1", "(nothing)"));
+ my_print("Information 2: ", ifpot.call("info2", "(nothing)"));
+
+ ifpot.set_prefix("3.1/");
+ my_print("[3]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "(nothing)"));
+ my_print("Information 1: ", ifpot.call("info1", "(nothing)"));
+ my_print("Information 2: ", ifpot.call("info2", "(nothing)"));
+ my_print("Information 3: ", ifpot.call("info3", "(nothing)"));
+ my_print("Information 4: ", ifpot.call("info4", "(nothing)"));
+ my_print("Information 5: ", ifpot.call("info5", "(nothing)"));
+ my_print("Information 6: ", ifpot.call("info6", "(nothing)"));
+ my_print("Information 7: ", ifpot.call("info7", "(nothing)"));
+
+ ifpot.set_prefix("3.2/");
+ my_print("[3.2]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "(nothing)"));
+ my_print("Information 1: ", ifpot.call("info1", "(nothing)"));
+
+ ifpot.set_prefix("3.3/");
+ my_print("[3.3]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "(nothing)"));
+ my_print("Information 1: ", ifpot.call("info1", "(nothing)"));
+ my_print("Information 2: ", ifpot.call("info2", "(nothing)"));
+ my_print("Information 3: ", ifpot.call("info3", "(nothing)"));
+ my_print("Information 4: ", ifpot.call("info4", "(nothing)"));
+ my_print("Information 5: ", ifpot.call("info5", "(nothing)"));
+ my_print("Information 6: ", ifpot.call("info6", "(nothing)"));
+ my_print("Information 7: ", ifpot.call("info7", "(nothing)"));
+
+ ifpot.set_prefix("3.4/");
+ my_print("[3.4]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "(nothing)"));
+ my_print("Information 1: ", ifpot.call("info1", "(nothing)"));
+ my_print("Information 2: ", ifpot.call("info2", "(nothing)"));
+
+ ifpot.set_prefix("3.5/");
+ my_print("[3.5]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "(nothing)"));
+ my_print("Information 1: ", ifpot.call("info1", "(nothing)"));
+ my_print("Information 2: ", ifpot.call("info2", "(nothing)"));
+ my_print("Information 3: ", ifpot.call("info3", "(nothing)"));
+ my_print("Information 4: ", ifpot.call("info4", "(nothing)"));
+ my_print("Information 5: ", ifpot.call("info5", "(nothing)"));
+ my_print("Information 6: ", ifpot.call("info6", "(nothing)"));
+ my_print("Information 7: ", ifpot.call("info7", "(nothing)"));
+
+ ifpot.set_prefix("3.6/");
+ my_print("[3.6]--------------------------------------------------------------------------");
+ my_print("Information 0: ", ifpot.call("info0", "(nothing)"));
+ my_print("Information 1: ", ifpot.call("info1", "(nothing)"));
+ }
+
+ static void my_print(String Str) {
+ System.out.println(Str);
+ }
+
+ static void my_print(String Str1, String Str2) {
+ System.out.println(Str1 + Str2);
+ }
+}
--- /dev/null
+// -*- java -*-
+// FILE: Filter.java
+// (C) 2002 Frank R. Schaefer
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+///////////////////////////////////////////////////////////////////////////////////
+import GetPot.*;
+import java.lang.String;
+
+public class Filter {
+
+ static double Sqr(double x) { return x*x; }
+
+
+ public static void main(String args[]) {
+ GetPot cl = new GetPot(args, "Filter");
+ GetPot ifpot = new GetPot("example.pot");
+
+ // (1) search for multiple options with the same meaning
+ if( cl.search("--help", "-h", "--hilfe", "--sos") ) {
+ String Msg = "Example program treating the prefix filtering.\n\n" +
+ " Using the function .set_prefix(section) only arguments, options \n" +
+ " variables are considered in the given 'section'\n\n" +
+ "--help, -h, --hilfe, --sos \n" +
+ " this page.\n" +
+ "--nice \n" +
+ " demonstrates how pseudo function calls can be accomplished.\n\n" +
+ "please refer to the file 'example.pot' as input file.\n";
+ System.out.println(Msg);
+ System.exit(0);
+ }
+
+ // -- note that the prefix is not considered as a flag
+ // -- the index in 'argument contains' indicates the position
+ // of the argument inside the namespace given by prefix
+ ifpot.set_prefix("group/");
+
+ System.out.println(" -- flags in options / arguments");
+ boolean first_f = ifpot.argument_contains(1, "xX");
+ boolean second_f = ifpot.argument_contains(1, "cCkK");
+ boolean abc_f = ifpot.options_contain("abc");
+ System.out.println(" Flags in first argument in [flags]\n");
+ System.out.println(" x or X in arg 1 = " + first_f);
+ System.out.println(" c, C, k or K in arg 1 = " + second_f);
+ System.out.println(" a,b, or c in options = " + abc_f);
+ System.out.println("");
+ System.out.println(" -- search(), next() and follow()");
+ System.out.println("");
+ System.out.println(" found \"--rudimental\" = " + ifpot.search("--rudimental"));
+
+ int Tmp1 = ifpot.next(-1);
+ int Tmp2 = ifpot.next(-1);
+ System.out.println(" followed by " + Tmp1 + " " + Tmp2);
+
+ String Tmp3 = ifpot.follow("nothing", "--rudimental");
+ int Tmp4 = ifpot.next(-1);
+ System.out.println(" rudimental = " + Tmp3 + ", " + Tmp4 + "\n");
+
+ // -- variables
+ System.out.println("");
+ System.out.println(" -- variables in section [user-variables]");
+ System.out.println("");
+ ifpot.set_prefix("user-variables/");
+
+ String variable_names[] = ifpot.get_variable_names();
+ for(int i=0; i < variable_names.length ; i++) {
+ String name = variable_names[i];
+ System.out.print(" " + name + " \t= ");
+ System.out.print(ifpot.call(name, 1e37, 0));
+ System.out.print("[" + ifpot.call(name, "[1]", 1) + "]\n");
+ }
+ System.out.println("");
+
+ // -- pseudo function calls
+ if( cl.search("--nice") ) {
+ System.out.println(" -- pseudo function call feature");
+ System.out.println("");
+ ifpot.set_prefix("pseudo-function-calls/");
+ ifpot.init_multiple_occurrence();
+
+ ifpot.search("LE-DEBUT");
+ while( 1 + 1 == 2 ) {
+ String Next = ifpot.next("(no-func)");
+
+ if( Next.compareTo("(no-func)") == 0 ) break;
+ else if( Next.compareTo("rectangle") == 0) {
+ int size_x = ifpot.next(10);
+ int size_y = ifpot.next(10);
+ System.out.print("\n");
+ for(int y=0; y < size_y; y++) {
+ for(int x=0; x < size_x; x++) {
+ System.out.print("*");
+ }
+ System.out.print("\n");
+ }
+ }
+ else if( Next.compareTo("circle") == 0) {
+ int radius = ifpot.next(4);
+ System.out.println("\n");
+ for(int y=0; y < radius*2 + 1; y++) {
+ for(int x=0; x < radius*2 + 1; x++)
+ if( Sqr(x-radius) + Sqr(y-radius) <= Sqr(radius)
+ && Sqr(x-radius) + Sqr(y-radius) >= Sqr(radius)/4. )
+ System.out.print(".");
+ else
+ System.out.print(" ");
+ System.out.print("\n");
+ }
+ }
+ else if( Next.compareTo("smiley") == 0 ) {
+ String Mood = ifpot.next("happy");
+ if( Mood.compareTo("sad") == 0 ) System.out.print(":( ");
+ else System.out.print(":) ");
+ }
+ else if( Next.compareTo("new-line") == 0 ) {
+ int No = ifpot.next(1);
+ for(int i=0; i<No ;i++)
+ System.out.println("\n");
+ }
+ }
+ }
+ else {
+ System.out.println("(use the --nice command line flag for graphical output)");
+ }
+ System.out.println("");
+ }
+}
+
+
+
--- /dev/null
+// -*- java -*-
+// FILE: Flags.java Version 0.9.8
+// (C) 2001 Frank R. Schaefer
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//////////////////////////////////////////////////////////////////////////////////////
+import GetPot.*;
+import java.lang.String;
+
+public class Flags {
+ public static void main(String args []) {
+ GetPot cl = new GetPot(args, "Flags");
+ if( cl.size() == 1 || cl.search("--help", "-h") ) print_help();
+
+ // does first argument contain 'x', 'X', 'c', 'C', 'k', or 'K' ?
+ boolean first_f = cl.argument_contains(1, "xX");
+ boolean second_f = cl.argument_contains(1, "cCkK");
+
+ // is there any option starting with '-' containing 'a', 'b', or 'c' ?
+ boolean abc_f = cl.options_contain("abc");
+
+ System.out.println("first flag = " + first_f);
+ System.out.println("second flag = " + second_f);
+ System.out.println("a, b, or c found = " + abc_f );
+ }
+
+
+ static void print_help() {
+ System.out.println();
+ System.out.println("Example using flags:");
+ System.out.println("USAGE:");
+ System.out.println("--help, -h get some help about this program.");
+ System.out.println();
+ System.out.println("The first argument will be checked if it contains 'x' or 'X'.");
+ System.out.println("If so the first flag will be set. The second flag will be set if");
+ System.out.println("the first argument contains a 'c', 'C', 'k', or a 'K'.");
+ System.out.println();
+ System.out.println("The 'abc' flag is set when any argument starting with '-' contains an");
+ System.out.println("'a', 'b' or a 'c'.");
+ System.out.println();
+ System.exit(0);
+ }
+}
+
+
+
--- /dev/null
+// -*- java -*-
+// FILE: Follow.java
+// (C) 2001 Frank R. Schaefer
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//////////////////////////////////////////////////////////////////////////////////////
+import GetPot.*;
+import java.lang.String;
+
+public class Follow {
+ public static void main(String args []) {
+ GetPot cl = new GetPot(args, "Follow");
+
+ // to function 'cl.search(..)'
+ if( cl.search("--help", "-h", "--hilfe") )
+ print_help();
+
+ // read arguments one by one on the command line
+ // (lazy command line parsing)
+ double Alpha = cl.follow(0., "--alpha"); // [rad]
+ int Beta = cl.follow(256, "--beta"); // [1/s]
+ cl.init_multiple_occurrence();
+ String User = cl.follow("You", "--user");
+ int No = cl.next(0x42);
+ String User2 = cl.follow("You Two", "--user"); // second user specified ?
+ int No2 = cl.next(0x43);
+ cl.enable_loop();
+ double XSz = cl.follow(0., "--size", "--sz", "-s"); // [cm]
+ double YSz = cl.next(0.); // [cm]
+
+ System.out.println();
+ System.out.println("Alpha = " + Alpha);
+ System.out.println("Beta = " + Beta );
+ System.out.println("Names = " + User + " and " + User2);
+ System.out.println("Special numbers = " + No + " and " + No2);
+ System.out.println("x-size, y-size = " + XSz + ", " + YSz);
+ System.out.println();
+ }
+
+ static void print_help() {
+ System.out.println();
+ System.out.println("Example to use follow()-functions:");
+ System.out.println("USAGE:");
+ System.out.println("--help, -h");
+ System.out.println(" get some help about this program.");
+ System.out.println("--alpha number");
+ System.out.println(" specify the value of alpha given as number.");
+ System.out.println("--beta number");
+ System.out.println(" specify the value of beta given as number.");
+ System.out.println("--user string number");
+ System.out.println(" specify user name as string and id as number");
+ System.out.println(" (default = 'You' and '0x42').");
+ System.out.println(" multiple users possible. ");
+ System.out.println("--size, --sz, -s number1 number2");
+ System.out.println(" specify x and y sizes");
+ System.out.println();
+ System.exit(0);
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+// -*- java -*-
+// FILE: Get.java Version 0.9.8
+// (C) 2001 Frank R. Schaefer
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//////////////////////////////////////////////////////////////////////////////////////
+import GetPot.*;
+import java.lang.String;
+
+public class Get {
+ public static void main(String args []) {
+ GetPot cl = new GetPot(args, "Get");
+
+ // GetPot Java can treat upto 6 strings, then it needs a String[]
+ if( cl.search("--help", "-h", "--hilfe", "--sos", "--about", "--what-is") ) {
+ System.out.println("call " + cl.getitem(0) + " with four arguments.");
+ System.exit(0);
+ }
+ if( cl.search(new String[]{"--stop", "--quit", "--do-nothing",
+ "--let-it-be", "-q", "-s", "--never-mind",
+ "--achtung-anhalten", "--arrete", "--fait-rien",
+ "--glonde-rien"}) )
+ System.exit(0);
+
+ int A = cl.get(4, 256); // integer version of get()
+ double B = cl.get(1, 3.14); // double version of get()
+ String C = cl.get(2, "You"); // const char* version of get()
+
+ System.out.println("A (argument no 4) = " + A);
+ System.out.println("B (argument no 1) = " + B);
+ System.out.println("C (argument no 2) = " + C);
+ }
+}
+
+
--- /dev/null
+// -*- java -*-
+// GetPot Version 1.0 Sept/13/2002
+//
+// WEBSITE: http://getpot.sourceforge.net
+//
+// This library is free software; you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation; either version 2.1 of the
+// License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA
+//
+// (C) 2001 Frank R. Schaefer
+//==========================================================================
+import java.io.*;
+import java.lang.String.*;
+import java.lang.Object.*;
+import java.lang.NumberFormatException;
+import java.lang.Integer;
+import java.lang.Double;
+import java.util.*;
+
+public class GetPot {
+ // variable structure
+ public class variable {
+ // (*) constructor
+ variable(String Name, String Value) {
+ name = Name;
+ take(Value);
+ }
+ variable() {
+ name = "";
+ value = new String[1];
+ value[0] = "";
+ original = "";
+ }
+ // (*) get a specific element in the string vector
+ String get_element(int Idx) {
+ if( Idx < 0 || Idx > value.length ) return new String("");
+ else return value[Idx];
+ }
+
+ void take(String Value) {
+ original = Value;
+ StringTokenizer st = new StringTokenizer(Value);
+ value = new String[st.countTokens()];
+ for(int i =0; st.hasMoreTokens(); i++ )
+ value[i] = st.nextToken();
+ }
+ // (*) data memebers
+ String name; // identifier of variable
+ String value[]; // value of variable stored in vector
+ String original; // value of variable as given on command line
+ };
+ String prefix; // prefix indicating section for search
+ String section; // section for dollar bracket parsing
+ Vector argv; // String[]
+ Vector section_list;
+ int cursor;
+ Vector idx_nominus; // int[]
+ int nominus_cursor;
+ boolean search_loop_f;
+ boolean search_failed_f;
+ Vector variables; // class variable
+
+
+ // (*) constructor
+ GetPot(String argv_[], String applicationName) {
+ prefix = "";
+ cursor = 0;
+ nominus_cursor = -1;
+ search_loop_f = true;
+ search_failed_f = false;
+
+ Vector __argv = new Vector();
+ idx_nominus = new Vector();
+ variables = new Vector();
+ section_list = new Vector();
+
+ // in java the argv[0] does not contain the application name
+ // => append application name to argv vector by hand
+
+ for(int i=0; i < argv_.length ; i++) {
+ String copied_str = new String(argv_[i]);
+ __argv.addElement(copied_str);
+ }
+
+ argv = new Vector();
+ __argv.insertElementAt(applicationName, 0);
+ __parse_argument_vector(__argv);
+ }
+
+ GetPot(String FileName) {
+ prefix = "";
+ cursor = 0;
+ nominus_cursor = -1;
+ search_loop_f = true;
+ search_failed_f = false;
+
+ Vector __argv = new Vector();
+ idx_nominus = new Vector();
+ variables = new Vector();
+ section_list = new Vector();
+
+ __argv = read_in_file(FileName);
+
+ argv = new Vector();
+ __argv.insertElementAt(FileName, 0);
+ __parse_argument_vector(__argv);
+ }
+
+ void __parse_argument_vector(Vector _argv) {
+ // build internal database
+ // 1) array with no-minus arguments (usually used as filenames)
+ // 2) section label treatment
+ // 3) variable assignments:
+ // 'variable name' '=' number | string
+ int i=0;
+ section = "";
+ Vector section_stack = new Vector();
+ if( _argv.size() < 1 ) return;
+
+ for(Enumeration arge = _argv.elements(); arge.hasMoreElements() ;i++) {
+ String arg = (String)arge.nextElement();
+
+ if( i == 0 ) { argv.addElement(arg); continue; }
+ if( arg.length() == 0) continue;
+
+ // -- [section] labels
+ if( arg.length() > 1 && arg.charAt(0) == '[' && arg.charAt(arg.length()-1) == ']' ) {
+ String name = DBE_expand_string(arg.substring(1, arg.length()-1));
+ // String name = arg.substring(1, arg.length()-1);
+ section = process_section_label(name, section_stack);
+ // new section --> append to list of sections
+ if( section_list.indexOf(section) == -1 )
+ if( section.length() != 0 ) section_list.addElement(section);
+ argv.addElement(arg);
+ }
+ else {
+ arg = section + DBE_expand_string(arg);
+ argv.addElement(arg);
+ }
+
+ // 1) separate array for nominus arguments
+ if( arg.charAt(0) != '-' )
+ idx_nominus.addElement(new Integer(i));
+
+ // 2) variables: does _argv[i] contain a '=' operator ?
+ int k = arg.indexOf('=');
+ if( k > 0 ) {
+ variable Var = find_variable(arg.substring(0,k));
+ if( Var.name.compareTo("") == 0 )
+ variables.addElement(new variable(arg.substring(0,k),
+ arg.substring(k+1)));
+ else
+ Var.take(arg.substring(k+1));
+ }
+ }
+ }
+ // file parsing
+ Vector read_in_file(String filename) {
+ Vector Empty = new Vector();
+ try {
+ InputStream i = new FileInputStream(filename);
+ if( i.available() == 0 ) return Empty;
+ // argv[0] == the filename of the file that was read in
+ return read_in_stream(new PushbackInputStream(i));
+ }
+ catch(FileNotFoundException ID_10T) { return Empty; }
+ catch(IOException ID_20T) { return Empty; }
+ }
+
+ Vector read_in_stream(PushbackInputStream istr) {
+ Vector brute_tokens = new Vector();
+ String token;
+ Vector arglist = new Vector();
+
+ while( 1 + 1 == 2 ) {
+ if( __skip_whitespace(istr) == -1 ) break;
+ token = __get_next_token(istr);
+ if( token.length() == 0 ) break;
+ brute_tokens.addElement(token);
+ }
+
+ // for(int i=0; i<brute_tokens.size() ; i++)
+ // System.out.println((String)(brute_tokens.elementAt(i)));
+
+ // -- reduce expressions of token1'='token2 to a single
+ // string 'token1=token2'
+ // -- copy everything into 'result'
+ // -- arguments preceded by something like '[' name ']' (section)
+ // produce a second copy of each argument with a prefix '[name]argument'
+ int i1 = 0;
+ int i2 = 1;
+ int i3 = 2;
+ String section = new String("");
+
+ while( i1 < brute_tokens.size() ) {
+ String SRef = (String)brute_tokens.elementAt(i1);
+ // 1) concatinate 'abcdef' '=' 'efgasdef' to 'abcdef=efgasdef'
+ // note: java.lang.String: substring(a,b) = from a to b-1
+ // C++ string: substr(a,b) = from a to a + b
+ if( i2 < brute_tokens.size() && ((String)brute_tokens.elementAt(i2)).charAt(0) == '=' ) {
+ if( i3 >= brute_tokens.size() )
+ arglist.addElement((String)brute_tokens.elementAt(i1)
+ + (String)brute_tokens.elementAt(i2));
+ else
+ arglist.addElement((String)brute_tokens.elementAt(i1)
+ + (String)brute_tokens.elementAt(i2)
+ + (String)brute_tokens.elementAt(i3));
+
+ i1 = i3+1; i2 = i3+2; i3 = i3+3;
+ continue;
+ }
+ else {
+ arglist.addElement(SRef);
+ i1=i2; i2=i3; i3++;
+ }
+ }
+ return arglist;
+ }
+
+
+ int __skip_whitespace(PushbackInputStream istr) {
+ try {
+ while( 1 + 1 == 2 ) {
+ int tmp = istr.read(); // read first character out of stream
+ if( tmp == -1 ) return -1;
+ while( (char)tmp == ' ' || (char)tmp == '\t' || (char)tmp == '\n' )
+ { tmp = istr.read(); if( tmp == -1 ) return -1; }
+
+ // found a non whitespace
+ if( (char)tmp == '#' ) {
+ // comment => skip until end of line
+ do { tmp = istr.read(); if( tmp == -1 ) return -1; }
+ while( (char)tmp != '\n' );
+
+ istr.unread(tmp);
+ continue;
+ }
+ else {
+ // go back to last mark
+ istr.unread(tmp);
+ return 1;
+ }
+ }
+ }
+ catch(IOException ID_10T) {}
+ return 1;
+ }
+
+ String __get_next_token(PushbackInputStream istr) {
+ // get next concatinates string token. consider quotes that embrace
+ // whitespaces
+ try {
+ String token = new String("");
+ int tmp0 = 0;
+ char tmp = 0;
+ char last_letter = 0;
+ while(1+1 == 2) {
+ last_letter = tmp; tmp0 = istr.read(); tmp = (char)tmp0;
+ if( tmp == -1
+ || ((tmp == ' ' || tmp == '\t' || tmp == '\n') && last_letter != '\\') ) {
+ return token;
+ }
+ else if( tmp == '\'' && last_letter != '\\' ) {
+ // QUOTES: un-backslashed quotes => it's a string
+ token += __get_string(istr);
+ continue;
+ }
+ else if( tmp == '{' && last_letter == '$') {
+ token += '{' + __get_until_closing_bracket(istr);
+ continue;
+ }
+ else if( tmp == '$' && last_letter == '\\') {
+ token += tmp; tmp = 0; // so that last_letter will become = 0, not '$';
+ continue;
+ }
+ else if( tmp == '\\' && last_letter != '\\')
+ continue; // don't append un-backslashed backslashes
+ token += tmp;
+ }
+ }
+ catch(IOException ID_10T) {}
+ return "";
+ }
+
+ String __get_string(PushbackInputStream istr) {
+ // parse input until next matching '
+
+ try {
+ String str = new String("");
+ int tmp0 = 0;
+ char tmp = 0;
+ char last_letter = 0;
+ while(1 + 1 == 2) {
+ last_letter = tmp; tmp0 = istr.read(); tmp = (char)tmp0;
+ if( tmp0 == -1 ) return str;
+ // un-backslashed quotes => it's the end of the string
+ else if( tmp == '\'' && last_letter != '\\') return str;
+ else if( tmp == '\\' && last_letter != '\\') continue; // don't append
+
+ str += tmp;
+ }
+ // return str;
+ }
+ catch(IOException ID_10T) {}
+ return "";
+ }
+
+ String __get_until_closing_bracket(PushbackInputStream istr) {
+ try {
+ // parse input until next matching }
+ String str = new String("");
+ int tmp0 = 0;
+ char tmp = 0;
+ char last_letter = 0;
+ int brackets = 1;
+ while(1 + 1 == 2) {
+ last_letter = tmp; tmp0 = istr.read(); tmp = (char)tmp0;
+ if( tmp == -1 ) return str;
+ else if( tmp == '{' && last_letter == '$') brackets += 1;
+ else if( tmp == '}') {
+ brackets -= 1;
+ // un-backslashed brackets => it's the end of the string
+ if( brackets == 0) return str + '}';
+ else if( tmp == '\\' && last_letter != '\\')
+ continue; // do not append an unbackslashed backslash
+ }
+ str += tmp;
+ }
+ }
+ catch(IOException ID_10T) {}
+ return "";
+ }
+
+ String process_section_label(String label,
+ Vector section_stack) {
+ String sname = label;
+ // 1) subsection of actual section ('./' prefix)
+ if( sname.length() >= 2 && sname.substring(0, 2).compareTo("./") == 0) {
+ sname = sname.substring(2, sname.length());
+ }
+ // 2) subsection of parent section ('../' prefix)
+ else if( sname.length() >= 3 && sname.substring(0, 3).compareTo("../") == 0) {
+ do {
+ if( section_stack.size() != 0 )
+ section_stack.removeElementAt(section_stack.size()-1);
+ sname = sname.substring(3, sname.length());
+ } while( sname.substring(0, 3).compareTo("../") == 0 );
+ }
+ // 3) subsection of the root-section
+ else {
+ // a root section
+ section_stack.removeAllElements();
+ }
+
+ if( sname.compareTo("") != 0 ) {
+ // parse section name for 'slashes'
+ int i=0;
+ while( i < sname.length() ) {
+ if( sname.charAt(i) == '/' ) {
+ section_stack.addElement(sname.substring(0,i));
+ if( i+1 < sname.length()-1 )
+ sname = sname.substring(i+1, sname.length());
+ i = 0;
+ }
+ else
+ i++;
+ }
+ section_stack.addElement(sname);
+ }
+ // else: "[]" => back to root section
+
+ String section = new String("");
+ if( section_stack.size() != 0 )
+ for(int i=0; i< section_stack.size() ; i++)
+ section += (String)(section_stack.elementAt(i)) + "/";
+ return section;
+ }
+ // (*) helper functions
+ int __convert_to_type(String S, int Default) {
+ int start_i = 0;
+ if( S.length() >= 2 && S.substring(0,2).compareTo("0x") == 0 ) start_i = 2;
+ else if( S.length() >=3 && S.substring(0,3).compareTo("-0x") == 0) start_i = 3;
+ else {
+ // a normal integer, not a hex number
+ try { return Integer.parseInt(S); }
+ catch(NumberFormatException ID_10T) {
+ try { return (int)java.lang.Math.rint(Double.valueOf(S).doubleValue()); }
+ catch(NumberFormatException ID_20T) { return Default; }
+ }
+ }
+
+ // a hexadecimal number
+ int number = 0;
+ for(int i=start_i; i<S.length(); i++) {
+ int c = (int)S.charAt(i);
+ int digit = 0;
+ if( c >= '0' && c <= '9') digit = c - '0';
+ else if( c >= 'a' && c <= 'f') digit = c - 'a';
+ else if( c >= 'A' && c <= 'F') digit = c - 'a';
+ else
+ break;
+ number *= 16;
+ number += digit;
+ }
+ if( start_i == 2 ) return number;
+ else return -number;
+ }
+
+ double __convert_to_type(String S, double Default) {
+ try { return Double.valueOf(S).doubleValue(); }
+ catch(NumberFormatException ID_10T) { return Default; }
+ }
+
+ void set_prefix(String Prefix) { prefix = Prefix; }
+
+ String __get_remaining_string(String String, String Start) {
+ // Checks if 'String' begins with 'Start' and returns the remaining String.
+ // Returns None if String does not begin with Start.
+
+ // note: java.lang.String: substring(a,b) = from a to b-1
+ // C++ string: substr(a,b) = from a to a + b
+ if( Start.compareTo("") == 0 ) return String;
+ if( String.indexOf(Start) == 0 ) return String.substring(Start.length(), String.length());
+ else return "";
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) cursor oriented functions
+ //.............................................................................
+ //
+ void disable_loop() { search_loop_f = false; }
+ void enable_loop() { search_loop_f = true; }
+ void reset_cursor() { search_failed_f = false; cursor = 0; }
+
+ void init_multiple_occurrence()
+ { disable_loop(); reset_cursor(); }
+
+ // -- search for a certain argument and set cursor to position
+ boolean search(String Option) {
+ int OldCursor = cursor;
+ String SearchTerm = prefix + Option;
+
+ if( OldCursor >= argv.size() ) OldCursor = argv.size() - 1;
+ search_failed_f = true;
+
+ // (*) first loop from cursor position until end
+ for(int c = cursor; c < argv.size(); c++) {
+ if( ((String)argv.elementAt(c)).compareTo(SearchTerm) == 0 )
+ { cursor = c; search_failed_f = false; return true; }
+ }
+ if( ! search_loop_f ) return false;
+
+ // (*) second loop from 0 to old cursor position
+ for(int c = 1; c < OldCursor; c++) {
+ if( ((String)argv.elementAt(c)).compareTo(SearchTerm) == 0 )
+ { cursor = c; search_failed_f = false; return true; }
+ }
+ // in case nothing is found the cursor stays where it was
+ return false;
+ }
+
+
+ boolean search(String P[]) {
+ for(int i=0; i<P.length; i++)
+ if( search(P[i]) == true ) return true;
+ return false;
+ }
+
+ boolean search(String P1, String P2) {
+ if( search(P1) == true ) return true;
+ else if( search(P2) == true ) return true;
+ else return false;
+ }
+
+ boolean search(String P1, String P2, String P3) {
+ if( search(P1, P2) == true ) return true;
+ else if( search(P3) == true ) return true;
+ else return false;
+ }
+
+ boolean search(String P1, String P2, String P3, String P4) {
+ if( search(P1, P2, P3) == true ) return true;
+ else if( search(P4) == true ) return true;
+ else return false;
+ }
+
+ boolean search(String P1, String P2, String P3, String P4,
+ String P5) {
+ if( search(P1, P2, P3, P4) == true ) return true;
+ else if( search(P5) == true ) return true;
+ else return false;
+ }
+
+ boolean search(String P1, String P2, String P3, String P4,
+ String P5, String P6) {
+ if( search(P1, P2, P3, P4, P5) == true ) return true;
+ else if( search(P6) == true ) return true;
+ else return false;
+ }
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) No operator overloading in java
+ // => give them the 'python names'
+ String getitem(int idx) {
+ if( idx < argv.size() ) return (String)argv.elementAt(idx) ;
+ else return new String("");
+ }
+
+ int get(int Idx, int Default) {
+ if( Idx >= argv.size() ) return Default;
+ return __convert_to_type((String)argv.elementAt(Idx), Default);
+ }
+
+ double get(int Idx, double Default) {
+ if( Idx >= argv.size() ) return Default;
+ return __convert_to_type((String)argv.elementAt(Idx), Default);
+ }
+
+ String get(int Idx, String Default) {
+ if( Idx >= argv.size() ) return Default;
+ else return (String)argv.elementAt(Idx);
+ }
+
+ int size() { return argv.size(); }
+ // -- next() function group
+ int next(int Default) {
+ if( search_failed_f ) return Default;
+ cursor++;
+ if( cursor >= argv.size() )
+ { cursor = argv.size(); return Default; }
+
+ if( prefix.compareTo("") == 0)
+ return __convert_to_type((String)argv.elementAt(cursor), Default);
+
+ String Remain = __get_remaining_string((String)argv.elementAt(cursor), prefix);
+
+ return Remain.compareTo("") != 0 ? __convert_to_type(Remain, Default) : Default;
+ }
+
+ double next(double Default) {
+ if( search_failed_f ) return Default;
+ cursor++;
+ if( cursor >= argv.size() )
+ { cursor = argv.size(); return Default; }
+
+ if( prefix.compareTo("") == 0)
+ return __convert_to_type((String)argv.elementAt(cursor), Default);
+
+ String Remain = __get_remaining_string((String)argv.elementAt(cursor), prefix);
+
+ return Remain.compareTo("") != 0 ? __convert_to_type(Remain, Default) : Default;
+ }
+
+ String next(String Default) {
+ if( search_failed_f ) return Default;
+ cursor++;
+ if( cursor >= argv.size() )
+ { cursor = argv.size(); return Default; }
+
+ if( prefix.compareTo("") == 0)
+ return (String)argv.elementAt(cursor);
+
+ String Remain = __get_remaining_string((String)argv.elementAt(cursor), prefix);
+
+ return Remain.compareTo("") != 0 ? Remain : Default;
+ }
+ // -- follow() function group
+ // distinct option to be searched for
+ int follow(int Default, String A1) {
+ if( search(A1) == false ) return Default;
+ return next(Default);
+ }
+ int follow(int Default, String A[]) {
+ if( search(A) == false ) return Default;
+ return next(Default);
+ }
+ int follow(int Default, String A1, String A2) {
+ if( search(A1, A2) == false ) return Default;
+ return next(Default);
+ }
+ int follow(int Default, String A1, String A2, String A3) {
+ if( search(A1, A2, A3) == false ) return Default;
+ return next(Default);
+ }
+ int follow(int Default, String A1, String A2, String A3, String A4) {
+ if( search(A1, A2, A3, A4) == false ) return Default;
+ return next(Default);
+ }
+ int follow(int Default, String A1, String A2, String A3, String A4,
+ String A5) {
+ if( search(A1, A2, A3, A4, A5) == false ) return Default;
+ return next(Default);
+ }
+ int follow(int Default, String A1, String A2, String A3, String A4,
+ String A5, String A6) {
+ if( search(A1, A2, A3, A4, A5, A6) == false ) return Default;
+ return next(Default);
+ }
+
+ ///////// double
+ double follow(double Default, String A1) {
+ if( search(A1) == false ) return Default;
+ return next(Default);
+ }
+ double follow(double Default, String A[]) {
+ if( search(A) == false ) return Default;
+ return next(Default);
+ }
+ double follow(double Default, String A1, String A2) {
+ if( search(A1, A2) == false ) return Default;
+ return next(Default);
+ }
+ double follow(double Default, String A1, String A2, String A3) {
+ if( search(A1, A2, A3) == false ) return Default;
+ return next(Default);
+ }
+ double follow(double Default, String A1, String A2, String A3, String A4) {
+ if( search(A1, A2, A3, A4) == false ) return Default;
+ return next(Default);
+ }
+ double follow(double Default, String A1, String A2, String A3, String A4,
+ String A5) {
+ if( search(A1, A2, A3, A4, A5) == false ) return Default;
+ return next(Default);
+ }
+ double follow(double Default, String A1, String A2, String A3, String A4,
+ String A5, String A6) {
+ if( search(A1, A2, A3, A4, A5, A6) == false ) return Default;
+ return next(Default);
+ }
+ ///////// String ...
+ String follow(String Default, String A1) {
+ if( search(A1) == false ) return Default;
+ return next(Default);
+ }
+ String follow(String Default, String A[]) {
+ if( search(A) == false ) return Default;
+ return next(Default);
+ }
+ String follow(String Default, String A1, String A2) {
+ if( search(A1, A2) == false ) return Default;
+ return next(Default);
+ }
+ String follow(String Default, String A1, String A2, String A3) {
+ if( search(A1, A2, A3) == false ) return Default;
+ return next(Default);
+ }
+ String follow(String Default, String A1, String A2, String A3, String A4) {
+ if( search(A1, A2, A3, A4) == false ) return Default;
+ return next(Default);
+ }
+ String follow(String Default, String A1, String A2, String A3, String A4,
+ String A5) {
+ if( search(A1, A2, A3, A4, A5) == false ) return Default;
+ return next(Default);
+ }
+ String follow(String Default, String A1, String A2, String A3, String A4,
+ String A5, String A6) {
+ if( search(A1, A2, A3, A4, A5, A6) == false ) return Default;
+ return next(Default);
+ }
+ // (*) directly followed arguments
+ int direct_follow(int Default, String Option) {
+ String FollowStr = match_starting_string(Option);
+ if( FollowStr.compareTo("") == 0 ) return Default;
+
+ int Value = __convert_to_type(FollowStr, Default);
+ if( ++cursor >= argv.size() ) cursor = argv.size();
+ return Value;
+ }
+
+ double direct_follow(double Default, String Option) {
+ String FollowStr = match_starting_string(Option);
+ if( FollowStr.compareTo("") == 0 ) return Default;
+ double Value = __convert_to_type(FollowStr, Default);
+ if( ++cursor >= argv.size() ) cursor = argv.size();
+ return Value;
+ }
+
+ String direct_follow(String Default, String Option) {
+ String FollowStr = match_starting_string(Option);
+ if( FollowStr.compareTo("") == 0) return Default;
+ if( ++cursor >= argv.size() ) cursor = argv.size();
+ return FollowStr;
+ }
+
+ String match_starting_string(String StartString) {
+ // pointer to the place where the string after
+ // the match inside the found argument starts.
+ // 0 no argument matches the starting string.
+ int N = StartString.length();
+ int OldCursor = cursor;
+ if( OldCursor >= argv.size() ) OldCursor = argv.size() - 1;
+ search_failed_f = true;
+
+ // (*) first loop from cursor position until end
+ for(int c = cursor; c < argv.size(); c++) {
+ String Arg = (String)argv.elementAt(c);
+ if( Arg.length() >= N && Arg.substring(0,N).compareTo(StartString) == 0) {
+ cursor = c; search_failed_f = false;
+ return ((String)argv.elementAt(c)).substring(N);
+ }
+ }
+
+ if( search_loop_f == false ) return "";
+
+ // (*) second loop from 0 to old cursor position
+ for(int c = 1; c < OldCursor; c++) {
+ String Arg = (String)argv.elementAt(c);
+ if( Arg.length() >= N && Arg.substring(0,N).compareTo(StartString)==0 ) {
+ cursor = c; search_failed_f = false;
+ return ((String)argv.elementAt(c)).substring(N);
+ }
+ }
+ return "";
+ }
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) search for flags
+ //.............................................................................
+ //
+ boolean options_contain(String FlagList) {
+ // go through all arguments that start with a '-', but not more than one
+ for(int i = 0; i<argv.size() ; i++) {
+ String str;
+ if( prefix.compareTo("") != 0 ) str = __get_remaining_string((String)argv.elementAt(i), prefix);
+ else str = (String)argv.elementAt(i);
+
+ if( str.length() > 1 && str.charAt(0) == '-' && str.charAt(1) != '-' )
+ if( check_flags(str, FlagList) ) return true;
+ }
+ return false;
+ }
+
+ boolean argument_contains(int Idx, String FlagList) {
+ if( Idx >= argv.size() || Idx < 0) return false;
+
+ if( prefix.compareTo("") == 0 )
+ return check_flags((String)argv.elementAt(Idx), FlagList);
+
+ // if a prefix is set, then the argument index is the index
+ // inside the 'namespace'
+ // => only check list of arguments that start with prefix
+ int no_matches = 0;
+ for(int i=0; i < argv.size(); i++) {
+ String Remain = __get_remaining_string((String)argv.elementAt(i), prefix);
+ if( Remain.compareTo("") != 0 ) {
+ no_matches += 1;
+ if( no_matches == Idx)
+ return check_flags(Remain, FlagList);
+ }
+ }
+ // no argument in this namespace
+ return false;
+
+ }
+
+ boolean check_flags(String Str, String FlagList) {
+ for(int i=0; i != FlagList.length() ; i++)
+ if( Str.indexOf(FlagList.charAt(i)) != -1 )
+ // one of the flags was found in given string
+ return true;
+ return false;
+ }
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) nominus arguments
+ String[] nominus_vector() {
+ String nv[] = new String[idx_nominus.size()];
+ int i=0;
+ for(Enumeration inm = idx_nominus.elements() ; inm.hasMoreElements(); i++) {
+ Integer e = (Integer)inm.nextElement();
+ nv[i] = (String)argv.elementAt(e.intValue());
+ }
+ return nv;
+ }
+
+ String next_nominus() {
+ if( nominus_cursor >= idx_nominus.size()-1 ) return "";
+ int C = ++nominus_cursor;
+ return (String)argv.elementAt(((Integer)idx_nominus.elementAt(C)).intValue());
+ }
+
+ void reset_nominus_cursor()
+ { nominus_cursor = -1; }
+
+ boolean search_failed()
+ { return search_failed_f; }
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) variables
+ // (no operator overloading, => functions with 'python names' for
+ // operators
+ int call(String VarName, int Default) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0 ) return Default;
+ return __convert_to_type(sv.original, Default);
+ }
+
+ double call(String VarName, double Default) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0) return Default;
+ return __convert_to_type(sv.original, Default);
+ }
+
+ String call(String VarName, String Default) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0) return Default;
+ return sv.original;
+ }
+
+ int call(String VarName, int Default, int Idx) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0) return Default;
+ String element = sv.get_element(Idx);
+ if( element.compareTo("") == 0) return Default;
+ return __convert_to_type(element, Default);
+ }
+
+ double call(String VarName, double Default, int Idx) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0) return Default;
+ String element = sv.get_element(Idx);
+ if( element.compareTo("") == 0) return Default;
+ return __convert_to_type(element, Default);
+ }
+
+ String call(String VarName, String Default, int Idx) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0) return Default;
+ String element = sv.get_element(Idx);
+ if( element.compareTo("") == 0) return Default;
+ return element;
+ }
+
+ int vector_variable_size(String VarName) {
+ variable sv = find_variable(VarName);
+ if( sv.name.compareTo("") == 0) return 0;
+ return sv.value.length;
+ }
+
+ variable find_variable(String NameX) {
+ String Name = prefix + NameX;
+ for(Enumeration inm = variables.elements() ; inm.hasMoreElements(); ) {
+ variable v = (variable)inm.nextElement();
+ if( v.name.compareTo(Name) == 0 ) return v;
+ }
+ return new variable("","");
+ }
+
+ String[] get_variable_names() {
+ Vector result = new Vector();
+ int length = 0;
+ for(Enumeration inm = variables.elements() ; inm.hasMoreElements(); ) {
+ String Name = ((variable)inm.nextElement()).name;
+ String Tmp = __get_remaining_string(Name, prefix);
+ if( Tmp != "") {
+ result.addElement(new String(Tmp));
+ length++;
+ }
+ }
+ String end[] = new String[length];
+ int i = 0;
+ for(Enumeration inm = result.elements() ; inm.hasMoreElements(); i++) {
+ String Name = (String)inm.nextElement();
+ end[i] = Name;
+ }
+ return end;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) ouput (basically for debugging reasons)
+ //.............................................................................
+ //
+ void print() {
+ System.out.println("argc = " + argv.size() + "\n");
+ for(int i=0; i<argv.size() ; i++)
+ System.out.println(argv.elementAt(i));
+ return;
+ }
+
+ // (*) dollar bracket expressions (DBEs) ------------------------------------
+ //
+ // 1) Entry Function: dbe_expand_string()
+ // Takes a string such as
+ //
+ // "${+ ${x} ${y}} Subject-${& ${section} ${subsection}}: ${title}"
+ //
+ // calls DBE_expand_string() for each of the expressions
+ //
+ // ${+ ${x} ${y}}
+ // ${& ${section} ${subsection}}
+ // ${Title}
+ //
+ // and returns the string
+ //
+ // "4711 Subject-1.01: Mit den Clowns kamen die Schwaene"
+ //
+ // assuming that
+ // x = "4699"
+ // y = "12"
+ // section = "1."
+ // subsection = "01"
+ // title = "Mit den Clowns kamen die Schwaene"
+ //
+ // 2) DBE_expand():
+ //
+ // checks for the command, i.e. the 'sign' that follows '${'
+ // divides the argument list into sub-expressions using
+ // DBE_get_expr_list()
+ //
+ // ${+ ${x} ${y}} -> "${x}" "${y}"
+ // ${& ${section} ${subsection}} -> "${section}" "${subsection}"
+ // ${Title} -> Nothing, variable expansion
+ //
+ // 3) DBE_expression_list():
+ //
+ // builds a vector of unbracketed whitespace separated strings, i.e.
+ //
+ // " ${Number}.a ${: Das Marmorbild} AB-${& Author= ${Eichendorf}-1870}"
+ //
+ // is split into a vector
+ //
+ // [0] ${Number}.a
+ // [1] ${: Das Marmorbild}
+ // [2] AB-${& Author= ${Eichendorf}}-1870
+ //
+ // Each sub-expression is expanded using expand().
+ //---------------------------------------------------------------------------
+ String DBE_expand_string(String str) {
+ // Parses for closing operators '${ }' and expands them letting
+ // white spaces and other letters as they are.
+ String new_string = "";
+ int open_brackets = 0;
+ int first = 0;
+ for(int i = 0; i<str.length(); i++) {
+ if( i < str.length() - 2 && str.substring(i, i+2).compareTo("${") == 0 ) {
+ if( open_brackets == 0 ) first = i+2;
+ open_brackets++;
+ }
+ else if( str.charAt(i) == '}' && open_brackets > 0) {
+ open_brackets -= 1;
+ if( open_brackets == 0 ) {
+ String Replacement = DBE_expand(str.substring(first, i));
+ new_string += Replacement;
+ }
+ }
+ else if( open_brackets == 0 )
+ new_string += str.charAt(i);
+ }
+ return new_string;
+ }
+
+ Vector DBE_get_expr_list(String str_, int ExpectedNumber) {
+ // ensures that the resulting vector has the expected number
+ // of arguments, but they may contain an error message
+
+ String str = str_;
+ // Separates expressions by non-bracketed whitespaces, expands them
+ // and puts them into a list.
+ int i=0;
+
+ // (1) eat initial whitespaces
+ for(; i < str.length(); i++) {
+ char tmp = str.charAt(i);
+ if( tmp != ' ' && tmp != '\t' && tmp != '\n' ) break;
+ }
+
+ Vector expr_list = new Vector();
+ int open_brackets = 0;
+ Vector start_idx = new Vector();
+ int start_new_string = i;
+ int l = str.length();
+
+ // (2) search for ${ } expressions ...
+ while( i < l ) {
+ char letter = str.charAt(i);
+ // whitespace -> end of expression
+ if( (letter == ' ' || letter == '\t' || letter == '\n') && open_brackets == 0) {
+ expr_list.addElement(str.substring(start_new_string, i));
+ boolean no_breakout_f = true;
+ for(i++; i < l ; i++) {
+ char tmp = str.charAt(i);
+ if( tmp != ' ' && tmp != '\t' && tmp != '\n' )
+ { no_breakout_f = false; start_new_string = i; break; }
+ }
+ if( no_breakout_f == true ) {
+ // end of expression list
+ if( expr_list.size() < ExpectedNumber ) {
+ String pre_tmp = "<< ${ }: missing arguments>>";
+ for(int ni = expr_list.size(); ni < ExpectedNumber; ni++)
+ expr_list.addElement(pre_tmp);
+ }
+ return expr_list;
+ }
+ }
+
+ // dollar-bracket expression
+ if( str.length() >= i+2 && str.substring(i, i+2).compareTo("${") == 0 ) {
+ open_brackets++;
+ start_idx.addElement(new Integer(i+2));
+ }
+ else if( letter == '}' && open_brackets > 0) {
+ int start = ((Integer)start_idx.elementAt(start_idx.size()-1)).intValue();
+ start_idx.removeElementAt(start_idx.size()-1);
+ String Replacement = DBE_expand(str.substring(start, i));
+ if( start - 3 < 0)
+ str = Replacement + str.substring(i+1);
+ else
+ str = str.substring(0, start-2) + Replacement + str.substring(i+1);
+ l = str.length();
+ i = start + Replacement.length() - 3;
+ open_brackets--;
+ }
+ i++;
+ }
+
+ // end of expression list
+ expr_list.addElement(str.substring(start_new_string, i));
+
+ if( expr_list.size() < ExpectedNumber ) {
+ String pre_tmp = "<< ${ }: missing arguments>>";
+ for(int ni = expr_list.size(); ni < ExpectedNumber; ni++)
+ expr_list.addElement(pre_tmp);
+ }
+ return expr_list;
+ }
+
+ variable DBE_get_variable(String VarName) {
+ variable ev = new variable();
+ String secure_Prefix = prefix;
+
+ prefix = section;
+ // (1) first search in currently active section
+ variable var = find_variable(VarName);
+ if( var.name != "" ) { prefix = secure_Prefix; return var; }
+
+ // (2) search in root name space
+ prefix = "";
+ var = find_variable(VarName);
+ if( var.name != "" ) { prefix = secure_Prefix; return var; }
+
+ prefix = secure_Prefix;
+
+ // error occured => variable name == ""
+ ev.name = "";
+ ev.original = "<<${ } variable '" + VarName + "' undefined>>";
+ return ev;
+ }
+
+ String DBE_expand(String expr) {
+ // ${: } pure text
+ if( expr.charAt(0) == ':' )
+ return expr.substring(1);
+
+ // ${& expr expr ... } text concatination
+ else if( expr.charAt(0) == '&' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 1);
+ String result = "";
+ for(Enumeration e = A.elements() ; e.hasMoreElements() ; ) {
+ String add = (String)e.nextElement();
+ result += add;
+ }
+ return result;
+ }
+
+ // ${<-> expr expr expr} text replacement
+ else if( expr.length() >= 3 && expr.substring(0, 3).compareTo("<->") == 0) {
+ Vector A = DBE_get_expr_list(expr.substring(3), 3);
+ String Arg0 = (String)A.elementAt(0);
+ String Arg1 = (String)A.elementAt(1);
+ String Arg2 = (String)A.elementAt(2);
+ int L = Arg1.length();
+
+ while( 1 + 1 == 2 ) {
+ int tmp = Arg0.indexOf(Arg1);
+ if( tmp == -1 ) break;
+ if( tmp == 0 ) Arg0 = Arg2 + Arg0.substring(L);
+ else Arg0 = Arg0.substring(0, tmp) + Arg2 + Arg0.substring(L+tmp);
+ }
+ return Arg0;
+ }
+ // ${+ ...}, ${- ...}, ${* ...}, ${/ ...} expressions
+ else if( expr.charAt(0) == '+' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 2);
+
+ double result = 0.0;
+
+ for(Enumeration e = A.elements() ; e.hasMoreElements() ; ) {
+ String add = (String)e.nextElement();
+ result += __convert_to_type(add, 0.0);
+ }
+
+ return (new Double(result)).toString();
+ }
+ else if( expr.charAt(0) == '-' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 2);
+
+ Enumeration e = A.elements();
+ double result = __convert_to_type((String)e.nextElement(), 0.0);
+ for(; e.hasMoreElements() ; ) {
+ String sub = (String)e.nextElement();
+ result -= __convert_to_type(sub, 0.0);
+ }
+ return (new Double(result)).toString();
+ }
+ else if( expr.charAt(0) == '*' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 2);
+
+ double result = 1.0;
+ for(Enumeration e = A.elements() ; e.hasMoreElements() ; ) {
+ String mul = (String)e.nextElement();
+ result *= __convert_to_type(mul, 0.0);
+ }
+
+ return (new Double(result)).toString();
+ }
+ else if( expr.charAt(0) == '/' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 2);
+ Enumeration e = A.elements();
+ double result = __convert_to_type((String)e.nextElement(), 0.0);
+ if( result == 0 ) return "0.0";
+ for(; e.hasMoreElements() ; ) {
+ double Q = __convert_to_type((String)e.nextElement(), 0.0);
+ if( Q == 0.0) return "0.0";
+ result /= Q;
+ }
+ return (new Double(result)).toString();
+ }
+
+ // ${^ ... } power expressions
+ else if( expr.charAt(0) == '^' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 2);
+
+ Enumeration e = A.elements();
+ double result = __convert_to_type((String)e.nextElement(), 0.0);
+ for(; e.hasMoreElements() ; ) {
+ double p = __convert_to_type((String)e.nextElement(), 0.0);
+ result = java.lang.Math.pow(result, p);
+ }
+
+ return (new Double(result)).toString();
+ }
+
+ // ${== } ${<= } ${>= } comparisons (return the number of the first 'match'
+ else if(expr.length() >= 2 &&
+ (expr.substring(0,2).compareTo("==") == 0 ||
+ expr.substring(0,2).compareTo(">=") == 0 ||
+ expr.substring(0,2).compareTo("<=") == 0 ||
+ expr.charAt(0) == '>' ||
+ expr.charAt(0) == '<') ) {
+ // differentiate between two and one sign operators
+ int op = 0;
+ // EQ = 0 GEQ = 1 LEQ = 2 GT = 3 LT = 4
+ if ( expr.substring(0, 2).compareTo("==") == 0 ) op = 0;
+ else if ( expr.substring(0, 2).compareTo(">=") == 0 ) op = 1;
+ else if ( expr.substring(0, 2).compareTo("<=") == 0 ) op = 2;
+ else if ( expr.charAt(0) == '>' ) op = 3;
+ else op = 4;
+
+ Vector a = new Vector();
+ if ( op >= 3 ) a = DBE_get_expr_list(expr.substring(1), 2);
+ else a = DBE_get_expr_list(expr.substring(2), 2);
+
+ Enumeration e = a.elements();
+ String x_orig = (String)e.nextElement();
+ double x = __convert_to_type(x_orig, 1e37);
+ int i = 1;
+ for(; e.hasMoreElements() ; ) {
+ String y_orig = (String)e.nextElement();
+ double y = __convert_to_type(y_orig, 1e37);
+
+ // set the strings as reference if something wasn't a number
+ if ( x == 1e37 || y == 1e37 ) {
+ // it's a string comparison
+ int comparison = x_orig.compareTo(y_orig);
+
+ if( ( op == 0 && comparison == 0)
+ || (op == 1 && comparison >= 0)
+ || (op == 2 && comparison <= 0)
+ || (op == 3 && comparison > 0)
+ || (op == 4 && comparison < 0) ) {
+ return (new Integer(i)).toString();
+ }
+ }
+ else {
+ // it's a number comparison
+ if( (op == 0 && x == y) || (op == 1 && x >= y) ||
+ (op == 2 && x <= y) || (op == 3 && x > y) ||
+ (op == 4 && x < y) ) {
+ return (new Integer(i)).toString();
+ }
+ }
+ i++;
+ }
+ // nothing fulfills the condition => return 0
+ return "0";
+ }
+ // ${?? expr expr} select
+ else if( expr.length() >= 2 && expr.substring(0, 2).compareTo("??") == 0) {
+ Vector a = DBE_get_expr_list(expr.substring(2), 2);
+ double x = __convert_to_type((String)a.elementAt(0), 1e37);
+ // last element is always the default argument
+ if( x == 1e37 || x < 0 || x >= a.size() - 1 )
+ return (String)a.elementAt(a.size()-1);
+
+ // round x to closest integer
+ int rx = (int)java.lang.Math.rint(x);
+ return (String)a.elementAt(rx);
+ }
+ // ${? expr expr expr} if then else conditions
+ else if( expr.charAt(0) == '?' ) {
+ Vector a = DBE_get_expr_list(expr.substring(1), 2);
+ if( __convert_to_type((String)a.elementAt(0), 0.0) == 1.0 )
+ return (String)a.elementAt(1);
+ else if( a.size() > 2 )
+ return (String)a.elementAt(2);
+ }
+ // ${! expr} maxro expansion
+ else if( expr.charAt(0) == '!' ) {
+ variable Var = DBE_get_variable(expr.substring(1));
+ // error
+ if( Var.name == "" ) return Var.original;
+
+ Vector A = DBE_get_expr_list(Var.original, 2);
+ return (String)A.elementAt(0);
+ }
+ // ${@: } - string subscription
+ else if( expr.length() >=2 && expr.substring(0,2).compareTo("@:") == 0 ) {
+ Vector A = DBE_get_expr_list(expr.substring(2), 2);
+ double x = __convert_to_type((String)A.elementAt(1), 1e37);
+
+ // last element is always the default argument
+ if( x == 1e37 || x < 0 || x >= (double)((String)A.elementAt(0)).length() - 1)
+ return "<<1st index out of range>>";
+
+ if( A.size() > 2 ) {
+ double y = __convert_to_type((String)A.elementAt(2), 1e37);
+ if ( y != 1e37 && y > 0 && y <= (double)((String)A.elementAt(0)).length() - 1 && y > x ) {
+ // note: java.lang.String: substring(a,b) = from a to b - 1
+ // C++ string: substr(a,b) = from a to a + b
+ int rx1 = (int)java.lang.Math.rint(x);
+ int rx2 = (int)java.lang.Math.rint(y + 1.0);
+ return ((String)A.elementAt(0)).substring(rx1, rx2);
+ }
+ else if( y == -1 ) {
+ int rx = (int)java.lang.Math.rint(x);
+ return ((String)A.elementAt(0)).substring(rx);
+ }
+ return "<<2nd index out of range>>";
+ }
+ else {
+ String tmp = (String)A.elementAt(0);
+ int rx = (int)java.lang.Math.rint(x);
+ return (String)tmp.substring(rx, rx+1);
+ }
+ }
+ // ${@ } - vector subscription
+ else if( expr.charAt(0) == '@' ) {
+ Vector A = DBE_get_expr_list(expr.substring(1), 2);
+ variable Var = DBE_get_variable((String)A.elementAt(0));
+ // error
+ if( Var.name == "" ) {
+ // make a copy of the string if an error occured
+ // (since the error variable is a static variable inside get_variable())
+ return Var.original;
+ }
+
+ double x = __convert_to_type((String)A.elementAt(1), 1e37);
+
+ // last element is always the default argument
+ if (x == 1e37 || x < 0 || x >= Var.value.length )
+ return "<<1st index out of range>>";
+
+ if ( A.size() > 2) {
+ double y = __convert_to_type((String)A.elementAt(2), 1e37);
+ int begin = (int)java.lang.Math.rint(x);
+ int end = 0;
+ if ( y != 1e37 && y > 0 && y <= Var.value.length && y > x)
+ end = (int)java.lang.Math.rint(y + 1.0);
+ else if( y == -1 )
+ end = Var.value.length;
+ else
+ return "<<2nd index out of range>>";
+
+ String result = Var.get_element(begin);
+ for(int i = begin+1; i < end; i++)
+ result += " " + Var.get_element(i);
+ return result;
+ }
+ else {
+ int tmp = (int)java.lang.Math.rint(x);
+ return Var.get_element(tmp);
+ }
+ }
+ Vector A = DBE_get_expr_list(expr, 1);
+ variable B = DBE_get_variable((String)A.elementAt(0));
+
+ // make a copy of the string if an error occured
+ // (since the error variable is a static variable inside get_variable())
+ if( B.name == "" ) return (String)B.original;
+ else return B.original;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // (*) unidentified flying objects
+ //.............................................................................
+ //
+ String[] string_vector_to_string_array(Vector Vec) {
+ String[] result = new String[Vec.size()];
+ for(int i =0; i < Vec.size(); i++ )
+ result[i] = (String)Vec.elementAt(i);
+ return result;
+ }
+
+ int __search_string_array(String[] Arr, String Str) {
+ for(int i=0; i < Arr.length ; i++)
+ if( Str.compareTo(Arr[i]) == 0 ) return i;
+ return -1;
+ }
+
+ String[] unidentified_arguments(String KnownArguments[]) {
+ Vector ufos = new Vector();
+ Enumeration arge = argv.elements();
+ if( arge.hasMoreElements() == false )
+ return string_vector_to_string_array(ufos);
+
+ // forget about first element (application name)
+ String it = (String)arge.nextElement();
+ for(; arge.hasMoreElements() ;) {
+ it = (String)arge.nextElement();
+ // -- argument belongs to prefixed section ?
+ String arg = __get_remaining_string(it, prefix);
+ if( arg == "" ) continue;
+
+ // -- check if argument is known
+ if( __search_string_array(KnownArguments, arg) == -1 )
+ ufos.addElement(it);
+ }
+ return string_vector_to_string_array(ufos);
+ }
+
+
+ String[] unidentified_options(String KnownOptions[]) {
+ Vector ufos = new Vector();
+
+ Enumeration arge = argv.elements();
+ if( arge.hasMoreElements() == false )
+ return string_vector_to_string_array(ufos);
+ // forget about first element (application name)
+ String it = (String)arge.nextElement();
+ for(; arge.hasMoreElements() ;) {
+ it = (String)arge.nextElement();
+ // -- argument belongs to prefixed section ?
+ String arg = __get_remaining_string(it, prefix);
+ if( arg == "" ) continue;
+ // -- argument == option ?
+ if( arg.length() < 1 || arg.charAt(0) != '-' ) continue;
+ // -- check if argument is known
+ if( __search_string_array(KnownOptions, arg) == -1 )
+ ufos.addElement(it);
+ }
+ return string_vector_to_string_array(ufos);
+ }
+
+ String unidentified_flags(String KnownFlagList) {
+ return unidentified_flags(KnownFlagList, -1);
+ }
+
+ String unidentified_flags(String KFL, int ArgumentNumber) {
+ // Two modes:
+ // ArgumentNumber >= 0 check specific argument
+ // ArgumentNumber == -1 check all options starting with one '-'
+ // for flags
+
+ String ufos = "";
+ Vector known_arguments;
+
+ // (2) iteration over '-' arguments (options)
+ if( ArgumentNumber == -1 ) {
+ // iterate over all arguments
+ Enumeration arge = argv.elements();
+ if( arge.hasMoreElements() == false ) return ufos;
+ // forget about first element (application name)
+ String it = (String)arge.nextElement();
+ for(; arge.hasMoreElements() ;) {
+ it = (String)arge.nextElement();
+ // -- argument belongs to prefixed section ?
+ String arg = __get_remaining_string(it, prefix);
+ if( arg == "" ) continue;
+
+ // does arguments start with '-' (but not '--')
+ if ( arg.length() < 2 ) continue;
+ else if( arg.charAt(0) != '-' ) continue;
+ else if( arg.charAt(1) == '-' ) continue;
+
+ // -- check out if flags inside option are contained in KnownFlagList
+ for(int i=1; i<arg.length() ; i++) {
+ char flag = arg.charAt(i);
+ if( KFL.indexOf(flag) == -1 ) ufos += flag;
+ }
+ }
+ }
+ else {
+ int no_matches = 0;
+ // -- only check arguments that start with prefix
+ Enumeration arge = argv.elements();
+ if( arge.hasMoreElements() == false ) return ufos;
+ // forget about first element (application name)
+ String it = (String)arge.nextElement();
+ for(; arge.hasMoreElements() ;) {
+ it = (String)arge.nextElement();
+ String Remain = __get_remaining_string(it, prefix);
+ if( Remain != "") {
+ no_matches += 1;
+ if( no_matches == ArgumentNumber) {
+ // -- the right argument number inside the section is found
+ // => check it for flags
+ for(int i=0; i<Remain.length() ; i++) {
+ char flag = Remain.charAt(i);
+ if( KFL.indexOf(flag) == -1 ) ufos += flag;
+ }
+ }
+ }
+ }
+ }
+ return ufos;
+ }
+
+
+ String[] unidentified_variables(String[] Knowns) {
+ Vector ufos = new Vector();
+
+ for(Enumeration inm = variables.elements() ; inm.hasMoreElements(); ) {
+ variable it = (variable)inm.nextElement();
+ // -- variable belongs to prefixed section ?
+ String var_name = __get_remaining_string(it.name, prefix);
+ if( var_name == "" ) continue;
+
+ // -- check if variable is known
+ if( __search_string_array(Knowns, var_name) == -1 )
+ ufos.addElement(it.name);
+ }
+ return string_vector_to_string_array(ufos);
+ }
+
+
+ String[] unidentified_sections(String[] Knowns) {
+ Vector ufos = new Vector();
+
+ for(Enumeration inm = section_list.elements() ; inm.hasMoreElements(); ) {
+ String it = (String)inm.nextElement();
+ // -- section a subsection of prefix ?
+ String sec_name = __get_remaining_string(it, prefix);
+ if( sec_name == "" ) continue;
+
+ // -- section is known ?
+ if( __search_string_array(Knowns, sec_name) == -1 )
+ ufos.addElement(it);
+ }
+ return string_vector_to_string_array(ufos);
+ }
+
+
+ String[] unidentified_nominuses(String[] KnownNominuses) {
+ Vector ufos = new Vector();
+
+ // iterate over all arguments
+ Enumeration arge = argv.elements();
+ if( arge.hasMoreElements() == false )
+ return string_vector_to_string_array(ufos);
+ // forget about first element (application name)
+ String it = (String)arge.nextElement();
+ for(; arge.hasMoreElements() ;) {
+ it = (String)arge.nextElement();
+ // -- argument belongs to prefixed section ?
+ String arg = __get_remaining_string(it, prefix);
+ if( arg == "" ) continue;
+
+ if( arg.length() < 1 ) continue;
+ // option ? --> not a nomius
+ if( arg.charAt(0) == '-' ) continue;
+ // section ? --> not a real nominus
+ if( arg.charAt(0) == '[' && arg.charAt(arg.length()-1) == ']' ) continue;
+ // variable definition ? --> not a real nominus
+ boolean continue_f = false;
+ for(int i=0; i<arg.length() ; i++)
+ if( arg.charAt(i) == '=' ) { continue_f = true; break; }
+ if( continue_f ) continue;
+
+ // real nominuses are compared with the given list
+ if( __search_string_array(KnownNominuses, arg) == -1 )
+ ufos.addElement(it);
+ }
+ return string_vector_to_string_array(ufos);
+ }
+}
--- /dev/null
+// -*- java -*-
+// FILE: InputFile.java Version 0.9.8
+// (C) 2001 Frank R. Schaefer
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//////////////////////////////////////////////////////////////////////////////////////
+import GetPot.*;
+import java.lang.String;
+
+public class InputFile {
+ public static void main(String args []) {
+ GetPot cl = new GetPot(args, "InputFile");
+ GetPot ifile = new GetPot("example.pot");
+
+ if( cl.size() == 1 || cl.search("--help", "-h") )
+ { print_help(); System.exit(0); }
+
+ if( cl.search("--internal-information", "-i") )
+ { ifile.print(); System.exit(0); }
+
+ // (2) playing with sections
+ System.out.println("webpage = " + ifile.call("webpage", "nothing.somewhere.idn"));
+ System.out.println("user = " + ifile.call("user", "nobody"));
+ System.out.println("dos-file = " + ifile.call("dos-file", "nobody"));
+ System.out.println("latex-formula = " + ifile.call("latex-formula", "nobody"));
+ System.out.println("no. clicks = " + ifile.call("clicks", 0));
+ System.out.println("acceleration = " + ifile.call("acceleration", 3.14));
+
+ System.out.println("vehicle/wheel-base = " + ifile.call("vehicle/wheel-base",2.66));
+ System.out.print("vehicle/initial-xyz = ");
+ // first element of vector
+ System.out.print(ifile.call("vehicle/initial-xyz", 0., 0) + "\t");
+ // second element of vector
+ System.out.print(ifile.call("vehicle/initial-xyz", 0., 1) + "\t");
+ // third element of vector
+ System.out.print(ifile.call("vehicle/initial-xyz", 0., 2) + "\n");
+
+ System.out.println("vehicle/tires/B = " + ifile.call("vehicle/tires/B",777.7));
+ System.out.println(" C = " + ifile.call("vehicle/tires/C", 777.7));
+ System.out.println(" E = " + ifile.call("vehicle/tires/E", 777.7));
+ System.out.println(" D = " + ifile.call("vehicle/tires/D", 777.7));
+
+ System.out.println("vehicle/chassis/Roh = " + ifile.call("vehicle/chassis/Roh",777.7));
+ System.out.println(" S = " + ifile.call("vehicle/chassis/S", 777.7));
+ System.out.println(" Cd = " + ifile.call("vehicle/chassis/Cd", 777.7));
+
+ System.out.println("vehicle/chassis/doors/number = " + ifile.call("vehicle/chassis/doors/number",2));
+ System.out.println(" locks = " + ifile.call("vehicle/chassis/doors/locks","yes"));
+
+ // (3) playing with things we do normally only with command line arguments
+ boolean n_f = ifile.search("--nonsense", "-n", "--unsinn", "--sans-sense");
+ double XR = ifile.follow(3.14, "vehicle/-x");
+ System.out.println("x-ratio = " + XR);
+ System.out.println("sound-mode = " + ifile.next("none"));
+ System.out.println("nonsense-flag = " + (n_f ? "activated" : "disabled"));
+ }
+
+
+ static void
+ print_help() {
+ System.out.println();
+ System.out.println("Example how to use GetPot to parse input files.");
+ System.out.println();
+ System.out.println("USAGE:");
+ System.out.println("--ok");
+ System.out.println(" run the input file parsing." );
+ System.out.println("--help, -h, --hilfe, --sos");
+ System.out.println(" get some help about this program.");
+ System.out.println();
+ System.out.println("--internal-information, -i");
+ System.out.println(" show contents of database that was created by file parser.");
+ System.out.println();
+ System.out.println("--infile string");
+ System.out.println(" input file name (default: example.pot)");
+ System.out.println();
+ }
+}
--- /dev/null
+// -*- java -*-
+// FILE: Next.java Version 0.9.8
+// (C) 2001 Frank R. Schaefer
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//////////////////////////////////////////////////////////////////////////////////////
+import GetPot.*;
+import java.lang.String;
+
+public class Next {
+ public static void main(String args []) {
+ GetPot cl = new GetPot(args, "Next");
+
+ // all the following pain, only to pass a string array
+ // to function 'cl.search(..)'
+ if( cl.search("--help", "-h", "--hilfe") ) print_help();
+ // read arguments one by one on the command line
+ // (lazy command line parsing)
+ cl.reset_cursor();
+ double A = cl.next(0.); // [rad]
+ int B = cl.next(256); // [1/s]
+ String User = cl.next("You");
+ int No = cl.next(0x42);
+
+ System.out.println();
+ System.out.println("A = " + A);
+ System.out.println("B = " + B);
+ System.out.println("Name = " + User);
+ System.out.println("Special number = " + No);
+ System.out.println();
+ }
+
+ static void print_help() {
+ System.out.println();
+ System.out.println("Example to use next()-functions:\n");
+ System.out.println("USAGE:");
+ System.out.println(" $1 (double) Value of A");
+ System.out.println(" $2 (integer) Value of B");
+ System.out.println(" $3 (string) Name to be printed");
+ System.out.println(" $4 (integer) Some number to be printed");
+ System.out.println();
+ System.exit(0);
+ }
+}
+
--- /dev/null
+// -*- java -*-
+// FILE: Nominus.java
+// (C) 2001 Frank R. Schaefer
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//////////////////////////////////////////////////////////////////////////////////////
+import GetPot.*;
+import java.lang.String;
+
+public class Nominus {
+ public static void main(String args []) {
+ GetPot cl = new GetPot(args, "Nominus");
+
+ // if( cl.size() == 1 || cl.search("--help", "-h") ) print_help();
+
+ // print out all argument that do not start with a minus
+ String nm = cl.next_nominus();
+ while( nm != "" ) {
+ System.out.println("[" + nm + "]");
+ nm = cl.next_nominus();
+ }
+
+ System.out.println();
+
+ // now get the whole vector at once
+ String[] files = cl.nominus_vector();
+ for(int i=0; i<files.length ; i++)
+ System.out.println("<" + files[i] + ">");
+
+ }
+
+ static void print_help() {
+ System.out.println();
+ System.out.println( "Example to use nominus arguments:");
+ System.out.println( "USAGE:");
+ System.out.println( "--help, -h get some help about this program.");
+ System.out.println();
+ System.out.println( "any option that does not start with '-'");
+ System.out.println( "will be printed on screen twice.");
+ System.out.println();
+ System.exit(0);
+ }
+}
+
+
--- /dev/null
+// -*- java -*-
+// FILE: Options.java Version 0.9.8
+// (C) 2001 Frank R. Schaefer
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//////////////////////////////////////////////////////////////////////////////////////
+import GetPot.*;
+import java.lang.String;
+
+public class Options {
+ public static void main(String args []) {
+ GetPot cl = new GetPot(args, "Options");
+
+ // (1) search for a single option
+ // -------------------------------
+ // check if the '--do-nothing' flag is set and exit if yes
+ if( cl.search("--do-nothing") ) System.exit(0);
+
+ // (2) search for multiple options with the same meaning
+ // GetPot Java can treat upto 6 strings, then it needs a String[]
+ if( cl.search("--help", "-h", "--hilfe", "--sos", "--about", "--what-is") )
+ print_help();
+
+ // does the user want us to be nice ... ?
+ boolean be_nice_f = cl.search("--nice");
+
+
+ if( cl.search("--beep", "--piepse", "--bip", "--senal-acustica", "-b") )
+ System.out.println("(imagine a beep - the '\\a' is a invalid escape character in Java)");
+
+ System.out.println( "Program terminated.");
+ if( be_nice_f == true )
+ System.out.println( "Have a nice day.");
+ }
+
+
+ static void print_help() {
+ System.out.println();
+ System.out.println("Example to use search()-functions:\n\n");
+ System.out.println();
+ System.out.println("USAGE:");
+ System.out.println("--do-nothing quit without doing anything.");
+ System.out.println("--nice write a nice phrase on the terminal.");
+ System.out.println("--help, -h, --hilfe, --sos");
+ System.out.println(" get some help about this program.");
+ System.out.println("--beep, -b, --piepse, --bip, --senal-acustica");
+ System.out.println(" get your system to make a beep.");
+ System.out.println( );
+ System.exit(0);
+ }
+}
+
+
+
--- /dev/null
+// -*- java -*-
+// FILE: Ufo.java Version 0.9
+// (C) 2001-2002 Frank R. Schaefer
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//////////////////////////////////////////////////////////////////////////////////////
+
+import GetPot.*;
+import java.lang.String;
+
+
+public class Ufo {
+public static void main(String args []) {
+ GetPot cl = new GetPot(args, "Ufo");
+ String[] ufos = {};
+
+ if( cl.search("-h", "--help") ) {
+ print_help();
+ System.exit(0);
+ }
+ else if( cl.search("--arguments") ) {
+ // (*) unidentified flying arguments ---------------------------------------------
+ ufos = cl.unidentified_arguments(new String[]{"--arguments", "-h", "--help", "yes", "no"});
+ print("Unidentified Arguments (other than '--arguments', '-h', '--help', 'yes', 'no'):\n");
+ }
+ else if( cl.search("--options") ) {
+ // (*) unidentified flying options (starting with '-' or '--') -------------------
+ ufos = cl.unidentified_options(new String[]{"--options", "-h", "--help",
+ "yes(ignored anyway)", "no(ignored anyway)"});
+ print("Unidentified Options (different from '--options', '-h', '--help'):\n");
+ }
+ else if( cl.search("--flags") ) {
+ // (*) unidentified flying flags -------------------------------------------------
+
+ // -- flags in the first argument
+ String ufo_s = cl.unidentified_flags("xzfjct", 1);
+ print("-- Unaccepted flags in argument 1:\n");
+ for(int i=0; i< ufo_s.length() ; i++)
+ print(" '" + ufo_s.charAt(i) + "'\n");
+
+ print("\n Accepted flags: 'x' 'z' 'f' 'j' 'c' 't'\n\n");
+
+ // -- flags in arguments starting with a single '-'
+ ufo_s = cl.unidentified_flags("ltrm");
+ print("-- Unaccepted flags in options (argument with one '-'):\n");
+ for(int k=0; k< ufo_s.length() ; k++)
+ print(" '" + ufo_s.charAt(k) + "'\n");
+
+ print("\n Accepted flags in options: 'l' 't' 'r' 'm'\n");
+ }
+ else if( cl.search("--variables") ) {
+ // (*) unidentified flying variables ---------------------------------------------
+ ufos = cl.unidentified_variables(new String[]{"x", "y", "z", "length", "height"});
+
+ print("Unidentified Variables (other than 'x', 'y', 'z', 'length', 'height'):\n");
+ }
+ else if( cl.search("--sections") ) {
+ // (*) unidentified flying sections ----------------------------------------------
+ GetPot ifile = new GetPot("example.pot");
+ ufos = ifile.unidentified_sections(new String[]{
+ "vehicle/",
+ "vehicle/tires/",
+ "vehicle/chassis/",
+ "vehicle/chassis/doors/",
+ "group/",
+ "other/",
+ "user-variables/",
+ "pseudo-function-calls/"});
+
+ print("Unidentified sections in file 'example.pot':\n");
+ if( ufos.length == 0 )
+ print(" (none) add [..] section labels in file 'example.pot'.\n");
+ }
+ else if( cl.search("--nominuses") ) {
+ // (*) unidentified flying options (starting with '-' or '--') -------------------
+ String tmp[] = new String[2];
+ // -- read two filenames for demonstration purposes
+ tmp[0] = cl.follow("default-in.znf", "-i");
+ tmp[1] = cl.follow("default-out.znf", "-o");
+
+ // -- get any other nominuses not used until now
+ ufos = cl.unidentified_nominuses(tmp);
+
+ print("Unused Nominus Arguments (other than arguments after -i and -o):\n");
+ }
+ else {
+ print_help();
+ System.exit(0);
+ }
+
+ // (*) print out unidentified flying objects
+ for(int i=0; i < ufos.length ; i++)
+ print(" " + ufos[i] + "\n");
+}
+
+
+ static void print_help() {
+ String msg =
+ "USAGE: java Ufo [--help] [--arguments] [--options] [--flags] [--sections] \n" +
+ " [--variables] [--nominuses [-i file] [-o filename]]\n" +
+ " ... any arguments\n" +
+ "\n" +
+ "PURPOSE: \n" +
+ " Testing the GetPot's ability to detect unknown flying objects\n" +
+ " (i.e. un-recognized command line arguments). The type of flying\n" +
+ " object you want to check for is specified through one of the\n" +
+ " following options:\n" +
+ "\n" +
+ " --arguments\n" +
+ " test all arguments against an internal list of possible arguments.\n" +
+ "\n" +
+ " --options\n" +
+ " test all options (arguments starting with at least one '-') against\n" +
+ " an internal list of options.\n" +
+ "\n" +
+ " --flags\n" +
+ " test first argument and all options against internal list of flags\n" +
+ " (i.e. letters in arguments that act as switches)\n" +
+ "\n" +
+ " --sections\n" +
+ " reads the input file 'example.pot' for sections that are\n" +
+ " unidentified. add some sections yourself to test this feature.\n" +
+ "\n" +
+ " --variables\n" +
+ " tests all variables specified on the command line against a list\n" +
+ " of specified variables.\n" +
+ "\n" +
+ " --nominuses\n" +
+ " check for unrecognized nominuses. filenames after -i and -o are\n" +
+ " recognized.\n" +
+ "\n" +
+ " Once you specified your mode add any number of command line\n" +
+ " arguments and watch the output.\n" +
+ "\n" +
+ "EXAMPLES:\n" +
+ " java Ufo yes no -i source.cpp --arguments\n" +
+ "\n" +
+ " java Ufo -i source.cpp --force n=13 -xzt --options\n" +
+ "\n" +
+ " java Ufo zfd if=source.cpp force n=13 -l -zrt -olp --flags\n" +
+ "\n" +
+ " java Ufo zfd x=12 y=234 loength=21 height=21 n=2 --variables\n" +
+ "\n" +
+ " java Ufo --sections # (edit file section labels in example.pot)\n" +
+ "\n" +
+ " java Ufo n=21 -i in.dat -o out.dat /etc/fstab force --nominuses \n" +
+ "\n" +
+ "AUTHOR: (C) 2002 Frank R. Schaefer\n";
+ System.out.print(msg);
+
+ }
+
+ static void print(String Str) {
+ System.out.print(Str);
+ }
+
+}
--- /dev/null
+// -*- java -*-
+// FILE: Variables.java Version 0.9.8
+// (C) 2001 Frank R. Schaefer
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//////////////////////////////////////////////////////////////////////////////////////
+import GetPot.*;
+import java.lang.String;
+
+public class Variables {
+ public static void main(String args []) {
+ GetPot cl = new GetPot(args, "Variables");
+ if( cl.size() == 1 || cl.search("--help", "-h") ) print_help("java Variables");
+
+ if( cl.search("--internal-information", "-i") ) {
+ cl.print(); System.exit(0);
+ }
+ // (2) some variables of each type
+ double A_Number = cl.call("float", 0.);
+ double An_Integer = cl.call("integer", 0);
+ String A_String = cl.call("string", "default");
+
+ double Element1 = cl.call("vector", 0., 0);
+ String Element2 = cl.call("vector", "default", 1);
+ int Element3 = cl.call("vector", 0, 2);
+
+ System.out.println("Specified Parameters:");
+ System.out.println("float = " + A_Number);
+ System.out.println("integer = " + An_Integer);
+ System.out.println("string = " + A_String);
+ System.out.println();
+ System.out.println("Vector elements:");
+ System.out.println("Element 0 (double) = " + Element1);
+ System.out.println("Element 1 (string) = " + Element2);
+ System.out.println("Element 2 (int) = " + Element3);
+ }
+
+ static void print_help(String Application) {
+ System.out.println();
+ System.out.println("Example how to use GetPot to parse variables on the command line.");
+ System.out.println();
+ System.out.println("USAGE:");
+ System.out.println("--help, -h, --hilfe, --sos");
+ System.out.println(" get some help about this program.");
+ System.out.println("--internal-information, -i");
+ System.out.println(" show contents of database that was created by parser.");
+ System.out.println();
+ System.out.println("type a command line like the following:");
+ System.out.println(Application + " string=otto.von.bismarck float=3.14 \\");
+ System.out.println(" integer=41 vector='1.26 something 0x40'");
+ System.out.println();
+ System.out.println("the variables that can be specified are:");
+ System.out.println(" float a double variable");
+ System.out.println(" integer an integer variable");
+ System.out.println(" string a string variable");
+ System.out.println(" vector a mixed type vector:");
+ System.out.println(" element 0 => double ");
+ System.out.println(" element 1 => string");
+ System.out.println(" element 2 => int");
+ System.out.println();
+ }
+}
--- /dev/null
+# -*- getpot -*- GetPot mode activation for emacs
+#
+# Example input file to be parsed by 'GetPot'
+#
+# (C) 2001 Frank R. Schaefer
+# License Terms: GNU LGPL
+############################################################################
+
+# (*) --------------------------------------------------------------------------
+# examples dealing with input file parsing (input-file.py/.cpp/.java etc.)
+#-------------------------------------------------------------------------------
+clicks = 231 # [1/s]
+acceleration = 1.231 # [m/s^2]
+
+[vehicle]
+wheel-base = 2.65 # [m]
+initial-xyz = '100. 0.1 5.0' # [m]
+
+
+ [./tires] # i.e. vehicle/tires/
+ # Coefficients for Pacejka's Magic Formula
+ # Reference: Bakker, Nyborg, Pacejka:
+ # "Modelling for Use in Vehicle Dynamics Studies",
+ # SAE Technical Paper Series 870421, 1988
+ B = 3.7976 # [1]
+ C = 1.25 # [1]
+ E = -0.5 # [1]
+ D = 64322.404 # [N]
+
+ [../chassis] # i.e. vehicle/chassis/
+ Roh = 1.21 # [kg/m^3] density of air
+ S = 5.14 # [m^2] reference surface
+ Cd = 0.45 # [1] air drag coefficient
+
+ [./doors] # i.e. vehicle/chassis/doors/
+ number = 777
+ locks = 'in place'
+
+# back to the root name space
+[]
+webpage = http://getpot.sourceforge.net/index.html
+
+# some words about quotes and backslashes
+# (1) whitespace requires quotes
+user = 'Alfons Haeberle'
+# (2) backslashed quote => quote
+latex-formula = '\\kappa\' = \\frac{d}{d s} \\kappa'
+# (3) double backslash in quotes = backslash
+dos-file = 'C:\\Program Files\\Applications'
+
+# (*) --------------------------------------------------------------------------
+# examples using the prefix filter (filter.py/.cpp/.java etc.)
+#-------------------------------------------------------------------------------
+[group]
+# playing with pseudo command line arguments:
+# note that
+# '-x', '3134' and '--rudimental'
+# will be known as
+# 'flags/-x', 'flags/3234' and 'flags/rudimental'.
+#
+# Therefore 3134, for example, is **NOT** a number as long,
+# as no prefix filter "flags/" is set.
+-x 3134
+--rudimental 12 777
+
+[other]
+# this section will be skipped by the 'next' function when the prefix
+# is set
+nonsense
+
+
+[user-variables]
+# This section contains variables that the user defined himself.
+# The GetPot interpreter uses 'get_variable_names()' in order to
+# get to know their names.
+preview-coefficient = '12 cm'
+lateral-side-distance = '2.1 m/s'
+control-interval = '0.1 s'
+compensation-ratio = '0.4e34 rad/(m*s)'
+
+[pseudo-function-calls]
+# The following code shows how GetPot can be used to emulate
+# trivial function calls. Please, note that no syntax checking
+# can be provided by this method.
+LE-DEBUT
+smiley sad
+new-line 1
+# draw rectangle width = 40, height = 10
+rectangle 40 10
+new-line 1
+smiley happy
+# draw circle radius = 15
+circle 15
+new-line 1
+smiley happy
+new-line 2
+LA-FIN
+
--- /dev/null
+# -*- getpot -*- GetPot mode activation for emacs
+#
+# Example input file to be parsed by 'GetPot':
+#-------------------------------------------------------------------------------
+# PURPOSE:
+# Demonstration of the abilities of the $-Bracket Language in GetPot.
+#
+#
+# (*) STRING OPERATORS:
+#
+# ${string} variable replacement (possibly recursive):
+# replace ${}-expression by content of variable named 'string'.
+#
+# ${:string} pure strings:
+# replace ${}-expression by the string 'string' itself (including
+# whitespace). This becomes important in combination with macro
+# expansion. It allows ${}-expressions inside strings without
+# being parsed directly.
+#
+# ${& string1 string2 string3 ... } concatination:
+# concatinate 'string1', 'string2', 'string3', etc. to one single
+# string whithout any kind of whitespace in between.
+#
+# ${<-> string orginal replacement} replacement:
+# replace all occurences of 'original' in 'string' with 'replacement'
+#
+# (*) ARITHMETIC OPERATORS:
+#
+# ${+ arg1 arg2 arg3 ...} plus:
+# replace ${}-expression by the sum: 'arg1' + 'arg2' + 'arg3' + ...
+#
+# ${* arg1 arg2 arg3 ...} multiplication:
+# replace ${}-expression by the product: 'arg1' * 'arg2' * 'arg3' * ...
+#
+# ${- arg1 arg2 arg3 ...} substraction:
+# replace ${}-expression by: 'arg1' - 'arg2' - 'arg3' - ...
+#
+# ${/ arg1 arg2 arg3 ...} division:
+# replace ${}-expression by: 'arg1' / 'arg2' / 'arg3' / ...
+#
+# (*) COMPARISON OPERATORS:
+#
+# ${== arg0 arg1 arg2 ...} equal:
+# returns the number of the first argument starting with '1' for 'arg1'
+# that is equal to 'arg0'.
+# returns '0' in case none is equal.
+# ${> arg0 arg1 arg2 ...} greater:
+# ${< arg0 arg1 arg2 ...} less:
+# ${>= arg0 arg1 arg2 ...} greater or equal:
+# ${<= arg0 arg1 arg2 ...} less or equal:
+# analogous to ${== }-operator.
+#
+# (*) CONDITIONAL EXPANSION:
+#
+# ${? arg0 if-string else-string} if-then statement:
+# return 'if-string' in case arg0 == 1 and 'else-string' else.
+#
+# ${?? arg0 string1 string 2 string3 ...} choice.
+# return string0 if arg1 == 1, string1 if arg1 == 2, etc.
+#
+# (*) VECTOR/STRING SUBSCRIPTION:
+#
+# ${@: string index} letter:
+# return letter number 'index' in 'string'.
+#
+# ${@: string index1 index2} substrings:
+# return substring in 'string' from 'index1' to 'index2'
+#
+# ${@ variable index} vector element:
+# return element number 'index' in 'variable'
+#
+# ${@ variable index1 index2} sub-vector:
+# return sub-vector in 'variable' from element 'index1' to
+# element 'index2'.
+#
+# (*) MAKRO EXPANSION:
+#
+# ${! variable} expand:
+# replacement ${}-expression by the evaluation of the content of 'variable'.
+# The variable should be defined with a pure string (${: }) so that expressions
+# inside it are not parsed during the assignment.
+#
+# (C) 2002 Frank R. Schaefer
+# License Terms: GNU GPL
+################################################################################
+
+#-------------------------------------------------------------------------------
+# (1) variable replacement -----------------------------------------------------
+#-------------------------------------------------------------------------------
+name = GetPot
+
+[${name}] # meaning: [GetPot]
+address = getpot.sourceforge.net
+[]
+info0 = ${GetPot/address}
+
+[1.2] # advanced variable replacement ------------------------------------------
+[Philosophy]
+ boss = 'Dr. Frederique Mouillard'
+ members = 4
+ professors = 3
+[Mechanical-Engineering]
+ boss = Dr.\ Frieda\ LaBlonde
+ members = 24
+ professors = 5
+
+[]
+x1 = Mechanical-Engineering
+x2 = Philosophy
+[1.2]
+info0 = '${${x1}/boss}: ${${x1}/professors}/${${x1}/members}'
+info1 = '${${x2}/boss}: ${${x2}/professors}/${${x2}/members}'
+
+
+[1.3] # recursive replacements -------------------------------------------------
+# 1.3.1 simple replacements
+car = Citroen-2CV
+ground-vehicle = car
+vehicle = ground-vehicle
+object = vehicle
+# ${object} --> vehicle
+# ${vehicle} --> ground-vehicle
+# ${ground-vehicle} --> car
+# ${car} --> Citroen-2CV
+
+# note that even variable names can be composed of ${ } expressions
+variable = info0
+${variable} = '${${ ${ ${object}}}}'
+
+# 1.3.2 conglomerate variable names
+[Citroen-2CV]
+ [./wheels]
+ [./front]
+ [./right]
+ radius = 30 # [cm]
+
+[1.3]
+part = wheels
+attribute = radius
+position = front/right
+
+variable = info1
+${variable} = '${${${${${object}}}}/${part}/${position}/${attribute}}'
+
+[1.4] # dictionaries -----------------------------------------------------------
+
+[Nicknames]
+ BMW = Beamer
+ Mercedez = Grandpa\'s\ Slide
+ Volkswagen = Beetle
+ Citroen-2CV = Deuche
+[1.4]
+info0 = '${Nicknames/${1.3/info0}}'
+my-car = Mercedez
+info1 = '${Nicknames/${1.4/my-car}}'
+
+#-------------------------------------------------------------------------------
+# (2) string expressions -------------------------------------------------------
+#-------------------------------------------------------------------------------
+[2.1] # pure strings -----------------------------------------------------------
+info0 = ${:even expressions like ${my-car} are left as they are}
+info1 = ${:\\-ing (backslashing) works still the same way}
+info2 = ${:backslashes allow one to have spaces w/o quotes}
+
+[2.2] # concatination ----------------------------------------------------------
+info0 = ${& simple concatination without whitespaces results in a mess}
+info1 = '${& ${:In France, the } ${1.3/info0}
+ ${: is called \'La } ${Nicknames/${1.3/info0}} \'}
+ '
+
+[2.3] # replacement ------------------------------------------------------------
+info0 = 'We spell your name \'${<-> Phillip Ph F}\''
+info1 = 'The ${<-> ${Nicknames/Volkswagen} ee ea}s'
+car = Nicknames/Citroen-2CV
+info2 = 'I switched from ${${car}} to ${${<-> ${car} Citroen-2CV Volkswagen}}'
+
+#-------------------------------------------------------------------------------
+# (3) numeric expressions ------------------------------------------------------
+#-------------------------------------------------------------------------------
+[3.1] # basics -----------------------------------------------------------------
+info0 = ${+ 1 1}
+x = 4699 y = 14 z = 4
+# don't forget to glue the minus sign to negative numbers
+info1 = ${+ ${x} ${y} -2}
+
+info2 = ${- 10 1}
+info3 = ${- ${x} ${y} -2}
+
+info4 = '${* 12 12}'
+info5 = '${* 2 2 ${z}}'
+
+info6 = '${/ 12 6}'
+info7 = '${/ 144 12 3 2}'
+
+[3.2] # power expressions ------------------------------------------------------
+info0 = '${^ 2 16}'
+info1 = '${^ 2 2 2 2}' # ((2^2 = 4)^2 = 16)^2 = 256
+
+
+[3.3] # comparisons ------------------------------------------------------------
+info0 = ${== 1 2}
+info1 = ${== Deuche ${${2.3/car}}}
+info2 = ${== 1.0 1.000}
+info3 = '${>= 3.14 12} but ${>= 3.14 0.0} and ${>= 3.14 3.140000}'
+info4 = '${< 12 3.14} but ${< 3.14 3.141} and ${> Berta Vladimir}'
+info5 = '${> 12 3.14} but ${> 3.14 3.141} and ${> Zeppelin Alberta}'
+
+# which one is right ? ---------------------------------------------------------
+# comparison operator return number of first matching in list
+info6 = 'The real name for 'Deuche' is number ${== Deuche
+ ${Nicknames/Volkswagen}
+ ${Nicknames/Mercedez}
+ ${Nicknames/Citroen-2CV}
+ ${Nicknames/BMW}}'
+
+info7 = 'The first element less than 2 is element number ${> 2 10 1001 3 6 1 9 -10}'
+
+[3.4] # conditions -------------------------------------------------------------
+guess = Citroen-2CV
+info0 = 'Your guess was ${? ${== Citroen-2CV ${guess}} right wrong}'
+x = 12 y = 14
+info1 = 'x (=${x}) is ${?${> ${x} ${y}} greater less} than y (=${y})'
+[msg]
+english = 'Star Wars'
+francais = 'La Guerre des Etoiles'
+espagnol = 'Las Guerras De la Estrella'
+italiano = 'Le Guerre Della Stella'
+deutsch = 'Krieg der Beruehmten'
+portugues = 'As Guerras Da Estrela'
+
+[3.4] # choices
+domain = .fr
+info2 = '${?? ${== ${domain} .de .uk .fr .es .it .pt}
+ ${msg/deutsch}
+ ${msg/english}
+ ${msg/francais}
+ ${msg/espagnol}
+ ${msg/italiano}
+ ${msg/portugues}}'
+
+[3.5] # vector/string subscription ---------------------------------------------
+# (note, that '-1' stands for end of array)
+# string subscription ${@:
+info0 = '${@: Wasserkraftwerkinstallationsunternehmenspruefstelle 6 10}'
+info1 = '${@: Wasserkraftwerkinstallationsunternehmenspruefstelle 4}'
+info2 = '${@: Wasserkraftwerkinstallationsunternehmenspruefstelle 40 -1}'
+info3 = '${@: Wasserkraftwerkinstallationsunternehmenspruefstelle 0 5}'
+
+my-vector = 'Cordoba Madrid Buenos-Aires Kairo Moskow Heidelberg
+ Grenoble Marseille Disneyland'
+
+# vector subscription ${@:
+info4 = ${@ my-vector 4 -1} # element 4 until end
+info5 = ${@ info4 3 4} # element 3 and 4
+info6 = ${@ info4 0 3} # element 0 until 3 (3 included)
+info7 = ${@ info4 4} # element 4
+
+
+[3.6] # macro evalutation ------------------------------------------------------
+# Note that the accuracy is horrible :-) !
+# approximation of a sinus (defined as a pure string):
+# sin(x) = x -1/6 x^3 + 1/120 x^5 -1/5400 x^7 ....
+x2 = ${: ${* ${x} ${x}}}
+x4 = ${: ${* ${!x2} ${!x2}}}
+x6 = ${: ${* ${!x4} ${!x2}}}
+sin = ${: ${* ${x}
+ ${+ 1
+ ${/ ${!x2} -6}
+ ${/ ${!x4} 120}
+ ${/ ${!x6} -5040}
+ }
+ }
+ }
+
+convert = ${/ 3.14 180.0} # [degree] -> [rad]
+
+x = ${* 30 ${convert}}
+info0 = ${!sin}
+
+x = ${* 60 ${convert}}
+info1 = ${!sin}
+