lzo压缩文件程序,看不懂它到底实现什么功能,C语言

C语言入门 2019-02-16 11:49:46
我知道是实现了文件的压缩功能,但是不清楚它到底是怎么实现的……有没有人帮忙看一下?

{
FILE *inputfile = NULL,*outputfile = NULL;
if (lzo_init() != LZO_E_OK)
{
printf("internal error - lzo_init() failed !!!\n");
printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
return 3;
}
if (argc < 3)
{
inputfile = fopen("standalone_tcflash.txt","r");
outputfile = fopen("output.bin","wb");
}
else
{
inputfile = fopen(argv[1],"r");
outputfile = fopen(argv[2],"wb");
}
if (!((NULL != inputfile) && (NULL != outputfile)))
{
return -1;
}
else
{
for (unsigned long address = 0;address < 0x10000000;address+= 32768)
{
int ret = 0,i = 0;
for (; i < 32768; i++)
{
if(1 == fscanf(inputfile,"%X",inputdata + i))
{
}
else
{
break;
}
}
for (int temp = i; temp < 32768; temp++)
{
inputdata[temp] = 0xFF;
}
ret = lzo1x_1_compress(inputdata,32768,outputdata,&outputdata_len,wrkmem);
for (int temp = outputdata_len; temp < 32768; temp++)
{
outputdata[temp] = 0xFF;
}
if(0 == ret)
{
fwrite(outputdata,1,outputdata_len,outputfile);
}
if (i != 32768)
{
break;
}
}
fclose(inputfile);
fclose(outputfile);
}

}
...全文
537 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
C语言入门 2019-02-16
  • 打赏
  • 举报
回复
// tests1932k.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include "minilzo.h"

unsigned char inputdata[32 * 1024];
unsigned long inputdata_len = 32 * 1024;

unsigned char outputdata[32 * 1024];
unsigned long outputdata_len = 0;

#define HEAP_ALLOC(var,size) \
lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ]

static HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS);

void outputs19file(const unsigned long address,const unsigned char *data)
{
for (int tempaddr = address; tempaddr < 32; tempaddr++)
{

}
}

int main(int argc, char *argv[])
{
FILE *inputfile = NULL,*outputfile = NULL;
if (lzo_init() != LZO_E_OK)
{
printf("internal error - lzo_init() failed !!!\n");
printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
return 3;
}
if (argc < 3)
{
inputfile = fopen("standalone_tcflash.txt","r");
outputfile = fopen("output.bin","wb");
}
else
{
inputfile = fopen(argv[1],"r");
outputfile = fopen(argv[2],"wb");
}
if (!((NULL != inputfile) && (NULL != outputfile)))
{
return -1;
}
else
{
for (unsigned long address = 0;address < 0x10000000;address+= 32768)
{
int ret = 0,i = 0;
for (; i < 32768; i++)
{
if(1 == fscanf(inputfile,"%X",inputdata + i))
{
}
else
{
break;
}
}
for (int temp = i; temp < 32768; temp++)
{
inputdata[temp] = 0xFF;
}
ret = lzo1x_1_compress(inputdata,32768,outputdata,&outputdata_len,wrkmem);
for (int temp = outputdata_len; temp < 32768; temp++)
{
outputdata[temp] = 0xFF;
}
if(0 == ret)
{
fwrite(outputdata,1,outputdata_len,outputfile);
}
if (i != 32768)
{
break;
}
}
fclose(inputfile);
fclose(outputfile);
}

}

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