Compare commits
2 Commits
5ec23566db
...
e8d1a179d6
| Author | SHA1 | Date | |
|---|---|---|---|
| e8d1a179d6 | |||
| a83e85cc09 |
39
README.md
39
README.md
@@ -45,7 +45,7 @@ The library is stable, portable, and designed for projects that need a scripting
|
||||
- [@include and @include\_once](#include-and-include_once)
|
||||
- [Comments](#comments)
|
||||
- [Reserved Words](#reserved-words)
|
||||
- [More Examples](#more-examples)
|
||||
- [Some Examples](#some-examples)
|
||||
- [Garbage Collection](#garbage-collection)
|
||||
- [Modules](#modules)
|
||||
- [Hawk](#hawk)
|
||||
@@ -1012,6 +1012,29 @@ The `sys` module provides various functions concerning the underlying operation
|
||||
- sys::wait
|
||||
- sys::write
|
||||
|
||||
#### Signals
|
||||
|
||||
Use these to register handlers and raise signals from Hawk.
|
||||
|
||||
- sys::signal(sig, func) sets a handler function for a signal number. pass nil to clear it.
|
||||
- sys::raise(sig) raises a signal to the current runtime.
|
||||
- sys::kill(pid, sig) sends a signal to another process or to self.
|
||||
|
||||
Example:
|
||||
|
||||
```awk
|
||||
function on_int(sig) { print "got", sig }
|
||||
|
||||
BEGIN {
|
||||
sys::signal(sys::SIGINT, on_int);
|
||||
sys::raise(sys::SIGINT);
|
||||
## sys::kill(sys::getpid(), sys::SIGINT);
|
||||
sys::signal(sys::SIGINT, @nil);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### Raw byte reads
|
||||
|
||||
You may read the file in raw bytes.
|
||||
|
||||
@@ -1025,6 +1048,8 @@ BEGIN {
|
||||
}
|
||||
```
|
||||
|
||||
#### Wrap a file descriptor
|
||||
|
||||
You can map a raw file descriptor to a handle created by this module and use it.
|
||||
|
||||
```awk
|
||||
@@ -1037,6 +1062,8 @@ BEGIN {
|
||||
}
|
||||
```
|
||||
|
||||
#### Pipe to a child process
|
||||
|
||||
Creating pipes and sharing them with a child process is not big an issue.
|
||||
|
||||
```awk
|
||||
@@ -1091,6 +1118,8 @@ BEGIN {
|
||||
}
|
||||
```
|
||||
|
||||
#### Read child stdout
|
||||
|
||||
You can read standard output of a child process in a parent process.
|
||||
|
||||
```awk
|
||||
@@ -1142,6 +1171,8 @@ BEGIN {
|
||||
}
|
||||
```
|
||||
|
||||
#### Duplicate file handles
|
||||
|
||||
You can duplicate file handles as necessary.
|
||||
|
||||
```awk
|
||||
@@ -1165,6 +1196,8 @@ BEGIN {
|
||||
}
|
||||
```
|
||||
|
||||
#### Directory traversal
|
||||
|
||||
Directory traversal is easy.
|
||||
|
||||
```awk
|
||||
@@ -1183,6 +1216,8 @@ BEGIN {
|
||||
}
|
||||
```
|
||||
|
||||
#### Network interface info
|
||||
|
||||
You can get information of a network interface.
|
||||
|
||||
```awk
|
||||
@@ -1194,6 +1229,8 @@ BEGIN {
|
||||
}
|
||||
```
|
||||
|
||||
#### Sockets
|
||||
|
||||
Socket functions are available.
|
||||
|
||||
```awk
|
||||
|
||||
14
bin/hawk.c
14
bin/hawk.c
@@ -341,7 +341,14 @@ static void on_sigset (hawk_rtx_t* rtx, int sig, hawk_fun_t* fun)
|
||||
else
|
||||
{
|
||||
int back_to_stop_run = 0;
|
||||
hawk_main_unset_signal_handler(sig);
|
||||
|
||||
#if defined(SIGPIPE)
|
||||
if (sig == SIGPIPE)
|
||||
{
|
||||
set_intr_pipe(); // to application default. not OS default.
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if defined(SIGTERM)
|
||||
if (sig == SIGTERM) back_to_stop_run = 1;
|
||||
#endif
|
||||
@@ -351,7 +358,10 @@ static void on_sigset (hawk_rtx_t* rtx, int sig, hawk_fun_t* fun)
|
||||
#if defined(SIGINT)
|
||||
if (sig == SIGINT) back_to_stop_run = 1;
|
||||
#endif
|
||||
if (back_to_stop_run) hawk_main_set_signal_handler(sig, stop_run, 0);
|
||||
if (back_to_stop_run)
|
||||
hawk_main_set_signal_handler(sig, stop_run, 0);
|
||||
else
|
||||
hawk_main_unset_signal_handler(sig);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ func run_script(h *hawk.Hawk, fs_idx int, data_idx int, cfg* Config, rtx_chan ch
|
||||
}
|
||||
}
|
||||
|
||||
rtx.SetSigsetHandler(func(rtx *hawk.Rtx, signo int, reset bool) {
|
||||
rtx.OnSigset(func(rtx *hawk.Rtx, signo int, reset bool) {
|
||||
var s os.Signal
|
||||
s = syscall.Signal(signo)
|
||||
if reset {
|
||||
@@ -229,7 +229,7 @@ func run_script(h *hawk.Hawk, fs_idx int, data_idx int, cfg* Config, rtx_chan ch
|
||||
args[idx].Close()
|
||||
}
|
||||
} else {
|
||||
rtx.SetSigsetHandler(func(rtx *hawk.Rtx, signo int, reset bool) {
|
||||
rtx.OnSigset(func(rtx *hawk.Rtx, signo int, reset bool) {
|
||||
var s os.Signal
|
||||
s = syscall.Signal(signo)
|
||||
if reset {
|
||||
|
||||
8
hawk.go
8
hawk.go
@@ -632,7 +632,7 @@ func (rtx* Rtx) Halt() {
|
||||
C.hawk_rtx_halt(rtx.c)
|
||||
}
|
||||
|
||||
func (rtx *Rtx) SetSigsetHandler(f RtxSigsetHandler) {
|
||||
func (rtx *Rtx) OnSigset(f RtxSigsetHandler) {
|
||||
rtx.sigset_handler = f
|
||||
}
|
||||
|
||||
@@ -814,6 +814,8 @@ func (rtx *Rtx) GetNamedVars(vars map[string]*Val) {
|
||||
|
||||
//export hawk_go_sigset_handler
|
||||
func hawk_go_sigset_handler(rtx_xtn *C.rtx_xtn_t, sig C.int, reset C.int) {
|
||||
// this handler is called when sys::signal() is invoked in a script.
|
||||
|
||||
//var inst HawkInstance
|
||||
var rtx_inst RtxInstance
|
||||
var rtx *Rtx
|
||||
@@ -822,7 +824,9 @@ func hawk_go_sigset_handler(rtx_xtn *C.rtx_xtn_t, sig C.int, reset C.int) {
|
||||
rtx_inst = rtx_inst_table.slot_to_instance(int(rtx_xtn.rtx_inst_no))
|
||||
rtx = rtx_inst.g.Value()
|
||||
|
||||
rtx.sigset_handler(rtx, int(sig), reset != 0)
|
||||
if rtx.sigset_handler != nil {
|
||||
rtx.sigset_handler(rtx, int(sig), reset != 0)
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
51
lib/Hawk.cpp
51
lib/Hawk.cpp
@@ -132,6 +132,17 @@ static HAWK_INLINE rxtn_t* GET_RXTN(hawk_rtx_t* rtx) { return (rxtn_t*)((hawk_ui
|
||||
#define GET_RXTN(rtx) ((rxtn_t*)((hawk_uint8_t*)hawk_rtx_getxtn(rtx) - HAWK_SIZEOF(rxtn_t)))
|
||||
#endif
|
||||
|
||||
static void rtx_on_sigset (hawk_rtx_t* rtx, int sig, hawk_fun_t* fun)
|
||||
{
|
||||
rxtn_t* rxtn = GET_RXTN(rtx);
|
||||
Hawk::Run* run = rxtn->run;
|
||||
if (run)
|
||||
{
|
||||
Hawk* hawk = (Hawk*)*run; // call operator Hawk*
|
||||
if (hawk) hawk->uponSigset(*run, sig, fun == HAWK_NULL);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Hawk::Pipe
|
||||
//////////////////////////////////////////////////////////////////
|
||||
@@ -1881,7 +1892,7 @@ int Hawk::open ()
|
||||
HAWK_HTB_SIZER_DEFAULT,
|
||||
HAWK_HTB_HASHER_DEFAULT
|
||||
};
|
||||
hawk_htb_setstyle (this->functionMap, &style);
|
||||
hawk_htb_setstyle(this->functionMap, &style);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1935,6 +1946,11 @@ void Hawk::uponClearing ()
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
void Hawk::uponSigset (Run& run, int sig, bool reset)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
Hawk::Run* Hawk::parse (Source& in, Source& out)
|
||||
{
|
||||
HAWK_ASSERT(this->hawk != HAWK_NULL);
|
||||
@@ -1981,7 +1997,7 @@ int Hawk::loop (Value* ret)
|
||||
HAWK_ASSERT(this->hawk != HAWK_NULL);
|
||||
HAWK_ASSERT(this->runctx.rtx != HAWK_NULL);
|
||||
|
||||
hawk_val_t* rv = hawk_rtx_loop (this->runctx.rtx);
|
||||
hawk_val_t* rv = hawk_rtx_loop(this->runctx.rtx);
|
||||
if (rv == HAWK_NULL)
|
||||
{
|
||||
this->retrieveError(&this->runctx);
|
||||
@@ -2010,7 +2026,7 @@ int Hawk::call (const hawk_bch_t* name, Value* ret, const Value* args, hawk_oow_
|
||||
ptr = (hawk_val_t**)hawk_allocmem(this->hawk, HAWK_SIZEOF(hawk_val_t*) * nargs);
|
||||
if (ptr == HAWK_NULL)
|
||||
{
|
||||
this->runctx.setError (HAWK_ENOMEM);
|
||||
this->runctx.setError(HAWK_ENOMEM);
|
||||
this->retrieveError(&this->runctx);
|
||||
return -1;
|
||||
}
|
||||
@@ -2096,6 +2112,12 @@ void Hawk::halt ()
|
||||
hawk_haltall (this->hawk);
|
||||
}
|
||||
|
||||
int Hawk::raiseSignal (int sig)
|
||||
{
|
||||
if (this->runctx.rtx) return hawk_rtx_raisesig(this->runctx.rtx, sig);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Hawk::init_runctx ()
|
||||
{
|
||||
if (this->runctx.rtx) return 0;
|
||||
@@ -2118,6 +2140,9 @@ int Hawk::init_runctx ()
|
||||
|
||||
rxtn_t* rxtn = GET_RXTN(rtx);
|
||||
rxtn->run = &this->runctx;
|
||||
HAWK_MEMSET(&this->runctx.rtx_ecb, 0, HAWK_SIZEOF(this->runctx.rtx_ecb));
|
||||
this->runctx.rtx_ecb.sigset = rtx_on_sigset;
|
||||
hawk_rtx_pushecb(rtx, &this->runctx.rtx_ecb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2142,7 +2167,7 @@ int Hawk::getTrait () const
|
||||
void Hawk::setTrait (int trait)
|
||||
{
|
||||
HAWK_ASSERT(this->hawk != HAWK_NULL);
|
||||
hawk_setopt (this->hawk, HAWK_OPT_TRAIT, &trait);
|
||||
hawk_setopt(this->hawk, HAWK_OPT_TRAIT, &trait);
|
||||
}
|
||||
|
||||
hawk_oow_t Hawk::getMaxDepth (depth_t id) const
|
||||
@@ -2157,7 +2182,7 @@ hawk_oow_t Hawk::getMaxDepth (depth_t id) const
|
||||
void Hawk::setMaxDepth (depth_t id, hawk_oow_t depth)
|
||||
{
|
||||
HAWK_ASSERT(this->hawk != HAWK_NULL);
|
||||
hawk_setopt (this->hawk, (hawk_opt_t)id, &depth);
|
||||
hawk_setopt(this->hawk, (hawk_opt_t)id, &depth);
|
||||
}
|
||||
|
||||
int Hawk::setIncludeDirs (const hawk_uch_t* dirs)
|
||||
@@ -2179,11 +2204,11 @@ int Hawk::setIncludeDirs (const hawk_bch_t* dirs)
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
hawk_ooch_t* tmp;
|
||||
tmp = hawk_dupbtoucstr(hawk, dirs, HAWK_NULL, 1);
|
||||
tmp = hawk_dupbtoucstr(this->hawk, dirs, HAWK_NULL, 1);
|
||||
if (HAWK_UNLIKELY(!tmp)) return -1;
|
||||
|
||||
int n = hawk_setopt(hawk, HAWK_OPT_INCLUDEDIRS, tmp);
|
||||
hawk_freemem(hawk, tmp);
|
||||
int n = hawk_setopt(this->hawk, HAWK_OPT_INCLUDEDIRS, tmp);
|
||||
hawk_freemem(this->hawk, tmp);
|
||||
return n;
|
||||
#else
|
||||
return hawk_setopt(this->hawk, HAWK_OPT_INCLUDEDIRS, dirs);
|
||||
@@ -2539,7 +2564,7 @@ int Hawk::getGlobal (int id, Value& v)
|
||||
HAWK_ASSERT(this->hawk != HAWK_NULL);
|
||||
HAWK_ASSERT(runctx.rtx != HAWK_NULL);
|
||||
|
||||
int n = runctx.getGlobal (id, v);
|
||||
int n = runctx.getGlobal(id, v);
|
||||
if (n <= -1) this->retrieveError();
|
||||
return n;
|
||||
}
|
||||
@@ -2576,7 +2601,7 @@ int Hawk::addFunction (
|
||||
hawk_htb_pair_t* pair = hawk_htb_upsert(this->functionMap, (hawk_ooch_t*)fnc->name.ptr, fnc->name.len, &handler, HAWK_SIZEOF(handler));
|
||||
if (!pair)
|
||||
{
|
||||
hawk_delfncwithbcstr (this->hawk, name);
|
||||
hawk_delfncwithbcstr(this->hawk, name);
|
||||
this->retrieveError();
|
||||
return -1;
|
||||
}
|
||||
@@ -2586,7 +2611,7 @@ int Hawk::addFunction (
|
||||
catch (...) { pair = HAWK_NULL; }
|
||||
if (!pair)
|
||||
{
|
||||
hawk_delfncwithbcstr (this->hawk, name);
|
||||
hawk_delfncwithbcstr(this->hawk, name);
|
||||
this->setError(HAWK_ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
@@ -2627,7 +2652,7 @@ int Hawk::addFunction (
|
||||
hawk_htb_pair_t* pair = hawk_htb_upsert(this->functionMap, (hawk_ooch_t*)fnc->name.ptr, fnc->name.len, &handler, HAWK_SIZEOF(handler));
|
||||
if (HAWK_UNLIKELY(!pair))
|
||||
{
|
||||
hawk_delfncwithucstr (this->hawk, name);
|
||||
hawk_delfncwithucstr(this->hawk, name);
|
||||
this->retrieveError();
|
||||
return -1;
|
||||
}
|
||||
@@ -2637,7 +2662,7 @@ int Hawk::addFunction (
|
||||
catch (...) { pair = HAWK_NULL; }
|
||||
if (HAWK_UNLIKELY(!pair))
|
||||
{
|
||||
hawk_delfncwithucstr (this->hawk, name);
|
||||
hawk_delfncwithucstr(this->hawk, name);
|
||||
this->setError(HAWK_ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1330,6 +1330,7 @@ public:
|
||||
protected:
|
||||
Hawk* hawk;
|
||||
hawk_rtx_t* rtx;
|
||||
hawk_rtx_ecb_t rtx_ecb;
|
||||
};
|
||||
|
||||
///
|
||||
@@ -1389,6 +1390,11 @@ public:
|
||||
///
|
||||
virtual void uponClearing ();
|
||||
|
||||
/// The uponSigset() function is called back when sys::signal()
|
||||
/// attempts to set or unset a signal handler. This maps to the
|
||||
/// sigset callback of #hawk_rtx_ecb_t.
|
||||
virtual void uponSigset (Run& run, int sig, bool reset);
|
||||
|
||||
///
|
||||
/// The parse() function parses the source code read from the input
|
||||
/// stream \a in and writes the parse tree to the output stream \a out.
|
||||
@@ -1477,6 +1483,7 @@ public:
|
||||
/// The halt() function makes request to abort execution
|
||||
///
|
||||
void halt ();
|
||||
int raiseSignal (int sig);
|
||||
/// \}
|
||||
|
||||
///
|
||||
|
||||
48
lib/Std.cpp
48
lib/Std.cpp
@@ -172,7 +172,7 @@ int HawkStd::open ()
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
Hawk::close ();
|
||||
Hawk::close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -180,11 +180,11 @@ void HawkStd::close ()
|
||||
{
|
||||
if (this->cmgrtab_inited)
|
||||
{
|
||||
hawk_htb_fini (&this->cmgrtab);
|
||||
hawk_htb_fini(&this->cmgrtab);
|
||||
this->cmgrtab_inited = false;
|
||||
}
|
||||
|
||||
clearConsoleOutputs ();
|
||||
clearConsoleOutputs();
|
||||
|
||||
//
|
||||
// HawkStd called hawk_stdmodstartup() after Hawk::open().
|
||||
@@ -198,12 +198,12 @@ void HawkStd::close ()
|
||||
//
|
||||
//if (this->stdmod_up)
|
||||
//{
|
||||
// hawk_stdmodshutdown (this->hawk);
|
||||
// hawk_stdmodshutdown(this->hawk);
|
||||
// this->stdmod_up = false;
|
||||
//}
|
||||
//
|
||||
|
||||
Hawk::close ();
|
||||
Hawk::close();
|
||||
}
|
||||
|
||||
void HawkStd::uponClosing ()
|
||||
@@ -215,7 +215,7 @@ void HawkStd::uponClosing ()
|
||||
}
|
||||
|
||||
// chain up
|
||||
Hawk::uponClosing ();
|
||||
Hawk::uponClosing();
|
||||
}
|
||||
|
||||
HawkStd::Run* HawkStd::parse (Source& in, Source& out)
|
||||
@@ -227,7 +227,7 @@ HawkStd::Run* HawkStd::parse (Source& in, Source& out)
|
||||
// if cmgrtab has already been initialized,
|
||||
// just clear the contents regardless of
|
||||
// parse() result.
|
||||
hawk_htb_clear (&this->cmgrtab);
|
||||
hawk_htb_clear(&this->cmgrtab);
|
||||
}
|
||||
else if (run && (this->getTrait() & HAWK_RIO))
|
||||
{
|
||||
@@ -240,11 +240,11 @@ HawkStd::Run* HawkStd::parse (Source& in, Source& out)
|
||||
this->setError (HAWK_ENOMEM);
|
||||
return HAWK_NULL;
|
||||
}
|
||||
hawk_htb_setstyle (&this->cmgrtab, hawk_get_htb_style(HAWK_HTB_STYLE_INLINE_KEY_COPIER));
|
||||
hawk_htb_setstyle(&this->cmgrtab, hawk_get_htb_style(HAWK_HTB_STYLE_INLINE_KEY_COPIER));
|
||||
this->cmgrtab_inited = true;
|
||||
}
|
||||
|
||||
if (run && make_additional_globals(run) <= -1) return HAWK_NULL;
|
||||
if (run && this->make_additional_globals(run) <= -1) return HAWK_NULL;
|
||||
|
||||
return run;
|
||||
}
|
||||
@@ -553,8 +553,8 @@ int HawkStd::open_nwio (Pipe& io, int flags, void* nwad)
|
||||
if (cmgr) hawk_nwio_setcmgr(handle, cmgr);
|
||||
#endif
|
||||
|
||||
io.setHandle ((void*)handle);
|
||||
io.setUflags (1);
|
||||
io.setHandle((void*)handle);
|
||||
io.setUflags(1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -594,8 +594,8 @@ int HawkStd::open_pio (Pipe& io)
|
||||
hawk_pio_setcmgr(pio, HAWK_PIO_ERR, cmgr);
|
||||
}
|
||||
#endif
|
||||
io.setHandle (pio);
|
||||
io.setUflags (0);
|
||||
io.setHandle(pio);
|
||||
io.setUflags(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -618,7 +618,7 @@ static int parse_rwpipe_uri (const hawk_ooch_t* uri, int* flags, hawk_nwad_t* nw
|
||||
|
||||
for (i = 0; i < HAWK_COUNTOF(x); i++)
|
||||
{
|
||||
if (hawk_strzcmp (uri, x[i].prefix, x[i].len) == 0)
|
||||
if (hawk_strzcmp(uri, x[i].prefix, x[i].len) == 0)
|
||||
{
|
||||
if (hawk_strtonwad (uri + x[i].len, nwad) <= -1) return -1;
|
||||
*flags = x[i].flags;
|
||||
@@ -656,7 +656,7 @@ int HawkStd::closePipe (Pipe& io)
|
||||
if (io.getUflags() > 0)
|
||||
{
|
||||
/* nwio can't honor partical close */
|
||||
hawk_nwio_close ((hawk_nwio_t*)io.getHandle());
|
||||
hawk_nwio_close((hawk_nwio_t*)io.getHandle());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -677,7 +677,7 @@ int HawkStd::closePipe (Pipe& io)
|
||||
}
|
||||
}
|
||||
|
||||
hawk_pio_close (pio);
|
||||
hawk_pio_close(pio);
|
||||
#if defined(ENABLE_NWIO)
|
||||
}
|
||||
#endif
|
||||
@@ -850,7 +850,7 @@ int HawkStd::addConsoleOutput (const hawk_bch_t* arg)
|
||||
|
||||
void HawkStd::clearConsoleOutputs ()
|
||||
{
|
||||
this->ofile.clear (this->hawk);
|
||||
this->ofile.clear(this->hawk);
|
||||
}
|
||||
|
||||
static int check_var_assign (hawk_rtx_t* rtx, const hawk_ooch_t* str)
|
||||
@@ -1243,7 +1243,7 @@ void* HawkStd::modopen (const hawk_mod_spec_t* spec)
|
||||
|
||||
void HawkStd::modclose (void* handle)
|
||||
{
|
||||
hawk_stdmodclose (this->hawk, handle);
|
||||
hawk_stdmodclose(this->hawk, handle);
|
||||
}
|
||||
|
||||
void* HawkStd::modgetsym (void* handle, const hawk_ooch_t* name)
|
||||
@@ -1326,13 +1326,13 @@ int HawkStd::SourceFile::open (Data& io)
|
||||
if (totlen >= HAWK_COUNTOF(fbuf))
|
||||
{
|
||||
dbuf = (hawk_ooch_t*)hawk_allocmem((hawk_t*)io, HAWK_SIZEOF(hawk_ooch_t) * (totlen + 1));
|
||||
if (!dbuf) return -1;
|
||||
if (HAWK_UNLIKELY(!dbuf)) return -1;
|
||||
path = dbuf;
|
||||
}
|
||||
else path = fbuf;
|
||||
|
||||
tmplen = hawk_copy_oochars_to_oocstr_unlimited((hawk_ooch_t*)path, outer, dirlen);
|
||||
hawk_copy_oocstr_unlimited ((hawk_ooch_t*)path + tmplen, ioname);
|
||||
hawk_copy_oocstr_unlimited((hawk_ooch_t*)path + tmplen, ioname);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1370,8 +1370,8 @@ int HawkStd::SourceFile::open (Data& io)
|
||||
);
|
||||
if (!sio) return -1;
|
||||
|
||||
io.setPath (xpath);
|
||||
io.setHandle (sio);
|
||||
io.setPath(xpath);
|
||||
io.setHandle(sio);
|
||||
if (this->cmgr) hawk_sio_setcmgr(sio, this->cmgr);
|
||||
}
|
||||
|
||||
@@ -1382,7 +1382,7 @@ int HawkStd::SourceFile::open (Data& io)
|
||||
int HawkStd::SourceFile::close (Data& io)
|
||||
{
|
||||
hawk_sio_t* sio = (hawk_sio_t*)io.getHandle();
|
||||
hawk_sio_flush (sio);
|
||||
hawk_sio_flush(sio);
|
||||
hawk_sio_close(sio);
|
||||
return 0;
|
||||
}
|
||||
@@ -1483,7 +1483,7 @@ int HawkStd::SourceString::open (Data& io)
|
||||
else path = fbuf;
|
||||
|
||||
tmplen = hawk_copy_oochars_to_oocstr_unlimited((hawk_ooch_t*)path, outer, dirlen);
|
||||
hawk_copy_oocstr_unlimited ((hawk_ooch_t*)path + tmplen, ioname);
|
||||
hawk_copy_oocstr_unlimited((hawk_ooch_t*)path + tmplen, ioname);
|
||||
}
|
||||
}
|
||||
xpath = hawk_addsionamewithoochars((hawk_t*)io, path, hawk_count_oocstr(path));
|
||||
|
||||
@@ -1369,7 +1369,7 @@ static hawk_ooi_t sf_in_open (hawk_t* hawk, hawk_sio_arg_t* arg, xtn_t* xtn)
|
||||
else path = fbuf;
|
||||
|
||||
tmplen = hawk_copy_oochars_to_oocstr_unlimited((hawk_ooch_t*)path, outer, dirlen);
|
||||
hawk_copy_oocstr_unlimited ((hawk_ooch_t*)path + tmplen, arg->name);
|
||||
hawk_copy_oocstr_unlimited((hawk_ooch_t*)path + tmplen, arg->name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2021,7 +2021,7 @@ static int parse_rwpipe_uri (const hawk_ooch_t* uri, int* flags, hawk_nwad_t* nw
|
||||
|
||||
for (i = 0; i < HAWK_COUNTOF(x); i++)
|
||||
{
|
||||
if (hawk_strzcmp (uri, x[i].prefix, x[i].len) == 0)
|
||||
if (hawk_strzcmp(uri, x[i].prefix, x[i].len) == 0)
|
||||
{
|
||||
if (hawk_strtonwad (uri + x[i].len, nwad) <= -1) return -1;
|
||||
*flags = x[i].flags;
|
||||
@@ -2129,7 +2129,7 @@ static hawk_ooi_t pio_handler_rest (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_ri
|
||||
|
||||
case HAWK_RIO_CMD_FLUSH:
|
||||
/*if (riod->mode == HAWK_RIO_PIPE_READ) return -1;*/
|
||||
return hawk_pio_flush ((hawk_pio_t*)riod->handle, HAWK_PIO_IN);
|
||||
return hawk_pio_flush((hawk_pio_t*)riod->handle, HAWK_PIO_IN);
|
||||
|
||||
case HAWK_RIO_CMD_NEXT:
|
||||
break;
|
||||
|
||||
@@ -54,6 +54,15 @@ typedef HAWK::HawkStd HawkStd;
|
||||
typedef HAWK::HawkStd::Run Run;
|
||||
typedef HAWK::HawkStd::Value Value;
|
||||
|
||||
#ifdef _WIN32
|
||||
static BOOL WINAPI stop_run (DWORD ctrl_type);
|
||||
#else
|
||||
static void stop_run (int sig);
|
||||
static void do_nothing (int sig);
|
||||
#endif
|
||||
static void relay_signal (int sig);
|
||||
static int setsignal (int sig, void(*handler)(int), int restart);
|
||||
|
||||
class MyHawk: public HawkStd
|
||||
{
|
||||
public:
|
||||
@@ -80,6 +89,26 @@ public:
|
||||
return -1;
|
||||
}
|
||||
|
||||
void uponSigset (Run& run, int sig, bool reset)
|
||||
{
|
||||
if (reset)
|
||||
{
|
||||
/* this part must be in sync with set_singal() */
|
||||
if (sig == SIGINT)
|
||||
setsignal(sig, stop_run, 0);
|
||||
#if defined(SIGPIPE)
|
||||
else if (sig == SIGPIPE)
|
||||
setsignal(sig, do_nothing, 0);
|
||||
#endif
|
||||
else
|
||||
setsignal(sig, SIG_DFL, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
setsignal(sig, relay_signal, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int sleep (Run& run, Value& ret, Value* args, hawk_oow_t nargs, const hawk_ooch_t* name, hawk_oow_t len)
|
||||
{
|
||||
if (args[0].isIndexed())
|
||||
@@ -169,6 +198,11 @@ private:
|
||||
|
||||
static MyHawk* app_hawk = HAWK_NULL;
|
||||
|
||||
static void relay_signal (int sig)
|
||||
{
|
||||
if (app_hawk) app_hawk->raiseSignal(sig);
|
||||
}
|
||||
|
||||
static void print_error (const hawk_bch_t* fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
@@ -201,7 +235,7 @@ static BOOL WINAPI stop_run (DWORD ctrl_type)
|
||||
if (ctrl_type == CTRL_C_EVENT ||
|
||||
ctrl_type == CTRL_CLOSE_EVENT)
|
||||
{
|
||||
if (app_hawk) app_hawk->stop ();
|
||||
if (app_hawk) app_hawk->halt();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -214,7 +248,7 @@ static int setsignal (int sig, void(*handler)(int), int restart)
|
||||
struct sigaction sa_int;
|
||||
|
||||
sa_int.sa_handler = handler;
|
||||
sigemptyset (&sa_int.sa_mask);
|
||||
sigemptyset(&sa_int.sa_mask);
|
||||
|
||||
sa_int.sa_flags = 0;
|
||||
|
||||
@@ -230,13 +264,13 @@ static int setsignal (int sig, void(*handler)(int), int restart)
|
||||
sa_int.sa_flags |= SA_INTERRUPT;
|
||||
#endif
|
||||
}
|
||||
return sigaction (sig, &sa_int, NULL);
|
||||
return sigaction(sig, &sa_int, NULL);
|
||||
}
|
||||
|
||||
static void stop_run (int sig)
|
||||
{
|
||||
int e = errno;
|
||||
if (app_hawk) app_hawk->halt ();
|
||||
if (app_hawk) app_hawk->halt();
|
||||
errno = e;
|
||||
}
|
||||
|
||||
@@ -249,21 +283,21 @@ static void do_nothing (int sig)
|
||||
static void set_signal (void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
SetConsoleCtrlHandler (stop_run, TRUE);
|
||||
SetConsoleCtrlHandler(stop_run, TRUE);
|
||||
#else
|
||||
/*setsignal (SIGINT, stop_run, 1); TO BE MORE COMPATIBLE WITH WIN32*/
|
||||
setsignal (SIGINT, stop_run, 0);
|
||||
setsignal (SIGPIPE, do_nothing, 0);
|
||||
/*setsignal(SIGINT, stop_run, 1); TO BE MORE COMPATIBLE WITH WIN32*/
|
||||
setsignal(SIGINT, stop_run, 0);
|
||||
setsignal(SIGPIPE, do_nothing, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void unset_signal (void)
|
||||
static void unset_signal(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
SetConsoleCtrlHandler (stop_run, FALSE);
|
||||
SetConsoleCtrlHandler(stop_run, FALSE);
|
||||
#else
|
||||
setsignal (SIGINT, SIG_DFL, 1);
|
||||
setsignal (SIGPIPE, SIG_DFL, 1);
|
||||
setsignal(SIGINT, SIG_DFL, 1);
|
||||
setsignal(SIGPIPE, SIG_DFL, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user