comp.lang.ada
 help / color / mirror / Atom feed
* File_Type
@ 2004-04-18 12:17 Jorge Suarez-Solis Rivaya
  2004-04-18 16:30 ` File_Type Martin Krischik
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Jorge Suarez-Solis Rivaya @ 2004-04-18 12:17 UTC (permalink / raw)


Is there anyway to use an Integer Type like a File_Type?, 
Is there anyway to asign a File_Type the value 3?

Thank u



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

* Re: File_Type
  2004-04-18 12:17 File_Type Jorge Suarez-Solis Rivaya
@ 2004-04-18 16:30 ` Martin Krischik
  2004-04-18 20:47 ` File_Type tmoran
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Martin Krischik @ 2004-04-18 16:30 UTC (permalink / raw)


Jorge Suarez-Solis Rivaya wrote:

> Is there anyway to use an Integer Type like a File_Type?,

Spot the word which does not fit in: "in out append integer".

;-) hope you are not upset about my little joke. But I think you have mixed
File_Type and Element_Type. Or if you want to use Streams look for
Integer'Output and Integer'Input.

> Is there anyway to asign a File_Type the value 3?

File_Type'Val (3) - Of course there is little use in that since it is likely
to raise Containt_Error.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




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

* Re: File_Type
  2004-04-18 12:17 File_Type Jorge Suarez-Solis Rivaya
  2004-04-18 16:30 ` File_Type Martin Krischik
@ 2004-04-18 20:47 ` tmoran
  2004-04-18 22:02 ` File_Type sk
  2004-04-18 22:11 ` File_Type Marius Amado Alves
  3 siblings, 0 replies; 11+ messages in thread
From: tmoran @ 2004-04-18 20:47 UTC (permalink / raw)


>Is there anyway to use an Integer Type like a File_Type?,
>Is there anyway to asign a File_Type the value 3?
  Perhaps you want an array
    File_List : array(1 .. 10) of File_Type;
    ...
    Open(File_List(3), ...
Or perhaps you are thinking of some systems' (eg DOS) small integer
file handles - 0=stdin, 1=stdout, 2=stderr, 3=aux, 4=prn?  Ada.Text_IO
has routines to convert the first three to File_Type:
  function Standard_Input return File_Type;
  function Standard_Output return File_Type;
  function Standard_Error return File_Type;



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

* Re: File_Type
  2004-04-18 12:17 File_Type Jorge Suarez-Solis Rivaya
  2004-04-18 16:30 ` File_Type Martin Krischik
  2004-04-18 20:47 ` File_Type tmoran
@ 2004-04-18 22:02 ` sk
  2004-04-20  5:30   ` File_Type Simon Wright
  2004-04-18 22:11 ` File_Type Marius Amado Alves
  3 siblings, 1 reply; 11+ messages in thread
From: sk @ 2004-04-18 22:02 UTC (permalink / raw)
  To: comp.lang.ada

 > Is there anyway to use an Integer Type like a File_Type?,
 > Is there anyway to asign a File_Type the value 3?

1) Are you using GNAT ?
2) Are you trying to associate the standard C/Unix integer
file types to Ada file types ?
3) Are you comfortable with Ada ?

If so, look at Gnat.Os_Lib and how the File_Descriptor
is defined; look at Interfaces.C_Streams. I vaguely
remember, AND I COULD BE WRONG, that there are conversion
functions somewhere in the GNAT supplied libraries.

... if you answered yes to #3, then you should be able
to use UC to get what you need.

... if you answered no to #3, I would search for other
solutions.



-- 
-------------------------------------------------
-- Merge vertically for real address
--
--     s n p @ t . o
--      k i e k c c m
-------------------------------------------------




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

* Re: File_Type
  2004-04-18 12:17 File_Type Jorge Suarez-Solis Rivaya
                   ` (2 preceding siblings ...)
  2004-04-18 22:02 ` File_Type sk
@ 2004-04-18 22:11 ` Marius Amado Alves
  2004-04-18 23:17   ` File_Type Georg Bauhaus
  3 siblings, 1 reply; 11+ messages in thread
From: Marius Amado Alves @ 2004-04-18 22:11 UTC (permalink / raw)
  To: comp.lang.ada

