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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [orp/] [orp_soc/] [sw/] [utils/] [bin2flimg.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 750 lampret
#include <stdio.h>
2 1289 partain
#include <stdlib.h>
3 750 lampret
 
4
int main(int argc, char **argv)
5
{
6
 
7
        FILE  *fd;
8 1289 partain
        int c, j, width;
9 750 lampret
        unsigned long word;
10
 
11 1268 lampret
        if(argc < 3) {
12 1289 partain
                fprintf(stderr,"no input file specified\n");
13 1268 lampret
                exit(1);
14
        }
15 1289 partain
        if(argc > 3) {
16
                fprintf(stderr,"too many input files (more than one) specified\n");
17
                exit(1);
18
        }
19 1268 lampret
 
20 750 lampret
        width = atoi(argv[1]);
21
 
22
        fd = fopen( argv[2], "r" );
23 1289 partain
        if (fd == NULL) {
24
                fprintf(stderr,"failed to open input file: %s\n",argv[1]);
25
                exit(1);
26
        }
27 750 lampret
 
28
        while (!feof(fd)) {
29
                j = 0;
30
                word = 0;
31
                while (j < width) {
32
                        c = fgetc(fd);
33
                        if (c == EOF) {
34
                                c = 0;
35
                        }
36
                        word = (word << 8) + c;
37
                        j++;
38
                }
39
                if(width == 1)
40
                        printf("%.2lx\n", word);
41
                else if(width == 2)
42
                        printf("%.4lx\n", word);
43
                else
44
                        printf("%.8lx\n", word);
45
        }
46
        return 0;
47
}

powered by: WebSVN 2.1.0

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