⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 easycics.ccs

📁 CICS简单入门例程 CICS环境构架 1 安装服务器 1) 建立用户CICSTEST(要用超户权) 2)用CICSTEST用户登录 3)安装DB2指定CICSTEST为管理用户
💻 CCS
📖 第 1 页 / 共 2 页
字号:
/* EasyCICS v1.95 */

/******************************************************************************/
/*------------------------------- HEADER FILES -------------------------------*/

#ifndef  WIN32
	#define _stdcall
#endif


#include <stdio.h>
#include <stdlib.h>
#include <string.h>


/******************************************************************************/
/*--------------------------------- DEFINES ----------------------------------*/

#define BUF_SIZE 32000
#define ROW_SIZE 4000
#define WARN_SIZE 28000
#define BLOCK_SIZE 28000


/******************************************************************************/
/*----------------------------- Global Variables -----------------------------*/

int ForPbUse=0, RetCode;
char *pCommArea=0, pCommBuf[BUF_SIZE]="", *pComm, pRow[ROW_SIZE]="", pRtnBuf[BUF_SIZE]="", *pCwa;
char TsqName[20]="", TsqName1[20]="", PrgName[20]="", SysId[10]="", SysId0[10]="", TableLst[1000], CommPad[1000]="", CicsRegionTag[]="CD1.9";
int RsRowNum=0, RsRowNum0=0, RsColNum=0, RsRow=0, LongNum=0, BlockNum=0, BlockSize=0, UpfLen=0;
short int RsBlk=0, RsBlkCli=0; 


