HP OpenVMS Systems Documentation
OpenVMS Programming Concepts Manual
22.2 Using SYS$INPUT and SYS$OUTPUT
Typically, you set up your program so that the user is the invoker. The
user starts the program either by entering a DCL command associated
with the program or by using the RUN command.
The user's input and output devices are defined by the logical names SYS$INPUT and SYS$OUTPUT, which are initially set to the values listed in Table 22-1.
Generally, use of SYS$INPUT and SYS$OUTPUT as the primary input and output devices is recommended. A user of the program can redefine SYS$INPUT and SYS$OUTPUT to redirect input and output as desired. For example, the interactive user might redefine SYS$OUTPUT as a file name to save output in a file rather than display it on the terminal.
Usually, you can request information from or provide information to the user with little regard for formatting. For such simple I/O, use either LIB$GET_INPUT and LIB$PUT_OUTPUT or the I/O statements for your programming language.
The LIB$GET_INPUT and LIB$PUT_OUTPUT routines read from SYS$INPUT and
write to SYS$OUTPUT, respectively. The logical names SYS$INPUT and
SYS$OUTPUT are implicit to the routines, because you need only call the
routine to access the I/O unit (device or file) associated with
SYS$INPUT and SYS$OUTPUT. You cannot use these routines to access an
I/O unit other than the one associated with SYS$INPUT or SYS$OUTPUT.
A read operation transfers one record from the input unit to a variable or variables of your choice. At a terminal, the user ends a record by pressing a terminator. The terminators are the ASCII characters NUL through US (0 through 31) except for LF, VT, FF, TAB, and BS. The usual terminator is CR (carriage return), which is generated by pressing the Return key.
If you are reading character data, LIB$GET_INPUT is a simple way of prompting for and reading the data. If you are reading noncharacter data, programming language I/O statements are preferable since they allow you to translate the data to a format of your choice.
For example, Fortran offers the ACCEPT statement, which reads data from SYS$INPUT, and the READ statement, which reads data from an I/O unit of your choice.
Make sure the variables that you specify can hold the largest number of characters the user of your program might enter, unless you want to truncate the input deliberately. Overflowing the input variable using LIB$GET_INPUT causes the fatal error LIB$_INPSTRTRU (defined in $LIBDEF); overflowing the input variable using language I/O statements may not cause an error but does truncate your data.
LIB$GET_INPUT places the characters read in a variable of your choice. You must define the variable type as a character. Optionally, LIB$GET_INPUT places the number of characters read in another variable of your choice. For input at a terminal, LIB$GET_INPUT optionally writes a prompt before reading the input. The prompt is suppressed automatically for an operation not taking place at a terminal.
Example 22-1 uses LIB$GET_INPUT to read a line of input.
22.3.3 Getting Several Lines of Input
The usual technique for obtaining a variable number of input records---either values for which you are prompting or data records from a file---is to read and process records until the end-of-file. End-of-file means one of the following:
Example 22-2 uses a Fortran READ statement in a loop to read a sequence of integers from SYS$INPUT.
22.3.4 Writing Simple Output
You can use LIB$PUT_OUTPUT to write character data. If you are writing noncharacter data, programming language I/O statements are preferable because they allow you to translate the data to a format of your choice.
LIB$PUT_OUTPUT writes one record of output to SYS$OUTPUT. Typically, you should avoid writing records that exceed the device width. The width of a terminal is 80 or 132 characters, depending on the setting of the physical characteristics of the device. The width of a line printer is 132 characters. If your output record exceeds the width of the device, the excess characters are either truncated or wrapped to the next line, depending on the setting of the physical characteristics.
You must define a value (a variable, constant, or expression) to be written. The value must be expressed in characters. You should specify the exact number of characters being written and not include the trailing portion of a variable.
22.4 Working with Complex User I/O
The following sections present Compaq DECwindows Motif for OpenVMS
(DECwindows Motif), and the SMG$ run-time library routines that enable
complex screen display I/O.
The Compaq DECwindows Motif environment provides a consistent user interface for developing software applications. It also includes an extensive set of programming libraries and tools. The following Compaq DECwindows Motif software allows you to build a graphical user interface:
Compaq DECwindows Motif environment also makes available the LinkWorks
services for creating, managing, and traversing informational links
between different application-specific data. Along with the LinkWorks
Manager application, LinkWorks services help organize information into
a hyperinformation environment. LinkWorks Developer's Tools provide a
development environment for creating, modifying, and maintaining
On OpenVMS VAX systems, when an X application sends the display server a width or height greater than 32767, the application may terminate with a BadValue error similar to the following:
The following calls can cause this problem:
This is due to the width and height being defined as a signed word by the display server when it should be defined as an unsigned word (CARD16) that allows for values up to 65536.
To modify the default operation, perform the following steps:
To make this a permanent change, add the command from step 1 to the
When creating WSA pseudo workstation devices using the SET DISPLAY command, be careful not to create WSA devices that are never destroyed. For example, this DCL command procedure is wrong:
If the clock cannot be started for some reason, one WSA device will be created for each failed attempt. These WSA devices will use up non-paged dynamic memory, and eventually the process will exceed its BYTLM quota and enter a resource wait state (if resource waiting is enabled, as it is by default).
A better version of this command procedure is the following:
The SET DISPLAY/DELETE command deletes the WSA device that was created at the beginning of the command procedure; the logical name DECW$DISPLAY contains the name of the WSA device that was created.
For information about using OpenVMS Compaq DECwindows Motif, see the
Overview of DECwindows Motif for OpenVMS Documentation and the DECwindows Motif Guide to Application Programming.
To use the screen management facility for output, do the following:
Example 22-3 associates a pasteboard with the terminal, creates a virtual display the size of the terminal screen, and pastes the display to the pasteboard. When text is written to the virtual display, the text appears on the terminal screen.
To use the SMG$ routines for input, you associate a virtual keyboard with a physical device or file using the SMG$CREATE_VIRTUAL_KEYBOARD routine. The SMG$ input routines can be used alone or with the output routines. This section assumes that you are using the input routines with the output routines. Section 22.5 describes how to use the input routines without the output routines.
The screen management facility keeps an internal representation of the
screen contents; therefore, it is important that you do not mix SMG$
routines with other forms of terminal I/O. The following subsections
contain guidelines for using most of the SMG$ routines; for more
details, see the OpenVMS RTL Screen Management (SMG$) Manual.
Use the SMG$CREATE_PASTEBOARD routine to create a pasteboard and associate it with a physical device. SMG$CREATE_PASTEBOARD returns a unique pasteboard identification number; use that number to refer to the pasteboard in subsequent calls to SMG$ routines. After associating a pasteboard with a device, your program references only the pasteboard. The screen management facility performs all necessary operations between the pasteboard and the physical device. Example 22-4 creates a pasteboard.
188.8.131.52 Erasing a Pasteboard
When you create a pasteboard, the screen management facility clears the screen by default. To clear the screen yourself, invoke the SMG$ERASE_PASTEBOARD routine. Any virtual displays associated with the pasteboard are removed from the screen, but their contents in memory are not affected. The following example erases the screen:
184.108.40.206 Deleting a Pasteboard
Invoking the SMG$DELETE_PASTEBOARD routine deletes a pasteboard, making the screen unavailable for further pasting. The optional second argument of the SMG$DELETE_PASTEBOARD routine allows you to indicate whether the routine clears the screen (the default) or leaves it as is. The following example deletes a pasteboard and clears the screen:
By default, the screen is erased when you create a pasteboard.
Generally, you should erase the screen at the end of a session.
The SMG$CHANGE_PBD_CHARACTERISTICS routine sets the dimensions of the screen and its background color. You can also use this routine to retrieve dimensions and background color. To get more detailed information about the physical device, use the SMG$GET_PASTEBOARD_ATTRIBUTES routine. Example 22-5 changes the screen width to 132 and the background to white, then restores the original width and background before exiting.