Here is the code excerpt:
#
# search the header for the base addresses of my slaves and other interesting properties
#
puts ""
puts "Searching \"$system_header_file_path\" for various system information..."
set C_M_N   [ string toupper $console_master_name ]
set sysid_base_re       "^\[ \t\]*#define\[ \t\]+$C_M_N\_SYSID_BASE\[ \t\]+(0x\[0-9a-fA-F\]+)"
set sysid_id_re         "^\[ \t\]*#define\[ \t\]+$C_M_N\_SYSID_ID\[ \t\]+(\[0-9a-fA-F\]+)u"
set sysid_timestamp_re  "^\[ \t\]*#define\[ \t\]+$C_M_N\_SYSID_TIMESTAMP\[ \t\]+(\[0-9a-fA-F\]+)u"
set build_id_base_re    "^\[ \t\]*#define\[ \t\]+$C_M_N\_BUILD_ID_BASE\[ \t\]+(0x\[0-9a-fA-F\]+)"
set gate_base_re        "^\[ \t\]*#define\[ \t\]+$C_M_N\_GATE_BASE\[ \t\]+(0x\[0-9a-fA-F\]+)"
set define_re           "^\[ \t\]*#define\[ \t\]+.*"
set sysid_base              "unknown"
set sysid_id                "unknown"
set sysid_timestamp         "unknown"
set build_id_base           "unknown"
set gate_base               "unknown"
set header_file [ open $system_header_file_path r ]
while { [ gets $header_file next_line ] >= 0 } {
    if { [ regexp $define_re $next_line ] } {
        if { [ regexp $sysid_base_re $next_line -> value ] } {
            set sysid_base              $value
        } elseif { [ regexp $sysid_id_re $next_line -> value ] } {
            set sysid_id                $value
        } elseif { [ regexp $sysid_timestamp_re $next_line -> value ] } {
            set sysid_timestamp         $value
        } elseif { [ regexp $build_id_base_re $next_line -> value ] } {
            set build_id_base           $value
        } elseif { [ regexp $gate_base_re $next_line -> value ] } {
            set gate_base           $value
        }
    }
}
close $header_file
I am trying to figure out these things:
File I/O
- Does the open command open the file as text file or binary file? If it opens as text file, how to make it open as binary file instead?
- How does gets $header_file cause next line to be read from file? Is the header_file some sort of file pointer?
- Why are we checking if the value returned by the gets is >= 0, is there no eof function in TCL?
Regular expressions
- What is this -> operator being used in the line with the regexp command? As far as I am aware, the regular expression command can be used without this operator as well.
 
    