1 /***********************************************************
2 | tracehex by Steve Rhoads 12/25/01
3 | This tool modifies trace files from the free VHDL simulator
4 | http://www.symphonyeda.com/.
5 | The binary numbers are converted to hex values.
6 ************************************************************/
12 #define BUF_SIZE (1024*1024*4)
13 #define LINE_SIZE 10000
15 char drop_char[10000];
17 int main(int argc, char *argv[])
20 char *buf,*ptr_in,*ptr_out,*line_store,*line;
21 char *line_start,*source_start;
22 int bytes,digits,value,isbinary,col,col_num,row,drop_cnt;
23 int col_index,line_index,back_count,drop_start=0;
30 /* Reading trace.txt */
31 file=fopen("trace.txt","r");
33 printf("Can't open file\n");
36 line_store=(char*)malloc(LINE_SIZE);
39 buf=(char*)malloc(BUF_SIZE*2);
41 printf("Can't malloc!\n");
45 bytes=fread(buf,1,BUF_SIZE-1,file);
57 for(ptr_in=strstr(buf,"=");*ptr_in;++ptr_in) {
59 if(drop_start==0&&*ptr_in==' ') {
60 for(drop_start=3;drop_start<30;++drop_start) {
61 if(ptr_in[drop_start]!=' ') {
65 for(;drop_start<30;++drop_start) {
66 if(ptr_in[drop_start]==' ') {
76 if(drop_start<=col&&col<=drop_start+2) {
85 /* convert binary number to hex */
86 if(isbinary&&(*ptr_in=='0'||*ptr_in=='1')) {
87 value=value*2+*ptr_in-'0';
89 drop_char[col_num++]=1;
90 } else if(isbinary&&*ptr_in=='Z') {
93 drop_char[col_num++]=1;
94 } else if(isbinary&&(*ptr_in=='U'||*ptr_in=='X')) {
97 drop_char[col_num++]=1;
104 if(isspace(*ptr_in)) {
108 for(digits_length=1;!isspace(ptr_in[digits_length]);++digits_length) ;
118 /* convert every four binary digits to a hex digit */
119 if(digits&&(digits_length%4)==0) {
120 drop_char[--col_num]=0;
122 *ptr_out++=value<10?value+'0':value-10+'A';
123 } else if(value<5000) {
135 /* now process the header */
136 file=fopen("trace2.txt","w");
139 for(ptr_in=buf;*ptr_in;++ptr_in) {
147 for(col_index=0;col_index<col;++col_index) {
148 if(drop_char[col_index]) {
150 while(line[line_index-back_count]!=' '&&back_count<10) {
153 if(line[line_index-back_count-1]!=' ') {
156 strcpy(line+line_index-back_count,line+line_index-back_count+1);
161 fprintf(file,"%s",line);
166 for(col_index=13;col_index<sizeof(drop_char);++col_index) {
167 if(drop_char[col_index]) {
171 fprintf(file,"%s",buf+BUF_SIZE+drop_cnt);