Login
Username:

Password:

Remember me



Lost Password?

Register now!
Main Menu
Who's Online
1 user(s) are online (1 user(s) are browsing Forum)

Members: 0
Guests: 1

more...

Browsing this Thread:   1 Anonymous Users





use of .KEY and space in arguments

Joined:
2004/4/7 4:26
Group:
Member
Posts: 4346
Offline
Hello

i am writing a little script to convert paths from AROS hosted to system host native format. For instance, assuming that Windows hosted AROS is installed into D:\stuff\Icaros and I must target a file which is in SYS:MyWorkspace/documents/paolo/mydoc.txt, the final output would be

D:\stuff\Icaros\MyWorkspace\documents\paolo\mydoc.txt

All the conversion stuff is ready and works, no problem about it. My issues start when there are spaces in paths. Every time the .KEY command encounters a space, it assumes it as a separator for arguments. So I have temporarily resolved the issue accepting 15 arguments

.KEY w01,w02,w03,w04,...,w15

and then "rebuilding" the path with a echo command

echo {w01} {w02} {w03} {w04} ... {w15} >t:tempfile

this way I can handle paths with a maximum of 14 spaces. Problem is: isn't there a way to tell .KEY command to ignore spaces, and to treat them as normal characters? I have tried using " but they don't work. They just disappear when I'd need them to stay where they are.

The other option would be to create a different script which operates on a temporary file, but I prefered the "command style" interfact that accepts parameters.

Other question. At the end of the script, i cast a

echo ${t:tempfile}

to return the output (the transformed path). Assuming that my script is called winconv, I'd expect that a command like

execute winconv sys:pippo/pluto >t:otherfile

would forward the output from the shell to t:otherfile. This does not happen. I can always see the output on the screen, and a empty t:otherfile is created instead. Is this a bug or a feature? Thank you so much

(so, to recap:

1. is there a way to let .KEY ignore spaces?
2. is there a way to keep " when included into parameters?
3. is there a way to redirect output from a echo command in a script to another file?

thank you in advance)

Posted on: 3/29 8:45
_________________
p.bes
Icaros Desktop AROS distribution mantainer
Transfer the post to other applications Transfer


Re: use of .KEY and space in arguments

Joined:
2004/3/29 9:54
From Scotland "The Cold"
Group:
Member
Posts: 2024
Offline
Then you should be enclosing your parameters in quotation marks?

Execute myscript "first param" "second param"

Posted on: 3/29 13:14
_________________
Click to see original Image in a new window
Transfer the post to other applications Transfer


Re: use of .KEY and space in arguments

Joined:
2004/5/7 2:45
From Daoulas (Finistère, France)
Group:
Member
Posts: 648
Offline
Interesting as always, thank you!

1. According to the dos.library ReadArgs() function autodocs, the /M modifier "eats all strings that don't fit into any other option", and the /F modifier "eats the rest of the line even if there are option keywords in it". That means that you can use one of them to be sure that a .KEY argument "eats" all what you give in input.

2. Not sure how to answer this, there are many things to think about. You should find answers in the following script.

3. That's indeed a limitation in the use of scripts, you can't redirect their output as if it were a real command. If I remember correctly this was also the case on Amiga OS 3.1, so I wouldn't say it's a bug in AROS, but it's definitely not a feature.

.KEY AROSPATH/A/F
.BRA {
.
KET }

We get rid of the device name part, if any
Cut 
"{AROSPATH}" WORD 2 SEPARATOR ":" >ENV:path
If "${path}test" EQ "test"
  
SetEnv path "{AROSPATH}"
EndIf

We loop as long as there are "/" to convert to "\" in $path
Lab start
Cut 
"$pathWORD 1 SEPARATOR "/" >ENV:path2
Cut 
"$pathWORD 2SEPARATOR "/" >ENV:path3

If "${path3}test" NOT EQ "test"
  
SetEnv path "${path2}\${path3}"
  
Skip start BACK
endif

echo 
"*"${path}*""

Posted on: 3/29 13:24
_________________
Everyone knew it was impossible. Along came a fool who did not know and he did it.
Transfer the post to other applications Transfer


Re: use of .KEY and space in arguments

Joined:
2004/4/7 4:26
Group:
Member
Posts: 4346
Offline
@Ball000: thanks for explanation and suggestions

@Kalamatee:
Quote:

Then you should be enclosing your parameters in quotation marks?

Execute myscript "first param" "second param"


Hi, have a look at the following screenshot.

On the left: some tests, on the right, the test script.

Attach file:



jpg  220-keybraket1.jpg (53.62 KB)
106_58dcb3527d64d.jpg 818X234 px

Posted on: 3/30 0:27

Edited by paolone on 2017/3/30 1:23:08
_________________
p.bes
Icaros Desktop AROS distribution mantainer
Transfer the post to other applications Transfer


Re: use of .KEY and space in arguments

Joined:
2004/5/7 2:45
From Daoulas (Finistère, France)
Group:
Member
Posts: 648
Offline
Now try:
execute prova "*"palla matta*"" "hello kitty"

Keep in mind that the ReadArgs() function uses the quotes to distinguish arguments at its own level (so the separator keeps being the blanc space), but that it does remove those quotes when sending the arguments to the calling function. In your example you want some quotes anyway, so you have to add another level inside the first argument(s) (by escaping the second level of quotes). The lastest argument doesn't need that as ReadArgs() seems to use an implicit /M modifier for it.

Posted on: 3/30 1:26
_________________
Everyone knew it was impossible. Along came a fool who did not know and he did it.
Transfer the post to other applications Transfer


Re: use of .KEY and space in arguments

Joined:
2004/4/7 4:26
Group:
Member
Posts: 4346
Offline
Quote:

Ball000 wrote:
Now try:
execute prova "*"palla matta*"" "hello kitty"


oooooooooooh.

Quote:
Keep in mind that the ReadArgs() function uses the quotes to distinguish arguments at its own level (so the separator keeps being the blanc space), but that it does remove those quotes when sending the arguments to the calling function. In your example you want some quotes anyway, so you have to add another level inside the first argument(s) (by escaping the second level of quotes). The lastest argument doesn't need that as ReadArgs() seems to use an implicit /M modifier for it.


Ok, I guess I lost myself at some level, but I understood... Thank you!!

Posted on: 3/31 12:16
_________________
p.bes
Icaros Desktop AROS distribution mantainer
Transfer the post to other applications Transfer


Re: use of .KEY and space in arguments

Joined:
2004/4/7 4:26
Group:
Member
Posts: 4346
Offline
Ok, I've almost finished with my path conversion script, however I now found another 'oddity' I can't explain to myself. So here I am again to ask you all.

Try yourself. Edit this little script and call it 'test' if you like, then make it executable with a
protect test s add

.KEY w01/F
.BRA {
.
KET }

DEBUG
echo entered program##{w01}##


now these lines are *exactly* the first ones of my script. Now create these dummy files

echo "test1" >"sys:prova1.txt"
echo "test2" >"sys:prova2 with spaces.txt"

and test with

test sys:prova1.txt
test "sys:prova2 with spaces.txt"

expected results would be
entered program ##sys:prova1.txt##
entered program ##sys:prova2 with spaces.txt##

HOWEVER, the second line is producing this:

entered program ##sys:prova2 with spaces.txt ##

it seems quite he same, but please notice that added space between .txt and ##: it is causing a lot of headaches to me, since every time I try to convert a path with a space (it does not matter if it is inside a file or directory name), that damn unwanted space AFTER the result alters my script behavior, so Linux host is unable to find the file I specified. I have looked so many times to my script to understand why a space would led to this behavior, but after many checks and retries I found that the problem was not in my script, but in the way my input parameter is passed by AROS.

Is this normal, or a bug?


(EDIT: in the meanwhile I managed to work around this, but curiosity for my question persists...)

Posted on: 5/2 3:28

Edited by paolone on 2017/5/2 7:14:52
_________________
p.bes
Icaros Desktop AROS distribution mantainer
Transfer the post to other applications Transfer


Re: use of .KEY and space in arguments

Joined:
2004/5/7 2:45
From Daoulas (Finistère, France)
Group:
Member
Posts: 648
Offline
You're right, I too think it's a bug: it was also apparent with the last line of my proposed script of the 29th March.

Posted on: 5/2 11:42
_________________
Everyone knew it was impossible. Along came a fool who did not know and he did it.
Transfer the post to other applications Transfer


Re: use of .KEY and space in arguments

Joined:
2016/8/16 0:09
Group:
Member
Posts: 294
Offline
Since i am unable to reproduce the shown behavior on classic, i also think it is a bug.

Posted on: 5/2 12:00
Transfer the post to other applications Transfer


Re: use of .KEY and space in arguments

Joined:
2004/4/7 4:26
Group:
Member
Posts: 4346
Offline
Ok, I created a new ticket in the bugtracker
https://sourceforge.net/p/aros/bugs/543/

kind regards

Posted on: 5/2 12:40
_________________
p.bes
Icaros Desktop AROS distribution mantainer
Transfer the post to other applications Transfer






You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.

[Advanced Search]


Search
Top Posters
1 paolone
paolone
4346
2 magorium
magorium
4095
3 phoenixkonsole
phoenixkonsole
3891
4 nikolaos
nikolaos
3677
5 deadwood
deadwood
2923
6 ncafferkey
ncafferkey
2633
7 mazze
mazze
2214
8 clusteruk
clusteruk
2103
9 Kalamatee
Kalamatee
2024
10 damocles
damocles
1789
© 2004-2017 AROS Exec