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

📄 ysapi.pc

📁 unix 下用pro*c tuxedo 开发的东西
💻 PC
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>

#include <stdlib.h>

#include <sqlca.h>

#include <time.h>

#include <stddef.h>

#include <fcntl.h>

#include <signal.h>

#include "sqlcpr.h"

#include "/usr/bkfx/include/myapi.h"

#include "/usr/bkfx/include/Pcs_RD_BK_Q_x/Pcs_RD_BK_Q_YS.h"

#include "/usr/bkfx/include/Pcs_RD_BK_Q_x/ysapi.h"



void ProcessError( char *LOG, char *sErrorMessage1, char *sErrorMessage2 )
{
	FILE* hErrorFile;
	char cDateTime[100],tempstr[100];
	int i,j,len,n;
	long filesize;
	char bakfile[100];
	
	tempstr[0]='\0';
	len=strlen(sErrorMessage1);
	for(i=0;i<=len;i++)
	{
		if(sErrorMessage1[i]=='%')
		{			
			n=i;
			if(len!=i+1)
			{
				for(j=0;j<200&&sErrorMessage1[i+2]!='\0';j++,i++)
				tempstr[j]=sErrorMessage1[i+2];
				tempstr[j]='\0';
			}	
			break;
		}
		if(sErrorMessage1[i]=='\0')
		{
			n=i;
			tempstr[0] = '\0';
			break;
		}
			
	}
	
	printf("\n%s",LOG);
	printf("%s",sErrorMessage1);
	printf("%s",sErrorMessage2);
	printf("%s\n",tempstr);

	sErrorMessage1[n]='\0';
	hErrorFile = fopen( ERROR_LOG_FILE, "a" );
	if( hErrorFile == NULL )
	{
		printf( "Critical! Cannot open ERROR_LOG_FILE for append or cannot create!\n");
		return;
	}
	fseek( hErrorFile, 0 ,SEEK_END );
	filesize = ftell(hErrorFile);
	if (filesize > 5242880/5)
	{
		fclose(hErrorFile );
		sprintf(bakfile, "mv %s %s.bak", ERROR_LOG_FILE, ERROR_LOG_FILE);
		system(bakfile);
		hErrorFile = fopen( ERROR_LOG_FILE, "a" );
		if( hErrorFile == NULL )
		{
			printf( "Critical! Cannot open ERROR_LOG_FILE for append or cannot create!\n");
			return;
		}
	}
	fseek( hErrorFile, 0 ,SEEK_END );
	fputs( "\n",hErrorFile);
	fputs( LOG ,hErrorFile);
	fputs( sErrorMessage1,hErrorFile );
	fputs( sErrorMessage2,hErrorFile );
	fputs( tempstr,hErrorFile );
	fputs( "\n",hErrorFile);
	fclose( hErrorFile );

	sprintf( cDateTime, "date >> %s\n", ERROR_LOG_FILE );
	system( cDateTime );
	system( "date");
}

void PutintoF(char *string )
{
	FILE *fp;
	fp=fopen("checkfile.txt","w");
	fputs(string,fp);
	fclose(fp);
}



void sqlerror()
{
	char tempstring[200];
	char ERR_CODE[10];
	int init_time=0;
	
	ERROR=1;
	EXEC SQL WHENEVER sqlerror continue;
	ProcessError( LOG_ERROR, "PCS_RCV_YS: ",sqlca.sqlerrm.sqlerrmc );
	strncpy(ERR_CODE,sqlca.sqlerrm.sqlerrmc,9);
	ERR_CODE[9]='\0';
	if( strcmp(ERR_CODE,"ORA-03127")==0|| strcmp(ERR_CODE,"ORA-03114")==0|| strcmp(ERR_CODE,"ORA-03123")==0|| strcmp(ERR_CODE,"ORA-01034")==0|| strcmp(ERR_CODE,"ORA-01089")==0||strcmp(ERR_CODE,"ORA-01012")==0||strcmp(ERR_CODE,"ORA-01089") ==0||strcmp( ERR_CODE, "ORA-01033") ==0 )
	{
		sleep(INIT_INTERVAL);
		init_time++;
		if (init_time == 6)
		{
			ProcessError(LOG_NORMAL, "PCS_RCV_YS: Could not connect to the database, so exit now!",END);
			freect(0);
			exit(0);
		}
		InitPcsRcvYS();
		EXEC SQL ROLLBACK WORK;
		return;
	}
	EXEC SQL ROLLBACK WORK;
	return;
}	


/************** insert a record into the t_jsrz  ****************/

int CreateRecLogRec(char datatype, char *fssbh ,long int lg_Key )

