Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] Re: [RFC PATCH] init_techs
Home

[Freeciv-Dev] Re: [RFC PATCH] init_techs

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Justin Moore <justin@xxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [RFC PATCH] init_techs
From: Arien Malec <arien_malec@xxxxxxxxx>
Date: Sat, 22 Sep 2001 21:31:35 -0700 (PDT)

--- Justin Moore <justin@xxxxxxxxxxx> wrote:
>    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).

Arien

__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger. 
http://im.yahoo.com


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