comp.lang.ada
 help / color / mirror / Atom feed
* Ada-kernel calls / IF & ELSE...
@ 2002-03-11 19:42 Karl Ran
  2002-03-11 20:41 ` Bj�rn Lundin
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Karl Ran @ 2002-03-11 19:42 UTC (permalink / raw)


Hi,
I'm just starting to understand how to make Ada-kernel calls...

Has anyone compiled the Kernel Calls demo on
http://www.vaxxine.com/pegasoft/homes/13.html#13.5.4 
?

Here is a much simpler version:

-----------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;

procedure audiocd is 

  DevCDROM : constant string := "/dev/cdrom";

  type aFileID is new integer;

  procedure open( id : out aFileID;
                  path : string;
                  flags : integer );

  pragma import( C, open, "open");
  pragma import_valued_procedure( open );

  procedure perror( prefixstr : string );
  pragma import( C, perror, "perror");

  cd : aFileID;

begin

  Put_Line( "Openning " & DevCDROM & "..." );
  Open( cd, DevCDROM, 0 );

  if cd < 0 then
     perror( "IF: Error openning CDROM drive " );
  else
     Put_Line( "ELSE: opened CDROM drive successfully " );
  end if;

end audiocd; 
-----------------------------------------------------

>gnatmake -gnatwa audiocd.adb
gcc -c -gnatwa audiocd.adb
gnatbind -x audiocd.ali
gnatlink audiocd.ali

>./audiocd
Openning /dev/cdrom...
IF: Error openning CDROM drive ELSE: opened CDROM drive successfully :
No such file or directory


Would someone please explain whats going on here?

Is this just because of my bleeding-edge-suse71-gnat3.14p-unsupported
system or is normal?


Karl



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

* Re: Ada-kernel calls / IF & ELSE...
  2002-03-11 19:42 Ada-kernel calls / IF & ELSE Karl Ran
@ 2002-03-11 20:41 ` Bj�rn Lundin
  2002-03-12 15:09   ` Karl Ran
  2002-03-11 21:06 ` Vadim Godunko
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Bj�rn Lundin @ 2002-03-11 20:41 UTC (permalink / raw)


> >./audiocd
> Openning /dev/cdrom...
> IF: Error openning CDROM drive ELSE: opened CDROM drive successfully :
> No such file or directory
>
> Would someone please explain whats going on here?
> 
> Is this just because of my bleeding-edge-suse71-gnat3.14p-unsupported
> system or is normal?
> 
> 
> Karl

No I get the same output on mandrake 8.1 with 3.13p, but if you replace perror with 
another  put_line, it behaves ok.

/Bj�rn



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

