fixed Hawk & HawkStd more

This commit is contained in:
hyung-hwan 2020-01-07 16:34:26 +00:00
parent 05c58df30f
commit 4af782af80
9 changed files with 273 additions and 130 deletions

View File

@ -115,7 +115,7 @@ void Mmgr::setDFL (Mmgr* mmgr) HAWK_CPP_NOEXCEPT
struct xtn_t
{
Hawk* awk;
Hawk* hawk;
hawk_ecb_t ecb;
};
@ -134,39 +134,6 @@ 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
//////////////////////////////////////////////////////////////////
// Hawk::RIO
//////////////////////////////////////////////////////////////////
Hawk::RIOBase::RIOBase (Run* run, hawk_rio_arg_t* riod): run (run), riod (riod)
{
}
const hawk_ooch_t* Hawk::RIOBase::getName () const
{
return this->riod->name;
}
const void* Hawk::RIOBase::getHandle () const
{
return this->riod->handle;
}
void Hawk::RIOBase::setHandle (void* handle)
{
this->riod->handle = handle;
}
int Hawk::RIOBase::getUflags () const
{
return this->riod->uflags;
}
void Hawk::RIOBase::setUflags (int uflags)
{
this->riod->uflags = uflags;
}
//////////////////////////////////////////////////////////////////
// Hawk::Pipe
//////////////////////////////////////////////////////////////////
@ -1228,7 +1195,7 @@ void Hawk::Run::formatError (hawk_errnum_t code, const hawk_loc_t* loc, const ha
HAWK_ASSERT (this->rtx != HAWK_NULL);
va_list ap;
va_start (ap, fmt);
hawk_rtx_seterrbfmt (this->rtx, loc, code, fmt, ap);
hawk_rtx_seterrbvfmt (this->rtx, loc, code, fmt, ap);
va_end (ap);
}
@ -1237,7 +1204,7 @@ void Hawk::Run::formatError (hawk_errnum_t code, const hawk_loc_t* loc, const ha
HAWK_ASSERT (this->rtx != HAWK_NULL);
va_list ap;
va_start (ap, fmt);
hawk_rtx_seterrufmt (this->rtx, loc, code, fmt, ap);
hawk_rtx_seterruvfmt (this->rtx, loc, code, fmt, ap);
va_end (ap);
}
@ -1362,8 +1329,9 @@ void Hawk::formatError (hawk_errnum_t code, const hawk_loc_t* loc, const hawk_bc
{
va_list ap;
va_start (ap, fmt);
hawk_seterrbfmt (this->awk, loc, code, fmt, ap);
hawk_seterrbvfmt (this->awk, loc, code, fmt, ap);
va_end (ap);
this->retrieveError ();
}
else
{
@ -1380,8 +1348,9 @@ void Hawk::formatError (hawk_errnum_t code, const hawk_loc_t* loc, const hawk_uc
{
va_list ap;
va_start (ap, fmt);
hawk_seterrufmt (this->awk, loc, code, fmt, ap);
hawk_seterruvfmt (this->awk, loc, code, fmt, ap);
va_end (ap);
this->retrieveError ();
}
else
{
@ -1420,13 +1389,13 @@ void Hawk::retrieveError (Run* run)
static void fini_xtn (hawk_t* awk)
{
xtn_t* xtn = GET_XTN(awk);
xtn->awk->uponClosing ();
xtn->hawk->uponClosing ();
}
static void clear_xtn (hawk_t* awk)
{
xtn_t* xtn = GET_XTN(awk);
xtn->awk->uponClearing ();
xtn->hawk->uponClearing ();
}
int Hawk::open ()
@ -1457,7 +1426,7 @@ int Hawk::open ()
// associate this Hawk object with the underlying awk object
xtn_t* xtn = (xtn_t*)GET_XTN(this->awk);
xtn->awk = this;
xtn->hawk = this;
xtn->ecb.close = fini_xtn;
xtn->ecb.clear = clear_xtn;
@ -2224,42 +2193,40 @@ int Hawk::deleteFunction (const hawk_ooch_t* name)
return n;
}
hawk_ooi_t Hawk::readSource (
hawk_t* awk, sio_cmd_t cmd, sio_arg_t* arg,
hawk_ooch_t* data, hawk_oow_t count)
hawk_ooi_t Hawk::readSource (hawk_t* hawk, sio_cmd_t cmd, sio_arg_t* arg, hawk_ooch_t* data, hawk_oow_t count)
{
xtn_t* xtn = GET_XTN(awk);
Source::Data sdat (xtn->awk, Source::READ, arg);
xtn_t* xtn = GET_XTN(hawk);
Source::Data sdat(xtn->hawk, Source::READ, arg);
switch (cmd)
{
case HAWK_SIO_CMD_OPEN:
return xtn->awk->source_reader->open (sdat);
return xtn->hawk->source_reader->open(sdat);
case HAWK_SIO_CMD_CLOSE:
return xtn->awk->source_reader->close (sdat);
return xtn->hawk->source_reader->close(sdat);
case HAWK_SIO_CMD_READ:
return xtn->awk->source_reader->read (sdat, data, count);
return xtn->hawk->source_reader->read(sdat, data, count);
default:
hawk_seterrnum (hawk, HAWK_NULL, HAWK_EINTERN);
return -1;
}
}
hawk_ooi_t Hawk::writeSource (
hawk_t* awk, hawk_sio_cmd_t cmd, sio_arg_t* arg,
hawk_ooch_t* data, hawk_oow_t count)
hawk_ooi_t Hawk::writeSource (hawk_t* hawk, hawk_sio_cmd_t cmd, sio_arg_t* arg, hawk_ooch_t* data, hawk_oow_t count)
{
xtn_t* xtn = GET_XTN(awk);
Source::Data sdat (xtn->awk, Source::WRITE, arg);
xtn_t* xtn = GET_XTN(hawk);
Source::Data sdat (xtn->hawk, Source::WRITE, arg);
switch (cmd)
{
case HAWK_SIO_CMD_OPEN:
return xtn->awk->source_writer->open (sdat);
return xtn->hawk->source_writer->open (sdat);
case HAWK_SIO_CMD_CLOSE:
return xtn->awk->source_writer->close (sdat);
return xtn->hawk->source_writer->close (sdat);
case HAWK_SIO_CMD_WRITE:
return xtn->awk->source_writer->write (sdat, data, count);
return xtn->hawk->source_writer->write (sdat, data, count);
default:
hawk_seterrnum (hawk, HAWK_NULL, HAWK_EINTERN);
return -1;
}
}
@ -2295,6 +2262,7 @@ hawk_ooi_t Hawk::pipeHandler (hawk_rtx_t* rtx, rio_cmd_t cmd, hawk_rio_arg_t* ri
return awk->pipe_handler->flush(pipe);
default:
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}
}
@ -2318,6 +2286,7 @@ hawk_ooi_t Hawk::pipeHandler (hawk_rtx_t* rtx, rio_cmd_t cmd, hawk_rio_arg_t* ri
return awk->flushPipe(pipe);
default:
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}
}
@ -2359,6 +2328,7 @@ hawk_ooi_t Hawk::fileHandler (hawk_rtx_t* rtx, rio_cmd_t cmd, hawk_rio_arg_t* ri
return awk->file_handler->flush(file);
default:
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}
}
@ -2382,6 +2352,7 @@ hawk_ooi_t Hawk::fileHandler (hawk_rtx_t* rtx, rio_cmd_t cmd, hawk_rio_arg_t* ri
return awk->flushFile(file);
default:
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}
}
@ -2425,6 +2396,7 @@ hawk_ooi_t Hawk::consoleHandler (hawk_rtx_t* rtx, rio_cmd_t cmd, hawk_rio_arg_t*
return awk->console_handler->next(console);
default:
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}
}
@ -2450,6 +2422,7 @@ hawk_ooi_t Hawk::consoleHandler (hawk_rtx_t* rtx, rio_cmd_t cmd, hawk_rio_arg_t*
return awk->nextConsole(console);
default:
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}
}
@ -2577,37 +2550,37 @@ int Hawk::nextConsole (Console& io)
int Hawk::functionHandler (hawk_rtx_t* rtx, const fnc_info_t* fi)
{
rxtn_t* rxtn = GET_RXTN(rtx);
return rxtn->run->awk->dispatch_function (rxtn->run, fi);
return rxtn->run->awk->dispatch_function(rxtn->run, fi);
}
Hawk::flt_t Hawk::pow (hawk_t* awk, flt_t x, flt_t y)
{
xtn_t* xtn = GET_XTN(awk);
return xtn->awk->pow (x, y);
return xtn->hawk->pow(x, y);
}
Hawk::flt_t Hawk::mod (hawk_t* awk, flt_t x, flt_t y)
{
xtn_t* xtn = GET_XTN(awk);
return xtn->awk->mod (x, y);
return xtn->hawk->mod(x, y);
}
void* Hawk::modopen (hawk_t* awk, const mod_spec_t* spec)
{
xtn_t* xtn = GET_XTN(awk);
return xtn->awk->modopen (spec);
return xtn->hawk->modopen(spec);
}
void Hawk::modclose (hawk_t* awk, void* handle)
{
xtn_t* xtn = GET_XTN(awk);
xtn->awk->modclose (handle);
xtn->hawk->modclose (handle);
}
void* Hawk::modgetsym (hawk_t* awk, void* handle, const hawk_ooch_t* name)
{
xtn_t* xtn = GET_XTN(awk);
return xtn->awk->modgetsym (handle, name);
return xtn->hawk->modgetsym(handle, name);
}
/////////////////////////////////
HAWK_END_NAMESPACE(HAWK)
@ -2617,7 +2590,7 @@ HAWK_END_NAMESPACE(HAWK)
void* operator new (hawk_oow_t size, HAWK::Mmgr* mmgr) /*HAWK_CPP_THREXCEPT1(HAWK::Mmgr::MemoryError)*/
{
return mmgr->allocate (size);
return mmgr->allocate(size);
}
#if defined(HAWK_CPP_NO_OPERATOR_DELETE_OVERLOADING)
@ -2639,7 +2612,7 @@ void* operator new (hawk_oow_t size, HAWK::Mmgr* mmgr, void* existing_ptr) /*HAW
#if 0
void* operator new[] (hawk_oow_t size, HAWK::Mmgr* mmgr)
{
return mmgr->allocate (size);
return mmgr->allocate(size);
}
void operator delete[] (void* ptr, HAWK::Mmgr* mmgr)

View File

@ -622,16 +622,16 @@ public:
class HAWK_EXPORT RIOBase
{
protected:
RIOBase (Run* run, hawk_rio_arg_t* riod);
RIOBase (Run* run, hawk_rio_arg_t* riod): run(run), riod(riod) {}
public:
const hawk_ooch_t* getName() const;
const hawk_ooch_t* getName() const { return this->riod->name; }
const void* getHandle () const;
void setHandle (void* handle);
const void* getHandle () const { return this->riod->handle; }
void setHandle (void* handle) { this->riod->handle = handle; }
int getUflags () const;
void setUflags (int uflags);
int getUflags () const { return this->riod->uflags; }
void setUflags (int uflags) { this->riod->uflags = uflags; }
operator Hawk* () const { return this->run->awk; }
operator hawk_t* () const

View File

@ -48,6 +48,8 @@
# error UNSUPPORTED DYNAMIC LINKER
#endif
extern char **environ;
/////////////////////////////////
HAWK_BEGIN_NAMESPACE(HAWK)
/////////////////////////////////
@ -76,29 +78,31 @@ void MmgrStd::freeMem (void* ptr) HAWK_CPP_NOEXCEPT
HawkStd::ioattr_t HawkStd::default_ioattr;
static hawk_sio_t* open_sio (Hawk* awk, HawkStd::Run* run, const hawk_ooch_t* file, int flags)
static hawk_sio_t* open_sio (Hawk* hawk, HawkStd::Run* run, const hawk_ooch_t* file, int flags)
{
hawk_sio_t* sio;
//sio = hawk_sio_open ((run? ((Hawk::awk_t*)*(Hawk*)*run)->mmgr: awk->getMmgr()), 0, file, flags);
sio = hawk_sio_open((run? (hawk_gem_t*)*run: (hawk_gem_t*)*awk), 0, file, flags);
sio = hawk_sio_open((run? (hawk_gem_t*)*run: (hawk_gem_t*)*hawk), 0, file, flags);
if (sio == HAWK_NULL)
{
if (run)
{
const hawk_ooch_t* bem = hawk_rtx_backuperrmsg(*run);
run->formatError (HAWK_EOPEN, HAWK_NULL, HAWK_T("unable to open %js - %js"), file, bem);
const hawk_ooch_t* bem = hawk_rtx_backuperrmsg((hawk_rtx_t*)*run);
//run->formatError (HAWK_EOPEN, HAWK_NULL, HAWK_T("unable to open %js - %js"), file, bem);
hawk_rtx_seterrfmt ((hawk_rtx_t*)*run, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), file, bem);
}
else
{
const hawk_ooch_t* bem = hawk_backuperrmsg(*awk);
awk->formatError (HAWK_EOPEN, HAWK_NULL, HAWK_T("unable to open %js - %js"), file, bem);
const hawk_ooch_t* bem = hawk_backuperrmsg((hawk_t*)*hawk);
//hawk->formatError (HAWK_EOPEN, HAWK_NULL, HAWK_T("unable to open %js - %js"), file, bem);
hawk_seterrfmt ((hawk_t*)*hawk, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), file, bem);
}
}
return sio;
}
static hawk_sio_t* open_sio_std (Hawk* awk, HawkStd::Run* run, hawk_sio_std_t std, int flags)
static hawk_sio_t* open_sio_std (Hawk* hawk, HawkStd::Run* run, hawk_sio_std_t std, int flags)
{
hawk_sio_t* sio;
static const hawk_ooch_t* std_names[] =
@ -109,18 +113,20 @@ static hawk_sio_t* open_sio_std (Hawk* awk, HawkStd::Run* run, hawk_sio_std_t st
};
//sio = hawk_sio_openstd ((run? ((Hawk::awk_t*)*(Hawk*)*run)->mmgr: awk->getMmgr()), 0, std, flags);
sio = hawk_sio_openstd((run? (hawk_gem_t*)*run: (hawk_gem_t*)*awk), 0, std, flags);
sio = hawk_sio_openstd((run? (hawk_gem_t*)*run: (hawk_gem_t*)*hawk), 0, std, flags);
if (sio == HAWK_NULL)
{
if (run)
{
const hawk_ooch_t* bem = hawk_rtx_backuperrmsg(*run);
run->formatError (HAWK_EOPEN, HAWK_NULL, HAWK_T("unable to open %js - %js"), std_names[std], bem);
const hawk_ooch_t* bem = hawk_rtx_backuperrmsg((hawk_rtx_t*)*run);
//run->formatError (HAWK_EOPEN, HAWK_NULL, HAWK_T("unable to open %js - %js"), std_names[std], bem);
hawk_rtx_seterrfmt ((hawk_rtx_t*)*run, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), std_names[std], bem);
}
else
{
const hawk_ooch_t* bem = hawk_backuperrmsg(*awk);
awk->formatError (HAWK_EOPEN, HAWK_NULL, HAWK_T("unable to open %js - %js"), std_names[std], bem);
const hawk_ooch_t* bem = hawk_backuperrmsg((hawk_t*)*hawk);
//awk->formatError (HAWK_EOPEN, HAWK_NULL, HAWK_T("unable to open %js - %js"), std_names[std], bem);
hawk_seterrfmt ((hawk_t*)*hawk, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), std_names[std], bem);
}
}
return sio;
@ -340,10 +346,9 @@ int HawkStd::build_environ (Run* run, env_char_t* envarr[])
int HawkStd::make_additional_globals (Run* run)
{
/* TODO: use wenviron where it's available */
extern char **environ;
if (build_argcv(run) <= -1 ||
build_environ(run, environ) <= -1) return -1;
build_environ(run, ::environ) <= -1) return -1;
return 0;
}
@ -562,8 +567,7 @@ int HawkStd::open_pio (Pipe& io)
{
case Hawk::Pipe::READ:
/* TODO: should we specify ERRTOOUT? */
flags |= HAWK_PIO_READOUT |
HAWK_PIO_ERRTOOUT;
flags |= HAWK_PIO_READOUT | HAWK_PIO_ERRTOOUT;
break;
case Hawk::Pipe::WRITE:
@ -571,19 +575,12 @@ int HawkStd::open_pio (Pipe& io)
break;
case Hawk::Pipe::RW:
flags |= HAWK_PIO_READOUT |
HAWK_PIO_ERRTOOUT |
HAWK_PIO_WRITEIN;
flags |= HAWK_PIO_READOUT | HAWK_PIO_ERRTOOUT | HAWK_PIO_WRITEIN;
break;
}
pio = hawk_pio_open (
*this,
0,
io.getName(),
flags
);
if (pio == HAWK_NULL) return -1;
pio = hawk_pio_open((hawk_gem_t*)*this, 0, io.getName(), flags);
if (!pio) return -1;
#if defined(HAWK_OOCH_IS_UCH)
hawk_cmgr_t* cmgr = this->getiocmgr(io.getName());
@ -740,17 +737,14 @@ int HawkStd::openFile (File& io)
flags |= HAWK_SIO_READ;
break;
case Hawk::File::WRITE:
flags |= HAWK_SIO_WRITE |
HAWK_SIO_CREATE |
HAWK_SIO_TRUNCATE;
flags |= HAWK_SIO_WRITE | HAWK_SIO_CREATE | HAWK_SIO_TRUNCATE;
break;
case Hawk::File::APPEND:
flags |= HAWK_SIO_APPEND |
HAWK_SIO_CREATE;
flags |= HAWK_SIO_APPEND | HAWK_SIO_CREATE;
break;
}
sio = hawk_sio_open(*this, 0, io.getName(), flags);
sio = hawk_sio_open((hawk_gem_t*)*this, 0, io.getName(), flags);
if (!sio) return -1;
#if defined(HAWK_OOCH_IS_UCH)
hawk_cmgr_t* cmgr = this->getiocmgr(io.getName());
@ -842,13 +836,10 @@ int HawkStd::open_console_in (Console& io)
{
hawk_sio_t* sio;
sio = open_sio_std(
HAWK_NULL, io, HAWK_SIO_STDIN,
HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
sio = open_sio_std(HAWK_NULL, io, HAWK_SIO_STDIN, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
if (sio == HAWK_NULL) return -1;
if (this->console_cmgr)
hawk_sio_setcmgr (sio, this->console_cmgr);
if (this->console_cmgr) hawk_sio_setcmgr (sio, this->console_cmgr);
io.setHandle (sio);
this->runarg_count++;
@ -885,13 +876,10 @@ int HawkStd::open_console_in (Console& io)
* 'BEGIN { ARGV[1]=""; ARGV[2]=""; }
* { print $0; }' file1 file2
*/
sio = open_sio_std(
HAWK_NULL, io, HAWK_SIO_STDIN,
HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
sio = open_sio_std(HAWK_NULL, io, HAWK_SIO_STDIN, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
if (sio == HAWK_NULL) return -1;
if (this->console_cmgr)
hawk_sio_setcmgr (sio, this->console_cmgr);
if (this->console_cmgr) hawk_sio_setcmgr (sio, this->console_cmgr);
io.setHandle (sio);
this->runarg_count++;
@ -1188,6 +1176,16 @@ void* HawkStd::modgetsym (void* handle, const hawk_ooch_t* name)
return s;
}
HawkStd::SourceFile::~SourceFile ()
{
if (this->_hawk)
{
HAWK_ASSERT (this->str != HAWK_NULL);
hawk_freemem (this->_hawk, this->name);
}
}
int HawkStd::SourceFile::open (Data& io)
{
hawk_sio_t* sio;
@ -1195,6 +1193,32 @@ int HawkStd::SourceFile::open (Data& io)
if (io.isMaster())
{
// open the main source file.
if (!this->name)
{
this->_hawk = (hawk_t*)io;
if (this->_type == NAME_UCH)
{
#if defined(HAWK_OOCH_IS_UCH)
this->name = hawk_dupucstr(this->_hawk, (hawk_uch_t*)this->_name, HAWK_NULL);
#else
this->name = hawk_duputobcstr(this->_hawk, (hawk_uch_t*)this->_name, HAWK_NULL);
#endif
}
else
{
HAWK_ASSERT (this->_type == NAME_BCH);
#if defined(HAWK_OOCH_IS_UCH)
this->name = hawk_dupbtoucstr(this->_hawk, (hawk_bch_t*)this->_name, HAWK_NULL, 0);
#else
this->name = hawk_dupbcstr(this->_hawk, (hawk_bch_t*)this->_name, HAWK_NULL);
#endif
}
if (!this->name)
{
// TODO: check if retrieveError is needed //((Hawk*)io)->retrieveError();
return -1;
}
}
if (this->name[0] == HAWK_T('-') && this->name[1] == HAWK_T('\0'))
{
@ -1341,6 +1365,7 @@ int HawkStd::SourceString::open (Data& io)
}
else
{
HAWK_ASSERT (this->_type == STR_BCH);
#if defined(HAWK_OOCH_IS_UCH)
this->str = hawk_dupbtoucstr(this->_hawk, (hawk_bch_t*)this->_str, HAWK_NULL, 0);
#else

View File

@ -65,19 +65,33 @@ public:
class HAWK_EXPORT SourceFile: public Source
{
public:
SourceFile (const hawk_ooch_t* name, hawk_cmgr_t* cmgr = HAWK_NULL):
name (name), cmgr (cmgr)
SourceFile (const hawk_uch_t* name, hawk_cmgr_t* cmgr = HAWK_NULL): _type(NAME_UCH), _name(name), _hawk(HAWK_NULL), name(HAWK_NULL), cmgr (cmgr)
{
dir.ptr = HAWK_NULL; dir.len = 0;
}
SourceFile (const hawk_bch_t* name, hawk_cmgr_t* cmgr = HAWK_NULL): _type(NAME_BCH), _name(name), _hawk(HAWK_NULL), name(HAWK_NULL), cmgr (cmgr)
{
dir.ptr = HAWK_NULL; dir.len = 0;
}
~SourceFile ();
int open (Data& io);
int close (Data& io);
hawk_ooi_t read (Data& io, hawk_ooch_t* buf, hawk_oow_t len);
hawk_ooi_t write (Data& io, const hawk_ooch_t* buf, hawk_oow_t len);
protected:
const hawk_ooch_t* name;
enum
{
NAME_UCH,
NAME_BCH
} _type;
const void* _name;
hawk_t* _hawk;
hawk_ooch_t* name;
hawk_oocs_t dir;
hawk_cmgr_t* cmgr;
};

View File

@ -348,6 +348,46 @@ void hawk_seterrufmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errn
hawk->_gem.errloc = (errloc? *errloc: _nullloc);
}
void hawk_seterrbvfmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, va_list ap)
{
hawk_fmtout_t fo;
/*if (hawk->shuterr) return;*/
hawk->errmsg_len = 0;
hawk->_gem.errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = hawk_getmmgr(hawk);
fo.putbchars = err_bchars;
fo.putuchars = err_uchars;
fo.ctx = hawk;
hawk_bfmt_outv (&fo, errfmt, ap);
hawk->_gem.errnum = errnum;
hawk->_gem.errloc = (errloc? *errloc: _nullloc);
}
void hawk_seterruvfmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* errfmt, va_list ap)
{
hawk_fmtout_t fo;
/*if (hawk->shuterr) return;*/
hawk->errmsg_len = 0;
hawk->_gem.errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = hawk_getmmgr(hawk);
fo.putbchars = err_bchars;
fo.putuchars = err_uchars;
fo.ctx = hawk;
hawk_ufmt_outv (&fo, errfmt, ap);
hawk->_gem.errnum = errnum;
hawk->_gem.errloc = (errloc? *errloc: _nullloc);
}
/* ------------------------------------------------------------------------- */
const hawk_loc_t* hawk_rtx_geterrloc (hawk_rtx_t* rtx)
@ -507,6 +547,46 @@ void hawk_rtx_seterrufmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum
rtx->_gem.errloc = (errloc? *errloc: _nullloc);
}
void hawk_rtx_seterrbvfmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, va_list ap)
{
hawk_fmtout_t fo;
/*if (hawk->shuterr) return;*/
rtx->errmsg_len = 0;
rtx->_gem.errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = hawk_rtx_getmmgr(rtx);
fo.putbchars = rtx_err_bchars;
fo.putuchars = rtx_err_uchars;
fo.ctx = rtx;
hawk_bfmt_outv (&fo, errfmt, ap);
rtx->_gem.errnum = errnum;
rtx->_gem.errloc = (errloc? *errloc: _nullloc);
}
void hawk_rtx_seterruvfmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* errfmt, va_list ap)
{
hawk_fmtout_t fo;
/*if (hawk->shuterr) return;*/
rtx->errmsg_len = 0;
rtx->_gem.errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = hawk_rtx_getmmgr(rtx);
fo.putbchars = rtx_err_bchars;
fo.putuchars = rtx_err_uchars;
fo.ctx = rtx;
hawk_ufmt_outv (&fo, errfmt, ap);
rtx->_gem.errnum = errnum;
rtx->_gem.errloc = (errloc? *errloc: _nullloc);
}
void hawk_rtx_errortohawk (hawk_rtx_t* rtx, hawk_t* hawk)
{
/* copy error information in 'rtx' to the 'hawk' object */

View File

@ -670,12 +670,12 @@ struct hawk_rio_arg_t
{
/* read-only. a user handler shouldn't change any of these fields */
hawk_rio_mode_t mode; /**< opening mode */
hawk_ooch_t* name; /**< name of I/O object */
hawk_ooch_t* name; /**< name of I/O object */
hawk_rio_rwcmode_t rwcmode; /**< closing mode for rwpipe */
/* read-write. a user handler can do whatever it likes to do with these. */
void* handle; /**< I/O handle set by a handler */
int uflags; /**< user-flags set by a handler */
void* handle; /**< I/O handle set by a handler */
int uflags; /**< user-flags set by a handler */
/*-- from here down, internal use only --*/
int type;
@ -707,8 +707,8 @@ typedef hawk_ooi_t (*hawk_rio_impl_t) (
hawk_rtx_t* rtx,
hawk_rio_cmd_t cmd,
hawk_rio_arg_t* arg,
void* data,
hawk_oow_t count
void* data,
hawk_oow_t count
);
/**
@ -1591,10 +1591,28 @@ HAWK_EXPORT void hawk_seterrufmt (
...
);
HAWK_EXPORT void hawk_seterrbvfmt (
hawk_t* awk,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_bch_t* errfmt,
va_list ap
);
HAWK_EXPORT void hawk_seterruvfmt (
hawk_t* awk,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_uch_t* errfmt,
va_list ap
);
#if defined(HAWK_OOCH_IS_UCH)
# define hawk_seterrfmt hawk_seterrufmt
# define hawk_seterrvfmt hawk_seterruvfmt
#else
# define hawk_seterrfmt hawk_seterrbfmt
# define hawk_seterrvfmt hawk_seterrbvfmt
#endif
/**
@ -2434,10 +2452,28 @@ HAWK_EXPORT void hawk_rtx_seterrufmt (
...
);
HAWK_EXPORT void hawk_rtx_seterrbvfmt (
hawk_rtx_t* rtx,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_bch_t* errfmt,
va_list ap
);
HAWK_EXPORT void hawk_rtx_seterruvfmt (
hawk_rtx_t* rtx,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_uch_t* errfmt,
va_list ap
);
#if defined(HAWK_OOCH_IS_UCH)
# define hawk_rtx_seterrfmt hawk_rtx_seterrufmt
# define hawk_rtx_seterrvfmt hawk_rtx_seterruvfmt
#else
# define hawk_rtx_seterrfmt hawk_rtx_seterrbfmt
# define hawk_rtx_seterrvfmt hawk_rtx_seterrbvfmt
#endif
/**

View File

@ -298,7 +298,7 @@ static int fnc_close (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
sys_list_t* sys_list;
sys_node_t* sys_node;
hawk_int_t rx = ERRNUM_TO_RC(HAWK_EOTHER);
hawk_int_t cflags;
hawk_int_t cflags = 0;
sys_list = rtx_to_sys_list(rtx, fi);
sys_node = get_sys_list_node_with_arg(rtx, sys_list, hawk_rtx_getarg(rtx, 0), SYS_NODE_DATA_FD);
@ -2072,7 +2072,7 @@ static int fnc_mkdir (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
hawk_ooch_t* str;
hawk_oow_t len;
int n = 0;
hawk_int_t mode;
hawk_int_t mode = DEFAULT_MODE;
a0 = hawk_rtx_getarg(rtx, 0);
str = hawk_rtx_getvaloocstr(rtx, a0, &len);

View File

@ -2111,8 +2111,7 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod)
if (rxtn->c.cmgr) hawk_sio_setcmgr (sio, rxtn->c.cmgr);
if (hawk_rtx_setfilename (
rtx, file, hawk_count_oocstr(file)) <= -1)
if (hawk_rtx_setfilename(rtx, file, hawk_count_oocstr(file)) <= -1)
{
hawk_sio_close (sio);
hawk_rtx_freevaloocstr (rtx, v, as.ptr);

View File

@ -182,15 +182,31 @@ static void print_error (const hawk_bch_t* fmt, ...)
static void print_error (MyHawk& hawk)
{
hawk_errnum_t code = hawk.getErrorNumber();
hawk_loc_t loc = hawk.getErrorLocation();
#if defined(HAWK_OOCH_IS_UCH)
hawk_bch_t msg[256]; // don't care about truncation for now
hawk_oow_t ucslen, bcslen = HAWK_COUNTOF(msg);
hawk_conv_ucstr_to_bcstr_with_cmgr (hawk.getErrorMessage(), &ucslen, msg, &bcslen, hawk_getcmgr((hawk_t*)hawk));
#else
const hawk_bch_t* msg = hawk.getErrorMessage();
#endif
if (loc.file)
{
print_error ("line %lu at %s - %s\n", (unsigned long int)loc.line, loc.file, hawk.getErrorMessage());
#if defined(HAWK_OOCH_IS_UCH)
hawk_bch_t file[128]; // don't care about truncation for now
bcslen = HAWK_COUNTOF(file);
hawk_conv_ucstr_to_bcstr_with_cmgr (loc.file, &ucslen, file, &bcslen, hawk_getcmgr((hawk_t*)hawk));
#else
const hawk_bch_t* file = loc.file;
#endif
print_error ("code %d line %lu at %s - %s\n", (int)code, (unsigned long int)loc.line, file, msg);
}
else
{
print_error ("line %lu - %s\n", (unsigned long int)loc.line, hawk.getErrorMessage());
print_error ("code %d line %lu - %s\n", (int)code, (unsigned long int)loc.line, msg);
}
}
@ -405,7 +421,7 @@ static int hawk_main (MyHawk& awk, int argc, hawk_bch_t* argv[])
}
MyHawk::Value ret;
if (awk.loop (&ret) <= -1)
if (awk.loop(&ret) <= -1)
{
print_error (awk);
return -1;