comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin David Condic, 561.796.8997, M/S 731-96" <condicma@PWFL.COM>
Subject: Re: comand line arguments
Date: 1997/10/13
Date: 1997-10-13T00:00:00+00:00	[thread overview]
Message-ID: <97101310345365@psavax.pwfl.com> (raw)


    Here's some code that should at least get you started developing
    whatever you need for processing a command line.

    MDC

Marin David Condic, Senior Computer Engineer     Voice:     561.796.8997
Pratt & Whitney GESP, M/S 731-96, P.O.B. 109600  Fax:       561.796.4669
West Palm Beach, FL, 33410-9600                  Internet:  CONDICMA@PWFL.COM
===============================================================================
    "Eagles may soar, but a weasle never gets sucked up into a jet engine."
===============================================================================

--
--  This function will return a string containing everything that
--  was on the command line. Due to OS pecularities, you may not
--  get it back exactly as typed. You may not get everything you
--  want, either. Ada can't fix that because it's going to depend on
--  what the OS decides to give you. From experience, Unix and WinNT
--  will produce different effects from the same code.
--
--  A lot of this implementation depends on what sort of command line
--  "language" you intend to be parsing out of the string. You'll
--  have to tailor the function as needed, but it at least
--  illustrates the proper calls to Ada.Command_Line.
--
--  The function presumes that you don't care about spaces between
--  parameters. You could modify it to put spaces between the
--  parameters, etc.
--

with Ada.Command_Line ;
with Ada.Strings ;
with Ada.Strings.Maps ;
with Ada.Strings.Fixed ;
with Ada.Characters.Handling ;
with Ada.Text_IO ;

function Get_Command_Line return String is
    --
    Temp            : String (1..256)   := (others => ' ') ;
    I               : Natural           := 0 ;
    --
    use Ada.Command_Line ;
    use Ada.Strings.Fixed ;
begin
    --
    --  Get the "command" or program name from the system if available.
    --
    Ada.Strings.Fixed.Move (
        Source  => Ada.Command_Line.Command_Name,
        Target  => Temp,
        Drop    => Ada.Strings.Right) ;
    --
    --  Get each of the args into the string - spaces don't matter.
    --
    I := Ada.Strings.Fixed.Index (
        Source  => Temp,
        Pattern => " ") ;
    for X in 1..Ada.Command_Line.Argument_Count loop
        Ada.Strings.Fixed.Move (
            Source  => Ada.Command_Line.Argument (X),
            Target  => Temp (I..Temp'Last),
            Drop    => Ada.Strings.Right) ;
        I := Index_Non_Blank (
            Source  => Temp,
            Going   => Ada.Strings.Backward) + 1 ;
    end loop ;
    --
    return Ada.Strings.Fixed.Trim (
        Source  => Temp,
        Side    => Ada.Strings.Both) ;
exception
    when Constraint_Error =>
        Ada.Text_IO.Put_Line ("Your command line is probably too long.") ;
        return "" ;
end Get_Command_Line ;




             reply	other threads:[~1997-10-13  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-10-13  0:00 Marin David Condic, 561.796.8997, M/S 731-96 [this message]
  -- strict thread matches above, loose matches on Subject: below --
1997-10-09  0:00 comand line arguments ucs_rat
1997-10-10  0:00 ` Pascal Obry
1997-10-10  0:00 ` bklungle
replies disabled

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