7.3.1 Showtext Examples

The following example shows the correlation between a helpfile and the calls to showtext. The C code in this example provides help sections for the components of a table. If a valid component is entered, the help section for the requested table component is displayed. If more help is requested by the operator, help sections on the table and then all the components of the table are displayed. If an invalid table component is entered, a help section regarding the error is shown and then all other help sections are displayed if the help session is not terminated.

The helpfile in this example is named table.h. The contents of this helpfile is:

1 table error

An invalid table component was entered.

2 table components.

A table is piece of furniture with a flat top

supported by legs.

The components of a table are:

1. table top

2. legs

3. brackets

4. screws

3 table top

A table top is a flat piece of furniture

supported horizontally by legs.

The flat piece can be in any shape or size,

and made out of many different materials.

3 legs

The legs support a table top horizontally.

The number of legs for a table varies

depending on the design of the table.

3 brackets

The brackets attach the legs to the table top.

A 90 degree bracket is most common when

assembling a table. Screws are often

used to attach the brackets to a table

top and it's legs.

3 screws

Screws are used to assemble a table.

The screws are used to connect the

brackets to the legs and table top.

The C program that displays the help sections according to the input from the operator is:

#include <stdio.h>



char part[127];

int rc;

printf ("Enter a component of a Table: ");

gets (part);

rc = showtext ("table.h", "table components", part, 1);

if (rc < 0) /* no such part */

showtext ("table.h", "table error", NULL, 0);

else if (rc) /* more help requested */

showtext ("table.h", "table components", NULL, 0);


In the above example, when an invalid table component is entered, the category table error is displayed. The section level for this help section is 1. If the operator does not interrupt the help process, all following help sections are displayed. If a valid table component is entered, first the help section for that component is displayed. If the operator does not interrupt the help process, the help text for the help section "table components" is displayed and then all of the following sub-topic help sections.