From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2d8bc00b1190f5f9 X-Google-Attributes: gid103376,public From: "bob" Subject: Re: GETARG in Ada? Date: 1999/02/27 Message-ID: <01be62a4$bb870820$0e2915c0@w95>#1/1 X-Deja-AN: 449421910 References: <7b9r2g$lha$1@netra.msu.montana.edu> Organization: B & D Associates X-NETCOM-Date: Sat Feb 27 4:58:30 PM CST 1999 Newsgroups: comp.lang.ada Date: 1999-02-27T16:58:30-06:00 List-Id: -- -- If I were doing this, I would get rid of ALL "use" clauses except for -- "use type". But this is just my personal preference. Since you knew the -- numerics were integers, you could have used the "'image" clause and not -- had to use "integer_io" at all. -- Here is a quick set of possible mods. -- I suspect you will get many variations on this, one for everyone who -- responds. -- I think the important thing is you are expanding your knowledge. -- -- cheers...bob -- 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_line("number of command-line args =" & integer'image(arg_count)); -- PUT("number of command-line args = "); -- PUT(ARG_COUNT, 0); -- NEW_LINE; -- if ARG_COUNT > 0 then for CURRENT_ARG in 1..ARG_COUNT loop PUT("arg" & integer'image(current_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; -- -- linux:~/atest> ada getarg.adb -- gcc -c -g getarg.adb -- getarg.adb:6:11: warning: file name does not match unit name, should be "test_getarg.adb" -- gnatbind -x getarg.ali -- gnatlink -g getarg.ali -- linux:~/atest> getarg abc def -- number of command-line args = 2 -- arg 1 = abc -- arg 2 = def -- *************************************************************** Lou Glassy wrote in article <7b9r2g$lha$1@netra.msu.montana.edu>... > 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) >