* Re: Ada-kernel calls / IF & ELSE...
  2002-03-11 19:42 Ada-kernel calls / IF & ELSE Karl Ran
  2002-03-11 20:41 ` Bj�rn Lundin
@ 2002-03-11 21:06 ` Vadim Godunko
  2002-03-11 21:06 ` Vadim Godunko
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Vadim Godunko @ 2002-03-11 21:06 UTC (permalink / raw)


You MUST append ASCII.Nul if you pass any string parameters direct to
imported C routines.
For passing strings to C routines better use Interfaces.C.char_array type.
In package Interfaces.C you may found needed String<=>char_array conversion
routines, that automaticaly append/remove ASCII.Nul at the end of strings.
And, in you case, may be used standard Ada-POSIX bindings, that have open,
close, read, write,... functions.
This bindings for GNAT called Florist.

Regards,
Vadim

----- Original Message -----
From: "Karl Ran" <karlran1234@yahoo.com>
Newsgroups: comp.lang.ada
Sent: Monday, March 11, 2002 10:42 PM
Subject: Ada-kernel calls / IF & ELSE...


> Hi,
> I'm just starting to understand how to make Ada-kernel calls...
>
> Has anyone compiled the Kernel Calls demo on
> http://www.vaxxine.com/pegasoft/homes/13.html#13.5.4
> ?
>
> Here is a much simpler version:
>
> -----------------------------------------------------
> with Ada.Text_IO; use Ada.Text_IO;
>
> procedure audiocd is
>
>   DevCDROM : constant string := "/dev/cdrom";
>
>   type aFileID is new integer;
>
>   procedure open( id : out aFileID;
>                   path : string;
>                   flags : integer );
>
>   pragma import( C, open, "open");
>   pragma import_valued_procedure( open );
>
>   procedure perror( prefixstr : string );
>   pragma import( C, perror, "perror");
>
>   cd : aFileID;
>
> begin
>
>   Put_Line( "Openning " & DevCDROM & "..." );
>   Open( cd, DevCDROM, 0 );
>
>   if cd < 0 then
>      perror( "IF: Error openning CDROM drive " );
>   else
>      Put_Line( "ELSE: opened CDROM drive successfully " );
>   end if;
>
> end audiocd;
> -----------------------------------------------------
>
> >gnatmake -gnatwa audiocd.adb
> gcc -c -gnatwa audiocd.adb
> gnatbind -x audiocd.ali
> gnatlink audiocd.ali
>
> >./audiocd
> Openning /dev/cdrom...
> IF: Error openning CDROM drive ELSE: opened CDROM drive successfully :
> No such file or directory
>
>
> Would someone please explain whats going on here?
>
> Is this just because of my bleeding-edge-suse71-gnat3.14p-unsupported
> system or is normal?
>
>
> Karl





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

* Re: Ada-kernel calls / IF & ELSE...
  2002-03-11 19:42 Ada-kernel calls / IF & ELSE Karl Ran
  2002-03-11 20:41 ` Bj�rn Lundin
  2002-03-11 21:06 ` Vadim Godunko
@ 2002-03-11 21:06 ` Vadim Godunko
  2002-03-11 21:07 ` Vadim Godunko
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Vadim Godunko @ 2002-03-11 21:06 UTC (permalink / raw)


You MUST append ASCII.Nul if you pass any string parameters direct to
imported C routines.
For passing strings to C routines better use Interfaces.C.char_array type.
In package Interfaces.C you may found needed String<=>char_array conversion
routines, that automaticaly append/remove ASCII.Nul at the end of strings.
And, in you case, may be used standard Ada-POSIX bindings, that have open,
close, read, write,... functions.
This bindings for GNAT called Florist.

Regards,
Vadim

----- Original Message -----
From: "Karl Ran" <karlran1234@yahoo.com>
Newsgroups: comp.lang.ada
Sent: Monday, March 11, 2002 10:42 PM
Subject: Ada-kernel calls / IF & ELSE...


> Hi,
> I'm just starting to understand how to make Ada-kernel calls...
>
> Has anyone compiled the Kernel Calls demo on
> http://www.vaxxine.com/pegasoft/homes/13.html#13.5.4
> ?
>
> Here is a much simpler version:
>
> -----------------------------------------------------
> with Ada.Text_IO; use Ada.Text_IO;
>
> procedure audiocd is
>
>   DevCDROM : constant string := "/dev/cdrom";
>
>   type aFileID is new integer;
>
>   procedure open( id : out aFileID;
>                   path : string;
>                   flags : integer );
>
>   pragma import( C, open, "open");
>   pragma import_valued_procedure( open );
>
>   procedure perror( prefixstr : string );
>   pragma import( C, perror, "perror");
>
>   cd : aFileID;
>
> begin
>
>   Put_Line( "Openning " & DevCDROM & "..." );
>   Open( cd, DevCDROM, 0 );
>
>   if cd < 0 then
>      perror( "IF: Error openning CDROM drive " );
>   else
>      Put_Line( "ELSE: opened CDROM drive successfully " );
>   end if;
>
> end audiocd;
> -----------------------------------------------------
>
> >gnatmake -gnatwa audiocd.adb
> gcc -c -gnatwa audiocd.adb
> gnatbind -x audiocd.ali
> gnatlink audiocd.ali
>
> >./audiocd
> Openning /dev/cdrom...
> IF: Error openning CDROM drive ELSE: opened CDROM drive successfully :
> No such file or directory
>
>
> Would someone please explain whats going on here?
>
> Is this just because of my bleeding-edge-suse71-gnat3.14p-unsupported
> system or is normal?
>
>
> Karl





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

* Re: Ada-kernel calls / IF & ELSE...
  2002-03-11 19:42 Ada-kernel calls / IF & ELSE Karl Ran
                   ` (2 preceding siblings ...)
  2002-03-11 21:06 ` Vadim Godunko
@ 2002-03-11 21:07 ` Vadim Godunko
  2002-03-11 21:09 ` Vadim Godunko
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Vadim Godunko @ 2002-03-11 21:07 UTC (permalink / raw)


You MUST append ASCII.Nul if you pass any string parameters direct to
imported C routines.
For passing strings to C routines better use Interfaces.C.char_array type.
In package Interfaces.C you may found needed String<=>char_array conversion
routines, that automaticaly append/remove ASCII.Nul at the end of strings.
And, in you case, may be used standard Ada-POSIX bindings, that have open,
close, read, write,... functions.
This bindings for GNAT called Florist.

Regards,
Vadim

----- Original Message -----
From: "Karl Ran" <karlran1234@yahoo.com>
Newsgroups: comp.lang.ada
Sent: Monday, March 11, 2002 10:42 PM
Subject: Ada-kernel calls / IF & ELSE...


> Hi,
> I'm just starting to understand how to make Ada-kernel calls...
>
> Has anyone compiled the Kernel Calls demo on
> http://www.vaxxine.com/pegasoft/homes/13.html#13.5.4
> ?
>
> Here is a much simpler version:
>
> -----------------------------------------------------
> with Ada.Text_IO; use Ada.Text_IO;
>
> procedure audiocd is
>
>   DevCDROM : constant string := "/dev/cdrom";
>
>   type aFileID is new integer;
>
>   procedure open( id : out aFileID;
>                   path : string;
>                   flags : integer );
>
>   pragma import( C, open, "open");
>   pragma import_valued_procedure( open );
>
>   procedure perror( prefixstr : string );
>   pragma import( C, perror, "perror");
>
>   cd : aFileID;
>
> begin
>
>   Put_Line( "Openning " & DevCDROM & "..." );
>   Open( cd, DevCDROM, 0 );
>
>   if cd < 0 then
>      perror( "IF: Error openning CDROM drive " );
>   else
>      Put_Line( "ELSE: opened CDROM drive successfully " );
>   end if;
>
> end audiocd;
> -----------------------------------------------------
>
> >gnatmake -gnatwa audiocd.adb
> gcc -c -gnatwa audiocd.adb
> gnatbind -x audiocd.ali
> gnatlink audiocd.ali
>
> >./audiocd
> Openning /dev/cdrom...
> IF: Error openning CDROM drive ELSE: opened CDROM drive successfully :
> No such file or directory
>
>
> Would someone please explain whats going on here?
>
> Is this just because of my bleeding-edge-suse71-gnat3.14p-unsupported
> system or is normal?
>
>
> Karl





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

* Re: Ada-kernel calls / IF & ELSE...
  2002-03-11 19:42 Ada-kernel calls / IF & ELSE Karl Ran
                   ` (3 preceding siblings ...)
  2002-03-11 21:07 ` Vadim Godunko
@ 2002-03-11 21:09 ` Vadim Godunko
  2002-03-11 21:09 ` Vadim Godunko
  2002-03-12  0:34 ` Adrian Knoth
  6 siblings, 0 replies; 12+ messages in thread
