File: jedecparse.cpp

package info (click to toggle)
xc3sprog 0%2Bsvn795%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 8,800 kB
  • sloc: cpp: 15,983; ansic: 849; vhdl: 410; makefile: 3
file content (84 lines) | stat: -rw-r--r-- 2,113 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Jedec .jed file parser

Copyright (C) 2009 Uwe Bonnes bon@elektron.ikp.physik.tu-darmstadt.de
Copyright (C) 2004 Andrew Rogers

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Changes:
Dmitry Teytelman [dimtey@gmail.com] 14 Jun 2006 [applied 13 Aug 2006]:
    Code cleanup for clean -Wall compile.
*/

#include <string.h>
#include <errno.h>
#include <cstdio>

#include "jedecfile.h"
#include "io_exception.h"

int main(int argc, char**args)
{
  if(argc < 2)
    {
      fprintf(stderr,"Usage: %s infile.jed\n",args[0]);
    }
  else
    {
      try
	{
	  JedecFile  file;
	  FILE *fp;
	  if (*args[1] == '-')
	    fp = stdin;
	  else
	    {
	      fp=fopen(args[1],"rb");
	      if(!fp)
		{
		  fprintf(stderr, "Can't open datafile %s: %s\n", args[1],
			  strerror(errno));
		  return 1;
		}
	    }

	  file.readFile(fp);
	  fp = NULL;
	  if(args[2])
	    {
	      if (*args[2] == '-')
		fp = stdout;
	      fp = fopen(args[2], "wb");
	      if (!fp)
		fprintf(stderr," Can't open %s: %s  \n", args[2],
			strerror(errno));
	    }
	  fprintf(stderr, "Device %s: %d Fuses\n"
		  "Checksum calculated: 0x%04x,"
		  "Checksum from file 0x%04x\n",
		 file.getDevice(), file.getLength(), file.calcChecksum(),
		  file.getChecksum());
	  fprintf(stderr, "Version : %s Date %s\n",  file.getVersion(),
		  file.getDate());
	  file.saveAsJed(file.getDevice(), fp);
	}
      catch(io_exception& e)
	{
	  fprintf(stderr, "IOException: %s", e.getMessage().c_str());
	  return  1;
	}

    }
}