ratpoison-devel
[Top][All Lists]
Advanced

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

[RP] Generic argument parsing & stuff


From: Gergely Nagy
Subject: [RP] Generic argument parsing & stuff
Date: Fri Sep 14 09:03:02 2001
User-agent: Mutt/1.3.20i

Greetings!

Well, I'm currently converting the ratpoison commands to the new
argument parsing scheme, and while there, I'm unifying the user
interface.

So, we have two new functions:

*) parse_cmdline, which splits the commandline into the specified number
of chunks

*) collect_input, which first looks at the arguments supplied by
parse_cmdline, then if there is not enough paramaters, then either
displays an input bar (when in interactive mode), or reports a warning
(when in non-interactive mode).

At the moment, the patch is too fuzzy, and not really elegant. I'll
try to finish it this weekend (sunday mostly, as I won't be home on
saturday).

So please, do not make fundamental changes to src/actions.c or
src/actions.h now. I don't want to port my patches to a completely
different codebase.

Umm.. did I mention what I'm currently doing? I guess I didn't.

I modified the user_command struct, so it has three new members:
input_prompt, max_args, min_args. The last two are ints, the first is
passed to parse_cmdline (called by command from src/actions.c), the
second is used to determine if we should ask for more input, if the
number of arguments is less than this. We'll see how it turns out, and
if it's useful or not. The first one (input_prompt) is a string, and
is used by collect_input.

The prototype of each command looks like this:
char * cmd_foo (int interactive, rp_args *args)

When a command is requested, the command function in actions.c gets
control, and does the following:

*) calls parse_cmdline, to parse its input
*) looks up args->argv[0] in user_commands
*) if it has less arguments than min_args, then calls collect_input
*) launches uc->func (interactive, args)
*) cleans up after itself

collect_input looks like this:
rp_args * collect_input (int interactive, char *prompt,
                         char *current_input, rp_args *args)

If in non-interactive mode, it simply returns args. In interactive
mode, it displays an input box, with current_input in it (command's
data), or prompt, if it isn't NULL, and loops 'till it has enough
input, or the user aborted with C-g, in which case, it behaves as if
it were in non-interactive mode.

This ensures that when the command is called, it has at least min_args
arguments, so we don't need to check it in each cmd_* function.

And of course, as I mentioned in one of my previous mails, I'm trying
to minimise code duplication, therefore I'm merging some commands into
common handlers.

All in all, I'm probably doing a rewrite of actions.c :)

TIA,
-- 
Gergely Nagy \ mhp/|8]

Attachment: pgpqoUtbcIQ8d.pgp
Description: PGP signature


reply via email to

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