1

I'm new to T32 script, and got a question about the scripting. Looking into our project's script, I found the code like below :

A.cmm
=======================================================
....
   if (&AAA==TRUE())
   (
      do B.cmm F=test1
      entry &detect
   )
.....
=======================================================

B.cmm
=======================================================
.......
test1:
........
return TRUE()
=======================================================

Got few questions: 1. is the entry function used to receive the return value of test1 subroutine, and put it to "detect" macro? 2. Any meaning of "F="? Can't we just use test1 behind do command? Thanks!

Nobody
  • 179
  • 2
  • 8

1 Answers1

4
DO <filename> [<parameter_list>]

This means F=test1 is a parameter which should be evaluated inside B.cmm. B.cmm seems to use F=function to decide which function inside B.cmm is called. There is probably some code similar to this inside B.cmm:

LOCAL &ARGS &ARG_FUNCTION 
ENTRY %LINE &ARGS
&ARG_FUNCTION=STRing.SCANAndExtract("&ARGS","F=","")

IF "&ARG_FUNCTION"!=""
(
    PRIVATE &rval
    GOSUB &ARG_FUNCTION
    ENTRY &rval
    ENDDO &rval
)
ENDDO

ENTRY is used for getting the parameters as well as getting the return value. entry &detect gets the return value from the call to B.cmm and saves it to &detect.

In newer versions of TRACE32 you can also use PARAMETERS and RETURNVALUES instead of ENTRY. However with PARAMETERS/RETURNVALUES all arguments must be passed in double-quotes (e.g. DO B.cmm "F=test1"). The example above would then look like this:

LOCAL &ARGS &ARG_FUNCTION
PARAMETERS &ARGS
&ARG_FUNCTION=STRing.SCANAndExtract("&ARGS","F=","")

IF "&function"!=""
(
    PRIVATE &rval
    GOSUB &function "&args"
    RETURNVALUES &rval
    ENDDO "&rval"
)
ENDDO
Joseph Lisee
  • 3,439
  • 26
  • 21
dev15
  • 665
  • 3
  • 14
  • Hi @dev15: Amazing! the code indeed got something like this! – Nobody Jan 16 '17 at 16:09
  • &FUNCTIONName=STRing.SCANAndExtract("&arguments","F=","") if ("&FUNCTIONName"=="") ( &FUNCTIONName=STRing.SCANAndExtract("&arguments","f=","") ) – Nobody Jan 16 '17 at 16:11
  • I got question here, I think STRing.SCANAndExtract is to extract all the arguments (since we use %LINE) behind do xxx.cmm command, right? And then it'll search for "F=" character, and characters following this "F=" will be assigned to &ARG_FUNCTION, so in my case, &ARG_FUNCTION=test1 , right? – Nobody Jan 16 '17 at 16:18
  • And, why do we want to judge this : IF "&ARG_FUNCTION"!="" ? Does it mean that if user did type anything after do command, it will enter this IF expression? Why not use : IF "&ARG_FUNCTION"="test1", and then GOSUB xxxx ? – Nobody Jan 16 '17 at 16:23
  • To your 1st question: You are indeed right about the way STRing.SCANAndExtract is used here. – Holger Jan 16 '17 at 21:43
  • To your 2nd question: The statement `IF "&ARG_FUNCTION"!="` means "only execute the following block if &ARG_FUNCTION is not empty" which is indeed used here to check if the script was called with "F=". You could also use `IF "&ARG_FUNCTION"=="test1"`, but then you have to repeat this for every other function you want to call within the script. The construct shown here by dev15 is something like the switch-statement from the C language: The execution continues at the specified label. By the way: You can handle the case in which the label/function does not exist with an `ON ERROR` handler – Holger Jan 16 '17 at 23:24
  • Hi @Holger, thanks a lot for your detailed explanation! Just want to confirm the usage of ENTRY in these examples..... 1. ENTRY %LINE &ARGS This ENTRY is used to get the parameters from this command `do B.cmm F=test1` 2. ENTRY &rval This ENTRY is used to get the return value from this sub routine `GOSUB &ARG_FUNCTION` 3. ENTRY &detect This ENTRY is used to get the return value from B.cmm (which should be `RETURN &rval` in dev15's example) – Nobody Feb 04 '17 at 14:48
  • So ENTRY has two functions, one is to get parameters, and the other is to get the return values. If the caller got some parameters behind it, there must be an ENTRY in front of the callee to "accept" these parameter. and if the callee has return value in the end, there must be an ENTER in next line of the caller to "receive" the value back. Am I understanding it correctly? Thanks! :) – Nobody Feb 04 '17 at 14:48
  • I think you've got it: ENTRY can be used to get the parameters passed to a script called with DO inside that called script. It can be used to get the parameters passed to a subroutine called with GOTO inside that routine. It can be used to get the values return by a called script with ENDDO. It can be used to get the values returned via RETURN by a GOSUB-subroutine. However ENTRY only assigns values to macros. It does not create new local or private macros if a macro with that name already exist. Thus PRIVATE/LOCAL should normally be used before ENTRY (like in the examples from dev15) – Holger Feb 06 '17 at 23:55