user args help

  • Creator
    Topic
  • #50521
    Gary Atkinson
    Participant

    Hi-

    I am stump here.  I set up a proc with some user args, but the engine keeps complaining the syntax is wrong.  Here is the top of the proc:

    Code:


    proc tps_escape_char { args } {
       keylget args MODE mode
       keylget args ARGS uargs   #Get user arguments and set default if not found
       
       set segtable CIS_TABLE     ;keylget uargs SEGMENTBL segtable
       set expr_match {&}         ;keylget uargs EXPR_MATCH expr_match
       set expr_set {\T\}           ;keylget uargs EXPR_SET expr_set

    The error code is this:

    Code:


    [0:TEST] Tcl error:
    msgId = message0
    proc = ‘tps_escape_char’
    args = ‘{SEGMENTBL CIS_TABLE} {EXPR_MATCH &} {EXPR_SET {\T\}}’
    result = ‘wrong # args: keylget listvar ?key? ?retvar | {}?’
    errorInfo: ‘
    wrong # args: keylget listvar ?key? ?retvar | {}?
       while executing
    “keylget args ARGS uargs   #Get user arguments and set default if not found”
       (procedure “tps_escape_char” line 3)
       invoked from within
    “tps_escape_char {MSGID message0} {CONTEXT sms_ib_data} {ARGS {{SEGMENTBL CIS_TABLE} {EXPR_MATCH &} {EXPR_SET {\T\}}}} {MODE run} {VERSION 3.0}”‘

    I’ve used user arguments before without a problem.  What am I missing  ðŸ˜¥ [/code]

Viewing 9 reply threads
  • Author
    Replies
    • #66448
      Gary Atkinson
      Participant

      Ah I forgot a semicolon!  ðŸ˜ˆ  DUH…

    • #66449
      Gary Atkinson
      Participant

      Ok, I may having a “blonde” day.  I am posting my entire proc.  Tcl is now complaining of the an extra switch without a body, but I do not see this…

      I am posting my code in hopes someone pitty me’s  ðŸ˜¯

      Code:


      proc tps_escape_char { args } {
         keylget args MODE mode
         keylget args ARGS uargs    ;# Get user arguments and set default if not found
         
         set segtable CIS_TABLE     ;keylget uargs SEGMENTBL segtable
         set expr_match {&}         ;keylget uargs EXPR_MATCH expr_match
         set expr_set {\T\}           ;keylget uargs EXPR_SET expr_set          
         
         set dispList {}    ;# Nothning to return

         switch -exact — $mode {  ;# Fetch mode
             start {
        return {}       ;# Nothing specific
             }

             run {
                 
                 keylget args MSGID mh ;# Get message handle
       set msg [msgget $mh]                   ;# Get message
            #  Create a copy of the message omitting the encoding characters and check
            #    Do any $expr_match exist in the remaining  message  – if yes, reformat else continue msg
                 set chkmsg [crange $msg 9 end]
                  if {[regexp “$expr_match” $chkmsg] == 1} {
            # Get field separator from MSH segment
                    set fieldSeparator [crange $msg 3 3]
            # Split message into segments  
                   set segmentList [split $msg r]
                   set newSegmentList “”
            # Search table for each Segment
            # When match on Segment ID, field numbers to check are returned
                   foreach segment $segmentList {
                          set tblfieldlist 0
                          set segmentID [crange $segment 0 2]
                          set tblfieldlist [tbllookup $segtable $segmentID]
                          if {$tblfieldlist != 0} {
                                 set fieldIDlist [split $tblfieldlist “-“]
                                 set fieldList [split $segment $fieldSeparator]
                                 foreach fieldID $fieldIDlist {
                                      set oldfield “”
                                      set oldfield [lindex $fieldList $fieldID]
       if {$oldfield != “”} {  
          regsub -all — “$expr_match” $oldfield “$expr_set” newfield
                                         set fieldList [lreplace $fieldList $fieldID $fieldID $newfield]
                                     }
                                 }
                          set segment [join $fieldList $fieldSeparator]
                         }      
                  set newSegmentList [lappend newSegmentList $segment]
                  }
                  set newMsg [join $newSegmentList r]
                  set mhNew [msgcopy $mh]
                  msgset $mhNew $newMsg
                  lappend dispList “KILL $mh”
                  lappend dispList “CONTINUE $mhNew”
                 } else {
                  lappend dispList “CONTINUE $mh”
                 }
           }

        shutdown {
         # Doing some clean-up work
        }

             default {
        error “Unknown mode ‘$mode’ in tps_escape_char”
         }
        }

       return $dispList
      }

      The error code is this:

      Code:


      [0:TEST] Tcl error:
      msgId = message0
      proc = ‘tps_escape_char’
      args = ”
      result = ‘extra switch pattern with no body’
      errorInfo: ‘
      extra switch pattern with no body
         while executing
      “switch -exact — $mode {  ;# Fetch mode
             start {
        return {}       ;# Nothing specific
             }

             run {
                 
                 keyl…”
         (procedure “tps_escape_char” line 11)
         invoked from within
      “tps_escape_char {MSGID message0} {CONTEXT sms_ib_data} {ARGS {}} {MODE run} {VERSION 3.0}”‘

      [/code]

    • #66450
      Gary Atkinson
      Participant

      Well, I removed all the comments and the code runs now (weird).  At any rate I have regular expression questions.  If I search for “&” then replace with T this works.  But if I do the reverse, and search for T, it is found but not replaced with “&”.

    • #66451

      You might have a problem with your braces. I went through and tried to line things up and clean things up to make it more readable and thus easier to troubleshoot..

      proc tps_escape_char { args } {

      [code]proc tps_escape_char { args } {

      -- Max Drown (Infor)

    • #66452
      Steve Carter
      Participant

      I haven’t looked over the entire proc, but you’re problem with the switch statement is this:

      switch -exact — $mode {  ;# Fetch mode

      This is what’s causing the ‘extra switch without a boy’.  You can’t have comments between the switches….only inside the body of each switch.

      Good:

      switch -exact — $mode {

        start {

            # Good comment

        }

        run {

            # Good comment

        }

      }

      Bad:

      switch -exact — $mode {

         # start switches

         start {

         }

         run {

         }

      }

      I don’t think Tcl really started enforcing this until 8.4.

      Steve

    • #66453
      Gary Atkinson
      Participant

      Thanks.  I did find something on a wiki site about the comments.  Any ideas on the regexp problem?

    • #66454

      Use string map instead of regsub. Backslash and ampersand cause all kinds of issues in tcl regular expressions.

      -- Max Drown (Infor)

    • #66455
      Gary Atkinson
      Participant

      I needed to escape the &.  After that it worked.  Thanks all for help and tips!

    • #66456

      Future reference:

      Code:

      [string map {\T\ & \F\ & \R\ & \Z\ &} $string]

      -- Max Drown (Infor)

    • #66457
      Troy Morton
      Participant

      You’re missing the # character in the comments following the regsub commands.

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

Forum Statistics

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