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

📄 sortlang.c

📁 多国语言排序。在进行炬力软件开发过程中
💻 C
字号:

/********************************************/
/*                                          */
/*                     多国语言排序         */
/*                                          */
/*              HJ.Jang 2008-01-15PM 14:55s */
/*                                          */
/********************************************/

#include<stdio.h>

#define false 0
#define true  1

FILE *fpTmp1,*fpTmp2,*fpTmp3;
int  g_langid;

char searchStr1L[] = {"name="};
char searchStr1C[] = {"NAME="};

char searchStr2L[] = {"string="};
char searchStr2C[] = {"STRING="};
char searchStr2T[] = {"0tring="};

char searchStr3L[] = {"exitexit"};
char searchStr3C[] = {"EXITEXIT"};

struct ItemStruct
{
	char stringItems[500][14];	/*name=12345678_*/
	int  ItemSum;
}ItemSt1, ItemSt2;

char buf[512];

/********************************************/
/*     
/*     将参考文件内的字符串名提取出来
/*     
/********************************************/
void Preprocessor(struct ItemStruct *ItemStTemp, FILE *fpTmp)
{
	long length32 = 0xF0000;
	int  i, j, searchStrLength1, searchStrLength2, searchStrLength3;
	char stringTmp[10];
	char charTmp;
	char langid;
	char equal1, equal2, equal3;
	char cmpStr1, cmpStr2, cmpStr3;

	{
		ItemStTemp->ItemSum = 0;
		i = 0;

		equal1 = false;
		equal3 = false;

		cmpStr1 = false;
		cmpStr3 = false;

		searchStrLength1 = sizeof(searchStr1L)-1;
		searchStrLength3 = sizeof(searchStr3L)-1;

		while(length32)
		{
			charTmp = fgetc(fpTmp);
			length32--;

			if(cmpStr1)
			{
				stringTmp[i] = charTmp;
				if(charTmp == searchStr1L[i] || charTmp == searchStr1C[i])
				{
					i++;
					if(i == searchStrLength1)
					{
						cmpStr1 = false;
						equal1 = true;
						i = 0;
					}
				}
				else
				{
					cmpStr1 = false;
					i = 0;
				}
			}
			else if(cmpStr3)
			{
				stringTmp[i] = charTmp;
				if(charTmp == searchStr3L[i] || charTmp == searchStr3C[i])
				{
					i++;
					if(i == searchStrLength3)
					{
						cmpStr3 = false;
						equal3 = true;
						i = 0;
					}
				}
				else
				{
					cmpStr3 = false;
					i = 0;
				}
			}
			else if(!(equal1 || equal3))
			{
				if(charTmp == searchStr1L[0] || charTmp == searchStr1C[0])
				{
					cmpStr1 = true;
					stringTmp[0] = charTmp;
					i = 1;
				}
				else if(charTmp == searchStr3L[0] || charTmp == searchStr3C[0])
				{
					cmpStr3 = true;
					stringTmp[0] = charTmp;
					i = 1;
				}
				else
				{
					i = 0;
				}
			}

			if(equal1)
			{
				fgets(stringTmp, 10, fpTmp);
				for(j=0; j<10; j++)
				{
					if(stringTmp[j]==0x0d || stringTmp[j]==0x0a)
					{
						stringTmp[j] = 0;
						break;
					}
					stringTmp[8] = 0;
				}
				strcpy(ItemStTemp->stringItems[ItemStTemp->ItemSum], searchStr1L);
				strcat(ItemStTemp->stringItems[ItemStTemp->ItemSum], stringTmp);
				ItemStTemp->ItemSum++;
				equal1 = false;
			}
			else if(equal3)
			{
				equal3 = false;
/*
				for(j=0; j<ItemStTemp->ItemSum; j++)
				{
					fputs(ItemStTemp->stringItems[j], fpTmp3);
					fputc(0x0d, fpTmp3);
					fputc(0x0a, fpTmp3);
				}
*/
				break;
			}
		}
	}
}

