Development Tools


The UI2 Code Generator

Paul Combellick


Paul Combellick has a BS in Petroleum Engineering from the University of Alaska, Fairbanks. He is a contract programmer specializing in dBASE and C local area network (LAN) database applications and can be reached at (602) 280-2569 or via Compuserve at 70671,3054.

As a Network DBMS applications developer, I recently undertook my first major C project. After having scoffed at UI2 for several months, I decided to give it a try as a fast prototyping tool. The resulting productivity gains exceeded my most optimistic expectations. I was able to produce about fifty percent of the 20,000 lines of C code in this application using UI2.

I used UI2 with Vermont Views Screen library and Btrieve Record Manager to build a Network DBMS application. As I was new to all three tools, I spent a third of project time learning the new tools, with the remaining weeks actually producing generated and hand-written code.

By the time I completed this single DBMS application, I had produced a set of templates and template libraries, using UI2 terminology, that would allow me to produce the next Network DBMS application in a few weeks, rather than in months if the code were entirely written by hand.

Description Of UI2

UI Programmer Version Two, The Developer's Release, by Wallsoft is a programmable code generator targeted toward dBASE programmers, but is flexible enough to be used for many languages in the MS/PC-DOS environment including C. UI2 contains four major components.

UI2 is shipped with a set of templates and template function libraries for dBASE programmers. The C programmer will have to create his own templates before any non-trivial C code, other than simple menus, can be generated.

Case Study

For this application the client specified C for portability to OS/2 and UNIX. The target system is a Novell Network which supports the Btrieve database server. Btrieve also has versions for OS/2 and Intel-based PCs running UNIX. I chose Vermont Views screen library for its portability to UNIX and OS/2. This networked DBMS application contains several types of screen input/output: menu-only screens, data entry-only screens, combined menu and data entry screens, and reports.

I created three templates, one for each of the first three screen types. These templates are actually source code files, written in the code generation language, that are executed by the code generator's interpreter. The templates describe how the code generator should handle a particular screen object to create the target source code language.

I painted the screens by drawing boxes, menus and their actions, background text, and defining data entry fields. Through the screen editor the user may specify menu attributes such as hot keys and the name of a function to call when the menu is selected. The editor also allows specification of field attributes such as type, width, picture and provision for such user-designed features as begin-field and end-field trigger and validation functions. The programmer designs the template language functions to take advantage of the entities and their attributes defined in the screen editor.

UI2 has an interactive mode as well as a command line mode that allows UI2's code generator to be accessed by make. A make response file can include the dependencies for generating target source code files from screen definitions, as well as compiling and linking the entire system. I can now modify a template file and make will call UI2 to regenerate all the affected source code modules. To modify a screen definition file — either by adding text or a data element, or changing one of the many field, form, or menu attributes — I don't edit the C source file; instead, I modify the screen definition file using the UI2 screen editor. I design screens so that I never modify the UI2 generated C code files except through the UI2 screen editor.

UI2 is not limited to any particular coding style or third-party library and is adaptable to many different compilers. UI2 was used on this project to generate 40 screens and about 10,000 lines of C code. The code generation language syntax is very dBASE-like and the learning period was brief.

UI2 Strengths

This type of code generator performs very well on repetitive tasks such as building screens. I was able to build all the screens — both menu and data entry — entirely with UI2. After learning Vermont Views, Btrieve, UI2 and building templates, I will probably be able to reproduce 40 new screens for a new application in a few days. More importantly, the generated C code will be free of syntax errors and errant pointers. This bug-free code is at least as important as the productivity in creating the code. Once the templates are debugged, future screens will be virtually free of syntax errors. On the very first project, I used UI2 to boost productivity significantly, despite a learning period to become familiar with a new tool.

Limitations

In light of the fact that UI2 was designed with the dBASE programmer in mind, it lacks a couple of features for the C programmer. The most obvious feature missing is a full-featured dictionary that supports C data types, including structures and scoping concepts, and general data file schema beyond the dBASE file support. However, I was able to work around most of the data dictionary limitations by creating a hidden box in each screen. The box, made up mostly of #includes and external declarations, contained code for the generator to insert literally into the generated C source code.

Conclusion

I am quite satisfied with UI2. I have created templates for my non-programmer partner to fast prototype systems for prospective clients in order to illustrate what a proposed system may look like. I believe that UI2 will boost my coding and debugging productivity by factors of five to ten in the area of screen generation and maintenance. On future projects I expect to realize tremendous productivity gains now that I am familiar with this tool and have created a set of templates and template libraries to create code that utilizes Vermont Views Screen Library.

Listing 1

Listing 2