/*MGD Dec. 1, 2001

 To use it, uninstall Swarm
2.1.1 or at least ensure that mounts to Swarm 2.1.1 things have been
removed, e.g. /bin.  Then install the latest Cygwin package and untar the
package above, making a /Swarm-2.2 mount to where you untarred it.
Finally, grab and gunzip the newer DLLs, copying them to /Swarm-2.2/bin and
copy the gunzipped swarm.jar.gz to /Swarm-2.2/share/swarm.
*/
import swarm.Globals;
import swarm.SwarmEnvironmentC;
import swarm.SwarmEnvironmentCImpl;
import swarm.SwarmEnvironmentImpl;
import swarm.defobj.Arguments;
import swarm.defobj.ArgumentsC;
import swarm.defobj.ArgumentsCImpl;
import swarm.defobj.ArgumentsImpl;
import swarm.defobj.Zone;

class MyArgumentsCImpl extends ArgumentsCImpl {
  MyArgumentsCImpl (Arguments arg) {
    super (arg);
  }
  
  public Object setArgc$Argv (int argc, String argv[]) {
    return super.setArgc$Argv (argc, argv);
  }
 
  public int parseKey$arg (int key, String arg) {
    if (super.parseKey$arg (key, arg) != 0) {
      if (key == (int) 'M') {
        ((MyArgumentsImpl) nextPhase).arg = arg;
      }
    }  
    return 0;
  }
}

class MyArgumentsImpl extends ArgumentsImpl {
  String arg;

  MyArgumentsImpl () {
    super ();
  }
}


public class TestArguments {
  public static void main (String args[]) {
    Zone aZone = Globals.env.globalZone;
    
    ArgumentsC argumentsC = new MyArgumentsCImpl (new MyArgumentsImpl ());
    MyArgumentsImpl arguments;

    int i, len = args.length;
    String argv[] = new String[1 + len];

    argv[0] = "TestArguments";

    for (i = 0; i < len; i++)
      argv[1 + i] = args[i];

    argumentsC.createBegin (aZone);
    argumentsC.setAppName (argv[0]);
    argumentsC.setArgc$Argv (len + 1, argv);
    argumentsC.setAppModeString ("default");
    argumentsC.setBugAddress ("bug-swarm@swarm.org");
    argumentsC.setVersion ("0.0");
      
    argumentsC.addOption$key$arg$flags$doc$group ("myarg", (int) 'M', "argvalue", 0, "My Argument", 0);
    arguments = (MyArgumentsImpl) argumentsC.createEnd ();

    Globals.envC.setArguments (arguments);
    Globals.envC.createEnd ();
    
    System.out.println (arguments.arg);
  }
}


