swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Argument passing to swarm (equal sign puzzle)


From: Paul E. Johnson
Subject: Argument passing to swarm (equal sign puzzle)
Date: Fri, 04 Dec 1998 16:04:16 -0600

I got curious to play around with processing of command line parameters.
So I decided to take heatbugs and pass in the number of bugs in the
simulation from the command line.  I think I have this working now, but
I've bumped up against one little problem.  Once I clear this up, I'll
post the code so our students can see a concrete example of this.

The command that works to transfer in the number of bugs is this:
   ./heatbugs -n137
However, when I do 
    ./heatbugs --help
I see this:
  -s, --varyseed             Run with a random seed
  -b, --batch                Run in batch mode
  -m, --mode=MODE            Specify mode of use (for archiving)
  -n, --numBugs=NUMBUGS      Set numBugs
  -t, --show-current-time    Show current time in control panel

This makes me think that the command line ought to be 
    ./heatbugs -n=137
However, this does not work, because the argument processing thinks that
the parameter string is "=137" and the atoi function does not work on it
(because of the equal sign being treated as part of the parameter). It
seems to me this is may be a general problem,or at least an ambiguity in
the docs distributed for Arguments.

The parameter managing class in this example is called HeatArgs (I could
not stand MySwarmArguments!). Here are the files:

-----------------------------------------
HeatArg.h:

#import <objectbase/Arguments.h>
@interface HeatArgs: Arguments
 {
   const char *numBugsArg;
 }
- (int)getNumBugsArg;
@end
-----------------------------------------
HeatArg.m:

#import "HeatArgs.h" 
#import <stdlib.h>

@implementation HeatArgs

 + createBegin: aZone
 {
   static struct argp_option options[] = {
     {"numBugs", 'n', "NUMBUGS", 0, "Set numBugs", 3},
     { 0 }
   };
   
   HeatArgs *obj = [super createBegin: aZone];

   [obj addOptions: options];
   return obj;
 }

 - (int)parseKey: (int)key arg: (const char*)arg
 {


    if (key == 'n')
     {
       numBugsArg =  arg ;

       return 0;
     }
   else
     return [super parseKey: key arg: arg];
 }

- (int)getNumBugsArg
{   
  int numbugs;
  numbugs=atoi( numBugsArg );

  return numbugs;
}

 @end





-- 
Paul E. Johnson                         email: address@hidden
Dept. of Political Science     http://lark.cc.ukans.edu/~pauljohn
University of Kansas                       Office: (785) 864-9086
Lawrence, Kansas 66045                        FAX: (785) 864-5700

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]