comp.lang.ada
 help / color / mirror / Atom feed
* How to exit a loop with keyboard input
@ 2010-04-12  4:12 Jerry
  2010-04-12  8:50 ` Georg Bauhaus
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Jerry @ 2010-04-12  4:12 UTC (permalink / raw)


[Sorry for the cross-post.]

I have a loop which is doing a repetitive calculation. Sometimes the
loop runs a long time and I want to manually cause the loop to be
exited but have the program continue running, for example to save some
results to a file or do other calculations. Preferably I would just
hit a key or key combination.

I thought Get_Immediate would work (reading Cohen's book) but it does
not do what I want. For example, the following program stops looping
and requires me to hit RETURN even if I hit another key first. It
continues looping (very slowly) if I hold down the RETURN key.

I don't mind using GNAT-specific stuff as long as it gets the job
done.

Thanks.

Jerry


with Ada.Text_IO;
use  Ada.Text_IO;
procedure key is
    i         : Integer;
    Keystroke : Character;
    Available : Boolean;
begin
    i := 0;
    loop
        Put(Integer'Image(i));
        Get_Immediate(Keystroke, Available);
            if Available then
                if Keystroke = 'q' then
                    exit;
                end if;
            end if;
        i := i + 1;
    end loop;
    Put_Line("Finished");
end key;



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

* Re: How to exit a loop with keyboard input
  2010-04-12  4:12 How to exit a loop with keyboard input Jerry
@ 2010-04-12  8:50 ` Georg Bauhaus
  2010-04-12  9:21   ` Manuel Collado
  2010-04-12 10:36 ` Jerry
  2010-04-12 20:57 ` Alex Mentis
  2 siblings, 1 reply; 23+ messages in thread
From: Georg Bauhaus @ 2010-04-12  8:50 UTC (permalink / raw)


Jerry schrieb:

> 
> with Ada.Text_IO;
> use  Ada.Text_IO;
> procedure key is
>     i         : Integer;
>     Keystroke : Character;
>     Available : Boolean;
> begin
>     i := 0;
>     loop
>         Put(Integer'Image(i));
>         Get_Immediate(Keystroke, Available);
>             if Available then
>                 if Keystroke = 'q' then
>                     exit;
>                 end if;
>             end if;
>         i := i + 1;
>     end loop;
>     Put_Line("Finished");
> end key;


Works as desired on Debian GNU/Linux stable.



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

* Re: How to exit a loop with keyboard input
  2010-04-12  8:50 ` Georg Bauhaus
@ 2010-04-12  9:21   ` Manuel Collado
  0 siblings, 0 replies; 23+ messages in thread
From: Manuel Collado @ 2010-04-12  9:21 UTC (permalink / raw)


Georg Bauhaus escribi�:
> Jerry schrieb:
> 
>> with Ada.Text_IO;
>> use  Ada.Text_IO;
>> procedure key is
>>     i         : Integer;
>>     Keystroke : Character;
>>     Available : Boolean;
>> begin
>>     i := 0;
>>     loop
>>         Put(Integer'Image(i));
>>         Get_Immediate(Keystroke, Available);
>>             if Available then
>>                 if Keystroke = 'q' then
>>                     exit;
>>                 end if;
>>             end if;
>>         i := i + 1;
>>     end loop;
>>     Put_Line("Finished");
>> end key;
> 
> 
> Works as desired on Debian GNU/Linux stable.

Also in Windows XP with GNAT GPL 2005

-- 
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado



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

* Re: How to exit a loop with keyboard input
  2010-04-12  4:12 How to exit a loop with keyboard input Jerry
  2010-04-12  8:50 ` Georg Bauhaus
@ 2010-04-12 10:36 ` Jerry
  2010-04-12 13:59   ` John McCormick
  2010-04-12 15:14   ` Tero Koskinen
  2010-04-12 20:57 ` Alex Mentis
  2 siblings, 2 replies; 23+ messages in thread
From: Jerry @ 2010-04-12 10:36 UTC (permalink / raw)


Thanks, Georg and Manuel, for testing. I'm on OS X 10.5.8 and:

MBPro:/ me$ gnat
GNAT 4.4.0 20080314 (experimental) [trunk revision 133226]
Copyright 1996-2007, Free Software Foundation, Inc.

I've tried the program on three different terminal programs with the
same result: it prints out 0 and waits for RETURN, then prints out 1,
etc. If I hit q then RETURN the loop is exited. But the loop never
"free-runs."

Jerry



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

* Re: How to exit a loop with keyboard input
  2010-04-12 10:36 ` Jerry
@ 2010-04-12 13:59   ` John McCormick
  2010-04-13 19:38     ` Jerry
  2010-04-12 15:14   ` Tero Koskinen
  1 sibling, 1 reply; 23+ messages in thread
From: John McCormick @ 2010-04-12 13:59 UTC (permalink / raw)


On Apr 12, 5:36 am, Jerry <lancebo...@qwest.net> wrote:
> Thanks, Georg and Manuel, for testing. I'm on OS X 10.5.8 and:
>
> MBPro:/ me$ gnat
> GNAT 4.4.0 20080314 (experimental) [trunk revision 133226]
> Copyright 1996-2007, Free Software Foundation, Inc.
>
> I've tried the program on three different terminal programs with the
> same result: it prints out 0 and waits for RETURN, then prints out 1,
> etc. If I hit q then RETURN the loop is exited. But the loop never
> "free-runs."
>
> Jerry

Perhaps the Asynchronous Transfer of Control mechanism would be
appropriate.  Here is some GNAT code that runs under Windows XP in
which the input loop is interrutpted by Ctrl-c.  The interrupt handler
must be at the library level so I put it in its own package.

   select
      Ctrl_C_Interrupt.Wait;
      Put_Line ("Handled Ctrl C");
   then abort
      loop
         Put_Line ("Enter an integer (Ctrl C to exit)");
         Get (Value);
         Put (Value);
         New_Line;
      end loop;
   end select;

-----------------------------------------------------------
with Ada.Interrupts.Names;
package Ctrl_C is

   protected Ctrl_C_Interrupt is
      entry Wait;
      procedure Handler;
      pragma Attach_Handler (Handler, Ada.Interrupts.Names.SIGINT);
      pragma Interrupt_Priority;
   private
      Received : Boolean := False;
   end Ctrl_C_Interrupt;
end Ctrl_C;

-----------------------------------------------------------
package body Ctrl_C is

   protected body Ctrl_C_Interrupt is
      procedure Handler is
      begin
         Received := True;
      end Handler;

      entry Wait when Received is
      begin
         Received := False;
      end Wait;
   end Ctrl_C_Interrupt;

end Ctrl_C;

John




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

* Re: How to exit a loop with keyboard input
  2010-04-12 10:36 ` Jerry
  2010-04-12 13:59   ` John McCormick
@ 2010-04-12 15:14   ` Tero Koskinen
  2010-04-12 16:16     ` John B. Matthews
  2010-04-12 20:04     ` Simon Wright
  1 sibling, 2 replies; 23+ messages in thread
From: Tero Koskinen @ 2010-04-12 15:14 UTC (permalink / raw)


On Mon, 12 Apr 2010 03:36:42 -0700 (PDT) Jerry wrote:

> Thanks, Georg and Manuel, for testing. I'm on OS X 10.5.8 and:

Most likely Get_Immediate is not implemented for OS X and
the code is defaulting to blocking behaviour.

Look at getc_immediate_common in sysdep.c.

I have there (gcc 4.3.4) following #ifdef jungle:
...
{
#if defined (linux) || defined (sun) || defined (sgi) || defined (__EMX__) \
    || (defined (__osf__) && ! defined (__alpha_vxworks)) \
    || defined (__CYGWIN32__) || defined (__MACHTEN__) || defined (__hpux__) \
    || defined (_AIX) || (defined (__svr4__) && defined (i386)) \
    || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__)
...

__MACHTEN__ might be related to OS X, but I don't have a Mac around, so
I am just guessing.

> Jerry


-- 
Tero Koskinen - http://iki.fi/tero.koskinen/



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

* Re: How to exit a loop with keyboard input
  2010-04-12 15:14   ` Tero Koskinen
@ 2010-04-12 16:16     ` John B. Matthews
  2010-04-12 20:04     ` Simon Wright
  1 sibling, 0 replies; 23+ messages in thread
From: John B. Matthews @ 2010-04-12 16:16 UTC (permalink / raw)


In article <20100412181434.dd154269.tero.koskinen@iki.fi>,
 Tero Koskinen <tero.koskinen@iki.fi> wrote:

> On Mon, 12 Apr 2010 03:36:42 -0700 (PDT) Jerry wrote:
> 
> > Thanks, Georg and Manuel, for testing. I'm on OS X 10.5.8 and:
> 
> Most likely Get_Immediate is not implemented for OS X and
> the code is defaulting to blocking behaviour.
> 
> Look at getc_immediate_common in sysdep.c.
> 
> I have there (gcc 4.3.4) following #ifdef jungle:
> ...
> {
> #if defined (linux) || defined (sun) || defined (sgi) || defined (__EMX__) \
>     || (defined (__osf__) && ! defined (__alpha_vxworks)) \
>     || defined (__CYGWIN32__) || defined (__MACHTEN__) || defined (__hpux__) \
>     || defined (_AIX) || (defined (__svr4__) && defined (i386)) \
>     || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__)
> ...
> 
> __MACHTEN__ might be related to OS X, but I don't have a Mac around, so
> I am just guessing.

For reference, MachTen is a product to run the GNU development toolset, 
including GNAT, on Mac OS 9.

<http://www.tenon.com/products/machten/>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



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

* Re: How to exit a loop with keyboard input
  2010-04-12 15:14   ` Tero Koskinen
  2010-04-12 16:16     ` John B. Matthews
@ 2010-04-12 20:04     ` Simon Wright
  2010-04-13 19:51       ` Jerry
  1 sibling, 1 reply; 23+ messages in thread
From: Simon Wright @ 2010-04-12 20:04 UTC (permalink / raw)


Tero Koskinen <tero.koskinen@iki.fi> writes:

> On Mon, 12 Apr 2010 03:36:42 -0700 (PDT) Jerry wrote:
>
>> Thanks, Georg and Manuel, for testing. I'm on OS X 10.5.8 and:
>
> Most likely Get_Immediate is not implemented for OS X and
> the code is defaulting to blocking behaviour.
>
> Look at getc_immediate_common in sysdep.c.
>
> I have there (gcc 4.3.4) following #ifdef jungle:
> ...
> {
> #if defined (linux) || defined (sun) || defined (sgi) || defined (__EMX__) \
>     || (defined (__osf__) && ! defined (__alpha_vxworks)) \
>     || defined (__CYGWIN32__) || defined (__MACHTEN__) || defined (__hpux__) \
>     || defined (_AIX) || (defined (__svr4__) && defined (i386)) \
>     || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__)
> ...
>
> __MACHTEN__ might be related to OS X, but I don't have a Mac around, so
> I am just guessing.

The current source (r156233) says

{
#if defined (linux) || defined (sun) || defined (sgi) || defined (__EMX__) \
    || (defined (__osf__) && ! defined (__alpha_vxworks)) \
    || defined (__CYGWIN32__) || defined (__MACHTEN__) || defined (__hpux__) \
    || defined (_AIX) || (defined (__svr4__) && defined (i386)) \
    || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
    || defined (__GLIBC__) || defined (__APPLE__)

and it's the __APPLE__ that does the trick. This was fixed 2009-04-15
(r146098) and is OK in GNAT GPL 2009 and, of course, in GCC 4.5.0 (still
only 'experimental').



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

* Re: How to exit a loop with keyboard input
  2010-04-12  4:12 How to exit a loop with keyboard input Jerry
  2010-04-12  8:50 ` Georg Bauhaus
  2010-04-12 10:36 ` Jerry
@ 2010-04-12 20:57 ` Alex Mentis
  2010-04-12 22:51   ` Jerry
  2 siblings, 1 reply; 23+ messages in thread
From: Alex Mentis @ 2010-04-12 20:57 UTC (permalink / raw)


On Apr 12, 12:12 am, Jerry <lancebo...@qwest.net> wrote:
> [Sorry for the cross-post.]

> I thought Get_Immediate would work (reading Cohen's book) but it does
> not do what I want. For example, the following program stops looping
> and requires me to hit RETURN even if I hit another key first. It
> continues looping (very slowly) if I hold down the RETURN key.
>

Are you using GPS as your IDE by any chance?  When I run programs
using Get_Immediate from inside GPS, Get_Immediate does not work as it
should (it requires a CR after the character input).  When I run those
same programs in an external terminal window it works fine.  Perhaps
something between your keyboard and your program is buffering your
input without your knowledge?

Alex




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

* Re: How to exit a loop with keyboard input
  2010-04-12 20:57 ` Alex Mentis
@ 2010-04-12 22:51   ` Jerry
  2010-04-16  0:06     ` BrianG
  0 siblings, 1 reply; 23+ messages in thread
From: Jerry @ 2010-04-12 22:51 UTC (permalink / raw)


On Apr 12, 1:57 pm, Alex Mentis <asmen...@gmail.com> wrote:
snip
> Are you using GPS as your IDE by any chance?  When I run programs
> using Get_Immediate from inside GPS, Get_Immediate does not work as it
> should (it requires a CR after the character input).  When I run those
> same programs in an external terminal window it works fine.  Perhaps
> something between your keyboard and your program is buffering your
> input without your knowledge?
>
> Alex

I'm not using GPS, but I thought of the possibility of a problem with
the development environment which in my case is Apple's Xcode. That's
why I executed in three other terminal programs (including Apple's
Terminal.app, the terminal in Path Finder, and something called
iTerm), but all gave the same result. Which doesn't completely answer
the question of stealth buffering. But given the discussion above
about a patch I'm guessing the problem is not weird buffering.

Jerry



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

* Re: How to exit a loop with keyboard input
  2010-04-12 13:59   ` John McCormick
@ 2010-04-13 19:38     ` Jerry
  0 siblings, 0 replies; 23+ messages in thread
From: Jerry @ 2010-04-13 19:38 UTC (permalink / raw)


On Apr 12, 6:59 am, John McCormick <mccorm...@cs.uni.edu> wrote:
> On Apr 12, 5:36 am, Jerry <lancebo...@qwest.net> wrote:
>
> > Thanks, Georg and Manuel, for testing. I'm on OS X 10.5.8 and:
>
> > MBPro:/ me$ gnat
> > GNAT 4.4.0 20080314 (experimental) [trunk revision 133226]
> > Copyright 1996-2007, Free Software Foundation, Inc.
>
> > I've tried the program on three different terminal programs with the
> > same result: it prints out 0 and waits for RETURN, then prints out 1,
> > etc. If I hit q then RETURN the loop is exited. But the loop never
> > "free-runs."
>
> > Jerry
>
> Perhaps the Asynchronous Transfer of Control mechanism would be
> appropriate.  Here is some GNAT code that runs under Windows XP in
> which the input loop is interrutpted by Ctrl-c.  The interrupt handler
> must be at the library level so I put it in its own package.
>
>    select
>       Ctrl_C_Interrupt.Wait;
>       Put_Line ("Handled Ctrl C");
>    then abort
>       loop
>          Put_Line ("Enter an integer (Ctrl C to exit)");
>          Get (Value);
>          Put (Value);
>          New_Line;
>       end loop;
>    end select;
>
> -----------------------------------------------------------
> with Ada.Interrupts.Names;
> package Ctrl_C is
>
>    protected Ctrl_C_Interrupt is
>       entry Wait;
>       procedure Handler;
>       pragma Attach_Handler (Handler, Ada.Interrupts.Names.SIGINT);
>       pragma Interrupt_Priority;
>    private
>       Received : Boolean := False;
>    end Ctrl_C_Interrupt;
> end Ctrl_C;
>
> -----------------------------------------------------------
> package body Ctrl_C is
>
>    protected body Ctrl_C_Interrupt is
>       procedure Handler is
>       begin
>          Received := True;
>       end Handler;
>
>       entry Wait when Received is
>       begin
>          Received := False;
>       end Wait;
>    end Ctrl_C_Interrupt;
>
> end Ctrl_C;
>
> John

Thanks, John.

Your solution does work (after I added pragma
Unreserve_All_Interrupts;) and I think I can adapt it to my specific
problem but it takes 100% of CPU time so I'm not sure how that would
affect my number-crunching loop. (A similar solution was suggested by
Chris on the GNAT-OSX list but I haven't tried it yet.)

Jerry



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

* Re: How to exit a loop with keyboard input
  2010-04-12 20:04     ` Simon Wright
@ 2010-04-13 19:51       ` Jerry
  2010-04-13 21:22         ` Simon Wright
  0 siblings, 1 reply; 23+ messages in thread
From: Jerry @ 2010-04-13 19:51 UTC (permalink / raw)


On Apr 12, 1:04 pm, Simon Wright <si...@pushface.org> wrote:
> Tero Koskinen <tero.koski...@iki.fi> writes:
> > On Mon, 12 Apr 2010 03:36:42 -0700 (PDT) Jerry wrote:
>
> >> Thanks, Georg and Manuel, for testing. I'm on OS X 10.5.8 and:
>
> > Most likely Get_Immediate is not implemented for OS X and
> > the code is defaulting to blocking behaviour.
>
> > Look at getc_immediate_common in sysdep.c.
>
> > I have there (gcc 4.3.4) following #ifdef jungle:
> > ...
> > {
> > #if defined (linux) || defined (sun) || defined (sgi) || defined (__EMX__) \
> >     || (defined (__osf__) && ! defined (__alpha_vxworks)) \
> >     || defined (__CYGWIN32__) || defined (__MACHTEN__) || defined (__hpux__) \
> >     || defined (_AIX) || (defined (__svr4__) && defined (i386)) \
> >     || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__)
> > ...
>
> > __MACHTEN__ might be related to OS X, but I don't have a Mac around, so
> > I am just guessing.
>
> The current source (r156233) says
>
> {
> #if defined (linux) || defined (sun) || defined (sgi) || defined (__EMX__) \
>     || (defined (__osf__) && ! defined (__alpha_vxworks)) \
>     || defined (__CYGWIN32__) || defined (__MACHTEN__) || defined (__hpux__) \
>     || defined (_AIX) || (defined (__svr4__) && defined (i386)) \
>     || defined (__Lynx__) || defined (__FreeBSD__) || defined (__OpenBSD__) \
>     || defined (__GLIBC__) || defined (__APPLE__)
>
> and it's the __APPLE__ that does the trick. This was fixed 2009-04-15
> (r146098) and is OK in GNAT GPL 2009 and, of course, in GCC 4.5.0 (still
> only 'experimental').

Thanks, Simon. The GPL versions from both your build at sourceforge
and from AdaCore indeed have this problem fixed.

However, both of these builds still contain the old bug which arises
when using
    Ada.Numerics.Long_Real_Arrays;
in which the linker can't find the non-existent (on OS X) library
lgnalasup (linear algebra support) requested by i-forbla.adb. I
thought this was fixed a long time ago and if I'm reading the history
correctly it was fixed on Apr 22 07:14:31 2008. I suppose I should
raise this on another thread, however.

Jerry



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

* Re: How to exit a loop with keyboard input
  2010-04-13 19:51       ` Jerry
@ 2010-04-13 21:22         ` Simon Wright
  2010-04-15  3:39           ` Jerry
  0 siblings, 1 reply; 23+ messages in thread
From: Simon Wright @ 2010-04-13 21:22 UTC (permalink / raw)


Jerry <lanceboyle@qwest.net> writes:

> However, both of these builds still contain the old bug which arises
> when using
>     Ada.Numerics.Long_Real_Arrays;
> in which the linker can't find the non-existent (on OS X) library
> lgnalasup (linear algebra support) requested by i-forbla.adb. I
> thought this was fixed a long time ago and if I'm reading the history
> correctly it was fixed on Apr 22 07:14:31 2008. I suppose I should
> raise this on another thread, however.

Same here.

$ gnatmake jerry
gcc -c jerry.adb
gnatbind -x jerry.ali
gnatlink jerry.ali
ld: library not found for -lgnalasup
collect2: ld returned 1 exit status
gnatlink: error when calling /opt/gnat-gpl-2009-x86_64/bin/gcc
gnatmake: *** link failed.

(sorry to take your name in vain, it helps me to keep my ~/tmp
code in order)

4.5.0 has a Darwin-specific i-forbla.adb containing

OX--------------------------------------------
--  Version for Mac OS X

package body Interfaces.Fortran.BLAS is
   pragma Linker_Options ("-Wl,-framework,vecLib");
end Interfaces.Fortran.BLAS;
OX--------------------------------------------

and I just managed to link (just a 'with', no execution) with GNAT GPL
2009 by compiling against this file -- I put it in a subdir called math
and said

$ gnatmake jerry -a -Imath
gcc -gnatpg -c -Imath i-forbla.adb
gnatbind -Imath -x jerry.ali
gnatlink jerry.ali



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

* Re: How to exit a loop with keyboard input
  2010-04-13 21:22         ` Simon Wright
@ 2010-04-15  3:39           ` Jerry
  2010-04-15  4:08             ` John B. Matthews
  2010-04-15 19:22             ` Simon Wright
  0 siblings, 2 replies; 23+ messages in thread
From: Jerry @ 2010-04-15  3:39 UTC (permalink / raw)


On Apr 13, 2:22 pm, Simon Wright <si...@pushface.org> wrote:
> Jerry <lancebo...@qwest.net> writes:
> > However, both of these builds still contain the old bug which arises
> > when using
> >     Ada.Numerics.Long_Real_Arrays;
> > in which the linker can't find the non-existent (on OS X) library
> > lgnalasup (linear algebra support) requested by i-forbla.adb. I
> > thought this was fixed a long time ago and if I'm reading the history
> > correctly it was fixed on Apr 22 07:14:31 2008. I suppose I should
> > raise this on another thread, however.
>
> Same here.
>
> $ gnatmake jerry
> gcc -c jerry.adb
> gnatbind -x jerry.ali
> gnatlink jerry.ali
> ld: library not found for -lgnalasup
> collect2: ld returned 1 exit status
> gnatlink: error when calling /opt/gnat-gpl-2009-x86_64/bin/gcc
> gnatmake: *** link failed.
>
> (sorry to take your name in vain, it helps me to keep my ~/tmp
> code in order)
>
> 4.5.0 has a Darwin-specific i-forbla.adb containing
>
> OX--------------------------------------------
> --  Version for Mac OS X
>
> package body Interfaces.Fortran.BLAS is
>    pragma Linker_Options ("-Wl,-framework,vecLib");
> end Interfaces.Fortran.BLAS;
> OX--------------------------------------------
>
> and I just managed to link (just a 'with', no execution) with GNAT GPL
> 2009 by compiling against this file -- I put it in a subdir called math
> and said
>
> $ gnatmake jerry -a -Imath
> gcc -gnatpg -c -Imath i-forbla.adb
> gnatbind -Imath -x jerry.ali
> gnatlink jerry.ali

Awesome. In the past I discovered that if I delete the inappropriate
linker pragma in i-forbla.adb and link with -largs to the BLAS and
LAPACK libraries in the OS X frameworks that I could work around this
problem. But this is better. Following your lead, I moved the newly-
made i-forbla.o and i-forbla.ali into

/opt/gnat-gpl-2009/lib/gcc/i386-apple-darwin9.7.0/4.3.4/adalib

I then moved /opt/gnat-gpl-2009 to /usr/local/ada-4.3 which is where
the Xcode Ada plug-in expects to find a compiler. I also moved your /
opt/gnu/ to /usr/local/gnu.

I can now compile a small program that uses Real_Vector etc. and has a
non-blocking Get_Immediate without any compiler switches using Xcode
with the (ever-brittle) Ada plug-in. 8o)

Trying to use the GUI debugger within Xcode,
(Apple version gdb-768) (Tue Oct  2 04:07:49 UTC 2007)
is mostly successful but it bombs with SIGBUS when trying to single-
step past a Put_Line.

I have also applied the fix to AdaCore's GPL 2009.

Unfortunately, with the new set-up, building PLplot (to which I wrote
Ada bindings) now results in the linker complaining of some dylibs,
"file is not of required  architecture."

Jerry



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

* Re: How to exit a loop with keyboard input
  2010-04-15  3:39           ` Jerry
@ 2010-04-15  4:08             ` John B. Matthews
  2010-04-15 18:51               ` Jerry
  2010-04-15 19:22             ` Simon Wright
  1 sibling, 1 reply; 23+ messages in thread
From: John B. Matthews @ 2010-04-15  4:08 UTC (permalink / raw)


In article 
<cde1ed80-fcd9-430d-bb96-07556e58665d@30g2000yqi.googlegroups.com>,
 Jerry <lanceboyle@qwest.net> wrote:

> Awesome. In the past I discovered that if I delete the inappropriate
> linker pragma in i-forbla.adb and link with -largs to the BLAS and
> LAPACK libraries in the OS X frameworks that I could work around this
> problem. But this is better. Following your lead, I moved the newly-
> made i-forbla.o and i-forbla.ali into
> 
> /opt/gnat-gpl-2009/lib/gcc/i386-apple-darwin9.7.0/4.3.4/adalib

For convenience, I wrote a little makefile to build and install a 
modified i-forbla.adb, et al.

<http://home.roadrunner.com/~jbmatthews/misc/groots.html>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



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

* Re: How to exit a loop with keyboard input
  2010-04-15  4:08             ` John B. Matthews
@ 2010-04-15 18:51               ` Jerry
  2010-04-16  0:44                 ` John B. Matthews
  0 siblings, 1 reply; 23+ messages in thread
From: Jerry @ 2010-04-15 18:51 UTC (permalink / raw)


On Apr 14, 9:08 pm, "John B. Matthews" <nos...@nospam.invalid> wrote:
> In article
> <cde1ed80-fcd9-430d-bb96-07556e586...@30g2000yqi.googlegroups.com>,
>
>  Jerry <lancebo...@qwest.net> wrote:
> > Awesome. In the past I discovered that if I delete the inappropriate
> > linker pragma in i-forbla.adb and link with -largs to the BLAS and
> > LAPACK libraries in the OS X frameworks that I could work around this
> > problem. But this is better. Following your lead, I moved the newly-
> > made i-forbla.o and i-forbla.ali into
>
> > /opt/gnat-gpl-2009/lib/gcc/i386-apple-darwin9.7.0/4.3.4/adalib
>
> For convenience, I wrote a little makefile to build and install a
> modified i-forbla.adb, et al.
>
> <http://home.roadrunner.com/~jbmatthews/misc/groots.html>
>
> --
> John B. Matthews
> trashgod at gmail dot com
> <http://sites.google.com/site/drjohnbmatthews>

Hmmm. I couldn't find it on that page.
Jerry



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

* Re: How to exit a loop with keyboard input
  2010-04-15  3:39           ` Jerry
  2010-04-15  4:08             ` John B. Matthews
@ 2010-04-15 19:22             ` Simon Wright
  2010-04-16 10:25               ` Jerry
  1 sibling, 1 reply; 23+ messages in thread
From: Simon Wright @ 2010-04-15 19:22 UTC (permalink / raw)


Jerry <lanceboyle@qwest.net> writes:

> Unfortunately, with the new set-up, building PLplot (to which I wrote
> Ada bindings) now results in the linker complaining of some dylibs,
> "file is not of required architecture."

The SourceForge Leopard GNAT GPL 2009 compiler is 32-bit, while
AdaCore's is 64-bit.

I had a Leopard issue, where libtk was a thin library supporting only
32-bit, so I got the sort of problem you report when using AdaCore's
compiler.

Are you getting the problem with both compilers? if so, I'd expect each
compiler to report the problem with different libraries. And your only
recourse will be to rebuild the offending libraries with the appropriate
compiler. What I've done is to use the matching GNAT compiler; eg for
64-bit,

$ PATH=/opt/gnat-gpl-2009-x86_64/bin:$PATH
$ ./configure ....
$ make

Given that most people don't build GNAT with c++, this is only going to
work if the library concerned is C-based.

You can find what architectures a library supports using lipo (-info or
-detailed_info): in my /opt/gnu/lib I have some of the libraries used
for compiler builds, so I get

$ lipo -info *.a
Architectures in the fat file: libgmp.a are: i386 x86_64 
input file libhistory.a is not a fat file
input file libltdl.a is not a fat file
Architectures in the fat file: libmpc.a are: i386 x86_64 
Architectures in the fat file: libmpfr.a are: i386 x86_64 
input file libreadline.a is not a fat file
Non-fat file: libhistory.a is architecture: i386
Non-fat file: libltdl.a is architecture: i386
Non-fat file: libreadline.a is architecture: i386



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

* Re: How to exit a loop with keyboard input
  2010-04-12 22:51   ` Jerry
@ 2010-04-16  0:06     ` BrianG
  2010-04-16  7:23       ` Jerry
  0 siblings, 1 reply; 23+ messages in thread
From: BrianG @ 2010-04-16  0:06 UTC (permalink / raw)


Jerry wrote:
> On Apr 12, 1:57 pm, Alex Mentis <asmen...@gmail.com> wrote:
> snip
>> Are you using GPS as your IDE by any chance?  When I run programs
>> using Get_Immediate from inside GPS, Get_Immediate does not work as it
>> should (it requires a CR after the character input).  When I run those
>> same programs in an external terminal window it works fine.  Perhaps
>> something between your keyboard and your program is buffering your
>> input without your knowledge?
>>
>> Alex
> 
> I'm not using GPS, but I thought of the possibility of a problem with
> the development environment which in my case is Apple's Xcode. That's
> why I executed in three other terminal programs (including Apple's
> Terminal.app, the terminal in Path Finder, and something called
> iTerm), but all gave the same result. Which doesn't completely answer
> the question of stealth buffering. But given the discussion above
> about a patch I'm guessing the problem is not weird buffering.
> 
> Jerry

When GNAT for DOS/Windows (yeah, a while ago - remember Ada9X?) did 
this, I used a 'wimp out' solution:

    function KB_Hit return Boolean;
    pragma Import(KB_Hit, "kbhit"); --not sure of the syntax
    ...
       exit when KB_Hit;
    ...
   (of course you have to remember to Flush or equiv)

Not pretty, but it worked.

--BrianG

	--I'm in a groove now -
	-- Or is it a rut?



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

* Re: How to exit a loop with keyboard input
  2010-04-15 18:51               ` Jerry
@ 2010-04-16  0:44                 ` John B. Matthews
  2010-04-16  4:43                   ` Simon Wright
  0 siblings, 1 reply; 23+ messages in thread
From: John B. Matthews @ 2010-04-16  0:44 UTC (permalink / raw)


In article 
<780f0643-3c51-4cc6-827e-3fd68d477423@x12g2000yqx.googlegroups.com>,
 Jerry <lanceboyle@qwest.net> wrote:

> On Apr 14, 9:08 pm, "John B. Matthews" <nos...@nospam.invalid> wrote:
> > In article
> > <cde1ed80-fcd9-430d-bb96-07556e586...@30g2000yqi.googlegroups.com>,
> >
> >  Jerry <lancebo...@qwest.net> wrote:
> > > Awesome. In the past I discovered that if I delete the inappropriate
> > > linker pragma in i-forbla.adb and link with -largs to the BLAS and
> > > LAPACK libraries in the OS X frameworks that I could work around this
> > > problem. But this is better. Following your lead, I moved the newly-
> > > made i-forbla.o and i-forbla.ali into
> >
> > > /opt/gnat-gpl-2009/lib/gcc/i386-apple-darwin9.7.0/4.3.4/adalib
> >
> > For convenience, I wrote a little makefile to build and install a
> > modified i-forbla.adb, et al.
> >
> > <http://home.roadrunner.com/~jbmatthews/misc/groots.html>
> 
> Hmmm. I couldn't find it on that page.

Sorry, it's in the .tgz in numeric/numerics/makefile:

# Ada.Numerics Makefile
# 
# Author: John B. Matthews, Gem City Software
# Distribution: GMGPL
# Last Modified: October 2007
#

PREFIX =  /usr/local/ada-4.3/lib/gcc/i686-apple-darwin9/4.3.4
OPTS = -a -k -O2
ADAINC = $(PREFIX)/adainclude
ADALIB = $(PREFIX)/adalib
SOURCE = $(wildcard *.ad[sb])
UNITS = $(basename $(wildcard *.ads))
ALIS = $(wildcard *.ali)
OBJS = $(wildcard *.o)

.PHONY: all install uninstall clean test

all:
    gnatmake $(OPTS) $(UNITS)

install:
    cp $(SOURCE) $(ADAINC)/
    cp *.ali $(ADALIB)/
    cp *.o $(ADALIB)/

uninstall:
    @for file in $(SOURCE); do ${RM} $(ADAINC)/$$file; done
    @for file in $(ALIS); do ${RM} $(ADALIB)/$$file; done
    @for file in $(OBJS); do ${RM} $(ADALIB)/$$file; done

clean:
    ${RM} *.ali *.o

test:
    @echo "Source files: $(SOURCE)"
    @echo "Compilation units: $(UNITS)"
    @for file in $(SOURCE); do ls $(ADAINC)/$$file; done
    @for file in $(ALIS); do ls $(ADALIB)/$$file; done
    @for file in $(OBJS); do ls $(ADALIB)/$$file; done

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



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

* Re: How to exit a loop with keyboard input
  2010-04-16  0:44                 ` John B. Matthews
@ 2010-04-16  4:43                   ` Simon Wright
  2010-04-16 14:03                     ` John B. Matthews
  0 siblings, 1 reply; 23+ messages in thread
From: Simon Wright @ 2010-04-16  4:43 UTC (permalink / raw)


The installed .ali files should be made read-only (which may mean adding
-f to the cp, rm calls).

Not sure about the uninstall target -- shouldn't the original be
replaced, if there was one?



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

* Re: How to exit a loop with keyboard input
  2010-04-16  0:06     ` BrianG
@ 2010-04-16  7:23       ` Jerry
  0 siblings, 0 replies; 23+ messages in thread
From: Jerry @ 2010-04-16  7:23 UTC (permalink / raw)


On Apr 15, 5:06 pm, BrianG <briang...@gmail.com> wrote:
> > Jerry
>
> When GNAT for DOS/Windows (yeah, a while ago - remember Ada9X?) did
> this, I used a 'wimp out' solution:
>
>     function KB_Hit return Boolean;
>     pragma Import(KB_Hit, "kbhit"); --not sure of the syntax
>     ...
>        exit when KB_Hit;
>     ...
>    (of course you have to remember to Flush or equiv)
>
> Not pretty, but it worked.
>
I would love to use this but it turns out that kbhit is a Windows
thing and possibly a Borland thing. And I'm on OS X. Seems Unix/Linux
doesn't have an equivalent which strikes me as odd. But I found an
implementation for Linux here:

http://www.pwilson.net/kbhit.html

I might give it a whirl.

Jerry

Jerry
> --BrianG
>
>         --I'm in a groove now -
>         -- Or is it a rut?




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

* Re: How to exit a loop with keyboard input
  2010-04-15 19:22             ` Simon Wright
@ 2010-04-16 10:25               ` Jerry
  0 siblings, 0 replies; 23+ messages in thread
From: Jerry @ 2010-04-16 10:25 UTC (permalink / raw)


On Apr 15, 12:22 pm, Simon Wright <si...@pushface.org> wrote:
> The SourceForge Leopard GNAT GPL 2009 compiler is 32-bit, while
> AdaCore's is 64-bit.
>
> I had a Leopard issue, where libtk was a thin library supporting only
> 32-bit, so I got the sort of problem you report when using AdaCore's
> compiler.
>
> Are you getting the problem with both compilers? if so, I'd expect each
> compiler to report the problem with different libraries. And your only
> recourse will be to rebuild the offending libraries with the appropriate
> compiler. What I've done is to use the matching GNAT compiler; eg for
> 64-bit,
>
> $ PATH=/opt/gnat-gpl-2009-x86_64/bin:$PATH
> $ ./configure ....
> $ make
>
> Given that most people don't build GNAT with c++, this is only going to
> work if the library concerned is C-based.
>
> You can find what architectures a library supports using lipo (-info or
> -detailed_info)

Thanks for the architecture tip. I get the problem with only the
AdaCore 64-bit compiler.

[I have another problem when using your 32-bit compiler from
Sourceforge but it's not actually a compiler problem--something goes
wrong when the PLplot build system tries to locate a compiler library:
dyld: Library not loaded: @rpath/libgnat-2009.dylib
Funny thing is, that library (or at least a symlink pointing to it) is
found earlier in the build process.]

But back to the architecture problem.  ld tries to ascertain the
architecture of the output (in some cases) by looking at the
architecture of the first-listed library. In this case, that is a 32-
bit PLplot library which points to a problem in the PLplot build
process. I've sent my findings to the PLplot guys. Also, they are
attempting to link the Carbon framework in the same command which of
course is a no-no because Carbon is 32 bits.

Jerry



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

* Re: How to exit a loop with keyboard input
  2010-04-16  4:43                   ` Simon Wright
@ 2010-04-16 14:03                     ` John B. Matthews
  0 siblings, 0 replies; 23+ messages in thread
From: John B. Matthews @ 2010-04-16 14:03 UTC (permalink / raw)


In article <m2zl1480t1.fsf@pushface.org>,
 Simon Wright <simon@pushface.org> wrote:

> The installed .ali files should be made read-only (which may mean adding
> -f to the cp, rm calls).
> 
> Not sure about the uninstall target -- shouldn't the original be
> replaced, if there was one?

You're right; thanks for commenting on this. I originally used the 
target to be sure I wasn't inadvertently mixing old and new. In 
practice, I use tar -zxv or svn revert to start fresh; but that seems 
outside the scope of a makefile. I should at least rename the target, or 
get rid of it outright.

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



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

end of thread, other threads:[~2010-04-16 14:03 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-12  4:12 How to exit a loop with keyboard input Jerry
2010-04-12  8:50 ` Georg Bauhaus
2010-04-12  9:21   ` Manuel Collado
2010-04-12 10:36 ` Jerry
2010-04-12 13:59   ` John McCormick
2010-04-13 19:38     ` Jerry
2010-04-12 15:14   ` Tero Koskinen
2010-04-12 16:16     ` John B. Matthews
2010-04-12 20:04     ` Simon Wright
2010-04-13 19:51       ` Jerry
2010-04-13 21:22         ` Simon Wright
2010-04-15  3:39           ` Jerry
2010-04-15  4:08             ` John B. Matthews
2010-04-15 18:51               ` Jerry
2010-04-16  0:44                 ` John B. Matthews
2010-04-16  4:43                   ` Simon Wright
2010-04-16 14:03                     ` John B. Matthews
2010-04-15 19:22             ` Simon Wright
2010-04-16 10:25               ` Jerry
2010-04-12 20:57 ` Alex Mentis
2010-04-12 22:51   ` Jerry
2010-04-16  0:06     ` BrianG
2010-04-16  7:23       ` Jerry

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