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

Subversion Repositories minsoc

[/] [minsoc/] [branches/] [rc-1.0/] [sw/] [utils/] [bin2flimg.c] - Blame information for rev 113

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

Line No. Rev Author Line
1 2 rfajardo
/*$$HEADER*/
2
/******************************************************************************/
3
/*                                                                            */
4
/*                    H E A D E R   I N F O R M A T I O N                     */
5
/*                                                                            */
6
/******************************************************************************/
7
 
8
// Project Name                   : ORPSoC v2
9
// File Name                      : bin2flimg.c
10
// Prepared By                    : 
11
// Project Start                  : 
12
 
13
/*$$COPYRIGHT NOTICE*/
14
/******************************************************************************/
15
/*                                                                            */
16
/*                      C O P Y R I G H T   N O T I C E                       */
17
/*                                                                            */
18
/******************************************************************************/
19
/*
20
  This library is free software; you can redistribute it and/or
21
  modify it under the terms of the GNU Lesser General Public
22
  License as published by the Free Software Foundation;
23
  version 2.1 of the License, a copy of which is available from
24
  http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
25
 
26
  This library is distributed in the hope that it will be useful,
27
  but WITHOUT ANY WARRANTY; without even the implied warranty of
28
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
29
  Lesser General Public License for more details.
30
 
31
  You should have received a copy of the GNU Lesser General Public
32
  License along with this library; if not, write to the Free Software
33
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
34
*/
35
 
36
/*$$DESCRIPTION*/
37
/******************************************************************************/
38
/*                                                                            */
39
/*                           D E S C R I P T I O N                            */
40
/*                                                                            */
41
/******************************************************************************/
42
//
43
// Generate flimg output to stdout from binary file input
44
//
45
 
46
#include <stdio.h>
47
#include <stdlib.h>
48
 
49
int main(int argc, char **argv)
50
{
51
 
52
        FILE  *fd;
53
        int c, j, width;
54
        unsigned long word;
55
 
56
        if(argc < 3) {
57
                fprintf(stderr,"no input file specified\n");
58
                exit(1);
59
        }
60
        if(argc > 3) {
61
                fprintf(stderr,"too many input files (more than one) specified\n");
62
                exit(1);
63
        }
64
 
65
        width = atoi(argv[1]);
66
 
67
        fd = fopen( argv[2], "r" );
68
        if (fd == NULL) {
69
                fprintf(stderr,"failed to open input file: %s\n",argv[1]);
70
                exit(1);
71
        }
72
 
73
        while (!feof(fd)) {
74
                j = 0;
75
                word = 0;
76
                while (j < width) {
77
                        c = fgetc(fd);
78
                        if (c == EOF) {
79
                                c = 0;
80
                        }
81
                        word = (word << 8) + c;
82
                        j++;
83
                }
84
                if(width == 1)
85
                        printf("%.2lx\n", word);
86
                else if(width == 2)
87
                        printf("%.4lx\n", word);
88
                else
89
                        printf("%.8lx\n", word);
90
        }
91
        return 0;
92
}

powered by: WebSVN 2.1.0

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