更改缺省程序设备
您可以更改设备文件的缺省设备。
示例:
以下示例说明如何使用
_Rpgmdev() 函数来更改缺省程序设备。注: 要运行此示例,必须使用系统上定义的两个显示设备来代替 DEVICE1 和 DEVICE2。
- 要使用下面显示的 DDS 创建显示文件 T1520DDE ,请输入:
CRTDSPF FILE(MYLIB/T1520DDE) SRCFILE(QCPPLE/QADDSSRC) MAXDEV(2)图 1。 T1520DDE -名称和密码显示的 DDS 源 A DSPSIZ(24 80 *DS3) A INVITE A R FORMAT1 A 9 13'Name:' A NAME 20A I 9 20 A 11 10'Address:' A ADDRESS 25A I 11 20 A R FORMAT2 A 9 13'Name:' A NAME 8A I 9 20 A 11 10'Password:' A PASSWORD 10A I 11 20 - 要用打印机文件 QPRINT 覆盖文件 STDOUT ,请输入:
OVRPRTF FILE(STDOUT) TOFILE(QPRINT) - 要使用下面显示的源创建程序 T1520CDV ,请输入:
CRTBNDC PGM(MYLIB/T1520CDV) SRCFILE(QCPPLE/QACSRC)/* This program illustrates how to change a default program device. */ /* using the _Racquire(), _Rpgmdev(), _Rreadindv() and _Rrelease() */ /* functions. */ #include <stdio.h> #include <recio.h> #include <string.h> #include <stdlib.h> typedef struct{ char name[20]; char address[25]; }format1; typedef struct{ char name[8]; char password[10]; }format2 ; typedef union{ format1 fmt1; format2 fmt2; }formats ; void io_error_check( _RIOFB_T *rfb ) { if ( memcmp(rfb->sysparm->_Maj_Min.major_rc,"00",2 ) || memcmp ( rfb->sysparm->_Maj_Min.minor_rc,"00",2 )) { printf ( "I/O error occurred, program ends.\n" ); exit ( 1 ); } } int main(void) { _RFILE *fp; _RIOFB_T *rfb; _XXIOFB_T *iofb; int size; formats buf; /* Open the device file. */ if (( fp = _Ropen ( "*LIBL/T1520DDE", "ar+" )) == NULL ) { printf ( "Could not open file\n" ); exit ( 1 ); } _Racquire ( fp,"DEVICE1" ); /* Acquire another device. */ /* Replace with the actual */ /* device name. */ _Rformat ( fp,"FORMAT1" ); /* Set the record format for the */ /* display file. */ rfb = _Rwrite ( fp, "", 0 ); /* Set up the display. */ io_error_check(rfb); _Racquire ( fp,"DEVICE2" ); /* Acquire another device. */ _Rpgmdev ( fp,"DEVICE2" ); /* Change the default program */ /* device. Replace with the */ /* actual device name. */ /* Device2 implicitly acquired at */ /* open. */ _Rformat ( fp,"FORMAT2" ); /* Set the record format for the */ /* the display file. */ rfb = _Rwrite ( fp, "", 0 ); /* Set up the display. */ io_error_check ( rfb ); _Rreadindv ( fp, &buf, sizeof(buf), __DFT ); /* Read from the first device that */ /* enters data. The device becomes */ /* the default program device. */ io_error_check ( rfb ); /* Determine which terminal responded first. */ iofb = _Riofbk ( fp ); if ( !strncmp ( "FORMAT1 ", iofb -> rec_format, 10 )) { _Rrelease ( fp, "DEVICE1" ); } else { _Rrelease(fp, "DEVICE2" ); } return(0); }ILE C 程序 T1520CDV 使用
_Racquire()函数来显式获取另一个名为 DEVICE1的设备。 DEVICE1 成为当前程序设备。_Rpgmdev()函数将名为 DEVICE1 的当前设备更改为 DEVICE2。_Rreadindv()函数从 DEVICE1读取记录。_Release()函数发布 DEVICE1 和 DEVICE2。 - 要运行程序 T1520CDV,请输入:
CALL PGM(MYLIB/T1520CDV)输出如下所示:Name: Password:运行应用程序时,每个设备上都会显示不同的屏幕。 可以在这两个屏幕上输入数据,但首先输入的数据将返回到程序。 程序的输出在 QPRINT 中。 例如,如果在 DEVICE2上输入任何数据之前,在 DEVICE1 上输入了名称SMITH和地址10 MAIN ST,那么文件 QPRINT 包含:Data displayed on DEVICE1 is SMITH 10 MAIN ST
注: 以上示例中创建了两种记录格式。 一个大小为 45 个字符 (fmt1) ,另一个大小为 18 个字符 (fmt2)。 联合 buf 包含两个记录格式声明。