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

📄 #my_api.c#

📁 unix 下用pro*c tuxedo 开发的东西
💻 C#
📖 第 1 页 / 共 2 页
字号:
	//The first line should be the file name.

	if( !myapi_ReadALine( cLine, hOriginalFile ) ) return;

	

	//Add suffix to form a unique file name if the file already exists

	sprintf( cFileName, "%s%s", DEPART_DIRECTORY, cLine );

	myapi_FormUniqueName( cFileName );



	//Create a new file for write	

	hGHFile = fopen( cFileName, "w" );

	if( hGHFile == NULL )

	{

		sDescription = (char *)malloc(1000);

		sprintf( sDescription, "PCS_Depart_Src_File: Cannot create file: %s!,Maybe there\

 is no enough disk space.",cFileName );

		ProcessError( LOG_ERROR, sDescription );

		free( sDescription );

		return;

	}

	

	//Write the content to GH file

	while( myapi_ReadALine( cLine, hOriginalFile ) )

	{

		//End process

		if( (cLine[0] == 'X') && (cLine[1] == 'X') && (cLine[2] == 'X'))

				break;



		//Normal write

		if( EOF == fputs( cLine, hGHFile ) )

		{

			printf( "%s\n", cLine );

			sDescription = (char *)malloc(1000);

			sprintf( sDescription, "PCS_Depart_Src_File: Cannot write file: %s!",cFileName );

			ProcessError( LOG_ERROR, sDescription );

			free( sDescription );

			continue;

		}

		if( EOF == fputc( '\n', hGHFile ) )

		{

			sDescription = (char *)malloc(1000);

			sprintf( sDescription, "PCS_Depart_Src_File: Cannot write file: %s!",cFileName );

			ProcessError( LOG_ERROR, sDescription );

			free( sDescription );

			continue;

		}

	}



	fclose( hGHFile );

		

	//Find the currespond program name to continue process.

	for( iIndex=0; iIndex<TOTAL_FILE_TYPE; iIndex++ )

	{

		if( !strncmp( cTypeArray[iIndex], "GHFILE", 6 ) )

		{

			sprintf( cCommand, "%s %s&\n", cProgramArray[iIndex], \

cFileName );

#ifndef DEBUG

			system( cCommand );

#endif			

			return;			

		}

	}

	

	//If cannot find the correspond process program

//	sDescription = (char *)malloc(1000);

	ProcessError( LOG_ERROR, "PCS_Depart_Src_File: Cannot find the program file to process: GHFile!\n" );

//	free( sDescription );



}







//

//"XXX4"

//Form BKML file, do not close handle.

//

void myapi_Form_BKMLFile( char* cLine, FILE* hOriginalFile )

