fixed a minor bug in calling qse_sed_setcompid() from sed/std.c

This commit is contained in:
hyung-hwan 2011-10-08 22:41:52 +00:00
parent 055334e965
commit 84eb18092f
3 changed files with 53 additions and 28 deletions

View File

@ -336,28 +336,28 @@ static qse_sio_t* open_sio_rtx (qse_awk_rtx_t* rtx, const qse_char_t* file, int
return sio; return sio;
} }
static const qse_char_t* std_names[] = static const qse_char_t* sio_std_names[] =
{ {
QSE_T("stdin"), QSE_T("stdin"),
QSE_T("stdout"), QSE_T("stdout"),
QSE_T("stderr"), QSE_T("stderr"),
}; };
static qse_sio_t* open_sio_std (qse_awk_t* awk, int std, int flags) static qse_sio_t* open_sio_std (qse_awk_t* awk, qse_sio_std_t std, int flags)
{ {
qse_sio_t* sio; qse_sio_t* sio;
sio = qse_sio_openstd (awk->mmgr, 0, std, flags); sio = qse_sio_openstd (awk->mmgr, 0, std, flags);
if (sio == QSE_NULL) if (sio == QSE_NULL)
{ {
qse_cstr_t ea; qse_cstr_t ea;
ea.ptr = std_names[std]; ea.ptr = sio_std_names[std];
ea.len = qse_strlen (std_names[std]); ea.len = qse_strlen (sio_std_names[std]);
qse_awk_seterrnum (awk, QSE_AWK_EOPEN, &ea); qse_awk_seterrnum (awk, QSE_AWK_EOPEN, &ea);
} }
return sio; return sio;
} }
static qse_sio_t* open_sio_std_rtx (qse_awk_rtx_t* rtx, int std, int flags) static qse_sio_t* open_sio_std_rtx (qse_awk_rtx_t* rtx, qse_sio_std_t std, int flags)
{ {
qse_sio_t* sio; qse_sio_t* sio;
@ -365,8 +365,8 @@ static qse_sio_t* open_sio_std_rtx (qse_awk_rtx_t* rtx, int std, int flags)
if (sio == QSE_NULL) if (sio == QSE_NULL)
{ {
qse_cstr_t ea; qse_cstr_t ea;
ea.ptr = std_names[std]; ea.ptr = sio_std_names[std];
ea.len = qse_strlen (std_names[std]); ea.len = qse_strlen (sio_std_names[std]);
qse_awk_rtx_seterrnum (rtx, QSE_AWK_EOPEN, &ea); qse_awk_rtx_seterrnum (rtx, QSE_AWK_EOPEN, &ea);
} }
return sio; return sio;
@ -388,7 +388,7 @@ static qse_ssize_t sf_in_open (
{ {
/* special file name '-' */ /* special file name '-' */
xtn->s.in.handle = open_sio_std ( xtn->s.in.handle = open_sio_std (
awk, 0, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR); awk, QSE_SIO_STDIN, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR);
if (xtn->s.in.handle == QSE_NULL) return -1; if (xtn->s.in.handle == QSE_NULL) return -1;
} }
else else
@ -412,7 +412,7 @@ static qse_ssize_t sf_in_open (
case QSE_AWK_PARSESTD_STDIO: case QSE_AWK_PARSESTD_STDIO:
xtn->s.in.handle = open_sio_std ( xtn->s.in.handle = open_sio_std (
awk, 0, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR); awk, QSE_SIO_STDIN, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR);
if (xtn->s.in.handle == QSE_NULL) return -1; if (xtn->s.in.handle == QSE_NULL) return -1;
return 1; return 1;
@ -604,7 +604,9 @@ static qse_ssize_t sf_out (
{ {
/* special file name '-' */ /* special file name '-' */
xtn->s.out.handle = open_sio_std ( xtn->s.out.handle = open_sio_std (
awk, 1, QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR); awk, QSE_SIO_STDOUT,
QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR
);
if (xtn->s.out.handle == QSE_NULL) return -1; if (xtn->s.out.handle == QSE_NULL) return -1;
} }
else else
@ -620,7 +622,9 @@ static qse_ssize_t sf_out (
case QSE_AWK_PARSESTD_STDIO: case QSE_AWK_PARSESTD_STDIO:
xtn->s.out.handle = open_sio_std ( xtn->s.out.handle = open_sio_std (
awk, 1, QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR); awk, QSE_SIO_STDOUT,
QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR
);
if (xtn->s.out.handle == QSE_NULL) return -1; if (xtn->s.out.handle == QSE_NULL) return -1;
return 1; return 1;
@ -997,7 +1001,9 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
if (rxtn->c.in.count == 0) if (rxtn->c.in.count == 0)
{ {
sio = open_sio_std_rtx ( sio = open_sio_std_rtx (
rtx, 0, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR); rtx, QSE_SIO_STDIN,
QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR
);
if (sio == QSE_NULL) return -1; if (sio == QSE_NULL) return -1;
riod->handle = sio; riod->handle = sio;
@ -1037,7 +1043,9 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
* { print $0; }' file1 file2 * { print $0; }' file1 file2
*/ */
sio = open_sio_std_rtx ( sio = open_sio_std_rtx (
rtx, 0, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR); rtx, QSE_SIO_STDIN,
QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR
);
if (sio == QSE_NULL) return -1; if (sio == QSE_NULL) return -1;
riod->handle = sio; riod->handle = sio;
@ -1103,8 +1111,10 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
file = out.u.cpldup.ptr; file = out.u.cpldup.ptr;
sio = (file[0] == QSE_T('-') && file[1] == QSE_T('\0'))? sio = (file[0] == QSE_T('-') && file[1] == QSE_T('\0'))?
open_sio_std_rtx (rtx, 0, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR): open_sio_std_rtx (rtx, QSE_SIO_STDIN,
open_sio_rtx (rtx, file, QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR); QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR):
open_sio_rtx (rtx, file,
QSE_SIO_READ | QSE_SIO_IGNOREMBWCERR);
if (sio == QSE_NULL) if (sio == QSE_NULL)
{ {
qse_awk_rtx_freemem (rtx, out.u.cpldup.ptr); qse_awk_rtx_freemem (rtx, out.u.cpldup.ptr);
@ -1138,7 +1148,9 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
if (rxtn->c.out.count == 0) if (rxtn->c.out.count == 0)
{ {
sio = open_sio_std_rtx ( sio = open_sio_std_rtx (
rtx, 1, QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR); rtx, QSE_SIO_STDOUT,
QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR
);
if (sio == QSE_NULL) return -1; if (sio == QSE_NULL) return -1;
riod->handle = sio; riod->handle = sio;
@ -1165,7 +1177,8 @@ static int open_rio_console (qse_awk_rtx_t* rtx, qse_awk_rio_arg_t* riod)
sio = (file[0] == QSE_T('-') && file[1] == QSE_T('\0'))? sio = (file[0] == QSE_T('-') && file[1] == QSE_T('\0'))?
open_sio_std_rtx ( open_sio_std_rtx (
rtx, 1, QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR): rtx, QSE_SIO_STDOUT,
QSE_SIO_WRITE | QSE_SIO_IGNOREMBWCERR):
open_sio_rtx ( open_sio_rtx (
rtx, file, rtx, file,
QSE_SIO_WRITE | QSE_SIO_CREATE | QSE_SIO_WRITE | QSE_SIO_CREATE |

View File

@ -3653,6 +3653,8 @@ const qse_char_t* qse_sed_setcompid (qse_sed_t* sed, const qse_char_t* id)
return (const qse_char_t*)(sed->src.cid + 1); return (const qse_char_t*)(sed->src.cid + 1);
} }
if (id == QSE_NULL) id = QSE_T("");
len = qse_strlen (id); len = qse_strlen (id);
cid = QSE_MMGR_ALLOC (sed->mmgr, cid = QSE_MMGR_ALLOC (sed->mmgr,
QSE_SIZEOF(*cid) + ((len + 1) * QSE_SIZEOF(*id))); QSE_SIZEOF(*cid) + ((len + 1) * QSE_SIZEOF(*id)));

View File

@ -161,22 +161,23 @@ static qse_sio_t* open_sio (qse_sed_t* sed, const qse_char_t* file, int flags)
return sio; return sio;
} }
static const qse_char_t* sio_std_names[] =
{
QSE_T("stdin"),
QSE_T("stdout"),
QSE_T("stderr"),
};
static qse_sio_t* open_sio_std (qse_sed_t* sed, qse_sio_std_t std, int flags) static qse_sio_t* open_sio_std (qse_sed_t* sed, qse_sio_std_t std, int flags)
{ {
qse_sio_t* sio; qse_sio_t* sio;
static const qse_char_t* std_names[] =
{
QSE_T("stdin"),
QSE_T("stdout"),
QSE_T("stderr"),
};
sio = qse_sio_openstd (sed->mmgr, 0, std, flags); sio = qse_sio_openstd (sed->mmgr, 0, std, flags);
if (sio == QSE_NULL) if (sio == QSE_NULL)
{ {
qse_cstr_t ea; qse_cstr_t ea;
ea.ptr = std_names[std]; ea.ptr = sio_std_names[std];
ea.len = qse_strlen (std_names[std]); ea.len = qse_strlen (sio_std_names[std]);
qse_sed_seterrnum (sed, QSE_SED_EIOFIL, &ea); qse_sed_seterrnum (sed, QSE_SED_EIOFIL, &ea);
} }
return sio; return sio;
@ -231,15 +232,24 @@ static int open_input_stream (
/* reset script location */ /* reset script location */
if (io->type == QSE_SED_IOSTD_FILE) if (io->type == QSE_SED_IOSTD_FILE)
{ {
qse_sed_setcompid (sed, io->u.file); qse_sed_setcompid (
sed,
((io->u.file == QSE_NULL)?
sio_std_names[QSE_SIO_STDIN]: io->u.file)
);
} }
else else
{ {
qse_char_t buf[64]; qse_char_t buf[64];
/* format an identifier to be something like M#1, S#5 */
buf[0] = (io->type == QSE_SED_IOSTD_MEM)? QSE_T('M'): QSE_T('S'); buf[0] = (io->type == QSE_SED_IOSTD_MEM)? QSE_T('M'): QSE_T('S');
buf[1] = QSE_T('#'); buf[1] = QSE_T('#');
if (int_to_str (io - xtn->s.in.ptr, &buf[2], QSE_COUNTOF(buf) - 2) >= 0) int_to_str (io - xtn->s.in.ptr, &buf[2], QSE_COUNTOF(buf) - 2);
qse_sed_setcompid (sed, buf);
/* don't care about failure int_to_str() though it's not
* likely to happen */
qse_sed_setcompid (sed, buf);
} }
sed->src.loc.line = 1; sed->src.loc.line = 1;
sed->src.loc.colm = 1; sed->src.loc.colm = 1;