void FindNextname(FILE *fpTmpSource)
{
	long length32 = 0xF0000;
	int  i, j, searchStrLength1, searchStrLength2, searchStrLength3;
	char stringTmp[10];
	char charTmp;
	char langid;
	char equal1, equal2, equal3;
	char cmpStr1, cmpStr2, cmpStr3;

	{
		i = 0;
		j = 0;

		equal1 = false;
		equal3 = false;

		cmpStr1 = false;
		cmpStr3 = false;

		searchStrLength1 = sizeof(searchStr1L)-1;
		searchStrLength3 = sizeof(searchStr3L)-1;

		while(length32)
		{
			charTmp = fgetc(fpTmpSource);
			buf[j++] = charTmp;
			length32--;

			if(cmpStr1)
			{
				stringTmp[i] = charTmp;
				if(charTmp == searchStr1L[i] || charTmp == searchStr1C[i])
				{
					i++;
					if(i == searchStrLength1)
					{
						cmpStr1 = false;
						equal1 = true;
						i = 0;
					}
				}
				else
				{
					cmpStr1 = false;
					i = 0;
				}
			}
			else if(cmpStr3)
			{
				stringTmp[i] = charTmp;
				if(charTmp == searchStr3L[i] || charTmp == searchStr3C[i])
				{
					i++;
					if(i == searchStrLength3)
					{
						cmpStr3 = false;
						equal3 = true;
						i = 0;
					}
				}
				else
				{
					cmpStr3 = false;
					i = 0;
				}
			}
			else if(!(equal1 || equal3))
			{
				if(charTmp == searchStr1L[0] || charTmp == searchStr1C[0])
				{
					cmpStr1 = true;
					stringTmp[0] = charTmp;
					i = 1;
				}
				else if(charTmp == searchStr3L[0] || charTmp == searchStr3C[0])
				{
					cmpStr3 = true;
					stringTmp[0] = charTmp;
					i = 1;
				}
				else
				{
					i = 0;
				}
			}

			if(equal1)
			{
				buf[j-5] = 0;
				equal1 = false;
				break;
			}
			else if(equal3)
			{
				buf[j-8] = 0;
				equal3 = false;
				break;
			}
		}
	}
}

void FindAndCopyString(char *ItemString, FILE *fpTmpSource, FILE *fpTmpDest)
{
	long length32 = 0xF0000;
	int  i, j, searchStrLength1, searchStrLength2, searchStrLength3;
	char stringTmp[10];
	char charTmp;
	char langid;
	char equal1, equal2, equal3;
	char cmpStr1, cmpStr2, cmpStr3;

	{
		i = 0;

		equal1 = false;
		cmpStr1 = false;
		for(j=0; j<14; j++)
		{
			if(ItemString[j]==0)
			{
				break;
			}
		}
		searchStrLength1 = j;

		while(length32)
		{
			charTmp = fgetc(fpTmpSource);
			length32--;

			if(cmpStr1)
			{
				if(charTmp == ItemString[i])
				{
					i++;
					if(i == searchStrLength1)
					{
						cmpStr1 = false;
						equal1 = true;
					}
				}
				else
				{
					cmpStr1 = false;
					i = 0;
				}
			}
			else if(!equal1)
			{
				if(charTmp == ItemString[0])
				{
					cmpStr1 = true;
					i = 1;
				}
				else
				{
					i = 0;
				}
			}

			if(equal1)
			{
				charTmp = fgetc(fpTmpSource);
				if(charTmp!=0x0d && charTmp!=' ')	/*防止短名被误处理*/
				{
					equal1 = false;
					continue;
				}
				else
				{
					if(charTmp==0x0d)
					{
						charTmp = fgetc(fpTmpSource);
						charTmp = 0x0a;
					}
				}

				FindNextname(fpTmpSource);
				fputs(ItemString, fpTmpDest);
				if(charTmp == 0x0a)
				{
					fputc(0x0d, fpTmpDest);
				}
				fputc(charTmp, fpTmpDest);
				fputs(buf, fpTmpDest);

				equal1 = false;
				break;
			}
		}
	}
}

