TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender:
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
X-To:
"Robert C. Leif, Ph.D." <[log in to unmask]>
Date:
Sun, 12 Dec 1999 06:21:09 -0600
Reply-To:
"David C. Hoos, Sr." <[log in to unmask]>
Subject:
MIME-Version:
1.0
Content-Transfer-Encoding:
7bit
Content-Type:
text/plain; charset="iso-8859-1"
From:
"David C. Hoos, Sr." <[log in to unmask]>
Parts/Attachments:
text/plain (164 lines)
----- Original Message -----
From: Robert C. Leif, Ph.D. <[log in to unmask]>
To: <[log in to unmask]>
Sent: December 11, 1999 3:45 PM
Subject: Re: Accessing "CGI data" (Was: Rational A.5 Command Line and HTML)


> From: Bob Leif
> To: Doug Smith et al.
> Your CGI.Environment.Adb contains the reference to the same getenv C
> function as does David Wheeler's CGI.Adb. Therefore my comments concerning
> his program apply to yours. I would like the luxury of using one or the
> other or combining parts of them. However, their use still requires a C
> compiler.
I was puzzled by this statement, so I whipped up this little example and
built it with Object Ada, no problem.  You need to include Libc.lib from the
apilib directory in your project.


The two nested functions and the import they require could be put in a
package.  You will note that the interface is "pure Ada" -- i.e, there are
no types from Interfaces.C, in the interface.

with Ada.Command_Line;
with Ada.Text_Io;
with Interfaces.C.Strings;
procedure Env
is
   function Getenv(Name : Interfaces.C.Strings.Chars_Ptr)
     return Interfaces.C.Strings.Chars_Ptr;
   pragma Import(C, Getenv, "getenv");
   -- getenv is a standard C library function; see K&R 2, 1988, pagr 253
   -- it returns a pointer to the first character; do NOT free its
   --results.
   function Environment_Value_Of
     (Name : String;
      Result_If_Undefined : String := "") return String
   is
      Name_In_C_Format : Interfaces.C.Strings.Chars_Ptr  :=
        Interfaces.C.Strings.New_String (Name);
      Result_Ptr : Interfaces.C.Strings.Chars_Ptr;
      use type Interfaces.C.Strings.Chars_Ptr;
   begin
      Result_Ptr := Getenv (Name_In_C_Format);
      Interfaces.C.Strings.Free (Name_In_C_Format);
      if Result_Ptr = Interfaces.C.Strings.Null_Ptr then
         return Result_If_Undefined;
      else
         return Interfaces.C.Strings.Value (Result_Ptr);
      end if;
   end Environment_Value_Of;

   function Is_Environment_Variable
     (Name : String) return Boolean
   is
      Name_In_C_Format : Interfaces.C.Strings.Chars_Ptr  :=
        Interfaces.C.Strings.New_String (Name);
      Result_Ptr : Interfaces.C.Strings.Chars_Ptr;
      use type Interfaces.C.Strings.Chars_Ptr;
   begin
      Result_Ptr := Getenv (Name_In_C_Format);
      Interfaces.C.Strings.Free (Name_In_C_Format);
      return Result_Ptr /= Interfaces.C.Strings.Null_Ptr;
   end Is_Environment_Variable;

begin
   if Is_Environment_Variable (Ada.Command_Line.Argument (1)) then
      Ada.Text_Io.Put_Line
        (Environment_Value_Of (Ada.Command_Line.Argument (1)));
   else
      Ada.Text_Io.Put_Line
        ("""" & Ada.Command_Line.Argument (1) &
         """ is not an envronment variable.");
   end if;
end Env;




> Thus, your example again proves my point. The standard libraries
> supplied by an Ada compiler vendor should include the equivalent of
> function getenv(Name : chars_ptr) return chars_ptr;
> ------------------------------------------------------------------
> function getenv(Name : chars_ptr) return chars_ptr;
>     pragma Import(C, getenv);
>     Result_Ptr : chars_ptr := getenv(Name_In_C_Format);
>       -- getenv is a standard C library function; see K&R 2, 1988, page 253.
>       -- it returns a pointer to the first character; do NOT free its
>       --results.
> --------------------------------------------------------------
> -----Original Message-----
> From: Team Ada: Ada Advocacy Issues (83 & 95)
> [mailto:[log in to unmask]]On Behalf Of Doug Smith
> Sent: Saturday, December 11, 1999 9:13 AM
> To: [log in to unmask]
> Subject: Re: Accessing "CGI data" (Was: Rational A.5 Command Line and
> HTML)
>
>
> Maybe you would prefer this style of binding (which is not currently being
> maintained, although no defects have been reported to me for over 4 years):
>
>   <http://www.adasmith.com/webada/source/cgi/>
>
> Doug
> [log in to unmask]
>
> At 11:31 AM -0500 12/11/99, Robert C. Leif, Ph.D. wrote:
> >From: Bob Leif
> >To: Geoff Bull et al.
> >
> >Please see David A. Wheeler's CGI.Adb. It contains the following:
> >------------------------------------------------------------------
> >function getenv(Variable : chars_ptr) return chars_ptr;
> >  pragma Import(C, getenv);
> >  -- getenv is a standard C library function; see K&R 2, 1988, page 253.
> >  -- it returns a pointer to the first character; do NOT free its results.
> >----------------------------------------------------------------------
> >I hope that the Ada compiler vendors will permit the use of Wheeler's CGI
> >library by including this function in their standard libraries. I have not
> >been able to find it in the ObjectAda libraries.
> >
> >I should note that the user of an Ada compiler should not be required to
> use
> >subprograms which include C data types. It should be possible to function
> in
> >Ada without any knowledge of C or its relatives. Since most of us believe
> >that Ada is an excellent choice for the first course in software
> >engineering, a knowledge of C should and can not be a prerequisite for the
> >learning of Ada. I might note that for the students that I have taught in
> >chemistry,  biology, and even biomedical engineering; two semesters of Ada
> >combined with software engineering would be a great improvement over their
> >present curriculum and sufficient for their future work.
> >
> >Ultimately, a standard library to interface with HTML-XML (Ada.XML_IO)
> >should be designed and implemented.
> >
> >It should include something like
> >function getenv(Variable_Name : String) return String;
> >
> >
> >-----Original Message-----
> >From: Team Ada: Ada Advocacy Issues (83 & 95)
> >[mailto:[log in to unmask]]On Behalf Of Geoff Bull
> >Sent: Saturday, December 11, 1999 6:24 AM
> >To: [log in to unmask]
> >Subject: Re: Accessing "CGI data" (Was: Rational A.5 Command Line and
> >HTML)
> >
> >
> >Jacob Sparre Andersen wrote:
> >>
> >> It seems that nobody are aware of to excellent (imo) Ada CGI
> >> library by David A. Wheeler that has been around for a while
> >> by now:
> >>
> >> http://wuarchive.wustl.edu/languages/ada/swcomps/cgi/cgi.html
> >>
> >> There is no need to play around with C code, if you use the
> >> routines in this library.
> >
> >Yeah, but unfortunately it is LGPL.
>

ATOM RSS1 RSS2