# CHAPTER 3: Utilities

## 3.1 Initializing a 4GL Database

Before a database can be used in the Empress 4GL environment, it must be initialized using the `emp4init` command. This command imports the 4GL system tables from the `apfmdb.tab` file in the Empress 4GL directory. The name of the database is passed as a parameter to `emp4init`. If the database does not exist, `emp4init` calls the `empmkdb` utility to create the database before importing the 4GL system tables. For example, if the user executes the following command:

       emp4init new_db

Empress responds with the following messages:

    Creating Database 'new_db'

    Importing 4GL Tables

      IMPORT V6.0

      Copyright Empress Software Inc. 1983, 2003

    sys_4gl_application

    sys_4gl_compile

    sys_4gl_domain

    sys_4gl_field

    sys_4gl_form

    sys_4gl_key

    sys_4gl_link

    sys_4gl_script

    sys_4gl_window

    sys_ag_attribute

    sys_ag_definition

    sys_ag_function

    sys_ag_menu

    sys_ag_menu_item

    sys_ag_parameter

    sys_ag_qual_list

    sys_ag_qualification

    sys_ag_screen

    sys_ag_screen_attr

    sys_ag_table

    sys_attr_privs

    sys_attrssys_dictionary

    sys_privssys_tables

## 3.2 The Terminal Definition

When Empress 4GL is started, the Empress variable `MSTERM` is read so that it knows what type of terminal is being used. If `MSTERM` is not set, then the system environment variable `TERM` is used. Then information on that terminal type is obtained from the terminal definition `termdb` database, which by default resides in the Empress 4GL directory.

To obtain a list of terminal names and their descriptions that `termdb` contains, run the following command:

       emp4term

It will display the location of the terminal database, a sorted list of terminal names and their descriptions.

An Empress 4GL application called `sys_terminal` can be used to add a new terminal definition or update the existing one. To invoke the `sys_terminal` application, type:

    emp4gl termdb sys_terminal

where:

`termdb` | is the `termdb` database.

After modifying existing entries or inserting new entries in `termdb`, the information must be compiled before Empress 4GL can make use of it. The compilation can be done through the `sys_terminal` application, or by using the utility `emp4ctdb`:

       emp4ctdb termdb

where:

`termdb` | is the `termdb` database.

The `termdb` database and the `sys_terminal` application are more thoroughly discussed in a subsequent chapter.

## 3.3 Using 4GL with X Windows (UNIX only)

Empress 4GL supports the X Windows environment. To run Empress 4GL in such an environment, set the `MSTERM` variable to an appropriate terminal name (use the `emp4term` utility to find a suitable terminal type). For example, on a Sun 4 console running X Windows, you could use the terminal type `sun4.xterm`:

       setenv MSTERM sun4.xterm

The default font used by Empress 4GL is usually 6x13 or 8x13. If that font is not available on your system, or if you would like to use another one, check the available fonts by listing the files in the directory named by the UNIX environment variable `FONTPATH`. Select a fixed font, i.e., one which does not use proportional spacing, and set the `MS4GLFONTNAME` variable to that font. For example:

       setenv MS4GLFONTNAME courier

When Empress 4GL is started, another window will be opened to run the 4GL process. If any errors are encountered when Empress 4GL is invoked, for example, if ASCII characters appear on the screen, the `-g` flag should be used:

    emp4gl -g database

where:

`database` | is the name of the database.

## 3.4 Printing an Application

In an application, the scripts, key contexts, window definitions, field definitions etc., are stored in several tables. To print out all these definitions in a single source, Empress provides a utility called `emp4prt`. It takes the name of the database and the application as arguments:

       emp4prt database application

where:

`database` | is the name of the database.
`application` | is the name of the application.

The output of this command can be redirected to a file.

## 3.5 Resetting Locks on Applications

Empress 4GL has a locking mechanism which enables multiple users to access the same 4GL database. The locking mechanism is built into the database and is manipulated by the `sys_main` application to prevent two users from editing the same application or Application Generator definition at the same time. If Empress 4GL terminates unexpectedly while the `sys_main` application is running an application or Application Generator definition may remain permanently locked preventing other users from editing it. In this case all locks on the 4GL database must be reset using the `empclrlk` command with the `-4gl` or `-ag` options, for example:

       empclrlk -4gl database application

where:

`database` | is the name of the database.
`application` | is the name of the application.

If the name of an application is supplied, then the locks on that application will be removed. Otherwise, locks on all applications will be removed.

Warning

Use the command `empclrlk` only when no one else is using Empress 4GL.

## 3.6 Building an Executable 4GL Application

The Empress 4GL Executable Builder is a facility that allows the user to build customized executables to run 4GL applications. A customized executable consists of zero or more terminal definitions and zero or more linked applications compiled as read only data and linked to a copy of the 4GL runtime executable. Read only data is part of the executable's text space and is automatically in memory when the executable is invoked. A customized executable can be invoked to run any application linked to it on any terminal whose definition has been linked to it without having to go to the database to get the information. Also, because the customized executable is a copy of the Empress 4GL runtime executable it can also be used to run applications on terminals that have not been linked to it as read only data.

Building a customized executable has several advantages:

- The initial startup time for running applications is reduced because they are already in memory.
- Memory usage for multiple users is reduced because only one copy of the terminal definitions and linked applications are kept in memory no matter how many times the executable is invoked.
- Application developers can package their applications for end users into an executable and remove the need for a 4GL application database.

The Empress 4GL Executable Builder is invoked by typing the following command:

       emp4bldx

(There are several options to this command that are described in the "Manual Pages" of this manual.) The Empress 4GL Executable Builder will prompt the user to enter a name for the customized executable to be built in the user's current working directory.

       Enter name of executable: exec1

The user is then prompted to enter the names of terminal definitions to be linked to the executable.

       Enter name of terminal: vt100

       Enter name of terminal: vt220

       Enter name of terminal:

(A <Return> by itself is used to tell the Empress 4GL Executable Builder that you are finished entering data.) The user is then prompted to enter the name of a database followed by names of linked applications from that database to be linked to the executable.

       Enter name of database: userdb

       Enter name of Application: applic1

       Enter name of Application: applic2

       Enter name of Application:

       Enter name of database:

(Applications from different databases can also be linked to the executable). The Empress 4GL Executable Builder then creates the appropriate C data files containing read only data and compiles and links them along with the 4GL runtime libraries to make a customized executable.

       Creating files .....

       Compiling ..........

       Linking ...............

The application `applic1` can now be run by simply entering the name of the executable:

       exec1

Application `applic1` was chosen because it was the first one entered above.

If application `applic1` needs a default user database then enter:

       exec1 -d userdb

If you wish to run a different application at startup you may do so by entering:

       exec1 -d userdb -a applic2

For more information on the Empress 4GL Executable Builder, refer to the Empress 4GL: Tools Reference manual.