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

 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

 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


 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 "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