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

📄 convapi.pc

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

#include "stdlib.h"

#include "sqlcpr.h"

#include <fcntl.h>

#include <signal.h>

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

#include "/usr/bkfx/include/Pcs_Convert_File/convapi.h"

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


void freect(int i)

{

	if( message!=NULL )

	free(message);

	if( messagesj!=NULL )

	free(messagesj);

	if( messagepd!=NULL )

	free(messagepd);

	if( messagepdsj!=NULL )

	free(messagepdsj);

	if( messagebkml!=NULL )

	free(messagebkml);

	if( buf!=NULL )
	free(buf);
	if( buf_sj!=NULL )
	free(buf_sj);

	if( h_zdys!=NULL )

	fclose(h_zdys);

	if( h_zdsj!=NULL )

	fclose(h_zdsj);

	if( h_pdys!=NULL )

	fclose(h_pdys);

	if( h_pdsj!=NULL )

	fclose(h_pdsj);

	if( h_gh!=NULL )

	fclose(h_gh);

	if( h_tjbb!=NULL )

	fclose(h_tjbb);

	if( h_bkml!=NULL )

	fclose(h_bkml);

	if( h_zfj!=NULL )

	fclose(h_zfj);

	if( h_yx!=NULL )

	fclose(h_yx);


	if( h_sm!=NULL )

	fclose(h_sm);

	if( h_sj!=NULL )

	fclose(h_sj);

	if( h_bag!=NULL )

	fclose(h_bag);


	EXEC SQL ROLLBACK WORK RELEASE;

	exit(0);
}



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


/* write the errorlog file when the database is wrong */
void sqlerror()
{
	char tempstring[200];
	char ERR_CODE[10];
	int init_time=0;
	
	ERROR=1;
	EXEC SQL WHENEVER sqlerror continue;
	ProcessError( LOG_ERROR, "PCS_CONVERT_FILE: ",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_CONVERT_FILE :Could not connect to the database, so exit now!",END);
			freect(0);
			exit(0);
		}
		InitPcsConvertFile();
		EXEC SQL ROLLBACK WORK;
		return;
	}
	EXEC SQL ROLLBACK WORK;
	return;
}	


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

}



/* change the int varible to the string */

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

{

	int k;

	char tmp[]="               ";

	char tempstr[15];

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

	k=strlen(The_out_string);

	if( k>=j )

		return;

	strncpy(tempstr,tmp,(j-k));

	tempstr[j-k]='\0';

	strcat(tempstr,The_out_string);

	strcpy(The_out_string,tempstr);

}

/*

{

	char exch_str[12];

	char a;

	int i=0, n, the_mod;

	The_out_string[0]='\0';

	

	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++;

		

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

		{

			exch_str[i] = (char)(The_int_data+48);

			exch_str[i+1] = '\0';

			break;

		}



	}

	

	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';

	

	

}



/*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';

}



int InitPcsConvertFile()

{

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

⌨️ 快捷键说明

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