summaryrefslogtreecommitdiff
path: root/lib/lib/ihextools.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lib/ihextools.tcl')
-rw-r--r--[-rwxr-xr-x]lib/lib/ihextools.tcl38
1 files changed, 26 insertions, 12 deletions
diff --git a/lib/lib/ihextools.tcl b/lib/lib/ihextools.tcl
index 071b178..458f799 100755..100644
--- a/lib/lib/ihextools.tcl
+++ b/lib/lib/ihextools.tcl
@@ -2,7 +2,7 @@
# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net )
############################################################################
-# Copyright (C) 2007-2009 by Martin Ošmera #
+# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera #
# martin.osmera@gmail.com #
# #
# This program is free software; you can redistribute it and#or modify #
@@ -21,6 +21,11 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
+# >>> File inclusion guard
+if { ! [ info exists _IHEXTOOLS_TCL ] } {
+set _IHEXTOOLS_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# Provides some tools for manipulating IHEX8, binary and sim files.
@@ -100,7 +105,7 @@ namespace eval IHexTools {
set index 0 ;# Last search result
# Get number of LF chracters
- while 1 {
+ while {1} {
set index [string first "\n" $data $index]
if {$index == -1} {break}
incr index
@@ -217,7 +222,7 @@ namespace eval IHexTools {
# Return result
if {$error_count} {
return 0
- } {
+ } else {
return 1
}
}
@@ -276,15 +281,19 @@ namespace eval IHexTools {
# Adjust input data
regsub -all {\r\n?} $data "\n" data ;# Any EOL to LF
- regsub -all -line {\s*#.*$} $data {} data ;# Remove comments
- regsub {^[^\n]+\n} $data {} data ;# Discard the first line
+ regsub -all {\s*#[^\n]*\n} $data {} data ;# Remove comments
- set lineNum 0 ;# Line number
+ set lineNum -1 ;# Line number
# Iterate over lines in the given data
foreach line [split $data "\n"] {
incr lineNum ;# Increment line number
+ # Discard the first line
+ if {!$lineNum} {
+ continue
+ }
+
# Skip empty lines
if {$line == {}} {continue}
@@ -330,7 +339,7 @@ namespace eval IHexTools {
# Return result
if {$error_count} {
return 0
- } {
+ } else {
return 1
}
}
@@ -356,12 +365,12 @@ namespace eval IHexTools {
# Convert it to binary value
if {$hex == {}} {
append pad "\0"
- } {
+ } else {
if {$pad != {}} {
append result $pad
set pad {}
}
- append result [subst "\\x$hex"]
+ append result [subst -nocommands "\\x$hex"]
}
# Increment address
incr addr
@@ -446,6 +455,7 @@ namespace eval IHexTools {
# Append EOF and return result
append result {:00000001FF}
+ append result "\n"
return $result
}
@@ -474,7 +484,7 @@ namespace eval IHexTools {
set result $content($addr)
if {$result == {}} {
return -1
- } {
+ } else {
return $result
}
}
@@ -510,7 +520,7 @@ namespace eval IHexTools {
}
## Append error message to error_string
- # @parm Int line - Number of line where the error occured
+ # @parm Int line - Number of line where the error occurred
# @parm String - Error message
# @return void
proc Error {line string} {
@@ -518,6 +528,10 @@ namespace eval IHexTools {
variable error_string ;# Error messages
incr error_count
- append error_string [mc "Error at line %s:\t" $line] $string "\n"
+ append error_string [mc "Error at %s:\t" $line] $string "\n"
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard