OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [trunk/] [tools/] [tracehex.c] - Diff between revs 7 and 16

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 7 Rev 16
Line 8... Line 8...
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <ctype.h>
#include <ctype.h>
 
 
#define BUF_SIZE (1024*1024)
#define BUF_SIZE (1024*1024)
 
#define LINE_SIZE 10000
 
 
char drop_char[10000];
char drop_char[10000];
 
//char line[10000];
 
 
int main(int argc, char *argv[])
int main(int argc, char *argv[])
{
{
   FILE *file;
   FILE *file;
   char *buf,*ptr_in,line[1000],*ptr_out;
   char *buf,*ptr_in,*ptr_out,*line_store,*line;
   int bytes,digits,value,isbinary,col,col_num,row,drop_cnt;
   int bytes,digits,value,isbinary,col,col_num,row,drop_cnt;
   int col_index,line_index,back_count,temp;
   int col_index,line_index,back_count;
 
   int digits_length=0;
   (void)argc,argv;
   (void)argc,argv;
 
 
 
   printf("tracehex\n");
 
 
   /* Reading trace.txt */
   /* Reading trace.txt */
   file=fopen("trace.txt","r");
   file=fopen("trace.txt","r");
   if(file==NULL) {
   if(file==NULL) {
      printf("Can't open file\n");
      printf("Can't open file\n");
      return -1;
      return -1;
   }
   }
 
   line_store=(char*)malloc(LINE_SIZE);
 
   line_store[0]=' ';
 
   line=line_store+1;
   buf=(char*)malloc(BUF_SIZE*2);
   buf=(char*)malloc(BUF_SIZE*2);
 
   if(buf==NULL) {
 
      printf("Can't malloc!\n");
 
      return -1;
 
   }
   ptr_out=buf+BUF_SIZE;
   ptr_out=buf+BUF_SIZE;
   bytes=fread(buf,1,BUF_SIZE-1,file);
   bytes=fread(buf,1,BUF_SIZE-1,file);
   buf[bytes]=0;
   buf[bytes]=0;
   fclose(file);
   fclose(file);
 
 
Line 58... Line 70...
      } else if(isbinary&&*ptr_in=='U') {
      } else if(isbinary&&*ptr_in=='U') {
         value=10000;
         value=10000;
         ++digits;
         ++digits;
         drop_char[col_num++]=1;
         drop_char[col_num++]=1;
      } else {
      } else {
         /* end of binary number? */
 
         if(digits) {
 
            drop_char[--col_num]=0;
 
            if(value<100) {
 
               /* test if digits not divisible by 4 */
 
               if('0'<=ptr_out[-1]&&ptr_out[-1]<='9') {
 
                  /* adjust previous digit */
 
                  value=value+((ptr_out[-1]-'0')<<digits);
 
                  temp=(value>>4);
 
                  ptr_out[-1]=temp<10?temp+'0':temp-10+'A';
 
               } else if('A'<=ptr_out[-1]&&ptr_out[-1]<='F') {
 
                  value=value+((ptr_out[-1]-'A'+10)<<digits);
 
                  temp=(value>>4);
 
                  ptr_out[-1]=temp<10?temp+'0':temp-10+'A';
 
               }
 
               value&=0xf;
 
               *ptr_out++=value<10?value+'0':value-10+'A';
 
            } else if(value<5000) {
 
               *ptr_out++='Z';
 
            } else {
 
               *ptr_out++='U';
 
            }
 
         }
 
         if(*ptr_in=='\n') {
         if(*ptr_in=='\n') {
            col=0;
            col=0;
            isbinary=0;
            isbinary=0;
            ++row;
            ++row;
         }
         }
         if(isspace(*ptr_in)) {
         if(isspace(*ptr_in)) {
            if(col>10) {
            if(col>10) {
               isbinary=1;
               isbinary=1;
               col_num=col;
               col_num=col;
 
               for(digits_length=1;!isspace(ptr_in[digits_length]);++digits_length) ;
 
               --digits_length;
            }
            }
         } else {
         } else {
            isbinary=0;
            isbinary=0;
         }
         }
         *ptr_out++=*ptr_in;
         *ptr_out++=*ptr_in;
         digits=0;
         digits=0;
         value=0;
         value=0;
      }
      }
 
 
      /* convert every four binary digits to a hex digit */
      /* convert every four binary digits to a hex digit */
      if(digits==4) {
      if(digits&&(digits_length%4)==0) {
         drop_char[--col_num]=0;
         drop_char[--col_num]=0;
         if(value<100) {
         if(value<100) {
            *ptr_out++=value<10?value+'0':value-10+'A';
            *ptr_out++=value<10?value+'0':value-10+'A';
         } else if(value<5000) {
         } else if(value<5000) {
            *ptr_out++='Z';
            *ptr_out++='Z';
Line 112... Line 102...
            *ptr_out++='U';
            *ptr_out++='U';
         }
         }
         digits=0;
         digits=0;
         value=0;
         value=0;
      }
      }
 
      --digits_length;
   }
   }
   *ptr_out=0;
   *ptr_out=0;
 
 
   /* now process the header */
   /* now process the header */
   file=fopen("trace2.txt","w");
   file=fopen("trace2.txt","w");
Line 154... Line 145...
      }
      }
   }
   }
   fprintf(file,"%s",buf+BUF_SIZE+drop_cnt);
   fprintf(file,"%s",buf+BUF_SIZE+drop_cnt);
 
 
   fclose(file);
   fclose(file);
 
   free(line_store);
   free(buf);
   free(buf);
   return 0;
   return 0;
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.