as400:SNDRCVF 的 C 等价物是什么
as400: what is the C equivalent of SNDRCVF
我有一个菜单显示文件。我成功地制作了一个显示菜单并等待输入的工作 CL 程序。很简单,它所做的就是显示文件并等待用户按 F1 退出。
显示文件(近似值):
A R DISPLAY
A CA01(01 'Exit')
A 2 2'some text....'
创建命令:crtdspf file(display) srcfile(test) srcmbr(display)
CL 程序:
PGM
DCLF FILE(DISPLAY) RCDFMT(DISPLAY)
LOOP: SNDRCVF
IF COND(&IN01 *EQ '1') THEN(DO)
GOTO END
ENDDO
GOTO LOOP
END:
ENDPGM
编译命令:crtclpgm pgm(test) srcfile(test) srcmbr(clsrc) output(*print)
C 语言中 SNDRCVF 的等价物是什么?
这是我到目前为止所带来的。它编译得很好,但是当我调用它时,它什么也没做。
#include <stdio.h>
#include <recio.h>
// Include my display file.
#pragma mapinc("display","lib/display(display)", "both", "")
#include "display"
// Shortcuts to the generated structs.
typedef LIB_DISPLAY_DISPLAY_i_t input_t;
typedef LIB_DISPLAY_DISPLAY_o_t output_t;
int main(int argc, char* argv[]){
input_t input;
output_t output;
_RFILE* dspf;
// The file opens fine.
dspf = _Ropen("lib/display", "wr");
if(dspf == NULL){
printf("ERROR: Display file open failed.\n");
return 0;
}
// I tell which record format to use.
_Rformat(dspf, "display");
// Write my file to display?
_Rwrite(dspf, "", 0);
// Wait for input.
_Rreadn(dspf, &input, sizeof(input), __DFT);
// Close it and quit.
_Rclose(dspf);
return 0;
}
编译命令:crtbndc pgm(test) srcfile(test) srcmbr(main) output(*print)
然后调用:call test
我做错了什么?
我做了一些小改动。首先,对于您的 TYPEDEF,我使用了这个:
// Shortcuts to the generated structs.
typedef MYLIB_CDSPMNU_DISPLAY_both_t input_t;
typedef MYLIB_CDSPMNU_DISPLAY_both_t output_t;
因为您指定了 "both",引用的标识符名称应该有 'both' 而不是 'i' 或 'o'。目前还不清楚你是如何成功编译的。也许您之前有一次成功的编译,因此您的 CALL 命令可以工作,但编译的程序不是当前版本。
然后我用这个模式打开文件:
// The file opens fine.
dspf = _Ropen("mylib/cdspmnu", "rr+");
你有 "wr",所以它只是为了输出而打开("wr"iting)。您需要它来进行输入和输出。在您调用程序后,您的作业日志应该显示 C2M3005 "File is not opened for read operations."(取决于您实际调用的编译版本)。
我更改了你的 _Rformat() 函数:
// I tell which record format to use.
_Rformat(dspf, "DISPLAY");
来自 ILE C/C++ Runtime Library Functions 手册,_Rformat() 的定义说:
The fmt parameter is a null-ended C string. The fmt parameter must
be in uppercase.
格式名称没有像其他地方的文件和库名称那样折叠成大写。不知道为什么不;它就是这样。就个人而言,我会在任何实际表示大写名称的地方使用大写字母,而不依赖于编译器;所以我还要更改代码中的其他几个地方。
从技术上讲,我还更改了 DSPF 源以引用 F3 键而不是您在 DDS 中显示的 F1 键。 F1 键通常用于 'help' 功能,而 F3 是 'Exit' 的标准功能。这并不重要,但这是一种开始的习惯。为了适应我的环境,更改了一两个名称。
不需要假脱机文件。在 CALL 命令后查看作业 "joblog" 的最简单方法是 运行 DSPJOBLOG 命令。不过,也许更好的方法是使用 CALL QCMD 提供的基本命令输入显示。使用 F10 键可以将基本作业日志消息 on/off 切换为 "Include detailed messages" 或 "Exclude detailed messages"。
总而言之,你们非常接近。如果这是您第一次尝试使用 DSPF,那还不错。
我有一个菜单显示文件。我成功地制作了一个显示菜单并等待输入的工作 CL 程序。很简单,它所做的就是显示文件并等待用户按 F1 退出。
显示文件(近似值):
A R DISPLAY
A CA01(01 'Exit')
A 2 2'some text....'
创建命令:crtdspf file(display) srcfile(test) srcmbr(display)
CL 程序:
PGM
DCLF FILE(DISPLAY) RCDFMT(DISPLAY)
LOOP: SNDRCVF
IF COND(&IN01 *EQ '1') THEN(DO)
GOTO END
ENDDO
GOTO LOOP
END:
ENDPGM
编译命令:crtclpgm pgm(test) srcfile(test) srcmbr(clsrc) output(*print)
C 语言中 SNDRCVF 的等价物是什么?
这是我到目前为止所带来的。它编译得很好,但是当我调用它时,它什么也没做。
#include <stdio.h>
#include <recio.h>
// Include my display file.
#pragma mapinc("display","lib/display(display)", "both", "")
#include "display"
// Shortcuts to the generated structs.
typedef LIB_DISPLAY_DISPLAY_i_t input_t;
typedef LIB_DISPLAY_DISPLAY_o_t output_t;
int main(int argc, char* argv[]){
input_t input;
output_t output;
_RFILE* dspf;
// The file opens fine.
dspf = _Ropen("lib/display", "wr");
if(dspf == NULL){
printf("ERROR: Display file open failed.\n");
return 0;
}
// I tell which record format to use.
_Rformat(dspf, "display");
// Write my file to display?
_Rwrite(dspf, "", 0);
// Wait for input.
_Rreadn(dspf, &input, sizeof(input), __DFT);
// Close it and quit.
_Rclose(dspf);
return 0;
}
编译命令:crtbndc pgm(test) srcfile(test) srcmbr(main) output(*print)
然后调用:call test
我做错了什么?
我做了一些小改动。首先,对于您的 TYPEDEF,我使用了这个:
// Shortcuts to the generated structs.
typedef MYLIB_CDSPMNU_DISPLAY_both_t input_t;
typedef MYLIB_CDSPMNU_DISPLAY_both_t output_t;
因为您指定了 "both",引用的标识符名称应该有 'both' 而不是 'i' 或 'o'。目前还不清楚你是如何成功编译的。也许您之前有一次成功的编译,因此您的 CALL 命令可以工作,但编译的程序不是当前版本。
然后我用这个模式打开文件:
// The file opens fine.
dspf = _Ropen("mylib/cdspmnu", "rr+");
你有 "wr",所以它只是为了输出而打开("wr"iting)。您需要它来进行输入和输出。在您调用程序后,您的作业日志应该显示 C2M3005 "File is not opened for read operations."(取决于您实际调用的编译版本)。
我更改了你的 _Rformat() 函数:
// I tell which record format to use.
_Rformat(dspf, "DISPLAY");
来自 ILE C/C++ Runtime Library Functions 手册,_Rformat() 的定义说:
The fmt parameter is a null-ended C string. The fmt parameter must be in uppercase.
格式名称没有像其他地方的文件和库名称那样折叠成大写。不知道为什么不;它就是这样。就个人而言,我会在任何实际表示大写名称的地方使用大写字母,而不依赖于编译器;所以我还要更改代码中的其他几个地方。
从技术上讲,我还更改了 DSPF 源以引用 F3 键而不是您在 DDS 中显示的 F1 键。 F1 键通常用于 'help' 功能,而 F3 是 'Exit' 的标准功能。这并不重要,但这是一种开始的习惯。为了适应我的环境,更改了一两个名称。
不需要假脱机文件。在 CALL 命令后查看作业 "joblog" 的最简单方法是 运行 DSPJOBLOG 命令。不过,也许更好的方法是使用 CALL QCMD 提供的基本命令输入显示。使用 F10 键可以将基本作业日志消息 on/off 切换为 "Include detailed messages" 或 "Exclude detailed messages"。
总而言之,你们非常接近。如果这是您第一次尝试使用 DSPF,那还不错。