#include <io.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void main(int argc,char * argv[])
{
int i,iLen,iVerLine,iCRs,iPos;
unsigned char v1,v2,v3,strBuf[1024],strTmp[5];
FILE * fp;
if(argc < 3) // 必须有两个参数
{
printf("\n*** Usage: EXE [Ver File Name] [Ver Message Line] ***\n");
exit(0);
}
// 将数据文件读入内存,不得超过1024Bytes
if( ( fp = fopen(argv[1], "rb") ) == NULL )
{
printf("\n*** Can't Open Version File! ***\n");
exit(0);
}
// 必须定义有效行号
if( (iVerLine = atoi(argv[2])) <= 0)
{
printf("\n*** Invalid Line Number Specified! ***\n");
exit(0);
}
// 取文件长度
fseek(fp, 0, SEEK_END);
iLen = ftell(fp);
// 确定 Version 起始位置
iPos = 0;
iCRs = 1;
fseek(fp, 0, SEEK_SET);
for(i=0;i<iLen;i++)
{
strBuf = fgetc(fp);
if(iCRs == iVerLine && iPos == 0)
{
if(strBuf >= '0' && strBuf <= '9')
iPos = i;
}
if(strBuf == 0x0A)
iCRs++;
}
fclose(fp);
// 编译计数器及版本号增加处理
i = atoi(&strBuf[iPos+6]);
v1 = strBuf[iPos+0];
v2 = strBuf[iPos+2];
v3 = strBuf[iPos+4];
i++;
if(i > 9999)
{
i = 1;
v3++;
if(v3 > '9')
{
v3 = '0';
v2++;
if(v2 > '9')
{
v2 = '0';
v1++;
}
}
}
strBuf[iPos+0] = v1;
strBuf[iPos+2] = v2;
strBuf[iPos+4] = v3;
sprintf(strTmp,"%04d",i);
for(i=0;i<4;i++)
strBuf[iPos+i+6] = strTmp;
// 将结果写入文件
if( ( fp = fopen(argv[1], "wb") ) == NULL )
{
printf("\n*** Can't Write File! ***\n");
exit(0);
}
for(i=0;i<iLen;i++)
fputc(strBuf,fp);
fclose(fp);
// 显示更改后的版本号
printf("\n***** Build:%s *****\n",strTmp);
exit(0);
} |