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

📄 pcs_fbkj_wjjs.pc

📁 unix 下用pro*c tuxedo 开发的东西
💻 PC
字号:
#include "stdio.h"

#include "stdlib.h"

#include "sqlcpr.h"

#include <fcntl.h>

#include <signal.h>

#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include "/usr/bkfx/include/myapi.h"

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


FILE *h_fbkj_wjjs,*h_temp_jsfile;

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

}


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

}



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 sqlerror()
{
	
	ERROR=1;
	EXEC SQL WHENEVER sqlerror continue;
	ProcessError( LOG_ERROR, "PCS_FBKJ_WJJS: ",sqlca.sqlerrm.sqlerrmc );
	EXEC SQL ROLLBACK WORK;
	return;
}	

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

}


int InitPcsFbkjWjjs()

{

	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 )

	{

		ERROR=0;

		return(-1);

	}

	return(0);

}



int check_fbkj_wjjs(char *dddddd)
{
	char sys_ls_str[200];
	char tmp_fname_str[100];
	char file_len[20],file_date[20];
	int sign_flag,count_i;

	sprintf(sys_ls_str,"%s%s/jsfile",FBKJ_PATH,dddddd);
	h_temp_jsfile=fopen(sys_ls_str,"r");
	if( h_temp_jsfile==NULL )
	{
		EXEC SQL DELETE FROM T_FBKJ_WJJS WHERE FBKJBH=:dddddd;
		return(0);
	}
	fclose(h_temp_jsfile);
	sprintf(sys_ls_str,"ls -l %s%s/jsfile > %s%s/bak/tmp_jszt.txt",FBKJ_PATH,dddddd,FBKJ_PATH,dddddd);
	system(sys_ls_str);

	sprintf(tmp_fname_str,"%s%s/bak/tmp_jszt.txt",FBKJ_PATH,dddddd);
	h_fbkj_wjjs=fopen(tmp_fname_str,"r");
	if( h_fbkj_wjjs==NULL )
	{
		printf("open file %s error\n",tmp_fname_str);
		return(-1);
	}

	sign_flag=myapi_ReadALinefromF(sys_ls_str,h_fbkj_wjjs);
	if( sign_flag==0 )
	{
		fclose(h_fbkj_wjjs);
		EXEC SQL delete from t_fbkj_wjjs where fbkjbh=:dddddd;
		return(0);
	}
	fclose(h_fbkj_wjjs);
	myapi_ReadString(sys_ls_str,file_len,27,39);
	trim(file_len);
	myapi_ReadString(sys_ls_str,file_date,40,52);
	trim(file_date);
	EXEC SQL SELECT count(*) INTO :count_i FROM t_fbkj_wjjs WHERE fbkjbh=:dddddd;
	if( count_i!=0)
	{
		EXEC SQL UPDATE t_fbkj_wjjs SET xgsj=:file_date WHERE fbkjbh=:dddddd;
		EXEC SQL UPDATE t_fbkj_wjjs SET wjlen=:file_len WHERE fbkjbh=:dddddd;
	}
	else 
	{
		EXEC SQL INSERT INTO t_fbkj_wjjs VALUES( :dddddd,:file_len,:file_date,:file_date);
	}
	if ( atol(file_len)==0 )
		EXEC SQL delete from t_fbkj_wjjs where fbkjbh=:dddddd;
	return(0);
	
}

int use_cursor()
{
	char temp_dos,temp_unix;
	int count_fbkj,sign_flag;
	char str_fbkjbh[3];

	temp_dos='0';
	temp_unix='3';
	ERROR=0;
	EXEC SQL WHENEVER SQLERROR DO sqlerror();
	EXEC SQL DECLARE cur_fbkjbh_wjjs CURSOR FOR SELECT fbkjbh FROM t_fbkj
		WHERE jsfs=:temp_dos OR jsfs=:temp_unix;
	EXEC SQL SELECT count(*) INTO :count_fbkj FROM t_fbkj
		WHERE jsfs=:temp_dos OR jsfs=:temp_unix;
	EXEC SQL OPEN cur_fbkjbh_wjjs;
	for( ;count_fbkj>0 ; count_fbkj-- )
	{
		EXEC SQL FETCH cur_fbkjbh_wjjs INTO :str_fbkjbh;
		trim(str_fbkjbh);
		sign_flag = check_fbkj_wjjs(str_fbkjbh);
		if( sign_flag<0 )
		{
			EXEC SQL ROLLBACK WORK;
			return(-1);
		}
	}

	EXEC SQL CLOSE cur_fbkjbh_wjjs;
	EXEC SQL COMMIT WORK ;
	return(0);
}

freect()
{
	EXEC SQL ROLLBACK WORK RELEASE;
	if( h_fbkj_wjjs!=NULL )
		fclose(h_fbkj_wjjs);
	if( h_temp_jsfile!=NULL )
		fclose(h_temp_jsfile);
	exit(0);
}

main()
{
	int sleep_time=10,sign_flag;

	signal(SIGTERM,freect);	
	sign_flag=InitPcsFbkjWjjs();
	if( sign_flag!=0 )
	{
		ProcessError(LOG_ERROR,"PCS_FBKJ_WJJS: cannot connect to database!",END);
		return(-1);
	}

	sleep_time=GetTimeInterval("PCS_FBKJ");
	for(;;)
	{
		use_cursor();
		sleep(sleep_time);
	}

}

⌨️ 快捷键说明

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