/******************************************************************************/
#ifdef  __cplusplus
extern "C" {
#endif
/******************************************************************************/
/*Functions*/
/******************************************************************************/
/*Encode-Decode --------------------------------------------------------------*/

/*
 */
char GetHexChr( char *p ){
int a, b;

	a=b=0;

	if( p[0] >= '0' && p[0] <= '9' )
	a= p[0] - '0';
	else if( p[0] >= 'A' && p[0] <= 'F' )
	a= p[0] - 'A' +10;

	if( p[1] >= '0' && p[1] <= '9' )
	b= p[1] - '0';
	else if( p[0] >= 'A' && p[1] <= 'F' )
	b= p[1] - 'A' +10;

	return (a*16 + b);
}



/*
 *! change pRtnBuf
 */
char *PbEncode(char *OrgStr){
unsigned char *p,  cc[4];


	*pRtnBuf =0;
for( p= (unsigned char *)OrgStr; *p; p++ ){
	cc[0] = *p;
	cc[1] = 0;

 if( *p == '%' ){
	strcpy( (char *)cc, "%25" );
 }
 else if( *p >= 128 ){
	sprintf( (char *)cc, "%%%X", *p );
 }

	strcat( pRtnBuf, (char *)cc );
}

	return pRtnBuf;
}



/*
 *! change pRtnBuf
 */
char *PbDecode(char *CodStr){
char *p, cc[4];


	*pRtnBuf =0;
	cc[1] = 0;
for( p=CodStr; *p; p++ ){
	*cc = *p;

 if( '%' == *p ){
	/*-*/
  if( !strncmp( "%25", p, 3 ) ){
	*cc='%';
	p= p+2;
  }
  else if( ( p[1] >= '8' && p[1] <= '9' ) || ( p[1] >= 'A' && p[1] <= 'F' ) ){
	*cc= GetHexChr(p+1);
	p= p+2;
  } 
	/*-*/
 }

	strcat( pRtnBuf, cc );
}

	return pRtnBuf;
}



/*
 */
void Encode(char *OrgStr, char *CodStr, int len){
char *p,  cc[4];


	*CodStr =0;
for( p=OrgStr; (p-OrgStr)<len; p++ ){
	cc[0] = *p;
	cc[1] = 0;

 switch(*p){
 case '%':
	strcpy( cc, "%25" );
	break;
 case '=':
	strcpy( cc, "%3D" );
	break;
 case '&':
	strcpy( cc, "%26" );
	break;
 }

	strcat( CodStr, cc );
}

}



/*
 */
void EncodeStr(char *OrgStr, char *CodStr){
	Encode( OrgStr, CodStr, strlen(OrgStr) );
}



/*
 */
void Decode(char *CodStr, char *OrgStr, int len){
char *p, cc[4];


	*OrgStr =0;
	cc[1] = 0;
for( p=CodStr; (p-CodStr)<len; p++ ){
	*cc = *p;

 if( '%' == *p ){
	/*-*/
  if( !strncmp( "%25", p, 3 ) ){
	*cc = '%';
	p= p+2;
  }
  else if( !strncmp( "%3D", p, 3 ) ){
	*cc = '=';
	p= p+2;
  } 
  else if( !strncmp( "%26", p, 3 ) ){
	*cc = '&';
	p= p+2;
  } 
	/*-*/
 }

	strcat( OrgStr, cc );
}

}



/*
 */
void DecodeStr(char *CodStr, char *OrgStr){
	Decode( CodStr, OrgStr, strlen(CodStr) );
}



/*
 */
void Encode_(char *OrgStr, char *CodStr, int len){
char *p,  cc[4];


	*CodStr =0;
for( p=OrgStr; (p-OrgStr)<len; p++ ){
	cc[0] = *p;
	cc[1] = 0;

 switch(*p){
 case '%':
	strcpy( cc, "%25" );
	break;
 case ',':
	strcpy( cc, "%2C" );
	break;
 }

	strcat( CodStr, cc );
}

}



/*
 */
void EncodeStr_(char *OrgStr, char *CodStr){
	Encode_( OrgStr, CodStr, strlen(OrgStr) );
}



/*
 */
void Decode_(char *CodStr, char *OrgStr, int len){
char *p, cc[4];


	*OrgStr =0;
	cc[1] = 0;
for( p=CodStr; (p-CodStr)<len; p++ ){
	*cc = *p;

 if( '%' == *p ){
	/*-*/
  if( !strncmp( "%25", p, 3 ) ){
	*cc='%';
	p= p+2;
  }
  else if( !strncmp( "%2C", p, 3 ) ){
	*cc=',';
	p= p+2;
  } 
	/*-*/
 }

	strcat( OrgStr, cc );
}

}



/*
 */
void DecodeStr_(char *CodStr, char *OrgStr){
	Decode_( CodStr, OrgStr, strlen(CodStr) );
}



/******************************************************************************/
/*Key & Value-----------------------------------------------------------------*/

/*
 */
void DelKey(char *KeyName){
char cod_key[200] ="&", *p1, *p2, cod_key0[200];


	EncodeStr(KeyName, cod_key0);
	strcat( cod_key0, "=" );
	strcpy( cod_key+1, cod_key0 );

	p1= strstr(pComm, cod_key);
if(p1){
	p2= strchr( p1+ strlen(cod_key), '&' );

	if(p2)
	strcpy( p1, p2 );
	else
	*p1= 0;
}
else if( !memcmp( pComm, cod_key0, strlen(cod_key0) ) ){
	p1=pComm;
	p2= strchr( p1+ strlen(cod_key0), '&' );

	if(p2)
	strcpy( p1, p2+1 );
	else
	*p1= 0;
}

}



/*
 */
void DelKeyX(char *KeyName, char *pBuf){
char cod_key[200] ="&", *p1, *p2, cod_key0[200];


	EncodeStr(KeyName, cod_key0);
	strcat( cod_key0, "=" );
	strcpy( cod_key+1, cod_key0 );

	p1= strstr(pBuf, cod_key);
if(p1){
	p2= strchr( p1+ strlen(cod_key), '&' );

	if(p2)
	strcpy( p1, p2 );
	else
	*p1= 0;
}
else if( !memcmp( pBuf, cod_key0, strlen(cod_key0) ) ){
	p1=pBuf;
	p2= strchr( p1+ strlen(cod_key0), '&' );

	if(p2)
	strcpy( p1, p2+1 );
	else
	*p1= 0;
}

}



/*
 */
void GetValue0( char *KeyName, char *Vlu ){
char cod_key[200] ="&", *p1, *p2, cod_key0[200];


if( !KeyName || !*KeyName ){
	strcpy(Vlu, pComm);
	return;
}
	*Vlu= 0;

	EncodeStr(KeyName, cod_key0);
	strcat( cod_key0, "=" );
	strcpy( cod_key+1, cod_key0 );

	p1= strstr(pComm, cod_key);
if(p1){
	p1= p1 + strlen(cod_key);
	p2= strchr(p1, '&');

	if(p2)
	Decode( p1, Vlu, p2-p1 );
	else
	DecodeStr(p1, Vlu);
}
else if( !memcmp( pComm, cod_key0, strlen(cod_key0) ) ){
	p1= pComm+ strlen(cod_key0);
	p2= strchr(p1, '&');

	if(p2)
	Decode( p1, Vlu, p2-p1 );
	else
	DecodeStr(p1, Vlu);
}

}



/*
 */
void GetValueX( char *KeyName, char *Vlu, char *pBuf ){
char cod_key[200] ="&", *p1, *p2, cod_key0[200];


if( !KeyName || !*KeyName ){
	strcpy(Vlu, pBuf);
	return;
}
	*Vlu= 0;

	EncodeStr(KeyName, cod_key0);
	strcat( cod_key0, "=" );
	strcpy( cod_key+1, cod_key0 );

	p1= strstr(pBuf, cod_key);
if(p1){
	p1= p1 + strlen(cod_key);
	p2= strchr(p1, '&');

	if(p2)
	Decode( p1, Vlu, p2-p1 );
	else
	DecodeStr(p1, Vlu);
}
else if( !memcmp( pBuf, cod_key0, strlen(cod_key0) ) ){
	p1= pBuf+ strlen(cod_key0);
	p2= strchr(p1, '&');

	if(p2)
	Decode( p1, Vlu, p2-p1 );
	else
	DecodeStr(p1, Vlu);
}

}



/*
 */
void SetValue0( char *KeyName, char *Vlu ){
char *p;


if( !KeyName || !*KeyName ){
	strcpy(pComm, Vlu);
	return;
}

	DelKey(KeyName);

	if( !Vlu || !*Vlu )return;

	if(*pComm)
	strcat(pComm, "&");

	p= pComm+ strlen(pComm);
	EncodeStr(KeyName, p);

	strcat(pComm, "=");

	p= pComm+ strlen(pComm);
	EncodeStr(Vlu, p);
}



/*
 */
void SetValue0_( char *KeyName, char *Vlu ){
char *p;


if( !KeyName || !*KeyName ){
	strcpy(pComm, Vlu);
	return;
}

	if( !Vlu || !*Vlu )return;

	if(*pComm)
	strcat(pComm, "&");

	p= pComm+ strlen(pComm);
	EncodeStr(KeyName, p);

	strcat(pComm, "=");

	p= pComm+ strlen(pComm);
	EncodeStr(Vlu, p);
}



/*
 */
void SetValueX( char *KeyName, char *Vlu, char *pBuf ){
char *p;


if( !KeyName || !*KeyName ){
	strcpy(pBuf, Vlu);
	return;
}

	DelKeyX(KeyName, pBuf);

	if( !Vlu || !*Vlu )return;

	if(*pBuf)
	strcat(pBuf, "&");

	p= pBuf+ strlen(pBuf);
	EncodeStr(KeyName, p);

	strcat(pBuf, "=");

	p= pBuf+ strlen(pBuf);
	EncodeStr(Vlu, p);
}



/*
 */
void SetValueA( char *KeyName, char *Vlu ){
	SetValueX( KeyName, Vlu, CommPad );
}



/*
 */
void SetValueX_( char *KeyName, char *Vlu, char *pBuf ){
char *p;


if( !KeyName || !*KeyName ){
	strcpy(pBuf, Vlu);
	return;
}


	if( !Vlu || !*Vlu )return;

	if(*pBuf)
	strcat(pBuf, "&");

	p= pBuf+ strlen(pBuf);
	EncodeStr(KeyName, p);

	strcat(pBuf, "=");

	p= pBuf+ strlen(pBuf);
	EncodeStr(Vlu, p);
}



/*
 */
void _stdcall GetValue( char *KeyName, char *Vlu ){

	GetValue0( KeyName, Vlu );

	if(ForPbUse)
	strcpy( Vlu, PbDecode(Vlu) );

}



/*
 */
void _stdcall SetValue( char *KeyName, char *Vlu ){

if(!ForPbUse){
	SetValue0( KeyName, Vlu );
}
else{
	SetValue0( KeyName, PbEncode(Vlu) );
}

}



/*
 */
void SetValue_( char *KeyName, char *Vlu ){

if(!ForPbUse){
	SetValue0_( KeyName, Vlu );
}
else{
	SetValue0_( KeyName, PbEncode(Vlu) );
}

}



/******************************************************************************/
/*Init------------------------------------------------------------------------*/

/*
 */
void _stdcall PrintStatus(char *statusbuf){
	if(!statusbuf)
	statusbuf=pComm;

	EXEC CICS WRITEQ TD QUEUE("CSMT") FROM(statusbuf) LENGTH( strlen(statusbuf) );
}



	void TsqFetchRows(char *SysId1);
	void TsqFetchBlock(char *SysId1);
	void TsqRemove(char *SysId1);


/*
 */
int _stdcall InitEasyCics(){
char s[100], sysid1[10];
int n;


	EXEC CICS ADDRESS EIB (dfheiptr);
	EXEC CICS ADDRESS COMMAREA (pCommArea);
	EXEC CICS ADDRESS CWA(pCwa);
	EXEC CICS ASSIGN SYSID(SysId0);

	pComm=pCommBuf;

	n=BUF_SIZE;
	if( n> dfheiptr->eibcalen )
	n= dfheiptr->eibcalen;

	memcpy(pComm,pCommArea,n);
	pComm[n-1] = '\0';
	memset( pCommArea, 0, (size_t)dfheiptr->eibcalen );

	RsRowNum = RsColNum =0;
	*TsqName = *TsqName1 = *CommPad = '\0';
	RsBlk=RsBlkCli=0;

/*-*/
	GetValue0( "_LANG", s );
	if( !strcmp( s, "1" ) )
	ForPbUse=1;	

	GetValue0( "_TSQ", TsqName );
if( *TsqName ){
	GetValue0( "_SYSID", sysid1 );

	GetValue0( "_DELTSQ", s );
	if( *s != 'Y' )
	TsqFetchRows(sysid1);
	else
	TsqRemove(sysid1);

	return 1;
}

	GetValue0( "_TSQ1", TsqName1 );
if( *TsqName1 ){
	GetValue0( "_SYSID", sysid1 );
	TsqFetchBlock(sysid1);
	return 2;
}

	return 0;
}



/*
 */
void _stdcall SetRegionTag( char a, char b ){
	CicsRegionTag[0] = a;
	CicsRegionTag[1] = b;
}



/*
 */
void _stdcall InitEIB(){
	EXEC CICS ADDRESS EIB (dfheiptr);
}



/*
 */
void _stdcall BeginWrite(){
	*TsqName = *TableLst = *CommPad = '\0';
	memset(pComm, 0, BUF_SIZE);
	RsRowNum = RsColNum =0;
	RsBlk=RsBlkCli=0;
	BlockNum=BlockSize=0;

	SetValue0_( "_CA", CicsRegionTag );
	SetValue0_( "_SYSID", SysId0 );
	if( ForPbUse )
	SetValue0( "_LANG", "1" );
}



void SaveBlk();
void _stdcall RsNewTable(int ColNum);

/*
 */
void _stdcall ExitEasyCics(){
char s[10];

	if(*pComm)
	SaveBlk();

if(RsRowNum){
	RsNewTable(0);

	sprintf( s, "%d", RsRowNum );
	SetValueX( "_RC", s, pCommArea );
	sprintf( s, "%d", RsColNum );
	SetValueX( "_CC", s, pCommArea );

	if(*TableLst)
	SetValueX( "_TL", TableLst, pCommArea );

 if(*CommPad){
	strcat( pCommArea, "&" );
	strcat( pCommArea, CommPad );
 }
}

	EXEC CICS RETURN;
}



/*
 */
int _stdcall GetCommLen(){

	return strlen(pComm);
}



/*
 */
void _stdcall SetCurrentCA(char *new_ca){
	if(!new_ca)
	pComm=pCommBuf;
	else
	pComm=new_ca;
}



/*
 */
int _stdcall MergeCA(char *ca){

	if( ( strlen(pComm) + strlen(ca) ) >BUF_SIZE )
	return -1;

	strcat( pComm, ca );
	return 0;
}



/*
 */
int _stdcall CallProgram(char *prg){
short ln;
char s[10];


if(RsRowNum){
	sprintf( s, "%d", RsRowNum );
	SetValue( "_RC", s );
	sprintf( s, "%d", RsColNum );
	SetValue( "_CC", s );
}

	ln=BUF_SIZE;

	strncpy( PrgName, prg, 20 );
	PrgName[19] = '\0';
	*SysId = '\0';

	EXEC CICS LINK PROGRAM( prg ) COMMAREA( pComm ) LENGTH( ln ) SYNCONRETURN RESP(RetCode);

	if( RetCode != DFHRESP(NORMAL) )
	return -1;
	else
	return 0;
}



/*
 */
int _stdcall CallProgramSys(char *prg, char *sys_id){
short ln;


	ln=BUF_SIZE;

	strncpy( PrgName, prg, 20 );
	PrgName[19] = '\0';
	strncpy( SysId, sys_id, 4 );
	SysId[4] = '\0';

	EXEC CICS LINK PROGRAM( prg ) COMMAREA( pComm ) LENGTH( ln ) SYSID( SysId ) SYNCONRETURN RESP(RetCode);

	if( RetCode != DFHRESP(NORMAL) )
	return -1;
	else
	return 0;
}



/*
 */
int _stdcall CallProgramXCTL(char *prg){
int ln;


	strcpy(pCommArea, pComm);
	ln= dfheiptr->eibcalen;
	EXEC CICS XCTL PROGRAM( prg ) COMMAREA( pCommArea ) LENGTH( ln ) RESP(RetCode);

	if( RetCode != DFHRESP(NORMAL) )
	return -1;
	else
	return 0;
}



/*
 */
int _CallProgram0(){

	if( !*SysId )
        return CallProgram(PrgName);
	else
        return CallProgramSys(PrgName, SysId);

}



/*
 */
int _stdcall StartTran(char *tran, char *para, short ln){

	EXEC CICS START TRANSID( tran ) FROM( para ) LENGTH( ln ) RESP(RetCode);

	if( RetCode != DFHRESP(NORMAL) )
	return -1;
	else
	return 0;

}



/*
 */
int _stdcall StartTranSys(char *tran, char *para, short ln, char *sys_id){

	EXEC CICS START TRANSID( tran ) FROM( para ) LENGTH( ln ) SYSID( sys_id ) RESP(RetCode);

	if( RetCode != DFHRESP(NORMAL) )
	return -1;
	else
	return 0;
}



/*
 */
int _stdcall RetrievePara(char *para, short *pln){

	memset( para, '\0', *pln );
	EXEC CICS RETRIEVE INTO( para ) LENGTH( *pln ) RESP(RetCode);

	if( RetCode != DFHRESP(NORMAL) )
	return -1;
	else
	return 0;
}



/******************************************************************************/
/*Advanced Functions----------------------------------------------------------*/

/*
 */
void CreateTsqName(){
unsigned char *pc;
int i;
/*
unsigned long l;
char s[20];	
short int n;

	*s=0;
	n=10;
	EXEC CICS READQ TD QUEUE("ECRS") INTO(s) LENGTH(n) NOHANDLE;

	if(!*s)
	l=0;
	else
	l= (unsigned long)atol(s+1);

	if(l<9999999l)
	l++;
	else
	l=1;

	sprintf(TsqName, "M%07lu", l);
	EXEC CICS WRITEQ TD QUEUE("ECRS") FROM(TsqName) LENGTH(10);
	SetValue0( "_TSQ", TsqName );
*/
/*
	strcpy(TsqName, "VVVVVVVV");
	l= *( (unsigned long *)dfheiptr->eibtaskn );
	sprintf(TsqName, "%08X", l);
*/
	pc= (unsigned char *)dfheiptr->eibtaskn;
	TsqName[0]= 'E';
	TsqName[1]= CicsRegionTag[0];
	TsqName[2]= pc[0] & 0x3F;
	TsqName[3]= pc[1] & 0x3F;
	TsqName[4]= pc[2] & 0x3F;
	TsqName[5]= pc[3] & 0x3F;
	TsqName[6]= (pc[0] >>6 <<2) | (pc[1] >>6);
	TsqName[7]= (pc[2] >>6 <<2) | (pc[3] >>6);

	for(i=2; i<=7; i++)
	TsqName[i] |= 0x40;

	TsqName[8] =0;
	SetValue0( "_TSQ", TsqName );
}


/*
 */
void CreateTsqName1(){
unsigned char *pc;
int i;


	pc= (unsigned char *)dfheiptr->eibtaskn;
	TsqName1[0]= 'E';
	TsqName1[1]= CicsRegionTag[1];
	TsqName1[2]= pc[0] & 0x3F;
	TsqName1[3]= pc[1] & 0x3F;
	TsqName1[4]= pc[2] & 0x3F;
	TsqName1[5]= pc[3] & 0x3F;
	TsqName1[6]= (pc[0] >>6 <<2) | (pc[1] >>6);
	TsqName1[7]= (pc[2] >>6 <<2) | (pc[3] >>6);

	for(i=2; i<=7; i++)
	TsqName1[i] |= 0x40;

	TsqName1[8] =0;

	SetValue0( "_TSQ1", TsqName1 );
}



/*
 */
void SaveBlk(){
short int sn;


if(!RsBlk){
	strcpy(pCommArea,pComm);
	return;
}
else if(RsBlk==1){
	EXEC CICS DELETEQ TS QUEUE(TsqName) NOHANDLE;
}

	sn= strlen(pComm);
/*
	EXEC CICS WRITEQ TS QUEUE(TsqName) FROM(pComm) LENGTH(sn) MAIN NOHANDLE;
*/
	EXEC CICS WRITEQ TS QUEUE(TsqName) FROM(pComm) LENGTH(sn) NOHANDLE;
}



/*
 */
void TsqFetchRows(char *SysId1){
char s[32];
short int sn;


	GetValue0( "_BLK", s );
	RsBlk= atoi(s);

if(!RsBlk){
	EXEC CICS RETURN;
}

	*pComm =0;
	sn= BUF_SIZE-1;
if(!*SysId1){
	EXEC CICS READQ TS QUEUE(TsqName) INTO(pComm) LENGTH(sn) ITEM(RsBlk) NOHANDLE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -