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

Subversion Repositories test_project

[/] [test_project/] [trunk/] [sw/] [utils/] [bin2flimg.c] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 julius
#include <stdio.h>
2
#include <stdlib.h>
3
 
4
int main(int argc, char **argv)
5
{
6
 
7
        FILE  *fd;
8
        int c, j, width;
9
        unsigned long word;
10
 
11
        if(argc < 3) {
12
                fprintf(stderr,"no input file specified\n");
13
                exit(1);
14
        }
15
        if(argc > 3) {
16
                fprintf(stderr,"too many input files (more than one) specified\n");
17
                exit(1);
18
        }
19
 
20
        width = atoi(argv[1]);
21
 
22
        fd = fopen( argv[2], "r" );
23
        if (fd == NULL) {
24
                fprintf(stderr,"failed to open input file: %s\n",argv[1]);
25
                exit(1);
26
        }
27
 
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.