English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System > Coders. Scripting

 
 
Thread Tools
Old 01 November 2021, 21:25   #1
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,886
Stick out tongue AmigaOS 1.3 'wmn' command

Based on DisasterIncarna's thread I have made a small script called 'wmn' (What's My Name) that is able to retrieve it's own name...

As I noticed, and wrote here, the script name is only available during the script initialization (.key, .def, argument substitution (if any)) and therefore really rapidly disappears. Then the 'status' command display the name of the commands executed within the script...

Therefore, what follows is only a proof of concept since to retrieve its name, the script has to call itself...

Even if I wrote it as a loop, I was surprised to notice that 9 out of 10, 1 recursive call was enough to retrieve the name.

Here is the code :
Code:
wmn :
.key DUMMY1
.bra {
.ket }
.def DUMMY1 0
failat 11
echo >env:np1{$$} "Process  {$$}: No command loaded"
echo >env:np2{$$} "Process  {$$}: wait"
if NOT EXISTS env:COMPTEUR{$$}
    setenv COMPTEUR{$$} 0
else
    eval <env:COMPTEUR{$$} >NIL: VALUE2 1 OP + TO t:cpt{$$}  ?
    type >env:COMPTEUR{$$} t:cpt{$$}
endif
if "{DUMMY1}" EQ "0"
    echo >t:NShell{$$} "wait 2 SECS*Nbreak {$$} C*Nwait 2*Nstatus >env:pn{$$} PROCESS {$$}*Nwait 3*Nendcli *>NIL:"
    run >NIL: newshell NEWCON:300/0/10/10/mlk/ FROM t:NShell{$$}
    wait >NIL: 1 MIN
    wait 1
    wmn 1
endif
if NOT "$pn{$$}" EQ "$np1{$$}"
    if NOT "$pn{$$}" EQ "$np2{$$}"
        echo >t:rmet{$$} "pa /d: /;sa//;m1;d;w"
        edit >NIL: FROM env:pn{$$} TO env:scrname{$$} WITH t:rmet{$$}
        echo "Script name is : " NOLINE
        getenv scrname{$$}
        echo "*e[1A*e[3m # of call(s) : " NOLINE
        getenv COMPTEUR{$$}
        echo "*e[0m" NOLINE
        run >NIL: delete env:COMPTEUR{$$} env:pn{$$} env:np1{$$} env:np2{$$} t:NShell{$$} t:cpt{$$} t:rmet{$$} QUIET
        quit 0
    endif
endif
wmn 0
As usual, don't forget to set the 's' bit. The result is stored in a variable.
Code:
getenv scrname<shell_number>
Here is how it looks :

Last edited by malko; 02 November 2021 at 00:31. Reason: typo
malko is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
AmigaOS 1.3 ' ls ' command malko Coders. Scripting 10 19 November 2021 21:09
AmigaOS 1.3 ' strlng ' command malko Coders. Scripting 12 08 November 2021 01:25
Is there a WB command at all that can... MethodGit request.Other 43 10 October 2010 09:06
What is the WB command that..... MethodGit request.Other 4 08 October 2010 04:21
final command runamuck request.Old Rare Games 10 23 September 2003 20:55

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 22:38.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.06327 seconds with 15 queries