ILE C/C++ Programmer's Guide


Establishing the Default Program Device

You can establish the default device for display and ICF files.

Example:

The following example illustrates how to explicitly establish a default program device for a display file using the _Racquire() function.

Note:
To run this example you must use a display device that is defined on your system in place of DEVICE2.
  1. To create the display file T1520DDD using the DDS shown below, enter:

    CRTDSPF FILE(MYLIB/T1520DDD) SRCFILE(QCPPLE/QADDSSRC) MAXDEV(2)

    Figure 141. T1520DDD -- DDS Source for an I/O Display


    
    
    A DSPSIZ(24 80 *DS3)
    A R EXAMPLE
    A OUTPUT 5A O 5 20
    A INPUT 20A I 7 20
    A 5 10'OUTPUT:'
    A 7 10'INPUT:'
  2. To override the file STDOUT with the printer file QPRINT, enter:

    OVRPRTF FILE(STDOUT) TOFILE(QPRINT)
  3. To create the program T1520DEV using the source shown below, enter:

    CRTBNDC PGM(MYLIB/T1520DEV) SRCFILE(QCPPLE/QACSRC)

    Figure 142. T1520DEV -- ILE C Source to Establish a Default Device


    
    
    /* This program establishes a default device using the _Racquire */
    /* function. */
     
    #include <stdio.h>
    #include <recio.h>
    #include <signal.h>
    #include <stdlib.h>
     
    void handler ( int );

    int main(void)
    {
    _RFILE *fp;
    _RIOFB_T *rfb;
    char buf[21];
     
    signal (SIGALL, handler );
     
    if (( fp = _Ropen ( "*LIBL/T1520DDD","ar+" )) == NULL )
    {
    printf ( "Could not open the display file\n" );
    exit ( 1 );
    }
    _Racquire ( fp,"DEVICE2" ); /* Acquire the device. */
    /* DEVICE2 is now the */
    /* default program device. */
    _Rformat ( fp,"EXAMPLE" ); /* Select the record */
    /* format. */
    _Rwrite ( fp, "Hello", 5 ); /* Write to the default */
    /* program device. */
     
    rfb = _Rreadn ( fp, buf, 20, __DFT ); /* Read from the default */
    /* program device. */
     
    buf[rfb -> num_bytes] = '\0';
     
    printf ( "Response from device : %s\n", buf );
     
    _Rrelease ( fp, "DEVICE2" );
    _Rclose ( fp );
    }
     
    void handler ( int sig )
    {
     
    printf ( "message = %7.7s\n", _EXCP_MSGID );
    printf ( "program continues \n" );
    signal ( SIGALL, handler );
    }

    The _Racquire() function explicitly acquires the program device DEVICE2. DEVICE2 is the current program device. The _Rformat() function selects the record format EXAMPLE. The _Rwrite() function writes data to the default device. The _Rreadn() function reads the string from the current program device DEVICE2.

  4. To run the program T1520DEV, enter:

    CALL PGM(MYLIB/T1520DEV)

    The output is as follows:

    +--------------------------------------------------------------------------------+
    |                                                                                |
    |                                                                                |
    |                                                                                |
    |        OUTPUT:   Hello                                                         |
    |                                                                                |
    |         INPUT:      __________________                                         |
    |                                                                                |
    |                                                                                |
    |                                                                                |
    |                                                                                |
    +--------------------------------------------------------------------------------+
  5. Type GOOD MORNING on the input line and press Enter.

    The file QPRINT contains:


    Response from device : GOOD MORNING


[ Top of Page | Previous Page | Next Page | Table of Contents ]