Posted to tcl by Pitol7Pi at Thu Apr 30 15:30:05 GMT 2020view raw
- set addon_save_sync_info__tcl_list_from_attr(1) {SYNC 1 1;SYNC 2 2;K1_SP4_SPA_FINISH_TURN 4}
- set addon_save_sync_info__tcl_list_from_attr(2) {SYNC 1 1;K2_SP4_SPA_GROOVE_OD 4;K2_SP4_SPA_SQUARE_SIDE_3_CUTCOM_SPA_DRILLING_FRONT 4;SYNC 2 2}
- set listlen(1) [expr [llength [split $addon_save_sync_info__tcl_list_from_attr(1) ";"]] - 1]
- set listlen(2) [expr [llength [split $addon_save_sync_info__tcl_list_from_attr(2) ";"]] - 1]
- puts $listen(1)
- puts $listen(2)
- definition of the value of 'noop' list entry
- set noop "NOOP -1"
- if {$listlen(1) >= $listlen(2)} {
- set listlen(max) $listlen(1)
- } else {
- set listlen(max) $listlen(2)
- }
- # save the lists
- set lists(1) [split $addon_save_sync_info__tcl_list_from_attr(1) ";"]
- set lists(2) [split $addon_save_sync_info__tcl_list_from_attr(2) ";"]
- # indicator to find the first sync marker in each list (channel)
- set sync_found(1) -1
- set sync_found(2) -1
- # counter
- set i 0
- # loop until list lengths are equal
- # while {$listlen(1) != $listlen(2) || $i < $listlen(max)} {}
- while {$listlen(1) != $listlen(2)} {
- # getting first element from each list
- set element(1) [lindex $lists(1) $i]
- set element(2) [lindex $lists(2) $i]
- if {$sync_found(1) == -1 || $sync_found(2) == -1} {
- # searching the elements for the keyword 'SYNC'
- # to jump over macros as start op
- set sync_found(1) [lsearch -exact $element(1) "SYNC"]
- set sync_found(2) [lsearch -exact $element(2) "SYNC"]
- }
- if {$sync_found(1) > -1 && $sync_found(2) > -1} {
- # so if we found the first sync, then we are able to get
- # the next element of each list
- set nxt_element(1) [lindex $lists(1) [expr $i + 1]]
- set nxt_element(2) [lindex $lists(2) [expr $i + 1]]
- if {[lindex $nxt_element(1) 0] == "SYNC"} {
- # setting start counter to the element index
- set ii [expr $i + 1]
- # loop until keyword 'SYNC' has been found
- while {[lindex $nxt_element(2) 0] != "SYNC"} {
- # insert the 'noop' in list 1
- set lists(1) [linsert $lists(1) $ii $noop]
- # increment the counter
- incr ii
- # setting the element to be checked to the next list element
- set nxt_element(2) [lindex $lists(2) $ii]
- if {$ii > $listlen(max)} {
- #puts "NOOP MAX ENDLOSSCHLEIFE KANAL 1"
- break
- }
- }
- # check if the first list element of next element is 'SYNC'
- } elseif {[lindex $nxt_element(2) 0] == "SYNC"} {
- #puts "22222: nxt_element(2)=$nxt_element(2)"
- set ii [expr $i + 1]
- # loop until keyword 'SYNC' has been found
- while {[lindex $nxt_element(1) 0] != "SYNC"} {
- #puts "22222 while: nxt_element(1)=$nxt_element(1)"
- # insert the 'noop' in list 2
- set lists(2) [linsert $lists(2) $ii $noop]
- # increment the counter
- incr ii
- # setting the element to be checked to the next list element
- set nxt_element(1) [lindex $lists(1) $ii]
- if {$ii > $listlen(max)} {
- #puts "NOOP MIN ENDLOSSCHLEIFE KANAL 2"
- break
- }
- }
- }
- # set new list lengths, because we probably inserted elements
- set listlen(1) [expr [llength $lists(1)] - 1]
- set listlen(2) [expr [llength $lists(2)] - 1]
- if {$listlen(1) >= $listlen(2)} {
- set listlen(max) $listlen(1)
- } else {
- set listlen(max) $listlen(2)
- }
- }
- # next element of the lists
- incr i
- # avoiding infinity loop, if no sync event has been set
- if {$i > $listlen(max)} {
- puts "ENDLOSSCHLEIFE"
- return
- }
- }
- puts $lists(1)
- puts $lists(2)
Comments
Posted by Pistol7Pi at Thu Apr 30 15:32:46 GMT 2020 [text] [code]
Acutal result {SYNC 1 1} {NOOP -1} {NOOP -1} {SYNC 2 2} {K1_SP4_SPA_FINISH_TURN 4} {SYNC 1 1} {K2_SP4_SPA_GROOVE_OD 4} {K2_SP4_SPA_SQUARE_SIDE_3_CUTCOM_SPA_DRILLING_FRONT 4} {SYNC 2 2} Result should be: {SYNC 1 1} {NOOP -1} {NOOP -1} {SYNC 2 2} {K1_SP4_SPA_FINISH_TURN 4} {SYNC 1 1} {K2_SP4_SPA_GROOVE_OD 4} {K2_SP4_SPA_SQUARE_SIDE_3_CUTCOM_SPA_DRILLING_FRONT 4} {SYNC 2 2} {NOOP -1}