next up previous contents index
Next: Objects and structures Up: Commands Previous: Introduction   Contents   Index


Structure of commands

A function that may be used as a command must be written in the following way :

int
func_name(int argc, char *argv[])
{
.
.
.
return 0
}

where func_name is the name of the function. It does not matter if the function returns something else than 0, because the interpreter does not use the returned value. But I use to return 0 if the command executed succesfully and 1 otherwise. This may be used in a future version of the interpreter.

In the preceeding function the integer argc is the number of arguments of the command (including the name of the command). The arguments of the command are contained in the array argv[]. So argv[0] is the name of the command (it is usually not useful, except if a function corresponds to distinct command names). The other arguments of the command are argv[1],...,argv[argc-1].

Some functions of the library can be used to parse numeric arguments (cf. 7) and objects or structure names (cf. 6).

It is also possible to recover the flow_data structure corresponding to the thread from which the command was given (cf. 10). It's address is argv[-1]. So if we need the flow_data structure inside the command we can do

    flow_data    *flow_interp;

    flow_interp = (flow_data *) argv[-1];

To be considered as a command the name of the preceeding function must be put in a list of functions corresponding to commands. Such a list is an array that has the following form :

pfi             proc_list1[] =
{
func_name1,
func_name2,
.
.
};

It corresponds to a section !func in an initialization file. Each command name in this section will correspond to a function in the list, in the same order. There can be several !func sections in an initialization file, and there must be corresponding lists. The set of these lists must be declared somewhere in the program (for instance in main.c) in the globally defined array proc

pfi *proc[] = 
{
    proc_list1,
    proc_list2,
    .
    .
};

Here the order of the lists in proc must be the same as the order of the !func sections that will be read in the initialization file.


next up previous contents index
Next: Objects and structures Up: Commands Previous: Introduction   Contents   Index
2009-11-12