📄 bin2ram.tcl
字号:
## See the file "L2_RTI_EO1/disclaimers-and-notices-L2.txt" for # information on usage and redistribution of this file, # and for a DISCLAIMER OF ALL WARRANTIES.## bin2ram.tcl - Binary To RAM Tcl implementation file## modification history# --------------------# 26may04,sec Made minor changes to mimic the behavior of the "bin2ram"# executable version.# 25jul01,sec Set the file translation to binary so that Windows doesn't use# ctrl-z as the end of file.# 19jul01,sec Changed modification history order and change program usage to# have required parameters instead of optional parameters.# 16jul01,sec Converted the signed 8-bit integers to unsigned 8-bit integers# to avoid outputting 16-bit integers.# 11jun01,sec Changed the output format from a string array to an individual# character array.# 07jun01,sec Written.## DESCRIPTION# This module takes in a binary file and converts it to a standard C# character array to be outputted to a file.## ARGUMENTS# 1st = input file - the name of the input file.# 2nd = output file - the name of the output file. If the output file# exist, it will be overwritten.# 3rd = variable name - the name of the character array.## NOTE:# No error checking is done. If anything fails, the script will exit.# Check for the right number of arguments.if {$argc != 3} { # If not the right number of arguments, print out some help. puts {Usage: wtxtcl bin2ram.tcl <input file> <output file> <variable name>} return}# Open the file and read it all at once into memory. This is much faster than# reading a byte at a time from the hard drive--especially those hard drives# with small cache sizes.set channelId [open [lindex $argv 0] r]fconfigure $channelId -translation binaryset file_data [read $channelId]close $channelId# Turn all the bytes into a list of decimal numbers.binary scan $file_data c* in_data# Set our end of file condition.set data_size [llength $in_data]# Start at beginning of the data.set data_index 0# Tcl's form of concatenation and is more efficient than using 'set'.append out_data "static char [lindex $argv 2]Buffer\[] = \{"while {$data_index < $data_size} { append out_data "\n" # Set when to add a new line. set end_line_index [expr 16 + $data_index] # Make a line of hexadecimal numbers from the binary data. while {$data_index < $end_line_index} { append out_data [format {0x%02x} \ [expr ([lindex $in_data $data_index] + 0x100) % 0x100]] incr data_index if {$data_index == $data_size} { break } # Append commas if there is more data. append out_data "," }}# Finish the definition of the character array.append out_data " \};\nstatic int [lindex $argv 2]Size = $data_size;"# Write everything out at once. Again this is faster than a byte at a time.set channelId [open [lindex $argv 1] w]puts $channelId $out_dataclose $channelId
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -