[Freeciv-Dev] Re: [RFC PATCH] init_techs
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
> > If the command they entered was invalid, tell them so. The command
> > struct could easily be modified to facilitate a change by associating a
> > function pointer with it. Thus:
> >
> > typedef void (*command_func)(char *args);
> >
> > struct command {
> > char *name; /* name - will be matched by unique prefix */
> > enum cmdlevel_id level; /* access level required to use the command */
> > char *synopsis; /* one or few-line summary of usage */
> > char *short_help; /* one line (about 70 chars) description */
> > char *extra_help; /* extra help information; will be line-wrapped
> > */
> > command_func *fptr; /* Pointer to a callback function */
> > };
>
> To allow functions that take a list, the command should have a content model:
>
> enum command_content {
> CMD_STR,
> CMD_INT,
> CMD_STR_LIST,
> CMD_INT_LIST
> };
>
> Or something. Otherwise the callback functions have to typecheck their
> arguments. If the parsing code typechecks, the callback functions can be:
>
> typedef void (*int_command_func) (int);
> typedef void (*str_command_func) (char *);
> typedef void (*int_list_command_func) (int, int *);
> typedef void (*str_list_command_func) (int, char **);
>
> (For the list callbacks, the first function is the size of the list).
Why? Just pass everything that wasn't the command to the function.
The overall framework doesn't need to know what each function takes. Fx:
/set xsize 80
^^^ ^^^^^^^^
/set attribute nation.Greek.techs Alphabet,Iron Working
^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/easy
^^^^
/hard Caesar
^^^^ ^^^^^^
The first part in each of these is the command. The second part is the
"char *arg" that gets passed to the function. These callbacks should be
content-oblivious, and it should be up to the specific functions to
interpret the data correctly.
-jdm
"You don't give blood then take it back again
We're all deserving of something more"
- "Grievance"
Department of Computer Science, Duke University, Durham, NC 27708-0129
Email: justin@xxxxxxxxxxx
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), (continued)
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Raimar Falke, 2001/09/28
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/28
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Raimar Falke, 2001/09/30
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/30
- [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs), Ross W. Wetmore, 2001/09/25
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Arien Malec, 2001/09/22
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Arien Malec, 2001/09/22
- [Freeciv-Dev] Re: [RFC PATCH] init_techs,
Justin Moore <=
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Daniel L Speyer, 2001/09/23
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Arien Malec, 2001/09/23
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Justin Moore, 2001/09/24
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Arien Malec, 2001/09/23
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Justin Moore, 2001/09/24
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Raimar Falke, 2001/09/24
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Justin Moore, 2001/09/24
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Reinier Post, 2001/09/24
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Daniel L Speyer, 2001/09/24
- [Freeciv-Dev] Re: [RFC PATCH] init_techs, Raimar Falke, 2001/09/24
|
|