Re: [fpc-pascal] How to use the `signals` unit?
On Fri, Oct 23, 2015 at 3:05 AM, Sven Barthwrote: > Am 23.10.2015 06:29 schrieb "silvioprog" : > > > > On Thu, Oct 22, 2015 at 6:40 AM, Sven Barth > wrote: > >> > >> Am 22.10.2015 09:23 schrieb "silvioprog" : > >> > What is the secret to use this it on Windows? > >> > >> The secret is to not use it. It's only real use is in the textmode IDE > and maybe there it should be checked whether it can be replaced. > > > > So is there some alternative for signals? ( SetConsoleCtrlHandler() on > Windows, but, what in Linux? ) > > > > Currently you need to do this for each platform separately. > It isn't a problem for me, because my app needs to run just on Windows and Linux. =) -- Silvio Clécio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to use the `signals` unit?
Am 23.10.2015 06:29 schrieb "silvioprog": > > On Thu, Oct 22, 2015 at 6:40 AM, Sven Barth wrote: >> >> Am 22.10.2015 09:23 schrieb "silvioprog" : >> > What is the secret to use this it on Windows? >> >> The secret is to not use it. It's only real use is in the textmode IDE and maybe there it should be checked whether it can be replaced. > > So is there some alternative for signals? ( SetConsoleCtrlHandler() on Windows, but, what in Linux? ) > Currently you need to do this for each platform separately. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to use the `signals` unit?
Oops ... On Wed, Oct 21, 2015 at 3:12 PM, silvioprogwrote: > What is the secret to use this it on Windows? > I meant: "... to use it on Windows ..". -- Silvio Clécio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] How to use the `signals` unit?
Hello, What is the secret to use this it on Windows? I have the following example in C: begin code === #include #include #include void sigproc() { printf("You have pressed Ctrl-C\n"); exit(0); } main() { signal(SIGINT, sigproc); printf("Use Ctrl-C to quit\n"); for(;;); } end code === So when I use the Ctrl+C command I get the "You have pressed Ctrl-C" in the terminal. However, using this code (compiled in FPC from trunk): begin code === program project1; {$mode objfpc}{$H+} uses signals; function sigproc(v: LongInt): longint; cdecl; begin WriteLn('You have pressed Ctrl-C'); Result := v; Halt(0); end; begin signal(SIGINT, @sigproc); WriteLn('Use Ctrl-C to quit'); while true do ; end. end code === It doesn't work. :-( The program quits, but I can't get the "You have pressed Ctrl-C". I can use the `Windows.SetConsoleCtrlHandler()`, but I would be happy to understand how to use the `signals` unit. =) -- Silvio Clécio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to use the `signals` unit?
Am 22.10.2015 09:23 schrieb "silvioprog": > What is the secret to use this it on Windows? The secret is to not use it. It's only real use is in the textmode IDE and maybe there it should be checked whether it can be replaced. AFAIR the signals unit is even completely broken if SEH is enabled (default on x86_64-win64, but to be made default on i386-win32). Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to use the `signals` unit?
On Thu, Oct 22, 2015 at 6:40 AM, Sven Barthwrote: > Am 22.10.2015 09:23 schrieb "silvioprog" : > > What is the secret to use this it on Windows? > > The secret is to not use it. It's only real use is in the textmode IDE and > maybe there it should be checked whether it can be replaced. > So is there some alternative for signals? ( SetConsoleCtrlHandler() on Windows, but, what in Linux? ) I have a console application, and I need to block the `Ctrl+C` command, allowing only the `Ctrl+\` (or Ctrl+Break on Windows). See a small example (*) that works fine on Windows (7 / 10) and Linux (*ubuntu 14.04). The original demo was written in C and is hosted here[1]. > AFAIR the signals unit is even completely broken if SEH is enabled > (default on x86_64-win64, but to be made default on i386-win32). > > Regards, > Sven > (*) === begin code === program project1; {$mode objfpc}{$H+} uses {$IFDEF UNIX} BaseUnix, {$ENDIF} ctypes, sysutils; const LIB_NAME = {$IFDEF MSWINDOWS}'msvcrt'{$ELSE}'c'{$ENDIF}; {$IFDEF MSWINDOWS} SIGINT = 2; SIGILL = 4; SIGFPE = 8; SIGSEGV = 11; SIGTERM = 15; SIGBREAK = 21; SIGABRT = 22; {$ENDIF} type signal_func = procedure(sig: cint); cdecl; function signal(sig: cint; func: signal_func): signal_func; cdecl; external LIB_NAME Name 'signal'; procedure sigproc(sig: cint); cdecl; begin signal(SIGINT, @sigproc); WriteLn('you have pressed ctrl-c'); end; procedure quitproc(sig: cint); cdecl; begin WriteLn('ctrl+break (or ctrl+\ on linux) pressed to quit'); halt(0); end; begin signal(SIGINT, @sigproc); {$IFDEF MSWINDOWS} signal(SIGBREAK, @quitproc); {$ELSE} signal(SIGTERM, @quitproc); {$ENDIF} WriteLn('ctrl-c disabled use ctrl+break (or ctrl+\ on linux) to quit'); while True do Sleep(100); end. === end code === [1] https://www.cs.cf.ac.uk/Dave/C/node24.html -- Silvio Clécio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal