fixed bugs in handling @include
This commit is contained in:
parent
8059913da3
commit
9eb2c2da4c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.hpp 249 2009-08-07 13:35:24Z hyunghwan.chung $
|
* $Id: Awk.hpp 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -275,17 +275,15 @@ public:
|
|||||||
* The Awk::Source::Data class is used to deliver information
|
* The Awk::Source::Data class is used to deliver information
|
||||||
* needed for source script I/O.
|
* needed for source script I/O.
|
||||||
*/
|
*/
|
||||||
class Data: protected qse_awk_sio_arg_t
|
class Data: protected sio_arg_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend class Awk;
|
friend class Awk;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Data (Awk* awk, Mode mode):
|
Data (Awk* awk, Mode mode, sio_arg_t* arg):
|
||||||
awk (awk), mode (mode)
|
awk (awk), mode (mode), arg (arg)
|
||||||
{
|
{
|
||||||
this->name = QSE_NULL;
|
|
||||||
this->handle = QSE_NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -296,17 +294,17 @@ public:
|
|||||||
|
|
||||||
const char_t* getName() const
|
const char_t* getName() const
|
||||||
{
|
{
|
||||||
return this->name;
|
return arg->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const void* getHandle () const
|
const void* getHandle () const
|
||||||
{
|
{
|
||||||
return this->handle;
|
return arg->handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setHandle (void* handle)
|
void setHandle (void* handle)
|
||||||
{
|
{
|
||||||
this->handle = handle;
|
arg->handle = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator Awk* () const
|
operator Awk* () const
|
||||||
@ -322,6 +320,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
Awk* awk;
|
Awk* awk;
|
||||||
Mode mode;
|
Mode mode;
|
||||||
|
sio_arg_t* arg;
|
||||||
};
|
};
|
||||||
|
|
||||||
Source () {}
|
Source () {}
|
||||||
@ -1090,9 +1089,6 @@ protected:
|
|||||||
|
|
||||||
map_t* functionMap;
|
map_t* functionMap;
|
||||||
|
|
||||||
Source::Data sourceIn;
|
|
||||||
Source::Data sourceOut;
|
|
||||||
|
|
||||||
Source* sourceReader;
|
Source* sourceReader;
|
||||||
Source* sourceWriter;
|
Source* sourceWriter;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: StdAwk.hpp 235 2009-07-15 10:43:31Z hyunghwan.chung $
|
* $Id: StdAwk.hpp 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -45,7 +45,10 @@ public:
|
|||||||
class SourceFile: public Source
|
class SourceFile: public Source
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SourceFile (const char_t* name): name (name) {}
|
SourceFile (const char_t* name): name (name)
|
||||||
|
{
|
||||||
|
dir.ptr = QSE_NULL; dir.len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int open (Data& io);
|
int open (Data& io);
|
||||||
int close (Data& io);
|
int close (Data& io);
|
||||||
@ -54,6 +57,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
const char_t* name;
|
const char_t* name;
|
||||||
|
qse_cstr_t dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SourceString: public Source
|
class SourceString: public Source
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h 249 2009-08-07 13:35:24Z hyunghwan.chung $
|
* $Id: awk.h 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -271,6 +271,15 @@ enum qse_awk_sio_cmd_t
|
|||||||
};
|
};
|
||||||
typedef enum qse_awk_sio_cmd_t qse_awk_sio_cmd_t;
|
typedef enum qse_awk_sio_cmd_t qse_awk_sio_cmd_t;
|
||||||
|
|
||||||
|
typedef struct qse_awk_sio_lxc_t qse_awk_sio_lxc_t;
|
||||||
|
struct qse_awk_sio_lxc_t
|
||||||
|
{
|
||||||
|
qse_cint_t c;
|
||||||
|
qse_size_t lin;
|
||||||
|
qse_size_t col;
|
||||||
|
const qse_char_t* file;
|
||||||
|
};
|
||||||
|
|
||||||
struct qse_awk_sio_arg_t
|
struct qse_awk_sio_arg_t
|
||||||
{
|
{
|
||||||
const qse_char_t* name; /**< [IN] name of I/O object */
|
const qse_char_t* name; /**< [IN] name of I/O object */
|
||||||
@ -287,6 +296,7 @@ struct qse_awk_sio_arg_t
|
|||||||
qse_size_t lin;
|
qse_size_t lin;
|
||||||
qse_size_t col;
|
qse_size_t col;
|
||||||
|
|
||||||
|
qse_awk_sio_lxc_t last;
|
||||||
struct qse_awk_sio_arg_t* next;
|
struct qse_awk_sio_arg_t* next;
|
||||||
};
|
};
|
||||||
typedef struct qse_awk_sio_arg_t qse_awk_sio_arg_t;
|
typedef struct qse_awk_sio_arg_t qse_awk_sio_arg_t;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.cpp 249 2009-08-07 13:35:24Z hyunghwan.chung $
|
* $Id: Awk.cpp 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -995,9 +995,7 @@ int Awk::Run::getGlobal (int id, Value& g) const
|
|||||||
// Awk
|
// Awk
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Awk::Awk () : awk (QSE_NULL), functionMap (QSE_NULL),
|
Awk::Awk () : awk (QSE_NULL), functionMap (QSE_NULL), runctx (this)
|
||||||
sourceIn (this, Source::READ), sourceOut (this, Source::WRITE),
|
|
||||||
runctx (this)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
errinf.num = (errnum_t)ERR_NOERR;
|
errinf.num = (errnum_t)ERR_NOERR;
|
||||||
@ -1608,16 +1606,16 @@ Awk::ssize_t Awk::readSource (
|
|||||||
char_t* data, size_t count)
|
char_t* data, size_t count)
|
||||||
{
|
{
|
||||||
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
|
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
|
||||||
|
Source::Data sdat (xtn->awk, Source::READ, arg);
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case QSE_AWK_SIO_OPEN:
|
case QSE_AWK_SIO_OPEN:
|
||||||
xtn->awk->sourceIn.name = arg->name;
|
return xtn->awk->sourceReader->open (sdat);
|
||||||
return xtn->awk->sourceReader->open (xtn->awk->sourceIn);
|
|
||||||
case QSE_AWK_SIO_CLOSE:
|
case QSE_AWK_SIO_CLOSE:
|
||||||
return xtn->awk->sourceReader->close (xtn->awk->sourceIn);
|
return xtn->awk->sourceReader->close (sdat);
|
||||||
case QSE_AWK_SIO_READ:
|
case QSE_AWK_SIO_READ:
|
||||||
return xtn->awk->sourceReader->read (xtn->awk->sourceIn, data, count);
|
return xtn->awk->sourceReader->read (sdat, data, count);
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1628,16 +1626,16 @@ Awk::ssize_t Awk::writeSource (
|
|||||||
char_t* data, size_t count)
|
char_t* data, size_t count)
|
||||||
{
|
{
|
||||||
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
|
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
|
||||||
|
Source::Data sdat (xtn->awk, Source::WRITE, arg);
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case QSE_AWK_SIO_OPEN:
|
case QSE_AWK_SIO_OPEN:
|
||||||
xtn->awk->sourceOut.name = arg->name;
|
return xtn->awk->sourceWriter->open (sdat);
|
||||||
return xtn->awk->sourceWriter->open (xtn->awk->sourceOut);
|
|
||||||
case QSE_AWK_SIO_CLOSE:
|
case QSE_AWK_SIO_CLOSE:
|
||||||
return xtn->awk->sourceWriter->close (xtn->awk->sourceOut);
|
return xtn->awk->sourceWriter->close (sdat);
|
||||||
case QSE_AWK_SIO_WRITE:
|
case QSE_AWK_SIO_WRITE:
|
||||||
return xtn->awk->sourceWriter->write (xtn->awk->sourceOut, data, count);
|
return xtn->awk->sourceWriter->write (sdat, data, count);
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: StdAwk.cpp 241 2009-07-22 12:47:13Z hyunghwan.chung $
|
* $Id: StdAwk.cpp 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -778,14 +778,18 @@ int StdAwk::vsprintf (
|
|||||||
int StdAwk::SourceFile::open (Data& io)
|
int StdAwk::SourceFile::open (Data& io)
|
||||||
{
|
{
|
||||||
qse_sio_t* sio;
|
qse_sio_t* sio;
|
||||||
|
const qse_char_t* ioname = io.getName();
|
||||||
|
|
||||||
if (name[0] == QSE_T('-') &&
|
if (ioname == QSE_NULL)
|
||||||
name[1] == QSE_T('\0'))
|
{
|
||||||
|
if (name[0] == QSE_T('-') && name[1] == QSE_T('\0'))
|
||||||
{
|
{
|
||||||
sio = (io.getMode() == READ)? qse_sio_in: qse_sio_out;
|
sio = (io.getMode() == READ)? qse_sio_in: qse_sio_out;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
const qse_char_t* base;
|
||||||
|
|
||||||
sio = qse_sio_open (
|
sio = qse_sio_open (
|
||||||
((awk_t*)io)->mmgr,
|
((awk_t*)io)->mmgr,
|
||||||
0,
|
0,
|
||||||
@ -795,6 +799,58 @@ int StdAwk::SourceFile::open (Data& io)
|
|||||||
(QSE_SIO_WRITE|QSE_SIO_CREATE|QSE_SIO_TRUNCATE))
|
(QSE_SIO_WRITE|QSE_SIO_CREATE|QSE_SIO_TRUNCATE))
|
||||||
);
|
);
|
||||||
if (sio == QSE_NULL) return -1;
|
if (sio == QSE_NULL) return -1;
|
||||||
|
|
||||||
|
base = qse_awk_basename ((awk_t*)io, name);
|
||||||
|
if (base != name)
|
||||||
|
{
|
||||||
|
dir.ptr = name;
|
||||||
|
dir.len = base - name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const char_t* file = name;
|
||||||
|
char_t fbuf[64];
|
||||||
|
char_t* dbuf = QSE_NULL;
|
||||||
|
|
||||||
|
if (dir.len > 0)
|
||||||
|
{
|
||||||
|
size_t tmplen, totlen;
|
||||||
|
|
||||||
|
totlen = qse_strlen(ioname) + dir.len;
|
||||||
|
if (totlen >= QSE_COUNTOF(fbuf))
|
||||||
|
{
|
||||||
|
dbuf = (qse_char_t*) QSE_MMGR_ALLOC (
|
||||||
|
((awk_t*)io)->mmgr,
|
||||||
|
QSE_SIZEOF(qse_char_t) * (totlen + 1)
|
||||||
|
);
|
||||||
|
if (dbuf == QSE_NULL)
|
||||||
|
{
|
||||||
|
((Awk*)io)->setError (ERR_NOMEM);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
file = dbuf;
|
||||||
|
}
|
||||||
|
else file = fbuf;
|
||||||
|
|
||||||
|
tmplen = qse_strncpy (
|
||||||
|
(char_t*)file, dir.ptr, dir.len);
|
||||||
|
qse_strcpy ((char_t*)file + tmplen, ioname);
|
||||||
|
}
|
||||||
|
|
||||||
|
sio = qse_sio_open (
|
||||||
|
((awk_t*)io)->mmgr,
|
||||||
|
0,
|
||||||
|
file,
|
||||||
|
(io.getMode() == READ?
|
||||||
|
QSE_SIO_READ:
|
||||||
|
(QSE_SIO_WRITE|QSE_SIO_CREATE|QSE_SIO_TRUNCATE))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (dbuf != QSE_NULL) QSE_MMGR_FREE (((awk_t*)io)->mmgr, dbuf);
|
||||||
|
if (sio == QSE_NULL) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
io.setHandle (sio);
|
io.setHandle (sio);
|
||||||
@ -826,29 +882,69 @@ StdAwk::ssize_t StdAwk::SourceFile::write (Data& io, char_t* buf, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int StdAwk::SourceString::open (Data& io)
|
int StdAwk::SourceString::open (Data& io)
|
||||||
|
{
|
||||||
|
qse_sio_t* sio;
|
||||||
|
const char_t* ioname = io.getName();
|
||||||
|
|
||||||
|
if (ioname == QSE_NULL)
|
||||||
{
|
{
|
||||||
/* SourceString does not support writing */
|
/* SourceString does not support writing */
|
||||||
if (io.getMode() == WRITE) return -1;
|
if (io.getMode() == WRITE) return -1;
|
||||||
ptr = str;
|
ptr = str;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* open an included file */
|
||||||
|
sio = qse_sio_open (
|
||||||
|
((awk_t*)io)->mmgr,
|
||||||
|
0,
|
||||||
|
ioname,
|
||||||
|
(io.getMode() == READ?
|
||||||
|
QSE_SIO_READ:
|
||||||
|
(QSE_SIO_WRITE|QSE_SIO_CREATE|QSE_SIO_TRUNCATE))
|
||||||
|
);
|
||||||
|
if (sio == QSE_NULL) return -1;
|
||||||
|
io.setHandle (sio);
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int StdAwk::SourceString::close (Data& io)
|
int StdAwk::SourceString::close (Data& io)
|
||||||
{
|
{
|
||||||
|
if (io.getName() != QSE_NULL)
|
||||||
|
qse_sio_close ((qse_sio_t*)io.getHandle());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
StdAwk::ssize_t StdAwk::SourceString::read (Data& io, char_t* buf, size_t len)
|
StdAwk::ssize_t StdAwk::SourceString::read (Data& io, char_t* buf, size_t len)
|
||||||
|
{
|
||||||
|
if (io.getName() == QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_size_t n = 0;
|
qse_size_t n = 0;
|
||||||
while (*ptr != QSE_T('\0') && n < len) buf[n++] = *ptr++;
|
while (*ptr != QSE_T('\0') && n < len) buf[n++] = *ptr++;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return qse_sio_getsn ((qse_sio_t*)io.getHandle(), buf, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StdAwk::ssize_t StdAwk::SourceString::write (Data& io, char_t* buf, size_t len)
|
StdAwk::ssize_t StdAwk::SourceString::write (Data& io, char_t* buf, size_t len)
|
||||||
|
{
|
||||||
|
if (io.getName() == QSE_NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// in fact, this block will never be reached as
|
||||||
|
// there is no included file concept for deparsing
|
||||||
|
return qse_sio_putsn ((qse_sio_t*)io.getHandle(), buf, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
QSE_END_NAMESPACE(QSE)
|
QSE_END_NAMESPACE(QSE)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h 248 2009-08-06 08:27:14Z hyunghwan.chung $
|
* $Id: awk.h 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -106,15 +106,6 @@ struct qse_awk_token_t
|
|||||||
qse_size_t col;
|
qse_size_t col;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct qse_awk_lxc_t qse_awk_lxc_t;
|
|
||||||
struct qse_awk_lxc_t
|
|
||||||
{
|
|
||||||
qse_cint_t c;
|
|
||||||
qse_size_t lin;
|
|
||||||
qse_size_t col;
|
|
||||||
const qse_char_t* file;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct qse_awk_t
|
struct qse_awk_t
|
||||||
{
|
{
|
||||||
QSE_DEFINE_COMMON_FIELDS (sed)
|
QSE_DEFINE_COMMON_FIELDS (sed)
|
||||||
@ -186,10 +177,10 @@ struct qse_awk_t
|
|||||||
qse_awk_sio_fun_t inf;
|
qse_awk_sio_fun_t inf;
|
||||||
qse_awk_sio_fun_t outf;
|
qse_awk_sio_fun_t outf;
|
||||||
|
|
||||||
qse_awk_lxc_t last;
|
qse_awk_sio_lxc_t last;
|
||||||
|
|
||||||
qse_size_t nungots;
|
qse_size_t nungots;
|
||||||
qse_awk_lxc_t ungot[5];
|
qse_awk_sio_lxc_t ungot[5];
|
||||||
|
|
||||||
qse_awk_sio_arg_t arg; /* for the top level source */
|
qse_awk_sio_arg_t arg; /* for the top level source */
|
||||||
qse_awk_sio_arg_t* inp; /* current input */
|
qse_awk_sio_arg_t* inp; /* current input */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: misc.c 237 2009-07-16 12:43:47Z hyunghwan.chung $
|
* $Id: misc.c 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -999,3 +999,17 @@ void qse_awk_rtx_free (qse_awk_rtx_t* rtx, void* ptr)
|
|||||||
qse_awk_free (rtx->awk, ptr);
|
qse_awk_free (rtx->awk, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const qse_char_t* qse_awk_basename (qse_awk_t* awk, const qse_char_t* path)
|
||||||
|
{
|
||||||
|
const qse_char_t* p, * last = QSE_NULL;
|
||||||
|
|
||||||
|
for (p = path; *p != QSE_T('\0'); p++)
|
||||||
|
{
|
||||||
|
if (*p == QSE_T('/')) last = p;
|
||||||
|
#ifdef _WIN32
|
||||||
|
else if (*p == QSE_T('\\')) last = p;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return (last == QSE_NULL)? path: (last + 1);
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: misc.h 171 2009-06-01 09:34:34Z hyunghwan.chung $
|
* $Id: misc.h 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -67,6 +67,11 @@ int qse_awk_matchrex (
|
|||||||
qse_cstr_t* match, qse_awk_errnum_t* errnum
|
qse_cstr_t* match, qse_awk_errnum_t* errnum
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const qse_char_t* qse_awk_basename (
|
||||||
|
qse_awk_t* awk,
|
||||||
|
const qse_char_t* path
|
||||||
|
);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: parse.c 248 2009-08-06 08:27:14Z hyunghwan.chung $
|
* $Id: parse.c 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -398,11 +398,7 @@ static int get_char (qse_awk_t* awk)
|
|||||||
if (awk->sio.nungots > 0)
|
if (awk->sio.nungots > 0)
|
||||||
{
|
{
|
||||||
/* there are something in the unget buffer */
|
/* there are something in the unget buffer */
|
||||||
QSE_MEMCPY (
|
awk->sio.last = awk->sio.ungot[--awk->sio.nungots];
|
||||||
&awk->sio.last,
|
|
||||||
&awk->sio.ungot[--awk->sio.nungots],
|
|
||||||
QSE_SIZEOF(awk->sio.last)
|
|
||||||
);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,31 +429,28 @@ static int get_char (qse_awk_t* awk)
|
|||||||
awk->sio.inp->b.len = n;
|
awk->sio.inp->b.len = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
awk->sio.last.c = awk->sio.inp->b.buf[awk->sio.inp->b.pos++];
|
awk->sio.inp->last.c = awk->sio.inp->b.buf[awk->sio.inp->b.pos++];
|
||||||
awk->sio.last.lin = awk->sio.inp->lin;
|
awk->sio.inp->last.lin = awk->sio.inp->lin;
|
||||||
awk->sio.last.col = awk->sio.inp->col;
|
awk->sio.inp->last.col = awk->sio.inp->col;
|
||||||
awk->sio.last.file = awk->sio.inp->name;
|
awk->sio.inp->last.file = awk->sio.inp->name;
|
||||||
|
|
||||||
if (awk->sio.last.c == QSE_T('\n'))
|
if (awk->sio.inp->last.c == QSE_T('\n'))
|
||||||
{
|
{
|
||||||
awk->sio.inp->lin++;
|
awk->sio.inp->lin++;
|
||||||
awk->sio.inp->col = 1;
|
awk->sio.inp->col = 1;
|
||||||
}
|
}
|
||||||
else awk->sio.inp->col++;
|
else awk->sio.inp->col++;
|
||||||
|
|
||||||
|
awk->sio.last = awk->sio.inp->last;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unget_char (qse_awk_t* awk, const qse_awk_lxc_t* c)
|
static void unget_char (qse_awk_t* awk, const qse_awk_sio_lxc_t* c)
|
||||||
{
|
{
|
||||||
/* Make sure that the unget buffer is large enough */
|
/* Make sure that the unget buffer is large enough */
|
||||||
QSE_ASSERTX (awk->sio.nungots < QSE_COUNTOF(awk->sio.ungot),
|
QSE_ASSERTX (awk->sio.nungots < QSE_COUNTOF(awk->sio.ungot),
|
||||||
"Make sure that you have increased the size of sio.ungot large enough");
|
"Make sure that you have increased the size of sio.ungot large enough");
|
||||||
|
awk->sio.ungot[awk->sio.nungots++] = *c;
|
||||||
QSE_MEMCPY (
|
|
||||||
&awk->sio.ungot[awk->sio.nungots++],
|
|
||||||
c, QSE_SIZEOF(*c)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const qse_char_t* qse_awk_getgblname (
|
const qse_char_t* qse_awk_getgblname (
|
||||||
@ -762,8 +755,8 @@ static int end_include (qse_awk_t* awk)
|
|||||||
static qse_awk_t* parse_progunit (qse_awk_t* awk)
|
static qse_awk_t* parse_progunit (qse_awk_t* awk)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@include "xxxx"
|
||||||
global xxx, xxxx;
|
global xxx, xxxx;
|
||||||
include "xxxx";
|
|
||||||
BEGIN { action }
|
BEGIN { action }
|
||||||
END { action }
|
END { action }
|
||||||
pattern { action }
|
pattern { action }
|
||||||
@ -5132,16 +5125,16 @@ static int skip_spaces (qse_awk_t* awk)
|
|||||||
|
|
||||||
if (c == QSE_T('\\'))
|
if (c == QSE_T('\\'))
|
||||||
{
|
{
|
||||||
qse_awk_lxc_t bs;
|
qse_awk_sio_lxc_t bs;
|
||||||
qse_awk_lxc_t cr;
|
qse_awk_sio_lxc_t cr;
|
||||||
int hascr = 0;
|
int hascr = 0;
|
||||||
|
|
||||||
QSE_MEMCPY (&bs, &awk->sio.last, QSE_SIZEOF(bs));
|
bs = awk->sio.last;
|
||||||
GET_CHAR_TO (awk, c);
|
GET_CHAR_TO (awk, c);
|
||||||
if (c == QSE_T('\r'))
|
if (c == QSE_T('\r'))
|
||||||
{
|
{
|
||||||
hascr = 1;
|
hascr = 1;
|
||||||
QSE_MEMCPY (&cr, &awk->sio.last, QSE_SIZEOF(cr));
|
cr = awk->sio.last;
|
||||||
GET_CHAR_TO (awk, c);
|
GET_CHAR_TO (awk, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5157,7 +5150,7 @@ static int skip_spaces (qse_awk_t* awk)
|
|||||||
/* push CR if any */
|
/* push CR if any */
|
||||||
if (hascr) unget_char (awk, &cr);
|
if (hascr) unget_char (awk, &cr);
|
||||||
/* restore the orginal backslash */
|
/* restore the orginal backslash */
|
||||||
QSE_MEMCPY (&awk->sio.last, &bs, QSE_SIZEOF(bs));
|
awk->sio.last = bs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5176,7 +5169,7 @@ static int skip_spaces (qse_awk_t* awk)
|
|||||||
static int skip_comment (qse_awk_t* awk)
|
static int skip_comment (qse_awk_t* awk)
|
||||||
{
|
{
|
||||||
qse_cint_t c = awk->sio.last.c;
|
qse_cint_t c = awk->sio.last.c;
|
||||||
qse_awk_lxc_t lc;
|
qse_awk_sio_lxc_t lc;
|
||||||
|
|
||||||
if (c == QSE_T('#'))
|
if (c == QSE_T('#'))
|
||||||
{
|
{
|
||||||
@ -5192,7 +5185,7 @@ static int skip_comment (qse_awk_t* awk)
|
|||||||
if (c != QSE_T('/')) return 0; /* not a comment */
|
if (c != QSE_T('/')) return 0; /* not a comment */
|
||||||
|
|
||||||
/* save the last character */
|
/* save the last character */
|
||||||
QSE_MEMCPY (&lc, &awk->sio.last, QSE_SIZEOF(lc));
|
lc = awk->sio.last;
|
||||||
/* read a new character */
|
/* read a new character */
|
||||||
GET_CHAR_TO (awk, c);
|
GET_CHAR_TO (awk, c);
|
||||||
|
|
||||||
@ -5232,7 +5225,7 @@ static int skip_comment (qse_awk_t* awk)
|
|||||||
/* unget '*' */
|
/* unget '*' */
|
||||||
unget_char (awk, &awk->sio.last);
|
unget_char (awk, &awk->sio.last);
|
||||||
/* restore the previous state */
|
/* restore the previous state */
|
||||||
QSE_MEMCPY (&awk->sio.last, &lc, QSE_SIZEOF(lc));
|
awk->sio.last = lc;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -5359,7 +5352,11 @@ retry:
|
|||||||
{
|
{
|
||||||
n = end_include (awk);
|
n = end_include (awk);
|
||||||
if (n <= -1) return -1;
|
if (n <= -1) return -1;
|
||||||
if (n >= 1) goto retry;
|
if (n >= 1)
|
||||||
|
{
|
||||||
|
awk->sio.last = awk->sio.inp->last;
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
|
|
||||||
ADD_TOKEN_STR (awk, token, QSE_T("<EOF>"), 5);
|
ADD_TOKEN_STR (awk, token, QSE_T("<EOF>"), 5);
|
||||||
SET_TOKEN_TYPE (awk, token, TOKEN_EOF);
|
SET_TOKEN_TYPE (awk, token, TOKEN_EOF);
|
||||||
@ -5377,9 +5374,9 @@ retry:
|
|||||||
}
|
}
|
||||||
else if (c == QSE_T('.'))
|
else if (c == QSE_T('.'))
|
||||||
{
|
{
|
||||||
qse_awk_lxc_t lc;
|
qse_awk_sio_lxc_t lc;
|
||||||
|
|
||||||
QSE_MEMCPY (&lc, &awk->sio.last, QSE_SIZEOF(lc));
|
lc = awk->sio.last;
|
||||||
GET_CHAR_TO (awk, c);
|
GET_CHAR_TO (awk, c);
|
||||||
|
|
||||||
if (!(awk->option & QSE_AWK_EXPLICIT) &&
|
if (!(awk->option & QSE_AWK_EXPLICIT) &&
|
||||||
@ -5387,7 +5384,7 @@ retry:
|
|||||||
{
|
{
|
||||||
/* for a token such as .123 */
|
/* for a token such as .123 */
|
||||||
unget_char (awk, &awk->sio.last);
|
unget_char (awk, &awk->sio.last);
|
||||||
QSE_MEMCPY (&awk->sio.last, &lc, QSE_SIZEOF(lc));
|
awk->sio.last = lc;
|
||||||
if (get_number (awk, token) <= -1) return -1;
|
if (get_number (awk, token) <= -1) return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: std.c 247 2009-07-31 13:01:04Z hyunghwan.chung $
|
* $Id: std.c 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -45,6 +45,7 @@ typedef struct xtn_t
|
|||||||
const qse_char_t* end;
|
const qse_char_t* end;
|
||||||
} cpl;
|
} cpl;
|
||||||
} u;
|
} u;
|
||||||
|
qse_cstr_t dir;
|
||||||
qse_sio_t* handle; /* the handle to an open file */
|
qse_sio_t* handle; /* the handle to an open file */
|
||||||
} in;
|
} in;
|
||||||
|
|
||||||
@ -173,6 +174,8 @@ static qse_ssize_t sf_in_open (
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
const qse_char_t* base;
|
||||||
|
|
||||||
xtn->s.in.handle = qse_sio_open (
|
xtn->s.in.handle = qse_sio_open (
|
||||||
awk->mmgr,
|
awk->mmgr,
|
||||||
0,
|
0,
|
||||||
@ -190,6 +193,13 @@ static qse_ssize_t sf_in_open (
|
|||||||
);
|
);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base = qse_awk_basename (awk, xtn->s.in.u.file);
|
||||||
|
if (base != xtn->s.in.u.file)
|
||||||
|
{
|
||||||
|
xtn->s.in.dir.ptr = xtn->s.in.u.file;
|
||||||
|
xtn->s.in.dir.len = base - xtn->s.in.u.file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -208,10 +218,44 @@ static qse_ssize_t sf_in_open (
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* TODO: standard include path */
|
const qse_char_t* file = arg->name;
|
||||||
arg->handle = qse_sio_open (
|
qse_char_t fbuf[64];
|
||||||
awk->mmgr, 0, arg->name, QSE_SIO_READ
|
qse_char_t* dbuf = QSE_NULL;
|
||||||
|
|
||||||
|
if (xtn->s.in.dir.len > 0)
|
||||||
|
{
|
||||||
|
qse_size_t tmplen, totlen;
|
||||||
|
|
||||||
|
totlen = qse_strlen(arg->name) + xtn->s.in.dir.len;
|
||||||
|
if (totlen >= QSE_COUNTOF(fbuf))
|
||||||
|
{
|
||||||
|
dbuf = QSE_MMGR_ALLOC (
|
||||||
|
awk->mmgr,
|
||||||
|
QSE_SIZEOF(qse_char_t) * (totlen + 1)
|
||||||
);
|
);
|
||||||
|
if (dbuf == QSE_NULL)
|
||||||
|
{
|
||||||
|
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
file = dbuf;
|
||||||
|
}
|
||||||
|
else file = fbuf;
|
||||||
|
|
||||||
|
tmplen = qse_strncpy (
|
||||||
|
(qse_char_t*)file,
|
||||||
|
xtn->s.in.dir.ptr,
|
||||||
|
xtn->s.in.dir.len
|
||||||
|
);
|
||||||
|
qse_strcpy ((qse_char_t*)file + tmplen, arg->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
arg->handle = qse_sio_open (
|
||||||
|
awk->mmgr, 0, file, QSE_SIO_READ
|
||||||
|
);
|
||||||
|
|
||||||
|
if (dbuf != QSE_NULL) QSE_MMGR_FREE (awk->mmgr, dbuf);
|
||||||
if (arg->handle == QSE_NULL)
|
if (arg->handle == QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_cstr_t ea;
|
qse_cstr_t ea;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk04.c 211 2009-06-24 09:50:10Z hyunghwan.chung $
|
* $Id: awk04.c 250 2009-08-10 03:29:59Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ int main ()
|
|||||||
qse_size_t len;
|
qse_size_t len;
|
||||||
qse_awk_val_t* v;
|
qse_awk_val_t* v;
|
||||||
qse_awk_val_t* arg[2] = { QSE_NULL, QSE_NULL };
|
qse_awk_val_t* arg[2] = { QSE_NULL, QSE_NULL };
|
||||||
int ret, i;
|
int ret, i, opt;
|
||||||
|
|
||||||
/* create a main processor */
|
/* create a main processor */
|
||||||
awk = qse_awk_openstd (0);
|
awk = qse_awk_openstd (0);
|
||||||
@ -43,8 +43,14 @@ int main ()
|
|||||||
ret = -1; goto oops;
|
ret = -1; goto oops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opt = qse_awk_getoption(awk);
|
||||||
|
|
||||||
/* don't allow BEGIN, END, pattern-action blocks */
|
/* don't allow BEGIN, END, pattern-action blocks */
|
||||||
qse_awk_setoption (awk, qse_awk_getoption(awk) & ~QSE_AWK_PABLOCK);
|
opt &= ~QSE_AWK_PABLOCK;
|
||||||
|
/* enable ** */
|
||||||
|
opt |= QSE_AWK_EXTRAOPS;
|
||||||
|
|
||||||
|
qse_awk_setoption (awk, opt);
|
||||||
|
|
||||||
psin.type = QSE_AWK_PARSESTD_CP;
|
psin.type = QSE_AWK_PARSESTD_CP;
|
||||||
psin.u.cp = src;
|
psin.u.cp = src;
|
||||||
|
Loading…
Reference in New Issue
Block a user