tcl scipt

  • Creator
    Topic
  • #50410
    mark boomaars
    Participant

    Hi all,

    Can anyone explain to me what this script does?

    Code:

    if { ![clength $line] || [cequal $line x20] || [regexp ^x02+$ $line] }
    { set line “.” ; # for empty lines support in itn01 }
           else
    { set line [split [string trimright $line x02] ” “] }

    I have absolutely no idea what charaters like x20 and x02 mean…

    Thanx

    Mark

Viewing 5 reply threads
  • Author
    Replies
    • #66020
      Tom Rioux
      Participant

      if { ![clength $line] || [cequal $line x20] || [regexp ^x02+$ $line] }

              { set line “.”            ; # for empty lines support in itn01 }

             else

              { set line [split [string trimright $line x02] ” “] }

      ![clength $line]  = is saying that as long as the length of $line is not equal to zero

      [cequal $line x20] = is checking to see if $line is equal to space

      [regexp ^x02+$ $line] = checks for (I think) if there are multiple start of text characters in $line.  I believe the ^ and the $ is having it check for it either at the beginning of the line or the end of the line.

      Any of you tcl experts, by all means, correct me where I may be mistaken.

      Thanks…Tom

    • #66021
      Charlie Bursell
      Participant

      if { ![clength $line] || [cequal $line x20] || [regexp ^x02+$ $line] }

             { set line “.”            ; # for empty lines support in itn01 }

            else

             { set line [split [string trimright $line x02] ” “] }

      What it does in very poor fashion  ðŸ™‚

      If the line is not empty OR the line is equal to a single space OR the line starts with an STX (Hex 02) character set the line to period.  ELSE

      set the line to a list splitting on the STX character and ad a space at the end.  (I assume he wants to add an element?)

      The ORs do not make sense since if line contains a space or a STX it will not  be empty.  I would assume it should read

       if { ![clength $line] && ( [cequal $line x20] || [regexp ^x02+$ $line]) }

      Even then it is poor code

    • #66022
      Michael Hertel
      Participant

      I’ve spent too much time on this but it was fun.

      Here’s what I suggest:

      1) There is a typo, (s)he never meant x02, they meant x20 (space).

      And what you actually get is:

      If there is no length to line (empty) OR line is a single space OR line is all spaces, then set line to a period OTHERWISE split the line into words (in list form after removing all trailing spaces).

      Excercise:

      Code:

      hcitcl>set line {}
      hcitcl>if {![clength $line]} {echo empty}
      empty
      hcitcl>set line “this is a line”
      this is a line
      hcitcl>if {![clength $line]} {echo empty}
      hcitcl>set line [split [string trimright $line x20] ” “]
      this is a line
      hcitcl>foreach item $line {echo >$item<} >this< >is< >a< >line< hcitcl>

      But to answer the orginal question, it is doing the following:

      If there is no length to line (empty) OR line is a single space OR line is all characters, then set line to a period OTHERWISE split the line into words based on spaces (in list form after removing all trailing characters).

    • #66023
      mark boomaars
      Participant

      thanks for all your help guys…

      this is a part of a script that we still use to convert ORU into EDI. If the line is longer than 70 characters, the line has to break nicely and continue in the next TXT segment.

      But where can I find information on what all these hex characters mean:

      e.g. x01 xA0 x02 x20 etc.

    • #66024
      Michael Hertel
      Participant

      You can look up ascii table on the web or here’s a link:

      http://www.asciitable.com

      Hex is usually represented as maybe x02 in code so you would remove the x part and the rest is the number to look up (02). The tables usually don’t zero fill the value so look up 2.

      There is also EBCDIC which is another can of worms.

      I found this interesting blurb at http://en.wikipedia.org/wiki/Extended_Binary_Coded_Decimal_Interchange_Code

      Quote:

      Open source software advocate and hacker Eric S. Raymond writes in his Jargon File that EBCDIC was almost universally loathed by early hackers and programmers because of its multitude of different versions, none of which resembled the other versions, and that IBM produced it in direct competition with the already-established ASCII.

      The Jargon file 4.4.7 gives the following definition:

    • #66025
      Bala Pisupati
      Participant

      There is tool called HEX editor that my collegue suggested. You can look into that too. You can use it for editing binary files of any size, searching and replacing your data in a binary file etc

      http://www.hhdsoftware.com/Products/home/hex-editor-free.html

Viewing 5 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,296
Replies
34,439
Topic Tags
287
Empty Topic Tags
10