added hawk_json_feeduchars()
This commit is contained in:
@ -32,7 +32,7 @@
|
||||
|
||||
/// \file
|
||||
/// This file defines C++ classes that you can use when you create a stream
|
||||
/// editor. The C++ classes encapsulates the C data types and functions in
|
||||
/// editor. The C++ classes encapsulates the C data types and functions in
|
||||
/// a more object-oriented manner.
|
||||
///
|
||||
/// \todo support sed tracer
|
||||
@ -62,7 +62,7 @@ public:
|
||||
WRITE ///< open for write
|
||||
};
|
||||
|
||||
/// The Data class conveys information need for I/O operations.
|
||||
/// The Data class conveys information need for I/O operations.
|
||||
class HAWK_EXPORT Data
|
||||
{
|
||||
public:
|
||||
@ -77,12 +77,12 @@ public:
|
||||
/// requested.
|
||||
Mode getMode() const { return this->mode; }
|
||||
|
||||
/// The getHandle() function returns the I/O handle
|
||||
/// The getHandle() function returns the I/O handle
|
||||
/// saved by setHandle().
|
||||
void* getHandle () const { return this->arg->handle; }
|
||||
|
||||
/// The setHandle() function sets an I/O handle
|
||||
/// typically in the Stream::open() function.
|
||||
/// typically in the Stream::open() function.
|
||||
void setHandle (void* handle) { this->arg->handle = handle; }
|
||||
|
||||
/// The getName() function returns an I/O name.
|
||||
@ -93,7 +93,7 @@ public:
|
||||
/// The Sed* operator returns the associated Sed class.
|
||||
operator Sed* () const { return this->sed; }
|
||||
|
||||
/// The hawk_sed_t* operator returns a pointer to the
|
||||
/// The hawk_sed_t* operator returns a pointer to the
|
||||
/// underlying stream editor.
|
||||
operator hawk_sed_t* () const { return this->sed->getHandle(); }
|
||||
|
||||
@ -115,7 +115,7 @@ public:
|
||||
/// to open a stream. It can get the mode requested by calling
|
||||
/// the Data::getMode() function over the I/O parameter \a io.
|
||||
///
|
||||
/// The return value of 0 may look a bit tricky. Easygoers
|
||||
/// The return value of 0 may look a bit tricky. Easygoers
|
||||
/// can just return 1 on success and never return 0 from open().
|
||||
/// - If 0 is returned for the #READ mode, Sed::execute()
|
||||
/// returns success after having called close() as it has
|
||||
@ -125,7 +125,7 @@ public:
|
||||
/// failure after having called close() as it cannot write
|
||||
/// further on EOF.
|
||||
///
|
||||
/// \return -1 on failure, 1 on success,
|
||||
/// \return -1 on failure, 1 on success,
|
||||
/// 0 on success but reached EOF.
|
||||
virtual int open (Data& io) = 0;
|
||||
|
||||
@ -147,7 +147,7 @@ public:
|
||||
Sed (Mmgr* mmgr);
|
||||
|
||||
///
|
||||
/// The ~Sed() function destroys a stream editor.
|
||||
/// The ~Sed() function destroys a stream editor.
|
||||
/// \note The close() function is not called by this destructor.
|
||||
/// To avoid resource leaks, You should call close() before
|
||||
/// a stream editor is destroyed if it has been initialized
|
||||
@ -172,7 +172,7 @@ public:
|
||||
void close ();
|
||||
|
||||
///
|
||||
/// The compile() function compiles a script from a stream
|
||||
/// The compile() function compiles a script from a stream
|
||||
/// \a iostream.
|
||||
/// \return 0 on success, -1 on failure
|
||||
///
|
||||
@ -187,7 +187,7 @@ public:
|
||||
|
||||
///
|
||||
/// The halt() function makes a request to break a running loop
|
||||
/// inside execute(). Note that this does not affect blocking
|
||||
/// inside execute(). Note that this does not affect blocking
|
||||
/// operations in user-defined stream handlers.
|
||||
///
|
||||
void halt ();
|
||||
@ -213,7 +213,7 @@ public:
|
||||
);
|
||||
|
||||
///
|
||||
/// The getErrorMessage() function gets the description of the last
|
||||
/// The getErrorMessage() function gets the description of the last
|
||||
/// error occurred. It returns an empty string if the stream editor
|
||||
/// has not been initialized with the open() function.
|
||||
///
|
||||
@ -223,14 +223,14 @@ public:
|
||||
|
||||
///
|
||||
/// The getErrorLocation() function gets the location where
|
||||
/// the last error occurred. The line and the column of the #hawk_loc_t
|
||||
/// structure retruend are 0 if the stream editor has not been
|
||||
/// the last error occurred. The line and the column of the #hawk_loc_t
|
||||
/// structure retruend are 0 if the stream editor has not been
|
||||
/// initialized with the open() function.
|
||||
///
|
||||
hawk_loc_t getErrorLocation () const;
|
||||
|
||||
///
|
||||
/// The getErrorNumber() function gets the number of the last
|
||||
/// The getErrorNumber() function gets the number of the last
|
||||
/// error occurred. It returns HAWK_ENOERR if the stream editor
|
||||
/// has not been initialized with the open() function.
|
||||
///
|
||||
@ -268,14 +268,14 @@ public:
|
||||
|
||||
///
|
||||
/// The getConsoleLine() function returns the current line
|
||||
/// number from an input console.
|
||||
/// number from an input console.
|
||||
/// \return current line number
|
||||
///
|
||||
hawk_oow_t getConsoleLine ();
|
||||
|
||||
///
|
||||
/// The setConsoleLine() function changes the current line
|
||||
/// number from an input console.
|
||||
/// number from an input console.
|
||||
///
|
||||
void setConsoleLine (
|
||||
hawk_oow_t num ///< a line number
|
||||
@ -286,7 +286,7 @@ protected:
|
||||
/// The getErrorString() function returns an error formatting string
|
||||
/// for the error number \a num. A subclass wishing to customize
|
||||
/// an error formatting string may override this function.
|
||||
///
|
||||
///
|
||||
virtual const hawk_ooch_t* getErrorString (
|
||||
hawk_errnum_t num ///< an error number
|
||||
) const;
|
||||
@ -300,7 +300,7 @@ protected:
|
||||
/// handle to a primitive sed object
|
||||
hawk_sed_t* sed;
|
||||
/// default error formatting string getter
|
||||
hawk_errstr_t dflerrstr;
|
||||
hawk_errstr_t dflerrstr;
|
||||
/// Stream to read script from
|
||||
Stream* sstream;
|
||||
/// I/O stream to read data from
|
||||
@ -408,7 +408,7 @@ public:
|
||||
} out;
|
||||
|
||||
hawk_cmgr_t* cmgr;
|
||||
|
||||
|
||||
|
||||
static void on_sed_close (hawk_sed_t* sed, void* ctx);
|
||||
void clearInputData ();
|
||||
|
260
lib/Hawk.cpp
260
lib/Hawk.cpp
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
*
|
||||
Copyright (c) 2006-2020 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@ -80,7 +80,7 @@ static MmgrStd __attribute__((init_priority(101))) std_dfl_mmgr; //<- this solve
|
||||
#else
|
||||
static MmgrStd std_dfl_mmgr; //<-- has an issue for undefined initialization order
|
||||
#endif
|
||||
Mmgr* Mmgr::dfl_mmgr = &std_dfl_mmgr;
|
||||
Mmgr* Mmgr::dfl_mmgr = &std_dfl_mmgr;
|
||||
//Mmgr* Mmgr::dfl_mmgr = MmgrStd::getInstance(); //<--- has an issue as well
|
||||
Mmgr* Mmgr::getDFL () HAWK_CXX_NOEXCEPT
|
||||
{
|
||||
@ -89,7 +89,7 @@ Mmgr* Mmgr::getDFL () HAWK_CXX_NOEXCEPT
|
||||
#else
|
||||
// C++ initialization order across translation units are not defined.
|
||||
// so it's tricky to work around this... the init_priority attribute
|
||||
// can solve this problem. but it's compiler dependent.
|
||||
// can solve this problem. but it's compiler dependent.
|
||||
// Mmgr::getDFL() resets dfl_mmgr to &std_dfl_mmgr if it's NULL.
|
||||
Mmgr* Mmgr::dfl_mmgr = HAWK_NULL;
|
||||
|
||||
@ -167,7 +167,7 @@ Hawk::File::Mode Hawk::File::getMode () const
|
||||
// Hawk::Console
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
Hawk::Console::Console (Run* run, hawk_rio_arg_t* riod):
|
||||
Hawk::Console::Console (Run* run, hawk_rio_arg_t* riod):
|
||||
RIOBase (run, riod), filename (HAWK_NULL)
|
||||
{
|
||||
}
|
||||
@ -283,7 +283,7 @@ void* Hawk::Value::operator new (hawk_oow_t n, Run* run) throw ()
|
||||
return (char*)ptr + HAWK_SIZEOF(run);
|
||||
}
|
||||
|
||||
void* Hawk::Value::operator new[] (hawk_oow_t n, Run* run) throw ()
|
||||
void* Hawk::Value::operator new[] (hawk_oow_t n, Run* run) throw ()
|
||||
{
|
||||
void* ptr = hawk_rtx_allocmem (run->rtx, HAWK_SIZEOF(run) + n);
|
||||
if (ptr == HAWK_NULL) return HAWK_NULL;
|
||||
@ -293,29 +293,29 @@ void* Hawk::Value::operator new[] (hawk_oow_t n, Run* run) throw ()
|
||||
}
|
||||
|
||||
#if !defined(__BORLANDC__) && !defined(__WATCOMC__)
|
||||
void Hawk::Value::operator delete (void* ptr, Run* run)
|
||||
void Hawk::Value::operator delete (void* ptr, Run* run)
|
||||
{
|
||||
// this placement delete is to be called when the constructor
|
||||
// this placement delete is to be called when the constructor
|
||||
// throws an exception and it's caught by the caller.
|
||||
hawk_rtx_freemem (run->rtx, (char*)ptr - HAWK_SIZEOF(run));
|
||||
}
|
||||
|
||||
void Hawk::Value::operator delete[] (void* ptr, Run* run)
|
||||
void Hawk::Value::operator delete[] (void* ptr, Run* run)
|
||||
{
|
||||
// this placement delete is to be called when the constructor
|
||||
// this placement delete is to be called when the constructor
|
||||
// throws an exception and it's caught by the caller.
|
||||
hawk_rtx_freemem (run->rtx, (char*)ptr - HAWK_SIZEOF(run));
|
||||
}
|
||||
#endif
|
||||
|
||||
void Hawk::Value::operator delete (void* ptr)
|
||||
void Hawk::Value::operator delete (void* ptr)
|
||||
{
|
||||
// this delete is to be called for normal destruction.
|
||||
void* p = (char*)ptr - HAWK_SIZEOF(Run*);
|
||||
hawk_rtx_freemem ((*(Run**)p)->rtx, p);
|
||||
}
|
||||
|
||||
void Hawk::Value::operator delete[] (void* ptr)
|
||||
void Hawk::Value::operator delete[] (void* ptr)
|
||||
{
|
||||
// this delete is to be called for normal destruction.
|
||||
void* p = (char*)ptr - HAWK_SIZEOF(Run*);
|
||||
@ -323,7 +323,7 @@ void Hawk::Value::operator delete[] (void* ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
Hawk::Value::Value (): run(HAWK_NULL), val(hawk_get_nil_val())
|
||||
Hawk::Value::Value (): run(HAWK_NULL), val(hawk_get_nil_val())
|
||||
{
|
||||
this->cached.str.ptr = HAWK_NULL;
|
||||
this->cached.str.len = 0;
|
||||
@ -331,7 +331,7 @@ Hawk::Value::Value (): run(HAWK_NULL), val(hawk_get_nil_val())
|
||||
this->cached.mbs.len = 0;
|
||||
}
|
||||
|
||||
Hawk::Value::Value (Run& run): run(&run), val(hawk_get_nil_val())
|
||||
Hawk::Value::Value (Run& run): run(&run), val(hawk_get_nil_val())
|
||||
{
|
||||
this->cached.str.ptr = HAWK_NULL;
|
||||
this->cached.str.len = 0;
|
||||
@ -339,7 +339,7 @@ Hawk::Value::Value (Run& run): run(&run), val(hawk_get_nil_val())
|
||||
this->cached.mbs.len = 0;
|
||||
}
|
||||
|
||||
Hawk::Value::Value (Run* run): run(run), val(hawk_get_nil_val())
|
||||
Hawk::Value::Value (Run* run): run(run), val(hawk_get_nil_val())
|
||||
{
|
||||
this->cached.str.ptr = HAWK_NULL;
|
||||
this->cached.str.len = 0;
|
||||
@ -461,7 +461,7 @@ int Hawk::Value::getInt (hawk_int_t* v) const
|
||||
if (this->run)
|
||||
{
|
||||
int n = hawk_rtx_valtoint(this->run->rtx, this->val, &lv);
|
||||
if (n <= -1)
|
||||
if (n <= -1)
|
||||
{
|
||||
run->hawk->retrieveError (this->run);
|
||||
return -1;
|
||||
@ -601,9 +601,9 @@ int Hawk::Value::getMbs (const hawk_bch_t** str, hawk_oow_t* len) const
|
||||
|
||||
int Hawk::Value::setVal (hawk_val_t* v)
|
||||
{
|
||||
if (this->run == HAWK_NULL)
|
||||
if (this->run == HAWK_NULL)
|
||||
{
|
||||
/* no runtime context assoicated. unfortunately, i can't
|
||||
/* no runtime context assoicated. unfortunately, i can't
|
||||
* set an error number for the same reason */
|
||||
return -1;
|
||||
}
|
||||
@ -641,9 +641,9 @@ int Hawk::Value::setVal (Run* r, hawk_val_t* v)
|
||||
|
||||
int Hawk::Value::setInt (hawk_int_t v)
|
||||
{
|
||||
if (this->run == HAWK_NULL)
|
||||
if (this->run == HAWK_NULL)
|
||||
{
|
||||
/* no runtime context assoicated. unfortunately, i can't
|
||||
/* no runtime context assoicated. unfortunately, i can't
|
||||
* set an error number for the same reason */
|
||||
return -1;
|
||||
}
|
||||
@ -654,7 +654,7 @@ int Hawk::Value::setInt (Run* r, hawk_int_t v)
|
||||
{
|
||||
hawk_val_t* tmp;
|
||||
tmp = hawk_rtx_makeintval(r->rtx, v);
|
||||
if (tmp == HAWK_NULL)
|
||||
if (tmp == HAWK_NULL)
|
||||
{
|
||||
r->hawk->retrieveError (r);
|
||||
return -1;
|
||||
@ -667,9 +667,9 @@ int Hawk::Value::setInt (Run* r, hawk_int_t v)
|
||||
|
||||
int Hawk::Value::setFlt (hawk_flt_t v)
|
||||
{
|
||||
if (this->run == HAWK_NULL)
|
||||
if (this->run == HAWK_NULL)
|
||||
{
|
||||
/* no runtime context assoicated. unfortunately, i can't
|
||||
/* no runtime context assoicated. unfortunately, i can't
|
||||
* set an error number for the same reason */
|
||||
return -1;
|
||||
}
|
||||
@ -695,11 +695,11 @@ int Hawk::Value::setFlt (Run* r, hawk_flt_t v)
|
||||
|
||||
int Hawk::Value::setStr (const hawk_uch_t* str, hawk_oow_t len, bool numeric)
|
||||
{
|
||||
if (this->run == HAWK_NULL)
|
||||
if (this->run == HAWK_NULL)
|
||||
{
|
||||
/* no runtime context assoicated. unfortunately, i can't
|
||||
/* no runtime context assoicated. unfortunately, i can't
|
||||
* set an error number for the same reason */
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
return this->setStr(this->run, str, len, numeric);
|
||||
}
|
||||
@ -733,7 +733,7 @@ int Hawk::Value::setStr (Run* r, const hawk_uch_t* str, bool numeric)
|
||||
|
||||
tmp = numeric? hawk_rtx_makenumorstrvalwithuchars(r->rtx, str, hawk_count_ucstr(str)):
|
||||
hawk_rtx_makestrvalwithucstr(r->rtx, str);
|
||||
if (tmp == HAWK_NULL)
|
||||
if (tmp == HAWK_NULL)
|
||||
{
|
||||
r->hawk->retrieveError (r);
|
||||
return -1;
|
||||
@ -748,11 +748,11 @@ int Hawk::Value::setStr (Run* r, const hawk_uch_t* str, bool numeric)
|
||||
|
||||
int Hawk::Value::setStr (const hawk_bch_t* str, hawk_oow_t len, bool numeric)
|
||||
{
|
||||
if (this->run == HAWK_NULL)
|
||||
if (this->run == HAWK_NULL)
|
||||
{
|
||||
/* no runtime context assoicated. unfortunately, i can't
|
||||
/* no runtime context assoicated. unfortunately, i can't
|
||||
* set an error number for the same reason */
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
return this->setStr(this->run, str, len, numeric);
|
||||
}
|
||||
@ -786,7 +786,7 @@ int Hawk::Value::setStr (Run* r, const hawk_bch_t* str, bool numeric)
|
||||
|
||||
tmp = numeric? hawk_rtx_makenumorstrvalwithbchars(r->rtx, str, hawk_count_bcstr(str)):
|
||||
hawk_rtx_makestrvalwithbcstr(r->rtx, str);
|
||||
if (tmp == HAWK_NULL)
|
||||
if (tmp == HAWK_NULL)
|
||||
{
|
||||
r->hawk->retrieveError (r);
|
||||
return -1;
|
||||
@ -800,11 +800,11 @@ int Hawk::Value::setStr (Run* r, const hawk_bch_t* str, bool numeric)
|
||||
//////////////////////////////////////////////////////////////////
|
||||
int Hawk::Value::setMbs (const hawk_bch_t* str, hawk_oow_t len)
|
||||
{
|
||||
if (this->run == HAWK_NULL)
|
||||
if (this->run == HAWK_NULL)
|
||||
{
|
||||
/* no runtime context assoicated. unfortunately, i can't
|
||||
/* no runtime context assoicated. unfortunately, i can't
|
||||
* set an error number for the same reason */
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
return this->setMbs(this->run, str, len);
|
||||
}
|
||||
@ -839,7 +839,7 @@ int Hawk::Value::setMbs (Run* r, const hawk_bch_t* str)
|
||||
{
|
||||
hawk_val_t* tmp;
|
||||
tmp = hawk_rtx_makembsvalwithbchars(r->rtx, str, hawk_count_bcstr(str));
|
||||
if (!tmp)
|
||||
if (!tmp)
|
||||
{
|
||||
r->hawk->retrieveError (r);
|
||||
return -1;
|
||||
@ -862,10 +862,10 @@ int Hawk::Value::setIndexedVal (Run* r, const Index& idx, hawk_val_t* v)
|
||||
|
||||
if (HAWK_RTX_GETVALTYPE(r->rtx, this->val) != HAWK_VAL_MAP)
|
||||
{
|
||||
// the previous value is not a map.
|
||||
// the previous value is not a map.
|
||||
// a new map value needs to be created first.
|
||||
hawk_val_t* map = hawk_rtx_makemapval(r->rtx);
|
||||
if (map == HAWK_NULL)
|
||||
if (map == HAWK_NULL)
|
||||
{
|
||||
r->hawk->retrieveError (r);
|
||||
return -1;
|
||||
@ -873,7 +873,7 @@ int Hawk::Value::setIndexedVal (Run* r, const Index& idx, hawk_val_t* v)
|
||||
|
||||
hawk_rtx_refupval (r->rtx, map);
|
||||
|
||||
// update the map with a given value
|
||||
// update the map with a given value
|
||||
if (hawk_rtx_setmapvalfld(r->rtx, map, idx.ptr, idx.len, v) == HAWK_NULL)
|
||||
{
|
||||
hawk_rtx_refdownval (r->rtx, map);
|
||||
@ -882,7 +882,7 @@ int Hawk::Value::setIndexedVal (Run* r, const Index& idx, hawk_val_t* v)
|
||||
}
|
||||
|
||||
// free the previous value
|
||||
if (this->run)
|
||||
if (this->run)
|
||||
{
|
||||
// if val is not nil, this->run can't be NULL
|
||||
hawk_rtx_refdownval (this->run->rtx, this->val);
|
||||
@ -895,10 +895,10 @@ int Hawk::Value::setIndexedVal (Run* r, const Index& idx, hawk_val_t* v)
|
||||
{
|
||||
HAWK_ASSERT (run != HAWK_NULL);
|
||||
|
||||
// if the previous value is a map, things are a bit simpler
|
||||
// if the previous value is a map, things are a bit simpler
|
||||
// however it needs to check if the runtime context matches
|
||||
// with the previous one.
|
||||
if (this->run != r)
|
||||
if (this->run != r)
|
||||
{
|
||||
// it can't span across multiple runtime contexts
|
||||
this->run->setError (HAWK_EINVAL);
|
||||
@ -906,7 +906,7 @@ int Hawk::Value::setIndexedVal (Run* r, const Index& idx, hawk_val_t* v)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// update the map with a given value
|
||||
// update the map with a given value
|
||||
if (hawk_rtx_setmapvalfld(r->rtx, val, idx.ptr, idx.len, v) == HAWK_NULL)
|
||||
{
|
||||
r->hawk->retrieveError (r);
|
||||
@ -926,7 +926,7 @@ int Hawk::Value::setIndexedInt (const Index& idx, hawk_int_t v)
|
||||
int Hawk::Value::setIndexedInt (Run* r, const Index& idx, hawk_int_t v)
|
||||
{
|
||||
hawk_val_t* tmp = hawk_rtx_makeintval (r->rtx, v);
|
||||
if (tmp == HAWK_NULL)
|
||||
if (tmp == HAWK_NULL)
|
||||
{
|
||||
r->hawk->retrieveError (r);
|
||||
return -1;
|
||||
@ -948,7 +948,7 @@ int Hawk::Value::setIndexedFlt (const Index& idx, hawk_flt_t v)
|
||||
int Hawk::Value::setIndexedFlt (Run* r, const Index& idx, hawk_flt_t v)
|
||||
{
|
||||
hawk_val_t* tmp = hawk_rtx_makefltval(r->rtx, v);
|
||||
if (tmp == HAWK_NULL)
|
||||
if (tmp == HAWK_NULL)
|
||||
{
|
||||
r->hawk->retrieveError (r);
|
||||
return -1;
|
||||
@ -975,7 +975,7 @@ int Hawk::Value::setIndexedStr (Run* r, const Index& idx, const hawk_uch_t* str,
|
||||
|
||||
tmp = numeric? hawk_rtx_makenumorstrvalwithuchars(r->rtx, str, len):
|
||||
hawk_rtx_makestrvalwithuchars(r->rtx, str, len);
|
||||
if (HAWK_UNLIKELY(!tmp))
|
||||
if (HAWK_UNLIKELY(!tmp))
|
||||
{
|
||||
r->hawk->retrieveError (r);
|
||||
return -1;
|
||||
@ -1126,8 +1126,8 @@ int Hawk::Value::getIndexed (const Index& idx, Value* v) const
|
||||
{
|
||||
HAWK_ASSERT (val != HAWK_NULL);
|
||||
|
||||
// not a map. v is just nil. not an error
|
||||
if (HAWK_RTX_GETVALTYPE(this->run->rtx, val) != HAWK_VAL_MAP)
|
||||
// not a map. v is just nil. not an error
|
||||
if (HAWK_RTX_GETVALTYPE(this->run->rtx, val) != HAWK_VAL_MAP)
|
||||
{
|
||||
v->clear ();
|
||||
return 0;
|
||||
@ -1136,14 +1136,14 @@ int Hawk::Value::getIndexed (const Index& idx, Value* v) const
|
||||
// get the value from the map.
|
||||
hawk_val_t* fv = hawk_rtx_getmapvalfld(this->run->rtx, val, (hawk_ooch_t*)idx.ptr, idx.len);
|
||||
|
||||
// the key is not found. it is not an error. v is just nil
|
||||
// the key is not found. it is not an error. v is just nil
|
||||
if (fv == HAWK_NULL)
|
||||
{
|
||||
v->clear ();
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// if v.set fails, it should return an error
|
||||
// if v.set fails, it should return an error
|
||||
return v->setVal (this->run, fv);
|
||||
}
|
||||
|
||||
@ -1202,7 +1202,7 @@ Hawk::Run::~Run ()
|
||||
{
|
||||
}
|
||||
|
||||
void Hawk::Run::halt () const
|
||||
void Hawk::Run::halt () const
|
||||
{
|
||||
HAWK_ASSERT (this->rtx != HAWK_NULL);
|
||||
hawk_rtx_halt (this->rtx);
|
||||
@ -1214,19 +1214,19 @@ bool Hawk::Run::isHalt () const
|
||||
return !!hawk_rtx_ishalt(this->rtx);
|
||||
}
|
||||
|
||||
hawk_errnum_t Hawk::Run::getErrorNumber () const
|
||||
hawk_errnum_t Hawk::Run::getErrorNumber () const
|
||||
{
|
||||
HAWK_ASSERT (this->rtx != HAWK_NULL);
|
||||
return hawk_rtx_geterrnum(this->rtx);
|
||||
}
|
||||
|
||||
hawk_loc_t Hawk::Run::getErrorLocation () const
|
||||
hawk_loc_t Hawk::Run::getErrorLocation () const
|
||||
{
|
||||
HAWK_ASSERT (this->rtx != HAWK_NULL);
|
||||
return *hawk_rtx_geterrloc(this->rtx);
|
||||
}
|
||||
|
||||
const hawk_ooch_t* Hawk::Run::getErrorMessage () const
|
||||
const hawk_ooch_t* Hawk::Run::getErrorMessage () const
|
||||
{
|
||||
HAWK_ASSERT (this->rtx != HAWK_NULL);
|
||||
return hawk_rtx_geterrmsg(this->rtx);
|
||||
@ -1366,15 +1366,15 @@ int Hawk::Run::getGlobal (int id, Value& g) const
|
||||
// Hawk
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
Hawk::Hawk (Mmgr* mmgr):
|
||||
Mmged(mmgr), hawk(HAWK_NULL),
|
||||
Hawk::Hawk (Mmgr* mmgr):
|
||||
Mmged(mmgr), hawk(HAWK_NULL),
|
||||
#if defined(HAWK_USE_HTB_FOR_FUNCTION_MAP)
|
||||
functionMap(HAWK_NULL),
|
||||
functionMap(HAWK_NULL),
|
||||
#else
|
||||
functionMap(this),
|
||||
functionMap(this),
|
||||
#endif
|
||||
source_reader(HAWK_NULL), source_writer(HAWK_NULL),
|
||||
pipe_handler(HAWK_NULL), file_handler(HAWK_NULL),
|
||||
pipe_handler(HAWK_NULL), file_handler(HAWK_NULL),
|
||||
console_handler(HAWK_NULL), runctx(this)
|
||||
|
||||
{
|
||||
@ -1384,35 +1384,35 @@ Hawk::Hawk (Mmgr* mmgr):
|
||||
this->_cmgr = hawk_get_cmgr_by_id(HAWK_CMGR_UTF8);
|
||||
}
|
||||
|
||||
const hawk_ooch_t* Hawk::getErrorString (hawk_errnum_t num) const
|
||||
const hawk_ooch_t* Hawk::getErrorString (hawk_errnum_t num) const
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
HAWK_ASSERT (this->dflerrstr != HAWK_NULL);
|
||||
return this->dflerrstr(num);
|
||||
}
|
||||
|
||||
const hawk_ooch_t* Hawk::xerrstr (hawk_t* a, hawk_errnum_t num)
|
||||
const hawk_ooch_t* Hawk::xerrstr (hawk_t* a, hawk_errnum_t num)
|
||||
{
|
||||
Hawk* hawk = *(Hawk**)GET_XTN(a);
|
||||
return hawk->getErrorString(num);
|
||||
}
|
||||
|
||||
hawk_errnum_t Hawk::getErrorNumber () const
|
||||
hawk_errnum_t Hawk::getErrorNumber () const
|
||||
{
|
||||
return this->errinf.num;
|
||||
}
|
||||
|
||||
hawk_loc_t Hawk::getErrorLocation () const
|
||||
hawk_loc_t Hawk::getErrorLocation () const
|
||||
{
|
||||
return this->errinf.loc;
|
||||
}
|
||||
|
||||
const hawk_ooch_t* Hawk::getErrorLocationFile () const
|
||||
const hawk_ooch_t* Hawk::getErrorLocationFile () const
|
||||
{
|
||||
return this->errinf.loc.file;
|
||||
}
|
||||
|
||||
const hawk_uch_t* Hawk::getErrorLocationFileU () const
|
||||
const hawk_uch_t* Hawk::getErrorLocationFileU () const
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
return this->errinf.loc.file;
|
||||
@ -1425,7 +1425,7 @@ const hawk_uch_t* Hawk::getErrorLocationFileU () const
|
||||
#endif
|
||||
}
|
||||
|
||||
const hawk_bch_t* Hawk::getErrorLocationFileB () const
|
||||
const hawk_bch_t* Hawk::getErrorLocationFileB () const
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
if (!this->errinf.loc.file) return HAWK_NULL;
|
||||
@ -1438,12 +1438,12 @@ const hawk_bch_t* Hawk::getErrorLocationFileB () const
|
||||
#endif
|
||||
}
|
||||
|
||||
const hawk_ooch_t* Hawk::getErrorMessage () const
|
||||
const hawk_ooch_t* Hawk::getErrorMessage () const
|
||||
{
|
||||
return this->errinf.msg;
|
||||
}
|
||||
|
||||
const hawk_uch_t* Hawk::getErrorMessageU () const
|
||||
const hawk_uch_t* Hawk::getErrorMessageU () const
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
return this->errinf.msg;
|
||||
@ -1455,7 +1455,7 @@ const hawk_uch_t* Hawk::getErrorMessageU () const
|
||||
#endif
|
||||
}
|
||||
|
||||
const hawk_bch_t* Hawk::getErrorMessageB () const
|
||||
const hawk_bch_t* Hawk::getErrorMessageB () const
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
hawk_oow_t wcslen, mbslen;
|
||||
@ -1529,7 +1529,7 @@ void Hawk::clearError ()
|
||||
|
||||
void Hawk::retrieveError ()
|
||||
{
|
||||
if (this->hawk == HAWK_NULL)
|
||||
if (this->hawk == HAWK_NULL)
|
||||
{
|
||||
this->clearError ();
|
||||
}
|
||||
@ -1558,7 +1558,7 @@ static void clear_xtn (hawk_t* hawk, void* ctx)
|
||||
xtn->hawk->uponClearing ();
|
||||
}
|
||||
|
||||
int Hawk::open ()
|
||||
int Hawk::open ()
|
||||
{
|
||||
HAWK_ASSERT (this->hawk == HAWK_NULL);
|
||||
#if defined(HAWK_USE_HTB_FOR_FUNCTION_MAP)
|
||||
@ -1617,8 +1617,8 @@ int Hawk::open ()
|
||||
HAWK_HTB_COPIER_INLINE // copy the value into the pair
|
||||
},
|
||||
{
|
||||
HAWK_HTB_FREEER_DEFAULT, // free nothing
|
||||
HAWK_HTB_FREEER_DEFAULT // free nothing
|
||||
HAWK_HTB_FREEER_DEFAULT, // free nothing
|
||||
HAWK_HTB_FREEER_DEFAULT // free nothing
|
||||
},
|
||||
HAWK_HTB_COMPER_DEFAULT,
|
||||
HAWK_HTB_KEEPER_DEFAULT,
|
||||
@ -1626,7 +1626,7 @@ int Hawk::open ()
|
||||
HAWK_HTB_HASHER_DEFAULT
|
||||
};
|
||||
hawk_htb_setstyle (this->functionMap, &style);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// push the call back after everything else is ok.
|
||||
@ -1634,7 +1634,7 @@ int Hawk::open ()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Hawk::close ()
|
||||
void Hawk::close ()
|
||||
{
|
||||
this->fini_runctx ();
|
||||
this->clearArguments ();
|
||||
@ -1649,7 +1649,7 @@ void Hawk::close ()
|
||||
this->functionMap.clear ();
|
||||
#endif
|
||||
|
||||
if (this->hawk)
|
||||
if (this->hawk)
|
||||
{
|
||||
hawk_close (this->hawk);
|
||||
this->hawk = HAWK_NULL;
|
||||
@ -1679,11 +1679,11 @@ void Hawk::uponClearing ()
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
Hawk::Run* Hawk::parse (Source& in, Source& out)
|
||||
Hawk::Run* Hawk::parse (Source& in, Source& out)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
|
||||
if (&in == &Source::NONE)
|
||||
if (&in == &Source::NONE)
|
||||
{
|
||||
this->setError (HAWK_EINVAL);
|
||||
return HAWK_NULL;
|
||||
@ -1699,7 +1699,7 @@ Hawk::Run* Hawk::parse (Source& in, Source& out)
|
||||
sio.out = (source_writer == HAWK_NULL)? HAWK_NULL: Hawk::writeSource;
|
||||
|
||||
int n = hawk_parse(this->hawk, &sio);
|
||||
if (n <= -1)
|
||||
if (n <= -1)
|
||||
{
|
||||
this->retrieveError ();
|
||||
return HAWK_NULL;
|
||||
@ -1726,7 +1726,7 @@ int Hawk::loop (Value* ret)
|
||||
HAWK_ASSERT (this->runctx.rtx != HAWK_NULL);
|
||||
|
||||
hawk_val_t* rv = hawk_rtx_loop (this->runctx.rtx);
|
||||
if (rv == HAWK_NULL)
|
||||
if (rv == HAWK_NULL)
|
||||
{
|
||||
this->retrieveError (&this->runctx);
|
||||
return -1;
|
||||
@ -1734,7 +1734,7 @@ int Hawk::loop (Value* ret)
|
||||
|
||||
ret->setVal (&this->runctx, rv);
|
||||
hawk_rtx_refdownval (this->runctx.rtx, rv);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1767,7 +1767,7 @@ int Hawk::call (const hawk_bch_t* name, Value* ret, const Value* args, hawk_oow_
|
||||
|
||||
if (ptr != HAWK_NULL && ptr != buf) hawk_freemem (this->hawk, ptr);
|
||||
|
||||
if (rv == HAWK_NULL)
|
||||
if (rv == HAWK_NULL)
|
||||
{
|
||||
this->retrieveError (&this->runctx);
|
||||
return -1;
|
||||
@ -1808,7 +1808,7 @@ int Hawk::call (const hawk_uch_t* name, Value* ret, const Value* args, hawk_oow_
|
||||
|
||||
if (ptr != HAWK_NULL && ptr != buf) hawk_freemem (this->hawk, ptr);
|
||||
|
||||
if (rv == HAWK_NULL)
|
||||
if (rv == HAWK_NULL)
|
||||
{
|
||||
this->retrieveError (&this->runctx);
|
||||
return -1;
|
||||
@ -1834,13 +1834,13 @@ int Hawk::exec (Value* ret, const Value* args, hawk_oow_t nargs)
|
||||
return n;
|
||||
}
|
||||
|
||||
void Hawk::halt ()
|
||||
void Hawk::halt ()
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
hawk_haltall (this->hawk);
|
||||
}
|
||||
|
||||
int Hawk::init_runctx ()
|
||||
int Hawk::init_runctx ()
|
||||
{
|
||||
if (this->runctx.rtx) return 0;
|
||||
|
||||
@ -1851,7 +1851,7 @@ int Hawk::init_runctx ()
|
||||
rio.console = consoleHandler;
|
||||
|
||||
hawk_rtx_t* rtx = hawk_rtx_open(this->hawk, HAWK_SIZEOF(rxtn_t), &rio);
|
||||
if (HAWK_UNLIKELY(!rtx))
|
||||
if (HAWK_UNLIKELY(!rtx))
|
||||
{
|
||||
this->retrieveError();
|
||||
return -1;
|
||||
@ -1866,7 +1866,7 @@ int Hawk::init_runctx ()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Hawk::fini_runctx ()
|
||||
void Hawk::fini_runctx ()
|
||||
{
|
||||
if (this->runctx.rtx)
|
||||
{
|
||||
@ -1875,7 +1875,7 @@ void Hawk::fini_runctx ()
|
||||
}
|
||||
}
|
||||
|
||||
int Hawk::getTrait () const
|
||||
int Hawk::getTrait () const
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
int val;
|
||||
@ -1883,13 +1883,13 @@ int Hawk::getTrait () const
|
||||
return val;
|
||||
}
|
||||
|
||||
void Hawk::setTrait (int trait)
|
||||
void Hawk::setTrait (int trait)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
hawk_setopt (this->hawk, HAWK_OPT_TRAIT, &trait);
|
||||
}
|
||||
|
||||
hawk_oow_t Hawk::getMaxDepth (depth_t id) const
|
||||
hawk_oow_t Hawk::getMaxDepth (depth_t id) const
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
|
||||
@ -1898,7 +1898,7 @@ hawk_oow_t Hawk::getMaxDepth (depth_t id) const
|
||||
return depth;
|
||||
}
|
||||
|
||||
void Hawk::setMaxDepth (depth_t id, hawk_oow_t depth)
|
||||
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);
|
||||
@ -1941,12 +1941,12 @@ int Hawk::dispatch_function (Run* run, const hawk_fnc_info_t* fi)
|
||||
#if defined(HAWK_USE_HTB_FOR_FUNCTION_MAP)
|
||||
hawk_htb_pair_t* pair;
|
||||
pair = hawk_htb_search(this->functionMap, fi->name.ptr, fi->name.len);
|
||||
if (pair == HAWK_NULL)
|
||||
if (pair == HAWK_NULL)
|
||||
{
|
||||
run->formatError (HAWK_EFUNNF, HAWK_NULL, HAWK_T("function '%.*js' not defined"), &fi->name.len, &fi->name.ptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
FunctionHandler handler;
|
||||
handler = *(FunctionHandler*)HAWK_HTB_VPTR(pair);
|
||||
#else
|
||||
@ -1970,19 +1970,19 @@ int Hawk::dispatch_function (Run* run, const hawk_fnc_info_t* fi)
|
||||
{
|
||||
#if defined(AWK_VALUE_USE_IN_CLASS_PLACEMENT_NEW)
|
||||
args = new(run) Value[nargs];
|
||||
if (args == HAWK_NULL)
|
||||
if (args == HAWK_NULL)
|
||||
{
|
||||
run->setError (HAWK_ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
try
|
||||
{
|
||||
//args = (Value*)::operator new (HAWK_SIZEOF(Value) * nargs, this->getMmgr());
|
||||
try
|
||||
{
|
||||
//args = (Value*)::operator new (HAWK_SIZEOF(Value) * nargs, this->getMmgr());
|
||||
args = (Value*)this->getMmgr()->allocate(HAWK_SIZEOF(Value) * nargs);
|
||||
}
|
||||
catch (...) { args = HAWK_NULL; }
|
||||
if (args == HAWK_NULL)
|
||||
if (args == HAWK_NULL)
|
||||
{
|
||||
run->setError (HAWK_ENOMEM);
|
||||
return -1;
|
||||
@ -1990,7 +1990,7 @@ int Hawk::dispatch_function (Run* run, const hawk_fnc_info_t* fi)
|
||||
for (i = 0; i < nargs; i++)
|
||||
{
|
||||
// call the default constructor on the space allocated above.
|
||||
// no exception handling is implemented here as i know
|
||||
// no exception handling is implemented here as i know
|
||||
// that Value::Value() doesn't throw an exception
|
||||
new((HAWK::Mmgr*)HAWK_NULL, (void*)&args[i]) Value ();
|
||||
}
|
||||
@ -2055,7 +2055,7 @@ int Hawk::dispatch_function (Run* run, const hawk_fnc_info_t* fi)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Value ret (run);
|
||||
|
||||
int n;
|
||||
@ -2082,7 +2082,7 @@ int Hawk::dispatch_function (Run* run, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
}
|
||||
|
||||
if (args != buf)
|
||||
if (args != buf)
|
||||
{
|
||||
#if defined(AWK_VALUE_USE_IN_CLASS_PLACEMENT_NEW)
|
||||
delete[] args;
|
||||
@ -2098,9 +2098,9 @@ int Hawk::dispatch_function (Run* run, const hawk_fnc_info_t* fi)
|
||||
#endif
|
||||
}
|
||||
|
||||
if (n <= -1)
|
||||
if (n <= -1)
|
||||
{
|
||||
/* this is really the handler error. the underlying engine
|
||||
/* this is really the handler error. the underlying engine
|
||||
* will take care of the error code. */
|
||||
return -1;
|
||||
}
|
||||
@ -2109,7 +2109,7 @@ int Hawk::dispatch_function (Run* run, const hawk_fnc_info_t* fi)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Hawk::xstrs_t::add (hawk_t* hawk, const hawk_uch_t* arg, hawk_oow_t len)
|
||||
int Hawk::xstrs_t::add (hawk_t* hawk, const hawk_uch_t* arg, hawk_oow_t len)
|
||||
{
|
||||
if (this->len >= this->capa)
|
||||
{
|
||||
@ -2170,7 +2170,7 @@ int Hawk::xstrs_t::add (hawk_t* hawk, const hawk_bch_t* arg, hawk_oow_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Hawk::xstrs_t::clear (hawk_t* hawk)
|
||||
void Hawk::xstrs_t::clear (hawk_t* hawk)
|
||||
{
|
||||
if (this->ptr != HAWK_NULL)
|
||||
{
|
||||
@ -2183,7 +2183,7 @@ void Hawk::xstrs_t::clear (hawk_t* hawk)
|
||||
}
|
||||
}
|
||||
|
||||
int Hawk::addArgument (const hawk_uch_t* arg, hawk_oow_t len)
|
||||
int Hawk::addArgument (const hawk_uch_t* arg, hawk_oow_t len)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
int n = this->runarg.add(this->hawk, arg, len);
|
||||
@ -2191,12 +2191,12 @@ int Hawk::addArgument (const hawk_uch_t* arg, hawk_oow_t len)
|
||||
return n;
|
||||
}
|
||||
|
||||
int Hawk::addArgument (const hawk_uch_t* arg)
|
||||
int Hawk::addArgument (const hawk_uch_t* arg)
|
||||
{
|
||||
return this->addArgument(arg, hawk_count_ucstr(arg));
|
||||
}
|
||||
|
||||
int Hawk::addArgument (const hawk_bch_t* arg, hawk_oow_t len)
|
||||
int Hawk::addArgument (const hawk_bch_t* arg, hawk_oow_t len)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
int n = this->runarg.add(this->hawk, arg, len);
|
||||
@ -2204,17 +2204,17 @@ int Hawk::addArgument (const hawk_bch_t* arg, hawk_oow_t len)
|
||||
return n;
|
||||
}
|
||||
|
||||
int Hawk::addArgument (const hawk_bch_t* arg)
|
||||
int Hawk::addArgument (const hawk_bch_t* arg)
|
||||
{
|
||||
return this->addArgument(arg, hawk_count_bcstr(arg));
|
||||
}
|
||||
|
||||
void Hawk::clearArguments ()
|
||||
void Hawk::clearArguments ()
|
||||
{
|
||||
this->runarg.clear (this->hawk);
|
||||
}
|
||||
|
||||
int Hawk::addGlobal(const hawk_bch_t* name)
|
||||
int Hawk::addGlobal(const hawk_bch_t* name)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
int n = hawk_addgblwithbcstr(this->hawk, name);
|
||||
@ -2222,7 +2222,7 @@ int Hawk::addGlobal(const hawk_bch_t* name)
|
||||
return n;
|
||||
}
|
||||
|
||||
int Hawk::addGlobal(const hawk_uch_t* name)
|
||||
int Hawk::addGlobal(const hawk_uch_t* name)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
int n = hawk_addgblwithucstr(this->hawk, name);
|
||||
@ -2230,7 +2230,7 @@ int Hawk::addGlobal(const hawk_uch_t* name)
|
||||
return n;
|
||||
}
|
||||
|
||||
int Hawk::deleteGlobal (const hawk_bch_t* name)
|
||||
int Hawk::deleteGlobal (const hawk_bch_t* name)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
int n = hawk_delgblwithbcstr(this->hawk, name);
|
||||
@ -2238,7 +2238,7 @@ int Hawk::deleteGlobal (const hawk_bch_t* name)
|
||||
return n;
|
||||
}
|
||||
|
||||
int Hawk::deleteGlobal (const hawk_uch_t* name)
|
||||
int Hawk::deleteGlobal (const hawk_uch_t* name)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
int n = hawk_delgblwithucstr(this->hawk, name);
|
||||
@ -2247,7 +2247,7 @@ int Hawk::deleteGlobal (const hawk_uch_t* name)
|
||||
}
|
||||
|
||||
|
||||
int Hawk::findGlobal (const hawk_bch_t* name, bool inc_builtins)
|
||||
int Hawk::findGlobal (const hawk_bch_t* name, bool inc_builtins)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
int n = hawk_findgblwithbcstr(this->hawk, name, inc_builtins);
|
||||
@ -2255,7 +2255,7 @@ int Hawk::findGlobal (const hawk_bch_t* name, bool inc_builtins)
|
||||
return n;
|
||||
}
|
||||
|
||||
int Hawk::findGlobal (const hawk_uch_t* name, bool inc_builtins)
|
||||
int Hawk::findGlobal (const hawk_uch_t* name, bool inc_builtins)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
int n = hawk_findgblwithucstr(this->hawk, name, inc_builtins);
|
||||
@ -2263,12 +2263,12 @@ int Hawk::findGlobal (const hawk_uch_t* name, bool inc_builtins)
|
||||
return n;
|
||||
}
|
||||
|
||||
int Hawk::setGlobal (int id, const Value& v)
|
||||
int Hawk::setGlobal (int id, const Value& v)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
HAWK_ASSERT (this->runctx.rtx != HAWK_NULL);
|
||||
|
||||
if (v.run != &this->runctx)
|
||||
if (v.run != &this->runctx)
|
||||
{
|
||||
this->setError (HAWK_EINVAL);
|
||||
return -1;
|
||||
@ -2279,7 +2279,7 @@ int Hawk::setGlobal (int id, const Value& v)
|
||||
return n;
|
||||
}
|
||||
|
||||
int Hawk::getGlobal (int id, Value& v)
|
||||
int Hawk::getGlobal (int id, Value& v)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
HAWK_ASSERT (runctx.rtx != HAWK_NULL);
|
||||
@ -2290,7 +2290,7 @@ int Hawk::getGlobal (int id, Value& v)
|
||||
}
|
||||
|
||||
int Hawk::addFunction (
|
||||
const hawk_bch_t* name, hawk_oow_t minArgs, hawk_oow_t maxArgs,
|
||||
const hawk_bch_t* name, hawk_oow_t minArgs, hawk_oow_t maxArgs,
|
||||
const hawk_bch_t* argSpec, FunctionHandler handler, int validOpts)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
@ -2305,14 +2305,14 @@ int Hawk::addFunction (
|
||||
spec.trait = validOpts;
|
||||
|
||||
hawk_fnc_t* fnc = hawk_addfncwithbcstr(this->hawk, name, &spec);
|
||||
if (fnc == HAWK_NULL)
|
||||
if (fnc == HAWK_NULL)
|
||||
{
|
||||
this->retrieveError ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(HAWK_USE_HTB_FOR_FUNCTION_MAP)
|
||||
// handler is a pointer to a member function.
|
||||
// handler is a pointer to a member function.
|
||||
// sizeof(handler) is likely to be greater than sizeof(void*)
|
||||
// copy the handler pointer into the table.
|
||||
//
|
||||
@ -2341,7 +2341,7 @@ int Hawk::addFunction (
|
||||
}
|
||||
|
||||
int Hawk::addFunction (
|
||||
const hawk_uch_t* name, hawk_oow_t minArgs, hawk_oow_t maxArgs,
|
||||
const hawk_uch_t* name, hawk_oow_t minArgs, hawk_oow_t maxArgs,
|
||||
const hawk_uch_t* argSpec, FunctionHandler handler, int validOpts)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
@ -2356,14 +2356,14 @@ int Hawk::addFunction (
|
||||
spec.trait = validOpts;
|
||||
|
||||
hawk_fnc_t* fnc = hawk_addfncwithucstr(this->hawk, name, &spec);
|
||||
if (fnc == HAWK_NULL)
|
||||
if (fnc == HAWK_NULL)
|
||||
{
|
||||
this->retrieveError ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(HAWK_USE_HTB_FOR_FUNCTION_MAP)
|
||||
// handler is a pointer to a member function.
|
||||
// handler is a pointer to a member function.
|
||||
// sizeof(handler) is likely to be greater than sizeof(void*)
|
||||
// copy the handler pointer into the table.
|
||||
//
|
||||
@ -2391,12 +2391,12 @@ int Hawk::addFunction (
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Hawk::deleteFunction (const hawk_ooch_t* name)
|
||||
int Hawk::deleteFunction (const hawk_ooch_t* name)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
|
||||
int n = hawk_delfnc(this->hawk, name);
|
||||
if (n == 0)
|
||||
if (n == 0)
|
||||
{
|
||||
#if defined(HAWK_USE_HTB_FOR_FUNCTION_MAP)
|
||||
hawk_htb_delete (this->functionMap, name, hawk_count_oocstr(name));
|
||||
@ -2481,7 +2481,7 @@ hawk_ooi_t Hawk::pipeHandler (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_arg_
|
||||
|
||||
case HAWK_RIO_CMD_FLUSH:
|
||||
return hawk->pipe_handler->flush(pipe);
|
||||
|
||||
|
||||
default:
|
||||
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
|
||||
return -1;
|
||||
@ -2508,10 +2508,10 @@ hawk_ooi_t Hawk::pipeHandler (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_arg_
|
||||
|
||||
case HAWK_RIO_CMD_WRITE_BYTES:
|
||||
return hawk->writePipeBytes(pipe, (const hawk_bch_t*)data, count);
|
||||
|
||||
|
||||
case HAWK_RIO_CMD_FLUSH:
|
||||
return hawk->flushPipe(pipe);
|
||||
|
||||
|
||||
default:
|
||||
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
|
||||
return -1;
|
||||
@ -2558,7 +2558,7 @@ hawk_ooi_t Hawk::fileHandler (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_arg_
|
||||
|
||||
case HAWK_RIO_CMD_FLUSH:
|
||||
return hawk->file_handler->flush(file);
|
||||
|
||||
|
||||
default:
|
||||
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
|
||||
return -1;
|
||||
|
302
lib/Hawk.hpp
302
lib/Hawk.hpp
@ -67,22 +67,22 @@ HAWK_BEGIN_NAMESPACE(HAWK)
|
||||
#define HAWK_CXX_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1)))
|
||||
|
||||
#elif (__cplusplus >= 199711L) // C++98
|
||||
#undef HAWK_LANG_CXX11
|
||||
#undef HAWK_LANG_CXX11
|
||||
#define HAWK_CXX_NOEXCEPT throw()
|
||||
|
||||
#define HAWK_CXX_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name())
|
||||
#define HAWK_CXX_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1)))
|
||||
#else
|
||||
#undef HAWK_LANG_CXX11
|
||||
#define HAWK_CXX_NOEXCEPT
|
||||
#undef HAWK_LANG_CXX11
|
||||
#define HAWK_CXX_NOEXCEPT
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
|
||||
// Explicit destructor call requires a class name depending on the
|
||||
// C++ standard/compiler.
|
||||
//
|
||||
// C++ standard/compiler.
|
||||
//
|
||||
// Node* x;
|
||||
// x->~Node ();
|
||||
// x->~Node ();
|
||||
//
|
||||
// While x->~Node() is ok with modern compilers, some old compilers
|
||||
// like BCC55 required the class name in the call as shown below.
|
||||
@ -95,7 +95,7 @@ HAWK_BEGIN_NAMESPACE(HAWK)
|
||||
|
||||
#elif defined(__WATCOMC__)
|
||||
// WATCOM has a problem with this syntax.
|
||||
// Node* x; x->Node::~Node().
|
||||
// Node* x; x->Node::~Node().
|
||||
// But it doesn't support operator delete overloading.
|
||||
|
||||
#define HAWK_CXX_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name())
|
||||
@ -159,11 +159,11 @@ class HAWK_EXPORT Exception
|
||||
{
|
||||
public:
|
||||
Exception (
|
||||
const hawk_ooch_t* name, const hawk_ooch_t* msg,
|
||||
const hawk_ooch_t* file, hawk_oow_t line) HAWK_CXX_NOEXCEPT:
|
||||
const hawk_ooch_t* name, const hawk_ooch_t* msg,
|
||||
const hawk_ooch_t* file, hawk_oow_t line) HAWK_CXX_NOEXCEPT:
|
||||
name(name), msg(msg)
|
||||
#if !defined(HAWK_NO_LOCATION_IN_EXCEPTION)
|
||||
, file(file), line(line)
|
||||
, file(file), line(line)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
@ -214,21 +214,21 @@ private:
|
||||
|
||||
///
|
||||
/// The Mmgr class defines a memory manager interface that can be inherited
|
||||
/// by a class in need of a memory manager as defined in the primitive
|
||||
/// by a class in need of a memory manager as defined in the primitive
|
||||
/// #hawk_mmgr_t type. Using the class over the primitive type enables you to
|
||||
/// write code in more object-oriented fashion. An inheriting class should
|
||||
/// write code in more object-oriented fashion. An inheriting class should
|
||||
/// implement three pure virtual functions.
|
||||
///
|
||||
/// You are free to call allocMem(), reallocMem(), and freeMem() in C++ context
|
||||
/// where no exception raising is desired. If you want an exception to be
|
||||
/// where no exception raising is desired. If you want an exception to be
|
||||
/// raised upon memory allocation errors, you can call allocate(), reallocate(),
|
||||
/// dispose() instead.
|
||||
///
|
||||
///
|
||||
///
|
||||
///
|
||||
class HAWK_EXPORT Mmgr: public hawk_mmgr_t
|
||||
{
|
||||
public:
|
||||
/// defines an alias type to #hawk_mmgr_t
|
||||
/// defines an alias type to #hawk_mmgr_t
|
||||
typedef hawk_mmgr_t mmgr_t;
|
||||
|
||||
HAWK_EXCEPTION (MemoryError);
|
||||
@ -268,7 +268,7 @@ public:
|
||||
}
|
||||
|
||||
///
|
||||
/// The callocate() function allocates memory like allocate() and
|
||||
/// The callocate() function allocates memory like allocate() and
|
||||
/// clears the memory before returning.
|
||||
///
|
||||
void* callocate (hawk_oow_t n, bool raise_exception = true);
|
||||
@ -294,13 +294,13 @@ public:
|
||||
}
|
||||
|
||||
//protected:
|
||||
///
|
||||
/// The allocMem() function allocates a chunk of memory of the
|
||||
///
|
||||
/// The allocMem() function allocates a chunk of memory of the
|
||||
/// size \a n and return the pointer to the beginning of the chunk.
|
||||
/// If it fails to allocate memory, it should return #HAWK_NULL.
|
||||
///
|
||||
virtual void* allocMem (
|
||||
hawk_oow_t n ///< size of memory chunk to allocate in bytes
|
||||
hawk_oow_t n ///< size of memory chunk to allocate in bytes
|
||||
) HAWK_CXX_NOEXCEPT = 0;
|
||||
|
||||
///
|
||||
@ -319,7 +319,7 @@ public:
|
||||
/// the allocMem() function or resized with the reallocMem() function.
|
||||
///
|
||||
virtual void freeMem (
|
||||
void* ptr ///< pointer to memory chunk to free
|
||||
void* ptr ///< pointer to memory chunk to free
|
||||
) HAWK_CXX_NOEXCEPT = 0;
|
||||
|
||||
protected:
|
||||
@ -358,10 +358,10 @@ public:
|
||||
Mmgr* getMmgr () const { return this->_mmgr; }
|
||||
|
||||
protected:
|
||||
///
|
||||
///
|
||||
/// The setMmgr() function changes the memory manager.
|
||||
/// Changing memory manager requires extra care to be taken
|
||||
/// especially when you have some data allocated with the previous
|
||||
/// Changing memory manager requires extra care to be taken
|
||||
/// especially when you have some data allocated with the previous
|
||||
/// manager. for this reason, i put this as a protected function.
|
||||
///
|
||||
void setMmgr(Mmgr* mmgr);
|
||||
@ -370,8 +370,8 @@ private:
|
||||
Mmgr* _mmgr;
|
||||
};
|
||||
|
||||
///
|
||||
/// The Hawk class implements an AWK interpreter by wrapping around
|
||||
///
|
||||
/// The Hawk class implements an AWK interpreter by wrapping around
|
||||
/// #hhawk_t and #hawk_rtx_t.
|
||||
///
|
||||
class HAWK_EXPORT Hawk: public Uncopyable, public Mmged
|
||||
@ -407,7 +407,7 @@ protected:
|
||||
/// different. The example below changes the formatting string for
|
||||
/// #HAWK_ENOENT.
|
||||
/// \code
|
||||
/// const hawk_ooch_t* MyHawk::getErrorString (hawk_errnum_t num) const
|
||||
/// const hawk_ooch_t* MyHawk::getErrorString (hawk_errnum_t num) const
|
||||
/// {
|
||||
/// if (num == HAWK_ENOENT) return HAWK_T("cannot find '${0}'");
|
||||
/// return Hawk::getErrorString(num);
|
||||
@ -426,7 +426,7 @@ public:
|
||||
hawk_errnum_t getErrorNumber () const;
|
||||
|
||||
///
|
||||
/// The getErrorLocation() function returns the location of the
|
||||
/// The getErrorLocation() function returns the location of the
|
||||
/// last error occurred.
|
||||
///
|
||||
hawk_loc_t getErrorLocation () const;
|
||||
@ -462,11 +462,11 @@ public:
|
||||
);
|
||||
|
||||
///
|
||||
/// The clearError() function clears error information
|
||||
/// The clearError() function clears error information
|
||||
///
|
||||
void clearError ();
|
||||
|
||||
//protected: can't make it protected for borland
|
||||
//protected: can't make it protected for borland
|
||||
void retrieveError ();
|
||||
void retrieveError (Run* run);
|
||||
/// \}
|
||||
@ -475,7 +475,7 @@ protected:
|
||||
class NoSource;
|
||||
|
||||
public:
|
||||
///
|
||||
///
|
||||
/// The Source class is an abstract class to encapsulate
|
||||
/// source script I/O. The Hawk::parse function requires a concrete
|
||||
/// object instantiated from its child class.
|
||||
@ -494,7 +494,7 @@ public:
|
||||
|
||||
///
|
||||
/// The Data class encapsulates information passed in and out
|
||||
/// for source script I/O.
|
||||
/// for source script I/O.
|
||||
///
|
||||
class HAWK_EXPORT Data
|
||||
{
|
||||
@ -502,7 +502,7 @@ public:
|
||||
friend class Hawk;
|
||||
|
||||
protected:
|
||||
Data (Hawk* hawk, Mode mode, hawk_sio_arg_t* arg):
|
||||
Data (Hawk* hawk, Mode mode, hawk_sio_arg_t* arg):
|
||||
hawk(hawk), mode(mode), arg(arg)
|
||||
{
|
||||
}
|
||||
@ -606,7 +606,7 @@ protected:
|
||||
|
||||
public:
|
||||
///
|
||||
/// The RIOBase class is a base class to represent runtime I/O
|
||||
/// The RIOBase class is a base class to represent runtime I/O
|
||||
/// operations. The Console, File, Pipe classes implement more specific
|
||||
/// I/O operations by inheriting this class.
|
||||
///
|
||||
@ -625,10 +625,10 @@ public:
|
||||
void setUflags (int uflags) { this->riod->uflags = uflags; }
|
||||
|
||||
operator Hawk* () const { return this->run->hawk; }
|
||||
operator hawk_t* () const
|
||||
operator hawk_t* () const
|
||||
{
|
||||
HAWK_ASSERT (hawk_rtx_gethawk(this->run->rtx) == this->run->hawk->getHandle());
|
||||
return this->run->hawk->getHandle();
|
||||
return this->run->hawk->getHandle();
|
||||
}
|
||||
operator hawk_rio_arg_t* () const { return this->riod; }
|
||||
operator Run* () const { return this->run; }
|
||||
@ -669,14 +669,14 @@ public:
|
||||
enum CloseMode
|
||||
{
|
||||
/// close both read and write ends
|
||||
CLOSE_FULL = HAWK_RIO_CMD_CLOSE_FULL,
|
||||
CLOSE_FULL = HAWK_RIO_CMD_CLOSE_FULL,
|
||||
/// close the read end only
|
||||
CLOSE_READ = HAWK_RIO_CMD_CLOSE_READ,
|
||||
/// close the write end only
|
||||
CLOSE_WRITE = HAWK_RIO_CMD_CLOSE_WRITE
|
||||
};
|
||||
|
||||
class HAWK_EXPORT Handler
|
||||
class HAWK_EXPORT Handler
|
||||
{
|
||||
public:
|
||||
virtual ~Handler () {}
|
||||
@ -695,14 +695,14 @@ public:
|
||||
|
||||
public:
|
||||
/// The getMode() function returns the opening mode requested.
|
||||
/// You can inspect the opening mode, typically in the
|
||||
/// openPipe() function, to create a pipe with proper
|
||||
/// You can inspect the opening mode, typically in the
|
||||
/// openPipe() function, to create a pipe with proper
|
||||
/// access mode. It is harmless to call this function from
|
||||
/// other pipe handling functions.
|
||||
Mode getMode () const;
|
||||
|
||||
/// The getCloseMode() function returns the closing mode
|
||||
/// requested. The returned value is valid if getMode()
|
||||
/// The getCloseMode() function returns the closing mode
|
||||
/// requested. The returned value is valid if getMode()
|
||||
/// returns #RW.
|
||||
CloseMode getCloseMode () const;
|
||||
};
|
||||
@ -722,7 +722,7 @@ public:
|
||||
APPEND = HAWK_RIO_FILE_APPEND
|
||||
};
|
||||
|
||||
class HAWK_EXPORT Handler
|
||||
class HAWK_EXPORT Handler
|
||||
{
|
||||
public:
|
||||
virtual ~Handler () {}
|
||||
@ -744,7 +744,7 @@ public:
|
||||
};
|
||||
|
||||
///
|
||||
/// The Console class encapsulates the console operations by
|
||||
/// The Console class encapsulates the console operations by
|
||||
/// inheriting RIOBase.
|
||||
///
|
||||
class HAWK_EXPORT Console: public RIOBase
|
||||
@ -759,10 +759,10 @@ public:
|
||||
WRITE = HAWK_RIO_CONSOLE_WRITE ///< open for output
|
||||
};
|
||||
|
||||
///
|
||||
///
|
||||
/// The Handler class is an abstract class that can be
|
||||
/// implemented for customized I/O handling.
|
||||
class HAWK_EXPORT Handler
|
||||
class HAWK_EXPORT Handler
|
||||
{
|
||||
public:
|
||||
virtual ~Handler () {}
|
||||
@ -778,8 +778,8 @@ public:
|
||||
virtual int open (Console& io) = 0;
|
||||
|
||||
/// The close() function is called when the console
|
||||
/// is not needed any more. It must return 0 for success
|
||||
/// and -1 for failure.
|
||||
/// is not needed any more. It must return 0 for success
|
||||
/// and -1 for failure.
|
||||
virtual int close (Console& io) = 0;
|
||||
|
||||
/// The read() function is called when the console
|
||||
@ -794,19 +794,19 @@ public:
|
||||
/// The write() function is called when the console
|
||||
/// is written for output. It can write upto \a len characters
|
||||
/// available in the buffer \a buf and return the number of
|
||||
/// characters written. It can return 0 to indicate EOF and -1
|
||||
/// characters written. It can return 0 to indicate EOF and -1
|
||||
/// for failure.
|
||||
virtual hawk_ooi_t write (Console& io, const hawk_ooch_t* buf, hawk_oow_t len) = 0;
|
||||
|
||||
virtual hawk_ooi_t writeBytes (Console& io, const hawk_bch_t* buf, hawk_oow_t len) = 0;
|
||||
|
||||
/// You may choose to buffer the data passed to the write()
|
||||
/// function and perform actual writing when flush() is called.
|
||||
/// You may choose to buffer the data passed to the write()
|
||||
/// function and perform actual writing when flush() is called.
|
||||
/// It must return 0 for success and -1 for failure.
|
||||
virtual int flush (Console& io) = 0;
|
||||
|
||||
/// The next() function is called when \b nextfile or
|
||||
/// \b nextofile is executed. It must return 0 for success
|
||||
/// The next() function is called when \b nextfile or
|
||||
/// \b nextofile is executed. It must return 0 for success
|
||||
/// and -1 for failure.
|
||||
virtual int next (Console& io) = 0;
|
||||
};
|
||||
@ -829,7 +829,7 @@ public:
|
||||
|
||||
|
||||
///
|
||||
/// The Value class wraps around #hawk_val_t to provide a more
|
||||
/// The Value class wraps around #hawk_val_t to provide a more
|
||||
/// comprehensive interface.
|
||||
///
|
||||
class HAWK_EXPORT Value
|
||||
@ -909,12 +909,12 @@ public:
|
||||
protected:
|
||||
// 2^32: 4294967296
|
||||
// 2^64: 18446744073709551616
|
||||
// 2^128: 340282366920938463463374607431768211456
|
||||
// 2^128: 340282366920938463463374607431768211456
|
||||
// -(2^32/2): -2147483648
|
||||
// -(2^64/2): -9223372036854775808
|
||||
// -(2^128/2): -170141183460469231731687303715884105728
|
||||
#if HAWK_SIZEOF_LONG_T > 16
|
||||
# error SIZEOF(hawk_int_t) TOO LARGE.
|
||||
# error SIZEOF(hawk_int_t) TOO LARGE.
|
||||
# error INCREASE THE BUFFER SIZE TO SUPPORT IT.
|
||||
#elif HAWK_SIZEOF_LONG_T == 16
|
||||
hawk_ooch_t buf[41];
|
||||
@ -935,13 +935,13 @@ public:
|
||||
friend class Value;
|
||||
|
||||
///
|
||||
/// The END variable is a special variable to
|
||||
/// The END variable is a special variable to
|
||||
/// represent the end of iteration.
|
||||
///
|
||||
static IndexIterator END;
|
||||
|
||||
///
|
||||
/// The IndexIterator() function creates an iterator
|
||||
/// The IndexIterator() function creates an iterator
|
||||
/// for an arrayed value.
|
||||
///
|
||||
IndexIterator ()
|
||||
@ -967,10 +967,10 @@ public:
|
||||
|
||||
///
|
||||
/// The Value() function creates an empty value associated
|
||||
/// with no runtime context. To set an actual inner value,
|
||||
/// with no runtime context. To set an actual inner value,
|
||||
/// you must specify a context when calling setXXX() functions.
|
||||
/// i.e., use setInt(run,10) instead of setInt(10).
|
||||
///
|
||||
///
|
||||
Value ();
|
||||
|
||||
///
|
||||
@ -1020,12 +1020,12 @@ public:
|
||||
const hawk_ooch_t* p;
|
||||
hawk_oow_t l;
|
||||
|
||||
if (this->getStr(&p, &l) <= -1)
|
||||
if (this->getStr(&p, &l) <= -1)
|
||||
{
|
||||
p = this->getEmptyStr();
|
||||
l = 0;
|
||||
}
|
||||
|
||||
|
||||
if (len) *len = l;
|
||||
return p;
|
||||
}
|
||||
@ -1035,12 +1035,12 @@ public:
|
||||
const hawk_bch_t* p;
|
||||
hawk_oow_t l;
|
||||
|
||||
if (this->getMbs(&p, &l) <= -1)
|
||||
if (this->getMbs(&p, &l) <= -1)
|
||||
{
|
||||
p = this->getEmptyMbs();
|
||||
l = 0;
|
||||
}
|
||||
|
||||
|
||||
if (len) *len = l;
|
||||
return p;
|
||||
}
|
||||
@ -1104,8 +1104,8 @@ public:
|
||||
///
|
||||
bool isIndexed () const;
|
||||
|
||||
///
|
||||
/// The getIndexed() function gets a value at the given
|
||||
///
|
||||
/// The getIndexed() function gets a value at the given
|
||||
/// index \a idx and sets it to \a val.
|
||||
/// \return 0 on success, -1 on failure
|
||||
///
|
||||
@ -1116,7 +1116,7 @@ public:
|
||||
|
||||
///
|
||||
/// The getFirstIndex() function stores the first index of
|
||||
/// an arrayed value into \a idx.
|
||||
/// an arrayed value into \a idx.
|
||||
/// \return IndexIterator::END if the arrayed value is empty,
|
||||
/// iterator that can be passed to getNextIndex() if not
|
||||
///
|
||||
@ -1125,8 +1125,8 @@ public:
|
||||
) const;
|
||||
|
||||
///
|
||||
/// The getNextIndex() function stores into \a idx the next
|
||||
/// index of an array value from the position indicated by
|
||||
/// The getNextIndex() function stores into \a idx the next
|
||||
/// index of an array value from the position indicated by
|
||||
/// \a iter.
|
||||
/// \return IndexIterator::END if the arrayed value is empty,
|
||||
/// iterator that can be passed to getNextIndex() if not
|
||||
@ -1160,7 +1160,7 @@ public:
|
||||
{
|
||||
protected:
|
||||
friend class Hawk;
|
||||
friend class Value;
|
||||
friend class Value;
|
||||
friend class RIOBase;
|
||||
friend class Console;
|
||||
|
||||
@ -1215,26 +1215,26 @@ public:
|
||||
...
|
||||
);
|
||||
|
||||
///
|
||||
/// The setGlobal() function sets the value of a global
|
||||
///
|
||||
/// The setGlobal() function sets the value of a global
|
||||
/// variable identified by \a id
|
||||
/// to \a v.
|
||||
/// \return 0 on success, -1 on failure
|
||||
///
|
||||
int setGlobal (int id, hawk_int_t v);
|
||||
|
||||
///
|
||||
/// The setGlobal() function sets the value of a global
|
||||
///
|
||||
/// The setGlobal() function sets the value of a global
|
||||
/// variable identified by \a id
|
||||
/// to \a v.
|
||||
/// \return 0 on success, -1 on failure
|
||||
///
|
||||
int setGlobal (int id, hawk_flt_t v);
|
||||
int setGlobal (int id, hawk_flt_t v);
|
||||
|
||||
///
|
||||
/// The setGlobal() function sets the value of a global
|
||||
///
|
||||
/// The setGlobal() function sets the value of a global
|
||||
/// variable identified by \a id
|
||||
/// to a string as long as \a len characters pointed to by
|
||||
/// to a string as long as \a len characters pointed to by
|
||||
/// \a ptr.
|
||||
/// \return 0 on success, -1 on failure
|
||||
///
|
||||
@ -1243,15 +1243,15 @@ public:
|
||||
int setGlobal (int id, const hawk_uch_t* ptr, bool mbs = false);
|
||||
int setGlobal (int id, const hawk_bch_t* ptr, bool mbs = false);
|
||||
|
||||
///
|
||||
/// The setGlobal() function sets a global variable
|
||||
///
|
||||
/// The setGlobal() function sets a global variable
|
||||
/// identified by \a id to a value \a v.
|
||||
/// \return 0 on success, -1 on failure
|
||||
///
|
||||
///
|
||||
int setGlobal (int id, const Value& v);
|
||||
|
||||
///
|
||||
/// The getGlobal() function gets the value of a global
|
||||
/// The getGlobal() function gets the value of a global
|
||||
/// variable identified by \a id and stores it in \a v.
|
||||
/// \return 0 on success, -1 on failure
|
||||
///
|
||||
@ -1263,7 +1263,7 @@ public:
|
||||
};
|
||||
|
||||
///
|
||||
/// Returns the primitive handle
|
||||
/// Returns the primitive handle
|
||||
///
|
||||
operator hawk_t* () const
|
||||
{
|
||||
@ -1280,9 +1280,9 @@ public:
|
||||
/// \{
|
||||
///
|
||||
|
||||
/// The Hawk() function creates an interpreter without fully
|
||||
/// The Hawk() function creates an interpreter without fully
|
||||
/// initializing it. You must call open() for full initialization
|
||||
/// before calling other functions.
|
||||
/// before calling other functions.
|
||||
Hawk (Mmgr* mmgr = HAWK_NULL);
|
||||
|
||||
/// The ~Hawk() function destroys an interpreter. Make sure to have
|
||||
@ -1293,23 +1293,23 @@ public:
|
||||
void setCmgr (hawk_cmgr_t* cmgr);
|
||||
|
||||
///
|
||||
/// The open() function initializes an interpreter.
|
||||
/// The open() function initializes an interpreter.
|
||||
/// You must call this function before doing anything meaningful.
|
||||
/// \return 0 on success, -1 on failure
|
||||
///
|
||||
int open ();
|
||||
|
||||
///
|
||||
/// The close() function closes the interpreter.
|
||||
/// The close() function closes the interpreter.
|
||||
///
|
||||
void close ();
|
||||
|
||||
///
|
||||
/// The uponClosing() function is called back after Hawk::close()
|
||||
/// has cleared most of the internal data but before destroying
|
||||
/// The uponClosing() function is called back after Hawk::close()
|
||||
/// has cleared most of the internal data but before destroying
|
||||
/// the underlying hawk object. This maps to the close callback
|
||||
/// of #hawk_ecb_t.
|
||||
///
|
||||
///
|
||||
virtual void uponClosing ();
|
||||
|
||||
///
|
||||
@ -1322,20 +1322,20 @@ public:
|
||||
///
|
||||
/// 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.
|
||||
/// To disable deparsing, you may set \a out to Hawk::Source::NONE.
|
||||
/// To disable deparsing, you may set \a out to Hawk::Source::NONE.
|
||||
/// However, it is not allowed to specify Hawk::Source::NONE for \a in.
|
||||
///
|
||||
/// \return Run object on success, #HAWK_NULL on failure
|
||||
///
|
||||
Hawk::Run* parse (
|
||||
Source& in, ///< script to parse
|
||||
Source& out ///< deparsing target
|
||||
Source& in, ///< script to parse
|
||||
Source& out ///< deparsing target
|
||||
);
|
||||
|
||||
///
|
||||
/// The getRunContext() funciton returns the execution context
|
||||
/// The getRunContext() funciton returns the execution context
|
||||
/// returned by the parse() function. The returned context
|
||||
/// is valid if parse() has been called. You may call this
|
||||
/// is valid if parse() has been called. You may call this
|
||||
/// function to get the context if you forgot to store it
|
||||
/// in a call to parse().
|
||||
///
|
||||
@ -1345,25 +1345,25 @@ public:
|
||||
}
|
||||
|
||||
///
|
||||
/// The getRunContext() funciton returns the execution context
|
||||
/// The getRunContext() funciton returns the execution context
|
||||
/// returned by the parse() function. The returned context
|
||||
/// is valid if parse() has been called. You may call this
|
||||
/// is valid if parse() has been called. You may call this
|
||||
/// function to get the context if you forgot to store it
|
||||
/// in a call to parse().
|
||||
///
|
||||
Hawk::Run* getRunContext ()
|
||||
Hawk::Run* getRunContext ()
|
||||
{
|
||||
return &this->runctx;
|
||||
}
|
||||
|
||||
///
|
||||
/// The resetRunContext() function closes an existing
|
||||
/// The resetRunContext() function closes an existing
|
||||
/// execution context and creates a new execution context.
|
||||
/// You may want to call this function if you want to
|
||||
/// reset it without calling the parse() function again
|
||||
/// after the first call to it.
|
||||
/// after the first call to it.
|
||||
Hawk::Run* resetRunContext ();
|
||||
|
||||
|
||||
///
|
||||
/// The loop() function executes the BEGIN block, pattern-action blocks,
|
||||
/// and the END block. The return value is stored into \a ret.
|
||||
@ -1396,7 +1396,7 @@ public:
|
||||
///
|
||||
/// The exec() function is the same as loop() if no @pragma startup
|
||||
/// is specified. It is the same as call() if it is specifed
|
||||
///
|
||||
///
|
||||
int exec (
|
||||
Value* ret, ///< return value holder
|
||||
const Value* args, ///< argument array
|
||||
@ -1424,10 +1424,10 @@ public:
|
||||
/// The setTrait() function changes the current traits.
|
||||
///
|
||||
void setTrait (
|
||||
int trait
|
||||
int trait
|
||||
);
|
||||
|
||||
///
|
||||
///
|
||||
/// The setMaxDepth() function sets the maximum processing depth
|
||||
/// for operations identified by \a ids.
|
||||
///
|
||||
@ -1448,10 +1448,10 @@ public:
|
||||
int setIncludeDirs (const hawk_bch_t* dirs);
|
||||
|
||||
///
|
||||
/// The addArgument() function adds an ARGV string as long as \a len
|
||||
/// characters pointed to
|
||||
/// by \a arg. loop() and call() make a string added available
|
||||
/// to a script through ARGV.
|
||||
/// The addArgument() function adds an ARGV string as long as \a len
|
||||
/// characters pointed to
|
||||
/// by \a arg. loop() and call() make a string added available
|
||||
/// to a script through ARGV.
|
||||
/// \return 0 on success, -1 on failure
|
||||
///
|
||||
int addArgument (
|
||||
@ -1465,9 +1465,9 @@ public:
|
||||
);
|
||||
|
||||
///
|
||||
/// The addArgument() function adds a null-terminated string \a arg.
|
||||
/// loop() and call() make a string added available to a script
|
||||
/// through ARGV.
|
||||
/// The addArgument() function adds a null-terminated string \a arg.
|
||||
/// loop() and call() make a string added available to a script
|
||||
/// through ARGV.
|
||||
/// \return 0 on success, -1 on failure
|
||||
///
|
||||
int addArgument (
|
||||
@ -1484,7 +1484,7 @@ public:
|
||||
void clearArguments ();
|
||||
|
||||
hawk_oow_t getArgumentCount () const
|
||||
{
|
||||
{
|
||||
return this->runarg.len;
|
||||
}
|
||||
|
||||
@ -1495,7 +1495,7 @@ public:
|
||||
}
|
||||
|
||||
///
|
||||
/// The addGlobal() function registers an intrinsic global variable.
|
||||
/// The addGlobal() function registers an intrinsic global variable.
|
||||
/// \return integer >= 0 on success, -1 on failure.
|
||||
///
|
||||
int addGlobal (
|
||||
@ -1507,7 +1507,7 @@ public:
|
||||
);
|
||||
|
||||
///
|
||||
/// The deleteGlobal() function unregisters an intrinsic global
|
||||
/// The deleteGlobal() function unregisters an intrinsic global
|
||||
/// variable by name.
|
||||
/// \return 0 on success, -1 on failure.
|
||||
///
|
||||
@ -1520,8 +1520,8 @@ public:
|
||||
);
|
||||
|
||||
///
|
||||
/// The findGlobal() function returns the numeric ID of an intrinsic
|
||||
// global variable.
|
||||
/// The findGlobal() function returns the numeric ID of an intrinsic
|
||||
// global variable.
|
||||
/// \return integer >= 0 on success, -1 on failure.
|
||||
///
|
||||
int findGlobal (
|
||||
@ -1534,8 +1534,8 @@ public:
|
||||
);
|
||||
|
||||
///
|
||||
/// The setGlobal() function sets the value of a global variable
|
||||
/// identified by \a id. The \a id is either a value returned by
|
||||
/// The setGlobal() function sets the value of a global variable
|
||||
/// identified by \a id. The \a id is either a value returned by
|
||||
/// addGlobal() or one of the #hawk_gbl_id_t enumerators. It is not allowed
|
||||
/// to call this function prior to parse().
|
||||
/// \return 0 on success, -1 on failure
|
||||
@ -1546,15 +1546,15 @@ public:
|
||||
);
|
||||
|
||||
///
|
||||
/// The getGlobal() function gets the value of a global variable
|
||||
/// identified by \a id. The \a id is either a value returned by
|
||||
/// The getGlobal() function gets the value of a global variable
|
||||
/// identified by \a id. The \a id is either a value returned by
|
||||
/// addGlobal() or one of the #hawk_gbl_id_t enumerators. It is not allowed
|
||||
/// to call this function before parse().
|
||||
/// \return 0 on success, -1 on failure
|
||||
///
|
||||
int getGlobal (
|
||||
int id, ///< numeric identifier
|
||||
Value& v ///< value store
|
||||
int id, ///< numeric identifier
|
||||
Value& v ///< value store
|
||||
);
|
||||
|
||||
///
|
||||
@ -1564,12 +1564,12 @@ public:
|
||||
Run& run,
|
||||
Value& ret,
|
||||
Value* args,
|
||||
hawk_oow_t nargs,
|
||||
hawk_oow_t nargs,
|
||||
const hawk_fnc_info_t* fi
|
||||
);
|
||||
|
||||
///
|
||||
/// The addFunction() function adds a new user-defined intrinsic
|
||||
///
|
||||
/// The addFunction() function adds a new user-defined intrinsic
|
||||
/// function.
|
||||
///
|
||||
int addFunction (
|
||||
@ -1591,7 +1591,7 @@ public:
|
||||
);
|
||||
|
||||
///
|
||||
/// The deleteFunction() function deletes a user-defined intrinsic
|
||||
/// The deleteFunction() function deletes a user-defined intrinsic
|
||||
/// function by name.
|
||||
///
|
||||
int deleteFunction (
|
||||
@ -1615,7 +1615,7 @@ public:
|
||||
/// outside this class without overriding various pipe functions.
|
||||
/// Note that an external pipe handler must outlive an outer
|
||||
/// hawk object.
|
||||
///
|
||||
///
|
||||
void setPipeHandler (Pipe::Handler* handler)
|
||||
{
|
||||
this->pipe_handler = handler;
|
||||
@ -1637,7 +1637,7 @@ public:
|
||||
/// outside this class without overriding various file functions.
|
||||
/// Note that an external file handler must outlive an outer
|
||||
/// hawk object.
|
||||
///
|
||||
///
|
||||
void setFileHandler (File::Handler* handler)
|
||||
{
|
||||
this->file_handler = handler;
|
||||
@ -1659,14 +1659,14 @@ public:
|
||||
/// outside this class without overriding various console functions.
|
||||
/// Note that an external console handler must outlive an outer
|
||||
/// hawk object.
|
||||
///
|
||||
///
|
||||
void setConsoleHandler (Console::Handler* handler)
|
||||
{
|
||||
this->console_handler = handler;
|
||||
}
|
||||
|
||||
protected:
|
||||
///
|
||||
///
|
||||
/// \name Pipe I/O handlers
|
||||
/// Pipe operations are achieved through the following functions
|
||||
/// if no external pipe handler is set with setPipeHandler().
|
||||
@ -1689,7 +1689,7 @@ protected:
|
||||
virtual int flushPipe (Pipe& io);
|
||||
/// \}
|
||||
|
||||
///
|
||||
///
|
||||
/// \name File I/O handlers
|
||||
/// File operations are achieved through the following functions
|
||||
/// if no external file handler is set with setFileHandler().
|
||||
@ -1704,7 +1704,7 @@ protected:
|
||||
virtual int flushFile (File& io);
|
||||
/// \}
|
||||
|
||||
///
|
||||
///
|
||||
/// \name Console I/O handlers
|
||||
/// Console operations are achieved through the following functions.
|
||||
/// if no external console handler is set with setConsoleHandler().
|
||||
@ -1720,7 +1720,7 @@ protected:
|
||||
virtual int nextConsole (Console& io);
|
||||
/// \}
|
||||
|
||||
// primitive handlers
|
||||
// primitive handlers
|
||||
virtual hawk_flt_t pow (hawk_flt_t x, hawk_flt_t y) = 0;
|
||||
virtual hawk_flt_t mod (hawk_flt_t x, hawk_flt_t y) = 0;
|
||||
|
||||
@ -1846,8 +1846,8 @@ public:
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
///
|
||||
/// The HawkStd class provides an easier-to-use interface by overriding
|
||||
/// primitive methods, and implementing the file handler, the pipe handler,
|
||||
/// The HawkStd class provides an easier-to-use interface by overriding
|
||||
/// primitive methods, and implementing the file handler, the pipe handler,
|
||||
/// and common intrinsic functions.
|
||||
///
|
||||
class HAWK_EXPORT HawkStd: public Hawk
|
||||
@ -1856,17 +1856,17 @@ public:
|
||||
///
|
||||
/// The SourceFile class implements script I/O from and to a file.
|
||||
///
|
||||
class HAWK_EXPORT SourceFile: public Source
|
||||
class HAWK_EXPORT SourceFile: public Source
|
||||
{
|
||||
public:
|
||||
SourceFile (const hawk_uch_t* name, hawk_cmgr_t* cmgr = HAWK_NULL): _type(NAME_UCH), _name(name), cmgr(cmgr)
|
||||
{
|
||||
dir.ptr = HAWK_NULL; dir.len = 0;
|
||||
dir.ptr = HAWK_NULL; dir.len = 0;
|
||||
}
|
||||
|
||||
SourceFile (const hawk_bch_t* name, hawk_cmgr_t* cmgr = HAWK_NULL): _type(NAME_BCH), _name(name), cmgr(cmgr)
|
||||
{
|
||||
dir.ptr = HAWK_NULL; dir.len = 0;
|
||||
dir.ptr = HAWK_NULL; dir.len = 0;
|
||||
}
|
||||
|
||||
~SourceFile () {};
|
||||
@ -1888,7 +1888,7 @@ public:
|
||||
};
|
||||
|
||||
///
|
||||
/// The SourceString class implements script input from a string.
|
||||
/// The SourceString class implements script input from a string.
|
||||
/// Deparsing is not supported.
|
||||
///
|
||||
class HAWK_EXPORT SourceString: public Source
|
||||
@ -1917,7 +1917,7 @@ public:
|
||||
hawk_cmgr_t* cmgr; // for reading included files
|
||||
};
|
||||
|
||||
HawkStd (Mmgr* mmgr = HAWK_NULL): Hawk(mmgr), cmgrtab_inited(false), stdmod_up(false), console_cmgr(HAWK_NULL)
|
||||
HawkStd (Mmgr* mmgr = HAWK_NULL): Hawk(mmgr), cmgrtab_inited(false), stdmod_up(false), console_cmgr(HAWK_NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1928,7 +1928,7 @@ public:
|
||||
|
||||
Run* parse (Source& in, Source& out);
|
||||
|
||||
/// The setConsoleCmgr() function sets the encoding type of
|
||||
/// The setConsoleCmgr() function sets the encoding type of
|
||||
/// the console streams. They include both the input and the output
|
||||
/// streams. It provides no way to specify a different encoding
|
||||
/// type for the input and the output stream.
|
||||
@ -1955,13 +1955,13 @@ protected:
|
||||
int build_argcv (Run* run);
|
||||
int build_environ (Run* run, env_char_t* envarr[]);
|
||||
|
||||
// intrinsic functions
|
||||
// intrinsic functions
|
||||
hawk_cmgr_t* getiocmgr (const hawk_ooch_t* ioname);
|
||||
|
||||
int setioattr (Run& run, Value& ret, Value* args, hawk_oow_t nargs, const hawk_ooch_t* name, hawk_oow_t len);
|
||||
int getioattr (Run& run, Value& ret, Value* args, hawk_oow_t nargs, const hawk_ooch_t* name, hawk_oow_t len);
|
||||
|
||||
// pipe io handlers
|
||||
// pipe io handlers
|
||||
int openPipe (Pipe& io);
|
||||
int closePipe (Pipe& io);
|
||||
hawk_ooi_t readPipe (Pipe& io, hawk_ooch_t* buf, hawk_oow_t len);
|
||||
@ -1970,7 +1970,7 @@ protected:
|
||||
hawk_ooi_t writePipeBytes (Pipe& io, const hawk_bch_t* buf, hawk_oow_t len);
|
||||
int flushPipe (Pipe& io);
|
||||
|
||||
// file io handlers
|
||||
// file io handlers
|
||||
int openFile (File& io);
|
||||
int closeFile (File& io);
|
||||
hawk_ooi_t readFile (File& io, hawk_ooch_t* buf, hawk_oow_t len);
|
||||
@ -1979,7 +1979,7 @@ protected:
|
||||
hawk_ooi_t writeFileBytes (File& io, const hawk_bch_t* buf, hawk_oow_t len);
|
||||
int flushFile (File& io);
|
||||
|
||||
// console io handlers
|
||||
// console io handlers
|
||||
int openConsole (Console& io);
|
||||
int closeConsole (Console& io);
|
||||
hawk_ooi_t readConsole (Console& io, hawk_ooch_t* buf, hawk_oow_t len);
|
||||
@ -1989,7 +1989,7 @@ protected:
|
||||
int flushConsole (Console& io);
|
||||
int nextConsole (Console& io);
|
||||
|
||||
// primitive handlers
|
||||
// primitive handlers
|
||||
void* allocMem (hawk_oow_t n);
|
||||
void* reallocMem (void* ptr, hawk_oow_t n);
|
||||
void freeMem (void* ptr);
|
||||
@ -2008,16 +2008,16 @@ protected:
|
||||
|
||||
hawk_cmgr_t* console_cmgr;
|
||||
|
||||
// global variables
|
||||
// global variables
|
||||
int gbl_argc;
|
||||
int gbl_argv;
|
||||
int gbl_environ;
|
||||
|
||||
// standard input console - reuse runarg
|
||||
// standard input console - reuse runarg
|
||||
hawk_oow_t runarg_index;
|
||||
hawk_oow_t runarg_count;
|
||||
|
||||
// standard output console
|
||||
// standard output console
|
||||
xstrs_t ofile;
|
||||
hawk_oow_t ofile_index;
|
||||
hawk_oow_t ofile_count;
|
||||
@ -2075,7 +2075,7 @@ HAWK_EXPORT void* operator new (hawk_oow_t size, HAWK::Mmgr* mmgr, void* existin
|
||||
// the placement new operator. if the array element is an instance
|
||||
// of a class, the pointer returned by the new operator call
|
||||
// may not be the actual pointer allocated. some compilers
|
||||
// seem to put some information about the array at the
|
||||
// seem to put some information about the array at the
|
||||
// beginning of the allocated memory and return the pointer
|
||||
// off a few bytes from the beginning.
|
||||
void* operator new[] (hawk_oow_t size, HAWK::Mmgr* mmgr);
|
||||
@ -2086,6 +2086,6 @@ void operator delete[] (void* ptr, HAWK::Mmgr* mmgr);
|
||||
do { \
|
||||
HAWK_CXX_CALL_DESTRUCTOR (ptr, class_name); \
|
||||
HAWK_CXX_CALL_PLACEMENT_DELETE1(ptr, mmgr); \
|
||||
} while(0);
|
||||
} while(0);
|
||||
|
||||
#endif
|
||||
|
@ -42,7 +42,7 @@ static HAWK_INLINE xtn_t* GET_XTN(hawk_sed_t* sed) { return (xtn_t*)((hawk_uint8
|
||||
#define GET_XTN(sed) ((xtn_t*)((hawk_uint8_t*)hawk_sed_getxtn(sed) - HAWK_SIZEOF(xtn_t)))
|
||||
#endif
|
||||
|
||||
Sed::Sed (Mmgr* mmgr): Mmged(mmgr), sed(HAWK_NULL), dflerrstr(HAWK_NULL)
|
||||
Sed::Sed (Mmgr* mmgr): Mmged(mmgr), sed(HAWK_NULL), dflerrstr(HAWK_NULL)
|
||||
{
|
||||
this->_cmgr = hawk_get_cmgr_by_id(HAWK_CMGR_UTF8);
|
||||
}
|
||||
@ -62,7 +62,7 @@ int Sed::open ()
|
||||
{
|
||||
hawk_errnum_t errnum;
|
||||
this->sed = hawk_sed_open(this->getMmgr(), HAWK_SIZEOF(xtn_t), this->getCmgr(), &errnum);
|
||||
if (!this->sed)
|
||||
if (!this->sed)
|
||||
{
|
||||
this->setError (errnum);
|
||||
return -1;
|
||||
@ -150,10 +150,10 @@ const hawk_bch_t* Sed::getErrorMessageB () const
|
||||
|
||||
hawk_loc_t Sed::getErrorLocation () const
|
||||
{
|
||||
if (this->sed == HAWK_NULL)
|
||||
if (this->sed == HAWK_NULL)
|
||||
{
|
||||
hawk_loc_t loc;
|
||||
loc.line = 0;
|
||||
loc.line = 0;
|
||||
loc.colm = 0;
|
||||
return loc;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ static hawk_sio_t* open_sio (SedStd::Stream::Data& io, const hawk_ooch_t* file,
|
||||
if (sio == HAWK_NULL)
|
||||
{
|
||||
const hawk_ooch_t* old_errmsg = hawk_sed_backuperrmsg((hawk_sed_t*)io);
|
||||
((Sed*)io)->formatError (HAWK_SED_EIOFIL, HAWK_NULL, "unable to open %js - %js", file, old_errmsg);
|
||||
((Sed*)io)->formatError(HAWK_SED_EIOFIL, HAWK_NULL, "unable to open %js - %js", file, old_errmsg);
|
||||
}
|
||||
return sio;
|
||||
}
|
||||
@ -60,18 +60,18 @@ static hawk_sio_t* open_sio_std (SedStd::Stream::Data& io, hawk_sio_std_t std, i
|
||||
if (sio == HAWK_NULL)
|
||||
{
|
||||
const hawk_ooch_t* old_errmsg = hawk_sed_backuperrmsg((hawk_sed_t*)io);
|
||||
((Sed*)io)->formatError (HAWK_SED_EIOFIL, HAWK_NULL, "unable to open %js - %js", std_names[std], old_errmsg);
|
||||
((Sed*)io)->formatError(HAWK_SED_EIOFIL, HAWK_NULL, "unable to open %js - %js", std_names[std], old_errmsg);
|
||||
}
|
||||
return sio;
|
||||
}
|
||||
|
||||
SedStd::FileStream::FileStream (const hawk_uch_t* file, hawk_cmgr_t* cmgr):
|
||||
_type(NAME_UCH), _file(file), file(HAWK_NULL), cmgr(cmgr)
|
||||
SedStd::FileStream::FileStream (const hawk_uch_t* file, hawk_cmgr_t* cmgr):
|
||||
_type(NAME_UCH), _file(file), file(HAWK_NULL), cmgr(cmgr)
|
||||
{
|
||||
}
|
||||
|
||||
SedStd::FileStream::FileStream (const hawk_bch_t* file, hawk_cmgr_t* cmgr ):
|
||||
_type(NAME_BCH), _file(file), file(HAWK_NULL), cmgr(cmgr)
|
||||
_type(NAME_BCH), _file(file), file(HAWK_NULL), cmgr(cmgr)
|
||||
{
|
||||
}
|
||||
SedStd::FileStream::~FileStream ()
|
||||
@ -103,7 +103,7 @@ int SedStd::FileStream::open (Data& io)
|
||||
//
|
||||
// a normal console is indicated by a null name or a dash
|
||||
//
|
||||
|
||||
|
||||
if (this->_file)
|
||||
{
|
||||
if (this->_type == NAME_UCH)
|
||||
@ -113,7 +113,7 @@ int SedStd::FileStream::open (Data& io)
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
this->file = hawk_gem_dupucstr(gem, tmp, HAWK_NULL);
|
||||
#else
|
||||
this->file = hawk_duputobcstr(gem, tmp, HAWK_NULL);
|
||||
this->file = hawk_gem_duputobcstr(gem, tmp, HAWK_NULL);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@ -154,7 +154,7 @@ int SedStd::FileStream::close (Data& io)
|
||||
{
|
||||
hawk_sio_close ((hawk_sio_t*)io.getHandle());
|
||||
|
||||
// this stream object may get called more than once and is merely a proxy
|
||||
// this stream object may get called more than once and is merely a proxy
|
||||
// object that has its own lifespan. while io.getHandle() returns a unique
|
||||
// handle value as set by io.setHandle() in the open method, this object
|
||||
// is resued for calls over multiple I/O objects created. When releasing
|
||||
@ -163,7 +163,7 @@ int SedStd::FileStream::close (Data& io)
|
||||
|
||||
if (!io.getName())
|
||||
{
|
||||
// for a master stream that's not started by r or w
|
||||
// for a master stream that's not started by r or w
|
||||
if (this->file)
|
||||
{
|
||||
hawk_gem_freemem ((hawk_gem_t*)io, this->file);
|
||||
@ -183,7 +183,7 @@ hawk_ooi_t SedStd::FileStream::read (Data& io, hawk_ooch_t* buf, hawk_oow_t len)
|
||||
if (!io.getName() && this->file) // io.getMode() must be READ
|
||||
{
|
||||
const hawk_ooch_t* old_errmsg = hawk_sed_backuperrmsg((hawk_sed_t*)io);
|
||||
((Sed*)io)->formatError (HAWK_SED_EIOFIL, HAWK_NULL, "unable to read %js - %js", this->file, old_errmsg);
|
||||
((Sed*)io)->formatError(HAWK_SED_EIOFIL, HAWK_NULL, "unable to read %js - %js", this->file, old_errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ hawk_ooi_t SedStd::FileStream::write (Data& io, const hawk_ooch_t* buf, hawk_oow
|
||||
if (!io.getName() && this->file) // io.getMode() must be WRITE
|
||||
{
|
||||
const hawk_ooch_t* old_errmsg = hawk_sed_backuperrmsg((hawk_sed_t*)io);
|
||||
((Sed*)io)->formatError (HAWK_SED_EIOFIL, HAWK_NULL, "unable to read %js - %js", this->file, old_errmsg);
|
||||
((Sed*)io)->formatError(HAWK_SED_EIOFIL, HAWK_NULL, "unable to read %js - %js", this->file, old_errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,7 +211,7 @@ SedStd::StringStream::StringStream (hawk_cmgr_t* cmgr): _type(STR_UCH) // this t
|
||||
this->cmgr = cmgr;
|
||||
|
||||
this->in._sed = HAWK_NULL;
|
||||
this->in._str = HAWK_NULL;
|
||||
this->in._str = HAWK_NULL;
|
||||
this->in._end = HAWK_NULL;
|
||||
this->in.str = HAWK_NULL;
|
||||
this->in.end = HAWK_NULL;
|
||||
@ -229,7 +229,7 @@ SedStd::StringStream::StringStream (const hawk_uch_t* in, hawk_cmgr_t* cmgr): _t
|
||||
this->cmgr = cmgr;
|
||||
|
||||
this->in._sed = HAWK_NULL;
|
||||
this->in._str = in;
|
||||
this->in._str = in;
|
||||
this->in._end = in + hawk_count_ucstr(in);
|
||||
this->in.str = HAWK_NULL;
|
||||
this->in.end = HAWK_NULL;
|
||||
@ -247,7 +247,7 @@ SedStd::StringStream::StringStream (const hawk_uch_t* in, hawk_oow_t len, hawk_c
|
||||
this->cmgr = cmgr;
|
||||
|
||||
this->in._sed = HAWK_NULL;
|
||||
this->in._str = in;
|
||||
this->in._str = in;
|
||||
this->in._end = in + len;
|
||||
this->in.str = HAWK_NULL;
|
||||
this->in.end = HAWK_NULL;
|
||||
@ -258,7 +258,7 @@ SedStd::StringStream::StringStream (const hawk_uch_t* in, hawk_oow_t len, hawk_c
|
||||
this->out.inited = false;
|
||||
this->out.alt_buf = HAWK_NULL;
|
||||
this->out.alt_sed = HAWK_NULL;
|
||||
|
||||
|
||||
}
|
||||
|
||||
SedStd::StringStream::StringStream (const hawk_bch_t* in, hawk_cmgr_t* cmgr): _type(STR_BCH)
|
||||
@ -266,7 +266,7 @@ SedStd::StringStream::StringStream (const hawk_bch_t* in, hawk_cmgr_t* cmgr): _t
|
||||
this->cmgr = cmgr;
|
||||
|
||||
this->in._sed = HAWK_NULL;
|
||||
this->in._str = in;
|
||||
this->in._str = in;
|
||||
this->in._end = in + hawk_count_bcstr(in);
|
||||
this->in.str = HAWK_NULL;
|
||||
this->in.end = HAWK_NULL;
|
||||
@ -284,7 +284,7 @@ SedStd::StringStream::StringStream (const hawk_bch_t* in, hawk_oow_t len, hawk_c
|
||||
this->cmgr = cmgr;
|
||||
|
||||
this->in._sed = HAWK_NULL;
|
||||
this->in._str = in;
|
||||
this->in._str = in;
|
||||
this->in._end = in + len;
|
||||
this->in.str = HAWK_NULL;
|
||||
this->in.end = HAWK_NULL;
|
||||
@ -315,17 +315,17 @@ int SedStd::StringStream::open (Data& io)
|
||||
if (ioname == HAWK_NULL)
|
||||
{
|
||||
// open a main data stream
|
||||
if (io.getMode() == READ)
|
||||
if (io.getMode() == READ)
|
||||
{
|
||||
HAWK_ASSERT (this->in.str == HAWK_NULL);
|
||||
|
||||
if (this->in._str == HAWK_NULL)
|
||||
{
|
||||
// no input data was passed to this object for construction
|
||||
// no input data was passed to this object for construction
|
||||
|
||||
if (this->out.inited)
|
||||
{
|
||||
// this object is being reused for input after output
|
||||
// this object is being reused for input after output
|
||||
// use the output data as input
|
||||
hawk_oocs_t out;
|
||||
hawk_ooecs_yield (&this->out.buf, &out, 0);
|
||||
@ -336,21 +336,21 @@ int SedStd::StringStream::open (Data& io)
|
||||
}
|
||||
else
|
||||
{
|
||||
((Sed*)io)->formatError (HAWK_EINVAL, HAWK_NULL, "no input data available to open");
|
||||
((Sed*)io)->formatError(HAWK_EINVAL, HAWK_NULL, "no input data available to open");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hawk_oow_t len;
|
||||
hawk_gem_t* gem = hawk_sed_getgem((hawk_sed_t*)io);
|
||||
hawk_gem_t* gem = hawk_sed_getgem((hawk_sed_t*)io);
|
||||
|
||||
if (this->_type == STR_UCH)
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
this->in.str = hawk_gem_dupucstr(gem, (const hawk_uch_t*)this->in._str, &len);
|
||||
#else
|
||||
this->in.str = hawk_duputobcstr(gem, (const hawk_uch_t*)this->in._str, &len);
|
||||
this->in.str = hawk_gem_duputobcstr(gem, (const hawk_uch_t*)this->in._str, &len);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@ -372,10 +372,10 @@ int SedStd::StringStream::open (Data& io)
|
||||
}
|
||||
else
|
||||
{
|
||||
this->clearOutputData (true);
|
||||
this->clearOutputData (true);
|
||||
// preserving this previous output data is a bit tricky when hawk_ooecs_init() fails.
|
||||
// let's not try to preserve the old output data for now.
|
||||
// full clearing is needed because this object may get passed to different sed objects
|
||||
// full clearing is needed because this object may get passed to different sed objects
|
||||
// in succession.
|
||||
|
||||
if (hawk_ooecs_init(&this->out.buf, (hawk_gem_t*)io, 256) <= -1) return -1;
|
||||
@ -395,7 +395,7 @@ int SedStd::StringStream::open (Data& io)
|
||||
// open files for a r or w command
|
||||
hawk_sio_t* sio;
|
||||
int mode = (io.getMode() == READ)?
|
||||
HAWK_SIO_READ:
|
||||
HAWK_SIO_READ:
|
||||
(HAWK_SIO_WRITE|HAWK_SIO_CREATE|HAWK_SIO_TRUNCATE);
|
||||
|
||||
sio = hawk_sio_open((hawk_gem_t*)io, 0, ioname, mode);
|
||||
@ -489,7 +489,7 @@ const hawk_uch_t* SedStd::StringStream::getOutputU (hawk_oow_t* len)
|
||||
if (this->out.inited)
|
||||
{
|
||||
hawk_uch_t* tmp = hawk_gem_dupbtoucharswithcmgr(hawk_sed_getgem(this->out._sed), HAWK_OOECS_PTR(&this->out.buf), HAWK_OOECS_LEN(&this->out.buf), len, this->cmgr, 1);
|
||||
if (tmp)
|
||||
if (tmp)
|
||||
{
|
||||
if (this->out.alt_buf) hawk_sed_freemem(this->out._sed, this->out.alt_buf);
|
||||
this->out.alt_buf = (void*)tmp;
|
||||
@ -511,7 +511,7 @@ const hawk_bch_t* SedStd::StringStream::getOutputB (hawk_oow_t* len)
|
||||
if (this->out.inited)
|
||||
{
|
||||
hawk_bch_t* tmp = hawk_gem_duputobcharswithcmgr(hawk_sed_getgem(this->out._sed), HAWK_OOECS_PTR(&this->out.buf), HAWK_OOECS_LEN(&this->out.buf), len, this->cmgr);
|
||||
if (tmp)
|
||||
if (tmp)
|
||||
{
|
||||
if (this->out.alt_buf) hawk_sed_freemem(this->out._sed, this->out.alt_buf);
|
||||
this->out.alt_buf = (void*)tmp;
|
||||
@ -543,7 +543,7 @@ void SedStd::StringStream::clearInputData ()
|
||||
|
||||
void SedStd::StringStream::clearOutputData (bool kill_ecb)
|
||||
{
|
||||
if (this->out.alt_buf)
|
||||
if (this->out.alt_buf)
|
||||
{
|
||||
HAWK_ASSERT (this->out.alt_sed != HAWK_NULL);
|
||||
hawk_sed_freemem(this->out.alt_sed, this->out.alt_buf);
|
||||
|
206
lib/Std.cpp
206
lib/Std.cpp
@ -32,7 +32,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
// TODO: remove the following definitions and find a way to share the similar definitions in std.c
|
||||
// TODO: remove the following definitions and find a way to share the similar definitions in std.c
|
||||
#if defined(HAWK_ENABLE_LIBLTDL)
|
||||
# define USE_LTDL
|
||||
#elif defined(HAVE_DLFCN_H)
|
||||
@ -131,7 +131,7 @@ static hawk_sio_t* open_sio_std (Hawk* hawk, HawkStd::Run* run, hawk_sio_std_t s
|
||||
return sio;
|
||||
}
|
||||
|
||||
int HawkStd::open ()
|
||||
int HawkStd::open ()
|
||||
{
|
||||
int n = Hawk::open();
|
||||
if (HAWK_UNLIKELY(n <= -1)) return n;
|
||||
@ -170,9 +170,9 @@ oops:
|
||||
return -1;
|
||||
}
|
||||
|
||||
void HawkStd::close ()
|
||||
void HawkStd::close ()
|
||||
{
|
||||
if (this->cmgrtab_inited)
|
||||
if (this->cmgrtab_inited)
|
||||
{
|
||||
hawk_htb_fini (&this->cmgrtab);
|
||||
this->cmgrtab_inited = false;
|
||||
@ -186,7 +186,7 @@ void HawkStd::close ()
|
||||
// but Hawk::close() still needs to call some module's fini and
|
||||
// unload functions. So it must be done in HawkStd::uponClosing()
|
||||
// which is called after modules have been unloaded but while
|
||||
// the underlying hawk object is still alive.
|
||||
// the underlying hawk object is still alive.
|
||||
//
|
||||
// See HawkStd::uponClosing() below.
|
||||
//
|
||||
@ -216,10 +216,10 @@ HawkStd::Run* HawkStd::parse (Source& in, Source& out)
|
||||
{
|
||||
Run* run = Hawk::parse(in, out);
|
||||
|
||||
if (this->cmgrtab_inited)
|
||||
if (this->cmgrtab_inited)
|
||||
{
|
||||
// if cmgrtab has already been initialized,
|
||||
// just clear the contents regardless of
|
||||
// just clear the contents regardless of
|
||||
// parse() result.
|
||||
hawk_htb_clear (&this->cmgrtab);
|
||||
}
|
||||
@ -379,10 +379,10 @@ HawkStd::ioattr_t* HawkStd::find_or_make_ioattr (const hawk_ooch_t* ptr, hawk_oo
|
||||
if (pair == HAWK_NULL)
|
||||
{
|
||||
pair = hawk_htb_insert (
|
||||
&this->cmgrtab, (void*)ptr, len,
|
||||
(void*)&HawkStd::default_ioattr,
|
||||
&this->cmgrtab, (void*)ptr, len,
|
||||
(void*)&HawkStd::default_ioattr,
|
||||
HAWK_SIZEOF(HawkStd::default_ioattr));
|
||||
if (pair == HAWK_NULL)
|
||||
if (pair == HAWK_NULL)
|
||||
{
|
||||
this->setError (HAWK_ENOMEM);
|
||||
return HAWK_NULL;
|
||||
@ -419,7 +419,7 @@ int HawkStd::setioattr (
|
||||
{
|
||||
return ret.setInt ((hawk_int_t)-1);
|
||||
}
|
||||
|
||||
|
||||
int tmout;
|
||||
if ((tmout = timeout_code (ptr[1])) >= 0)
|
||||
{
|
||||
@ -460,7 +460,7 @@ int HawkStd::setioattr (
|
||||
cmgr = hawk_get_cmgr_by_name(ptr[2]);
|
||||
if (cmgr == HAWK_NULL) return ret.setInt ((hawk_int_t)-1);
|
||||
}
|
||||
|
||||
|
||||
ioattr = find_or_make_ioattr(ptr[0], l[0]);
|
||||
if (ioattr == HAWK_NULL) return -1;
|
||||
|
||||
@ -554,8 +554,8 @@ int HawkStd::open_nwio (Pipe& io, int flags, void* nwad)
|
||||
}
|
||||
#endif
|
||||
|
||||
int HawkStd::open_pio (Pipe& io)
|
||||
{
|
||||
int HawkStd::open_pio (Pipe& io)
|
||||
{
|
||||
Hawk::Pipe::Mode mode = io.getMode();
|
||||
hawk_pio_t* pio = HAWK_NULL;
|
||||
int flags = HAWK_PIO_TEXT | HAWK_PIO_SHELL | HAWK_PIO_IGNOREECERR;
|
||||
@ -581,7 +581,7 @@ int HawkStd::open_pio (Pipe& io)
|
||||
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
hawk_cmgr_t* cmgr = this->getiocmgr(io.getName());
|
||||
if (cmgr)
|
||||
if (cmgr)
|
||||
{
|
||||
hawk_pio_setcmgr (pio, HAWK_PIO_IN, cmgr);
|
||||
hawk_pio_setcmgr (pio, HAWK_PIO_OUT, cmgr);
|
||||
@ -624,8 +624,8 @@ static int parse_rwpipe_uri (const hawk_ooch_t* uri, int* flags, hawk_nwad_t* nw
|
||||
}
|
||||
#endif
|
||||
|
||||
int HawkStd::openPipe (Pipe& io)
|
||||
{
|
||||
int HawkStd::openPipe (Pipe& io)
|
||||
{
|
||||
#if defined(ENABLE_NWIO)
|
||||
int flags;
|
||||
hawk_nwad_t nwad;
|
||||
@ -644,7 +644,7 @@ int HawkStd::openPipe (Pipe& io)
|
||||
#endif
|
||||
}
|
||||
|
||||
int HawkStd::closePipe (Pipe& io)
|
||||
int HawkStd::closePipe (Pipe& io)
|
||||
{
|
||||
#if defined(ENABLE_NWIO)
|
||||
if (io.getUflags() > 0)
|
||||
@ -675,11 +675,11 @@ int HawkStd::closePipe (Pipe& io)
|
||||
#if defined(ENABLE_NWIO)
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
hawk_ooi_t HawkStd::readPipe (Pipe& io, hawk_ooch_t* buf, hawk_oow_t len)
|
||||
{
|
||||
hawk_ooi_t HawkStd::readPipe (Pipe& io, hawk_ooch_t* buf, hawk_oow_t len)
|
||||
{
|
||||
#if defined(ENABLE_NWIO)
|
||||
return (io.getUflags() > 0)?
|
||||
hawk_nwio_read((hawk_nwio_t*)io.getHandle(), buf, len):
|
||||
@ -689,8 +689,8 @@ hawk_ooi_t HawkStd::readPipe (Pipe& io, hawk_ooch_t* buf, hawk_oow_t len)
|
||||
#endif
|
||||
}
|
||||
|
||||
hawk_ooi_t HawkStd::readPipeBytes (Pipe& io, hawk_bch_t* buf, hawk_oow_t len)
|
||||
{
|
||||
hawk_ooi_t HawkStd::readPipeBytes (Pipe& io, hawk_bch_t* buf, hawk_oow_t len)
|
||||
{
|
||||
#if defined(ENABLE_NWIO)
|
||||
return (io.getUflags() > 0)?
|
||||
hawk_nwio_readbytes((hawk_nwio_t*)io.getHandle(), buf, len):
|
||||
@ -700,8 +700,8 @@ hawk_ooi_t HawkStd::readPipeBytes (Pipe& io, hawk_bch_t* buf, hawk_oow_t len)
|
||||
#endif
|
||||
}
|
||||
|
||||
hawk_ooi_t HawkStd::writePipe (Pipe& io, const hawk_ooch_t* buf, hawk_oow_t len)
|
||||
{
|
||||
hawk_ooi_t HawkStd::writePipe (Pipe& io, const hawk_ooch_t* buf, hawk_oow_t len)
|
||||
{
|
||||
#if defined(ENABLE_NWIO)
|
||||
return (io.getUflags() > 0)?
|
||||
hawk_nwio_write((hawk_nwio_t*)io.getHandle(), buf, len):
|
||||
@ -711,8 +711,8 @@ hawk_ooi_t HawkStd::writePipe (Pipe& io, const hawk_ooch_t* buf, hawk_oow_t len)
|
||||
#endif
|
||||
}
|
||||
|
||||
hawk_ooi_t HawkStd::writePipeBytes (Pipe& io, const hawk_bch_t* buf, hawk_oow_t len)
|
||||
{
|
||||
hawk_ooi_t HawkStd::writePipeBytes (Pipe& io, const hawk_bch_t* buf, hawk_oow_t len)
|
||||
{
|
||||
#if defined(ENABLE_NWIO)
|
||||
return (io.getUflags() > 0)?
|
||||
hawk_nwio_writebytes((hawk_nwio_t*)io.getHandle(), buf, len):
|
||||
@ -722,8 +722,8 @@ hawk_ooi_t HawkStd::writePipeBytes (Pipe& io, const hawk_bch_t* buf, hawk_oow_t
|
||||
#endif
|
||||
}
|
||||
|
||||
int HawkStd::flushPipe (Pipe& io)
|
||||
{
|
||||
int HawkStd::flushPipe (Pipe& io)
|
||||
{
|
||||
#if defined(ENABLE_NWIO)
|
||||
return (io.getUflags() > 0)?
|
||||
hawk_nwio_flush((hawk_nwio_t*)io.getHandle()):
|
||||
@ -733,8 +733,8 @@ int HawkStd::flushPipe (Pipe& io)
|
||||
#endif
|
||||
}
|
||||
|
||||
int HawkStd::openFile (File& io)
|
||||
{
|
||||
int HawkStd::openFile (File& io)
|
||||
{
|
||||
Hawk::File::Mode mode = io.getMode();
|
||||
hawk_sio_t* sio = HAWK_NULL;
|
||||
int flags = HAWK_SIO_IGNOREECERR;
|
||||
@ -774,18 +774,18 @@ int HawkStd::openFile (File& io)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int HawkStd::closeFile (File& io)
|
||||
{
|
||||
int HawkStd::closeFile (File& io)
|
||||
{
|
||||
hawk_sio_close ((hawk_sio_t*)io.getHandle());
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
hawk_ooi_t HawkStd::readFile (File& io, hawk_ooch_t* buf, hawk_oow_t len)
|
||||
hawk_ooi_t HawkStd::readFile (File& io, hawk_ooch_t* buf, hawk_oow_t len)
|
||||
{
|
||||
return hawk_sio_getoochars((hawk_sio_t*)io.getHandle(), buf, len);
|
||||
}
|
||||
|
||||
hawk_ooi_t HawkStd::readFileBytes (File& io, hawk_bch_t* buf, hawk_oow_t len)
|
||||
hawk_ooi_t HawkStd::readFileBytes (File& io, hawk_bch_t* buf, hawk_oow_t len)
|
||||
{
|
||||
return hawk_sio_getbchars((hawk_sio_t*)io.getHandle(), buf, len);
|
||||
}
|
||||
@ -800,14 +800,14 @@ hawk_ooi_t HawkStd::writeFileBytes (File& io, const hawk_bch_t* buf, hawk_oow_t
|
||||
return hawk_sio_putbchars((hawk_sio_t*)io.getHandle(), buf, len);
|
||||
}
|
||||
|
||||
int HawkStd::flushFile (File& io)
|
||||
{
|
||||
int HawkStd::flushFile (File& io)
|
||||
{
|
||||
return hawk_sio_flush((hawk_sio_t*)io.getHandle());
|
||||
}
|
||||
|
||||
void HawkStd::setConsoleCmgr (const hawk_cmgr_t* cmgr)
|
||||
{
|
||||
this->console_cmgr = (hawk_cmgr_t*)cmgr;
|
||||
this->console_cmgr = (hawk_cmgr_t*)cmgr;
|
||||
}
|
||||
|
||||
const hawk_cmgr_t* HawkStd::getConsoleCmgr () const
|
||||
@ -815,7 +815,7 @@ const hawk_cmgr_t* HawkStd::getConsoleCmgr () const
|
||||
return this->console_cmgr;
|
||||
}
|
||||
|
||||
int HawkStd::addConsoleOutput (const hawk_uch_t* arg, hawk_oow_t len)
|
||||
int HawkStd::addConsoleOutput (const hawk_uch_t* arg, hawk_oow_t len)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
int n = this->ofile.add(this->hawk, arg, len);
|
||||
@ -823,12 +823,12 @@ int HawkStd::addConsoleOutput (const hawk_uch_t* arg, hawk_oow_t len)
|
||||
return n;
|
||||
}
|
||||
|
||||
int HawkStd::addConsoleOutput (const hawk_uch_t* arg)
|
||||
int HawkStd::addConsoleOutput (const hawk_uch_t* arg)
|
||||
{
|
||||
return this->addConsoleOutput(arg, hawk_count_ucstr(arg));
|
||||
}
|
||||
|
||||
int HawkStd::addConsoleOutput (const hawk_bch_t* arg, hawk_oow_t len)
|
||||
int HawkStd::addConsoleOutput (const hawk_bch_t* arg, hawk_oow_t len)
|
||||
{
|
||||
HAWK_ASSERT (this->hawk != HAWK_NULL);
|
||||
int n = this->ofile.add(this->hawk, arg, len);
|
||||
@ -836,13 +836,13 @@ int HawkStd::addConsoleOutput (const hawk_bch_t* arg, hawk_oow_t len)
|
||||
return n;
|
||||
}
|
||||
|
||||
int HawkStd::addConsoleOutput (const hawk_bch_t* arg)
|
||||
int HawkStd::addConsoleOutput (const hawk_bch_t* arg)
|
||||
{
|
||||
return this->addConsoleOutput(arg, hawk_count_bcstr(arg));
|
||||
}
|
||||
|
||||
|
||||
void HawkStd::clearConsoleOutputs ()
|
||||
void HawkStd::clearConsoleOutputs ()
|
||||
{
|
||||
this->ofile.clear (this->hawk);
|
||||
}
|
||||
@ -875,8 +875,8 @@ static int check_var_assign (hawk_rtx_t* rtx, const hawk_ooch_t* str)
|
||||
return n;
|
||||
}
|
||||
|
||||
int HawkStd::open_console_in (Console& io)
|
||||
{
|
||||
int HawkStd::open_console_in (Console& io)
|
||||
{
|
||||
hawk_rtx_t* rtx = (hawk_rtx_t*)io;
|
||||
hawk_sio_t* sio;
|
||||
hawk_val_t* v_argc, * v_argv, * v_pair;
|
||||
@ -894,17 +894,17 @@ int HawkStd::open_console_in (Console& io)
|
||||
if (hawk_rtx_valtoint(rtx, v_argc, &i_argc) <= -1) return -1;
|
||||
|
||||
/* handle special case when ARGV[x] has been altered.
|
||||
* so from here down, the file name gotten from
|
||||
* rxtn->c.in.files is not important and is overridden
|
||||
* so from here down, the file name gotten from
|
||||
* rxtn->c.in.files is not important and is overridden
|
||||
* from ARGV.
|
||||
* 'BEGIN { ARGV[1]="file3"; }
|
||||
* 'BEGIN { ARGV[1]="file3"; }
|
||||
* { print $0; }' file1 file2
|
||||
*/
|
||||
v_argv = hawk_rtx_getgbl(rtx, this->gbl_argv);
|
||||
HAWK_ASSERT (v_argv != HAWK_NULL);
|
||||
if (HAWK_RTX_GETVALTYPE(rtx, v_argv) != HAWK_VAL_MAP)
|
||||
{
|
||||
/* with flexmap on, you can change ARGV to a scalar.
|
||||
/* with flexmap on, you can change ARGV to a scalar.
|
||||
* BEGIN { ARGV="xxx"; }
|
||||
* you must not do this. */
|
||||
hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_EINVAL, HAWK_T("phony value in ARGV"));
|
||||
@ -933,12 +933,12 @@ nextfile:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ibuflen = hawk_int_to_oocstr(this->runarg_index + 1, 10, HAWK_NULL, ibuf, HAWK_COUNTOF(ibuf));
|
||||
pair = hawk_map_search(map, ibuf, ibuflen);
|
||||
if (!pair)
|
||||
if (!pair)
|
||||
{
|
||||
if (this->runarg_count <= 0) goto console_open_stdin;
|
||||
return 0;
|
||||
@ -970,8 +970,8 @@ nextfile:
|
||||
|
||||
/*
|
||||
* this is different from the -v option.
|
||||
* if an argument has a special form of var=val, it is treated specially
|
||||
*
|
||||
* if an argument has a special form of var=val, it is treated specially
|
||||
*
|
||||
* on the command-line
|
||||
* hawk -f a.hawk a=20 /etc/passwd
|
||||
* or via ARGV
|
||||
@ -990,12 +990,12 @@ nextfile:
|
||||
sio = open_sio_std(HAWK_NULL, io, HAWK_SIO_STDIN, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
|
||||
else
|
||||
sio = open_sio(HAWK_NULL, io, file, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
|
||||
if (sio == HAWK_NULL)
|
||||
if (sio == HAWK_NULL)
|
||||
{
|
||||
hawk_rtx_freevaloocstr (rtx, v_pair, as.ptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (hawk_rtx_setfilenamewithoochars(rtx, file, hawk_count_oocstr(file)) <= -1)
|
||||
{
|
||||
hawk_sio_close (sio);
|
||||
@ -1015,7 +1015,7 @@ nextfile:
|
||||
return 1;
|
||||
}
|
||||
|
||||
int HawkStd::open_console_out (Console& io)
|
||||
int HawkStd::open_console_out (Console& io)
|
||||
{
|
||||
hawk_rtx_t* rtx = (hawk_rtx_t*)io;
|
||||
|
||||
@ -1023,7 +1023,7 @@ int HawkStd::open_console_out (Console& io)
|
||||
{
|
||||
HAWK_ASSERT (this->ofile.len == 0 && this->ofile.capa == 0);
|
||||
|
||||
if (this->ofile_count == 0)
|
||||
if (this->ofile_count == 0)
|
||||
{
|
||||
hawk_sio_t* sio;
|
||||
sio = open_sio_std(
|
||||
@ -1042,7 +1042,7 @@ int HawkStd::open_console_out (Console& io)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* a temporary variable sio is used here not to change
|
||||
/* a temporary variable sio is used here not to change
|
||||
* any fields of riod when the open operation fails */
|
||||
hawk_sio_t* sio;
|
||||
const hawk_ooch_t* file;
|
||||
@ -1056,7 +1056,7 @@ int HawkStd::open_console_out (Console& io)
|
||||
}
|
||||
|
||||
if (hawk_count_oocstr(file) != this->ofile.ptr[this->ofile_index].len)
|
||||
{
|
||||
{
|
||||
((Run*)io)->formatError (HAWK_EIONMNL, HAWK_NULL, HAWK_T("invalid I/O name of length %zu containing '\\0'"), this->ofile.ptr[this->ofile_index].len);
|
||||
return -1;
|
||||
}
|
||||
@ -1066,7 +1066,7 @@ int HawkStd::open_console_out (Console& io)
|
||||
else
|
||||
sio = open_sio(HAWK_NULL, io, file, HAWK_SIO_WRITE | HAWK_SIO_CREATE | HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR);
|
||||
if (sio == HAWK_NULL) return -1;
|
||||
|
||||
|
||||
if (hawk_rtx_setofilenamewithoochars(rtx, file, hawk_count_oocstr(file)) == -1)
|
||||
{
|
||||
hawk_sio_close (sio);
|
||||
@ -1082,7 +1082,7 @@ int HawkStd::open_console_out (Console& io)
|
||||
}
|
||||
}
|
||||
|
||||
int HawkStd::openConsole (Console& io)
|
||||
int HawkStd::openConsole (Console& io)
|
||||
{
|
||||
Console::Mode mode = io.getMode();
|
||||
|
||||
@ -1102,13 +1102,13 @@ int HawkStd::openConsole (Console& io)
|
||||
}
|
||||
}
|
||||
|
||||
int HawkStd::closeConsole (Console& io)
|
||||
{
|
||||
int HawkStd::closeConsole (Console& io)
|
||||
{
|
||||
hawk_sio_close ((hawk_sio_t*)io.getHandle());
|
||||
return 0;
|
||||
}
|
||||
|
||||
hawk_ooi_t HawkStd::readConsole (Console& io, hawk_ooch_t* data, hawk_oow_t size)
|
||||
hawk_ooi_t HawkStd::readConsole (Console& io, hawk_ooch_t* data, hawk_oow_t size)
|
||||
{
|
||||
hawk_ooi_t nn;
|
||||
|
||||
@ -1120,7 +1120,7 @@ hawk_ooi_t HawkStd::readConsole (Console& io, hawk_ooch_t* data, hawk_oow_t size
|
||||
n = open_console_in(io);
|
||||
if (n == -1) return -1;
|
||||
|
||||
if (n == 0)
|
||||
if (n == 0)
|
||||
{
|
||||
/* no more input console */
|
||||
return 0;
|
||||
@ -1133,7 +1133,7 @@ hawk_ooi_t HawkStd::readConsole (Console& io, hawk_ooch_t* data, hawk_oow_t size
|
||||
return nn;
|
||||
}
|
||||
|
||||
hawk_ooi_t HawkStd::readConsoleBytes (Console& io, hawk_bch_t* data, hawk_oow_t size)
|
||||
hawk_ooi_t HawkStd::readConsoleBytes (Console& io, hawk_bch_t* data, hawk_oow_t size)
|
||||
{
|
||||
hawk_ooi_t nn;
|
||||
|
||||
@ -1145,7 +1145,7 @@ hawk_ooi_t HawkStd::readConsoleBytes (Console& io, hawk_bch_t* data, hawk_oow_t
|
||||
n = open_console_in(io);
|
||||
if (n == -1) return -1;
|
||||
|
||||
if (n == 0)
|
||||
if (n == 0)
|
||||
{
|
||||
/* no more input console */
|
||||
return 0;
|
||||
@ -1158,31 +1158,31 @@ hawk_ooi_t HawkStd::readConsoleBytes (Console& io, hawk_bch_t* data, hawk_oow_t
|
||||
return nn;
|
||||
}
|
||||
|
||||
hawk_ooi_t HawkStd::writeConsole (Console& io, const hawk_ooch_t* data, hawk_oow_t size)
|
||||
hawk_ooi_t HawkStd::writeConsole (Console& io, const hawk_ooch_t* data, hawk_oow_t size)
|
||||
{
|
||||
return hawk_sio_putoochars((hawk_sio_t*)io.getHandle(), data, size);
|
||||
}
|
||||
|
||||
hawk_ooi_t HawkStd::writeConsoleBytes (Console& io, const hawk_bch_t* data, hawk_oow_t size)
|
||||
hawk_ooi_t HawkStd::writeConsoleBytes (Console& io, const hawk_bch_t* data, hawk_oow_t size)
|
||||
{
|
||||
return hawk_sio_putbchars((hawk_sio_t*)io.getHandle(), data, size);
|
||||
}
|
||||
|
||||
int HawkStd::flushConsole (Console& io)
|
||||
{
|
||||
int HawkStd::flushConsole (Console& io)
|
||||
{
|
||||
return hawk_sio_flush ((hawk_sio_t*)io.getHandle());
|
||||
}
|
||||
|
||||
int HawkStd::nextConsole (Console& io)
|
||||
{
|
||||
int HawkStd::nextConsole (Console& io)
|
||||
{
|
||||
int n;
|
||||
hawk_sio_t* sio = (hawk_sio_t*)io.getHandle();
|
||||
|
||||
n = (io.getMode() == Console::READ)?
|
||||
n = (io.getMode() == Console::READ)?
|
||||
open_console_in(io): open_console_out(io);
|
||||
if (n == -1) return -1;
|
||||
|
||||
if (n == 0)
|
||||
if (n == 0)
|
||||
{
|
||||
/* if there is no more file, keep the previous handle */
|
||||
return 0;
|
||||
@ -1193,30 +1193,30 @@ int HawkStd::nextConsole (Console& io)
|
||||
}
|
||||
|
||||
// memory allocation primitives
|
||||
void* HawkStd::allocMem (hawk_oow_t n)
|
||||
{
|
||||
return ::malloc (n);
|
||||
void* HawkStd::allocMem (hawk_oow_t n)
|
||||
{
|
||||
return ::malloc (n);
|
||||
}
|
||||
|
||||
void* HawkStd::reallocMem (void* ptr, hawk_oow_t n)
|
||||
{
|
||||
return ::realloc (ptr, n);
|
||||
void* HawkStd::reallocMem (void* ptr, hawk_oow_t n)
|
||||
{
|
||||
return ::realloc (ptr, n);
|
||||
}
|
||||
|
||||
void HawkStd::freeMem (void* ptr)
|
||||
{
|
||||
::free (ptr);
|
||||
void HawkStd::freeMem (void* ptr)
|
||||
{
|
||||
::free (ptr);
|
||||
}
|
||||
|
||||
// miscellaneous primitive
|
||||
|
||||
hawk_flt_t HawkStd::pow (hawk_flt_t x, hawk_flt_t y)
|
||||
{
|
||||
hawk_flt_t HawkStd::pow (hawk_flt_t x, hawk_flt_t y)
|
||||
{
|
||||
return hawk_stdmathpow(this->hawk, x, y);
|
||||
}
|
||||
|
||||
hawk_flt_t HawkStd::mod (hawk_flt_t x, hawk_flt_t y)
|
||||
{
|
||||
hawk_flt_t HawkStd::mod (hawk_flt_t x, hawk_flt_t y)
|
||||
{
|
||||
return hawk_stdmathmod(this->hawk, x, y);
|
||||
}
|
||||
|
||||
@ -1258,12 +1258,12 @@ int HawkStd::SourceFile::open (Data& io)
|
||||
{
|
||||
if (io.getMode() == READ)
|
||||
sio = open_sio_std(
|
||||
io, HAWK_NULL, HAWK_SIO_STDIN,
|
||||
io, HAWK_NULL, HAWK_SIO_STDIN,
|
||||
HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
|
||||
else
|
||||
sio = open_sio_std(
|
||||
io, HAWK_NULL, HAWK_SIO_STDOUT,
|
||||
HAWK_SIO_WRITE | HAWK_SIO_CREATE |
|
||||
io, HAWK_NULL, HAWK_SIO_STDOUT,
|
||||
HAWK_SIO_WRITE | HAWK_SIO_CREATE |
|
||||
HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR | HAWK_SIO_LINEBREAK);
|
||||
if (sio == HAWK_NULL) return -1;
|
||||
}
|
||||
@ -1271,8 +1271,8 @@ int HawkStd::SourceFile::open (Data& io)
|
||||
{
|
||||
sio = open_sio(
|
||||
io, HAWK_NULL, xpath,
|
||||
(io.getMode() == READ?
|
||||
(HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH):
|
||||
(io.getMode() == READ?
|
||||
(HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH):
|
||||
(HAWK_SIO_WRITE | HAWK_SIO_CREATE | HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR))
|
||||
);
|
||||
if (sio == HAWK_NULL) return -1;
|
||||
@ -1284,7 +1284,7 @@ int HawkStd::SourceFile::open (Data& io)
|
||||
}
|
||||
else
|
||||
{
|
||||
// open an included file
|
||||
// open an included file
|
||||
const hawk_ooch_t* ioname;
|
||||
hawk_ooch_t* xpath;
|
||||
|
||||
@ -1351,8 +1351,8 @@ int HawkStd::SourceFile::open (Data& io)
|
||||
|
||||
sio = open_sio(
|
||||
io, HAWK_NULL, xpath,
|
||||
(io.getMode() == READ?
|
||||
(HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH):
|
||||
(io.getMode() == READ?
|
||||
(HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH):
|
||||
(HAWK_SIO_WRITE | HAWK_SIO_CREATE | HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR))
|
||||
);
|
||||
if (!sio) return -1;
|
||||
@ -1397,7 +1397,7 @@ int HawkStd::SourceString::open (Data& io)
|
||||
if (io.getName() == HAWK_NULL)
|
||||
{
|
||||
// open the main source file.
|
||||
if (io.getMode() == WRITE)
|
||||
if (io.getMode() == WRITE)
|
||||
{
|
||||
// SourceString does not support writing.
|
||||
((Hawk*)io)->setError (HAWK_ENOIMPL);
|
||||
@ -1424,7 +1424,7 @@ int HawkStd::SourceString::open (Data& io)
|
||||
this->str = hawk_dupbcstr(this->_hawk, (const hawk_bch_t*)this->_str, HAWK_NULL);
|
||||
#endif
|
||||
}
|
||||
if (HAWK_UNLIKELY(!this->str))
|
||||
if (HAWK_UNLIKELY(!this->str))
|
||||
{
|
||||
this->_hawk = HAWK_NULL;
|
||||
return -1;
|
||||
@ -1435,7 +1435,7 @@ int HawkStd::SourceString::open (Data& io)
|
||||
}
|
||||
else
|
||||
{
|
||||
// open an included file
|
||||
// open an included file
|
||||
const hawk_ooch_t* ioname;
|
||||
hawk_ooch_t* xpath;
|
||||
|
||||
@ -1484,8 +1484,8 @@ int HawkStd::SourceString::open (Data& io)
|
||||
|
||||
sio = open_sio(
|
||||
io, HAWK_NULL, xpath,
|
||||
(io.getMode() == READ?
|
||||
(HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH):
|
||||
(io.getMode() == READ?
|
||||
(HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH):
|
||||
(HAWK_SIO_WRITE | HAWK_SIO_CREATE | HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR))
|
||||
);
|
||||
if (!sio) return -1;
|
||||
@ -1542,7 +1542,7 @@ hawk_ooi_t HawkStd::SourceString::write (Data& io, const hawk_ooch_t* buf, hawk_
|
||||
else
|
||||
{
|
||||
// in fact, this block will never be reached as
|
||||
// there is no included file concept for deparsing
|
||||
// there is no included file concept for deparsing
|
||||
return hawk_sio_putoochars((hawk_sio_t*)io.getHandle(), buf, len);
|
||||
}
|
||||
}
|
||||
|
@ -66,9 +66,9 @@ struct hawk_cut_t
|
||||
hawk_ooch_t din; /**< input field delimiter */
|
||||
hawk_ooch_t dout; /**< output field delimiter */
|
||||
|
||||
hawk_oow_t count;
|
||||
hawk_oow_t fcount;
|
||||
hawk_oow_t ccount;
|
||||
hawk_oow_t count;
|
||||
hawk_oow_t fcount;
|
||||
hawk_oow_t ccount;
|
||||
} sel;
|
||||
|
||||
/** source text pointers */
|
||||
@ -101,7 +101,7 @@ struct hawk_cut_t
|
||||
hawk_oow_t len;
|
||||
int eof;
|
||||
} out;
|
||||
|
||||
|
||||
/** data needed for input streams */
|
||||
struct
|
||||
{
|
||||
|
56
lib/cut.c
56
lib/cut.c
@ -329,7 +329,7 @@ int hawk_cut_comp (hawk_cut_t* cut, hawk_cut_io_impl_t inf)
|
||||
if (c == HAWK_T('d'))
|
||||
{
|
||||
/* the next character is the input delimiter.
|
||||
* the output delimiter defaults to the input
|
||||
* the output delimiter defaults to the input
|
||||
* delimiter. */
|
||||
NXTSC_GOTO(cut, c, oops);
|
||||
if (EOF(c))
|
||||
@ -344,7 +344,7 @@ int hawk_cut_comp (hawk_cut_t* cut, hawk_cut_io_impl_t inf)
|
||||
}
|
||||
else if (c == HAWK_T('D'))
|
||||
{
|
||||
/* the next two characters are the input and
|
||||
/* the next two characters are the input and
|
||||
* the output delimiter each. */
|
||||
NXTSC_GOTO(cut, c, oops);
|
||||
if (EOF(c))
|
||||
@ -364,7 +364,7 @@ int hawk_cut_comp (hawk_cut_t* cut, hawk_cut_io_impl_t inf)
|
||||
|
||||
NXTSC_GOTO(cut, c, oops);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if (c == HAWK_T('c') || c == HAWK_T('f'))
|
||||
{
|
||||
@ -372,16 +372,16 @@ int hawk_cut_comp (hawk_cut_t* cut, hawk_cut_io_impl_t inf)
|
||||
NXTSC_GOTO(cut, c, oops);
|
||||
while (hawk_is_ooch_space(c)) NXTSC_GOTO(cut, c, oops);
|
||||
}
|
||||
|
||||
|
||||
if (hawk_is_ooch_digit(c))
|
||||
{
|
||||
do
|
||||
{
|
||||
start = start * 10 + (c - HAWK_T('0'));
|
||||
do
|
||||
{
|
||||
start = start * 10 + (c - HAWK_T('0'));
|
||||
NXTSC_GOTO(cut, c, oops);
|
||||
}
|
||||
}
|
||||
while (hawk_is_ooch_digit(c));
|
||||
|
||||
|
||||
while (hawk_is_ooch_space(c)) NXTSC_GOTO(cut, c, oops);
|
||||
mask |= MASK_START;
|
||||
}
|
||||
@ -394,11 +394,11 @@ int hawk_cut_comp (hawk_cut_t* cut, hawk_cut_io_impl_t inf)
|
||||
|
||||
if (hawk_is_ooch_digit(c))
|
||||
{
|
||||
do
|
||||
{
|
||||
end = end * 10 + (c - HAWK_T('0'));
|
||||
do
|
||||
{
|
||||
end = end * 10 + (c - HAWK_T('0'));
|
||||
NXTSC_GOTO(cut, c, oops);
|
||||
}
|
||||
}
|
||||
while (hawk_is_ooch_digit(c));
|
||||
mask |= MASK_END;
|
||||
}
|
||||
@ -477,7 +477,7 @@ static int read_line (hawk_cut_t* cut)
|
||||
break;
|
||||
}
|
||||
|
||||
if (c == HAWK_T('\n'))
|
||||
if (c == HAWK_T('\n'))
|
||||
{
|
||||
/* don't include the line terminater to a line */
|
||||
/* TODO: support different line end convension */
|
||||
@ -485,14 +485,14 @@ static int read_line (hawk_cut_t* cut)
|
||||
}
|
||||
|
||||
if (hawk_ooecs_ccat(&cut->e.in.line, c) == (hawk_oow_t)-1) return -1;
|
||||
len++;
|
||||
len++;
|
||||
}
|
||||
|
||||
cut->e.in.num++;
|
||||
|
||||
if (cut->option & HAWK_CUT_TRIMSPACE) hawk_ooecs_trim(&cut->e.in.line, HAWK_TRIM_LEFT | HAWK_TRIM_RIGHT);
|
||||
if (cut->option & HAWK_CUT_NORMSPACE) hawk_ooecs_compact(&cut->e.in.line);
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int flush (hawk_cut_t* cut)
|
||||
@ -553,7 +553,7 @@ static int cut_chars (hawk_cut_t* cut, hawk_oow_t start, hawk_oow_t end, int del
|
||||
if (end >= 1) end--;
|
||||
|
||||
if (end >= len) end = len - 1;
|
||||
|
||||
|
||||
if (delim && write_char(cut, cut->sel.dout) <= -1) return -1;
|
||||
if (write_str(cut, &ptr[start], end-start+1) <= -1) return -1;
|
||||
|
||||
@ -621,7 +621,7 @@ static int split_line (hawk_cut_t* cut)
|
||||
nsz = cut->e.in.cflds;
|
||||
if (nsz > 100000) nsz += 100000;
|
||||
else nsz *= 2;
|
||||
|
||||
|
||||
tmp = hawk_cut_allocmem(cut, HAWK_SIZEOF(*tmp) * nsz);
|
||||
if (HAWK_UNLIKELY(!tmp)) return -1;
|
||||
|
||||
@ -707,7 +707,7 @@ int hawk_cut_exec (hawk_cut_t* cut, hawk_cut_io_impl_t inf, hawk_cut_io_impl_t o
|
||||
cut->e.out.fun = outf;
|
||||
cut->e.out.eof = 0;
|
||||
cut->e.out.len = 0;
|
||||
|
||||
|
||||
cut->e.in.fun = inf;
|
||||
cut->e.in.eof = 0;
|
||||
cut->e.in.len = 0;
|
||||
@ -769,9 +769,9 @@ int hawk_cut_exec (hawk_cut_t* cut, hawk_cut_io_impl_t inf, hawk_cut_io_impl_t o
|
||||
cut,
|
||||
b->range[i].start,
|
||||
b->range[i].end,
|
||||
id == 2
|
||||
id == 2
|
||||
);
|
||||
if (n >= 1)
|
||||
if (n >= 1)
|
||||
{
|
||||
/* mark a char's been output */
|
||||
id = 1;
|
||||
@ -783,9 +783,9 @@ int hawk_cut_exec (hawk_cut_t* cut, hawk_cut_io_impl_t inf, hawk_cut_io_impl_t o
|
||||
cut,
|
||||
b->range[i].start,
|
||||
b->range[i].end,
|
||||
id > 0
|
||||
id > 0
|
||||
);
|
||||
if (n >= 1)
|
||||
if (n >= 1)
|
||||
{
|
||||
/* mark a field's been output */
|
||||
id = 2;
|
||||
@ -806,7 +806,7 @@ int hawk_cut_exec (hawk_cut_t* cut, hawk_cut_io_impl_t inf, hawk_cut_io_impl_t o
|
||||
{
|
||||
/* if only field selectors are specified */
|
||||
|
||||
if (delimited)
|
||||
if (delimited)
|
||||
{
|
||||
/* and if the input line is delimited,
|
||||
* write a line break */
|
||||
@ -819,7 +819,7 @@ int hawk_cut_exec (hawk_cut_t* cut, hawk_cut_io_impl_t inf, hawk_cut_io_impl_t o
|
||||
* on the option set. */
|
||||
if (write_str(cut, HAWK_OOECS_PTR(&cut->e.in.line), HAWK_OOECS_LEN(&cut->e.in.line)) <= -1)
|
||||
{
|
||||
ret = -1; goto done;
|
||||
ret = -1; goto done;
|
||||
}
|
||||
|
||||
/* a line break is needed in this case */
|
||||
@ -827,9 +827,9 @@ int hawk_cut_exec (hawk_cut_t* cut, hawk_cut_io_impl_t inf, hawk_cut_io_impl_t o
|
||||
}
|
||||
}
|
||||
|
||||
if (linebreak && write_linebreak(cut) <= -1)
|
||||
{
|
||||
ret = -1; goto done;
|
||||
if (linebreak && write_linebreak(cut) <= -1)
|
||||
{
|
||||
ret = -1; goto done;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
/** @file
|
||||
* This file defines a text cutter utility.
|
||||
*
|
||||
*
|
||||
* @todo HAWK_CUT_ORDEREDSEL - A selector 5,3,1 is ordered to 1,3,5
|
||||
*/
|
||||
|
||||
@ -42,7 +42,7 @@
|
||||
|
||||
/** @struct hawk_cut_t
|
||||
* The hawk_cut_t type defines a text cutter. The details are hidden as it is
|
||||
* a large complex structure vulnerable to unintended changes.
|
||||
* a large complex structure vulnerable to unintended changes.
|
||||
*/
|
||||
typedef struct hawk_cut_t hawk_cut_t;
|
||||
|
||||
@ -57,14 +57,14 @@ struct hawk_cut_alt_t
|
||||
HAWK_CUT_HDR;
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* The hawk_cut_option_t type defines various option codes for a text cutter.
|
||||
* Options can be OR'ed with each other and be passed to a text cutter with
|
||||
* the hawk_cut_setoption() function.
|
||||
*/
|
||||
enum hawk_cut_option_t
|
||||
{
|
||||
/** show delimited line only. if not set, undelimited lines are
|
||||
/** show delimited line only. if not set, undelimited lines are
|
||||
* shown in its entirety */
|
||||
HAWK_CUT_DELIMONLY = (1 << 0),
|
||||
|
||||
@ -83,7 +83,7 @@ enum hawk_cut_option_t
|
||||
typedef enum hawk_cut_option_t hawk_cut_option_t;
|
||||
|
||||
/**
|
||||
* The hawk_cut_io_cmd_t type defines I/O command codes. The code indicates
|
||||
* The hawk_cut_io_cmd_t type defines I/O command codes. The code indicates
|
||||
* the action to take in an I/O handler.
|
||||
*/
|
||||
enum hawk_cut_io_cmd_t
|
||||
@ -96,7 +96,7 @@ enum hawk_cut_io_cmd_t
|
||||
typedef enum hawk_cut_io_cmd_t hawk_cut_io_cmd_t;
|
||||
|
||||
/**
|
||||
* The hawk_cut_io_arg_t type defines a data structure required by
|
||||
* The hawk_cut_io_arg_t type defines a data structure required by
|
||||
* an I/O handler.
|
||||
*/
|
||||
struct hawk_cut_io_arg_t
|
||||
@ -106,7 +106,7 @@ struct hawk_cut_io_arg_t
|
||||
};
|
||||
typedef struct hawk_cut_io_arg_t hawk_cut_io_arg_t;
|
||||
|
||||
/**
|
||||
/**
|
||||
* The hawk_cut_io_impl_t type defines an I/O handler. hawk_cut_exec() calls
|
||||
* I/O handlers to read from and write to a text stream.
|
||||
*/
|
||||
@ -251,7 +251,7 @@ static HAWK_INLINE void hawk_cut_setcmgr (hawk_cut_t* cut, hawk_cmgr_t* cmgr) {
|
||||
/**
|
||||
* The hawk_cut_getoption() function retrieves the current options set in
|
||||
* a text cutter.
|
||||
* @return 0 or a number OR'ed of #hawk_cut_option_t values
|
||||
* @return 0 or a number OR'ed of #hawk_cut_option_t values
|
||||
*/
|
||||
HAWK_EXPORT int hawk_cut_getoption (
|
||||
hawk_cut_t* cut /**< text cutter */
|
||||
@ -368,7 +368,7 @@ HAWK_EXPORT void hawk_cut_clear (
|
||||
|
||||
/**
|
||||
* The hawk_cut_comp() function compiles a selector into an internal form.
|
||||
* @return 0 on success, -1 on error
|
||||
* @return 0 on success, -1 on error
|
||||
*/
|
||||
HAWK_EXPORT int hawk_cut_comp (
|
||||
hawk_cut_t* cut, /**< text cutter */
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <hawk-cmn.h>
|
||||
#include <hawk-gem.h>
|
||||
|
||||
/**
|
||||
/**
|
||||
* The hawk_json_t type defines a simple json parser.
|
||||
*/
|
||||
typedef struct hawk_json_t hawk_json_t;
|
||||
@ -126,13 +126,26 @@ HAWK_EXPORT void hawk_json_reset (
|
||||
hawk_json_t* json
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_json_feed (
|
||||
hawk_json_t* json,
|
||||
const void* ptr,
|
||||
hawk_oow_t len,
|
||||
hawk_oow_t* xlen
|
||||
HAWK_EXPORT int hawk_json_feedbchars (
|
||||
hawk_json_t* json,
|
||||
const hawk_bch_t* ptr,
|
||||
hawk_oow_t len,
|
||||
hawk_oow_t* xlen
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_json_feeduchars (
|
||||
hawk_json_t* json,
|
||||
const hawk_uch_t* ptr,
|
||||
hawk_oow_t len,
|
||||
hawk_oow_t* xlen
|
||||
);
|
||||
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
# define hawk_json_feed hawk_json_feeduchars
|
||||
#else
|
||||
# define hawk_json_feed hawk_json_feedbchars
|
||||
#endif
|
||||
|
||||
HAWK_EXPORT hawk_json_state_t hawk_json_getstate (
|
||||
hawk_json_t* json
|
||||
);
|
||||
@ -208,12 +221,12 @@ static HAWK_INLINE void hawk_json_geterror (hawk_json_t* json, hawk_errnum_t* er
|
||||
#define hawk_json_geterror(json, errnum, errmsg, errloc) (hawk_gem_geterror(hawk_json_getgem(json), errnum, errmsg, errloc))
|
||||
#endif
|
||||
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
# define hawk_json_geterrmsg hawk_json_geterrbmsg
|
||||
# define hawk_json_geterrinf hawk_json_geterrbinf
|
||||
#else
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
# define hawk_json_geterrmsg hawk_json_geterrumsg
|
||||
# define hawk_json_geterrinf hawk_json_geterruinf
|
||||
#else
|
||||
# define hawk_json_geterrmsg hawk_json_geterrbmsg
|
||||
# define hawk_json_geterrinf hawk_json_geterrbinf
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -143,6 +143,35 @@ HAWK_EXPORT int hawk_comp_bchars_bcstr (
|
||||
|
||||
/* ------------------------------------ */
|
||||
|
||||
HAWK_EXPORT int hawk_comp_ucstr_bcstr (
|
||||
const hawk_uch_t* str1,
|
||||
const hawk_bch_t* str2,
|
||||
int ignorecase
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_comp_ucstr_bcstr_limited (
|
||||
const hawk_uch_t* str1,
|
||||
const hawk_bch_t* str2,
|
||||
hawk_oow_t maxlen,
|
||||
int ignorecase
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_comp_uchars_bcstr (
|
||||
const hawk_uch_t* str1,
|
||||
hawk_oow_t len,
|
||||
const hawk_bch_t* str2,
|
||||
int ignorecase
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_comp_bchars_ucstr (
|
||||
const hawk_bch_t* str1,
|
||||
hawk_oow_t len,
|
||||
const hawk_uch_t* str2,
|
||||
int ignorecase
|
||||
);
|
||||
|
||||
/* ------------------------------------ */
|
||||
|
||||
HAWK_EXPORT hawk_oow_t hawk_concat_uchars_to_ucstr (
|
||||
hawk_uch_t* buf,
|
||||
hawk_oow_t bsz,
|
||||
|
@ -143,6 +143,35 @@ HAWK_EXPORT int hawk_comp_bchars_bcstr (
|
||||
|
||||
/* ------------------------------------ */
|
||||
|
||||
HAWK_EXPORT int hawk_comp_ucstr_bcstr (
|
||||
const hawk_uch_t* str1,
|
||||
const hawk_bch_t* str2,
|
||||
int ignorecase
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_comp_ucstr_bcstr_limited (
|
||||
const hawk_uch_t* str1,
|
||||
const hawk_bch_t* str2,
|
||||
hawk_oow_t maxlen,
|
||||
int ignorecase
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_comp_uchars_bcstr (
|
||||
const hawk_uch_t* str1,
|
||||
hawk_oow_t len,
|
||||
const hawk_bch_t* str2,
|
||||
int ignorecase
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_comp_bchars_ucstr (
|
||||
const hawk_bch_t* str1,
|
||||
hawk_oow_t len,
|
||||
const hawk_uch_t* str2,
|
||||
int ignorecase
|
||||
);
|
||||
|
||||
/* ------------------------------------ */
|
||||
|
||||
HAWK_EXPORT hawk_oow_t hawk_concat_uchars_to_ucstr (
|
||||
hawk_uch_t* buf,
|
||||
hawk_oow_t bsz,
|
||||
|
@ -374,35 +374,6 @@ HAWK_EXPORT hawk_oow_t hawk_hash_bytes_ (
|
||||
* STRING
|
||||
* ========================================================================= */
|
||||
|
||||
HAWK_EXPORT int hawk_comp_ucstr_bcstr (
|
||||
const hawk_uch_t* str1,
|
||||
const hawk_bch_t* str2,
|
||||
int ignorecase
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_comp_ucstr_bcstr_limited (
|
||||
const hawk_uch_t* str1,
|
||||
const hawk_bch_t* str2,
|
||||
hawk_oow_t maxlen,
|
||||
int ignorecase
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_comp_uchars_bcstr (
|
||||
const hawk_uch_t* str1,
|
||||
hawk_oow_t len,
|
||||
const hawk_bch_t* str2,
|
||||
int ignorecase
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_comp_bchars_ucstr (
|
||||
const hawk_bch_t* str1,
|
||||
hawk_oow_t len,
|
||||
const hawk_uch_t* str2,
|
||||
int ignorecase
|
||||
);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
HAWK_EXPORT hawk_oow_t hawk_subst_for_uchars_to_ucstr (
|
||||
hawk_uch_t* buf,
|
||||
hawk_oow_t bsz,
|
||||
|
@ -40,15 +40,15 @@ struct hawk_json_state_node_t
|
||||
|
||||
struct
|
||||
{
|
||||
/* 0: ready to get key (at the beginning or got comma),
|
||||
/* 0: ready to get key (at the beginning or got comma),
|
||||
* 1: got key, 2: got colon, 3: got value */
|
||||
int state;
|
||||
int state;
|
||||
} id; /* in dictionary */
|
||||
struct
|
||||
{
|
||||
int escaped;
|
||||
int digit_count;
|
||||
/* acc is always of unicode type to handle \u and \U.
|
||||
/* acc is always of unicode type to handle \u and \U.
|
||||
* in the bch mode, it will get converted to a utf8 stream. */
|
||||
hawk_uch_t acc;
|
||||
} sv;
|
||||
@ -58,7 +58,7 @@ struct hawk_json_state_node_t
|
||||
int digit_count;
|
||||
/* for a character, no way to support the unicode character
|
||||
* in the bch mode */
|
||||
hawk_ooch_t acc;
|
||||
hawk_ooch_t acc;
|
||||
} cv;
|
||||
struct
|
||||
{
|
||||
|
163
lib/json.c
163
lib/json.c
@ -58,7 +58,7 @@ static int add_char_to_token (hawk_json_t* json, hawk_ooch_t ch)
|
||||
static int add_chars_to_token (hawk_json_t* json, const hawk_ooch_t* ptr, hawk_oow_t len)
|
||||
{
|
||||
hawk_oow_t i;
|
||||
|
||||
|
||||
if (json->tok_capa - json->tok.len > len)
|
||||
{
|
||||
hawk_ooch_t* tmp;
|
||||
@ -72,7 +72,7 @@ static int add_chars_to_token (hawk_json_t* json, const hawk_ooch_t* ptr, hawk_o
|
||||
json->tok.ptr = tmp;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
for (i = 0; i < len; i++)
|
||||
json->tok.ptr[json->tok.len++] = ptr[i];
|
||||
json->tok.ptr[json->tok.len] = HAWK_T('\0');
|
||||
return 0;
|
||||
@ -104,7 +104,7 @@ static int push_state (hawk_json_t* json, hawk_json_state_t state)
|
||||
|
||||
ss->state = state;
|
||||
ss->next = json->state_stack;
|
||||
|
||||
|
||||
json->state_stack = ss;
|
||||
return 0;
|
||||
}
|
||||
@ -114,7 +114,7 @@ static void pop_state (hawk_json_t* json)
|
||||
hawk_json_state_node_t* ss;
|
||||
|
||||
ss = json->state_stack;
|
||||
HAWK_ASSERT (ss != HAWK_NULL && ss != &json->state_top);
|
||||
HAWK_ASSERT(ss != HAWK_NULL && ss != &json->state_top);
|
||||
json->state_stack = ss->next;
|
||||
|
||||
if (json->state_stack->state == HAWK_JSON_STATE_IN_ARRAY)
|
||||
@ -139,11 +139,11 @@ static void pop_all_states (hawk_json_t* json)
|
||||
|
||||
static int invoke_data_inst (hawk_json_t* json, hawk_json_inst_t inst)
|
||||
{
|
||||
if (json->state_stack->state == HAWK_JSON_STATE_IN_DIC && json->state_stack->u.id.state == 1)
|
||||
if (json->state_stack->state == HAWK_JSON_STATE_IN_DIC && json->state_stack->u.id.state == 1)
|
||||
{
|
||||
if (inst != HAWK_JSON_INST_STRING)
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "dictionary key not a string - %.*js", json->tok.len, json->tok.ptr);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "dictionary key not a string - %.*js", json->tok.len, json->tok.ptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -208,7 +208,7 @@ static int handle_string_value_char (hawk_json_t* json, hawk_ooci_t c)
|
||||
if (n == 0 || n > HAWK_COUNTOF(bcsbuf))
|
||||
{
|
||||
/* illegal character or buffer to small */
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EECERR, "unable to convert %jc", json->state_stack->u.sv.acc);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EECERR, "unable to convert %jc", json->state_stack->u.sv.acc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -220,7 +220,7 @@ static int handle_string_value_char (hawk_json_t* json, hawk_ooci_t c)
|
||||
}
|
||||
else if (json->state_stack->u.sv.escaped == 1)
|
||||
{
|
||||
if (c >= '0' && c <= '8')
|
||||
if (c >= '0' && c <= '8')
|
||||
{
|
||||
json->state_stack->u.sv.escaped = 3;
|
||||
json->state_stack->u.sv.digit_count = 0;
|
||||
@ -316,7 +316,7 @@ static int handle_character_value_char (hawk_json_t* json, hawk_ooci_t c)
|
||||
}
|
||||
else if (json->state_stack->u.cv.escaped == 1)
|
||||
{
|
||||
if (c >= '0' && c <= '8')
|
||||
if (c >= '0' && c <= '8')
|
||||
{
|
||||
json->state_stack->u.cv.escaped = 3;
|
||||
json->state_stack->u.cv.digit_count = 0;
|
||||
@ -353,10 +353,10 @@ static int handle_character_value_char (hawk_json_t* json, hawk_ooci_t c)
|
||||
else if (c == '\'')
|
||||
{
|
||||
pop_state (json);
|
||||
|
||||
|
||||
if (json->tok.len < 1)
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "no character in a character literal");
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "no character in a character literal");
|
||||
return -1;
|
||||
}
|
||||
if (invoke_data_inst(json, HAWK_JSON_INST_CHARACTER) <= -1) return -1;
|
||||
@ -366,9 +366,9 @@ static int handle_character_value_char (hawk_json_t* json, hawk_ooci_t c)
|
||||
if (add_char_to_token(json, c) <= -1) return -1;
|
||||
}
|
||||
|
||||
if (json->tok.len > 1)
|
||||
if (json->tok.len > 1)
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "too many characters in a character literal - %.*js", (int)json->tok.len, json->tok.ptr);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "too many characters in a character literal - %.*js", (int)json->tok.len, json->tok.ptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -392,10 +392,10 @@ static int handle_numeric_value_char (hawk_json_t* json, hawk_ooci_t c)
|
||||
|
||||
pop_state (json);
|
||||
|
||||
HAWK_ASSERT (json->tok.len > 0);
|
||||
HAWK_ASSERT(json->tok.len > 0);
|
||||
if (!hawk_is_ooch_digit(json->tok.ptr[json->tok.len - 1]))
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "invalid numeric value - %.*js", (int)json->tok.len, json->tok.ptr);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "invalid numeric value - %.*js", (int)json->tok.len, json->tok.ptr);
|
||||
return -1;
|
||||
}
|
||||
if (invoke_data_inst(json, HAWK_JSON_INST_NUMBER) <= -1) return -1;
|
||||
@ -419,7 +419,7 @@ static int handle_word_value_char (hawk_json_t* json, hawk_ooci_t c)
|
||||
else if (hawk_comp_oochars_bcstr(json->tok.ptr, json->tok.len, "false", 0) == 0) inst = HAWK_JSON_INST_FALSE;
|
||||
else
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "invalid word value - %.*js", json->tok.len, json->tok.ptr);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "invalid word value - %.*js", json->tok.len, json->tok.ptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -445,14 +445,14 @@ static int handle_start_char (hawk_json_t* json, hawk_ooci_t c)
|
||||
if (json->prim.instcb(json, HAWK_JSON_INST_START_DIC, HAWK_NULL) <= -1) return -1;
|
||||
return 1;
|
||||
}
|
||||
else if (hawk_is_ooch_space(c))
|
||||
else if (hawk_is_ooch_space(c))
|
||||
{
|
||||
/* do nothing */
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "not starting with [ or { - %jc", (hawk_ooch_t)c);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "not starting with [ or { - %jc", (hawk_ooch_t)c);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -469,7 +469,7 @@ static int handle_char_in_array (hawk_json_t* json, hawk_ooci_t c)
|
||||
{
|
||||
if (!json->state_stack->u.ia.got_value)
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "redundant comma in array - %jc", (hawk_ooch_t)c);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "redundant comma in array - %jc", (hawk_ooch_t)c);
|
||||
return -1;
|
||||
}
|
||||
json->state_stack->u.ia.got_value = 0;
|
||||
@ -484,7 +484,7 @@ static int handle_char_in_array (hawk_json_t* json, hawk_ooci_t c)
|
||||
{
|
||||
if (json->state_stack->u.ia.got_value)
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "comma required in array - %jc", (hawk_ooch_t)c);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "comma required in array - %jc", (hawk_ooch_t)c);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -531,7 +531,7 @@ static int handle_char_in_array (hawk_json_t* json, hawk_ooci_t c)
|
||||
}
|
||||
else
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "wrong character inside array - %jc[%d]", (hawk_ooch_t)c, (int)c);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "wrong character inside array - %jc[%d]", (hawk_ooch_t)c, (int)c);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -549,7 +549,7 @@ static int handle_char_in_dic (hawk_json_t* json, hawk_ooci_t c)
|
||||
{
|
||||
if (json->state_stack->u.id.state != 1)
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "redundant colon in dictionary - %jc", (hawk_ooch_t)c);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "redundant colon in dictionary - %jc", (hawk_ooch_t)c);
|
||||
return -1;
|
||||
}
|
||||
json->state_stack->u.id.state++;
|
||||
@ -559,7 +559,7 @@ static int handle_char_in_dic (hawk_json_t* json, hawk_ooci_t c)
|
||||
{
|
||||
if (json->state_stack->u.id.state != 3)
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "redundant comma in dicitonary - %jc", (hawk_ooch_t)c);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "redundant comma in dicitonary - %jc", (hawk_ooch_t)c);
|
||||
return -1;
|
||||
}
|
||||
json->state_stack->u.id.state = 0;
|
||||
@ -574,12 +574,12 @@ static int handle_char_in_dic (hawk_json_t* json, hawk_ooci_t c)
|
||||
{
|
||||
if (json->state_stack->u.id.state == 1)
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "colon required in dicitonary - %jc", (hawk_ooch_t)c);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "colon required in dicitonary - %jc", (hawk_ooch_t)c);
|
||||
return -1;
|
||||
}
|
||||
else if (json->state_stack->u.id.state == 3)
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "comma required in dicitonary - %jc", (hawk_ooch_t)c);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "comma required in dicitonary - %jc", (hawk_ooch_t)c);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -626,7 +626,7 @@ static int handle_char_in_dic (hawk_json_t* json, hawk_ooci_t c)
|
||||
}
|
||||
else
|
||||
{
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINVAL, "wrong character inside dictionary - %jc[%d]", (hawk_ooch_t)c, (int)c);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINVAL, "wrong character inside dictionary - %jc[%d]", (hawk_ooch_t)c, (int)c);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -648,7 +648,7 @@ start_over:
|
||||
}
|
||||
else
|
||||
{
|
||||
hawk_json_seterrnum (json, HAWK_NULL, HAWK_EEOF);
|
||||
hawk_json_seterrnum(json, HAWK_NULL, HAWK_EEOF);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -674,7 +674,7 @@ start_over:
|
||||
case HAWK_JSON_STATE_IN_STRING_VALUE:
|
||||
x = handle_string_value_char(json, c);
|
||||
break;
|
||||
|
||||
|
||||
case HAWK_JSON_STATE_IN_CHARACTER_VALUE:
|
||||
x = handle_character_value_char(json, c);
|
||||
break;
|
||||
@ -684,7 +684,7 @@ start_over:
|
||||
break;
|
||||
|
||||
default:
|
||||
hawk_json_seterrbfmt (json, HAWK_NULL, HAWK_EINTERN, "internal error - must not be called for state %d", (int)json->state_stack->state);
|
||||
hawk_json_seterrbfmt(json, HAWK_NULL, HAWK_EINTERN, "internal error - must not be called for state %d", (int)json->state_stack->state);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -696,7 +696,7 @@ start_over:
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
static int feed_json_data (hawk_json_t* json, const hawk_bch_t* data, hawk_oow_t len, hawk_oow_t* xlen)
|
||||
static int feed_json_data_b (hawk_json_t* json, const hawk_bch_t* data, hawk_oow_t len, hawk_oow_t* xlen)
|
||||
{
|
||||
const hawk_bch_t* ptr;
|
||||
const hawk_bch_t* end;
|
||||
@ -747,9 +747,51 @@ oops:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
static int feed_json_data_u (hawk_json_t* json, const hawk_uch_t* data, hawk_oow_t len, hawk_oow_t* xlen)
|
||||
{
|
||||
const hawk_uch_t* ptr;
|
||||
const hawk_uch_t* end;
|
||||
|
||||
ptr = data;
|
||||
end = ptr + len;
|
||||
|
||||
while (ptr < end)
|
||||
{
|
||||
hawk_ooci_t c;
|
||||
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
c = *ptr++;
|
||||
/* handle a single character */
|
||||
if (handle_char(json, c) <= -1) goto oops;
|
||||
#else
|
||||
hawk_bch_t bcsbuf[HAWK_BCSIZE_MAX];
|
||||
hawk_oow_t mlen = 0;
|
||||
hawk_oow_t n, i;
|
||||
|
||||
n = json->_gem.cmgr->uctobc(*ptr++, bcsbuf, HAWK_COUNTOF(bcsbuf));
|
||||
if (n == 0) goto oops; // illegal character
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (handle_char(json, bcsbuf[i]) <= -1) goto oops;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
*xlen = ptr - data;
|
||||
return 1;
|
||||
|
||||
oops:
|
||||
/* TODO: compute the number of processed bytes so far and return it via a parameter??? */
|
||||
/*printf ("feed oops....\n");*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
|
||||
hawk_json_t* hawk_json_open (hawk_mmgr_t* mmgr, hawk_oow_t xtnsize, hawk_cmgr_t* cmgr, hawk_json_prim_t* prim, hawk_errnum_t* errnum)
|
||||
{
|
||||
hawk_json_t* json;
|
||||
@ -761,7 +803,7 @@ hawk_json_t* hawk_json_open (hawk_mmgr_t* mmgr, hawk_oow_t xtnsize, hawk_cmgr_t*
|
||||
return HAWK_NULL;
|
||||
}
|
||||
|
||||
HAWK_MEMSET (json, 0, HAWK_SIZEOF(*json) + xtnsize);
|
||||
HAWK_MEMSET(json, 0, HAWK_SIZEOF(*json) + xtnsize);
|
||||
json->_instsize = HAWK_SIZEOF(*json);
|
||||
json->_gem.mmgr = mmgr;
|
||||
json->_gem.cmgr = cmgr;
|
||||
@ -784,9 +826,9 @@ hawk_json_t* hawk_json_open (hawk_mmgr_t* mmgr, hawk_oow_t xtnsize, hawk_cmgr_t*
|
||||
|
||||
void hawk_json_close (hawk_json_t* json)
|
||||
{
|
||||
pop_all_states (json);
|
||||
if (json->tok.ptr) hawk_json_freemem (json, json->tok.ptr);
|
||||
HAWK_MMGR_FREE (hawk_json_getmmgr(json), json);
|
||||
pop_all_states(json);
|
||||
if (json->tok.ptr) hawk_json_freemem(json, json->tok.ptr);
|
||||
HAWK_MMGR_FREE(hawk_json_getmmgr(json), json);
|
||||
}
|
||||
|
||||
int hawk_json_setoption (hawk_json_t* json, hawk_json_option_t id, const void* value)
|
||||
@ -798,7 +840,7 @@ int hawk_json_setoption (hawk_json_t* json, hawk_json_option_t id, const void* v
|
||||
return 0;
|
||||
}
|
||||
|
||||
hawk_json_seterrnum (json, HAWK_NULL, HAWK_EINVAL);
|
||||
hawk_json_seterrnum(json, HAWK_NULL, HAWK_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -811,7 +853,7 @@ int hawk_json_getoption (hawk_json_t* json, hawk_json_option_t id, void* value)
|
||||
return 0;
|
||||
};
|
||||
|
||||
hawk_json_seterrnum (json, HAWK_NULL, HAWK_EINVAL);
|
||||
hawk_json_seterrnum(json, HAWK_NULL, HAWK_EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -825,17 +867,17 @@ hawk_errstr_t hawk_json_geterrstr (hawk_json_t* json)
|
||||
void hawk_json_seterrbfmt (hawk_json_t* json, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
hawk_gem_seterrbvfmt (hawk_json_getgem(json), errloc, errnum, fmt, ap);
|
||||
va_end (ap);
|
||||
va_start(ap, fmt);
|
||||
hawk_gem_seterrbvfmt(hawk_json_getgem(json), errloc, errnum, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void hawk_json_seterrufmt (hawk_json_t* json, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, fmt);
|
||||
hawk_gem_seterruvfmt (hawk_json_getgem(json), errloc, errnum, fmt, ap);
|
||||
va_end (ap);
|
||||
va_start(ap, fmt);
|
||||
hawk_gem_seterruvfmt(hawk_json_getgem(json), errloc, errnum, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
@ -855,7 +897,7 @@ void* hawk_json_allocmem (hawk_json_t* json, hawk_oow_t size)
|
||||
void* ptr;
|
||||
|
||||
ptr = HAWK_MMGR_ALLOC(hawk_json_getmmgr(json), size);
|
||||
if (!ptr) hawk_json_seterrnum (json, HAWK_NULL, HAWK_ENOMEM);
|
||||
if (!ptr) hawk_json_seterrnum(json, HAWK_NULL, HAWK_ENOMEM);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@ -864,21 +906,21 @@ void* hawk_json_callocmem (hawk_json_t* json, hawk_oow_t size)
|
||||
void* ptr;
|
||||
|
||||
ptr = HAWK_MMGR_ALLOC(hawk_json_getmmgr(json), size);
|
||||
if (!ptr) hawk_json_seterrnum (json, HAWK_NULL, HAWK_ENOMEM);
|
||||
else HAWK_MEMSET (ptr, 0, size);
|
||||
if (!ptr) hawk_json_seterrnum(json, HAWK_NULL, HAWK_ENOMEM);
|
||||
else HAWK_MEMSET(ptr, 0, size);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* hawk_json_reallocmem (hawk_json_t* json, void* ptr, hawk_oow_t size)
|
||||
{
|
||||
ptr = HAWK_MMGR_REALLOC(hawk_json_getmmgr(json), ptr, size);
|
||||
if (!ptr) hawk_json_seterrnum (json, HAWK_NULL, HAWK_ENOMEM);
|
||||
if (!ptr) hawk_json_seterrnum(json, HAWK_NULL, HAWK_ENOMEM);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void hawk_json_freemem (hawk_json_t* json, void* ptr)
|
||||
{
|
||||
HAWK_MMGR_FREE (hawk_json_getmmgr(json), ptr);
|
||||
HAWK_MMGR_FREE(hawk_json_getmmgr(json), ptr);
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
@ -892,21 +934,38 @@ void hawk_json_reset (hawk_json_t* json)
|
||||
{
|
||||
/* TODO: reset XXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxx */
|
||||
pop_all_states (json);
|
||||
HAWK_ASSERT (json->state_stack == &json->state_top);
|
||||
HAWK_ASSERT(json->state_stack == &json->state_top);
|
||||
json->state_stack->state = HAWK_JSON_STATE_START;
|
||||
}
|
||||
|
||||
int hawk_json_feed (hawk_json_t* json, const void* ptr, hawk_oow_t len, hawk_oow_t* xlen)
|
||||
int hawk_json_feedbchars (hawk_json_t* json, const hawk_bch_t* ptr, hawk_oow_t len, hawk_oow_t* xlen)
|
||||
{
|
||||
int x;
|
||||
hawk_oow_t total, ylen;
|
||||
const hawk_bch_t* buf;
|
||||
|
||||
buf = (const hawk_bch_t*)ptr;
|
||||
total = 0;
|
||||
while (total < len)
|
||||
{
|
||||
x = feed_json_data(json, &buf[total], len - total, &ylen);
|
||||
x = feed_json_data_b(json, &ptr[total], len - total, &ylen);
|
||||
if (x <= -1) return -1;
|
||||
|
||||
total += ylen;
|
||||
if (x == 0) break; /* incomplete sequence encountered */
|
||||
}
|
||||
|
||||
*xlen = total;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hawk_json_feeduchars (hawk_json_t* json, const hawk_uch_t* ptr, hawk_oow_t len, hawk_oow_t* xlen)
|
||||
{
|
||||
int x;
|
||||
hawk_oow_t total, ylen;
|
||||
|
||||
total = 0;
|
||||
while (total < len)
|
||||
{
|
||||
x = feed_json_data_u(json, &ptr[total], len - total, &ylen);
|
||||
if (x <= -1) return -1;
|
||||
|
||||
total += ylen;
|
||||
|
@ -236,7 +236,7 @@ static hawk_ooi_t xout (hawk_cut_t* cut, hawk_cut_io_cmd_t cmd, hawk_cut_io_arg_
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user