comp.lang.ada
 help / color / mirror / Atom feed
* Command_Line question
@ 2001-12-10 20:29 Peter I. Hansen
  2001-12-10 21:25 ` Tucker Taft
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Peter I. Hansen @ 2001-12-10 20:29 UTC (permalink / raw)


Hello

I'm new to Ada95, and I'm trying to write a program which needs to read 
arguments from the command line. I found out that the Command_Line 
package is the way to go, but something i don't get. for example if I 
have this code :

WITH Ada.Text_IO;
WITH Ada.Command_Line;
WITH Ada.Integer_Text_IO;

PROCEDURE Test IS

Num : Natural ;
NumLength : Natural ;

BEGIN -- Test
   Ada.Integer_text_IO.Get( From => Ada.Command_Line.Argument(Number => 1),
                            Item => Num,
                            Last => NumLenght);
   Ada.Integer_Text_IO.Put(Item => Num);

END Test;

The question is : Is there a way to do this whitout the 'NumLength' 
variable, or is this just the way things work ?

/Peter




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Command_Line question
  2001-12-10 20:29 Command_Line question Peter I. Hansen
@ 2001-12-10 21:25 ` Tucker Taft
  2001-12-11  6:57   ` Anders Wirzenius
  2001-12-11 12:26   ` Peter I. Hansen
  2001-12-10 21:53 ` Mark Lundquist
  2001-12-11 13:03 ` Marc A. Criley
  2 siblings, 2 replies; 6+ messages in thread
From: Tucker Taft @ 2001-12-10 21:25 UTC (permalink / raw)


"Peter I. Hansen" wrote:
> 
> Hello
> 
> I'm new to Ada95, and I'm trying to write a program which needs to read
> arguments from the command line. I found out that the Command_Line
> package is the way to go, but something i don't get. for example if I
> have this code :
> 
> WITH Ada.Text_IO;
> WITH Ada.Command_Line;
> WITH Ada.Integer_Text_IO;
> 
> PROCEDURE Test IS
> 
> Num : Natural ;
> NumLength : Natural ;
> 
> BEGIN -- Test
>    Ada.Integer_text_IO.Get( From => Ada.Command_Line.Argument(Number => 1),
>                             Item => Num,
>                             Last => NumLenght);

Generally, it is easier to use "Integer'Value(blah)" than "Integer_Text_IO.Get(...)".
Integer_Text_IO gives you more control, but Integer'Value is usually adequate.
So you could change this to:

     Num := Integer'Value(Ada.Command_Line.Argument(Number => 1));

>    Ada.Integer_Text_IO.Put(Item => Num);
> 
> END Test;
> 
> The question is : Is there a way to do this whitout the 'NumLength'
> variable, or is this just the way things work ?
> 
> /Peter