{

	int i;

	char b;

	b='1';

	ERROR=0;

	EXEC SQL WHENEVER SQLERROR DO sqlerror();

	EXEC SQL INSERT INTO T_JSRZ VALUES (:lg_Key, :datatype, :b,:fssbh, sysdate );

	if( ERROR!=0 )

	{

		ERROR=0;

		return(-1);

	}

	

	return(1);

}



/***  update jsrz  ***/

int UpdateJSRZ_rec( long int lg_key,char *sjbh )

{

	char temp=WAITFORCONVERT;

	EXEC SQL WHENEVER SQLERROR DO sqlerror();

	EXEC SQL UPDATE T_JSRZ SET SJZT=:temp WHERE JSXH=:lg_key AND SJBH=:sjbh;

	if( ERROR!=0 )

	{

		ERROR=0;

		return(-1);

	}

	return(1);

}



/***delete the ' ' or '\n' of a string at the begin and end***/



void trim(char *CAline)

{

	int i,j;

	char temp_string[100];

	i=strlen(CAline);

	while(i>0)		/*delete the end ' ' or '\n' */

	{

		if(CAline[i-1]==' '||CAline[i-1]=='\n')

			CAline[i-1]='\0';

		else

			break;

		i--;

	}

	i=0;j=0;

	while( CAline[i]!='\0' )	/*delete the head ' ' or '\n' */

	{

		if(CAline[i]==' '||CAline[i]=='\n')

			i++;

		else

		{

			for (j=0;CAline[i]!='\0';i++,j++)

				CAline[j]=CAline[i];

			break;	

		}	

	}

	CAline[j]='\0';

}





/* init the main function such as DB environment */

int InitPcsRcvYS()

{

	EXEC SQL BEGIN DECLARE SECTION;

	VARCHAR username[20];

	VARCHAR password[20];

	EXEC SQL END DECLARE SECTION;

	

	strcpy(username.arr,"pcsdba");

	username.len=strlen(username.arr);

	strcpy(password.arr,"dba");

	password.len=strlen(password.arr);

	

	EXEC SQL WHENEVER SQLERROR DO sqlerror();

	EXEC SQL CONNECT :username IDENTIFIED BY :password;

	

	if ( ERROR==0 )

	{

		return(0);

	}

	else 

	{

		ERROR=0;

		return(-1);

	}

}





/*	Read a string from Pstring to Cstring 		*/

/*	m,n define the first point and the last point	*/

int myapi_ReadString(char *Pstring,char *Cstring,int m,int n)

{

	int i,j;

	Cstring[0]='\0';	/*First make the target string as a null string*/

	if( (strlen(Pstring)<n) || (m>n) || (m<0) )

	{	

		return(0);/*Some error when use this function */

	}

	for(i=m,j=0;i<=n;i++,j++)

	{

		Cstring[j]=Pstring[i];

	}

	Cstring[n-m+1]='\0';

	return(1);

}



/* change the int varible to the string */

void itoa(long The_int_data, char* The_out_string, int j)

{

	int size;

	int i;

	j=j-1;

	sprintf(The_out_string, "%d", The_int_data);

	size = strlen(The_out_string);

	for(i=size;i<j;i++)

	The_out_string[i]=' ';

	The_out_string[i]='\0';

}



/* change the float varible to string, the parameter 'm' is the decimal */

void ftoa(float The_float_data, char *The_out_string, int m, int j)		

