Login
Username:

Password:

Remember me



Lost Password?

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

Members: 1
Guests: 1

Yanosh, more...

Browsing this Thread:   1 Anonymous Users





use of .KEY and space in arguments

Joined:
2004/4/7 4:26
Group:
Member
Posts: 4245
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: 1991
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: 646
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: 4245
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: 646
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: 4245
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






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
4245
2 magorium
magorium
4095
3 phoenixkonsole
phoenixkonsole
3886
4 nikolaos
nikolaos
3657
5 deadwood
deadwood
2923
6 ncafferkey
ncafferkey
2540
7 mazze
mazze
2200
8 clusteruk
clusteruk
2055
9 Kalamatee
Kalamatee
1991
10 damocles
damocles
1789
© 2004-2014 AROS Exec