Originally posted by Duy Nguyen
Originally posted by Alice Schmautz
Originally posted by Sergey Sevastyanov
#!/bin/sh# -*- tcl -*-# The next line is executed by /bin/sh, but not tcl exec tclsh "$0" ${1+"$@};# Read messages from a text file and build message files for SMATpackage require Tkpackage require Tclx################################################################################ proc initWindow###############################################################################proc initWindow {} { wm title . "Generate SMAT files from a text file" # wm geometry size behaves differently when it contains text widget - sizes are in some different units # wm geometry . 13x13+20+20 global fstatus menu .menu -tearoff 0 set mf .menu.file menu $mf -tearoff 0 -activebackground DarkBlue -activeforeground White -font {Arial 8 normal} .menu add cascade -label "File" -menu $mf -underline 0 $mf add command -label "Open message text file..." -command "openFile" $mf add command -label "Create SMAT files" -command "createSMAT" $mf add command -label "Exit" -command {exit} . configure -menu .menu # set text area to display status of the program set fstatus .fstatus frame .fstatus -borderwidth 2 -height 200 -width 200 ; ###-relief sunken pack .fstatus -side top -fill both -pady 2 -padx 2 -expand yes text $fstatus.text -wrap none -height 20 -width 100 -setgrid true -highlightthickness 0 -pady 1 -padx 1 -font {Courier 10 normal} -bg white -xscrollcommand "$fstatus.xscroll set" -yscrollcommand "$fstatus.yscroll set" -relief sunken scrollbar $fstatus.yscroll -command "$fstatus.text yview" -highlightthickness 0 -orient vertical scrollbar $fstatus.xscroll -command "$fstatus.text xview" -highlightthickness 0 -orient horizontal grid $fstatus.text -in $fstatus -padx 1 -pady 1 -row 0 -column 0 -rowspan 1 -sticky news grid $fstatus.yscroll -in $fstatus -padx 1 -pady 1 -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news grid $fstatus.xscroll -in $fstatus -padx 1 -pady 1 -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news grid rowconfig $fstatus 0 -weight 1 -minsize 0 grid rowconfig $fstatus 1 -weight 0 -minsize 0 grid columnconfig $fstatus 0 -weight 1 -minsize 0 grid columnconfig $fstatus 1 -weight 0 -minsize 0 #define styles TextStyles $fstatus.text}proc TextStyles {text} { $text tag configure arial_12_bold_red -font {arial 12 bold} -foreground red $text tag configure arial_16_bold_red -font {arial 16 bold} -foreground red $text tag configure arial_12_bold_italic_red -font {arial 12 bold italic} -foreground red $text tag configure courier_10_bold -font {courier 10 bold} -foreground black $text tag configure courier_10_bold_blue -font {courier 10 bold} -foreground blue $text tag configure default -font {courier 10 } -foreground black}#============================================================# openFile#============================================================proc openFile {} { global filein set MessageFile [tk_getOpenFile -initialdir {C:Test } -title "Open message text file"] if { $MessageFile eq "" } { return } set filein [open $MessageFile r] if {$filein != 0} { return $filein } # read the whole file into $html while {[gets $filein line] >= 0} { append html $line "n" }}#============================================================# createSMAT#============================================================proc createSMAT {} { global filein set msgSMAT [tk_getSaveFile -initialdir {C:Test } -title "Save SMAT message file"] if { $msgSMAT eq "" } { return } set rootname [file rootname $msgSMAT] set ext [file extension $msgSMAT] if {$ext ne ".msg"} { set ext ".msg" } set ext2 ".idx" set msgSMAT "" set idxSMAT "" append msgSMAT $rootname $ext append idxSMAT $rootname $ext2 set outmsg [open $msgSMAT w] if {$outmsg == 0} { error "Error during creation of SMAT msg file $msgSMAT" return } # create SMAT idx file set outidx [open $idxSMAT w] if {$outidx == 0} { error "Error during creation of SMAT index file $idxSMAT" return } set offset 0 set len 0 # process input message file while {[gets $filein line] >= 0} { # display line #displayLog $line 1 # if MSH segment read create index record for previous message set seg [string range $line 0 2] ###displayLog "processing segment $seg" 1 arial_12_bold_italic_red if {($seg eq "MSH") && ($len > 0)} { # display MSH line displayLog $line 1 # create index record set indrec [createIndexRec $offset $len] incr offset $len set len 0 puts $outidx "{" foreach el $indrec { puts $outidx t$el } puts $outidx "}" } # write segment to message file incr len [string length $line] incr len 1 puts -nonewline $outmsg $linexd } # create index record for the last message set indrec [createIndexRec $offset $len] puts $outidx "{" foreach el $indrec { puts $outidx t$el } puts $outidx "}"close $fileinclose $outmsgclose $outidxdisplayLog "========================================================" 1displayLog "All Done" 1 }proc createIndexRec {offset len} { # set keylists set domain [list DOMAIN 0] set hub [list HUB 0] set num [list NUM 0] set mid [list MID [list $domain $hub $num]] set srcmid [list SRCMID [list $domain $hub $num]] set dest to_test set orig_dest to_test set source_conn frm_tets set orig_source_conn frm_test keylset midkl MID.DOMAIN 0 MID.HUB 0 MID.NUM 0 keylset srcmidkl SRCMID.DOMAIN 0 SRCMID.HUB 0 SRCMID.NUM 0 keylset typekl TYPE DATA keylset srcconn SOURCECONN $source_conn keylset osrcconn ORIGSOURCECONN $orig_source_conn keylset destconn DESTCONN $dest keylset origdestconn ORIGDESTCONN $orig_dest keylset time TIME 0 keylset prty PRIORITY 5120 keylset datfmt DATAFMT "" keylset savcntx SAVECONTEXT outbound keylset off OFFSET $offset keylset lenkl LENGTH $len set indrec2 [list $midkl $srcmidkl $typekl $srcconn $osrcconn $destconn $origdestconn $time $prty $datfmt $savcntx $off $lenkl] return $indrec2}#============================================================# displayLog - display text in the window#============================================================proc displayLog {text newline {style ""} } { global fstatus set textstyle default if {$style ne ""} { set textstyle $style } $fstatus.text insert end $text $textstyle if {$newline > 0} { for {set i 1} {$i <= $newline} {incr i} { $fstatus.text insert end "n" } } # scroll to the end $fstatus.text see end update idletasks}initWindow
set dest to_test set orig_dest to_test set source_conn frm_tets set orig_source_conn frm_test