pupa-devel
[Top][All Lists]
Advanced

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

Re: Argument parser


From: Marco Gerards
Subject: Re: Argument parser
Date: 14 Dec 2003 02:14:24 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Hi,

"Yoshinori K. Okuji" <address@hidden> writes:

> > I had nothing in mind, I just added it for completeness.  I can
> > remove this one.
> 
> Then, it is better to remove it. If you find any situation where 
> ARG_TYPE_CHAR could be useful, you can re-add it later.

Ok.

[...]

> > > Can you tell me how to get normal arguments?
> >
> > In the example the `option_parser' function will be called with as
> > key `PUPA_KEY_ARG' and the argument in ARG.
> 
> Isn't it difficult? For example, if you define a command which takes two 
> essential arguments, how do you implement this command with your 
> parser?

In the structure that is used to store the state of the parser you
have to include a counter, for example:

struct ls_arguments
{
  int longlist;
  int human;
  int all;
  char *dir;
  int count;
};

[...]

> > With my parser "ls -a foo -l" works perfectly.  Actually it is not
> > hard at all to make it GCS complaint.
> 
> It is easy until you start implementing the real function of ls. This is 
> the same question above, but how do you separate an option parser from 
> the real function completely? Using a linked list to store arguments?

Possibly.  The function will be called for every argument.  If you
would like to see an example I can write one.  Perhaps it is easier to
discuss code here so we both are talking about the exact same thing. :)

> > I assume I have some freedom here.  You can have a look at my patches
> > and we can discuss them if you'd like a command or not.
> 
> Exactly. But I prefer dicussing what should be implemented before you 
> start implementing things, so that you don't lose your time 
> unnecessarily.

Ok, I will send a mail about this later.

> > I thought about this too.  I actually wrote some generic code to do
> > this today.  With my code you can put the pager on and off.  It is
> > easy to change this so it works like GRUB.  I didn't know about this
> > feature because I'm still using GRUB 0.90 :(.
> 
> Please take a try with the latest. 0.90 is too old.

I will.

> > I have chosen to use "-?" as the short version of "--help" because
> > all programs that use argp, of which many GNU programs I guess, have
> > that as the short option too.  The reason to use "-h" for ls is that
> > this is what users might expect because the GNU version of ls works
> > the same way.
> 
> Ummh, you are right, ls uses -h for another purpose. But I don't think 
> this is so good.

Why don't you like it?  The '-?' short option is already used by other
GNU programs too, I don't remember GNU programs using '-h' for help,
more often '-h' is used for other purposes.  AFAIK --help doesn't even
have a short option.

> > What is the advantage of such scripting language?  What kind of
> > problems can be solved using such language?  Please let me know if
> > you know what you want to do.
> 
> That's the same question as RMS asked me.

*G*

[...]

> For example, there is a wish that you can "rotate" the default boot 
> entry. I think it would be even difficult for most people to just 
> understand why it is useful. Implementing this feature is quite easy, 
> but I don't think it is worth doing that in the official source code.

This means that it should be possible for PUPA to store stuff on
disk.  This should not be hard to do, but this is something we need to
discuss.  The best thing to me seems pre-allocating some blocks on
disk (by using a file of course) and reading and writing to this file.

[...]

> Another reason is portability. Writing portable C code is a nightmare.

True.

> If you want to see more details, see the archive of bug-grub. But I 
> guess you know how a scripting language is useful, as you understand 
> variables are useful. Variables are a feature required for a scripting 
> language, aren't them? If you think variables are useful, why not 
> conditionals? Don't you think this kind of code would be nice:

I will have a look at the mailinglist archives.  Variables should not
be hard to do (I've already added support to set, show and unset
variables in PUPA ;)).

> if test $TERM = serial; then
>   extra_args="console=ttyS1"
> else
>   extra_args=""
> fi
> 
> linux /boot/vmlinuz root=/dev/hda1 ro $extra_args
> boot

Oh, this looks nice.

> By a scripting language, I don't mean a feature-rich language, like 
> Python or Scheme. In a past discussion, Gordon preferred a meta 
> language, but I myself prefer a simple and small language, such as Lua, 
> Forth, or Bourne shell. :)

A bourne shell like language seems nice to me (especially because
people don't have to learn a new scripting language).  Forth usually
gives me a headache but I must admit I did not really try to write
something useful using forth.

Thanks,
Marco





reply via email to

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