Commands

4.1 Introduction

With the command interpreter it is possible to write functions, associate them with command names, in such a way that the function will be called when the command name is entered. These command can need arguments. In fact for the user of a program written with the command interpeter it is not possible to distinguish commands and programs. The library contains a set of functions that can be used as commands. Some other functions of the library can also be used to parse arguments of commands.
 
 


4.2 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. section  6) and objects or structure names (cf. section 5).

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  of the 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 all these lists must be defined somewhere in the program (for example 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.
 


Main page
Chapters   1   2   3   4   5   6   7   8    9    10   11