started writing qse_strfmt()/qse_strxfmt() and the famaily
This commit is contained in:
@ -11,9 +11,11 @@ noinst_HEADERS = \
|
||||
cp950.h \
|
||||
fmt.h \
|
||||
fmt-intmax.h \
|
||||
fmt-print.h \
|
||||
fmt-out.h \
|
||||
fs.h \
|
||||
mem.h \
|
||||
str-fcpy.h \
|
||||
str-fmt.h \
|
||||
str-join.h \
|
||||
str-subst.h \
|
||||
syscall.h \
|
||||
@ -40,7 +42,7 @@ libqsecmn_la_SOURCES = \
|
||||
fio.c \
|
||||
fma.c \
|
||||
fmt-intmax.c \
|
||||
fmt-print.c \
|
||||
fmt-out.c \
|
||||
fs.c \
|
||||
fs-err.c \
|
||||
fs-move.c \
|
||||
@ -84,6 +86,7 @@ libqsecmn_la_SOURCES = \
|
||||
str-end.c \
|
||||
str-excl.c \
|
||||
str-fcpy.c \
|
||||
str-fmt.c \
|
||||
str-fnmat.c \
|
||||
str-incl.c \
|
||||
str-join.c \
|
||||
|
@ -87,38 +87,38 @@ am__DEPENDENCIES_1 =
|
||||
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-intmax.c fmt-print.c fs.c fs-err.c fs-move.c glob.c \
|
||||
fma.c fmt-intmax.c fmt-out.c fs.c fs-err.c fs-move.c glob.c \
|
||||
hton.c ipad.c lda.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-join.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 \
|
||||
str-end.c str-excl.c str-fcpy.c str-fmt.c str-fnmat.c \
|
||||
str-incl.c str-join.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
|
||||
@ENABLE_XCMGRS_TRUE@am__objects_2 = cp949.lo cp950.lo
|
||||
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-intmax.lo fmt-print.lo fs.lo \
|
||||
fs-err.lo fs-move.lo glob.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 \
|
||||
htb.lo fio.lo fma.lo fmt-intmax.lo fmt-out.lo fs.lo fs-err.lo \
|
||||
fs-move.lo glob.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-join.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)
|
||||
str-dynw.lo str-end.lo str-excl.lo str-fcpy.lo str-fmt.lo \
|
||||
str-fnmat.lo str-incl.lo str-join.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)
|
||||
AM_V_lt = $(am__v_lt_@AM_V@)
|
||||
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
|
||||
@ -369,9 +369,11 @@ noinst_HEADERS = \
|
||||
cp950.h \
|
||||
fmt.h \
|
||||
fmt-intmax.h \
|
||||
fmt-print.h \
|
||||
fmt-out.h \
|
||||
fs.h \
|
||||
mem.h \
|
||||
str-fcpy.h \
|
||||
str-fmt.h \
|
||||
str-join.h \
|
||||
str-subst.h \
|
||||
syscall.h \
|
||||
@ -385,17 +387,17 @@ 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-intmax.c fmt-print.c fs.c fs-err.c fs-move.c glob.c hton.c \
|
||||
fmt-intmax.c fmt-out.c fs.c fs-err.c fs-move.c glob.c hton.c \
|
||||
ipad.c lda.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-join.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 \
|
||||
str-end.c str-excl.c str-fcpy.c str-fmt.c str-fnmat.c \
|
||||
str-incl.c str-join.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 $(am__append_1) $(am__append_2)
|
||||
libqsecmn_la_LDFLAGS = -version-info 1:0:0 -no-undefined
|
||||
@ -497,7 +499,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fma.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmt-intmax.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmt-print.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmt-out.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fs-err.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fs-move.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fs.Plo@am__quote@
|
||||
@ -543,6 +545,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str-end.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str-excl.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str-fcpy.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str-fmt.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str-fnmat.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str-incl.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str-join.Plo@am__quote@
|
||||
|
@ -24,6 +24,11 @@
|
||||
#include <qse/cmn/mbwc.h>
|
||||
#include <stdarg.h>
|
||||
#include "mem.h"
|
||||
#include "fmt.h"
|
||||
|
||||
#include <stdio.h> /* for snrintf() */
|
||||
/* TODO: remove stdio.h once snprintf gets replaced by own
|
||||
floting-point conversion implementation*/
|
||||
|
||||
/* number of bits in a byte */
|
||||
#define NBBY 8
|
||||
@ -106,44 +111,6 @@ static const qse_wchar_t* w_hex2ascii =
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
#include <stdio.h> /* TODO: remove dependency on this */
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
|
||||
# define snprintf _snprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static int put_wchar (qse_wchar_t c, void *arg)
|
||||
{
|
||||
qse_cmgr_t* cmgr;
|
||||
qse_mchar_t mbsbuf[QSE_MBLEN_MAX + 1];
|
||||
qse_size_t n;
|
||||
|
||||
cmgr = qse_getdflcmgr ();
|
||||
n = cmgr->wctomb (c, mbsbuf, QSE_COUNTOF(mbsbuf));
|
||||
if (n <= 0 || n > QSE_COUNTOF(mbsbuf))
|
||||
{
|
||||
return (putchar ('?') == EOF)? -1: 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_size_t i;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (putchar (mbsbuf[i]) == EOF) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int put_mchar (qse_mchar_t c, void *arg)
|
||||
{
|
||||
return (putchar (c) == EOF)? -1: 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
#undef char_t
|
||||
#undef uchar_t
|
||||
#undef ochar_t
|
||||
@ -152,7 +119,9 @@ static int put_mchar (qse_mchar_t c, void *arg)
|
||||
#undef toupper
|
||||
#undef hex2ascii
|
||||
#undef sprintn
|
||||
#undef xprintf
|
||||
#undef put_char
|
||||
#undef put_ochar
|
||||
#undef fmtout
|
||||
|
||||
#define char_t qse_mchar_t
|
||||
#define uchar_t qse_mchar_t
|
||||
@ -161,26 +130,13 @@ static int put_mchar (qse_mchar_t c, void *arg)
|
||||
#define OT(x) QSE_WT(x)
|
||||
#define toupper QSE_TOUPPER
|
||||
#define sprintn m_sprintn
|
||||
#define xprintf qse_mxprintf
|
||||
#define put_char put_mchar
|
||||
#define put_ochar put_wchar
|
||||
#define fmtout qse_mfmtout
|
||||
|
||||
#define hex2ascii(hex) (m_hex2ascii[hex])
|
||||
|
||||
#include "fmt-print.h"
|
||||
|
||||
qse_ssize_t qse_mprintf (const char_t *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
qse_ssize_t n;
|
||||
va_start (ap, fmt);
|
||||
n = qse_mxprintf (fmt, put_mchar, put_wchar, QSE_NULL, ap);
|
||||
va_end (ap);
|
||||
return n;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_mvprintf (const char_t* fmt, va_list ap)
|
||||
{
|
||||
return qse_mxprintf (fmt, put_mchar, put_wchar, QSE_NULL, ap);
|
||||
}
|
||||
#include "fmt-out.h"
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
@ -192,7 +148,9 @@ qse_ssize_t qse_mvprintf (const char_t* fmt, va_list ap)
|
||||
#undef toupper
|
||||
#undef hex2ascii
|
||||
#undef sprintn
|
||||
#undef xprintf
|
||||
#undef put_char
|
||||
#undef put_ochar
|
||||
#undef fmtout
|
||||
|
||||
#define char_t qse_wchar_t
|
||||
#define uchar_t qse_wchar_t
|
||||
@ -201,23 +159,11 @@ qse_ssize_t qse_mvprintf (const char_t* fmt, va_list ap)
|
||||
#define OT(x) QSE_MT(x)
|
||||
#define toupper QSE_TOWUPPER
|
||||
#define sprintn w_sprintn
|
||||
#define xprintf qse_wxprintf
|
||||
#define put_char put_wchar
|
||||
#define put_ochar put_mchar
|
||||
#define fmtout qse_wfmtout
|
||||
|
||||
#define hex2ascii(hex) (w_hex2ascii[hex])
|
||||
|
||||
#include "fmt-print.h"
|
||||
#include "fmt-out.h"
|
||||
|
||||
qse_ssize_t qse_wprintf (const char_t *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
qse_ssize_t n;
|
||||
va_start (ap, fmt);
|
||||
n = qse_wxprintf (fmt, put_wchar, put_mchar, QSE_NULL, ap);
|
||||
va_end (ap);
|
||||
return n;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_wvprintf (const char_t* fmt, va_list ap)
|
||||
{
|
||||
return qse_wxprintf (fmt, put_wchar, put_mchar, QSE_NULL, ap);
|
||||
}
|
@ -84,18 +84,17 @@ static char_t* sprintn (char_t* nbuf, qse_uintmax_t num, int base, int *lenp, in
|
||||
#undef PUT_CHAR
|
||||
#undef PUT_OCHAR
|
||||
|
||||
/* TODO: error check */
|
||||
#define PUT_CHAR(c) do { \
|
||||
if (put_char (c, arg) <= -1) goto oops; \
|
||||
outcnt++; \
|
||||
if (data->put_char (c, data->ctx) <= -1) goto oops; \
|
||||
data->count++; \
|
||||
} while (0)
|
||||
|
||||
#define PUT_OCHAR(c) do { \
|
||||
if (put_ochar (c, arg) <= -1) goto oops; \
|
||||
outcnt++; \
|
||||
if (data->put_ochar (c, data->ctx) <= -1) goto oops; \
|
||||
data->count++; \
|
||||
} while (0)
|
||||
|
||||
qse_ssize_t xprintf (const char_t* fmt, int (*put_char)(char_t, void*), int (*put_ochar) (ochar_t, void*), void *arg, va_list ap)
|
||||
int fmtout (const char_t* fmt, qse_fmtout_t* data, va_list ap)
|
||||
{
|
||||
char_t nbuf[MAXNBUF];
|
||||
const char_t* p, * percent;
|
||||
@ -106,7 +105,8 @@ qse_ssize_t xprintf (const char_t* fmt, int (*put_char)(char_t, void*), int (*pu
|
||||
int lm_flag, lm_dflag, flagc, numlen;
|
||||
qse_uintmax_t num = 0;
|
||||
int stop = 0;
|
||||
qse_ssize_t outcnt = 0;
|
||||
|
||||
data->count = 0;
|
||||
|
||||
struct
|
||||
{
|
||||
@ -133,7 +133,7 @@ qse_ssize_t xprintf (const char_t* fmt, int (*put_char)(char_t, void*), int (*pu
|
||||
while ((ch = (uchar_t)*fmt++) != T('%') || stop)
|
||||
{
|
||||
if (ch == T('\0')) goto done;
|
||||
PUT_CHAR(ch);
|
||||
PUT_CHAR (ch);
|
||||
}
|
||||
percent = fmt - 1;
|
||||
|
||||
@ -308,21 +308,21 @@ reswitch:
|
||||
|
||||
case T('n'):
|
||||
if (lm_flag & LF_J) /* j */
|
||||
*(va_arg(ap, qse_intmax_t*)) = outcnt;
|
||||
*(va_arg(ap, qse_intmax_t*)) = data->count;
|
||||
else if (lm_flag & LF_Z) /* z */
|
||||
*(va_arg(ap, qse_size_t*)) = outcnt;
|
||||
*(va_arg(ap, qse_size_t*)) = data->count;
|
||||
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||
else if (lm_flag & LF_Q) /* ll */
|
||||
*(va_arg(ap, long long int*)) = outcnt;
|
||||
*(va_arg(ap, long long int*)) = data->count;
|
||||
#endif
|
||||
else if (lm_flag & LF_L) /* l */
|
||||
*(va_arg(ap, long int*)) = outcnt;
|
||||
*(va_arg(ap, long int*)) = data->count;
|
||||
else if (lm_flag & LF_H) /* h */
|
||||
*(va_arg(ap, short int*)) = outcnt;
|
||||
*(va_arg(ap, short int*)) = data->count;
|
||||
else if (lm_flag & LF_C) /* hh */
|
||||
*(va_arg(ap, char*)) = outcnt;
|
||||
*(va_arg(ap, char*)) = data->count;
|
||||
else
|
||||
*(va_arg(ap, int*)) = outcnt;
|
||||
*(va_arg(ap, int*)) = data->count;
|
||||
break;
|
||||
|
||||
|
||||
@ -733,7 +733,7 @@ done:
|
||||
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), fltfmt.ptr);
|
||||
if (fltout.ptr != fltout.sbuf)
|
||||
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), fltout.ptr);
|
||||
return outcnt;
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
if (fltfmt.ptr != fltfmt.sbuf)
|
@ -24,36 +24,49 @@
|
||||
#include <qse/cmn/fmt.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
typedef int (*qse_printf_mchar_t) (
|
||||
typedef int (*qse_fmtout_mchar_t) (
|
||||
qse_mchar_t c,
|
||||
void* ctx
|
||||
);
|
||||
|
||||
typedef int (*qse_printf_wchar_t) (
|
||||
qse_mchar_t c,
|
||||
typedef int (*qse_fmtout_wchar_t) (
|
||||
qse_wchar_t c,
|
||||
void* ctx
|
||||
);
|
||||
|
||||
struct qse_fmtout_t
|
||||
{
|
||||
qse_size_t count; /* out */
|
||||
qse_size_t limit; /* in */
|
||||
void* ctx; /* in */
|
||||
qse_fmtout_mchar_t put_mchar; /* in */
|
||||
qse_fmtout_wchar_t put_wchar; /* in */
|
||||
};
|
||||
|
||||
typedef struct qse_fmtout_t qse_fmtout_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
qse_ssize_t qse_mxprintf (
|
||||
int qse_mfmtout (
|
||||
const qse_mchar_t* fmt,
|
||||
qse_printf_mchar_t put_mchar,
|
||||
qse_printf_wchar_t put_wchar,
|
||||
void* arg,
|
||||
qse_fmtout_t* data,
|
||||
va_list ap
|
||||
);
|
||||
|
||||
qse_ssize_t qse_wxprintf (
|
||||
int qse_wfmtout (
|
||||
const qse_wchar_t* fmt,
|
||||
qse_printf_wchar_t put_wchar,
|
||||
qse_printf_mchar_t put_mchar,
|
||||
void* arg,
|
||||
qse_fmtout_t* data,
|
||||
va_list ap
|
||||
);
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define qse_fmtout(fmt,fo,ap) qse_mfmtout(fmt,fo,ap)
|
||||
#else
|
||||
# define qse_fmtout(fmt,fo,ap) qse_wfmtout(fmt,fo,ap)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -636,12 +636,12 @@ qse_ssize_t qse_sio_putwcsn (
|
||||
return n;
|
||||
}
|
||||
|
||||
static int put_wchar (qse_wchar_t c, void *arg)
|
||||
static int put_wchar (qse_wchar_t c, void* arg)
|
||||
{
|
||||
return qse_sio_putwc ((qse_sio_t*)arg, c);
|
||||
}
|
||||
|
||||
static int put_mchar (qse_mchar_t c, void *arg)
|
||||
static int put_mchar (qse_mchar_t c, void* arg)
|
||||
{
|
||||
return qse_sio_putmb ((qse_sio_t*)arg, c);
|
||||
}
|
||||
@ -650,59 +650,90 @@ qse_ssize_t qse_sio_putmbsf (qse_sio_t* sio, const qse_mchar_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
qse_ssize_t x;
|
||||
qse_fmtout_t fo;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_ssize_t);
|
||||
fo.ctx = sio;
|
||||
fo.put_mchar = put_mchar;
|
||||
fo.put_wchar = put_wchar;
|
||||
|
||||
va_start (ap, fmt);
|
||||
x = qse_mxprintf (fmt, put_mchar, put_wchar, sio, ap);
|
||||
x = qse_mfmtout (fmt, &fo, ap);
|
||||
va_end (ap);
|
||||
|
||||
return x;
|
||||
return (x <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_putwcsf (qse_sio_t* sio, const qse_wchar_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
qse_ssize_t x;
|
||||
int x;
|
||||
qse_fmtout_t fo;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_ssize_t);
|
||||
fo.ctx = sio;
|
||||
fo.put_mchar = put_mchar;
|
||||
fo.put_wchar = put_wchar;
|
||||
|
||||
va_start (ap, fmt);
|
||||
x = qse_wxprintf (fmt, put_wchar, put_mchar, sio, ap);
|
||||
x = qse_wfmtout (fmt, &fo, ap);
|
||||
va_end (ap);
|
||||
|
||||
return x;
|
||||
return (x <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_putstrf (qse_sio_t* sio, const qse_char_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
qse_ssize_t x;
|
||||
int x;
|
||||
qse_fmtout_t fo;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_ssize_t);
|
||||
fo.ctx = sio;
|
||||
fo.put_mchar = put_mchar;
|
||||
fo.put_wchar = put_wchar;
|
||||
|
||||
va_start (ap, fmt);
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
x = qse_mxprintf (fmt, put_mchar, put_wchar, sio, ap);
|
||||
#else
|
||||
x = qse_wxprintf (fmt, put_wchar, put_mchar, sio, ap);
|
||||
#endif
|
||||
x = qse_fmtout (fmt, &fo, ap);
|
||||
va_end (ap);
|
||||
|
||||
return x;
|
||||
return (x <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_putmbsvf (qse_sio_t* sio, const qse_mchar_t* fmt, va_list ap)
|
||||
{
|
||||
return qse_mxprintf (fmt, put_mchar, put_wchar, sio, ap);
|
||||
qse_fmtout_t fo;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_ssize_t);
|
||||
fo.ctx = sio;
|
||||
fo.put_mchar = put_mchar;
|
||||
fo.put_wchar = put_wchar;
|
||||
|
||||
return (qse_mfmtout (fmt, &fo, ap) <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_putwcsvf (qse_sio_t* sio, const qse_wchar_t* fmt, va_list ap)
|
||||
{
|
||||
return qse_wxprintf (fmt, put_wchar, put_mchar, sio, ap);
|
||||
qse_fmtout_t fo;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_ssize_t);
|
||||
fo.ctx = sio;
|
||||
fo.put_mchar = put_mchar;
|
||||
fo.put_wchar = put_wchar;
|
||||
|
||||
return (qse_wfmtout (fmt, &fo, ap) <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_sio_putstrvf (qse_sio_t* sio, const qse_char_t* fmt, va_list ap)
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
return qse_mxprintf (fmt, put_mchar, put_wchar, sio, ap);
|
||||
#else
|
||||
return qse_wxprintf (fmt, put_wchar, put_mchar, sio, ap);
|
||||
#endif
|
||||
qse_fmtout_t fo;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_ssize_t);
|
||||
fo.ctx = sio;
|
||||
fo.put_mchar = put_mchar;
|
||||
fo.put_wchar = put_wchar;
|
||||
|
||||
return (qse_fmtout (fmt, &fo, ap) <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
int qse_sio_getpos (qse_sio_t* sio, qse_sio_pos_t* pos)
|
||||
@ -843,58 +874,89 @@ qse_sio_t* qse_getstderr (void)
|
||||
qse_ssize_t qse_putmbsf (const qse_mchar_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
qse_ssize_t x;
|
||||
int x;
|
||||
qse_fmtout_t fo;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_ssize_t);
|
||||
fo.ctx = sio_stdout;
|
||||
fo.put_mchar = put_mchar;
|
||||
fo.put_wchar = put_wchar;
|
||||
|
||||
va_start (ap, fmt);
|
||||
x = qse_mxprintf (fmt, put_mchar, put_wchar, sio_stdout, ap);
|
||||
x = qse_mfmtout (fmt, &fo, ap);
|
||||
va_end (ap);
|
||||
|
||||
return x;
|
||||
return (x <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_putwcsf (const qse_wchar_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
qse_ssize_t x;
|
||||
int x;
|
||||
qse_fmtout_t fo;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_ssize_t);
|
||||
fo.ctx = sio_stdout;
|
||||
fo.put_mchar = put_mchar;
|
||||
fo.put_wchar = put_wchar;
|
||||
|
||||
va_start (ap, fmt);
|
||||
x = qse_wxprintf (fmt, put_wchar, put_mchar, sio_stdout, ap);
|
||||
x = qse_wfmtout (fmt, &fo, ap);
|
||||
va_end (ap);
|
||||
|
||||
return x;
|
||||
return (x <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_putstrf (const qse_char_t* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
qse_ssize_t x;
|
||||
int x;
|
||||
qse_fmtout_t fo;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_ssize_t);
|
||||
fo.ctx = sio_stdout;
|
||||
fo.put_mchar = put_mchar;
|
||||
fo.put_wchar = put_wchar;
|
||||
|
||||
va_start (ap, fmt);
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
x = qse_mxprintf (fmt, put_mchar, put_wchar, sio_stdout, ap);
|
||||
#else
|
||||
x = qse_wxprintf (fmt, put_wchar, put_mchar, sio_stdout, ap);
|
||||
#endif
|
||||
x = qse_fmtout (fmt, &fo, ap);
|
||||
va_end (ap);
|
||||
|
||||
return x;
|
||||
return (x <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_putmbsvf (const qse_mchar_t* fmt, va_list ap)
|
||||
{
|
||||
return qse_mxprintf (fmt, put_mchar, put_wchar, sio_stdout, ap);
|
||||
qse_fmtout_t fo;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_ssize_t);
|
||||
fo.ctx = sio_stdout;
|
||||
fo.put_mchar = put_mchar;
|
||||
fo.put_wchar = put_wchar;
|
||||
|
||||
return (qse_mfmtout (fmt, &fo, ap) <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_putwcsvf (const qse_wchar_t* fmt, va_list ap)
|
||||
{
|
||||
return qse_wxprintf (fmt, put_wchar, put_mchar, sio_stdout, ap);
|
||||
qse_fmtout_t fo;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_ssize_t);
|
||||
fo.ctx = sio_stdout;
|
||||
fo.put_mchar = put_mchar;
|
||||
fo.put_wchar = put_wchar;
|
||||
|
||||
return (qse_wfmtout (fmt, &fo, ap) <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
qse_ssize_t qse_putstrvf (const qse_char_t* fmt, va_list ap)
|
||||
{
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
return qse_mxprintf (fmt, put_mchar, put_wchar, sio_stdout, ap);
|
||||
#else
|
||||
return qse_wxprintf (fmt, put_wchar, put_mchar, sio_stdout, ap);
|
||||
#endif
|
||||
qse_fmtout_t fo;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_ssize_t);
|
||||
fo.ctx = sio_stdout;
|
||||
fo.put_mchar = put_mchar;
|
||||
fo.put_wchar = put_wchar;
|
||||
|
||||
return (qse_fmtout (fmt, &fo, ap) <= -1)? -1: fo.count;
|
||||
}
|
||||
|
@ -20,452 +20,39 @@
|
||||
|
||||
#include <qse/cmn/str.h>
|
||||
|
||||
qse_size_t qse_mbsfcpy (
|
||||
qse_mchar_t* buf, const qse_mchar_t* fmt, const qse_mchar_t* str[])
|
||||
{
|
||||
qse_mchar_t* b = buf;
|
||||
const qse_mchar_t* f = fmt;
|
||||
#undef T
|
||||
#undef char_t
|
||||
#undef cstr_t
|
||||
#undef strfcpy
|
||||
#undef strfncpy
|
||||
#undef strxfcpy
|
||||
#undef strxfncpy
|
||||
|
||||
#define T(x) QSE_MT(x)
|
||||
#define char_t qse_mchar_t
|
||||
#define cstr_t qse_mcstr_t
|
||||
#define strfcpy qse_mbsfcpy
|
||||
#define strfncpy qse_mbsfncpy
|
||||
#define strxfcpy qse_mbsxfcpy
|
||||
#define strxfncpy qse_mbsxfncpy
|
||||
#include "str-fcpy.h"
|
||||
|
||||
/* ----------------------------------- */
|
||||
|
||||
#undef T
|
||||
#undef char_t
|
||||
#undef cstr_t
|
||||
#undef strfcpy
|
||||
#undef strfncpy
|
||||
#undef strxfcpy
|
||||
#undef strxfncpy
|
||||
|
||||
#define T(x) QSE_WT(x)
|
||||
#define char_t qse_wchar_t
|
||||
#define cstr_t qse_wcstr_t
|
||||
#define strfcpy qse_wcsfcpy
|
||||
#define strfncpy qse_wcsfncpy
|
||||
#define strxfcpy qse_wcsxfcpy
|
||||
#define strxfncpy qse_wcsxfncpy
|
||||
#include "str-fcpy.h"
|
||||
|
||||
while (*f != QSE_MT('\0'))
|
||||
{
|
||||
if (*f == QSE_MT('$'))
|
||||
{
|
||||
if (f[1] == QSE_MT('{') &&
|
||||
(f[2] >= QSE_MT('0') && f[2] <= QSE_MT('9')))
|
||||
{
|
||||
const qse_mchar_t* tmp;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_MT('0'));
|
||||
while (*f >= QSE_MT('0') && *f <= QSE_MT('9'));
|
||||
|
||||
if (*f != QSE_MT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx];
|
||||
while (*tmp != QSE_MT('\0')) *b++ = *tmp++;
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_MT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
*b = QSE_MT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_mbsfncpy (
|
||||
qse_mchar_t* buf, const qse_mchar_t* fmt, const qse_mcstr_t str[])
|
||||
{
|
||||
qse_mchar_t* b = buf;
|
||||
const qse_mchar_t* f = fmt;
|
||||
|
||||
while (*f != QSE_MT('\0'))
|
||||
{
|
||||
if (*f == QSE_MT('\\'))
|
||||
{
|
||||
/* get the escaped character and treat it normally.
|
||||
* if the escaper is the last character, treat it
|
||||
* normally also. */
|
||||
if (f[1] != QSE_MT('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_MT('$'))
|
||||
{
|
||||
if (f[1] == QSE_MT('{') &&
|
||||
(f[2] >= QSE_MT('0') && f[2] <= QSE_MT('9')))
|
||||
{
|
||||
const qse_mchar_t* tmp, * tmpend;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_MT('0'));
|
||||
while (*f >= QSE_MT('0') && *f <= QSE_MT('9'));
|
||||
|
||||
if (*f != QSE_MT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx].ptr;
|
||||
tmpend = tmp + str[idx].len;
|
||||
|
||||
while (tmp < tmpend) *b++ = *tmp++;
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_MT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
*b = QSE_MT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_mbsxfcpy (
|
||||
qse_mchar_t* buf, qse_size_t bsz,
|
||||
const qse_mchar_t* fmt, const qse_mchar_t* str[])
|
||||
{
|
||||
qse_mchar_t* b = buf;
|
||||
qse_mchar_t* end = buf + bsz - 1;
|
||||
const qse_mchar_t* f = fmt;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
|
||||
while (*f != QSE_MT('\0'))
|
||||
{
|
||||
if (*f == QSE_MT('\\'))
|
||||
{
|
||||
/* get the escaped character and treat it normally.
|
||||
* if the escaper is the last character, treat it
|
||||
* normally also. */
|
||||
if (f[1] != QSE_MT('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_MT('$'))
|
||||
{
|
||||
if (f[1] == QSE_MT('{') &&
|
||||
(f[2] >= QSE_MT('0') && f[2] <= QSE_MT('9')))
|
||||
{
|
||||
const qse_mchar_t* tmp;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_MT('0'));
|
||||
while (*f >= QSE_MT('0') && *f <= QSE_MT('9'));
|
||||
|
||||
if (*f != QSE_MT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx];
|
||||
while (*tmp != QSE_MT('\0'))
|
||||
{
|
||||
if (b >= end) goto fini;
|
||||
*b++ = *tmp++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_MT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = QSE_MT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_mbsxfncpy (
|
||||
qse_mchar_t* buf, qse_size_t bsz,
|
||||
const qse_mchar_t* fmt, const qse_mcstr_t str[])
|
||||
{
|
||||
qse_mchar_t* b = buf;
|
||||
qse_mchar_t* end = buf + bsz - 1;
|
||||
const qse_mchar_t* f = fmt;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
|
||||
while (*f != QSE_MT('\0'))
|
||||
{
|
||||
if (*f == QSE_MT('\\'))
|
||||
{
|
||||
/* get the escaped character and treat it normally.
|
||||
* if the escaper is the last character, treat it
|
||||
* normally also. */
|
||||
if (f[1] != QSE_MT('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_MT('$'))
|
||||
{
|
||||
if (f[1] == QSE_MT('{') &&
|
||||
(f[2] >= QSE_MT('0') && f[2] <= QSE_MT('9')))
|
||||
{
|
||||
const qse_mchar_t* tmp, * tmpend;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_MT('0'));
|
||||
while (*f >= QSE_MT('0') && *f <= QSE_MT('9'));
|
||||
|
||||
if (*f != QSE_MT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx].ptr;
|
||||
tmpend = tmp + str[idx].len;
|
||||
|
||||
while (tmp < tmpend)
|
||||
{
|
||||
if (b >= end) goto fini;
|
||||
*b++ = *tmp++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_MT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = QSE_MT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsfcpy (
|
||||
qse_wchar_t* buf, const qse_wchar_t* fmt, const qse_wchar_t* str[])
|
||||
{
|
||||
qse_wchar_t* b = buf;
|
||||
const qse_wchar_t* f = fmt;
|
||||
|
||||
while (*f != QSE_WT('\0'))
|
||||
{
|
||||
if (*f == QSE_WT('$'))
|
||||
{
|
||||
if (f[1] == QSE_WT('{') &&
|
||||
(f[2] >= QSE_WT('0') && f[2] <= QSE_WT('9')))
|
||||
{
|
||||
const qse_wchar_t* tmp;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_WT('0'));
|
||||
while (*f >= QSE_WT('0') && *f <= QSE_WT('9'));
|
||||
|
||||
if (*f != QSE_WT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx];
|
||||
while (*tmp != QSE_WT('\0')) *b++ = *tmp++;
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_WT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
*b = QSE_WT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsfncpy (
|
||||
qse_wchar_t* buf, const qse_wchar_t* fmt, const qse_wcstr_t str[])
|
||||
{
|
||||
qse_wchar_t* b = buf;
|
||||
const qse_wchar_t* f = fmt;
|
||||
|
||||
while (*f != QSE_WT('\0'))
|
||||
{
|
||||
if (*f == QSE_WT('\\'))
|
||||
{
|
||||
/* get the escaped character and treat it normally.
|
||||
* if the escaper is the last character, treat it
|
||||
* normally also. */
|
||||
if (f[1] != QSE_WT('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_WT('$'))
|
||||
{
|
||||
if (f[1] == QSE_WT('{') &&
|
||||
(f[2] >= QSE_WT('0') && f[2] <= QSE_WT('9')))
|
||||
{
|
||||
const qse_wchar_t* tmp, * tmpend;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_WT('0'));
|
||||
while (*f >= QSE_WT('0') && *f <= QSE_WT('9'));
|
||||
|
||||
if (*f != QSE_WT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx].ptr;
|
||||
tmpend = tmp + str[idx].len;
|
||||
|
||||
while (tmp < tmpend) *b++ = *tmp++;
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_WT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
*b = QSE_WT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsxfcpy (
|
||||
qse_wchar_t* buf, qse_size_t bsz,
|
||||
const qse_wchar_t* fmt, const qse_wchar_t* str[])
|
||||
{
|
||||
qse_wchar_t* b = buf;
|
||||
qse_wchar_t* end = buf + bsz - 1;
|
||||
const qse_wchar_t* f = fmt;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
|
||||
while (*f != QSE_WT('\0'))
|
||||
{
|
||||
if (*f == QSE_WT('\\'))
|
||||
{
|
||||
/* get the escaped character and treat it normally.
|
||||
* if the escaper is the last character, treat it
|
||||
* normally also. */
|
||||
if (f[1] != QSE_WT('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_WT('$'))
|
||||
{
|
||||
if (f[1] == QSE_WT('{') &&
|
||||
(f[2] >= QSE_WT('0') && f[2] <= QSE_WT('9')))
|
||||
{
|
||||
const qse_wchar_t* tmp;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_WT('0'));
|
||||
while (*f >= QSE_WT('0') && *f <= QSE_WT('9'));
|
||||
|
||||
if (*f != QSE_WT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx];
|
||||
while (*tmp != QSE_WT('\0'))
|
||||
{
|
||||
if (b >= end) goto fini;
|
||||
*b++ = *tmp++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_WT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = QSE_WT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t qse_wcsxfncpy (
|
||||
qse_wchar_t* buf, qse_size_t bsz,
|
||||
const qse_wchar_t* fmt, const qse_wcstr_t str[])
|
||||
{
|
||||
qse_wchar_t* b = buf;
|
||||
qse_wchar_t* end = buf + bsz - 1;
|
||||
const qse_wchar_t* f = fmt;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
|
||||
while (*f != QSE_WT('\0'))
|
||||
{
|
||||
if (*f == QSE_WT('\\'))
|
||||
{
|
||||
/* get the escaped character and treat it normally.
|
||||
* if the escaper is the last character, treat it
|
||||
* normally also. */
|
||||
if (f[1] != QSE_WT('\0')) f++;
|
||||
}
|
||||
else if (*f == QSE_WT('$'))
|
||||
{
|
||||
if (f[1] == QSE_WT('{') &&
|
||||
(f[2] >= QSE_WT('0') && f[2] <= QSE_WT('9')))
|
||||
{
|
||||
const qse_wchar_t* tmp, * tmpend;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - QSE_WT('0'));
|
||||
while (*f >= QSE_WT('0') && *f <= QSE_WT('9'));
|
||||
|
||||
if (*f != QSE_WT('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx].ptr;
|
||||
tmpend = tmp + str[idx].len;
|
||||
|
||||
while (tmp < tmpend)
|
||||
{
|
||||
if (b >= end) goto fini;
|
||||
*b++ = *tmp++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == QSE_WT('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = QSE_WT('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
244
qse/lib/cmn/str-fcpy.h
Normal file
244
qse/lib/cmn/str-fcpy.h
Normal file
@ -0,0 +1,244 @@
|
||||
/*
|
||||
* $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/>.
|
||||
*/
|
||||
|
||||
qse_size_t strfcpy (
|
||||
char_t* buf, const char_t* fmt, const char_t* str[])
|
||||
{
|
||||
char_t* b = buf;
|
||||
const char_t* f = fmt;
|
||||
|
||||
while (*f != T('\0'))
|
||||
{
|
||||
if (*f == T('$'))
|
||||
{
|
||||
if (f[1] == T('{') &&
|
||||
(f[2] >= T('0') && f[2] <= T('9')))
|
||||
{
|
||||
const char_t* tmp;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - T('0'));
|
||||
while (*f >= T('0') && *f <= T('9'));
|
||||
|
||||
if (*f != T('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx];
|
||||
while (*tmp != T('\0')) *b++ = *tmp++;
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == T('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
*b = T('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t strfncpy (
|
||||
char_t* buf, const char_t* fmt, const cstr_t str[])
|
||||
{
|
||||
char_t* b = buf;
|
||||
const char_t* f = fmt;
|
||||
|
||||
while (*f != T('\0'))
|
||||
{
|
||||
if (*f == T('\\'))
|
||||
{
|
||||
/* get the escaped character and treat it normally.
|
||||
* if the escaper is the last character, treat it
|
||||
* normally also. */
|
||||
if (f[1] != T('\0')) f++;
|
||||
}
|
||||
else if (*f == T('$'))
|
||||
{
|
||||
if (f[1] == T('{') &&
|
||||
(f[2] >= T('0') && f[2] <= T('9')))
|
||||
{
|
||||
const char_t* tmp, * tmpend;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - T('0'));
|
||||
while (*f >= T('0') && *f <= T('9'));
|
||||
|
||||
if (*f != T('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx].ptr;
|
||||
tmpend = tmp + str[idx].len;
|
||||
|
||||
while (tmp < tmpend) *b++ = *tmp++;
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == T('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
*b = T('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t strxfcpy (
|
||||
char_t* buf, qse_size_t bsz,
|
||||
const char_t* fmt, const char_t* str[])
|
||||
{
|
||||
char_t* b = buf;
|
||||
char_t* end = buf + bsz - 1;
|
||||
const char_t* f = fmt;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
|
||||
while (*f != T('\0'))
|
||||
{
|
||||
if (*f == T('\\'))
|
||||
{
|
||||
/* get the escaped character and treat it normally.
|
||||
* if the escaper is the last character, treat it
|
||||
* normally also. */
|
||||
if (f[1] != T('\0')) f++;
|
||||
}
|
||||
else if (*f == T('$'))
|
||||
{
|
||||
if (f[1] == T('{') &&
|
||||
(f[2] >= T('0') && f[2] <= T('9')))
|
||||
{
|
||||
const char_t* tmp;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - T('0'));
|
||||
while (*f >= T('0') && *f <= T('9'));
|
||||
|
||||
if (*f != T('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx];
|
||||
while (*tmp != T('\0'))
|
||||
{
|
||||
if (b >= end) goto fini;
|
||||
*b++ = *tmp++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == T('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = T('\0');
|
||||
return b - buf;
|
||||
}
|
||||
|
||||
qse_size_t strxfncpy (
|
||||
char_t* buf, qse_size_t bsz,
|
||||
const char_t* fmt, const cstr_t str[])
|
||||
{
|
||||
char_t* b = buf;
|
||||
char_t* end = buf + bsz - 1;
|
||||
const char_t* f = fmt;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
|
||||
while (*f != T('\0'))
|
||||
{
|
||||
if (*f == T('\\'))
|
||||
{
|
||||
/* get the escaped character and treat it normally.
|
||||
* if the escaper is the last character, treat it
|
||||
* normally also. */
|
||||
if (f[1] != T('\0')) f++;
|
||||
}
|
||||
else if (*f == T('$'))
|
||||
{
|
||||
if (f[1] == T('{') &&
|
||||
(f[2] >= T('0') && f[2] <= T('9')))
|
||||
{
|
||||
const char_t* tmp, * tmpend;
|
||||
qse_size_t idx = 0;
|
||||
|
||||
tmp = f;
|
||||
f += 2;
|
||||
|
||||
do idx = idx * 10 + (*f++ - T('0'));
|
||||
while (*f >= T('0') && *f <= T('9'));
|
||||
|
||||
if (*f != T('}'))
|
||||
{
|
||||
f = tmp;
|
||||
goto normal;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
tmp = str[idx].ptr;
|
||||
tmpend = tmp + str[idx].len;
|
||||
|
||||
while (tmp < tmpend)
|
||||
{
|
||||
if (b >= end) goto fini;
|
||||
*b++ = *tmp++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (f[1] == T('$')) f++;
|
||||
}
|
||||
|
||||
normal:
|
||||
if (b >= end) break;
|
||||
*b++ = *f++;
|
||||
}
|
||||
|
||||
fini:
|
||||
*b = T('\0');
|
||||
return b - buf;
|
||||
}
|
136
qse/lib/cmn/str-fmt.c
Normal file
136
qse/lib/cmn/str-fmt.c
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* $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/str.h>
|
||||
#include "fmt.h"
|
||||
|
||||
struct wbuf_t
|
||||
{
|
||||
qse_wchar_t* ptr;
|
||||
qse_size_t len;
|
||||
qse_size_t capa;
|
||||
};
|
||||
|
||||
struct mbuf_t
|
||||
{
|
||||
qse_mchar_t* ptr;
|
||||
qse_size_t len;
|
||||
qse_size_t capa;
|
||||
};
|
||||
|
||||
typedef struct wbuf_t wbuf_t;
|
||||
typedef struct mbuf_t mbuf_t;
|
||||
|
||||
static int put_wchar_to_wbuf (qse_wchar_t c, void* arg)
|
||||
{
|
||||
qse_fmtout_t* fo = (qse_fmtout_t*)arg;
|
||||
wbuf_t* buf = (wbuf_t*)fo->ctx;
|
||||
if (buf->len < buf->capa) buf->ptr[buf->len++] = c;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int put_mchar_to_mbuf (qse_mchar_t c, void* arg)
|
||||
{
|
||||
qse_fmtout_t* fo = (qse_fmtout_t*)arg;
|
||||
mbuf_t* buf = (mbuf_t*)fo->ctx;
|
||||
if (buf->len < buf->capa) buf->ptr[buf->len++] = c;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int put_wchar_to_mbuf (qse_wchar_t c, void* arg)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int put_mchar_to_wbuf (qse_mchar_t c, void* arg)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ----------------------------------- */
|
||||
|
||||
#undef T
|
||||
#undef char_t
|
||||
#undef buf_t
|
||||
#undef fmtout
|
||||
#undef output_char
|
||||
#undef output_ochar
|
||||
#undef strfmt
|
||||
#undef strxfmt
|
||||
|
||||
#define T(x) QSE_MT(x)
|
||||
#define char_t qse_mchar_t
|
||||
#define buf_t mbuf_t
|
||||
#define fmtout qse_mfmtout
|
||||
#define output_mchar put_mchar_to_mbuf
|
||||
#define output_wchar put_wchar_to_mbuf
|
||||
#define strfmt qse_mbsfmt
|
||||
#define strxfmt qse_mbsxfmt
|
||||
#include "str-fmt.h"
|
||||
|
||||
/* ----------------------------------- */
|
||||
|
||||
#undef T
|
||||
#undef char_t
|
||||
#undef buf_t
|
||||
#undef fmtout
|
||||
#undef output_mchar
|
||||
#undef output_wchar
|
||||
#undef strfmt
|
||||
#undef strxfmt
|
||||
|
||||
#define T(x) QSE_WT(x)
|
||||
#define char_t qse_wchar_t
|
||||
#define buf_t wbuf_t
|
||||
#define fmtout qse_wfmtout
|
||||
#define output_mchar put_mchar_to_wbuf
|
||||
#define output_wchar put_wchar_to_wbuf
|
||||
#define strfmtx qse_wcsfmt
|
||||
#define strxfmtx qse_wcsxfmt
|
||||
#include "str-fmt.h"
|
||||
|
||||
|
||||
/* ----------------------------------- */
|
||||
|
||||
#undef T
|
||||
#undef char_t
|
||||
#undef buf_t
|
||||
#undef fmtout
|
||||
#undef output_mchar
|
||||
#undef output_wchar
|
||||
#undef strfmt
|
||||
#undef strxfmt
|
||||
|
||||
#define T(x) QSE_T(x)
|
||||
#define char_t qse_char_t
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
# define buf_t mbuf_t
|
||||
# define output_mchar put_mchar_to_mbuf
|
||||
# define output_wchar put_wchar_to_mbuf
|
||||
# define fmtout qse_mfmtout
|
||||
#else
|
||||
# define buf_t wbuf_t
|
||||
# define output_mchar put_mchar_to_wbuf
|
||||
# define output_wchar put_wchar_to_wbuf
|
||||
# define fmtout qse_wfmtout
|
||||
#endif
|
||||
#define strfmt qse_strfmt
|
||||
#define strxfmt qse_strxfmt
|
||||
#include "str-fmt.h"
|
79
qse/lib/cmn/str-fmt.h
Normal file
79
qse/lib/cmn/str-fmt.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* $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/>.
|
||||
*/
|
||||
|
||||
|
||||
qse_size_t strfmt (char_t* buf, const char_t* fmt, ...)
|
||||
{
|
||||
buf_t b;
|
||||
va_list ap;
|
||||
qse_fmtout_t fo;
|
||||
|
||||
b.ptr = buf;
|
||||
b.len = 0;
|
||||
b.capa = QSE_TYPE_MAX(qse_ssize_t);
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_size_t) - 1;
|
||||
fo.ctx = &b;
|
||||
fo.put_mchar = output_mchar;
|
||||
fo.put_wchar = output_wchar;
|
||||
|
||||
/* no error must be returned by fmtout since
|
||||
* the callback function never fails. */
|
||||
va_start (ap, fmt);
|
||||
fmtout (fmt, &fo, ap);
|
||||
va_end (ap);
|
||||
|
||||
b.ptr[b.len] = T('\0');
|
||||
|
||||
return fo.count;
|
||||
}
|
||||
|
||||
qse_size_t strxfmt (char_t* buf, qse_size_t len, const char_t* fmt, ...)
|
||||
{
|
||||
buf_t b;
|
||||
va_list ap;
|
||||
qse_fmtout_t fo;
|
||||
|
||||
b.ptr = buf;
|
||||
b.len = 0;
|
||||
|
||||
if (len > QSE_TYPE_MAX(qse_ssize_t))
|
||||
b.capa = QSE_TYPE_MAX(qse_ssize_t);
|
||||
else if (len > 0)
|
||||
b.capa = len - 1;
|
||||
else
|
||||
b.capa = 0;
|
||||
|
||||
fo.limit = QSE_TYPE_MAX(qse_size_t) - 1;
|
||||
fo.ctx = &b;
|
||||
fo.put_mchar = output_mchar;
|
||||
fo.put_wchar = output_wchar;
|
||||
|
||||
/* no error must be returned by fmtout since
|
||||
* the callback function never fails. */
|
||||
va_start (ap, fmt);
|
||||
fmtout (fmt, &fo, ap);
|
||||
va_end (ap);
|
||||
|
||||
if (len > 0) b.ptr[b.len] = T('\0');
|
||||
|
||||
return fo.count;
|
||||
}
|
||||
|
@ -668,6 +668,11 @@ static int server_open (qse_httpd_t* httpd, qse_httpd_server_t* server)
|
||||
flag = 1;
|
||||
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (void*)&flag, QSE_SIZEOF(flag));
|
||||
#endif
|
||||
|
||||
#if defined(SO_REUSEPORT)
|
||||
flag = 1;
|
||||
setsockopt (fd, SOL_SOCKET, SO_REUSEPORT, (void*)&flag, QSE_SIZEOF(flag));
|
||||
#endif
|
||||
|
||||
/* TODO: linux. use capset() to set required capabilities just in case */
|
||||
#if defined(IP_TRANSPARENT)
|
||||
|
Reference in New Issue
Block a user