From 2 to 1 executable

I remember the accounting lady creating the indexes: from the main menu select Utility, then from the Utility menu, select Rebuild indexes and from a pop-up menu (aChoice) select the index to be recreated and finally confirm pressing a F key. The process was streamlined: I never noticed that when the lady selected Utility from the main menu, the program actually exited and a new one was loaded. The nested menus appeared without issues, and pressing exit you could go back, with the menus clearing itself and then going back to main menu executable.

I now partly understand the complex menu code: part of it is to handle screen coherency. Merging all the different programs into one should allow to simplify that code, if I will see fit.

Let’s have a look at the code of the main menu. When the user selects to open the Utility menu, an errorlevel is set and program exits. Looking at the batch file and tracing that errorlevel, I saw that it starts uti.exe. Obviously there is a uti.lnk file, a uti.prg file and several utiXX.prg files.

Uti.prg has some startup code that is a reduced version of that of the main menu source. Infact it skips some checks due to the fact that is a program that should not be called directly, but it is called with the proper working directory set. It also sets some hotkeys (SET KET), loads some default values, etc. I converted all these function calls and commands to remarks.

Uti.prg contains the Utility menu, that has about a dozen options. Some of them work on archiving data (backups, conversions from/to other programs, creating new workareas), others work on screen configuration (fonts, colors) and finally one opens the list of files that can be indexes.

I decided to disable all the options except the index one: I don’t even know if the other options are used!

So I included the following lines into exe01.hbp:

# Utility menu
src/uti
# Reindex
src/uti04

I then modified the main menu code to call uti() function and not setting errorlevel and exiting. Since the menus use ondo() that has the function names as strings, the program compiled and linked without problems.

The missing and unknown function I talked about here was used in the indexing code and I was a bit worried about it. It is used to create indexes in data root dir if the dbf file is present there and not in the subdir. The program runs correctly and the indexes are created. I didn’t check if the indexes are created in the proper directory – I’m satisfied that they are created.

Merging this code was quite easy:
– located the files to be compiled and added them to exe01.hbp
– removed all the init functions in uti.prg
– added call to uti.prg in main menu

There were a couple of issues that needed to be solved. First of all, the screen. The program didn’t remove the Utility menu when exiting: it was main menu job to refresh the screen and simulate keypresses to show the exact menu when starting, depending on the passed parameter. A lot of code full of K_DOWN, ESC, K_RIGTH that is just waiting to be removed when port completed.
Anyway, I just added a pair of saveScreen/restScreen to uti.prg. It was quick but also, perhaps, not the best choice. Perhaps adding this logic to main menu program will solve this problem for all the future imported functions.

I then did a couple of minor changes to the code. Moving all variables to local and modify some variables to fixed size arrays to variable size, filled with aAdd.
The changes were minimal, and probably a waste of time, but I wanted to go deeper into the code. I will probably refactor the code in the future because I want to add the option to rebuild all the indexes at the same time, and not only one by one: now for each index I have to press 3 keys…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>