Posted to tcl by sebres at Mon Apr 27 12:11:39 GMT 2020view raw

  1. set var1 {SYNC 1 2;K1_SP4_SPA_CLEANUP_DIAMETER UGT0101_008;K1_SP4_SPA_FACING UGT0101_008;SYNC 2 2;K1_SP4_SPA_ROUGHING UGT0101_008}
  2. set var2 {SYNC 1 2;K2_SP4_CHECK_DIAMETER UGT010_0232;SYNC 2 2}
  3.  
  4. set var1 [split $var1 ";"]
  5. set var2 [split $var2 ";"]
  6. set res {}
  7. set i 0
  8. foreach v2 $var2 {
  9. set v1 [lindex $var1 $i]
  10. if {[regexp {^SYNC } $v2] && $v1 ne $v2} {
  11. while {$i < [llength $var1] && [set v1 [lindex $var1 $i]] ne $v2} {
  12. lappend res NOOP
  13. incr i
  14. }
  15. if {$v1 ne $v2} {
  16. error "Unexpected: missing $v2 in var1."
  17. }
  18. }
  19. lappend res $v2
  20. incr i
  21. }
  22. while {$i < [llength $var1]} {
  23. lappend res NOOP
  24. incr i
  25. }
  26. puts "expect:\tSYNC 1 2;K2_SP4_CHECK_DIAMETER UGT010_0232;NOOP;SYNC 2 2;NOOP"
  27. puts "result:\t[join $res ";"]"
  28.