tcl argument question

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf tcl argument question

  • Creator
    Topic
  • #51133
    Kevin Crist
    Participant

    We have a tclproc that we use that we put in arguments to change a field value. That works great, but i was under the impression i could put in another set of arguments but i doesnt recognize the second set. For example… {SEGMENT MSH}{FIELDNUM 8}{FIELDVAL MSH^A04}. That one works but i put this below and isnt recognized. {SEGMENT EVN} {FIELDNUM 1} {FIELDVAL A04}. I know this can all be set up easily in an xlate but in this case we dont have one, i was just seeing if i could add one more set of args. how do i set this up for multiple args. thanks for any ideas.

    #########################################################################################

    # Initialize Variables Used

    #########################################################################################

    set dispList

  • ;# Disposition List Returned to Engine

    set fldSep “” ;# Field Seperator – get from MSH

    set subSep “” ;# SubField Seperator – get from MSH

    set repSep “” ;# Repeating Field Seperator – get from MSH

    set SegName “” ;# User Supplied Segment to Change

    set FieldNum 0 ;# User Supplied Field Num to Change

    set FieldVal “” ;# User Supplied Value to set in Field Num

    set segList

  • ;# Message Segments in List Form

    set SegPos

  • ;# List of Seg Pos in segList that match

    ;#  the User Supplied Segment Name

    #########################################################################################

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

    #########################################################################################

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

    keylget args ARGS.SEGMENT SegName ;# Segment Name

    set SegName [string toupper $SegName] ;# Force to uppercase

    keylget args ARGS.FIELDNUM FieldNum ;# Field Number to Change

    keylget args ARGS.FIELDVAL FieldVal ;# Value to Set Field To

    #########################################################################################

    # Switch based on what mode the engine was in when it called the procedure

    #########################################################################################

     switch -exact — $mode {

       run {

        set mh [keylget args MSGID] ;# Get message handle from args

       set dispList

      ;# 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

      set segList [split $msg r] ;# Split message into segList

      #########################################################################################

      # Validate the user supplied values

      #########################################################################################

      if { $SegName == “” } {

       echo n n

       echo “==========================================================”

        echo “:WARN – No Segement Name Was Supplied !”

       echo “:WARN – Message Continued As Is.”

       echo “:WARN – Here Is: $myname”

       echo “:WARN – Now Is: $nowis”

       echo $msg

       echo “==========================================================”  

       echo n n

             return $dispList

      }

      if { $FieldNum == “” || $FieldNum == 0 } {

       echo n n

       echo “==========================================================”

        echo “:WARN – Invalid or No Field Number Was Supplied !”

        echo “:WARN – Field Number is: “$FieldNum””

       echo “:WARN – Message Continued As Is.”

       echo “:WARN – Here Is: $myname”

       echo “:WARN – Now Is: $nowis”

       echo $msg

       echo “==========================================================”  

       echo n n

             return $dispList

      }

      #########################################################################################

      # Find Position of Segement(s) – If missing -> Continue Message and Return

      #########################################################################################

      set SegPos [lsearch -all -regexp $segList “^$SegName”]

      if { [lindex $SegPos 0] < 0 } {  echo n n  echo “==========================================================”   echo “:WARN – Segment “$SegName” Is Missing !”  echo “:WARN – Message Continued As Is.”  echo “:WARN – Here Is: $myname”  echo “:WARN – Now Is: $nowis”  echo $msg  echo “==========================================================”    echo n n        return $dispList } ######################################################################################### # Force the Segment/Field Value – Add Blank fields is Seg is too short. ######################################################################################### foreach Seg $SegPos { set fldList [split [lindex $segList $Seg] $fldSep] set fldCnt [llength $fldList] for { set flds $fldCnt } { $flds < [expr $FieldNum + 1] } { incr flds } {   lappend fldList {}   }     lset fldList $FieldNum $FieldVal     lset segList $Seg [join $fldList $fldSep]     } ######################################################################################### # Recreate the message and store back at msg handle #########################################################################################  set msg [join $segList r]        msgset $mh $msg } start { }    time { }    shutdown { }    default {     echo “:WARN”     echo “:WARN ======================================”  echo “:WARN – tps called with invalid mode !” echo “:WARN – Mode Is: $mode” echo “:WARN – Here Is: $myname” echo “:WARN – Now Is: $nowis” echo “:WARN ======================================” echo “:WARN”    } } ;# End Switch return $dispList } ;#

Viewing 6 reply threads
  • Author
    Replies
    • #68893
      Tom Rioux
      Participant

      Kevin,

      Here is the proc.  I left most of it intact.  I changed mostly the top part of it.   When you put the args in for the proc, put them in as :

      {{SEGMENT MSH} {FIELDNUM 8} {FIELDVAL ADT^A04}}

      {{SEGMENT EVN} {FIELDNUM 1} {FIELDVAL A04}}

      I’ve done a little testing with it and it appears to work with what little testing I’ve done.  You will definitely want to test it out thoroughly before using.

      proc arg_insert { args } {

         global Debug

         keylget args MODE mode               ;# Fetch mode

         #########################################################################################

         # Initialize Variables Used

         #########################################################################################

         set dispList {} ;# Disposition List Returned to Engine

         set fldSep “” ;# Field Seperator – get from MSH

         set subSep “” ;# SubField Seperator – get from MSH

         set repSep “” ;# Repeating Field Seperator – get from MSH

         set SegName “” ;# User Supplied Segment to Change

         set FieldNum 0 ;# User Supplied Field Num to Change

         set FieldVal “” ;# User Supplied Value to set in Field Num

         set segList {} ;# Message Segments in List Form

         set SegPos {} ;# List of Seg Pos in segList that match

             ;#  the User Supplied Segment Name

         #########################################################################################

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

         #########################################################################################

         keylget args ARGS msgargs

         global HciConnName env

         set module “$HciConnName:[lindex [info level [info level]] 0]”

         append module :[clock format [clock seconds] -format %m%d%H%M]

      #########################################################################################

      # Switch based on what mode the engine was in when it called the procedure

      #########################################################################################

         switch -exact — $mode {

             start {

                 # Perform special init functions

         # N.B.: there may or may not be a MSGID key in args

         if [file exists $HciConnName.debug] {

            set Debug 1

         } else {

            set Debug 0

         }

             }

             run {

      set mh [keylget args MSGID] ;# Get message handle from args

        set dispList

        ;# 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

        set segList [split $msg r] ;# Split message into segList

               

                 foreach  pargs $msgargs {

         #########################################################################################

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

                   #########################################################################################

                   set SegName [keylget pargs SEGMENT]

                   set FieldNum [keylget pargs FIELDNUM]

                   set FieldVal [keylget pargs FIELDVAL]

         #########################################################################################

         # Validate the user supplied values

         #########################################################################################

         if { $SegName == “” } {

            echo n n

            echo “==========================================================”

              echo “:WARN – No Segement Name Was Supplied !”

            echo “:WARN – Message Continued As Is.”

            echo $msg

            echo “==========================================================”  

            echo n n

                      return $dispList

                   }

         if { $FieldNum == “” || $FieldNum == 0 } {

            echo n n

            echo “==========================================================”

              echo “:WARN – Invalid or No Field Number Was Supplied !”

              echo “:WARN – Field Number is: “$FieldNum””

            echo “:WARN – Message Continued As Is.”

              echo $msg

            echo “==========================================================”  

            echo n n

                  return $dispList

             }

           #########################################################################################

         # Find Position of Segement(s) – If missing -> Continue Message and Return

         #########################################################################################

         set SegPos [lsearch -all -regexp $segList “^$SegName”]

         if { [lindex $SegPos 0] < 0 } {

        echo n n

        echo “==========================================================”

        echo “:WARN – Segment “$SegName” Is Missing !”

        echo “:WARN – Message Continued As Is.”

        echo $msg

        echo “==========================================================”  

        echo n n

              return $dispList

         }

         #########################################################################################

         # Force the Segment/Field Value – Add Blank fields is Seg is too short.

         #########################################################################################

         foreach Seg $SegPos {

        set fldList [split [lindex $segList $Seg] $fldSep]

        set fldCnt [llength $fldList]

        for { set flds $fldCnt } { $flds < [expr $FieldNum + 1] } { incr flds } {

          lappend fldList {}

          }

         

          lset fldList $FieldNum $FieldVal

          lset segList $Seg [join $fldList $fldSep]

         

             }

                 }

         #########################################################################################

         # Recreate the message and store back at msg handle

         #########################################################################################

         set msg [join $segList r]  

               msgset $mh $msg

                }

                time {

                   # Timer-based processing

           # N.B.: there may or may not be a MSGID key in args

              }

              shutdown {

              }

              default {

            echo “:WARN”

            echo “:WARN ======================================”

        echo “:WARN – tps called with invalid mode !”

        echo “:WARN – Mode Is: $mode”

        echo “:WARN ======================================”

        echo “:WARN”

              }

          } ;# End Switch

        return $dispList

        } ;#

    • #68894
      Kevin Crist
      Participant

      thanks tom, i will give this a try when i get a chance. If you have time can you explain the changes you made, it helps me in the learning process to know why something is like that if i cant figure it out.

      thanks so much.

    • #68895
      Charlie Bursell
      Participant

      I guess my response to this would be: WHY!  ðŸ˜•

      It would seem to me that a proc such as this would cause more problems in its use and maintenance that it is worth.  How much effort would be involved to write a simple proc to replace a field?  Especially if you are doing several fields.  You are then parsing out the same segment multiple times.

      Write a simple proc using namespaces with a separate routine for each filter.  You can then have one routine to parse the data into shared variables.  It is then very simple to add or modify additional filters.

      As I have stated many times over, the bang for the buck is in the ease of maintenance not in the development.  According to this document: http://fast.faa.gov/pricing/c1919-6.htm  “Estimates of the magnitude of software maintenance costs range from 50 to 75% of overall software life cycle costs”

      I am off my soap box now  ðŸ™„

    • #68896
      Tom Rioux
      Participant

      Here are the two major changes that I made.   First of all, you were accessing the arguments as:

      keylget args ARGS.SEGMENT SegName

      Without some sort of looping, you are only going to grab the first “SEGMENT” argument and never get to the second. So what I did to solve that was to put the all of the args into one variable called “msgargs”.   Then separate each iteration into its own grouping:

      {{SEGMENT MSH} {FIELDNUM 8} {FIELDVAL ADT^A04}}

      {{SEGMENT EVN} {FIELDNUM 1} {FIELDVAL A04}}

      So, the first iteration of “msgargs” is:  {{SEGMENT MSH} {FIELDNUM 8} {FIELDVAL ADT^A04}}

      The second iteration of “msgargs” is:  {{SEGMENT EVN} {FIELDNUM 1} {FIELDVAL A04}}

      Second, you need to loop through the msgargs with a foreach loop to grab each iteration grouping.   I set each iteration into a variable called “pargs”.   No real reason, that is just what we call them here.   With that being done, I can then grab the “SEGMENT”, the “FIELDNUM” and the “FIELDVAL” values individually, much like you were doing previously:

      set SegName [keylget pargs SEGMENT]

      set FieldNum [keylget pargs FIELDNUM]

      set FieldVal [keylget pargs FIELDVAL]

      This should be done inside the foreach loop.  Each pass will give you any subsequent argument grouping that you have provided.  

      Let me know if you have any further questions.  I know this isn’t the best of explanations but I think you can get my meaning.

      Thanks….Tom

    • #68897
      Kevin Crist
      Participant

      thanks for the explanation tom. it makes sense and was understandable. Just more nuggets of info to go on my tcl wall.

    • #68898
      Troy Morton
      Participant

      Hey Charlie,

      I understand where you’re coming from, however, when you support hundreds of interfaces, you don’t want to re-write the same filter procs over and over with different fields and values to filter.  

      In my opinion its best to have one filter proc that takes arguments and filters accordingly.  Much less code maintenance than having two hundred filter procs for two hundred applications.

      Obviously, its also better to filter messages with a pre-proc if possible so that messages are not using up resources being Xlated just to be KILLed.

      My .02 cents.  ðŸ˜†

    • #68899
      Charlie Bursell
      Participant

      Whatever works for you is OK with me  ðŸ˜€

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

Forums

Forum Statistics

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