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

📄 yspapi.pc

📁 unix 下用pro*c tuxedo 开发的东西
💻 PC
字号:
#include "stdio.h"
#include "stdlib.h"
#include "sqlcpr.h"
#include "sqlca.h"
#include "/usr/bkfx/include/myapi.h"
#include "/usr/bkfx/include/Pcs_Snd_YS_P/Pcs_Snd_YS_P.h"

void sqlerror()
{
	char tempstring[200];
	char ERR_CODE[10];
	int init_time=0;
	
	ERROR=1;
	EXEC SQL WHENEVER sqlerror continue;
	ProcessError( LOG_ERROR, "PCS_SND_YS_P: ",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_SND_YS_P: Could not connect to the database, so exit now!",END);
			freect(0);
			exit(0);
		}
		InitPcsSndYSP();
		EXEC SQL ROLLBACK WORK;
		return;
	}
	EXEC SQL ROLLBACK WORK;
	return;
}	

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);
}

/*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);
	if( CAline[i]!='\0' )
	exit;
	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';
}

/**  add '0' if sbh is one number  **/

int sbh_format(char *tempstr)
{
	trim(tempstr);
	if( strlen(tempstr)==1 )
	{
		tempstr[2]='\0';
		tempstr[1]=tempstr[0];
		tempstr[0]='0';
	}
	if( strlen(tempstr)==0||strlen(tempstr)>2 )
		return(-1);
	return(0);
}


/* init the main function such as DB environment */
int InitPcsSndYSP()
{
	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 GOTO sqlerror;
	EXEC SQL CONNECT :username IDENTIFIED BY :password;
	return(0);
sqlerror:
	sqlerror();
	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);
}

/* update the table to locate the relative flag */
int UpdateSndLogRecStatus( long int lg_Key )
{
	char temp=SENDED;
	EXEC SQL WHENEVER SQLERROR DO sqlerror();
	EXEC SQL UPDATE T_FSRZ SET SJZT=:temp, JSSJ = SYSDATE WHERE FSXH=:lg_Key;
	EXEC SQL COMMIT WORK;
	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);
}

/*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);
}

/*Get the local sbh specified in the file and return it*/
/* the bsbh will be got from table t_bsbh , not from a file!
int GetBSBH(void)
{
	FILE *hbsbh;
	char cLine[MAX_LINE_LEN+1];
	int iInterval;
	
	hbsbh = fopen( CONFIG_FILE_FOR_BSBH, "r" );
	if( hbsbh == NULL )
	{
		return(DEFAULT_BSBH);  
	}
	
	while( myapi_ReadALinefromF( cLine, hbsbh ) )
	{
		if( cLine[0] == '#' ) continue;
		if( cLine[0] == NULL )continue;
		iInterval = atoi( cLine );
		if(iInterval <= 0) 		
		{
			return(DEFAULT_BSBH);
		}
		else
			return(iInterval);
	}
	fclose( hbsbh );
	return(0);
}
*/
int GetBSBH(void)
{
	int iInterval;
	char bsbh[3];
	EXEC SQL SELECT BSBH INTO :bsbh FROM T_BSBH;
	iInterval = atoi( bsbh );
	return( iInterval );
}

/* change the int varible to the string */
void itoa(long The_int_data, char* The_out_string, int j)
{
	char exch_str[12];
	char a;
	int i=0, n, the_mod;
	The_out_string[0]='\0';
	
	/* if the int varible is zero, then ...*/
	if (The_int_data==0)
	{
		exch_str[0]='0';
		exch_str[1]='\0';
		
		
		strcat( The_out_string, exch_str);
		for(n=1;n<j-1;n++)
		The_out_string[n]=' ';
		The_out_string[n]='\0';
		return;
	}
	
	
	while(1)
	{
		
		the_mod = The_int_data%10;
		exch_str[i] = (char )(the_mod+48);
		exch_str[i+1] = '\0';
		i++;
		
		/* change the last digit to char */
		if((The_int_data = (The_int_data/10))<10) 
		{
			exch_str[i] = (char)(The_int_data+48);
			exch_str[i+1] = '\0';
			break;
		}

	}
	
	/* overtrun the order */
	for(n=0;n<=i;n++)
	The_out_string[n] = exch_str[i-n];
	for(n=i+1;n<j-1;n++)
	The_out_string[n]=' ';
	The_out_string[n]='\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';
	
	
}

/**  get sbh from bkdh  **/

void getsbh(char *bkdh,char *tempstring)
{
	tempstring[0]=bkdh[0];
	if ( bkdh[1]!='-' )
	{
		tempstring[1]=bkdh[1];
		tempstring[2]='\0';
	}
	else 
	tempstring[1]='\0';
}

/**  add ' ' to format a string to a appointed length  **/

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[n-1]='\0';
}
int MQBKSend( void )
{
	return(0);
}

⌨️ 快捷键说明

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