From: Vadim Godunko @ 2002-03-11 21:09 UTC (permalink / raw)


You MUST append ASCII.Nul if you pass any string parameters direct to
imported C routines.
For passing strings to C routines better use Interfaces.C.char_array type.
In package Interfaces.C you may found needed String<=>char_array conversion
routines, that automaticaly append/remove ASCII.Nul at the end of strings.
And, in you case, may be used standard Ada-POSIX bindings, that have open,
close, read, write,... functions.
This bindings for GNAT called Florist.

Regards,
Vadim

----- Original Message -----
From: "Karl Ran" <karlran1234@yahoo.com>
Newsgroups: comp.lang.ada
Sent: Monday, March 11, 2002 10:42 PM
Subject: Ada-kernel calls / IF & ELSE...


> Hi,
> I'm just starting to understand how to make Ada-kernel calls...
>
> Has anyone compiled the Kernel Calls demo on
> http://www.vaxxine.com/pegasoft/homes/13.html#13.5.4
> ?
>
> Here is a much simpler version:
>
> -----------------------------------------------------
> with Ada.Text_IO; use Ada.Text_IO;
>
> procedure audiocd is
>
>   DevCDROM : constant string := "/dev/cdrom";
>
>   type aFileID is new integer;
>
>   procedure open( id : out aFileID;
>                   path : string;
>                   flags : integer );
>
>   pragma import( C, open, "open");
>   pragma import_valued_procedure( open );
>
>   procedure perror( prefixstr : string );
>   pragma import( C, perror, "perror");
>
>   cd : aFileID;
>
> begin
>
>   Put_Line( "Openning " & DevCDROM & "..." );
>   Open( cd, DevCDROM, 0 );
>
>   if cd < 0 then
>      perror( "IF: Error openning CDROM drive " );
>   else
>      Put_Line( "ELSE: opened CDROM drive successfully " );
>   end if;
>
> end audiocd;
> -----------------------------------------------------
>
> >gnatmake -gnatwa audiocd.adb
> gcc -c -gnatwa audiocd.adb
> gnatbind -x audiocd.ali
> gnatlink audiocd.ali
>
> >./audiocd
> Openning /dev/cdrom...
> IF: Error openning CDROM drive ELSE: opened CDROM drive successfully :
> No such file or directory
>
>
> Would someone please explain whats going on here?
>
> Is this just because of my bleeding-edge-suse71-gnat3.14p-unsupported
> system or is normal?
>
>
> Karl







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

