Posted to tcl by mookie at Fri Sep 20 00:00:45 GMT 2024view raw

  1. if I am to read a line from text file, I encounter the issue where it seems to detect % at range positions where, it doesn't exist...
  2. ranges 23 25 27 29 don't hold the value % and so shouldn't trigger my switch case
  3.  
  4. <legend>%_frame_title_%</legend>
  5. I can add a break clause, which I ultimately need to do, but still confusing to why is this switch triggering.
  6.  
  7. mookie@cuddles:~/~scrap/~tcl $ tclsh hexScope.ix
  8. my line in base16: 3c6c6567656e643e255f6672616d655f7469746c655f253c2f6c6567656e643e
  9. my line in base32: <legend>%_frame_title_%</legend>
  10. nothing found
  11. nothing found
  12. nothing found
  13. nothing found
  14. nothing found
  15. nothing found
  16. nothing found
  17. nothing found
  18. I found my % @ 8
  19. String is: %_frame_title_%</legend>
  20. Now lets see if the next character to see if it has _
  21. found _
  22. nothing found
  23. nothing found
  24. nothing found
  25. nothing found
  26. nothing found
  27. nothing found
  28. nothing found
  29. nothing found
  30. nothing found
  31. nothing found
  32. nothing found
  33. nothing found
  34. nothing found
  35. I found my % @ 22
  36. String is: %</legend>
  37. Now lets see if the next character to see if it has _
  38. _ not found
  39. What about my previous character, was that a _?
  40. indeed my previous character is a _ @ 21
  41. nothing found
  42. I found my % @ 24
  43. String is: /legend>
  44. Now lets see if the next character to see if it has _
  45. _ not found
  46. What about my previous character, was that a _?
  47. indeed my previous character is a _ @ 23
  48. nothing found
  49. I found my % @ 26
  50. String is: egend>
  51. Now lets see if the next character to see if it has _
  52. _ not found
  53. What about my previous character, was that a _?
  54. indeed my previous character is a _ @ 25
  55. nothing found
  56. I found my % @ 28
  57. String is: end>
  58. Now lets see if the next character to see if it has _
  59. _ not found
  60. What about my previous character, was that a _?
  61. indeed my previous character is a _ @ 27
  62. nothing found
  63. I found my % @ 30
  64. String is: d>
  65. Now lets see if the next character to see if it has _
  66. _ not found
  67. What about my previous character, was that a _?
  68. indeed my previous character is a _ @ 29
  69. nothing found
  70. >> 8 21 23 25 27 29
  71.  
  72.  
  73.  
  74. ###### CODE #######
  75.  
  76. # set myFile [open $base32_myFile]
  77. # set myFile [open "./timezone.craft"]
  78. # set lines [split [read $myFile] "\n"]
  79. # close $myFile
  80.  
  81. set lines "<legend>%_frame_title_%</legend>"
  82.  
  83. foreach line $lines {
  84. set x_pos 0
  85. set y_pos 1
  86. set z_pos 2
  87. set a_pos 3
  88. set list ""
  89. set located 0
  90.  
  91. set i 0
  92. set string_length [string length $line]
  93. puts "\n"
  94. puts "my line in base16: [binary encode hex $line]"
  95. puts "my line in base32: $line "
  96.  
  97. for {set z 0} {$z < $string_length} {incr z} {
  98.  
  99. switch [binary encode hex [string range $line $x_pos $x_pos]] {
  100. 25 { puts "I found my % @ $z"
  101.  
  102. switch $located {
  103. 0 {
  104. lappend list $z
  105. }
  106. }
  107.  
  108. puts "String is: [string range $line $z end]"
  109. puts "Now lets see if the next character to see if it has _"
  110. incr i
  111.  
  112. switch [binary encode hex [string range $line $y_pos $y_pos]] {
  113. 5f {
  114. puts "found _ "
  115. incr x_pos
  116. incr y_pos
  117. }
  118.  
  119. default {
  120. puts "_ not found"
  121. puts "What about my previous character, was that a _?"
  122. incr x_pos -1
  123.  
  124. switch [binary encode hex [string range $line $x_pos $x_pos]] {
  125. 5f {
  126. puts "indeed my previous character is a _ @ [expr $z-1]"
  127. lappend list [expr $z-1] ;# append the previous position
  128.  
  129. }
  130. default {
  131. puts "it was not"
  132. incr x_pos 2
  133. break
  134. }
  135. } ;# end switch
  136. }
  137. } ;# end switch
  138. }
  139.  
  140. default {
  141. puts "nothing found"
  142. incr x_pos
  143. incr y_pos
  144. }
  145. } ;# end switch
  146. incr i
  147. switch [string range $line $x_pos $y_pos] { "" { break } }
  148. }
  149. puts ">> $list"
  150. } ;# end foreach
  151.  

Comments

Posted by mookie at Fri Sep 20 00:22:12 GMT 2024 [text] [code]

Replace: switch [binary encode hex [string range $line $x_pos $x_pos]] { 5f { puts "indeed my previous character is a _ @ [expr $z-1]" lappend list [expr $z-1] } default { puts "it was not" break } with switch [binary encode hex [string range $line $y_pos $y_pos]] { 5f { puts "indeed my previous character is a _ @ [expr $z-1]" lappend list [expr $z-1] } default { puts "it was not" break } As I was subtracting $x_pos by minus one, it would than hunt backwards, find the same result, than loop.. strange.

Add a comment

Please note that this site uses the meta tags nofollow,noindex for all pages that contain comments.
Items are closed for new comments after 1 week