代码拉取完成,页面将自动刷新
同步操作将从 Safly已存在/MergeHex 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include<direct.h>
/*
path : 文件路径
返回值:文件行数(hex文件每行44列)
*/
int GetFileLIine(char * path)
{
int i = 0;
// char j = 0;
char str[45];
FILE *fp;
// printf("Path: %s \n",path);
if( (fp = fopen(path, "r")) == NULL )
printf("fail to open the file path:%s! \n",path);
while(fgets(str,45,fp))
{
i++;
}
//printf("Path: %s,line number:%d \n",path,i);
/* while((j=fgetc(fp))!=EOF)//fgetc读取一个字符,当读到结尾会返回EOF
{
if(j=='\n')//读取到回车符i++
{
i++;
}
}*/
fclose(fp);
return i;
}
/*
路径处理
flag: 1表示遇到'\'需要进行增加一个'\'处理, 0表示不需要处理
*/
int FileNameHandle( char * ParaPath, char * TargetPath, int flag)
{
char * CurrentPath;
int i = 0,j = 0, k = 0;
int PathLevel = 0,PathLast = 0;
// 获取传入的参数路径有多少个上级目录,也就是"..\"的个数
for(i = 0; (ParaPath[i] == '\\')||(ParaPath[i] == '.'); i++)
{
if((ParaPath[i] == '.')&&(ParaPath[i-1] == '.'))
{
PathLevel++;
}
}
//printf("ParaPath:%s\n",ParaPath);
//printf("PathLevel:%d i is:%d\n",PathLevel,i);
// 获取当前绝对路径
if((CurrentPath = getcwd(NULL,0))==NULL)
{
perror("getcwd error");
}
//printf("CurrentPath: %s\n",CurrentPath);
// 当前绝对路径字符串由后往前遍历,根据上级目录个数PathLevel,去掉多余路径,得到参数路径的绝对路径
for(i = strlen(CurrentPath)-1; PathLast < PathLevel; i--)
{
if(CurrentPath[i] == '\\')
{
PathLast++;
}
}
//printf("PathLast:%d i is:%d\n",PathLast,i);
// 将处理后的当前绝对路径,赋值到目标路径的前面
for(j = 0,k = 0; j <= i; j++)
{
TargetPath[k++] = CurrentPath[j];
if(flag)
if(CurrentPath[j] == '\\')
TargetPath[k++] = '\\';
}
TargetPath[k]='\0';
//printf("TargetPath:%s\n",TargetPath);
for(i = 0; ParaPath[i] != '\0'; i++)
{
if(ParaPath[i] != '.')
{
TargetPath[k++] = ParaPath[i];
if(flag)
if(ParaPath[i] == '\\')
TargetPath[k++] = ParaPath[i];
}
if((ParaPath[i] == '.')&&((ParaPath[i-1] != '.')&&(ParaPath[i+1] != '.')))
TargetPath[k++] = ParaPath[i];
}
TargetPath[k] = '\0';
//printf("TargetPath:%s\n",TargetPath);
free(CurrentPath);
return k;
}
int FileHandle(char * path1,char * path2,char * path3,char * path4)
{
FILE *fp1;
FILE *fp2;
FILE *fp3;
char str[45];
char * mergeflie;
int i = 0;
int k1 = 0,k2 = 0;
char CurrentPath[2048];
FileNameHandle(path4,CurrentPath,0);
k1 = GetFileLIine(path1);
k2 = GetFileLIine(path2);
mergeflie = (char *)malloc((k1+k2)*45);
mergeflie[0] = '\0';
if( (fp1 = fopen(path1, "r")) == NULL )
printf("fail to open the file path:%s! \n",path1);
for(i = 0; i < k1-2; i++)
{
fgets(str,45,fp1);
strcat(mergeflie,str);
}
fclose(fp1);
//printf("Path: %s,line number:%d \n",path1,i);
if( (fp2 = fopen(path2, "r")) == NULL )
printf("fail to open the file path:%s! \n",path2);
//printf("k2-1:%d\n",k2-1);
fgets(str,45,fp2);
for(i = 0; i< k2-1; i++)
{
fgets(str,45,fp2);
strcat(mergeflie,str);
//printf("strcat:%d\n",i);
}
fclose(fp2);
//printf("Path: %s,line number:%d \n",path2,i);
// printf("%s",mergeflie);
i = strlen(mergeflie);
mergeflie[i] = '\n';
if( (fp3 = fopen(path3, "w")) == NULL )
printf("fail to open the file path:%s! \n",path3);
else
{
fwrite(mergeflie,strlen(mergeflie),1,fp3);
printf("creat %s success!\n",CurrentPath); // 打印参数传入的原始路径
}
fclose(fp3);
free(mergeflie);
return 0;
}
int main(int argc, char **argv)
{
char path[3][2048];
if (argc < 4)
{
printf("error!\n");
printf("参数缺失\n");
return -1;
}
FileNameHandle(argv[1],path[0],1); // bootloader path
FileNameHandle(argv[2],path[1],1); // app path
FileNameHandle(argv[3],path[2],1); // mergeHex path
//printf("handle path is:%s\n",path[0]);
//printf("handle path is:%s\n",path[1]);
//printf("handle path is:%s\n",path[2]);
FileHandle(path[0],path[1],path[2],argv[3]);
//while(1);
return 0;
}
/*
int main()
{
// char path[80] = {"E:\\test\\Uboot.hex"};
char path[80] = {"..\\Uboot.hex"};
char * Path[3] = {"E:\\LXW work\\1.STM32_test\\codeblocks_test\\mergeHEX\\bin\\Debug\\Uboot.txt","E:\\test\\Uboot.txt","E:\\test\\merge.hex"};
char argv[3][2048];
FileNameHandle(path,argv[1]); // bootloader path
// File(path,Path[1],Path[2]);
return 0;
}
*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。