* Re: Ada-kernel calls / IF & ELSE...
  2002-03-11 19:42 Ada-kernel calls / IF & ELSE Karl Ran
                   ` (4 preceding siblings ...)
  2002-03-11 21:09 ` Vadim Godunko
@ 2002-03-11 21:09 ` Vadim Godunko
  2002-03-11 21:17   ` Sorry for repeat " Vadim Godunko
  2002-03-12 15:01   ` Karl Ran
  2002-03-12  0:34 ` Adrian Knoth
  6 siblings, 2 replies; 12+ messages in thread
From: Vadim Godunko @ 2002-03-11 21:09 UTC (permalink / raw)


You MUST append ASCII.Nul if you pass any string parameters direct to
imported C routines.
For passing strings to C routines better use Interfaces.C.char_array type.
In package Interfaces.C you may found needed String<=>char_array conversion
routines, that automaticaly append/remove ASCII.Nul at the end of strings.
And, in you case, may be used standard Ada-POSIX bindings, that have open,
close, read, write,... functions.
This bindings for GNAT called Florist.

Regards,
Vadim

----- Original Message -----
From: "Karl Ran" <karlran1234@yahoo.com>
Newsgroups: comp.lang.ada
Sent: Monday, March 11, 2002 10:42 PM
Subject: Ada-kernel calls / IF & ELSE...


> Hi,
> I'm just starting to understand how to make Ada-kernel calls...
>
> Has anyone compiled the Kernel Calls demo on
> http://www.vaxxine.com/pegasoft/homes/13.html#13.5.4
> ?
>
> Here is a much simpler version:
>
> -----------------------------------------------------
> with Ada.Text_IO; use Ada.Text_IO;
>
> procedure audiocd is
>
>   DevCDROM : constant string := "/dev/cdrom";
>
>   type aFileID is new integer;
>
>   procedure open( id : out aFileID;
>                   path : string;
>                   flags : integer );
>
>   pragma import( C, open, "open");
>   pragma import_valued_procedure( open );
>
>   procedure perror( prefixstr : string );
>   pragma import( C, perror, "perror");
>
>   cd : aFileID;
>
> begin
>
>   Put_Line( "Openning " & DevCDROM & "..." );
>   Open( cd, DevCDROM, 0 );
>
>   if cd < 0 then
>      perror( "IF: Error openning CDROM drive " );
>   else
>      Put_Line( "ELSE: opened CDROM drive successfully " );
>   end if;
>
> end audiocd;
> -----------------------------------------------------
>
> >gnatmake -gnatwa audiocd.adb
> gcc -c -gnatwa audiocd.adb
> gnatbind -x audiocd.ali
> gnatlink audiocd.ali
>
> >./audiocd
> Openning /dev/cdrom...
> IF: Error openning CDROM drive ELSE: opened CDROM drive successfully :
> No such file or directory
>
>
> Would someone please explain whats going on here?
>
> Is this just because of my bleeding-edge-suse71-gnat3.14p-unsupported
> system or is normal?
>
>
> Karl







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

* Re: Sorry for repeat Ada-kernel calls / IF & ELSE...
  2002-03-11 21:09 ` Vadim Godunko
@ 2002-03-11 21:17   ` Vadim Godunko
  2002-03-12 15:01   ` Karl Ran
  1 sibling, 0 replies; 12+ messages in thread
From: Vadim Godunko @ 2002-03-11 21:17 UTC (permalink / raw)


Sorry for repeat.





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

* Re: Ada-kernel calls / IF & ELSE...
  2002-03-11 19:42 Ada-kernel calls / IF & ELSE Karl Ran
                   ` (5 preceding siblings ...)
  2002-03-11 21:09 ` Vadim Godunko
@ 2002-03-12  0:34 ` Adrian Knoth
  6 siblings, 0 replies; 12+ messages in thread
From: Adrian Knoth @ 2002-03-12  0:34 UTC (permalink / raw)


Karl Ran <karlran1234@yahoo.com> wrote:

> procedure audiocd is 
>   DevCDROM : constant string := "/dev/cdrom";

Besides your main problem I believe that you cannot open an audio-CD
by reading the device. The same approach doesn't work if you try
cat /dev/cdrom

>   Put_Line( "Openning " & DevCDROM & "..." );

Opening is with single-n, even if you're using a fast-spinning drive. :)


-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

Lieber einen albernen Haufen als einen Haufen Albaner (Ingo Appelt)



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

* Re: Ada-kernel calls / IF & ELSE...
  2002-03-11 21:09 ` Vadim Godunko
  2002-03-11 21:17   ` Sorry for repeat " Vadim Godunko
@ 2002-03-12 15:01   ` Karl Ran
  1 sibling, 0 replies; 12+ messages in thread
From: Karl Ran @ 2002-03-12 15:01 UTC (permalink / raw)


"Vadim Godunko" <vgodunko@vipmail.ru> wrote in message news:<mailman.1015881064.32112.comp.lang.ada@ada.eu.org>...

> This bindings for GNAT called Florist.

The florist package looks good.
Thanks for the hint!

Karl



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

* Re: Ada-kernel calls / IF & ELSE...
  2002-03-11 20:41 ` Bj�rn Lundin
@ 2002-03-12 15:09   ` Karl Ran
  2002-03-12 20:16     ` Vadim Godunko
  0 siblings, 1 reply; 12+ messages in thread
From: Karl Ran @ 2002-03-12 15:09 UTC (permalink / raw)


Bj?n Lundin <bjorn.lundin@swipnet.se> wrote in message news:<20020311214143.5e9e1061.bjorn.lundin@swipnet.se>...
> > >./audiocd

> > Is this just because of my bleeding-edge-suse71-gnat3.14p-unsupported
> > system or is normal?
> > 
> > 
> > Karl
> 
> No I get the same output on mandrake 8.1 with 3.13p, but if you replace perror with 
> another  put_line, it behaves ok.

OK, same here.
So, why does gnat generate incorrect code when using perror?

A compile-time warning would be great!

Karl



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

* Re: Ada-kernel calls / IF & ELSE...
  2002-03-12 15:09   ` Karl Ran
@ 2002-03-12 20:16     ` Vadim Godunko
  0 siblings, 0 replies; 12+ messages in thread
From: Vadim Godunko @ 2002-03-12 20:16 UTC (permalink / raw)


> So, why does gnat generate incorrect code when using perror?

See LRM B.3(72)





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

end of thread, other threads:[~2002-03-12 20:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-11 19:42 Ada-kernel calls / IF & ELSE Karl Ran
2002-03-11 20:41 ` Bj�rn Lundin
2002-03-12 15:09   ` Karl Ran
2002-03-12 20:16     ` Vadim Godunko
2002-03-11 21:06 ` Vadim Godunko
2002-03-11 21:06 ` Vadim Godunko
2002-03-11 21:07 ` Vadim Godunko
2002-03-11 21:09 ` Vadim Godunko
2002-03-11 21:09 ` Vadim Godunko
2002-03-11 21:17   ` Sorry for repeat " Vadim Godunko
2002-03-12 15:01   ` Karl Ran
2002-03-12  0:34 ` Adrian Knoth

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