> Is there anyway to use an Integer Type like a File_Type?, 
Of course not.
> Is there anyway to asign a File_Type the value 3?
Of course not.
Maybe you want to write integers to a file?





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

* Re: File_Type
  2004-04-18 22:11 ` File_Type Marius Amado Alves
@ 2004-04-18 23:17   ` Georg Bauhaus
  2004-04-21 17:03     ` File_Type Warren W. Gay VE3WWG
  0 siblings, 1 reply; 11+ messages in thread
From: Georg Bauhaus @ 2004-04-18 23:17 UTC (permalink / raw)


Marius Amado Alves <amado.alves@netcabo.pt> wrote:
:> Is there anyway to asign a File_Type the value 3?
: Of course not.
: Maybe you want to write integers to a file?

Or maybe you (OT) are thinking of UNIX file descriptors?




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

* Re: File_Type
  2004-04-18 22:02 ` File_Type sk
@ 2004-04-20  5:30   ` Simon Wright
  2004-04-20  8:08     ` File_Type Ludovic Brenta
  2004-04-20  8:23     ` File_Type sk
  0 siblings, 2 replies; 11+ messages in thread
From: Simon Wright @ 2004-04-20  5:30 UTC (permalink / raw)


sk <noname@myob.com> writes:

>  > Is there anyway to use an Integer Type like a File_Type?,
>  > Is there anyway to asign a File_Type the value 3?
> 
> 1) Are you using GNAT ?
> 2) Are you trying to associate the standard C/Unix integer
> file types to Ada file types ?
> 3) Are you comfortable with Ada ?
> 
> If so, look at Gnat.Os_Lib and how the File_Descriptor
> is defined; look at Interfaces.C_Streams. I vaguely
> remember, AND I COULD BE WRONG, that there are conversion
> functions somewhere in the GNAT supplied libraries.
> 
> ... if you answered yes to #3, then you should be able
> to use UC to get what you need.

If you are comfortable with Ada then UC is possible for you, but to
use UC one has to look at what is being converted.

GNAT's Ada.Text_IO (a-textio.ads in the library sources) says

   package FCB renames System.File_Control_Block;

   type Text_AFCB;
   type File_Type is access all Text_AFCB;           <<<<<<<<<<<<<<<<<<

   type Text_AFCB is new FCB.AFCB with record
      ...

so there is *no* *way* you can hope to "use an Integer Type like a
File_Type" or "asign a File_Type the value 3".

-- 
Simon Wright                               100% Ada, no bugs.



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

* Re: File_Type
  2004-04-20  5:30   ` File_Type Simon Wright
@ 2004-04-20  8:08     ` Ludovic Brenta
  2004-04-20 19:39       ` File_Type Keith Thompson
  2004-04-20  8:23     ` File_Type sk
  1 sibling, 1 reply; 11+ messages in thread
From: Ludovic Brenta @ 2004-04-20  8:08 UTC (permalink / raw)



Jorge Suarez-Solis Rivaya asked:
> Is there anyway to use an Integer Type like a File_Type?,
> Is there anyway to asign a File_Type the value 3?

Yes, there is, on Unix and Unix-like operating systems; perhaps also
on others as well.  The way to achieve this is to write a thin binding
to the operating system's file management functions, like so:

package Low_Level_IO is
   type File_Type is new Integer;
   File_Error : exception;
   function Open (File_Name : in String) return File_Type;
   procedure Write (Into : in File_Type; What : in String);
end Low_Level_IO;

package body Low_Level_IO is
   function Open (File_Name : in String) return File_Type is
      function Internal (File_Name : in String,
                         Flags : in Integer) return File_Type;
      pragma Import (C, Internal, "open");
      Result : File_Type := Internal (File_Name & ASCII.NUL, 12);
   begin
      if Result = 0 then
         raise File_Error;
      end if;
      return Result;
   end Open;


   procedure Write (Into : in File_Type; What : in String) is
      function Internal (Into : in File_Type; What : in String;
                         Size : in Integer) return Integer;
      pragma Import (C, Internal, "write");
      Result : Integer := Internal (Into, What, What'Length);
   begin
      if Result /= What'Length then
         raise File_Error;
      end if;
   end Write;
end Low_Level_IO;


But, you have to ask yourself exactly why you are trying to use such
low-level code.  This is platform-dependent and error-prone.  I
encourage you to consider using Ada's IO libraries, or GNAT.OS_Lib,
which provide most of what you want in a portable manner.  Indeed, if
you look at the implementation of GNAT.OS_Lib, you will find something
roughly equivalent to what I wrote above.

You should try to avoid messing around with file descriptors if you
can.  It is better to use high-level abstractions; they are much
safer.

-- 
Ludovic Brenta.

-- 
Ce message a ete poste via la plateforme Web club-Internet.fr
This message has been posted by the Web platform club-Internet.fr

http://forums.club-internet.fr/



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

* Re: File_Type
  2004-04-20  5:30   ` File_Type Simon Wright
  2004-04-20  8:08     ` File_Type Ludovic Brenta
@ 2004-04-20  8:23     ` sk
  1 sibling, 0 replies; 11+ messages in thread
From: sk @ 2004-04-20  8:23 UTC (permalink / raw)
  To: comp.lang.ada

 From "System.File_Control_Block" :

    type AFCB is abstract new Ada.Streams.Root_Stream_Type with record

       Stream : Interfaces.C_Streams.FILEs;
       --  The file descriptor

which gets back to my comment on Interfaces.C.Streams :-)

However ...

 > so there is *no* *way* you can hope to "use an Integer Type like a
 > File_Type" or "asign a File_Type the value 3".

... I totally agree. My thoughts were that the OP was trying to
hook into the C integer file type descriptors rather than trying
to create them.

-- 
-------------------------------------------------
-- Merge vertically for real address
--
--     s n p @ t . o
--      k i e k c c m
-------------------------------------------------




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

* Re: File_Type
  2004-04-20  8:08     ` File_Type Ludovic Brenta
@ 2004-04-20 19:39       ` Keith Thompson
  0 siblings, 0 replies; 11+ messages in thread
From: Keith Thompson @ 2004-04-20 19:39 UTC (permalink / raw)


Ludovic Brenta <ludovic.brenta@insalien.org> writes:
> Jorge Suarez-Solis Rivaya asked:
> > Is there anyway to use an Integer Type like a File_Type?,
> > Is there anyway to asign a File_Type the value 3?
> 
> Yes, there is, on Unix and Unix-like operating systems; perhaps also
> on others as well.  The way to achieve this is to write a thin binding
> to the operating system's file management functions, like so:
> 
> package Low_Level_IO is
[...]

You might want to pick a different name.  If I recall correctly,
Low_Level_IO was the name of a predefined package in Ada 83.  It was
optional, and I'm not even sure anybody ever implemented it, but
it's best to avoid name collisions.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"



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

* Re: File_Type
  2004-04-18 23:17   ` File_Type Georg Bauhaus
@ 2004-04-21 17:03     ` Warren W. Gay VE3WWG
  0 siblings, 0 replies; 11+ messages in thread
From: Warren W. Gay VE3WWG @ 2004-04-21 17:03 UTC (permalink / raw)


Georg Bauhaus wrote:

> Marius Amado Alves <amado.alves@netcabo.pt> wrote:
> :> Is there anyway to asign a File_Type the value 3?
> : Of course not.
> : Maybe you want to write integers to a file?
> 
> Or maybe you (OT) are thinking of UNIX file descriptors?

If so, you may want to explore the FLORIST package for Ada
(POSIX binding).
-- 
Warren W. Gay VE3WWG
http://ve3wwg.tk




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

end of thread, other threads:[~2004-04-21 17:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-18 12:17 File_Type Jorge Suarez-Solis Rivaya
2004-04-18 16:30 ` File_Type Martin Krischik
2004-04-18 20:47 ` File_Type tmoran
2004-04-18 22:02 ` File_Type sk
2004-04-20  5:30   ` File_Type Simon Wright
2004-04-20  8:08     ` File_Type Ludovic Brenta
2004-04-20 19:39       ` File_Type Keith Thompson
2004-04-20  8:23     ` File_Type sk
2004-04-18 22:11 ` File_Type Marius Amado Alves
2004-04-18 23:17   ` File_Type Georg Bauhaus
2004-04-21 17:03     ` File_Type Warren W. Gay VE3WWG

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