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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [tools/] [utils/] [bin2abs.c] - Diff between revs 106 and 116

Show entire file | Details | Blame | View Log

Rev 106 Rev 116
Line 58... Line 58...
{
{
 
 
        FILE  *fd;
        FILE  *fd;
        int c;
        int c;
        int i = 0;
        int i = 0;
 
        int j = 1;
        int line = 0;
        int line = 0;
        int filename_index=1;
        int filename_index=1;
        int bytes_per_line=1;
        int bytes_per_line=1;
        int bytes_per_line_index=2;
        int bytes_per_line_index=2;
        int min_num_bytes_index=3;
 
        int min_num_bytes = 0;
        int min_num_bytes = 0;
 
        int min_num_bytes_index=3;
 
        int byte_lane=0;
 
        int byte_lane_index=4;
 
 
 
 
        if(argc < 3) {
        if(argc < 3) {
          fprintf(stderr,"\n\tInsufficient options.\n");
          fprintf(stderr,"\n\tInsufficient options.\n");
          fprintf(stderr,"\tPlease specify, in this order: a binary file to\n");
          fprintf(stderr,"\tPlease specify, in this order: a binary file to\n");
Line 75... Line 78...
          fprintf(stderr,"\tper line.\n");
          fprintf(stderr,"\tper line.\n");
          exit(1);
          exit(1);
        }
        }
 
 
        fd = fopen( argv[filename_index], "r" );
        fd = fopen( argv[filename_index], "r" );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
        bytes_per_line = atoi(argv[bytes_per_line_index]);
        bytes_per_line = atoi(argv[bytes_per_line_index]);
 
 
 
 
 
 
 
 
        if(argc > 3) {
        if(argc > 3) {
        min_num_bytes = atoi(argv[min_num_bytes_index]);
        min_num_bytes = atoi(argv[min_num_bytes_index]);
        }
        }
 
 
 
 
 
        if(argc > 4) {
 
        byte_lane = atoi(argv[byte_lane_index]);
 
        }
 
 
 
 
        if ((bytes_per_line == 0) || (bytes_per_line > 8))
        if ((bytes_per_line == 0) || (bytes_per_line > 8) || (byte_lane > bytes_per_line )    )
          {
          {
            fprintf(stderr,"bytes per line incorrect or missing: %s\n",argv[bytes_per_line_index]);
            fprintf(stderr,"bytes per line incorrect or missing: %s\n",argv[bytes_per_line_index]);
            exit(1);
            exit(1);
          }
          }
 
 
 
 
 
 
 
        if (fd == NULL) {
 
                fprintf(stderr,"failed to open input file: %s\n",argv[1]);
 
                exit(1);
 
        }
 
 
 
        i=0;
 
        line=0;
 
 
 
        if(byte_lane)
 
          {
 
        // Now write out the binary data to hex format
 
        while ((c = fgetc(fd)) != EOF) {
 
          j=i+1;
 
          if(byte_lane == j)
 
            {   printf("%.2x", (unsigned int) c);
 
 
 
            }
 
                if (++i == bytes_per_line) {
 
                        printf("\n");
 
                        line++;
 
                        i = 0;
 
                }
 
        }
 
 
 
 
 
        while (i) {
 
          j=i+1;
 
          if(byte_lane == j)
 
            {   printf("00");
 
 
        if (fd == NULL) {
 
                fprintf(stderr,"failed to open input file: %s\n",argv[1]);
 
                exit(1);
 
        }
        }
 
 
 
 
 
                if (++i == bytes_per_line) {
 
                        printf("\n");
 
                        line++;
        i=0;
        i=0;
        line=0;
                }
 
        }
 
 
 
 
 
 
 
        while (line < min_num_bytes) {
 
                printf("00\n");
 
                line++;
 
        }
 
          }
 
      else
 
 
 
          {
 
            // no byte lane
        // Now write out the binary data to hex format
        // Now write out the binary data to hex format
        while ((c = fgetc(fd)) != EOF) {
        while ((c = fgetc(fd)) != EOF) {
                printf("%.2x", (unsigned int) c);
                printf("%.2x", (unsigned int) c);
                if (++i == bytes_per_line) {
                if (++i == bytes_per_line) {
                        printf("\n");
                        printf("\n");
Line 143... Line 175...
 
 
        while (line < min_num_bytes) {
        while (line < min_num_bytes) {
                printf("00000000\n");
                printf("00000000\n");
                line++;
                line++;
        }
        }
 
          }
 
 
 
 
 
 
 
 
        return 0;
        return 0;

powered by: WebSVN 2.1.0

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