www.digitalmars.com         C & C++   DMDScript  

D - signals

reply "Carlos Santander B." <carlos8294 msn.com> writes:
Hi, are there any plans to support signals? I mean, something to handle
interrupts and such. Or is something already there? The only way I know to
do that is (in C) with signal(), but is it doable in D? By the way, if
Windows doesn't send SIGINT to programs, how can I handle Ctrl+C?

-------------------------
Carlos Santander


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25
Mar 27 2003
parent reply "Jon Allen" <jallen minotstateu.edu> writes:
I don't know if catching ctrl+c is such a good idea in windows, at least not
if you are planning on using it in the same way it's used in the command
line.  I think people would get annoyed if their program closed everytime
they went to copy a bit of text.
That being said, the best way I know how to do it is to use the
RegisterHotKey function, then handle the WM_HOTKEY message.

i've made a quick and dirty port of signal.h and included it.  put it in
dmd\src\phobos\c, then use it like this:

/+
you probably know how to do this already, but just in case you get bitten by
the extern (C) bit like I did <slaps forehead> :-)
+/

import c.signal;

void main()
{
    signal(SIGINT, &blah);
    while(1)
    {
    }
}

extern (C) void blah(int sig)
{
    printf("bye");
    raise(SIGTERM);
}


"Carlos Santander B." <carlos8294 msn.com> wrote in message
news:b5vo8h$2ben$1 digitaldaemon.com...
 Hi, are there any plans to support signals? I mean, something to handle
 interrupts and such. Or is something already there? The only way I know to
 do that is (in C) with signal(), but is it doable in D? By the way, if
 Windows doesn't send SIGINT to programs, how can I handle Ctrl+C?

 -------------------------
 Carlos Santander


 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25
Mar 27 2003
next sibling parent reply "Jon Allen" <jallen minotstateu.edu> writes:
uh, oops, this time i'm including it :-)

"Jon Allen" <jallen minotstateu.edu> wrote in message
news:b60dj5$2stv$1 digitaldaemon.com...
 I don't know if catching ctrl+c is such a good idea in windows, at least
not
 if you are planning on using it in the same way it's used in the command
 line.  I think people would get annoyed if their program closed everytime
 they went to copy a bit of text.
 That being said, the best way I know how to do it is to use the
 RegisterHotKey function, then handle the WM_HOTKEY message.

 i've made a quick and dirty port of signal.h and included it.  put it in
 dmd\src\phobos\c, then use it like this:

 /+
 you probably know how to do this already, but just in case you get bitten
by
 the extern (C) bit like I did <slaps forehead> :-)
 +/

 import c.signal;

 void main()
 {
     signal(SIGINT, &blah);
     while(1)
     {
     }
 }

 extern (C) void blah(int sig)
 {
     printf("bye");
     raise(SIGTERM);
 }


 "Carlos Santander B." <carlos8294 msn.com> wrote in message
 news:b5vo8h$2ben$1 digitaldaemon.com...
 Hi, are there any plans to support signals? I mean, something to handle
 interrupts and such. Or is something already there? The only way I know
to
 do that is (in C) with signal(), but is it doable in D? By the way, if
 Windows doesn't send SIGINT to programs, how can I handle Ctrl+C?

 -------------------------
 Carlos Santander


 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25
begin 666 signal.d M/3$U.PT*8V]N<W0 :6YT(%-)1T)214%+/3(Q.PT*8V]N<W0 :6YT(%-)1T%" M9 T*8V]N<W0 <VEG9G5N8R!324=?1$9,/6-A<W0H<VEG9G5N8RDP.PT*8V]N M<W0 <VEG9G5N8R!324=?24=./6-A<W0H<VEG9G5N8RDQ.PT*8V]N<W0 <VEG M9G5N8R!324=?4T=%/6-A<W0H<VEG9G5N8RDS.PT*8V]N<W0 <VEG9G5N8R!3 M24=?04-+/6-A<W0H<VEG9G5N8RDT.PT*8V]N<W0 <VEG9G5N8R!324=?15)2 M/6-A<W0H<VEG9G5N8RDM,3L-" T*+RH 1G5N8W1I;VX <')O=&]T>7!E<R J M+PT*<VEG9G5N8R!S:6=N86PH:6YT('-I9RP <VEG9G5N8R!H86YD;&5R*3L- ;"FEN="!R86ES92AI;G0 <VEG*3L-" T*?0T* ` end
Mar 27 2003
parent reply "Carlos Santander B." <carlos8294 msn.com> writes:
"Jon Allen" <jallen minotstateu.edu> escribiσ en el mensaje
news:b60dl6$2sv1$1 digitaldaemon.com...
| uh, oops, this time i'm including it :-)
|

Thanks! This works just fine for me.

—————————————————————————
Carlos Santander
"Jon Allen" <jallen minotstateu.edu> escribiσ en el mensaje
news:b60dl6$2sv1$1 digitaldaemon.com...
| uh, oops, this time i'm including it :-)
|

Thanks! This works just fine for me.

—————————————————————————
Carlos Santander
Mar 27 2003
parent "Jon Allen" <jallen minotstateu.edu> writes:
Glad to hear it.

"Carlos Santander B." <carlos8294 msn.com> wrote in message
news:b60kik$31hq$1 digitaldaemon.com...
 "Jon Allen" <jallen minotstateu.edu> escribiσ en el mensaje
 news:b60dl6$2sv1$1 digitaldaemon.com...
 | uh, oops, this time i'm including it :-)
 |

 Thanks! This works just fine for me.

 -------------------------
 Carlos Santander
 "Jon Allen" <jallen minotstateu.edu> escribiσ en el mensaje
 news:b60dl6$2sv1$1 digitaldaemon.com...
 | uh, oops, this time i'm including it :-)
 |

 Thanks! This works just fine for me.

 -------------------------
 Carlos Santander
Mar 27 2003
prev sibling parent "Carlos Santander B." <carlos8294 msn.com> writes:
"Jon Allen" <jallen minotstateu.edu> escribiσ en el mensaje
news:b60dj5$2stv$1 digitaldaemon.com...
| I don't know if catching ctrl+c is such a good idea in windows, at least
not
| if you are planning on using it in the same way it's used in the command
| line.  I think people would get annoyed if their program closed everytime
| they went to copy a bit of text.
|

Well, yes that's what I want: for a console application. (probably I
should've specified that before)

—————————————————————————
Carlos Santander


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25
Mar 27 2003