{



	int iIndex;

	char* sDescription;

	char cFileName[MAX_LINE_LEN+1], cCommand[200];

	char cShortFileName[MAX_LINE_LEN+1];

	FILE* hBKMLFile;

	

	//The first line should be the file name.

	if( !myapi_ReadALine( cLine, hOriginalFile ) ) return;

	strcpy( cShortFileName, cLine );

	

	//Add suffix to form a unique file name if the file already exists

	sprintf( cFileName, "%s%s", DEPART_DIRECTORY, cLine );

	myapi_FormUniqueName( cFileName );



	//Create a new file for write	

	hBKMLFile = fopen( cFileName, "w" );

	if( hBKMLFile == NULL )

	{

		sDescription = (char *)malloc(1000);

		sprintf( sDescription, "PCS_Depart_Src_File: Cannot create file: %s!,Maybe there\

 is no enough disk space.",cFileName );

		ProcessError( LOG_ERROR, sDescription );

		free( sDescription );

		return;

	}

	

	//Write the content to BKML file

	while( myapi_ReadALine( cLine, hOriginalFile ) )

	{

		//End process

		if( (cLine[0] == 'X') && (cLine[1] == 'X') && (cLine[2] == 'X'))

				break;



		//Normal write

		if( EOF == fputs( cLine, hBKMLFile ) )

		{

			printf( "%s\n", cLine );

			sDescription = (char *)malloc(1000);

			sprintf( sDescription, "PCS_Depart_Src_File: Cannot write file: %s!",cFileName );

			ProcessError( LOG_ERROR, sDescription );

			free( sDescription );

			continue;

		}

		if( EOF == fputc( '\n', hBKMLFile ) )

		{

			sDescription = (char *)malloc(1000);

			sprintf( sDescription, "PCS_Depart_Src_File: Cannot write file: %s!",cFileName );

			ProcessError( LOG_ERROR, sDescription );

			free( sDescription );

			continue;

		}

	}



	fclose( hBKMLFile );

		

	//Find the currespond program name to continue process.

	if( !strncmp( cShortFileName, "BSFX", 4 ) )

	{

		for( iIndex=0; iIndex<TOTAL_FILE_TYPE; iIndex++ )

		{

			if( !strncmp( cTypeArray[iIndex], "BSFXFILE", 10 ) )

			{

				sprintf( cCommand, "%s %s&\n", cProgramArray[iIndex], \

cFileName );

#ifndef DEBUG

				system( cCommand );

#endif				

				return;			

			}

		}

		//If cannot find the correspond process program

//		sDescription = (char *)malloc(1000);

		ProcessError( LOG_ERROR, "PCS_Depart_Src_File: Cannot find the program file to process: BSFXBKMLFile!\n" );

//		free( sDescription );

	}

	else if( !strncmp( cShortFileName, "BKML", 4 ) )

	{

		for( iIndex=0; iIndex<TOTAL_FILE_TYPE; iIndex++ )

		{

			if( !strncmp( cTypeArray[iIndex], "BKJHMLFILE", 10 ) )

			{

				sprintf( cCommand, "%s %s&\n", cProgramArray[iIndex], \

cFileName );

#ifndef DEBUG

				system( cCommand );

#endif				

				return;			

			}

		}

		//If cannot find the correspond process program

//		sDescription = (char *)malloc(1000);

		ProcessError( LOG_ERROR, "PCS_Depart_Src_File: Cannot find the program file to process: BKJHMLFile!\n" );

//		free( sDescription );

	}



}







//

//"XXX5"

//Form SNML file, do not close handle.

//

void myapi_Form_SNMLFile( char* cLine, FILE* hOriginalFile )

{



	int iIndex;

	char* sDescription;

	char cFileName[MAX_LINE_LEN+1], cCommand[200];

	FILE* hSNMLFile;

	

	//The first line should be the file name.

	if( !myapi_ReadALine( cLine, hOriginalFile ) ) return;

	

	//Add suffix to form a unique file name if the file already exists

	sprintf( cFileName, "%s%s", DEPART_DIRECTORY, cLine );

	myapi_FormUniqueName( cFileName );



	//Create a new file for write	

	hSNMLFile = fopen( cFileName, "w" );

	if( hSNMLFile == NULL )

	{

		sDescription = (char *)malloc(1000);

		sprintf( sDescription, "PCS_Depart_Src_File: Cannot create file: %s!,Maybe there\

 is no enough disk space.",cFileName );

		ProcessError( LOG_ERROR, sDescription );

		free( sDescription );

		return;

	}

	

	//Write the content to SNML file

	while( myapi_ReadALine( cLine, hOriginalFile ) )

	{

		//End process

		if( (cLine[0] == 'X') && (cLine[1] == 'X') && (cLine[2] == 'X'))

				break;



		//Normal write

		if( EOF == fputs( cLine, hSNMLFile ) )

		{

			printf( "%s\n", cLine );

			sDescription = (char *)malloc(1000);

			sprintf( sDescription, "PCS_Depart_Src_File: Cannot write file: %s!",cFileName );

			ProcessError( LOG_ERROR, sDescription );

			free( sDescription );

			continue;

		}

		if( EOF == fputc( '\n', hSNMLFile ) )

		{

			sDescription = (char *)malloc(1000);

			sprintf( sDescription, "PCS_Depart_Src_File: Cannot write file: %s!",cFileName );

			ProcessError( LOG_ERROR, sDescription );

			free( sDescription );

			continue;

		}

	}



	fclose( hSNMLFile );

		

	//Find the currespond program name to continue process.

	for( iIndex=0; iIndex<TOTAL_FILE_TYPE; iIndex++ )

	{

		if( !strncmp( cTypeArray[iIndex], "SNMLFILE", 8 ) )

		{

			sprintf( cCommand, "%s %s&\n", cProgramArray[iIndex], \

cFileName );

#ifndef DEBUG

			system( cCommand );

#endif			

			return;			

		}

	}

	

	//If cannot find the correspond process program

//	sDescription = (char *)malloc(1000);

	ProcessError( LOG_ERROR, "PCS_Depart_Src_File: Cannot find the program file to process: SNMLFile!\n" );

//	free( sDescription );



}





//

//"X0X0"

//Form YSSJ file, do not close handle.

//

void myapi_Form_YSSJFile( char* cLine, FILE* hOriginalFile )

{



	int iIndex;

	char* sDescription;

	char cFileName[MAX_LINE_LEN+1], cCommand[200];

	FILE* hYSSJFile;

	

	

	//Find the currespond program name to continue process.

	for( iIndex=0; iIndex<TOTAL_FILE_TYPE; iIndex++ )

	{

		if( !strncmp( cTypeArray[iIndex], "YSSJFILE", 8 ) )

		{

			break;			

		}

	}

	//if cannot find the corresponding program

	if( iIndex >= TOTAL_FILE_TYPE )

	{

//		sDescription = (char *)malloc(1000);

		ProcessError( LOG_ERROR, "PCS_Depart_Src_File: Cannot find the program file to process: YSSJFile!\n" );

//		free( sDescription );

		return;

	}

	

	hYSSJFile = NULL;

	//The first line should be the file name.

	while( myapi_ReadALine( cLine, hOriginalFile ) )

	{

		if( myapi_IsFileName( cLine ) )

		{

			//End process

			if( (cLine[0] == 'X') && (cLine[1] == 'X') && (cLine[2] == 'X'))

				break;



			if( hYSSJFile != NULL )

			{

				fclose( hYSSJFile );

				sprintf( cCommand, "%s %s&\n", cProgramArray[iIndex], \

cFileName );

#ifndef DEBUG

				system( cCommand );

#endif				

			}

			

			sprintf( cFileName, "%s%s", DEPART_DIRECTORY, cLine );

			//Add suffix to form a unique file name if the file already exists

			myapi_FormUniqueName( cFileName );

			

			//Create a new file for write	

			hYSSJFile = fopen( cFileName, "w" );

			if( hYSSJFile == NULL )

			{

				sDescription = (char *)malloc(1000);

				sprintf( sDescription, "PCS_Depart_Src_File: Cannot create file: %s!,Maybe there\

 is no enough disk space.",cFileName );

				ProcessError( LOG_ERROR, sDescription );

				free( sDescription );

				return;

			}

		}

		else

		{

			//Normal write

			if( EOF == fputs( cLine, hYSSJFile ) )

			{

				printf( "%s\n", cLine );

				sDescription = (char *)malloc(1000);

				sprintf( sDescription, "PCS_Depart_Src_File: Cannot write file: %s!",cFileName );

				ProcessError( LOG_ERROR, sDescription );

				free( sDescription );

				continue;

			}

			if( EOF == fputc( '\n', hYSSJFile ) )

			{

				sDescription = (char *)malloc(1000);

				sprintf( sDescription, "PCS_Depart_Src_File: Cannot write file: %s!",cFileName );

				ProcessError( LOG_ERROR, sDescription );

				free( sDescription );

				continue;

			}

		}

	}

	if( hYSSJFile != NULL )

	{

		fclose( hYSSJFile );

		sprintf( cCommand, "%s %s&\n", cProgramArray[iIndex], \

cFileName );

#ifndef

		system( cCommand );

#endif		

	}

}







//

//"XXX6"

//Form ZFJBH file, do not close handle.

//

void myapi_Form_ZFJBHFile( char* cLine, FILE* hOriginalFile )

{



	int iIndex;

	char* sDescription;

	char cFileName[MAX_LINE_LEN+1], cCommand[200];

	FILE* hZFJBHFile;

	

	//The first line should be the file name.

	if( !myapi_ReadALine( cLine, hOriginalFile ) ) return;

	

	//Add suffix to form a unique file name if the file already exists

	sprintf( cFileName, "%s%s", DEPART_DIRECTORY, cLine );

	myapi_FormUniqueName( cFileName );



	//Create a new file for write	

	hZFJBHFile = fopen( cFileName, "w" );

	if( hZFJBHFile == NULL )

	{

		sDescription = (char *)malloc(1000);

		sprintf( sDescription, "PCS_Depart_Src_File: Cannot create file: %s!,Maybe there\

 is no enough disk space.",cFileName );

		ProcessError( LOG_ERROR, sDescription );

		free( sDescription );

		return;

	}

	

	//Write the content to ZFJBH file

	while( myapi_ReadALine( cLine, hOriginalFile ) )

	{

		//End process

		if( (cLine[0] == 'X') && (cLine[1] == 'X') && (cLine[2] == 'X'))

				break;



		//Normal write

		if( EOF == fputs( cLine, hZFJBHFile ) )

		{

			printf( "%s\n", cLine );

			sDescription = (char *)malloc(1000);

			sprintf( sDescription, "PCS_Depart_Src_File: Cannot write file: %s!",cFileName );

			ProcessError( LOG_ERROR, sDescription );

			free( sDescription );

			continue;

		}

		if( EOF == fputc( '\n', hZFJBHFile ) )

		{

			sDescription = (char *)malloc(1000);

			sprintf( sDescription, "PCS_Depart_Src_File: Cannot write file: %s!",cFileName );

			ProcessError( LOG_ERROR, sDescription );

			free( sDescription );

			continue;

		}

	}



	fclose( hZFJBHFile );

		

	//Find the currespond program name to continue process.

	for( iIndex=0; iIndex<TOTAL_FILE_TYPE; iIndex++ )

	{

		if( !strncmp( cTypeArray[iIndex], "ZFJBHFILE", 9 ) )

		{

			sprintf( cCommand, "%s %s&\n", cProgramArray[iIndex], \

cFileName );

#ifndef DEBUG

			system( cCommand );

#endif			

			return;			

		}

	}

	

	//If cannot find the correspond process program

//	sDescription = (char *)malloc(1000);

	ProcessError( LOG_ERROR, "PCS_Depart_Src_File: Cannot find the program file to process: ZFJBHFile!\n" );

//	free( sDescription );



}





//

//To determine wether the string is a filename or file content

//Return 1 if the string contain no ','

//Return 0 otherwise

//

int myapi_IsFileName( char *cALine )

{

	char *pLine;

	pLine = cALine;

	while( *pLine != '\0' )

	{

		if( *pLine == ',' ) return (0);

		pLine++;

	}

	return(1);

}





//

//To generic a unique file name based on the file name given.

//First, add suffix "0",then add the suffix by number "1", until there

//is no such file. If 9999 is reached by suffix, "0" is assigned.

//

void myapi_FormUniqueName( char* cFileName )

{

	int i=0;

	FILE* hFileName;

	char cFileContent[100], *pTempFile, *pFileContent;

	

	strcpy( cFileContent, cFileName );

	

	while( MyExistFile( cFileName ) )

	{

		sprintf( cFileName, "%s%i",cFileContent, i++ );

		if( i > 9999 )

		{

			i=0;

			sprintf( cFileName, "%s0", cFileContent );

			return;

		}

	}

}



⌨️ 快捷键说明

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