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:52 PST Path: nntp.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newshub2.home.com!news.home.com!news1.sttls1.wa.home.com.POSTED!not-for-mail From: "DuckE" Newsgroups: comp.lang.ada References: <3AADFFCF.691F1F8@labe.felk.cvut.cz> Subject: Re: Handling signals in ADA X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Message-ID: Date: Thu, 15 Mar 2001 05:21:10 GMT NNTP-Posting-Host: 24.6.221.63 X-Complaints-To: abuse@home.net X-Trace: news1.sttls1.wa.home.com 984633670 24.6.221.63 (Wed, 14 Mar 2001 21:21:10 PST) NNTP-Posting-Date: Wed, 14 Mar 2001 21:21:10 PST Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: nntp.stanford.edu comp.lang.ada:91469 Date: 2001-03-15T05:21:10+00:00 List-Id: Yes, here it is, but that's probably not what you really want to do. WITH Signal_Handler_Package; PROCEDURE SignalTest IS BEGIN Signal_Handler_Package.Test_Signal; END SignalTest; PACKAGE Signal_Handler_Package IS PROCEDURE Test_Signal; END Signal_Handler_Package; with Ada.Text_Io; with Ada.Integer_Text_Io; package body Signal_Handler_Package is Stop : Integer := 0; pragma Atomic( Stop ); sigusr1 : constant := 1; type Handler_Procedure is access procedure( Signo : Integer ); pragma Convention( C, Handler_Procedure ); procedure Signal ( Sig_Type : Integer; handler_access : Handler_Procedure ); pragma Import( C, Signal ); procedure Handler ( Signo : Integer ); pragma Convention( C, Handler); procedure Handler ( Signo : Integer ) is begin Stop := 1; Ada.Text_Io.Put( "Signal " ); Ada.Integer_Text_Io.Put( Signo ); Ada.Text_Io.Put_Line( " received" ); end Handler; procedure Test_Signal is begin Signal( Sigusr1, Handler'access ); while Stop = 0 loop null; end loop; end Test_Signal; end Signal_Handler_Package; I don't know the correct definition for sigusr1, so I made one up just to get the code to build. But as I mentioned, this most likely isn't what you want to do since Ada has protected types and tasking built into the language for performing functions of this nature. The above example does however illustrate that if you want to do it the 'C' way in Ada, you can. SteveD "Tomas Hlavaty" wrote in message news:3AADFFCF.691F1F8@labe.felk.cvut.cz... > Hi, could you help me with translating following C code to ADA? > > -- My C program is: > > #include > > int stop = 0; > > void handler(int signo) > { > stop = 1; > printf("Signal %i received\n", signo); > } > > int main() > { > signal(SIGUSR1, handler); > while (stop == 0); > return 0; > } > > -- How to translate it to ADA? > > Thanks > > Tomas