void DealFile(struct ItemStruct *ItemStTemp1, struct ItemStruct *ItemStTemp2)
{
	int  i, j, ItemNum, searchStrLength1, searchStrLength2, searchStrLength3;
	char stringTmp[10];
	char charTmp;
	char langid;
	char equal1, equal2, equal3;
	char cmpStr1, cmpStr2, cmpStr3;
	char bHaveItem;

	{
		ItemNum = 0;

		while(ItemNum < ItemStTemp1->ItemSum)	/*先行扫描已存在于源文件内的字符串*/
		{
			for(i=0; i<ItemStTemp2->ItemSum; i++)
			{
				if(0 == strcmp(ItemStTemp1->stringItems[ItemNum], ItemStTemp2->stringItems[i]))
				{
					fseek(fpTmp2, 0, SEEK_SET);
					FindAndCopyString(ItemStTemp2->stringItems[i], fpTmp2, fpTmp3);

					ItemStTemp2->stringItems[i][0] = 0;
					break;
				}
			}
			ItemNum++;
		}
	}

	{
		ItemNum = 0;

		while(ItemNum < ItemStTemp2->ItemSum)	/*再扫描未存在于参考文件内的字符串*/
		{
			if(ItemStTemp2->stringItems[ItemNum][0] != 0)
			{
				fseek(fpTmp2, 0, SEEK_SET);
				FindAndCopyString(ItemStTemp2->stringItems[ItemNum], fpTmp2, fpTmp3);

				ItemStTemp2->stringItems[ItemNum][0] = 0;
			}
			ItemNum++;
		}
		fputs(searchStr3L, fpTmp3);
	}
}

/********************************************/
/*     参数1: 参考文件
/*     参数2: 源文件
/*     参数3: 目标文件
/********************************************/
void main(int argc,char *argv[])
{
	char tcCommand[50];

	argc = argc;
	system("cls");

	/*参考文件  拷贝至临时文件Tmp1 */
	printf("del   Tmp1.Bin\n");
	system("del Tmp1.Bin");
	printf("copy   argv[1]   Tmp1.Bin\n");
	strcpy(tcCommand, "copy ");
	strcat(tcCommand, argv[1]);
	strcat(tcCommand, " Tmp1.Bin");
	system(tcCommand);

	/*源文件  拷贝至临时文件Tmp2 */
	printf("del   Tmp2.Bin\n");
	system("del Tmp2.Bin");
	printf("copy   argv[2]   Tmp2.Bin\n");
	strcpy(tcCommand, "copy ");
	strcat(tcCommand, argv[2]);
	strcat(tcCommand, " Tmp2.Bin");
	system(tcCommand);

	/*临时文件2  拷贝至临时文件Tmp3 */
	printf("del   Tmp3.Bin\n");
	system("del Tmp3.Bin");
	printf("copy   Tmp2.Bin   Tmp3.Bin\n");
	strcpy(tcCommand, "copy Tmp2.Bin Tmp3.Bin");
	system(tcCommand);

	{
		/*统一打开临时文件*/
		if((fpTmp1=fopen("Tmp1.Bin","rb"))==NULL)
		{
			printf("Cannot open Tmp1.Bin\n");
			getch();
			exit(1);
		}

		if((fpTmp2=fopen("Tmp2.Bin","rb"))==NULL)
		{
			printf("Cannot open Tmp2.Bin\n");
			getch();
			exit(1);
		}

		if((fpTmp3=fopen("Tmp3.Bin","wb"))==NULL)
		{
			printf("Cannot open Tmp3.Bin\n");
			getch();
			exit(1);
		}

		/*文件操作*/
		{
			Preprocessor(&ItemSt1, fpTmp1);
			Preprocessor(&ItemSt2, fpTmp2);
			DealFile(&ItemSt1, &ItemSt2);
		}

		/*统一关闭临时文件*/
		fclose(fpTmp1);
		fclose(fpTmp2);
		fclose(fpTmp3);
	}

	/*临时文件Tmp3 拷贝至目标文件3 */
	printf("del   argv[3]\n");
	strcpy(tcCommand, "del ");
	strcat(tcCommand, argv[3]);
	system(tcCommand);

	printf("copy   Tmp3.Bin   argv[3]\n");
	strcpy(tcCommand, "copy ");
	strcat(tcCommand, "Tmp3.Bin ");
	strcat(tcCommand, argv[3]);
	system(tcCommand);

	/*删除过程文件 */
	printf("del   Tmp1.Bin\n");
	strcpy(tcCommand, "del Tmp1.Bin");
	system(tcCommand);
	printf("del   Tmp2.Bin\n");
	strcpy(tcCommand, "del Tmp2.Bin");
	system(tcCommand);
	printf("del   Tmp3.Bin\n");
	strcpy(tcCommand, "del Tmp3.Bin");
	system(tcCommand);
}

⌨️ 快捷键说明

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