-- 
-Tucker Taft   stt@avercom.net   http://www.avercom.net
Chief Technology Officer, AverCom Corporation (A Titan Company) 
Bedford, MA  USA (AverCom was formerly the Commercial Division of AverStar:
http://www.averstar.com/~stt)



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Command_Line question
  2001-12-10 20:29 Command_Line question Peter I. Hansen
  2001-12-10 21:25 ` Tucker Taft
@ 2001-12-10 21:53 ` Mark Lundquist
  2001-12-11 13:03 ` Marc A. Criley
  2 siblings, 0 replies; 6+ messages in thread
From: Mark Lundquist @ 2001-12-10 21:53 UTC (permalink / raw)



"Peter I. Hansen" <pih@oek.dk> wrote in message
news:3C151B2C.4010601@oek.dk...
> Hello
>
> I'm new to Ada95, and I'm trying to write a program which needs to read
> arguments from the command line. I found out that the Command_Line
> package is the way to go, but something i don't get. for example if I
> have this code :
>
> WITH Ada.Text_IO;
> WITH Ada.Command_Line;
> WITH Ada.Integer_Text_IO;
>
> PROCEDURE Test IS
>
> Num : Natural ;
> NumLength : Natural ;
>
> BEGIN -- Test
>    Ada.Integer_text_IO.Get( From => Ada.Command_Line.Argument(Number =>
1),
>                             Item => Num,
>                             Last => NumLenght);
>    Ada.Integer_Text_IO.Put(Item => Num);
>
> END Test;
>
> The question is : Is there a way to do this whitout the 'NumLength'
> variable, or is this just the way things work ?
>
> /Peter
>

Sort of...

You have to give an actual for any parameter that does not have a default,
and that includes all 'out' mode parameters.

And for the purpose for which this overloading of Get is intended, the Last
parameter is necessary -- that is, so that you know where to 'pick up where
you left off' if you're going to continue parsing the string.  That's why
there isn't an overloading of Get that is like this but without the Last
parameter.

That said... for what you're doing, Integer_Text_IO is probably not the best
way anyway.  You'd probably find that using an integer type 'Value attribute
convenient, e.g.:

    Num := Natural'Value (Ada.Command_Line.Argument (1));

-- mark






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Command_Line question
  2001-12-10 21:25 ` Tucker Taft
@ 2001-12-11  6:57   ` Anders Wirzenius
  2001-12-11 12:26   ` Peter I. Hansen
  1 sibling, 0 replies; 6+ messages in thread
From: Anders Wirzenius @ 2001-12-11  6:57 UTC (permalink / raw)



Tucker Taft wrote in message <3C152834.F1B1850F@avercom.net>...
>"Peter I. Hansen" wrote:
>>
>> Hello
>>
>> I'm new to Ada95, and I'm trying to write a program which needs to read
>> arguments from the command line. I found out that the Command_Line
>> package is the way to go, but something i don't get. for example if I
>> have this code :
>>
>> WITH Ada.Text_IO;
>> WITH Ada.Command_Line;
>> WITH Ada.Integer_Text_IO;
>>
>> PROCEDURE Test IS
>>
>> Num : Natural ;
>> NumLength : Natural ;
>>
>> BEGIN -- Test
>>    Ada.Integer_text_IO.Get( From => Ada.Command_Line.Argument(Number =>
1),
>>                             Item => Num,
>>                             Last => NumLenght);
>
>Generally, it is easier to use "Integer'Value(blah)" than
"Integer_Text_IO.Get(...)".
>Integer_Text_IO gives you more control, but Integer'Value is usually
adequate.

FWIW
One of the "more control" things is that Integer_Text_IO.Get(..) will
swallow a command line like "Test 3a" or "Test 3." where the Get stops
reading at the character "a" or "."
The Integer'Value(..) will raise an exception.

Neither of them accepts "Test a3".

As a newbe to Ada95 myself I have been through the same process as Peter. I
want to recommend (as has been done by several persons on cla earlier)
studying the generous possibilities that the attributes offer, see
http://www.quickreferences.yucom.be/QRC/Ada%20Reference%20Card.pdf

Anders Wirzenius







^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Command_Line question
  2001-12-10 21:25 ` Tucker Taft
  2001-12-11  6:57   ` Anders Wirzenius
@ 2001-12-11 12:26   ` Peter I. Hansen
  1 sibling, 0 replies; 6+ messages in thread
From: Peter I. Hansen @ 2001-12-11 12:26 UTC (permalink / raw)


Tucker Taft wrote:

>"Peter I. Hansen" wrote:
>
>>Hello
>>
>>I'm new to Ada95, and I'm trying to write a program which needs to read
>>arguments from the command line. I found out that the Command_Line
>>package is the way to go, but something i don't get. for example if I
>>have this code :
>>
>>WITH Ada.Text_IO;
>>WITH Ada.Command_Line;
>>WITH Ada.Integer_Text_IO;
>>
>>PROCEDURE Test IS
>>
>>Num : Natural ;
>>NumLength : Natural ;
>>
>>BEGIN -- Test
>>   Ada.Integer_text_IO.Get( From => Ada.Command_Line.Argument(Number => 1),
>>                            Item => Num,
>>                            Last => NumLenght);
>>
>
>Generally, it is easier to use "Integer'Value(blah)" than "Integer_Text_IO.Get(...)".
>Integer_Text_IO gives you more control, but Integer'Value is usually adequate.
>So you could change this to:
>
>     Num := Integer'Value(Ada.Command_Line.Argument(Number => 1));
>
This is just what I'm looking for. This notation is not in my Ada95 book.

>>   Ada.Integer_Text_IO.Put(Item => Num);
>>
>>END Test;
>>
>>The question is : Is there a way to do this whitout the 'NumLength'
>>variable, or is this just the way things work ?
>>
>>/Peter
>>
>
Thanks

/Peter




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Command_Line question
  2001-12-10 20:29 Command_Line question Peter I. Hansen
  2001-12-10 21:25 ` Tucker Taft
  2001-12-10 21:53 ` Mark Lundquist
@ 2001-12-11 13:03 ` Marc A. Criley
  2 siblings, 0 replies; 6+ messages in thread
From: Marc A. Criley @ 2001-12-11 13:03 UTC (permalink / raw)


"Peter I. Hansen" wrote:
> 
> Hello
> 
> I'm new to Ada95, and I'm trying to write a program which needs to read
> arguments from the command line. I found out that the Command_Line
> package is the way to go, but something i don't get. 

<PLUG>
Another way to go is to use my command line utility for extracting and
identifying options and arguments.  It's available at
http://www.adapower.com/reuse/cmd_line.html.  It's basically a generic
that is instantiated with a type corresponding to the options you
define, and the characters or strings that that represent them.  It also
handles just plain arguments, and allow "help" to be provided as well.
</PLUG>

Marc A. Criley
Senior Staff Engineer
Quadrus Corporation
www.quadruscorp.com



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-12-11 13:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-10 20:29 Command_Line question Peter I. Hansen
2001-12-10 21:25 ` Tucker Taft
2001-12-11  6:57   ` Anders Wirzenius
2001-12-11 12:26   ` Peter I. Hansen
2001-12-10 21:53 ` Mark Lundquist
2001-12-11 13:03 ` Marc A. Criley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox