added qse_awk_rtx_openstdwithmbs(), qse_awk_rtx_openstdwithwcs().
added QSE_AWK_PARSESTD_MBS, QSE_AWK_PARSESTD_WCS
This commit is contained in:
parent
d5320cfd30
commit
74ff72564e
@ -46,7 +46,10 @@ enum qse_awk_parsestd_type_t
|
||||
{
|
||||
QSE_AWK_PARSESTD_NULL = 0, /**< pseudo-value to indicate no script */
|
||||
QSE_AWK_PARSESTD_FILE = 1, /**< file */
|
||||
QSE_AWK_PARSESTD_STR = 2 /**< length-bounded string */
|
||||
QSE_AWK_PARSESTD_STR = 2, /**< length-bounded string */
|
||||
QSE_AWK_PARSESTD_MBS = 3,
|
||||
QSE_AWK_PARSESTD_WCS = 4
|
||||
|
||||
};
|
||||
typedef enum qse_awk_parsestd_type_t qse_awk_parsestd_type_t;
|
||||
|
||||
@ -86,6 +89,8 @@ struct qse_awk_parsestd_t
|
||||
* avoid memory leaks.
|
||||
*/
|
||||
qse_cstr_t str;
|
||||
qse_mcstr_t mbs;
|
||||
qse_wcstr_t wcs;
|
||||
} u;
|
||||
};
|
||||
|
||||
@ -146,20 +151,41 @@ QSE_EXPORT int qse_awk_parsestd (
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_rtx_openstd() function creates a standard runtime context.
|
||||
* The qse_awk_rtx_openstdwithmbs() function creates a standard runtime context.
|
||||
* The caller should keep the contents of \a icf and \a ocf valid throughout
|
||||
* the lifetime of the runtime context created. The \a cmgr is set to the
|
||||
* streams created with \a icf and \a ocf if it is not #QSE_NULL.
|
||||
*/
|
||||
QSE_EXPORT qse_awk_rtx_t* qse_awk_rtx_openstd (
|
||||
QSE_EXPORT qse_awk_rtx_t* qse_awk_rtx_openstdwithmbs (
|
||||
qse_awk_t* awk,
|
||||
qse_size_t xtnsize,
|
||||
const qse_char_t* id,
|
||||
const qse_char_t* icf[],
|
||||
const qse_char_t* ocf[],
|
||||
const qse_mchar_t* id,
|
||||
const qse_mchar_t* icf[],
|
||||
const qse_mchar_t* ocf[],
|
||||
qse_cmgr_t* cmgr
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_awk_rtx_openstdwithwcs() function creates a standard runtime context.
|
||||
* The caller should keep the contents of \a icf and \a ocf valid throughout
|
||||
* the lifetime of the runtime context created. The \a cmgr is set to the
|
||||
* streams created with \a icf and \a ocf if it is not #QSE_NULL.
|
||||
*/
|
||||
QSE_EXPORT qse_awk_rtx_t* qse_awk_rtx_openstdwithwcs (
|
||||
qse_awk_t* awk,
|
||||
qse_size_t xtnsize,
|
||||
const qse_wchar_t* id,
|
||||
const qse_wchar_t* icf[],
|
||||
const qse_wchar_t* ocf[],
|
||||
qse_cmgr_t* cmgr
|
||||
);
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_awk_rtx_openstd qse_awk_rtx_openstdwithmbs
|
||||
#else
|
||||
# define qse_awk_rtx_openstd qse_awk_rtx_openstdwithwcs
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The qse_awk_rtx_getiocmgrstd() function gets the current character
|
||||
* manager associated with a particular I/O target indicated by the name
|
||||
|
@ -97,6 +97,16 @@ typedef struct xtn_t
|
||||
const qse_char_t* ptr;
|
||||
const qse_char_t* end;
|
||||
} str;
|
||||
struct
|
||||
{
|
||||
const qse_mchar_t* ptr;
|
||||
const qse_mchar_t* end;
|
||||
} mbs;
|
||||
struct
|
||||
{
|
||||
const qse_wchar_t* ptr;
|
||||
const qse_wchar_t* end;
|
||||
} wcs;
|
||||
} u;
|
||||
} in;
|
||||
|
||||
@ -113,6 +123,14 @@ typedef struct xtn_t
|
||||
{
|
||||
qse_str_t* buf;
|
||||
} str;
|
||||
struct
|
||||
{
|
||||
qse_mbs_t* buf;
|
||||
} mbs;
|
||||
struct
|
||||
{
|
||||
qse_wcs_t* buf;
|
||||
} wcs;
|
||||
} u;
|
||||
} out;
|
||||
} s; /* script/source handling */
|
||||
@ -671,6 +689,22 @@ static int open_parsestd (qse_awk_t* awk, qse_awk_sio_arg_t* arg, xtn_t* xtn, qs
|
||||
xtn->s.in.u.str.end = psin->u.str.ptr + psin->u.str.len;
|
||||
return 0;
|
||||
|
||||
case QSE_AWK_PARSESTD_MBS:
|
||||
if (index >= 1 && xtn->s.in.x[index-1].type == QSE_AWK_PARSESTD_FILE)
|
||||
qse_sio_close (arg->handle);
|
||||
|
||||
xtn->s.in.u.mbs.ptr = psin->u.mbs.ptr;
|
||||
xtn->s.in.u.mbs.end = psin->u.mbs.ptr + psin->u.mbs.len;
|
||||
return 0;
|
||||
|
||||
case QSE_AWK_PARSESTD_WCS:
|
||||
if (index >= 1 && xtn->s.in.x[index-1].type == QSE_AWK_PARSESTD_FILE)
|
||||
qse_sio_close (arg->handle);
|
||||
|
||||
xtn->s.in.u.wcs.ptr = psin->u.wcs.ptr;
|
||||
xtn->s.in.u.wcs.end = psin->u.wcs.ptr + psin->u.wcs.len;
|
||||
return 0;
|
||||
|
||||
default:
|
||||
qse_awk_seterrnum (awk, QSE_AWK_EINTERN, QSE_NULL);
|
||||
return -1;
|
||||
@ -788,6 +822,8 @@ static qse_ssize_t sf_in_close (qse_awk_t* awk, qse_awk_sio_arg_t* arg, xtn_t* x
|
||||
break;
|
||||
|
||||
case QSE_AWK_PARSESTD_STR:
|
||||
case QSE_AWK_PARSESTD_MBS:
|
||||
case QSE_AWK_PARSESTD_WCS:
|
||||
/* nothing to close */
|
||||
break;
|
||||
|
||||
@ -831,6 +867,7 @@ static qse_ssize_t sf_in_read (qse_awk_t* awk, qse_awk_sio_arg_t* arg, qse_char_
|
||||
break;
|
||||
|
||||
case QSE_AWK_PARSESTD_STR:
|
||||
parsestd_str:
|
||||
n = 0;
|
||||
while (n < size && xtn->s.in.u.str.ptr < xtn->s.in.u.str.end)
|
||||
{
|
||||
@ -838,6 +875,54 @@ static qse_ssize_t sf_in_read (qse_awk_t* awk, qse_awk_sio_arg_t* arg, qse_char_
|
||||
}
|
||||
break;
|
||||
|
||||
case QSE_AWK_PARSESTD_MBS:
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
goto parsestd_str;
|
||||
#else
|
||||
{
|
||||
int m;
|
||||
qse_size_t mbslen, wcslen;
|
||||
|
||||
mbslen = xtn->s.in.u.mbs.end - xtn->s.in.u.mbs.ptr;
|
||||
wcslen = size;
|
||||
if ((m = qse_mbsntowcsnwithcmgr(xtn->s.in.u.mbs.ptr, &mbslen, data, &wcslen, qse_awk_getcmgr(awk))) <= -1 && m != -2)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_EINVAL, QSE_NULL);
|
||||
n = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
xtn->s.in.u.mbs.ptr += mbslen;
|
||||
n = wcslen;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case QSE_AWK_PARSESTD_WCS:
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
{
|
||||
int m;
|
||||
qse_size_t mbslen, wcslen;
|
||||
|
||||
wcslen = xtn->s.in.u.wcs.end - xtn->s.in.u.wcs.ptr;
|
||||
mbslen = size;
|
||||
if ((m = qse_wcsntombsnwithcmgr(xtn->s.in.u.wcs.ptr, &wcslen, data, &mbslen, qse_awk_getcmgr(awk))) <= -1 && m != -2)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_EINVAL, QSE_NULL);
|
||||
n = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
xtn->s.in.u.wcs.ptr += wcslen;
|
||||
n = mbslen;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#else
|
||||
goto parsestd_str;
|
||||
#endif
|
||||
|
||||
default:
|
||||
/* this should never happen */
|
||||
qse_awk_seterrnum (awk, QSE_AWK_EINTERN, QSE_NULL);
|
||||
@ -959,7 +1044,24 @@ static qse_ssize_t sf_out (qse_awk_t* awk, qse_awk_sio_cmd_t cmd, qse_awk_sio_ar
|
||||
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
|
||||
case QSE_AWK_PARSESTD_MBS:
|
||||
xtn->s.out.u.mbs.buf = qse_mbs_open(qse_awk_getmmgr(awk), 0, 512);
|
||||
if (xtn->s.out.u.mbs.buf == QSE_NULL)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
|
||||
case QSE_AWK_PARSESTD_WCS:
|
||||
xtn->s.out.u.wcs.buf = qse_wcs_open(qse_awk_getmmgr(awk), 0, 512);
|
||||
if (xtn->s.out.u.wcs.buf == QSE_NULL)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -976,6 +1078,8 @@ static qse_ssize_t sf_out (qse_awk_t* awk, qse_awk_sio_cmd_t cmd, qse_awk_sio_ar
|
||||
return 0;
|
||||
|
||||
case QSE_AWK_PARSESTD_STR:
|
||||
case QSE_AWK_PARSESTD_MBS:
|
||||
case QSE_AWK_PARSESTD_WCS:
|
||||
/* i don't close xtn->s.out.u.str.buf intentionally here.
|
||||
* it will be closed at the end of qse_awk_parsestd() */
|
||||
return 0;
|
||||
@ -1005,7 +1109,7 @@ static qse_ssize_t sf_out (qse_awk_t* awk, qse_awk_sio_cmd_t cmd, qse_awk_sio_ar
|
||||
}
|
||||
|
||||
case QSE_AWK_PARSESTD_STR:
|
||||
{
|
||||
parsestd_str:
|
||||
if (size > QSE_TYPE_MAX(qse_ssize_t)) size = QSE_TYPE_MAX(qse_ssize_t);
|
||||
if (qse_str_ncat(xtn->s.out.u.str.buf, data, size) == (qse_size_t)-1)
|
||||
{
|
||||
@ -1013,7 +1117,70 @@ static qse_ssize_t sf_out (qse_awk_t* awk, qse_awk_sio_cmd_t cmd, qse_awk_sio_ar
|
||||
return -1;
|
||||
}
|
||||
return size;
|
||||
|
||||
case QSE_AWK_PARSESTD_MBS:
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
goto parsestd_str;
|
||||
#else
|
||||
{
|
||||
qse_size_t mbslen, wcslen;
|
||||
qse_size_t orglen;
|
||||
|
||||
wcslen = size;
|
||||
if (qse_wcsntombsnwithcmgr(data, &wcslen, QSE_NULL, &mbslen, qse_awk_getcmgr(awk)) <= -1)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_EINVAL, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mbslen > QSE_TYPE_MAX(qse_ssize_t)) mbslen = QSE_TYPE_MAX(qse_ssize_t);
|
||||
|
||||
orglen = qse_mbs_getlen(xtn->s.out.u.mbs.buf);
|
||||
if (qse_mbs_setlen(xtn->s.out.u.mbs.buf, orglen + mbslen) == (qse_size_t)-1)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
wcslen = size;
|
||||
qse_wcsntombsnwithcmgr(data, &wcslen, QSE_MBS_CPTR(xtn->s.out.u.mbs.buf, orglen), &mbslen, qse_awk_getcmgr(awk));
|
||||
size = wcslen;
|
||||
|
||||
return size;
|
||||
}
|
||||
#endif
|
||||
|
||||
case QSE_AWK_PARSESTD_WCS:
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
{
|
||||
qse_size_t mbslen, wcslen;
|
||||
qse_size_t orglen;
|
||||
|
||||
mbslen = size;
|
||||
if (qse_mbsntowcsnwithcmgr(data, &mbslen, QSE_NULL, &wcslen, qse_awk_getcmgr(awk)) <= -1)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_EINVAL, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (wcslen > QSE_TYPE_MAX(qse_ssize_t)) wcslen = QSE_TYPE_MAX(qse_ssize_t);
|
||||
|
||||
orglen = qse_mbs_getlen(xtn->s.out.u.wcs.buf);
|
||||
if (qse_wcs_setlen(xtn->s.out.u.wcs.buf, orglen + wcslen) == (qse_size_t)-1)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mbslen = size;
|
||||
qse_mbsntowcsnwithcmgr(data, &mbslen, QSE_MBS_CPTR(xtn->s.out.u.wcs.buf, orglen), &wcslen, qse_awk_getcmgr(awk));
|
||||
size = mbslen;
|
||||
|
||||
return size;
|
||||
}
|
||||
#else
|
||||
goto parsestd_str;
|
||||
#endif
|
||||
}
|
||||
|
||||
break;
|
||||
@ -1035,7 +1202,9 @@ int qse_awk_parsestd (qse_awk_t* awk, qse_awk_parsestd_t in[], qse_awk_parsestd_
|
||||
int n;
|
||||
|
||||
if (in == QSE_NULL || (in[0].type != QSE_AWK_PARSESTD_FILE &&
|
||||
in[0].type != QSE_AWK_PARSESTD_STR))
|
||||
in[0].type != QSE_AWK_PARSESTD_STR &&
|
||||
in[0].type != QSE_AWK_PARSESTD_MBS &&
|
||||
in[0].type != QSE_AWK_PARSESTD_WCS))
|
||||
{
|
||||
/* the input is a must. at least 1 file or 1 string
|
||||
* must be specified */
|
||||
@ -1050,7 +1219,9 @@ int qse_awk_parsestd (qse_awk_t* awk, qse_awk_parsestd_t in[], qse_awk_parsestd_
|
||||
else
|
||||
{
|
||||
if (out->type != QSE_AWK_PARSESTD_FILE &&
|
||||
out->type != QSE_AWK_PARSESTD_STR)
|
||||
out->type != QSE_AWK_PARSESTD_STR &&
|
||||
out->type != QSE_AWK_PARSESTD_MBS &&
|
||||
out->type != QSE_AWK_PARSESTD_WCS)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_EINVAL, QSE_NULL);
|
||||
return -1;
|
||||
@ -1061,14 +1232,37 @@ int qse_awk_parsestd (qse_awk_t* awk, qse_awk_parsestd_t in[], qse_awk_parsestd_
|
||||
|
||||
n = qse_awk_parse(awk, &sio);
|
||||
|
||||
if (out && out->type == QSE_AWK_PARSESTD_STR)
|
||||
if (out)
|
||||
{
|
||||
switch (out->type)
|
||||
{
|
||||
case QSE_AWK_PARSESTD_STR:
|
||||
if (n >= 0)
|
||||
{
|
||||
QSE_ASSERT (xtn->s.out.u.str.buf != QSE_NULL);
|
||||
qse_str_yield (xtn->s.out.u.str.buf, &out->u.str, 0);
|
||||
}
|
||||
if (xtn->s.out.u.str.buf) qse_str_close (xtn->s.out.u.str.buf);
|
||||
break;
|
||||
|
||||
case QSE_AWK_PARSESTD_MBS:
|
||||
if (n >= 0)
|
||||
{
|
||||
QSE_ASSERT (xtn->s.out.u.mbs.buf != QSE_NULL);
|
||||
qse_mbs_yield (xtn->s.out.u.mbs.buf, &out->u.mbs, 0);
|
||||
}
|
||||
if (xtn->s.out.u.mbs.buf) qse_mbs_close (xtn->s.out.u.mbs.buf);
|
||||
break;
|
||||
|
||||
case QSE_AWK_PARSESTD_WCS:
|
||||
if (n >= 0)
|
||||
{
|
||||
QSE_ASSERT (xtn->s.out.u.wcs.buf != QSE_NULL);
|
||||
qse_wcs_yield (xtn->s.out.u.wcs.buf, &out->u.wcs, 0);
|
||||
}
|
||||
if (xtn->s.out.u.wcs.buf) qse_wcs_close (xtn->s.out.u.wcs.buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
@ -1959,7 +2153,7 @@ static int make_additional_globals (
|
||||
return 0;
|
||||
}
|
||||
|
||||
qse_awk_rtx_t* qse_awk_rtx_openstd (
|
||||
static qse_awk_rtx_t* open_rtx_std (
|
||||
qse_awk_t* awk,
|
||||
qse_size_t xtnsize,
|
||||
const qse_char_t* id,
|
||||
@ -2040,6 +2234,141 @@ qse_awk_rtx_t* qse_awk_rtx_openstd (
|
||||
return rtx;
|
||||
}
|
||||
|
||||
qse_awk_rtx_t* qse_awk_rtx_openstdwithmbs (
|
||||
qse_awk_t* awk,
|
||||
qse_size_t xtnsize,
|
||||
const qse_mchar_t* id,
|
||||
const qse_mchar_t* icf[],
|
||||
const qse_mchar_t* ocf[],
|
||||
qse_cmgr_t* cmgr)
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
return open_rtx_std(awk, xtnsize, id, icf, ocf, cmgr);
|
||||
#else
|
||||
qse_awk_rtx_t* rtx = QSE_NULL;
|
||||
qse_size_t wcslen, i;
|
||||
qse_wchar_t* wid = QSE_NULL, ** wicf = QSE_NULL, ** wocf = QSE_NULL;
|
||||
|
||||
wid = qse_awk_mbstowcsdup(awk, id, &wcslen);
|
||||
if (!wid) return QSE_NULL;
|
||||
|
||||
if (icf)
|
||||
{
|
||||
for (i = 0; icf[i]; i++) ;
|
||||
|
||||
wicf = (qse_wchar_t**)qse_awk_callocmem(awk, QSE_SIZEOF(*wicf) * (i + 1));
|
||||
if (!wicf) goto done;
|
||||
|
||||
for (i = 0; icf[i]; i++)
|
||||
{
|
||||
wicf[i] = qse_awk_mbstowcsdup(awk, icf[i], &wcslen);
|
||||
if (!wicf[i]) goto done;
|
||||
}
|
||||
wicf[i] = QSE_NULL;
|
||||
}
|
||||
|
||||
if (ocf)
|
||||
{
|
||||
for (i = 0; ocf[i]; i++) ;
|
||||
|
||||
wocf = (qse_wchar_t**)qse_awk_callocmem(awk, QSE_SIZEOF(*wocf) * (i + 1));
|
||||
if (!wocf) goto done;
|
||||
|
||||
for (i = 0; ocf[i]; i++)
|
||||
{
|
||||
wocf[i] = qse_awk_mbstowcsdup(awk, ocf[i], &wcslen);
|
||||
if (!wocf[i]) goto done;
|
||||
}
|
||||
wocf[i] = QSE_NULL;
|
||||
}
|
||||
|
||||
rtx = open_rtx_std(awk, xtnsize, wid, (const qse_wchar_t**)wicf, (const qse_wchar_t**)wocf, cmgr);
|
||||
|
||||
done:
|
||||
if (wocf)
|
||||
{
|
||||
for (i = 0; wocf[i]; i++) qse_awk_freemem (awk, wocf[i]);
|
||||
qse_awk_freemem (awk, wocf);
|
||||
}
|
||||
if (wicf)
|
||||
{
|
||||
for (i = 0; wicf[i]; i++) qse_awk_freemem (awk, wicf[i]);
|
||||
qse_awk_freemem (awk, wicf);
|
||||
}
|
||||
if (wid) qse_awk_freemem (awk, wid);
|
||||
|
||||
return rtx;
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_awk_rtx_t* qse_awk_rtx_openstdwithwcs (
|
||||
qse_awk_t* awk,
|
||||
qse_size_t xtnsize,
|
||||
const qse_wchar_t* id,
|
||||
const qse_wchar_t* icf[],
|
||||
const qse_wchar_t* ocf[],
|
||||
qse_cmgr_t* cmgr)
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
qse_awk_rtx_t* rtx = QSE_NULL;
|
||||
qse_size_t mbslen, i;
|
||||
qse_mchar_t* mid = QSE_NULL, ** micf = QSE_NULL, ** mocf = QSE_NULL;
|
||||
|
||||
mid = qse_awk_wcstombsdup(awk, id, &mbslen);
|
||||
if (!mid) return QSE_NULL;
|
||||
|
||||
if (icf)
|
||||
{
|
||||
for (i = 0; icf[i]; i++) ;
|
||||
|
||||
micf = (qse_mchar_t**)qse_awk_callocmem(awk, QSE_SIZEOF(*micf) * (i + 1));
|
||||
if (!micf) goto done;
|
||||
|
||||
for (i = 0; icf[i]; i++)
|
||||
{
|
||||
micf[i] = qse_awk_wcstombsdup(awk, icf[i], &mbslen);
|
||||
if (!micf[i]) goto done;
|
||||
}
|
||||
micf[i] = QSE_NULL;
|
||||
}
|
||||
|
||||
if (ocf)
|
||||
{
|
||||
for (i = 0; ocf[i]; i++) ;
|
||||
|
||||
mocf = (qse_wchar_t**)qse_awk_callocmem(awk, QSE_SIZEOF(*mocf) * (i + 1));
|
||||
if (!mocf) goto done;
|
||||
|
||||
for (i = 0; ocf[i]; i++)
|
||||
{
|
||||
mocf[i] = qse_awk_wcstombsdup(awk, ocf[i], &mbslen);
|
||||
if (!mocf[i]) goto done;
|
||||
}
|
||||
mocf[i] = QSE_NULL;
|
||||
}
|
||||
|
||||
rtx = open_rtx_std(awk, xtnsize, mid, (const qse_mchar_t**)micf, (const qse_mchar_t**)mocf, cmgr);
|
||||
|
||||
done:
|
||||
if (mocf)
|
||||
{
|
||||
for (i = 0; mocf[i]; i++) qse_awk_freemem (awk, mocf[i]);
|
||||
qse_awk_freemem (awk, mocf);
|
||||
}
|
||||
if (micf)
|
||||
{
|
||||
for (i = 0; micf[i]; i++) qse_awk_freemem (awk, micf[i]);
|
||||
qse_awk_freemem (awk, micf);
|
||||
}
|
||||
if (mid) qse_awk_freemem (awk, mid);
|
||||
|
||||
return rtx;
|
||||
#else
|
||||
return open_rtx_std(awk, xtnsize, id, icf, ocf, cmgr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static int timeout_code (const qse_char_t* name)
|
||||
{
|
||||
if (qse_strcasecmp(name, QSE_T("rtimeout")) == 0) return 0;
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include <qse/awk/awk.h>
|
||||
#include <qse/awk/stdawk.h>
|
||||
#include <qse/cmn/mem.h>
|
||||
#include <qse/cmn/path.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/si/sio.h>
|
||||
|
||||
static const qse_char_t* src = QSE_T(
|
||||
@ -40,7 +42,7 @@ static const qse_char_t* src = QSE_T(
|
||||
"}"
|
||||
);
|
||||
|
||||
int main ()
|
||||
int main (int argc, char* argv[])
|
||||
{
|
||||
qse_awk_t* awk = QSE_NULL;
|
||||
qse_awk_rtx_t* rtx = QSE_NULL;
|
||||
@ -49,10 +51,22 @@ int main ()
|
||||
qse_awk_parsestd_t psin[2];
|
||||
qse_awk_parsestd_t psout;
|
||||
|
||||
int ret;
|
||||
int ret, omode = 0;
|
||||
|
||||
qse_open_stdsios ();
|
||||
|
||||
if (argc >= 2)
|
||||
{
|
||||
if (argc == 2 && qse_mbscmp(argv[1], "-m") == 0) omode = 1;
|
||||
else if (argc == 2 && qse_mbscmp(argv[1], "-w") == 0) omode = 2;
|
||||
else
|
||||
{
|
||||
qse_fprintf (QSE_STDERR, QSE_T("USAGE: %hs [-m | -w]\n"), qse_basenameasmbs(argv[0]));
|
||||
ret = -1; goto oops;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
awk = qse_awk_openstd(0, QSE_NULL);
|
||||
if (awk == QSE_NULL)
|
||||
{
|
||||
@ -65,44 +79,68 @@ int main ()
|
||||
psin[0].u.str.len = qse_strlen(src);
|
||||
psin[1].type = QSE_AWK_PARSESTD_NULL;
|
||||
|
||||
switch (omode)
|
||||
{
|
||||
case 1:
|
||||
psout.type = QSE_AWK_PARSESTD_MBS;
|
||||
break;
|
||||
case 2:
|
||||
psout.type = QSE_AWK_PARSESTD_WCS;
|
||||
break;
|
||||
|
||||
default:
|
||||
psout.type = QSE_AWK_PARSESTD_STR;
|
||||
break;
|
||||
/* ps.out.u.str.ptr and ps.out.u.str.len are set when qse_awk_parsestd()
|
||||
* returns success */
|
||||
}
|
||||
|
||||
ret = qse_awk_parsestd(awk, psin, &psout);
|
||||
if (ret <= -1)
|
||||
{
|
||||
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"),
|
||||
qse_awk_geterrmsg(awk));
|
||||
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"), qse_awk_geterrmsg(awk));
|
||||
ret = -1; goto oops;
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("DEPARSED SOURCE:\n%s\n"), psout.u.str.ptr);
|
||||
qse_printf (QSE_T("DEPARSED SOURCE:\n"));
|
||||
switch (omode)
|
||||
{
|
||||
case 1:
|
||||
qse_printf (QSE_T("%hs\n"), psout.u.mbs.ptr);
|
||||
qse_awk_freemem (awk, psout.u.mbs.ptr);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
qse_printf (QSE_T("%ls\n"), psout.u.wcs.ptr);
|
||||
qse_awk_freemem (awk, psout.u.wcs.ptr);
|
||||
break;
|
||||
|
||||
default:
|
||||
qse_printf (QSE_T("%js\n"), psout.u.str.ptr);
|
||||
qse_awk_freemem (awk, psout.u.str.ptr);
|
||||
break;
|
||||
}
|
||||
qse_printf (QSE_T("=================================\n"));
|
||||
qse_fflush (QSE_STDOUT);
|
||||
|
||||
QSE_MMGR_FREE (qse_awk_getmmgr(awk), psout.u.str.ptr);
|
||||
|
||||
rtx = qse_awk_rtx_openstd (
|
||||
awk,
|
||||
0,
|
||||
QSE_T("awk02"),
|
||||
QSE_T("awk15"),
|
||||
QSE_NULL, /* stdin */
|
||||
QSE_NULL, /* stdout */
|
||||
QSE_NULL /* default cmgr */
|
||||
);
|
||||
if (rtx == QSE_NULL)
|
||||
{
|
||||
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"),
|
||||
qse_awk_geterrmsg(awk));
|
||||
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"), qse_awk_geterrmsg(awk));
|
||||
ret = -1; goto oops;
|
||||
}
|
||||
|
||||
retv = qse_awk_rtx_loop(rtx);
|
||||
if (retv == QSE_NULL)
|
||||
{
|
||||
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"),
|
||||
qse_awk_rtx_geterrmsg(rtx));
|
||||
qse_fprintf (QSE_STDERR, QSE_T("ERROR: %s\n"), qse_awk_rtx_geterrmsg(rtx));
|
||||
ret = -1; goto oops;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user