Posted to tcl by greycat at Thu Apr 30 16:15:24 GMT 2020view pretty
#!/usr/bin/env tclsh set input1 {SYNC 1 1;SYNC 2 2;K1_SP4_SPA_FINISH_TURN 4} set input2 {SYNC 1 1;K2_SP4_SPA_GROOVE_OD 4;K2_SP4_SPA_SQUARE_SIDE_3_CUTCOM_SPA_DRILLING_FRONT 4;SYNC 2 2} set L1 [split $input1 ";"] set L2 [split $input2 ";"] set out1 [list] set out2 [list] set i1 0 set i2 0 while {$i1 < [llength $L1] || $i2 < [llength $L2]} { set tmp1 [lindex $L1 $i1] set tmp2 [lindex $L2 $i2] if {[string match SYNC* $tmp1] && [string match SYNC* $tmp2]} { lappend out1 $tmp1 lappend out2 $tmp2 incr i1 incr i2 continue } if {[string match SYNC* $tmp1]} { # Out of sync -- list 1 is "ahead". Add a NOOP to output list 1. # Only advance in list 2. lappend out1 NOOP lappend out2 $tmp2 incr i2 continue } if {[string match SYNC* $tmp2]} { # Opposite of above. lappend out1 $tmp1 incr i1 lappend out2 NOOP continue } # Otherwise, we just advance normally in each list. lappend out1 $tmp1 lappend out2 $tmp2 incr i1 incr i2 } puts "out1: $out1" puts "out2: $out2"