fixed a bug in awk's built-in function fflush().
added the mb8 conversion routines for raw byte conversion
This commit is contained in:
@ -225,7 +225,7 @@ static int fnc_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
if (name == QSE_NULL) return -1;
|
||||
}
|
||||
|
||||
if (a1 != QSE_NULL)
|
||||
if (a1)
|
||||
{
|
||||
if (a1->type == QSE_AWK_VAL_STR)
|
||||
{
|
||||
@ -246,7 +246,7 @@ static int fnc_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
/* getline or print doesn't allow an emptry for the
|
||||
/* getline or print doesn't allow an empty string for the
|
||||
* input or output file name. so close should not allow
|
||||
* it either.
|
||||
* another reason for this is if close is called explicitly
|
||||
@ -346,8 +346,16 @@ static int fnc_fflush (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
|
||||
|
||||
if (nargs == 0)
|
||||
{
|
||||
/* flush the console output.
|
||||
* fflush() should return -1 on errors */
|
||||
/* fflush() flushes the console output.
|
||||
* fflush() should return -1 on errors.
|
||||
*
|
||||
* if no previous console output statement is seen,
|
||||
* this function won't be able to find the entry.
|
||||
* so it returns -1;
|
||||
*
|
||||
* BEGIN { flush(); } # flush() returns -1
|
||||
* BEGIN { print 1; flush(); } # flush() returns 0
|
||||
*/
|
||||
n = qse_awk_rtx_flushio (run, QSE_AWK_OUT_CONSOLE, QSE_T(""));
|
||||
}
|
||||
else
|
||||
@ -380,17 +388,43 @@ static int fnc_fflush (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
|
||||
ptr++;
|
||||
}
|
||||
|
||||
/* flush the given rio */
|
||||
/* flush the given rio.
|
||||
*
|
||||
* flush("") flushes all output streams regardless of names.
|
||||
* pass QSE_NULL for the name in that case so that the
|
||||
* callee matches any streams.
|
||||
*
|
||||
* fflush() doesn't specify the type of output streams
|
||||
* so it attemps to flush all types of output streams.
|
||||
*
|
||||
* though not useful, it's possible to have multiple
|
||||
* streams with the same name but of different types.
|
||||
*
|
||||
* BEGIN {
|
||||
* print 1 | "/tmp/x";
|
||||
* print 1 > "/tmp/x";
|
||||
* fflush("/tmp/x");
|
||||
* }
|
||||
*/
|
||||
|
||||
n = flush_io (
|
||||
run, QSE_AWK_RIO_FILE,
|
||||
run, QSE_AWK_OUT_FILE,
|
||||
((len0 == 0)? QSE_NULL: str0), 1);
|
||||
/*if (n == -99) return -1;*/
|
||||
n = flush_io (
|
||||
run, QSE_AWK_RIO_PIPE,
|
||||
run, QSE_AWK_OUT_APFILE,
|
||||
((len0 == 0)? QSE_NULL: str0), n);
|
||||
/*if (n == -99) return -1;*/
|
||||
n = flush_io (
|
||||
run, QSE_AWK_OUT_PIPE,
|
||||
((len0 == 0)? QSE_NULL: str0), n);
|
||||
/*if (n == -99) return -1;*/
|
||||
n = flush_io (
|
||||
run, QSE_AWK_OUT_RWPIPE,
|
||||
((len0 == 0)? QSE_NULL: str0), n);
|
||||
/*if (n == -99) return -1;*/
|
||||
|
||||
/* if n remains 1, no ip handlers have been defined for
|
||||
/* if n remains 1, no io handlers have been defined for
|
||||
* file, pipe, and rwpipe. so make fflush return -1.
|
||||
* if n is -2, no such named io has been found at all
|
||||
* if n is -1, the io handler has returned an error */
|
||||
|
@ -114,7 +114,7 @@ static int find_rio_in (
|
||||
}
|
||||
|
||||
/* search the chain for exiting an existing io name */
|
||||
while (p != QSE_NULL)
|
||||
while (p)
|
||||
{
|
||||
if (p->type == (io_type | io_mask) &&
|
||||
qse_strcmp (p->name,name) == 0) break;
|
||||
@ -688,7 +688,7 @@ int qse_awk_rtx_writeio_str (
|
||||
}
|
||||
|
||||
/* look for the corresponding rio for name */
|
||||
while (p != QSE_NULL)
|
||||
while (p)
|
||||
{
|
||||
/* the file "1.tmp", in the following code snippets,
|
||||
* would be opened by the first print statement, but not by
|
||||
@ -799,7 +799,7 @@ int qse_awk_rtx_flushio (
|
||||
{
|
||||
qse_awk_rio_arg_t* p = run->rio.chain;
|
||||
qse_awk_rio_impl_t handler;
|
||||
int io_type, /*io_mode,*/ io_mask;
|
||||
int io_type, io_mode, io_mask;
|
||||
qse_ssize_t n;
|
||||
int ok = 0;
|
||||
|
||||
@ -809,7 +809,7 @@ int qse_awk_rtx_flushio (
|
||||
|
||||
/* translate the out_type into the relevant I/O type and mode */
|
||||
io_type = out_type_map[out_type];
|
||||
/*io_mode = out_mode_map[out_type];*/
|
||||
io_mode = out_mode_map[out_type];
|
||||
io_mask = out_mask_map[out_type];
|
||||
|
||||
handler = run->rio.handler[io_type];
|
||||
@ -821,9 +821,13 @@ int qse_awk_rtx_flushio (
|
||||
}
|
||||
|
||||
/* look for the corresponding rio for name */
|
||||
while (p != QSE_NULL)
|
||||
while (p)
|
||||
{
|
||||
if (p->type == (io_type | io_mask) &&
|
||||
/* without the check for io_mode and p->mode,
|
||||
* QSE_AWK_OUT_FILE and QSE_AWK_OUT_APFILE matches the
|
||||
* same entry since (io_type | io_mask) has the same value
|
||||
* for both. */
|
||||
if (p->type == (io_type | io_mask) && p->mode == io_mode &&
|
||||
(name == QSE_NULL || qse_strcmp(p->name,name) == 0))
|
||||
{
|
||||
qse_awk_rtx_seterrnum (run, QSE_AWK_ENOERR, QSE_NULL);
|
||||
@ -1123,7 +1127,7 @@ int qse_awk_rtx_closeio (
|
||||
{
|
||||
qse_awk_rio_arg_t* p = rtx->rio.chain, * px = QSE_NULL;
|
||||
|
||||
while (p != QSE_NULL)
|
||||
while (p)
|
||||
{
|
||||
/* it handles the first that matches the given name
|
||||
* regardless of the io type */
|
||||
|
@ -45,6 +45,7 @@ libqsecmn_la_SOURCES = \
|
||||
ipad.c \
|
||||
lda.c \
|
||||
main.c \
|
||||
mb8.c \
|
||||
mbwc.c \
|
||||
mbwc-str.c \
|
||||
mem.c \
|
||||
|
@ -88,15 +88,15 @@ libqsecmn_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am__libqsecmn_la_SOURCES_DIST = alg-base64.c alg-rand.c alg-search.c \
|
||||
alg-sort.c assert.c chr.c dir.c dll.c env.c gdl.c htb.c fio.c \
|
||||
fma.c fmt.c fs.c fs-err.c fs-move.c glob.c hton.c ipad.c lda.c \
|
||||
main.c mbwc.c mbwc-str.c mem.c mux.c nwad.c nwad-skad.c nwif.c \
|
||||
nwif-cfg.c nwio.c oht.c opt.c path-basename.c path-canon.c \
|
||||
pio.c pma.c rbt.c rex.c sio.c sll.c slmb.c stdio.c str-beg.c \
|
||||
str-cat.c str-chr.c str-cnv.c str-cmp.c str-cpy.c str-del.c \
|
||||
str-dup.c str-dynm.c str-dynw.c str-end.c str-excl.c \
|
||||
str-fcpy.c str-fnmat.c str-incl.c str-len.c str-pac.c \
|
||||
str-pbrk.c str-put.c str-rev.c str-rot.c str-set.c str-spl.c \
|
||||
str-spn.c str-str.c str-subst.c str-tok.c str-trm.c str-word.c \
|
||||
task.c time.c tio.c tre.c tre-ast.c tre-compile.c \
|
||||
main.c mb8.c mbwc.c mbwc-str.c mem.c mux.c nwad.c nwad-skad.c \
|
||||
nwif.c nwif-cfg.c nwio.c oht.c opt.c path-basename.c \
|
||||
path-canon.c pio.c pma.c rbt.c rex.c sio.c sll.c slmb.c \
|
||||
stdio.c str-beg.c str-cat.c str-chr.c str-cnv.c str-cmp.c \
|
||||
str-cpy.c str-del.c str-dup.c str-dynm.c str-dynw.c str-end.c \
|
||||
str-excl.c str-fcpy.c str-fnmat.c str-incl.c str-len.c \
|
||||
str-pac.c str-pbrk.c str-put.c str-rev.c str-rot.c str-set.c \
|
||||
str-spl.c str-spn.c str-str.c str-subst.c str-tok.c str-trm.c \
|
||||
str-word.c task.c time.c tio.c tre.c tre-ast.c tre-compile.c \
|
||||
tre-match-backtrack.c tre-match-parallel.c tre-parse.c \
|
||||
tre-stack.c uri.c utf8.c xma.c uni.c cp949.c cp950.c
|
||||
@ENABLE_BUNDLED_UNICODE_TRUE@am__objects_1 = uni.lo
|
||||
@ -104,17 +104,17 @@ am__libqsecmn_la_SOURCES_DIST = alg-base64.c alg-rand.c alg-search.c \
|
||||
am_libqsecmn_la_OBJECTS = alg-base64.lo alg-rand.lo alg-search.lo \
|
||||
alg-sort.lo assert.lo chr.lo dir.lo dll.lo env.lo gdl.lo \
|
||||
htb.lo fio.lo fma.lo fmt.lo fs.lo fs-err.lo fs-move.lo glob.lo \
|
||||
hton.lo ipad.lo lda.lo main.lo mbwc.lo mbwc-str.lo mem.lo \
|
||||
mux.lo nwad.lo nwad-skad.lo nwif.lo nwif-cfg.lo nwio.lo oht.lo \
|
||||
opt.lo path-basename.lo path-canon.lo pio.lo pma.lo rbt.lo \
|
||||
rex.lo sio.lo sll.lo slmb.lo stdio.lo str-beg.lo str-cat.lo \
|
||||
str-chr.lo str-cnv.lo str-cmp.lo str-cpy.lo str-del.lo \
|
||||
str-dup.lo str-dynm.lo str-dynw.lo str-end.lo str-excl.lo \
|
||||
str-fcpy.lo str-fnmat.lo str-incl.lo str-len.lo str-pac.lo \
|
||||
str-pbrk.lo str-put.lo str-rev.lo str-rot.lo str-set.lo \
|
||||
str-spl.lo str-spn.lo str-str.lo str-subst.lo str-tok.lo \
|
||||
str-trm.lo str-word.lo task.lo time.lo tio.lo tre.lo \
|
||||
tre-ast.lo tre-compile.lo tre-match-backtrack.lo \
|
||||
hton.lo ipad.lo lda.lo main.lo mb8.lo mbwc.lo mbwc-str.lo \
|
||||
mem.lo mux.lo nwad.lo nwad-skad.lo nwif.lo nwif-cfg.lo nwio.lo \
|
||||
oht.lo opt.lo path-basename.lo path-canon.lo pio.lo pma.lo \
|
||||
rbt.lo rex.lo sio.lo sll.lo slmb.lo stdio.lo str-beg.lo \
|
||||
str-cat.lo str-chr.lo str-cnv.lo str-cmp.lo str-cpy.lo \
|
||||
str-del.lo str-dup.lo str-dynm.lo str-dynw.lo str-end.lo \
|
||||
str-excl.lo str-fcpy.lo str-fnmat.lo str-incl.lo str-len.lo \
|
||||
str-pac.lo str-pbrk.lo str-put.lo str-rev.lo str-rot.lo \
|
||||
str-set.lo str-spl.lo str-spn.lo str-str.lo str-subst.lo \
|
||||
str-tok.lo str-trm.lo str-word.lo task.lo time.lo tio.lo \
|
||||
tre.lo tre-ast.lo tre-compile.lo tre-match-backtrack.lo \
|
||||
tre-match-parallel.lo tre-parse.lo tre-stack.lo uri.lo utf8.lo \
|
||||
xma.lo $(am__objects_1) $(am__objects_2)
|
||||
libqsecmn_la_OBJECTS = $(am_libqsecmn_la_OBJECTS)
|
||||
@ -355,7 +355,7 @@ noinst_HEADERS = \
|
||||
libqsecmn_la_SOURCES = alg-base64.c alg-rand.c alg-search.c alg-sort.c \
|
||||
assert.c chr.c dir.c dll.c env.c gdl.c htb.c fio.c fma.c fmt.c \
|
||||
fs.c fs-err.c fs-move.c glob.c hton.c ipad.c lda.c main.c \
|
||||
mbwc.c mbwc-str.c mem.c mux.c nwad.c nwad-skad.c nwif.c \
|
||||
mb8.c mbwc.c mbwc-str.c mem.c mux.c nwad.c nwad-skad.c nwif.c \
|
||||
nwif-cfg.c nwio.c oht.c opt.c path-basename.c path-canon.c \
|
||||
pio.c pma.c rbt.c rex.c sio.c sll.c slmb.c stdio.c str-beg.c \
|
||||
str-cat.c str-chr.c str-cnv.c str-cmp.c str-cpy.c str-del.c \
|
||||
@ -475,6 +475,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipad.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lda.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mb8.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbwc-str.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbwc.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem.Plo@am__quote@
|
||||
|
38
qse/lib/cmn/mb8.c
Normal file
38
qse/lib/cmn/mb8.c
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright 2006-2012 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
|
||||
QSE is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
QSE is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <qse/cmn/mb8.h>
|
||||
|
||||
qse_size_t qse_wctomb8 (qse_wchar_t wc, qse_mchar_t* utf8, qse_size_t size)
|
||||
{
|
||||
if (size <= 0) return size + 1; /* buffer too small */
|
||||
if (wc > QSE_TYPE_MAX(qse_uint8_t)) return 0; /* illegal character */
|
||||
if (utf8) *(qse_uint8_t*)utf8 = wc;
|
||||
return 1;
|
||||
}
|
||||
|
||||
qse_size_t qse_mb8towc (
|
||||
const qse_mchar_t* utf8, qse_size_t size, qse_wchar_t* wc)
|
||||
{
|
||||
QSE_ASSERT (utf8 != QSE_NULL);
|
||||
QSE_ASSERT (size > 0);
|
||||
*wc = *(const qse_uint8_t*)utf8;
|
||||
return 1;
|
||||
}
|
@ -21,6 +21,7 @@
|
||||
#include <qse/cmn/mbwc.h>
|
||||
#include <qse/cmn/slmb.h>
|
||||
#include <qse/cmn/utf8.h>
|
||||
#include <qse/cmn/mb8.h>
|
||||
#include <qse/cmn/cp949.h>
|
||||
#include <qse/cmn/cp950.h>
|
||||
#include <qse/cmn/str.h>
|
||||
@ -30,31 +31,18 @@
|
||||
* dependent.
|
||||
*/
|
||||
|
||||
/* TODO: binary cmgr -> simply expands a byte to wchar and vice versa. */
|
||||
|
||||
static qse_cmgr_t builtin_cmgr[] =
|
||||
{
|
||||
{
|
||||
qse_slmbtoslwc,
|
||||
qse_slwctoslmb
|
||||
},
|
||||
|
||||
/* keep the order aligned with qse_cmgr_id_t values in <qse/cmn/mbwc.h> */
|
||||
{ qse_slmbtoslwc, qse_slwctoslmb },
|
||||
{ qse_utf8touc, qse_uctoutf8 },
|
||||
{ qse_mb8towc, qse_wctomb8 }
|
||||
#if defined(QSE_ENABLE_XCMGRS)
|
||||
{
|
||||
qse_cp949touc,
|
||||
qse_uctocp949
|
||||
},
|
||||
|
||||
{
|
||||
qse_cp950touc,
|
||||
qse_uctocp950
|
||||
},
|
||||
,
|
||||
{ qse_cp949touc, qse_uctocp949 },
|
||||
{ qse_cp950touc, qse_uctocp950 }
|
||||
#endif
|
||||
|
||||
{
|
||||
qse_utf8touc,
|
||||
qse_uctoutf8
|
||||
}
|
||||
};
|
||||
|
||||
static qse_cmgr_t* dfl_cmgr = &builtin_cmgr[QSE_CMGR_SLMB];
|
||||
@ -84,6 +72,8 @@ qse_cmgr_t* qse_findcmgrbyid (qse_cmgr_id_t id)
|
||||
|
||||
qse_cmgr_t* qse_findcmgr (const qse_char_t* name)
|
||||
{
|
||||
/* TODO: binary search or something better for performance improvement
|
||||
* when there are many entries in the table */
|
||||
static struct
|
||||
{
|
||||
const qse_char_t* name;
|
||||
@ -95,7 +85,8 @@ qse_cmgr_t* qse_findcmgr (const qse_char_t* name)
|
||||
{ QSE_T("cp949"), QSE_CMGR_CP949 },
|
||||
{ QSE_T("cp950"), QSE_CMGR_CP950 },
|
||||
#endif
|
||||
{ QSE_T("slmb"), QSE_CMGR_UTF8 }
|
||||
{ QSE_T("slmb"), QSE_CMGR_SLMB },
|
||||
{ QSE_T("mb8"), QSE_CMGR_MB8 }
|
||||
};
|
||||
|
||||
if (name)
|
||||
|
Reference in New Issue
Block a user