📄 hex2aray.c
字号:
/*==============================================================================
//File : hex2aray.c
//Take an ASCII file generated by hex6x converter and convert it
//in an array of byte in C language.
//
//Date : November 26, 1997
//Author : Eric Biscondi
//Modification :
//
// (c) Copyright Texas Instruments France
//============================================================================*/
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <string.h>
#include <time.h>
extern directvideo;
void main(int argc,char *argv[])
{
char c[3];
char s;
FILE *out_file,*in_file;
char chn_fileo[32],chn_filei[32], name_array[32], charac;
int i,i1,in,out,out1,out2,line_count, zero_count, j, zero;
zero = 0x30;
/*arguments coming from the shell -------------------------------*/
if (argc<5)
{
printf ("dspc6x [-i <file_in>] [-o <file_out>]\n");
return;
}
/*initialisation with shell's arguments----------------------------*/
for (i=1; i<(argc); i++)
{
if (!strcmp(strlwr(argv[i]),"-i"))
{
if (++i<=argc)
{
strcpy(chn_filei,argv[i]);
}
}
else if (!strcmp(strlwr(argv[i]),"-o"))
{
if (++i<=argc)
{
strcpy(chn_fileo,argv[i]);
}
}
else
{
printf ("dspc6x [-i <file_in>] [-o <file_out>]\n");
}
}
/*open in file-----------------------------------------------------*/
if ((in_file = fopen(chn_filei,"rb")) == NULL)
{
printf("Unable to open input file \n");
exit (1);
}
if ((out_file = fopen(chn_fileo,"wb")) == NULL)
{
printf("Unable to open output file \n");
exit (1);
}
// gettime(&t);
// getdate(&d);
// fprintf(out_file,"/***************************************************************************/\n");
// fprintf(out_file,"/* Header file containing C6x code generated from HEX2ARAY.EXE */\n");
// fprintf(out_file,"/* */\n");
// fprintf(out_file,"/* */\n");
// fprintf(out_file,"/* */\n");
// fprintf(out_file,"/* (c) Copyright Texas Instruments*/\n");
// fprintf(out_file,"/***************************************************************************/\n");
/* Suppress the file name extension */
i=0;
do
{
sscanf(chn_fileo,"%1s %s", &name_array[i], &chn_fileo);
}while( name_array[i++] != '.');
name_array[i-1]='\0';
//printf(out_file, "\n\n\nconst char %s[]={",name_array);
line_count = 0;
zero_count = 0;
while((in = fgetc(in_file)) != EOF)
{
i = in&0x0ff;
switch(i) {
case(0x02):
break;
case(0x20):
break;
case(0x0d):
break;
case(0x0a):
break;
case(0x24): /* Case $ */
while( (in=fgetc(in_file)) != 0x0a);
break;
default:
if( (in = fgetc(in_file)) == EOF) break;
i1 = in&0x0ff;
if( (i==0x30) && (i1==0x30) ) /* Zero detection */ {
zero_count++;
}
else {
if(zero_count != 0) {
for(j=0 ; j < zero_count ; j++)
{
line_count++;
//printf(out_file,"0x");
//fputc(zero, out_file);
//fputc(zero, out_file);
s = 0;
fwrite(&s, 1, 1, out_file);
//printf(out_file,","); /* Printf "," */
// if (line_count>10) {
// line_count = 0;
// fprintf(out_file,"\n ");
//
}
zero_count=0;
}
line_count++;
//printf(out_file,"0x");
//fputc(i, out_file);
//fputc(i1, out_file);
c[0] = i;
c[1] = i1;
c[2] = 0;
//s = atof(c);
sscanf(c, "%02X", &s);
fwrite(&s, 1, 1, out_file);
//printf(out_file,","); /* Printf "," */
//f (line_count>10) {
//line_count = 0;
// fprintf(out_file,"\n ");
// }
}
}
}
s = 0;
for(j=0; j<1024; j++)
fwrite(&s, 1, 1, out_file);
//printf(out_file,"0x00};");
fcloseall();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -