File: checksum.py

package info (click to toggle)
mkgmap 0.0.0%2Bsvn4905-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,032 kB
  • sloc: java: 73,856; xml: 1,695; python: 713; sh: 240; makefile: 149; perl: 31
file content (48 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download | duplicates (7)
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
#
# Copyright (C) 2006 Steve Ratcliffe
# 
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License version 2 as
#  published by the Free Software Foundation.
# 
#  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.
# 
# 
# Author: Steve Ratcliffe
# Create date: 10 Dec 2006
#

#
# Sets the check sum for the file.  It is possible that the check sum
# is not actually checked by anything.
#

import sys

file = sys.argv[1]
print "file is", file

f = open(file)

cksum = 0
while 1:
	block = f.read(512)
	if not block: break
	for c in block:
		cksum -= ord(c)

cksum = (cksum & 0xff)
print "checksum is", cksum, hex(cksum)

if cksum != 0:
	fw = open(file, "r+b")
	fw.seek(15)
	print "setting checksum, please re-check afterwards"
	ch = chr(cksum)
	print 'chr', ord(ch)
	fw.write(ch)
	fw.close()