changed @inclone to @include_once

changed the sf_in_open() to set arg->uniqie_id in lib/awk/std.c
This commit is contained in:
hyung-hwan 2019-05-13 05:22:40 +00:00
parent 3bfaaa2bc9
commit 546d34d732
21 changed files with 121 additions and 129 deletions

View File

@ -360,7 +360,7 @@ static void start_rewriter (ursd_t* ursd, rewriter_t* rewriter)
if (rewriter->pio)
{
if (insert_to_mux (ursd->mux, qse_pio_gethandle(rewriter->pio, QSE_PIO_OUT), TYPE_PIO_OUT, rewriter->index) <= -1)
if (insert_to_mux (ursd->mux, qse_pio_gethnd(rewriter->pio, QSE_PIO_OUT), TYPE_PIO_OUT, rewriter->index) <= -1)
{
/* error logging */
qse_pio_kill (rewriter->pio);
@ -376,11 +376,11 @@ static void stop_rewriter (ursd_t* ursd, rewriter_t* rewriter)
{
if (rewriter->pio_in_in_mux)
{
delete_from_mux (ursd->mux, qse_pio_gethandle(rewriter->pio, QSE_PIO_IN), TYPE_PIO_IN, rewriter->index);
delete_from_mux (ursd->mux, qse_pio_gethnd(rewriter->pio, QSE_PIO_IN), TYPE_PIO_IN, rewriter->index);
rewriter->pio_in_in_mux = 0;
}
delete_from_mux (ursd->mux, qse_pio_gethandle(rewriter->pio, QSE_PIO_OUT), TYPE_PIO_OUT, rewriter->index);
delete_from_mux (ursd->mux, qse_pio_gethnd(rewriter->pio, QSE_PIO_OUT), TYPE_PIO_OUT, rewriter->index);
qse_pio_kill (rewriter->pio);
qse_pio_close (rewriter->pio);
@ -439,7 +439,7 @@ static void release_rewriter (ursd_t* ursd, rewriter_t* rewriter, int send_empty
if (rewriter->pio_in_in_mux)
{
QSE_ASSERT (rewriter->pio);
delete_from_mux (ursd->mux, qse_pio_gethandle(rewriter->pio, QSE_PIO_IN), TYPE_PIO_IN, rewriter->index);
delete_from_mux (ursd->mux, qse_pio_gethnd(rewriter->pio, QSE_PIO_IN), TYPE_PIO_IN, rewriter->index);
rewriter->pio_in_in_mux = 0;
}
@ -466,7 +466,7 @@ static void seize_rewriter (ursd_t* ursd, rewriter_t* rewriter)
if (rewriter->pio_in_in_mux)
{
delete_from_mux (ursd->mux, qse_pio_gethandle(rewriter->pio, QSE_PIO_IN), TYPE_PIO_IN, rewriter->index);
delete_from_mux (ursd->mux, qse_pio_gethnd(rewriter->pio, QSE_PIO_IN), TYPE_PIO_IN, rewriter->index);
rewriter->pio_in_in_mux = 0;
}
@ -489,7 +489,7 @@ static int feed_rewriter (ursd_t* ursd, rewriter_t* rewriter)
if (qse_pio_geterrnum(rewriter->pio) == QSE_PIO_EAGAIN)
{
if (rewriter->pio_in_in_mux ||
insert_to_mux (ursd->mux, qse_pio_gethandle(rewriter->pio, QSE_PIO_IN), TYPE_PIO_IN, rewriter->index) >= 0)
insert_to_mux (ursd->mux, qse_pio_gethnd(rewriter->pio, QSE_PIO_IN), TYPE_PIO_IN, rewriter->index) >= 0)
{
/* this is partial success. the request has not
been passed to the rewriter in its entirety yet. */

View File

@ -580,7 +580,7 @@ struct qse_awk_sio_arg_t
/**
* [OUT] unique id set by an input handler. it is used for a single time inclusion check.
*/
qse_uint8_t unique_id[16];
qse_uint8_t unique_id[QSE_SIZEOF_INTPTR_T * 2];
/**
* [IN] points to the includer. #QSE_NULL for the toplevel.

View File

@ -237,9 +237,9 @@ QSE_EXPORT qse_fio_errnum_t qse_fio_geterrnum (
);
/**
* The qse_fio_gethandle() function returns the native file handle.
* The qse_fio_gethnd() function returns the native file handle.
*/
QSE_EXPORT qse_fio_hnd_t qse_fio_gethandle (
QSE_EXPORT qse_fio_hnd_t qse_fio_gethnd (
const qse_fio_t* fio
);

View File

@ -48,8 +48,8 @@ struct qse_fattr_t
qse_uintptr_t mode;
qse_uintmax_t size;
qse_uintmax_t ino;
qse_uintmax_t dev;
qse_uintptr_t ino;
qse_uintptr_t dev;
qse_uintptr_t uid;
qse_uintptr_t gid;

View File

@ -169,9 +169,9 @@ QSE_EXPORT qse_nwio_errnum_t qse_nwio_geterrnum (
);
/**
* The qse_nwio_gethandle() function returns the native file handle.
* The qse_nwio_gethnd() function returns the native file handle.
*/
QSE_EXPORT qse_nwio_hnd_t qse_nwio_gethandle (
QSE_EXPORT qse_nwio_hnd_t qse_nwio_gethnd (
const qse_nwio_t* nwio
);

View File

@ -320,10 +320,10 @@ QSE_EXPORT void qse_pio_setcmgr (
);
/**
* The qse_pio_gethandle() function gets a pipe handle.
* The qse_pio_gethnd() function gets a pipe handle.
* \return pipe handle
*/
QSE_EXPORT qse_pio_hnd_t qse_pio_gethandle (
QSE_EXPORT qse_pio_hnd_t qse_pio_gethnd (
const qse_pio_t* pio, /**< pio object */
qse_pio_hid_t hid /**< handle ID */
);

View File

@ -208,7 +208,7 @@ QSE_EXPORT void qse_sio_setcmgr (
qse_cmgr_t* cmgr
);
QSE_EXPORT qse_sio_hnd_t qse_sio_gethandle (
QSE_EXPORT qse_sio_hnd_t qse_sio_gethnd (
const qse_sio_t* sio
);

View File

@ -80,8 +80,8 @@ struct dir_list_t
struct
{
dir_node_t** tab;
int capa;
int high;
qse_size_t capa;
qse_size_t high;
} map;
int errnum;
@ -162,7 +162,7 @@ static dir_node_t* new_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, const qse
{
if (list->map.high <= list->map.capa)
{
int newcapa;
qse_size_t newcapa;
dir_node_t** tmp;
newcapa = list->map.capa + 64;

View File

@ -117,8 +117,8 @@ enum tok_t
/* === extended reserved words === */
TOK_XGLOBAL,
TOK_XLOCAL,
TOK_XINCLONE,
TOK_XINCLUDE,
TOK_XINCLUDE_ONCE,
TOK_XPRAGMA,
TOK_XABORT,
TOK_XRESET,
@ -262,8 +262,8 @@ static kwent_t kwtab[] =
* also keep it sorted by the first field for binary search */
{ { QSE_T("@abort"), 6 }, TOK_XABORT, 0 },
{ { QSE_T("@global"), 7 }, TOK_XGLOBAL, 0 },
{ { QSE_T("@inclone"), 8 }, TOK_XINCLONE, 0 },
{ { QSE_T("@include"), 8 }, TOK_XINCLUDE, 0 },
{ { QSE_T("@include_once"), 13 }, TOK_XINCLUDE_ONCE, 0 },
{ { QSE_T("@local"), 6 }, TOK_XLOCAL, 0 },
{ { QSE_T("@pragma"), 7 }, TOK_XPRAGMA, 0 },
{ { QSE_T("@reset"), 6 }, TOK_XRESET, 0 },
@ -850,6 +850,12 @@ static int begin_include (qse_awk_t* awk, int once)
{
end_include (awk);
/* it has been included previously. don't include this file again. */
if (get_token(awk) <= -1) return -1; /* skip the include file name */
if (MATCH(awk, TOK_SEMICOLON) || MATCH(awk, TOK_NEWLINE))
{
if (get_token(awk) <= -1) return -1; /* skip the semicolon */
}
}
else
{
@ -904,7 +910,7 @@ static int parse_progunit (qse_awk_t* awk)
return -1;
}
}
else if (MATCH(awk, TOK_XINCLUDE) || MATCH(awk, TOK_XINCLONE))
else if (MATCH(awk, TOK_XINCLUDE) || MATCH(awk, TOK_XINCLUDE_ONCE))
{
int once;
@ -915,7 +921,7 @@ static int parse_progunit (qse_awk_t* awk)
return -1;
}
once = MATCH(awk, TOK_XINCLONE);
once = MATCH(awk, TOK_XINCLUDE_ONCE);
if (get_token(awk) <= -1) return -1;
if (!MATCH(awk, TOK_STR))
@ -1557,7 +1563,7 @@ static qse_awk_nde_t* parse_block (qse_awk_t* awk, const qse_awk_loc_t* xloc, in
if (get_token(awk) <= -1) return QSE_NULL;
}
if (MATCH(awk,TOK_XINCLUDE) || MATCH(awk, TOK_XINCLONE))
if (MATCH(awk,TOK_XINCLUDE) || MATCH(awk, TOK_XINCLUDE_ONCE))
{
/* @include ... */
int once;
@ -1569,7 +1575,7 @@ static qse_awk_nde_t* parse_block (qse_awk_t* awk, const qse_awk_loc_t* xloc, in
return QSE_NULL;
}
once = MATCH(awk, TOK_XINCLONE);
once = MATCH(awk, TOK_XINCLUDE_ONCE);
if (get_token(awk) <= -1) return QSE_NULL;
if (!MATCH(awk,TOK_STR))
@ -1635,7 +1641,7 @@ static qse_awk_nde_t* parse_block (qse_awk_t* awk, const qse_awk_loc_t* xloc, in
break;
}
else if (MATCH(awk, TOK_XINCLUDE) || MATCH(awk, TOK_XINCLONE))
else if (MATCH(awk, TOK_XINCLUDE) || MATCH(awk, TOK_XINCLUDE_ONCE))
{
int once;
@ -1646,7 +1652,7 @@ static qse_awk_nde_t* parse_block (qse_awk_t* awk, const qse_awk_loc_t* xloc, in
return QSE_NULL;
}
once = MATCH(awk, TOK_XINCLONE);
once = MATCH(awk, TOK_XINCLUDE_ONCE);
if (get_token(awk) <= -1) return QSE_NULL;
if (!MATCH(awk,TOK_STR))

View File

@ -32,8 +32,8 @@ enum qse_awk_kwid_t
{
QSE_AWK_KWID_XABORT,
QSE_AWK_KWID_XGLOBAL,
QSE_AWK_KWID_XINCLONE,
QSE_AWK_KWID_XINCLUDE,
QSE_AWK_KWID_XINCLUDE_ONCE,
QSE_AWK_KWID_XLOCAL,
QSE_AWK_KWID_XPRAGMA,
QSE_AWK_KWID_XRESET,

View File

@ -35,6 +35,7 @@
#include <qse/si/sio.h>
#include <qse/si/pio.h>
#include <qse/si/nwio.h>
#include <qse/si/fs.h>
#include "../cmn/mem-prv.h"
#include <stdarg.h>
@ -698,6 +699,7 @@ static qse_ssize_t sf_in_open (qse_awk_t* awk, qse_awk_sio_arg_t* arg, xtn_t* xt
const qse_char_t* path;
qse_char_t fbuf[64];
qse_char_t* dbuf = QSE_NULL;
qse_fattr_t fattr;
QSE_ASSERT (arg->name != QSE_NULL);
@ -746,7 +748,20 @@ static qse_ssize_t sf_in_open (qse_awk_t* awk, qse_awk_sio_arg_t* arg, xtn_t* xt
return -1;
}
/* TODO: set arg->unique_id.... to support @inclone */
/* TODO: use the system handle(file descriptor) instead of the path? */
/*syshnd = qse_sio_gethnd(arg->handle);*/
if (qse_get_file_attr_with_mmgr(path, 0, &fattr, awk->mmgr) >= 0)
{
struct
{
qse_uintptr_t ino;
qse_uintptr_t dev;
} tmp;
tmp.ino = fattr.ino;
tmp.dev = fattr.dev;
QSE_MEMCPY (&arg->unique_id[0], &tmp, (QSE_SIZEOF(tmp) > QSE_SIZEOF(arg->unique_id)? QSE_SIZEOF(arg->unique_id): QSE_SIZEOF(fattr.ino)));
}
return 0;
}
}

View File

@ -512,7 +512,7 @@ qse_awk_val_t* qse_awk_rtx_makemapval (qse_awk_rtx_t* rtx)
if (qse_htb_init(val->map, rtx->awk->mmgr, 256, 70, QSE_SIZEOF(qse_char_t), 1) <= -1)
{
qse_awk_rtx_freemem (rtx->awk, val);
qse_awk_rtx_freemem (rtx, val);
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
return QSE_NULL;
}
@ -1517,7 +1517,7 @@ qse_mchar_t* qse_awk_rtx_valtombsdup (qse_awk_rtx_t* rtx, const qse_awk_val_t* v
qse_size_t len0, len1;
str0 = qse_awk_rtx_getvalstr(rtx, v, &len0);
if (!str0) return -1;
if (!str0) return QSE_NULL;
mbs = qse_wcsntombsdupwithcmgr(str0, len0, &len1, rtx->awk->mmgr, rtx->awk->cmgr);
qse_awk_rtx_freevalstr (rtx, v, str0);
@ -1543,8 +1543,9 @@ qse_wchar_t* qse_awk_rtx_valtowcsdup (qse_awk_rtx_t* rtx, const qse_awk_val_t* v
{
case QSE_AWK_VAL_MBS:
{
qse_size_t wcslen;
wcs = qse_mbsntowcsalldupwithcmgr(((qse_awk_val_mbs_t*)v)->val.ptr, ((qse_awk_val_mbs_t*)v)->val.len, &wcslen, rtx->awk->mmgr, rtx->awk->cmgr);
qse_size_t mbslen, wcslen;
mbslen = ((qse_awk_val_mbs_t*)v)->val.len;
wcs = qse_mbsntowcsalldupwithcmgr(((qse_awk_val_mbs_t*)v)->val.ptr, &mbslen, &wcslen, rtx->awk->mmgr, rtx->awk->cmgr);
if (!wcs)
{
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOMEM, QSE_NULL, QSE_NULL);
@ -1558,8 +1559,9 @@ qse_wchar_t* qse_awk_rtx_valtowcsdup (qse_awk_rtx_t* rtx, const qse_awk_val_t* v
case QSE_AWK_VAL_STR:
{
#if defined(QSE_CHAR_IS_MCHAR)
qse_size_t wcslen;
wcs = qse_mbsntowcsalldupwithcmgr(((qse_awk_val_str_t*)v)->val.ptr, ((qse_awk_val_str_t*)v)->val.len, &wcslen, rtx->awk->mmgr, rtx->awk->cmgr);
qse_size_t wcslen, mbslen;
mbslen = ((qse_awk_val_str_t*)v)->val.len
wcs = qse_mbsntowcsalldupwithcmgr(((qse_awk_val_str_t*)v)->val.ptr, &mbslen, &wcslen, rtx->awk->mmgr, rtx->awk->cmgr);
#else
wcs = qse_strxdup(((qse_awk_val_str_t*)v)->val.ptr, ((qse_awk_val_str_t*)v)->val.len, rtx->awk->mmgr);
#endif

View File

@ -759,8 +759,7 @@ static int occbound (comp_t* com, qse_rex_node_t* n)
bound = bound * 10 + com->c.value - QSE_T('0');
if (getc_noesc(com) <= -1) return -1;
}
while (com->c.value >= QSE_T('0') &&
com->c.value <= QSE_T('9'));
while (com->c.value >= QSE_T('0') && com->c.value <= QSE_T('9'));
n->occ.max = bound;
}
@ -768,7 +767,7 @@ static int occbound (comp_t* com, qse_rex_node_t* n)
}
else n->occ.max = n->occ.min;
if (n->occ.min > n->occ.min)
if (n->occ.min > n->occ.max)
{
/* invalid occurrences range */
com->rex->errnum = QSE_REX_EBOUND;
@ -1103,8 +1102,7 @@ static qse_rex_node_t* comp_branches (comp_t* c, qse_rex_node_t* ge)
return left;
}
qse_rex_node_t* qse_rex_comp (
qse_rex_t* rex, const qse_char_t* ptr, qse_size_t len)
qse_rex_node_t* qse_rex_comp (qse_rex_t* rex, const qse_char_t* ptr, qse_size_t len)
{
comp_t c;
qse_rex_node_t* end, * body;

View File

@ -123,9 +123,7 @@ qse_size_t qse_slwcrtoslmb (
#endif
}
qse_size_t qse_slmbrtoslwc (
const qse_mchar_t* mb, qse_size_t mbl,
qse_wchar_t* wc, qse_mbstate_t* state)
qse_size_t qse_slmbrtoslwc (const qse_mchar_t* mb, qse_size_t mbl, qse_wchar_t* wc, qse_mbstate_t* state)
{
#if defined(FORCE_UTF8)
@ -152,43 +150,15 @@ qse_size_t qse_slmbrtoslwc (
}
return dbcslen;
#elif defined(__sun__) && defined(HAVE_MBRTOWC)
/*
* Read comments in qse_slmbrlen().
*/
size_t n;
QSE_ASSERT (mb != QSE_NULL);
QSE_ASSERT (mbl > 0);
if (wc)
{
n = mbrtowc (wc, mb, mbl, (mbstate_t*)state);
if (n == 0)
{
*wc = QSE_WT('\0');
return 1;
}
}
else
{
qse_wchar_t dummy;
n = mbrtowc (&dummy, mb, mbl, (mbstate_t*)state);
if (n == 0) return 1;
}
if (n == (size_t)-1) return 0; /* invalid sequence */
if (n == (size_t)-2) return mbl + 1; /* incomplete sequence */
return (qse_size_t)n;
#elif defined(HAVE_MBRTOWC)
size_t n;
wchar_t tc;
QSE_ASSERT (mb != QSE_NULL);
QSE_ASSERT (mbl > 0);
n = mbrtowc (wc, mb, mbl, (mbstate_t*)state);
n = mbrtowc(&tc, mb, mbl, (mbstate_t*)state);
if (n == 0)
{
if (wc) *wc = QSE_WT('\0');
@ -197,6 +167,8 @@ qse_size_t qse_slmbrtoslwc (
if (n == (size_t)-1) return 0; /* invalid sequence */
if (n == (size_t)-2) return mbl + 1; /* incomplete sequence */
if (wc) *wc = tc; /* if sizeof(qse_wchar_t) < sizeof(wchar_t), *wc may get truncated */
return (qse_size_t)n;
#else
@ -205,8 +177,7 @@ qse_size_t qse_slmbrtoslwc (
#endif
}
qse_size_t qse_slmbrlen (
const qse_mchar_t* mb, qse_size_t mbl, qse_mbstate_t* state)
qse_size_t qse_slmbrlen (const qse_mchar_t* mb, qse_size_t mbl, qse_mbstate_t* state)
{
#if defined(FORCE_UTF8)
return qse_utf8len (mb, mbl);

View File

@ -1539,8 +1539,8 @@ static int task_main_cgi (
* writes it back to the client. so add a trigger for
* checking the data availability from the child process */
task->trigger.v[0].mask = QSE_HTTPD_TASK_TRIGGER_READ;
task->trigger.v[0].handle = qse_pio_gethandle (&cgi->pio, QSE_PIO_OUT);
task->trigger.v[1].handle = qse_pio_gethandle (&cgi->pio, QSE_PIO_IN);
task->trigger.v[0].handle = qse_pio_gethnd (&cgi->pio, QSE_PIO_OUT);
task->trigger.v[1].handle = qse_pio_gethnd (&cgi->pio, QSE_PIO_IN);
task->trigger.cmask = 0;
if (cgi->reqfwdbuf)

View File

@ -449,7 +449,7 @@ static QSE_INLINE qse_ssize_t __send_file (
qse_ssize_t ret;
qse_fio_hnd_t fh;
fh = qse_fio_gethandle (HANDLE_TO_FIO(in_fd));
fh = qse_fio_gethnd (HANDLE_TO_FIO(in_fd));
#if !defined(_LP64) && (QSE_SIZEOF_VOID_P<8) && defined(HAVE_SENDFILE64)
ret = sendfile64 (out_fd, fh, offset, count);
@ -464,7 +464,7 @@ static QSE_INLINE qse_ssize_t __send_file (
qse_ssize_t ret;
qse_fio_hnd_t fh;
fh = qse_fio_gethandle (HANDLE_TO_FIO(in_fd));
fh = qse_fio_gethnd (HANDLE_TO_FIO(in_fd));
#if defined(__FreeBSD__)
{
off_t nsent;
@ -487,7 +487,7 @@ static QSE_INLINE qse_ssize_t __send_file (
qse_ssize_t ret;
qse_fio_hnd_t fh;
fh = qse_fio_gethandle (HANDLE_TO_FIO(in_fd));
fh = qse_fio_gethnd (HANDLE_TO_FIO(in_fd));
ret = sendfile64 (out_fd, fh, offset, count);
if (ret <= -1) qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM());
return ret;
@ -505,7 +505,7 @@ static QSE_INLINE qse_ssize_t __send_file (
ssize_t ret;
qse_fio_hnd_t fh;
fh = qse_fio_gethandle (HANDLE_TO_FIO(in_fd));
fh = qse_fio_gethnd (HANDLE_TO_FIO(in_fd));
vec.sfv_fd = fh;
vec.sfv_flag = 0;

View File

@ -957,7 +957,7 @@ qse_fio_errnum_t qse_fio_geterrnum (const qse_fio_t* fio)
return fio->errnum;
}
qse_fio_hnd_t qse_fio_gethandle (const qse_fio_t* fio)
qse_fio_hnd_t qse_fio_gethnd (const qse_fio_t* fio)
{
return fio->handle;
}

View File

@ -1192,7 +1192,7 @@ void qse_nwio_setcmgr (qse_nwio_t* nwio, qse_cmgr_t* cmgr)
if (nwio->tio) qse_tio_setcmgr (nwio->tio, cmgr);
}
qse_nwio_hnd_t qse_nwio_gethandle (const qse_nwio_t* nwio)
qse_nwio_hnd_t qse_nwio_gethnd (const qse_nwio_t* nwio)
{
return nwio->handle;
}

View File

@ -1865,7 +1865,7 @@ void qse_pio_setcmgr (qse_pio_t* pio, qse_pio_hid_t hid, qse_cmgr_t* cmgr)
if (pio->pin[hid].tio) qse_tio_setcmgr (pio->pin[hid].tio, cmgr);
}
qse_pio_hnd_t qse_pio_gethandle (const qse_pio_t* pio, qse_pio_hid_t hid)
qse_pio_hnd_t qse_pio_gethnd (const qse_pio_t* pio, qse_pio_hid_t hid)
{
return pio->pin[hid].handle;
}

View File

@ -298,9 +298,9 @@ void qse_sio_setcmgr (qse_sio_t* sio, qse_cmgr_t* cmgr)
qse_tio_setcmgr (&sio->tio.io, cmgr);
}
qse_sio_hnd_t qse_sio_gethandle (const qse_sio_t* sio)
qse_sio_hnd_t qse_sio_gethnd (const qse_sio_t* sio)
{
/*return qse_fio_gethandle (&sio->file);*/
/*return qse_fio_gethnd (&sio->file);*/
return QSE_FIO_HANDLE(&sio->file);
}