issue with tcl error in new CL 6.0.1

Clovertech Forums Read Only Archives Cloverleaf Tcl Library issue with tcl error in new CL 6.0.1

  • Creator
    Topic
  • #54344
    Kevin Crist
    Participant

      We are in process of upgrade from CL 5.4.1 to CL 6.0.1 and i know that is a big jump and have found some procs that have needed updating but i am unsure how to fix this one. We have a tclproc that removes the ampersand and replaces it with a “+” but getting the error below.

      Any ideas would be awesome. thanks for your time. code below as well.

      0:TEST] Tcl error:

      msgId = message0

      proc = ‘tpsFixAmpersand’

      args = ”

      result = ‘wrong # args: should be “switch ?switches? string {pattern body … ?default body?}”‘

      errorInfo: ‘

      wrong # args: should be “switch ?switches? string {pattern body … ?default body?}”

         while executing

      “switch -exact — $nextchar

         (procedure “tpsFixAmpersand” line 60)

         invoked from within

      “tpsFixAmpersand {MSGID message0} {CONTEXT sms_ib_data} {ARGS {}} {MODE run} {VERSION 3.0}”‘

      Code:


      #######################################################################################
      #######################################################################################
      #######################################################################################
      #
      # Name: tpsFixAmpersand.tps
      # Purpose: This procedure fixes messages with the special character “&” in them.
      # This was needed because messages from affinity going to INPC had the
      # “&” in the message and it would mess up their feed.
      # The messages will now be fixed.
      # If the “&” is the last character in a field or subfield, it is deleted.
      # If it is in the middle of the field, it is replaced with a “-”
      #
      #
      # UPoC type: tps
      # Args: tps keyedlist containing the following keys:
      #       MODE    run mode (”start”, “run” or “time”)
      #       MSGID   message handle
      #       ARGS    user-supplied arguments:
      #
      # Returns: tps disposition list:
      #
      # John Zalesak 01-08-2009
      # Created
      #
      # John Zalesak 01-15-2009
      # Modified message in engine log so we can see it better
      #
      #
      #######################################################################################
      #######################################################################################
      #######################################################################################

      proc tpsFixAmpersand { args } {

      #######################################################################################
      # Setup some globals used
      #######################################################################################

      global HciConnName
      global HciRoot
      global HciSite

      #######################################################################################
      # Get the Connection Name for Error/Debug Messages
      #######################################################################################

      set myname “$HciSite/$HciConnName/[lindex [info level 1] 0]”

      #######################################################################################
      # Initialize Variables Used
      #######################################################################################

      set dispList {} ;# Disposition List Returned to Engine
      set badchar & ;# Bad Character to Look for
      set charloc 0 ;# Location of offending character
      set nextloc 0 ;# Location of Char after bad char
      set newchar “” ;# Replace bad char with this

      #######################################################################################
      # Load in the arguments we need that were passed from the caller
      #######################################################################################

      keylget args MODE mode             ;# The mode the engine called from

      #######################################################################################
      # We only want to take action if called from the run mode
      #######################################################################################

      switch -exact — $mode {
      start { }

      run {

      set mh [keylget args MSGID] ;# Get message handle from args
         set dispList [list “CONTINUE $mh”] ;# Initialize to good message
           set msg [msgget $mh] ;# Get a copy of the message
           
           set fldSep [string index $msg 3] ;# Field Seperator
           set subSep [string index $msg 4] ;# Sub-Field Seperator
           set repSep [string index $msg 5] ;# Repeating Field Seperator

           
      #######################################################################################
      # Search for “&” and if found correct
      #  Start at location 8 to get past field seperator definitions
      #######################################################################################

           while {[set charloc [string first $badchar $msg 8]] != -1} {
           
            set nextchar [string index $msg [expr $charloc + 1]]
           
            switch -exact — $nextchar
            $fldSep –
            $subSep –
            $repSep –
            “r” {set newchar “”}
            default {set newchar “+”}

      # echo “:WARN ”
      # echo “:WARN ——————————————————————-”
      # echo “:WARN $badchar character found going to infinity at location $charloc”
      # echo “:WARN Here is $myname”
      # echo “:WARN Now is [clock format [clock scan now] -format “%D – %T”]”
      # echo “:WARN Original Message shown below”
      # echo $msg
      # echo “:WARN ——————————————————————-”
      # echo “:WARN ”

      set msg [string replace $msg $charloc $charloc $newchar]

           }
           
      msgset $mh $msg

      }

         time { }
             
         shutdown { }
       
      } ;# End Switch

      return $dispList

      } ;# End Proc

    Viewing 9 reply threads
    • Author
      Replies
      • #81086
        Todd Yingling
        Participant

          Have you tried removing the comments from the switch command?  I believe this confuses the switch.  I understand you are commenting out the echos, but try removing them once.

        • #81087
          Kevin Crist
          Participant

            thanks for the reply. but i still get the error. i thought maybe it had something to do with the “”. i have had a couple of procs error in the new version where the was at the end of a line and the code went to the next line.

          • #81088
            James Cobane
            Participant

              Kevin,

              Have you tried putting braces around the body of the ‘switch’ statement?

              Jim Cobane

              Henry Ford Health

            • #81089

              A at the end of the line in tcl escapes the line break and wraps the code onto the next line. Are you meaning to use a literal here? If so, try \ instead.

              -- Max Drown (Infor)

            • #81090
              Charlie Bursell
              Participant

                The code for the switch is correct, backslashes and all.  You can code like this since the switch statement and all its arguments are one command.  That is why no remarks are allowed within the body of the switch.

                If I execute your switch statement I get no problems.  There fore I would recommend you look for bogus, unprintable characters with the statement.  Use a hex editor or hcihexdump

                Also make sure the backslash is the last character on a line prior to the line feed.  If not it is just a backslash and not a continuation.  Is this Unix?  If so look for CR at the end of the lines.

                These sort of things happen when you copy from one place to another

              • #81091
                Michael Hertel
                Participant

                  Try removing the comments at the beginning of the run section.

                • #81092
                  Suzy Hoffman
                  Participant

                    I’d try removing the  ;# End Switch comment as well.

                  • #81093
                    Charlie Bursell
                    Participant

                      Good catch Suzy.   Perhaps we were all not seeing the forest for the trees  ðŸ˜€

                      Maybe the error is coming from the TPS switch statement instead of the one in the run mode

                    • #81094
                      David Barr
                      Participant

                        My guess is your file has DOS end-of-line characters. You need to have an LF at the end of each line instead of CRLF. Tcl will normally ignore the extra CR characters, but if you have a backslash as a line continuation character, the backslash is now before a CR instead of an LF, so the line is not continued. The command is truncated at that point and the last argument is a string with a single CR character.

                      • #81095
                        David Barr
                        Participant

                          You can use the “file” command to check this:

                          Code:

                          file tpsFixAmpersand.tcl
                          tpsFixAmpersand.tcl: ASCII English text, with CRLF line terminators

                      Viewing 9 reply threads
                      • The forum ‘Tcl Library’ is closed to new topics and replies.