View previous topic :: View next topic
|
Author |
Message |
Gie Indesteege
New User
Joined: 20 May 2008 Posts: 3 Location: Leuven - Belgium
|
|
|
|
Hi,
is it possible to retrieve the name of the calling (main) REXX procedure in a called (subroutine) REXX procedure?
Thanks for the info
Gie
e.g. MyMain exec:
/* REXX main routine*/
V1 = 5
Call MySUB V1
If result > ....
exit
----------------------------------------------------------------
MySub exec:
/* REXX sub routine */
ARG Vx
/* -> I want to know the identity of the caller here */
Return x
---------------------------------------------------------------- |
|
Back to top |
|
|
genesis786
Active User
Joined: 28 Sep 2005 Posts: 210 Location: St Katherine's Dock London
|
|
|
|
i think one way is to pass the caller program name (main) to called program (subroutine).
MAIN
Code: |
/* rexx */
say 'in MAIN'
call SUBRTN MAIN
say 'out of SUBRTN, in MAIN'
exit
|
SUBRTN
Code: |
/* rexx */
parse arg caller_pgm
say 'in SUBRTN'
say caller_pgm
return
|
|
|
Back to top |
|
|
Gie Indesteege
New User
Joined: 20 May 2008 Posts: 3 Location: Leuven - Belgium
|
|
|
|
Thank you for that information, but I wanted to know if it is possible to obtain the caller's identity without passing the name as an argument?
In other words: is it possible to get access to the calling stack of the REXX interpreter?
Gie |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
if Your rexx subroutine functions needs to behave differently when called from different <caller>
from any point of view , the most appropriate way is to put an additional parm to select the proper subroutine/function behavior |
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
Take a look at the PARSE SOURCE instruction.
O. |
|
Back to top |
|
|
Gie Indesteege
New User
Joined: 20 May 2008 Posts: 3 Location: Leuven - Belgium
|
|
|
|
PARSE SOURCE only returns information on the way the routine is called (FUNCTION, SUBROUTINE or EXEC). Not the name of the caller.
Passing additional information is a valuable option, but this means that existing programs have to be modified.
I wondered whether it is/was possible to access the calling 'stack' in REXX to get that information, without changing existing 'caller' procs.
Gie |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
Quote: |
but this means that existing programs have to be modified. |
partially true, a good way around it would be to modify only the subroutine
checking the number of parameters, something along the lines
Code: |
parse version _version_
say "parse version _version_" _version_
parse source _source_
say "parse source _source_ " _source_
call sub1 a, b, c
call sub1 f, a, b, c
call sub1 f
exit
sub1:
say "inside sub1 "
if arg() = 3 then do
say "called old style"
parse arg arg1, arg2, arg3
end
else if arg() = 4 then do
say "called new style"
parse arg funccode, arg1, arg2, arg3
end
else ,
say "called with wrong arg count"
return |
or using a two stage parsing...
parse as if a function code was provided
if the assumed function code is invalid , reparse onlu for the real args
something like
Code: |
a = "a"
b = "b"
c = "c"
f = "f"
f1 = "f1"
f2 = "f2"
f2 = "f2"
call sub1 a, b, c
call sub1 f, a, b, c
call sub1 f
call sub2 a, b, c
call sub2 f1, a, b, c
call sub2 f2, a, b, c
exit
sub1:
say "inside sub1 "
if arg() = 3 then do
say "called old style"
parse arg arg1, arg2, arg3
end
else if arg() = 4 then do
say "called new style"
parse arg funccode, arg1, arg2, arg3
end
else ,
say "called with wrong arg count"
return
sub2:
say "inside sub2 "
parse arg funccode, arg1, arg2, arg3
if wordpos(funccode,"f1 f2 f3 f4") = 0 then do
funccode = "default"
parse arg arg1, arg2, arg3
end
say "sub2 called with funccode" funccode
return
|
|
|
Back to top |
|
|
jasorn Warnings : 1 Active User
Joined: 12 Jul 2006 Posts: 191 Location: USA
|
|
|
|
While the suggested solutions seem to make sense, I'd like to know the name of the calling routine for the sake of reporting purposes and would rather not rely on a passed argument.
Does the fact no solution to do that was given mean it's not possible or very hard to do? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
Quote: |
Does the fact no solution to do that was given mean it's not possible or very hard to do? |
not possible |
|
Back to top |
|
|
|