#include <simtools.h> // initSwarmArguments
#include <defobj.h>
#include <defobj/Arguments.h>
#include <misc.h> // atoi, strdup

@interface MyArguments: Arguments_c
{
  int foobar;
  char *gnorkGnork;
}
@end

@implementation MyArguments
+ createBegin: aZone
{
  MyArguments * args = [super createBegin: aZone];
  
  [args addOption: "foobar" key: 'X' arg: "value" flags: 0
	doc: "the important foobar value"
	group: 100];
  [args addOption: "gnorkgnork" key: 'Y' arg: "value" flags: 0
	doc: "the less crucial gnorkgnork value"
	group: 101];

  args->foobar = 10;
  args->gnorkGnork= "WHATEVER";

  return args;
}

- (int)parseKey: (int)key arg: (const char *)arg
{
  if (key == 'X') {
    foobar = atoi (arg);
    return 0;
  } else if (key == 'Y') { 
    gnorkGnork = strdup (arg);
    return 0;
  }
  else
    return [super parseKey: key arg: arg];
}


- (void)saveParameters: (char*)aString
{
  char dataArchiveName[strlen (aString + 4 + 1)];
  id dataArchiver;

  sprintf (dataArchiveName,"%s.scm", aString);
  printf ("saving to `%s'\n", dataArchiveName);
  dataArchiver = [LispArchiver create: [self getZone] 
			       setPath: dataArchiveName];

  [dataArchiver putShallow: "parameters" object: self];
  [dataArchiver sync];
  [dataArchiver drop];
}


@end

int
main (int argc, const char **argv)
{
  initSwarmArguments (argc, argv, [MyArguments class]);
  [(id) arguments saveParameters: "myFile"];
  return 0;
}

/*
Local Variables: 
compile-command: "gcc -D_GNU_SOURCE -DBUGADDRESS=marcus@snoutfarm.com -g -I/usr/include/swarm -L/usr/lib/swarm -Wl,-rpath,/usr/lib/swarm ArgumentsLispSave.m -lswarm -lobjc"
End:
*/
