用户输入过程 (UEP) 的源代码
在 图 1。 ILE C 源到其他模块中的调用函数
T1520IC1的源代码中, main() 函数:- 从 CL 程序接收用户标识,项目名称,数量和价格
- 调用模块
T1520IC2中的calc_and_format()函数,该函数:- 计算项目的总成本
- 从模块
T1520IC2调用write_audit_trail()函数,该模块将事务写入审计文件
/* This program demonstrates how to use multiple modules, service */
/* programs and a binding directory. This program accepts a user ID, */
/* item name, quantity, and price, calculates the total cost, and */
/* writes an audit trail of the transaction. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h.>
#include <decimal.h>
int calc_and_format (decimal(10,2),
short int,
char[]);
void write_audit_trail (char[],
char[],
decimal(10,2),
short int,
char[]);
int main(int argc, char *argv[]) 1
{
/* Incoming arguments from a CL program have been verified by */
/* the *CMD and null ended within the CL program. */ 2
char *user_id;
char *item_name;
short int *quantity;
decimal (10,2) *price;
char formatted_cost[22];
/* Incoming arguments are all pointers. */ 3
item_name = argv[1];
price = (decimal (10, 2) *) argv[2];
quantity = (short *) argv[3];
user_id = argv[4];
/* Call an ILE C function that returns a formatted cost. */ 4
/* Function calc_and_format returns true if successful. */
if (calc_and_format (*price, *quantity, formatted_cost))
{
write_audit_trail (user_id, 5
item_name,
*price,
*quantity,
formatted_cost);
printf("\n%d %s plus tax = %-s\n", *quantity,
item_name,
formatted_cost);
}
else
{
printf("Calculation failed\n");
}
return 0;
}
注:
- 此模块中的
main()函数是用户输入过程 (UEP) ,它是来自 CL 程序 T1520CL1的动态程序调用的目标。 UEP 从程序入口过程 (PEP) 接收控制。 此模块具有由 ILE C 编译器在编译期间生成的 PEP。 PEP 是来自 CL 程序 T1520CL1的动态程序调用上 ILE C/C++ 程序的入口点。 PEP 在调用堆栈中显示为 _C_pep。 - 此模块中的
main()函数从 CL 程序 T1520CL1 接收由 CL 命令提示符 T1520CM1验证的入局自变量。 - 所有传入参数都是指针。 变量
item_name在 CL 程序 T1520CL1中以 null 结束。 - 此模块中的
main()函数调用模块 T1520IC2 中的calc_and_format以返回格式化成本。 如果calc_and_format返回成功,那么服务程序 T1520SP1中的write_audit_trail会将记录写入审计跟踪。 - 未在此模块 (T1520IC1) 中定义函数
write_audit_trail,因此必须将其导入。