{

	float dot_data;

	long The_int_body, The_int_data;

	int k=10;

	int i=1,n;

	char First_string[8], End_string[8], dot[2],whole_string[10];

	

	

	The_out_string[0]='\0';

	dot[0]='.';

	dot[1]='\0';

	

	/* if the float equl to zero ,then ... */

	if (The_float_data==0)

	{

		if (m==0)

		{

			First_string[0]='0';

			First_string[1]='\0';

			strcat(The_out_string, First_string);

			for(n=1;n<j-1;n++)

			The_out_string[n]=' ';

			The_out_string[n]='\0';

			return;

		}

		First_string[0]='0';

		First_string[1]='\0';

		strcat(The_out_string, First_string);

		strcat(The_out_string, dot);

		for(n=0;n<m;n++)

		End_string[n]='0';

		End_string[n]='\0';

		strcat(The_out_string, End_string);

		for(n=m+2;n<j-1;n++)

		The_out_string[n]=' ';

		The_out_string[n]='\0';

		return;

	}

	

	

	/* change the float to long varible */

	for(n=1;n<m;n++)

	k = 10*k;

	

	if( (The_float_data*k-(int)(The_float_data*k))<0.5 )

		The_int_body = (int)(The_float_data*k);

	else 

		The_int_body = (int)(The_float_data*k)+1;

	

	/* calculate the digit of the long varible */

	The_int_data = The_int_body;

	while(1)

	{

		if((The_int_data = (The_int_data/10))<10) 

		break;

		i++;

	}

	i++;

	itoa(The_int_body, whole_string, i);

	

	/* if the float varible smaller than 1, then ... */

	if (The_float_data< 1 )

	{

		First_string[0]='0';

		First_string[1]='\0';

		strcat(The_out_string, First_string);

		strcat(The_out_string, dot);

		strcat(The_out_string, whole_string);

		for(n=i+2;n<j-1;n++)

		The_out_string[n]=' ';

		The_out_string[n]='\0';

		return;

	}

	

	/*change the varible to the First_string and End_string seperate by the dot */

	for(n=0;n<i-m;n++)

	First_string[n]=whole_string[n];

	First_string[n]='\0';

	

	for(n=0;n<m;n++)

	End_string[n]=whole_string[i-m+n];

	End_string[n]='\0';

	

	

	

	strcat( The_out_string, First_string );

	strcat( The_out_string, dot );

	strcat( The_out_string, End_string );

	for(n=i+1;n<j-1;n++)

	The_out_string[n]=' ';

	The_out_string[n]='\0';

	

	

}



/* 	add ' ' at the end of a string		*/

/* 	until the length of the string is n	*/

void str_format(char *str,int n)

{

	int i;

	for( i=0;i<n;i++ )

	{

		if(str[i]=='\0')

		break;

	}

	if( i==n )

		str[i-1]='\0';

	for( ;i<n-1;i++ )

	{

		str[i]=' ';

	}

	str[i-1]='\0';

}



/*Get the Time_Interval specified in the file and return it */

int GetTimeInterval(char* cType)

{

	FILE *hTimeInterval;

	char cLine[MAX_LINE_LEN+1], cCaption[100], cValue[21];

	int iInterval, i;

	char* pLine;

	

	 

	hTimeInterval = fopen( CONFIG_FILE_FOR_TIMEINTERVAL, "r" );

	if( hTimeInterval == NULL )

	{

		ProcessError(LOG_ERROR,   "GetTimeInterval: Cannot open file: ", CONFIG_FILE_FOR_TIMEINTERVAL);

		return(DEFAULT_TIMEINTERVAL);  

	}

	

	while( myapi_ReadALine( cLine, hTimeInterval ) )

	{

		if( cLine[0] == '#' ) continue;

		if( cLine[0] == NULL ) continue;

		

		pLine = cLine;

		while( (*pLine == ' ') || (*pLine == '\t') ) pLine++;

		i=0;

		while( (*pLine != ' ') && (*pLine != '\t') && (*pLine != '\0') )

		{

			cCaption[i] = *pLine;

			i++;

			pLine++;

		}

		

		cCaption[i] = '\0';

		if( strcmp( cCaption, cType ) == 0 ) /*Match*/

		{

			while( (*pLine == ' ') || (*pLine == '\t') ) pLine++;

			if( *pLine == '\0' )

			{
				fclose(hTimeInterval);
				return(DEFAULT_TIMEINTERVAL);

			}
			i=0;

			while( (*pLine != ' ') && (*pLine != '\t') && (*pLine != '\0') )

			{

				cValue[i] = *pLine;

				i++;

				pLine++;

			}

			cValue[i] = '\0';

			iInterval = atoi(cValue);

			

			if(iInterval <= 0) 		

			{

				fclose(hTimeInterval);
				return(DEFAULT_TIMEINTERVAL);

			}

			else

			{
				fclose(hTimeInterval);
				return(iInterval);

			}
		}

		else

			continue;

	}

	fclose( hTimeInterval );

	return(DEFAULT_TIMEINTERVAL);

}



/*Read a line to a string from a file, \n is excluded.

  return 1 if sucessful, 0 otherwise

  Do not close the file.*/

int myapi_ReadALine( char* cLine, FILE* hTable )

{

	char cChar;

	int i=0;

	cLine[0] = '\0';

	while( (cChar = fgetc( hTable )) != '\n' )

	{

		if( cChar == EOF ) return(0);

		cLine[i++] = cChar;

		

		

		if( i >= MAX_LINE_LEN ) i=0;

		cLine[i] = '\0';

	}

	return(1);

}



/*

Read a line to a string from a file, "\n" is excluded.

return 1 if sucessful, 0 otherwise

Do not close the file.

*/



int myapi_ReadALinefromF( char *cALine,FILE *hTable )

