📄 binsrc.c
字号:
/*
* Copyright 2006 by Texas Instruments Incorporated.
* All rights reserved. Property of Texas Instruments Incorporated.
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
*
* @(#) TCP/IP_Network_Developers_Kit 1.91.00.08 08-22-2006 (ndk-a08)
*/
#include <stdio.h>
#include <ctype.h>
unsigned char buffer[0x2000];
main(argc,argv)
int argc;
char *argv[];
{
FILE *infile,*outfile;
int tmp = 0;
long size,ltmp;
unsigned char *pc;
if (argc != 4)
{
printf("\nUsage: BINSRC [InFile] [OutFile] [Name]\n");
exit(1);
}
if (!(infile = fopen(argv[1],"rb")))
{ printf("Can't open source file: %s\n",argv[1]); exit(1); }
// Get the file size
fseek( infile, 0, SEEK_END );
size = ftell( infile );
rewind( infile );
printf("Input File : %s\n",argv[1]);
printf("File Size : %ld\n",size);
if (!(outfile = fopen(argv[2],"wb")))
{ printf("Can't open output file: %s\n",argv[2]); exit(1); }
printf("Output File: %s\n",argv[2]);
fprintf( outfile, "#define %s_SIZE %ld\r\n", argv[3], size );
fprintf( outfile, "unsigned char %s[] = {\r\n ", argv[3] );
tmp = 0;
while( size )
{
if( size >= sizeof(buffer) )
ltmp = sizeof(buffer);
else
ltmp = size;
fread(buffer,1,(short)ltmp,infile);
pc = buffer;
size -= ltmp;
while( ltmp-- )
{
if( size || ltmp )
{
fprintf(outfile,"0x%02X, ",*pc++);
if( !(++tmp % 12) )
fprintf(outfile,"\r\n ");
}
else
fprintf(outfile,"0x%02X };\r\n",*pc++);
}
}
fclose(infile);
fclose(outfile);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -