From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b42257070cad7d43 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-17 01:38:53 PST Path: nntp.stanford.edu!newsfeed.stanford.edu!paloalto-snf1.gtei.net!news.gtei.net!newsfeed.attap.net!enews.sgi.com!telocity-west!TELOCITY!newsrump.sjc.telocity.net!not-for-mail From: "David C. Hoos, Sr." Newsgroups: comp.lang.ada References: <3AADFFCF.691F1F8@labe.felk.cvut.cz> <87y9u6k7s6.fsf@deneb.enyo.de> Subject: Re: Handling signals in ADA MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: X-Trace: 0dvIpoepnZyAvZuNmsi8raSnq6G8scW6ramsrbq7yNrZ3sba2t/G3N/G3NHIyLyAncTI2d3IpYma!yNrY2NnI2d/S2t/S2tjIuLu8 X-Abuse-Info: Please forward ALL headers when reporting abuse. X-Complaints-To: abuse@telocity.net NNTP-Posting-Date: Thu, 15 Mar 2001 17:27:20 PST Date: Thu, 15 Mar 2001 19:27:21 -0600 Xref: nntp.stanford.edu comp.lang.ada:91500 Date: 2001-03-15T19:27:21-06:00 List-Id: "Florian Weimer" wrote in message news:87y9u6k7s6.fsf@deneb.enyo.de... > Tomas Hlavaty writes: > > > Hi, could you help me with translating following C code to ADA? > > The programming language is called 'Ada'. > > > -- How to translate it to ADA? > > The standard Ada library does not support signals. Typical Ada > programs use other communication mechanisms, and a verbatim > translation is not possible. If you need signal handling because it's > required by your environment, have a look at POSIX.5. This answer is just plain wrong. The following program demonstrates the use of signals in Ada, using only language-defined units. Now. to be sure, because Ada restricts interrupt handlers to being parameterless protected procedures, it is not possible to pass parameter like what can be done under UNIX with the standard C runtime, for example. But the "standard Ada library" _DOES_ support signals. -- begin source code package body Signal_Handlers is SIG_INT_Received : Boolean := False; function SIGINT_RECEIVED return BOOLEAN is begin return SIG_INT_Received; end SIGINT_Received; protected body Signals is procedure Handle_SIGINT is begin Ada.Text_IO.Put_Line ("SIGINT received..; Terminating."); SIG_INT_Received := True; end Handle_SIGINT; procedure Handle_SIGUSR1 is begin Ada.Text_IO.Put_Line ("SIGUSR1 received and handled."); end Handle_SIGUSR1; procedure Handle_SIGUSR2 is begin Ada.Text_IO.Put_Line ("SIGUSR2 received and handled."); end Handle_SIGUSR2; end Signals; end Signal_Handlers; with Ada.Interrupts.Names; with Ada.Text_IO; package Signal_Handlers is pragma Unreserve_All_Interrupts; function SIGINT_Received return Boolean; protected Signals is procedure Handle_SIGINT; procedure Handle_SIGUSR1; procedure Handle_SIGUSR2; private pragma Attach_Handler (Handle_SIGINT, Ada.Interrupts.Names.SIGINT); pragma Attach_Handler (Handle_SIGUSR1, Ada.Interrupts.Names.SIGUSR1); pragma Attach_Handler (Handle_SIGUSR2, Ada.Interrupts.Names.SIGUSR2); end Signals; end Signal_Handlers; with Ada.Text_IO; with Signal_Handlers; procedure Test_Signal_Handler is begin loop exit when Signal_Handlers.SIGINT_Received; Ada.Text_IO.Put_Line ("I'm alive..."); delay 1.0; end loop; end Test_Signal_Handler; .