Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Parsing command-line arguments for module commands

6 views
Skip to first unread message

Terje Slettebø

unread,
Sep 10, 2011, 6:11:37 PM9/10/11
to
I may be overlooking something obvious, but when implementing a
module, the command entry point receives the command tail, and the
number of arguments there is, but the arguments are not separated in
any way.

Is there a way using RISC OS to split the tail up, to get e.g. an
array of arguments, in a way that takes into account quoted strings
(like RISC OS apparently does when it counts the arguments)?

Regards,

Terje

Martin Bazley

unread,
Sep 10, 2011, 7:13:43 PM9/10/11
to
The following bytes were arranged on 10 Sep 2011 by Terje Sletteb� :

SWI "OS_ReadArgs".

Good luck wrangling with the explanation of the syntax string format,
though; it took me hours of experimentation to determine exactly what
each letter code did, and what they did when combined. Let me know if
you need help and I'll see if I can dig out my old notes.

--
__<^>__ "Your pet, our passion." - Purina
/ _ _ \ "Your potential, our passion." - Microsoft, a few months later
( ( |_| ) )
\_> <_/ ======================= Martin Bazley ==========================

Terje Slettebø

unread,
Sep 11, 2011, 4:31:47 AM9/11/11
to
On Sep 11, 1:13 am, Martin Bazley <martin.baz...@blueyonder.co.uk>
wrote:

> SWI "OS_ReadArgs".
>
> Good luck wrangling with the explanation of the syntax string format,
> though; it took me hours of experimentation to determine exactly what
> each letter code did, and what they did when combined. Let me know if
> you need help and I'll see if I can dig out my old notes.

Hi Martin.

Thanks. I did look at OS_ReadArgs, but it seemed to only support
parameters of the type "-<name>[ <value>]", so you couldn't use it
e.g. to parse the parameters of a command like "*copy <from> <to>".

In any case, I found that in my case, I'll manage with a simple way of
doing this, since it doesn't need to handle quoted strings.

Regards,

Terje

Martin Bazley

unread,
Sep 11, 2011, 9:32:16 AM9/11/11
to
The following bytes were arranged on 11 Sep 2011 by Terje Slettebø :

> On Sep 11, 1:13 am, Martin Bazley <martin.baz...@blueyonder.co.uk>
> wrote:
>
> > SWI "OS_ReadArgs".
> >
> Thanks. I did look at OS_ReadArgs, but it seemed to only support
> parameters of the type "-<name>[ <value>]", so you couldn't use it
> e.g. to parse the parameters of a command like "*copy <from> <to>".

Yes, you can. I do it all the time. The <name> part in the syntax
string is entirely optional - all you need are the commas separating
each argument, and /A inserted between them if a parameter is
compulsory.

As the StrongHelp manual puts it, "," is a perfectly valid syntax
string. Presumably the null string is also. The last time I used this,
I was writing a utility to save memory starting from a certain address
to a file (determining the length of memory to save from the contents of
the address given being the purpose of the utility). I used the string
"/A,/A/E".

One thing you do have to watch out for is that OS_ReadArgs generates a
rather unhelpful error if the parameters are junk, so standard practice
is to call it with the X flag set and, if V set, print a message of your
own along the lines of, "Syntax: <program> [-<arg1>] -<arg2>".

Terje Slettebø

unread,
Sep 12, 2011, 6:17:59 AM9/12/11
to
On Sep 11, 3:32 pm, Martin Bazley <martin.baz...@blueyonder.co.uk>
wrote:
> The following bytes were arranged on 11 Sep 2011 by Terje Slettebø :
>
> > On Sep 11, 1:13 am, Martin Bazley <martin.baz...@blueyonder.co.uk>
> > wrote:
>
> > > SWI "OS_ReadArgs".
>
> > Thanks. I did look at OS_ReadArgs, but it seemed to only support
> > parameters of the type "-<name>[ <value>]", so you couldn't use it
> > e.g. to parse the parameters of a command like "*copy <from> <to>".
>
> Yes, you can.  I do it all the time.  The <name> part in the syntax
> string is entirely optional - all you need are the commas separating
> each argument, and /A inserted between them if a parameter is
> compulsory.
>
> As the StrongHelp manual puts it, "," is a perfectly valid syntax
> string.  Presumably the null string is also.  The last time I used this,
> I was writing a utility to save memory starting from a certain address
> to a file (determining the length of memory to save from the contents of
> the address given being the purpose of the utility).  I used the string
> "/A,/A/E".
>
> One thing you do have to watch out for is that OS_ReadArgs generates a
> rather unhelpful error if the parameters are junk, so standard practice
> is to call it with the X flag set and, if V set, print a message of your
> own along the lines of, "Syntax: <program> [-<arg1>] -<arg2>".

Ah, great, thanks for the info. I'll try it out.

Regards,

Terje
0 new messages