JCShell documentation and examples for DEFUN

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

JCShell documentation and examples for DEFUN

Jump to solution
4,203 Views
makinako
Contributor III

I'm migrating a Java Card applet test structure to make use of JCShell and am having trouble finding documentation or examples on the use of DEFUN. I have a couple of questions out of this:

1) Aside from the JCShell user manual 6.9.0.X which doesn't really cover DEFUN syntax much, are there any further documents or examples that can be made available for more advanced JCShell scripting scenarios?

2) In particular, is it possible to provide arguments to functions defined using DEFUN? If not, is there a convention NXP uses to achieve a similar result?

Thanks

Labels (2)
Tags (2)
1 Solution
3,879 Views
msjcard
Contributor III

Older versions of JCShell had a directory called "scripts" and there are a number of examples within that directory of the use of DEFUN.

In any event, DEFUN is equivalent to placing the contents of the DEFUN function in a <name>.jcsh file in the defined scripts directory where <name> is the name of the function (and without the cotaining DEFUN END pair).  AFAICT, the instantiation of the DEFUN function is deferred until the containing file is called, and then is available for the life of the jcshell session.

 

View solution in original post

7 Replies
3,880 Views
msjcard
Contributor III

Older versions of JCShell had a directory called "scripts" and there are a number of examples within that directory of the use of DEFUN.

In any event, DEFUN is equivalent to placing the contents of the DEFUN function in a <name>.jcsh file in the defined scripts directory where <name> is the name of the function (and without the cotaining DEFUN END pair).  AFAICT, the instantiation of the DEFUN function is deferred until the containing file is called, and then is available for the life of the jcshell session.

 

3,795 Views
makinako
Contributor III

Thanks for the tip! I found the scripts folder in the v3.7.2.4 package in the archives. In this I found scripts/tools/script_tlv.jcsh which showed an example of arguments used by DEFUN:

So with the script "myscript.jcsh":

 

# Testing function arguments
DEFUN my_test_function
	/echo argv[0] is ${argv[0]}
	/echo argv[1] is ${argv[1]}
	/echo argv[2] is ${argv[2]}
END

# Run it with various arguments
my_test_function A B C
my_test_function A B
my_test_function A

 

 

And executing it using:

 

myscript 1 2 3

 

 

(I deliberately put "1  2 3" to make sure it is not getting argv from the arguments to the main script instead of the call to the function)

And I get the output:

 

argv[0] is A 
argv[1] is B 
argv[2] is C 
argv[0] is A 
argv[1] is B 
argv[2] is 
argv[0] is A 
argv[1] is 
argv[2] is 

 

 

Thanks!

P.S. @Kan_Li a suggestion for NXP is to update and re-introduce these scripts into the JCShell releases as well as explicitly document DEFUN.

Tags (1)
4,190 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi @makinako ,

 

Such kind of docs are under DNA, have you already signed it with NXP? If not, you may request it on line.

Kan_Li_0-1679886734884.png

 

Have a great day,
Kan


-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

 

4,186 Views
makinako
Contributor III
Hi yes I have an active NDA and have the JCOP 4.5 tools which contain JCShell, etc. As I described in my post there is a JCShell user manual, but this has no definition of the usage of DEFUN and no separate example scripts.
I am unable to find anything beyond this in the Secure Files and in my experience, it is not easy to know what documentation may exist that I do not have access to as there is no listing of available documents until you specifically have them pushed to your account.
Are you able to provide doc #'s or other references and can you push documents to an existing account with product access, or does this need to go through our account manager?
4,180 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi @makinako ,

 

Are you referring to the following DEFUN info?

https://www.gnu.org/software/emacs/manual/html_node/eintr/defun.html 

 

Have a great day,
Kan


-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

4,175 Views
makinako
Contributor III

No this is not the correct syntax. The code sample you just sent me is LISP and JCShell DEFUN does not resemble it. The example on the link you just sent me is this:

(defun function-name (arguments…)
  "optional-documentation…"
  (interactive argument-passing-info)     ; optional
  body…)

 and here is an example out of the JCShell documentation:

DEFUN GET_SCR_PATH
/echo ${script.name}
END

As I said in my first message, there is no actual section in the JCShell document that defines the syntax for DEFUN and the examples are not very comprehensive.

4,151 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi @makinako ,

Yes, it is strange not documented in JCShell user manual, and I have also asked a few people but there seems to be no such document at all. I am sorry about that! All I can do is sharing example. If you need it, I may share you via the Case Portal. Please submit a private ticket for it according to the following video.

https://www.nxp.com/video/tutorial-for-nxp-support-case-portal:NCP-VIDEO 

Have a great day,
Kan


-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------