Posted to tcl by Pitol7Pi at Thu Apr 30 15:30:05 GMT 2020view raw

  1. set addon_save_sync_info__tcl_list_from_attr(1) {SYNC 1 1;SYNC 2 2;K1_SP4_SPA_FINISH_TURN 4}
  2. 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}
  3.  
  4. set listlen(1) [expr [llength [split $addon_save_sync_info__tcl_list_from_attr(1) ";"]] - 1]
  5. set listlen(2) [expr [llength [split $addon_save_sync_info__tcl_list_from_attr(2) ";"]] - 1]
  6. puts $listen(1)
  7. puts $listen(2)
  8.  
  9. definition of the value of 'noop' list entry
  10. set noop "NOOP -1"
  11.  
  12. if {$listlen(1) >= $listlen(2)} {
  13. set listlen(max) $listlen(1)
  14. } else {
  15. set listlen(max) $listlen(2)
  16. }
  17.  
  18.  
  19. # save the lists
  20. set lists(1) [split $addon_save_sync_info__tcl_list_from_attr(1) ";"]
  21. set lists(2) [split $addon_save_sync_info__tcl_list_from_attr(2) ";"]
  22.  
  23. # indicator to find the first sync marker in each list (channel)
  24. set sync_found(1) -1
  25. set sync_found(2) -1
  26.  
  27. # counter
  28. set i 0
  29.  
  30. # loop until list lengths are equal
  31. # while {$listlen(1) != $listlen(2) || $i < $listlen(max)} {}
  32. while {$listlen(1) != $listlen(2)} {
  33. # getting first element from each list
  34. set element(1) [lindex $lists(1) $i]
  35. set element(2) [lindex $lists(2) $i]
  36.  
  37. if {$sync_found(1) == -1 || $sync_found(2) == -1} {
  38. # searching the elements for the keyword 'SYNC'
  39. # to jump over macros as start op
  40. set sync_found(1) [lsearch -exact $element(1) "SYNC"]
  41. set sync_found(2) [lsearch -exact $element(2) "SYNC"]
  42.  
  43. }
  44.  
  45. if {$sync_found(1) > -1 && $sync_found(2) > -1} {
  46. # so if we found the first sync, then we are able to get
  47. # the next element of each list
  48. set nxt_element(1) [lindex $lists(1) [expr $i + 1]]
  49. set nxt_element(2) [lindex $lists(2) [expr $i + 1]]
  50.  
  51.  
  52. if {[lindex $nxt_element(1) 0] == "SYNC"} {
  53.  
  54. # setting start counter to the element index
  55. set ii [expr $i + 1]
  56. # loop until keyword 'SYNC' has been found
  57. while {[lindex $nxt_element(2) 0] != "SYNC"} {
  58. # insert the 'noop' in list 1
  59. set lists(1) [linsert $lists(1) $ii $noop]
  60. # increment the counter
  61. incr ii
  62. # setting the element to be checked to the next list element
  63. set nxt_element(2) [lindex $lists(2) $ii]
  64.  
  65. if {$ii > $listlen(max)} {
  66. #puts "NOOP MAX ENDLOSSCHLEIFE KANAL 1"
  67. break
  68. }
  69. }
  70. # check if the first list element of next element is 'SYNC'
  71. } elseif {[lindex $nxt_element(2) 0] == "SYNC"} {
  72. #puts "22222: nxt_element(2)=$nxt_element(2)"
  73. set ii [expr $i + 1]
  74. # loop until keyword 'SYNC' has been found
  75. while {[lindex $nxt_element(1) 0] != "SYNC"} {
  76. #puts "22222 while: nxt_element(1)=$nxt_element(1)"
  77. # insert the 'noop' in list 2
  78. set lists(2) [linsert $lists(2) $ii $noop]
  79. # increment the counter
  80. incr ii
  81. # setting the element to be checked to the next list element
  82. set nxt_element(1) [lindex $lists(1) $ii]
  83.  
  84. if {$ii > $listlen(max)} {
  85. #puts "NOOP MIN ENDLOSSCHLEIFE KANAL 2"
  86. break
  87. }
  88. }
  89. }
  90. # set new list lengths, because we probably inserted elements
  91. set listlen(1) [expr [llength $lists(1)] - 1]
  92. set listlen(2) [expr [llength $lists(2)] - 1]
  93.  
  94. if {$listlen(1) >= $listlen(2)} {
  95. set listlen(max) $listlen(1)
  96. } else {
  97. set listlen(max) $listlen(2)
  98. }
  99. }
  100.  
  101. # next element of the lists
  102. incr i
  103.  
  104. # avoiding infinity loop, if no sync event has been set
  105. if {$i > $listlen(max)} {
  106. puts "ENDLOSSCHLEIFE"
  107. return
  108. }
  109. }
  110.  
  111. puts $lists(1)
  112. puts $lists(2)
  113.  
  114.  
  115.  
  116.  

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}