[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Argument parser
From: |
Yoshinori K. Okuji |
Subject: |
Re: Argument parser |
Date: |
Sun, 7 Dec 2003 23:13:06 +0100 |
User-agent: |
KMail/1.5 |
Some random ideas about your code:
* What is ARG_TYPE_CHAR? In what case would it be useful?
* ARG_TYPE_INT uses strtoul... It sounds odd, because I myself think
of _signed_ int when seeing just "int".
* It seems not to support concatenating multiple single-character
options (e.g. "-zxvf").
* Does it support normal arguments, like the "foobar" in "ls foobar"?
* shortarg should have the type int instead of char.
Also, I'd like to suggest an additional idea. Basically, my goal is to
reduce code which must be written for each command. So your parser
should be integrated with the command-line engine fully, so that your
parser is invoked automatically by the engine, instead of calling your
parser explicitly from a function of each command.
For example, you can extend the pupa_register_command to accept
information on options of a registered command. Then, probably it is
also necessary to change the arguments to a callback function for a
command.
Please see this psuedo code:
static struct pupa_option_information =
{
// The default is 1.
{ 'c', "count", "1", "Specify how many times ...", PUPA_TYPE_UINT },
{ 0 }
}
options;
pupa_cmd_hello(opts, args)
{
// 1 is the default value.
count = pupa_atoi(pupa_parser_get_option (opts, 'c'));
// Say it now!
while (count-- > 0)
pupa_printf ("Hello World\n");
}
init()
{
pupa_register_command ("hello", pupa_cmd_hello, &options);
}
I'm sorry that I didn't reply very soon. In my town, we had a big
festival, so I was enjoying with another thing (I was about dying
actually, though.)
Okuji
- Argument parser, Marco Gerards, 2003/12/05
- Re: Argument parser,
Yoshinori K. Okuji <=
- Re: Argument parser, Marco Gerards, 2003/12/07
- Re: Argument parser, Yoshinori K. Okuji, 2003/12/08
- Re: Argument parser, Marco Gerards, 2003/12/08
- Re: Argument parser, Yoshinori K. Okuji, 2003/12/13
- Re: Argument parser, Marco Gerards, 2003/12/13
- Re: Argument parser, Yoshinori K. Okuji, 2003/12/15
- Re: Argument parser, Marco Gerards, 2003/12/15
- Re: Argument parser, Yoshinori K. Okuji, 2003/12/15
- Re: Argument parser, Marco Gerards, 2003/12/15
- Re: Argument parser, Yoshinori K. Okuji, 2003/12/15