{

	char cChar='\0';

	int i=0;

	cALine[0] = '\0';

	while( (cChar = fgetc( hTable )) != '\n' )

	{

		if( cChar == EOF ) return(0);

		cALine[i++] = cChar;

		

		if( i >= MAX_LINE_LEN ) i=0;

		cALine[i] = '\0';	/* define the end of a string */

	}

	return(1);

}



/***  convert from message to stZDSM  ***/



int ZDYSSMRcv( char *message,struct stZDYSMsgHeader *stZDSM )

{

	int flag=0;

	flag+=myapi_ReadString(message,stZDSM->fsxh,0,9);

	flag+=myapi_ReadString(message,stZDSM->jssbh,10,11);

	flag+=myapi_ReadString(message,stZDSM->fssbh,12,13);

	flag+=myapi_ReadString(message,stZDSM->bkdh,14,20);

	flag+=myapi_ReadString(message,stZDSM->yslx,21,21);

	flag+=myapi_ReadString(message,stZDSM->wjbh,22,23);

	flag+=myapi_ReadString(message,stZDSM->qdqa,24,25);

	flag+=myapi_ReadString(message,stZDSM->kq,26,31);

	flag+=myapi_ReadString(message,stZDSM->dingj,32,38);

	flag+=myapi_ReadString(message,stZDSM->dyzs,39,48);

	flag+=myapi_ReadString(message,stZDSM->dyk,49,59);

	flag+=myapi_ReadString(message,stZDSM->lszs,60,69);

	flag+=myapi_ReadString(message,stZDSM->lsk,70,80);

	flag+=myapi_ReadString(message,stZDSM->yxnf,81,84);

	if( flag!=14 )

		return(-1);

	return(0);

}



/***  convert from message to stZDSJ  ***/



int ZDYSSJRcv( char *message,struct stZDYSMsgRec *stZDSJ )

{

	int flag=0;

	flag+=myapi_ReadString(message,stZDSJ->zfjbh,zdnumpoint,zdnumpoint+7);

	flag+=myapi_ReadString(message,stZDSJ->yffs ,zdnumpoint+8,zdnumpoint+14);

	flag+=myapi_ReadString(message,stZDSJ->qzlss,zdnumpoint+15,zdnumpoint+21);

	if( flag!=3 )

		return(-1);

	zdnumpoint+=22;		/*** it is a full varible  ***/

	return(0);

}



/***  convert from message to stPDSM  ***/



int PDYSSMRcv( char *message,struct stPDYSMsgHeader *stPDSM )

{

	int flag=0;

	flag+=myapi_ReadString(message,stPDSM->fsxh,0,9);

	flag+=myapi_ReadString(message,stPDSM->jssbh,10,11);

	flag+=myapi_ReadString(message,stPDSM->fssbh,12,13);

	flag+=myapi_ReadString(message,stPDSM->bkdh,14,20);

	flag+=myapi_ReadString(message,stPDSM->yslx,21,21);

	flag+=myapi_ReadString(message,stPDSM->wjbh,22,23);

	flag+=myapi_ReadString(message,stPDSM->qdqa,24,25);

	flag+=myapi_ReadString(message,stPDSM->qdqb,26,27);

	flag+=myapi_ReadString(message,stPDSM->zdqa,28,29);

	flag+=myapi_ReadString(message,stPDSM->zdqb,30,31);

	flag+=myapi_ReadString(message,stPDSM->kq,32,37);

	flag+=myapi_ReadString(message,stPDSM->dingj,38,44);

	flag+=myapi_ReadString(message,stPDSM->dyzs,45,54);

	flag+=myapi_ReadString(message,stPDSM->dyk,55,65);

	flag+=myapi_ReadString(message,stPDSM->lszs,66,75);

	flag+=myapi_ReadString(message,stPDSM->lsk,76,86);

	flag+=myapi_ReadString(message,stPDSM->yxnf,87,90);

	if( flag!=17 )

		return(-1);

	return(0);

}



/***  convert from message to stPDSJ  ***/



int PDYSSJRcv( char *message,struct stPDYSMsgRec *stPDSJ )

{

	int flag=0;

	flag+=myapi_ReadString(message,stPDSJ->zfjbh,pdnumpoint,pdnumpoint+7);

	flag+=myapi_ReadString(message,stPDSJ->zjfs ,pdnumpoint+8,pdnumpoint+14);

	flag+=myapi_ReadString(message,stPDSJ->lszjfs,pdnumpoint+15,pdnumpoint+21);

	if( flag!=3 )

		return(-1);

	pdnumpoint+=22;		/* it is a full varible */

	return(0);

}


⌨️ 快捷键说明

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