comp.lang.ada
 help / color / mirror / Atom feed
* GETARG in Ada?
@ 1999-02-27  0:00 Lou Glassy
  1999-02-27  0:00 ` bob
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Lou Glassy @ 1999-02-27  0:00 UTC (permalink / raw)


Question:  Can anyone help me clean up this program?
           No, this is not a homework assignment.
           I'm an old Fortran programmer, learning Ada... 

Here is a little Fortran program (compiles, runs with g77 under Linux)
that prints out the arguments on the Unix command line:

        PROGRAM TEST_GETARG
        IMPLICIT NONE

        INTEGER ARG_COUNT, I
        CHARACTER(LEN=20) CURRENT_ARG

        ARG_COUNT = IARGC()
        PRINT *, 'number of args = ', ARG_COUNT
        DO I = 1, ARG_COUNT
                CALL GETARG(I, CURRENT_ARG)
                PRINT *, 'ARG ', I, '=', CURRENT_ARG
        END DO 

        END

I'd like to do the same thing in Ada-95.  For concreteness, I'm 
using GNAT (3.10p), but I'm guessing any A95 implementation on a 
Unix box would eat something similar to the following:

with TEXT_IO;           use TEXT_IO;
with ADA.COMMAND_LINE;  use ADA.COMMAND_LINE;  
with ADA.STRINGS;       use ADA.STRINGS;
with ADA.STRINGS.FIXED; use ADA.STRINGS.FIXED;

procedure TEST_GETARG is

    package INT_IO is new INTEGER_IO(INTEGER);
    use INT_IO;

    ARG_COUNT: INTEGER;

    MAX_ARG_LENGTH: constant INTEGER := 80;

    ARG: STRING(1..MAX_ARG_LENGTH) := (others => ' ');

begin

    ARG_COUNT := ADA.COMMAND_LINE.ARGUMENT_COUNT;
    PUT("number of command-line args = ");
    PUT(ARG_COUNT);
    NEW_LINE;

    if ARG_COUNT > 0 then 
    
        for CURRENT_ARG in 1..ARG_COUNT loop
            PUT("arg ");
            PUT(CURRENT_ARG);
            PUT("=");
            ARG(1..ADA.COMMAND_lINE.ARGUMENT(CURRENT_ARG)'LENGTH) := 
                ADA.COMMAND_lINE.ARGUMENT(CURRENT_ARG);
            PUT(TRIM(ARG,RIGHT));
            NEW_LINE;
        end loop;
    
    end if;

end TEST_GETARG;

------------------------------------------

My A95 "TEST_GETARG" program works, I'm just trying to figure
out how to write it more cleanly.

I much appreciate Ehud Lamm's "Ada Idiom Page" and other postings 
kind souls have made to comp.lang.ada.  My question is, how would
an experienced Ada programmer write my little TEST_GETARG program 
in Ada-95?  Is there an easier way to handle strings than this?

Thanks in advance...

-lou

Lou Glassy (glassy@cs.montana.edu)




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

end of thread, other threads:[~1999-03-02  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-27  0:00 GETARG in Ada? Lou Glassy
1999-02-27  0:00 ` bob
1999-02-27  0:00 ` David C. Hoos, Sr.
1999-02-27  0:00   ` bill
1999-02-28  0:00     ` James S. Rogers
1999-03-02  0:00     ` Stephen Leake
1999-03-02  0:00       ` nabbasi
1999-02-28  0:00 ` Matthew Heaney

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