Weird parsing error message from AimsApplication

AIMS library and commands usage

Moderators: denghien, riviere

Post Reply
User avatar
oink
Posts: 4
Joined: Tue May 17, 2005 1:56 pm
Location: CEA, Orsay, France

Weird parsing error message from AimsApplication

Post by oink »

When compiling the following code:

Code: Select all

#include <aims/getopt/getopt2.h>
#include <aims/data/data_g.h>
#include <aims/io/io_g.h>
using namespace aims;
using namespace carto;
using namespace std;
int main(int argc, const char **argv)
{
  try
  {
    int n;
    AimsApplication application( argc, argv, "weird" );
    application.addOption( n, "-n", "an integer" );
    application.initialize(); 
  }
  catch( user_interruption &e ) {}
  catch( std::exception &e ) { cerr << argv[ 0 ] << ": " << e.what() << endl; } 
  return 0;
}
and calling it with a wrong input argument name, I get the following weird error message:

Code: Select all

% bin/AimsTemplate -m 3 -n 3
bin/AimsTemplate: -m is no a valid integer
What's more, I get the error only if the faulty parameter appears before all expected input arguments are parsed -- in the example above, no error is given if -m is set after -n. I did not fully investigate the problem, but it seems to me that the error stems from using plain type arguments -- in any case, the error message is different when Reader's are involved.

Pascal
User avatar
riviere
Site Admin
Posts: 1361
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Post by riviere »

Hi,

Well, this behaviour is "normal" since commandline args are ambiguous: switches names are optional in Aims: for instance "AimsFileConvert -i toto.ima -o tutu.ima" is equivalent to "AimsFileConvert toto.ima tutu.ima"
For this reason, the unknown switch "-m" has been understood as the value of the first (omitted) -n switch, of expected type int, hence the error message. The parser understood it as if you had typed "AimsTemplate -n -m 3 -n 3"
Of course it could be even more clever and see that the -n switch is actually present after this argument, but parsing is done as a forward process only, so this cannot be detected at the moment.

Denis
Post Reply