Posted to tcl by greycat at Thu Apr 30 16:15:24 GMT 2020view raw

  1. #!/usr/bin/env tclsh
  2.  
  3. set input1 {SYNC 1 1;SYNC 2 2;K1_SP4_SPA_FINISH_TURN 4}
  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}
  5.  
  6. set L1 [split $input1 ";"]
  7. set L2 [split $input2 ";"]
  8.  
  9. set out1 [list]
  10. set out2 [list]
  11.  
  12. set i1 0
  13. set i2 0
  14. while {$i1 < [llength $L1] || $i2 < [llength $L2]} {
  15. set tmp1 [lindex $L1 $i1]
  16. set tmp2 [lindex $L2 $i2]
  17.  
  18. if {[string match SYNC* $tmp1] && [string match SYNC* $tmp2]} {
  19. lappend out1 $tmp1
  20. lappend out2 $tmp2
  21. incr i1
  22. incr i2
  23. continue
  24. }
  25.  
  26. if {[string match SYNC* $tmp1]} {
  27. # Out of sync -- list 1 is "ahead". Add a NOOP to output list 1.
  28. # Only advance in list 2.
  29. lappend out1 NOOP
  30. lappend out2 $tmp2
  31. incr i2
  32. continue
  33. }
  34.  
  35. if {[string match SYNC* $tmp2]} {
  36. # Opposite of above.
  37. lappend out1 $tmp1
  38. incr i1
  39. lappend out2 NOOP
  40. continue
  41. }
  42.  
  43. # Otherwise, we just advance normally in each list.
  44. lappend out1 $tmp1
  45. lappend out2 $tmp2
  46. incr i1
  47. incr i2
  48. }
  49.  
  50. puts "out1: $out1"
  51. puts "out2: $out2"
  52.