From 2a4f9dc587af9e9c8f740910faab65accb2a916f Mon Sep 17 00:00:00 2001
From: Philipp Claves <pclaves@web.de>
Date: Sun, 18 Dec 2011 01:39:36 +0100
Subject: [PATCH] Support ruby 1.8.x in atmegacard eeprom generator.

---
 ATMegaCard/eeprom_gen.rb | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/ATMegaCard/eeprom_gen.rb b/ATMegaCard/eeprom_gen.rb
index aa0e0db..2277921 100755
--- a/ATMegaCard/eeprom_gen.rb
+++ b/ATMegaCard/eeprom_gen.rb
@@ -46,12 +46,20 @@ class IntelHexWriter
 end
 
 def hex2bin(hex)
-	c = hex.length / 2
-	bin = ('.'.encode('ASCII-8BIT'))*c
-	(0...c).each{|i|
-		bin.setbyte(i,hex[i << 1, 2].hex)
-	}
-	return bin
+        c = hex.length / 2
+        bin = ""
+        if ("".respond_to?(:encode))
+                bin = ('.'.encode('ASCII-8BIT'))*c
+                (0...c).each{|i|
+                        bin.setbyte(i,hex[i << 1, 2].hex)
+                }
+        else
+                bin = '.'*c
+                (0...c).each{|i|
+                        bin[i] = hex[i << 1, 2].hex
+                }
+        end
+        return bin
 end
 
 eeprom_file = ARGV[0]
@@ -71,4 +79,4 @@ f.write_data(hex2bin(keystring))
 f.write_data("\xFF"*KEY_LENGTH)
 f.close
 
-puts("OK")
\ No newline at end of file
+puts("OK")
-- 
GitLab