Managing the Terminal

If a called C routine accepts input from the user or performs screen I/O, those routines need to manage the terminal. This is because ACUCOBOL-GT programs and C programs expect the terminal to be in different initial states.

When the ACUCOBOL-GT runtime initializes the terminal manager on a character-based system, it puts the terminal into a "half-cooked" state. This allows the runtime to optimize certain screen I/O and provides support for auto-terminated fields and other screen niceties. C programs, on the other hand, expect the terminal to be in its default state. Therefore, C routines called from COBOL that interact with the user or display information to the screen must manage the state of the display device. Specifically, the C routine must set the terminal to its default mode before performing screen I/O, and restore the terminal to the "half-cooked" state before returning to COBOL. This is accomplished with the w_reset_term() and w_set_term() functions. These functions are built into the runtime.

To prepare the terminal for C screen I/O, at the top of your C routine call w_reset_term() to place the terminal in its default state.

To prepare the terminal for COBOL screen I/O, before your C routine returns call w_set_term() to place the terminal back into the "COBOL" state.