May 25, 2019

Grinder - menu system internals

When you type "oven" you get the text menu interface to the oven software. This is implemented via HOVEN (aka hoven_) in src/hoven.c -- which calls init_menus() and do_menus().

This file also has OOVEN, which seems to be an unused stub or prototype, but if we comment it out we get build errors, so it is referenced by something somewhere that is not obvious. Whatever the case, what we want is HOVEN.

The function init_menus() is in init.c and calls menus(), which is in menusm/menus.c. The function do_menus() is in domenus.c.

The menu system is a complex entity specified by a multitude of tables in a number of directories. Understanding the way the code is built is one thing. Understanding how to use the system is the other.

The key thing to remember in using it is that you use the arrow keys to navigate. Up and down make perfect sense, but the left and right keys do the opposite of what most people seem to expect:

It is not a source of confusion when using the system, but the top thing on the screen is not something you can select, it is the title for the submenu being shown to you (I would set it off some way like I do here):

-- Oven Main Menu
Exit
Configuration and Status
Error Log
Database
This top level menu have 4 choices it offers you. Use the up/down arrow keys to select one, then the left arrow to execute it.

Notice that a selection being offered you may be either an action (like "Exit" is here) or another menu with more selections. It is too bad that is not made clear in some way, but it all becomes clear enough with experience and context.

Where is this main menu defined in the source?

Maybe if we figure this out, other things will become clear. We search for the string "Oven Main Menu" and find this in the file menus/aa, which looks like this:
Oven Main Menu
Exit                          %ex      $
Configuration and Status      %cs      $
Error Log                     %er      $
Database                      %db      $
This is some kind of metalanguage. The notation %cs takes us to a file menus/cs that has the configuration and status menu. The notation %ex has no corresponding file in the menus directory, so it must be an action that is defined somewhere.

There are 5 directories with "menu stuff" in them.

drwxr-xr-x 2 irafdude irafdude 4096 Jun 26  2012 menus
drwxr-xr-x 2 irafdude irafdude 4096 Jan 19  2018 menusc
drwxr-xr-x 2 irafdude irafdude 4096 Jun 26  2012 menusk
drwxr-xr-x 2 irafdude irafdude 4096 Jan 19  2018 menusm
drwxr-xr-x 2 irafdude irafdude 4096 Jan 19  2018 menust
The directory "menusk" contains the makemenus.c program, and it is only 152 lines, so we stand a good chance of figuring it out. It is passed the list of names in menus/* as an argument list and generates: The directory "menusc" contains one C file per file in the menus directory and does not appear to be machine generated.

If we could understand what routines get called for the various entries in the database submenu, it would be instructive. The "db" file looks like this.

Database
Read  parameters from disk    %rf      $
Write parameters to   disk    %wf      $
Read  parameters from oven    %ro      $
Write parameters to   oven    %wo      $
Read  data       from oven    %rd      $
Read  errors     from oven    %re      $
Write parameters to   text    %wt      $
Read  parameters from text    %rt      $
If we look at menusc/db.c, we see a list of routines, the first of which looks like:
dbrfg ()
{
        int     t = 0;

        if (globalp->readonly)
            return (GOER_NOEDITP);
        db_bpread_disk ();
        t = GOER_EXECUTED;
        return (t);
}
There may be a pattern to this name "dbrfg" -- "db" is the menu name and "rf" is the code in the menu definition file. The letter "g" ends every function in this file, and seems to simply indicate a function that is the handler for some entry in a menu definition file.

This is certainly helpful and is enough to help us track down what functions get called when a given menu entry gets invoked.


Have any comments? Questions? Drop me a line!

Tom's home page / tom@mmto.org