The programming organization of the Opihi shell is such that it is trivial to add new C-level commands to Mana. Every command is a simple file which looks like a stand-along C main () program. There are a small number of globally accessible variables and simple library commands (APIs) to access the data mana knows about, such as vectors, images, or scalar variables. For example, here is the code for the create command:
# include "opihi.h"
int create (argc, argv)
int argc;
char **argv;
{
int i;
int Nvec;
double start, end, delta;
if ((argc != 5) && (argc != 4)) {
fprintf (stderr, "USAGE: create vector start end [delta]\n");
return (FALSE);
}
if (!SelectVector (&Nvec, argv[1], ANYVECTOR))
return (FALSE);
start = atof (argv[2]);
end = atof (argv[3]);
if (argc == 5)
delta = atof (argv[4]);
else
delta = 1;
if ((start == end) && (delta == 0)) {
fprintf (stderr, "error in value: %f to %f, %f\n", start, end, delta);
return (FALSE);
}
delta = fabs (delta);
if (end - start < 0) {
delta = -1.0 * delta;
}
vectors[Nvec].Nelements = (end - start) / delta + 1;
REALLOCATE (vectors[Nvec].elements, float, vectors[Nvec].Nelements);
for (i = 0; i < vectors[Nvec].Nelements; i++) {
vectors[Nvec].elements[i] = start + i*delta;
}
return (TRUE);
}
The would-be programmer simply creates a file with the command of interest, adds the file to the Makefile, and adds the command to a particular include file in a simple format. Only one routine in addition to the newly created routine needs to be recompiled, so compilation time is very quick. This ease of programming makes Mana particularly suited to the open-source model: we are essentially inviting users to add their own, interesting functions to the functionality of Mana by making it trivial.