added much more support code

This commit is contained in:
hyung-hwan 2020-05-01 14:00:27 +00:00
parent f1aa019091
commit a2f0fa9c7f
22 changed files with 24386 additions and 211 deletions

View File

@ -21,6 +21,7 @@ LIBADD_LIB_COMMON = $(LIBM)
include_HEADERS = \
mio-cfg.h \
mio-chr.h \
mio-cmn.h \
mio-dns.h \
mio-ecs.h \
@ -39,6 +40,7 @@ include_HEADERS = \
lib_LTLIBRARIES = libmio.la
libmio_la_SOURCES = \
chr.c \
dns.c \
dns-cli.c \
ecs.c \
@ -47,6 +49,8 @@ libmio_la_SOURCES = \
fmt.c \
fmt-imp.h \
htb.c \
htre.c \
http.c \
mio-prv.h \
mio.c \
nwif.c \

View File

@ -138,9 +138,10 @@ am__DEPENDENCIES_1 =
am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
libmio_la_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_libmio_la_OBJECTS = libmio_la-dns.lo libmio_la-dns-cli.lo \
libmio_la-ecs.lo libmio_la-err.lo libmio_la-fmt.lo \
libmio_la-htb.lo libmio_la-mio.lo libmio_la-nwif.lo \
am_libmio_la_OBJECTS = libmio_la-chr.lo libmio_la-dns.lo \
libmio_la-dns-cli.lo libmio_la-ecs.lo libmio_la-err.lo \
libmio_la-fmt.lo libmio_la-htb.lo libmio_la-htre.lo \
libmio_la-http.lo libmio_la-mio.lo libmio_la-nwif.lo \
libmio_la-pro.lo libmio_la-sck.lo libmio_la-skad.lo \
libmio_la-sys.lo libmio_la-sys-ass.lo libmio_la-sys-err.lo \
libmio_la-sys-log.lo libmio_la-sys-mux.lo libmio_la-sys-tim.lo \
@ -168,10 +169,12 @@ am__v_at_1 =
DEFAULT_INCLUDES =
depcomp = $(SHELL) $(top_srcdir)/ac/depcomp
am__maybe_remake_depfiles = depfiles
am__depfiles_remade = ./$(DEPDIR)/libmio_la-dns-cli.Plo \
am__depfiles_remade = ./$(DEPDIR)/libmio_la-chr.Plo \
./$(DEPDIR)/libmio_la-dns-cli.Plo \
./$(DEPDIR)/libmio_la-dns.Plo ./$(DEPDIR)/libmio_la-ecs.Plo \
./$(DEPDIR)/libmio_la-err.Plo ./$(DEPDIR)/libmio_la-fmt.Plo \
./$(DEPDIR)/libmio_la-htb.Plo ./$(DEPDIR)/libmio_la-mio.Plo \
./$(DEPDIR)/libmio_la-htb.Plo ./$(DEPDIR)/libmio_la-htre.Plo \
./$(DEPDIR)/libmio_la-http.Plo ./$(DEPDIR)/libmio_la-mio.Plo \
./$(DEPDIR)/libmio_la-nwif.Plo ./$(DEPDIR)/libmio_la-pro.Plo \
./$(DEPDIR)/libmio_la-sck.Plo ./$(DEPDIR)/libmio_la-skad.Plo \
./$(DEPDIR)/libmio_la-sys-ass.Plo \
@ -398,6 +401,7 @@ LIBADD_LIB_COMMON = $(LIBM)
#pkgbindir = $(bindir)
include_HEADERS = \
mio-cfg.h \
mio-chr.h \
mio-cmn.h \
mio-dns.h \
mio-ecs.h \
@ -416,6 +420,7 @@ include_HEADERS = \
lib_LTLIBRARIES = libmio.la
libmio_la_SOURCES = \
chr.c \
dns.c \
dns-cli.c \
ecs.c \
@ -424,6 +429,8 @@ libmio_la_SOURCES = \
fmt.c \
fmt-imp.h \
htb.c \
htre.c \
http.c \
mio-prv.h \
mio.c \
nwif.c \
@ -538,12 +545,15 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-chr.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-dns-cli.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-dns.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-ecs.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-err.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-fmt.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-htb.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-htre.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-http.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-mio.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-nwif.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-pro.Plo@am__quote@ # am--include-marker
@ -589,6 +599,13 @@ am--depfiles: $(am__depfiles_remade)
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
libmio_la-chr.lo: chr.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmio_la-chr.lo -MD -MP -MF $(DEPDIR)/libmio_la-chr.Tpo -c -o libmio_la-chr.lo `test -f 'chr.c' || echo '$(srcdir)/'`chr.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-chr.Tpo $(DEPDIR)/libmio_la-chr.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='chr.c' object='libmio_la-chr.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmio_la-chr.lo `test -f 'chr.c' || echo '$(srcdir)/'`chr.c
libmio_la-dns.lo: dns.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmio_la-dns.lo -MD -MP -MF $(DEPDIR)/libmio_la-dns.Tpo -c -o libmio_la-dns.lo `test -f 'dns.c' || echo '$(srcdir)/'`dns.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-dns.Tpo $(DEPDIR)/libmio_la-dns.Plo
@ -631,6 +648,20 @@ libmio_la-htb.lo: htb.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmio_la-htb.lo `test -f 'htb.c' || echo '$(srcdir)/'`htb.c
libmio_la-htre.lo: htre.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmio_la-htre.lo -MD -MP -MF $(DEPDIR)/libmio_la-htre.Tpo -c -o libmio_la-htre.lo `test -f 'htre.c' || echo '$(srcdir)/'`htre.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-htre.Tpo $(DEPDIR)/libmio_la-htre.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='htre.c' object='libmio_la-htre.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmio_la-htre.lo `test -f 'htre.c' || echo '$(srcdir)/'`htre.c
libmio_la-http.lo: http.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmio_la-http.lo -MD -MP -MF $(DEPDIR)/libmio_la-http.Tpo -c -o libmio_la-http.lo `test -f 'http.c' || echo '$(srcdir)/'`http.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-http.Tpo $(DEPDIR)/libmio_la-http.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='http.c' object='libmio_la-http.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmio_la-http.lo `test -f 'http.c' || echo '$(srcdir)/'`http.c
libmio_la-mio.lo: mio.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmio_la-mio.lo -MD -MP -MF $(DEPDIR)/libmio_la-mio.Tpo -c -o libmio_la-mio.lo `test -f 'mio.c' || echo '$(srcdir)/'`mio.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-mio.Tpo $(DEPDIR)/libmio_la-mio.Plo
@ -884,12 +915,15 @@ clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
mostlyclean-am
distclean: distclean-am
-rm -f ./$(DEPDIR)/libmio_la-dns-cli.Plo
-rm -f ./$(DEPDIR)/libmio_la-chr.Plo
-rm -f ./$(DEPDIR)/libmio_la-dns-cli.Plo
-rm -f ./$(DEPDIR)/libmio_la-dns.Plo
-rm -f ./$(DEPDIR)/libmio_la-ecs.Plo
-rm -f ./$(DEPDIR)/libmio_la-err.Plo
-rm -f ./$(DEPDIR)/libmio_la-fmt.Plo
-rm -f ./$(DEPDIR)/libmio_la-htb.Plo
-rm -f ./$(DEPDIR)/libmio_la-htre.Plo
-rm -f ./$(DEPDIR)/libmio_la-http.Plo
-rm -f ./$(DEPDIR)/libmio_la-mio.Plo
-rm -f ./$(DEPDIR)/libmio_la-nwif.Plo
-rm -f ./$(DEPDIR)/libmio_la-pro.Plo
@ -950,12 +984,15 @@ install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libmio_la-dns-cli.Plo
-rm -f ./$(DEPDIR)/libmio_la-chr.Plo
-rm -f ./$(DEPDIR)/libmio_la-dns-cli.Plo
-rm -f ./$(DEPDIR)/libmio_la-dns.Plo
-rm -f ./$(DEPDIR)/libmio_la-ecs.Plo
-rm -f ./$(DEPDIR)/libmio_la-err.Plo
-rm -f ./$(DEPDIR)/libmio_la-fmt.Plo
-rm -f ./$(DEPDIR)/libmio_la-htb.Plo
-rm -f ./$(DEPDIR)/libmio_la-htre.Plo
-rm -f ./$(DEPDIR)/libmio_la-http.Plo
-rm -f ./$(DEPDIR)/libmio_la-mio.Plo
-rm -f ./$(DEPDIR)/libmio_la-nwif.Plo
-rm -f ./$(DEPDIR)/libmio_la-pro.Plo

489
mio/lib/chr.c Normal file
View File

@ -0,0 +1,489 @@
/*
* $Id$
*
Copyright (c) 2006-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "mio-chr.h"
#include "mio-utl.h"
/* ---------------------------------------------------------- */
#include "uch-prop.h"
#include "uch-case.h"
/* ---------------------------------------------------------- */
#define UCH_PROP_MAP_INDEX(c) ((c) / MIO_COUNTOF(uch_prop_page_0000))
#define UCH_PROP_PAGE_INDEX(c) ((c) % MIO_COUNTOF(uch_prop_page_0000))
#define UCH_CASE_MAP_INDEX(c) ((c) / MIO_COUNTOF(uch_case_page_0000))
#define UCH_CASE_PAGE_INDEX(c) ((c) % MIO_COUNTOF(uch_case_page_0000))
#define UCH_IS_TYPE(c,type) \
((c) >= 0 && (c) <= UCH_PROP_MAX && \
(uch_prop_map[UCH_PROP_MAP_INDEX(c)][UCH_PROP_PAGE_INDEX(c)] & (type)) != 0)
int mio_is_uch_type (mio_uch_t c, mio_uch_prop_t type)
{
return UCH_IS_TYPE((mio_uchu_t)c, type);
}
int mio_is_uch_upper (mio_uch_t c)
{
return UCH_IS_TYPE((mio_uchu_t)c, MIO_UCH_PROP_UPPER);
}
int mio_is_uch_lower (mio_uch_t c)
{
return UCH_IS_TYPE((mio_uchu_t)c, MIO_UCH_PROP_LOWER);
}
int mio_is_uch_alpha (mio_uch_t c)
{
return UCH_IS_TYPE((mio_uchu_t)c, MIO_UCH_PROP_ALPHA);
}
int mio_is_uch_digit (mio_uch_t c)
{
return UCH_IS_TYPE((mio_uchu_t)c, MIO_UCH_PROP_DIGIT);
}
int mio_is_uch_xdigit (mio_uch_t c)
{
return UCH_IS_TYPE((mio_uchu_t)c, MIO_UCH_PROP_XDIGIT);
}
int mio_is_uch_alnum (mio_uch_t c)
{
return UCH_IS_TYPE((mio_uchu_t)c, MIO_UCH_PROP_ALNUM);
}
int mio_is_uch_space (mio_uch_t c)
{
return UCH_IS_TYPE((mio_uchu_t)c, MIO_UCH_PROP_SPACE);
}
int mio_is_uch_print (mio_uch_t c)
{
return UCH_IS_TYPE((mio_uchu_t)c, MIO_UCH_PROP_PRINT);
}
int mio_is_uch_graph (mio_uch_t c)
{
return UCH_IS_TYPE((mio_uchu_t)c, MIO_UCH_PROP_GRAPH);
}
int mio_is_uch_cntrl (mio_uch_t c)
{
return UCH_IS_TYPE((mio_uchu_t)c, MIO_UCH_PROP_CNTRL);
}
int mio_is_uch_punct (mio_uch_t c)
{
return UCH_IS_TYPE((mio_uchu_t)c, MIO_UCH_PROP_PUNCT);
}
int mio_is_uch_blank (mio_uch_t c)
{
return UCH_IS_TYPE((mio_uchu_t)c, MIO_UCH_PROP_BLANK);
}
mio_uch_t mio_to_uch_upper (mio_uch_t c)
{
mio_uchu_t uc = (mio_uchu_t)c;
if (uc >= 0 && uc <= UCH_CASE_MAX)
{
uch_case_page_t* page;
page = uch_case_map[UCH_CASE_MAP_INDEX(uc)];
return uc - page[UCH_CASE_PAGE_INDEX(uc)].upper;
}
return c;
}
mio_uch_t mio_to_uch_lower (mio_uch_t c)
{
mio_uchu_t uc = (mio_uchu_t)c;
if (uc >= 0 && uc <= UCH_CASE_MAX)
{
uch_case_page_t* page;
page = uch_case_map[UCH_CASE_MAP_INDEX(uc)];
return uc + page[UCH_CASE_PAGE_INDEX(uc)].lower;
}
return c;
}
/* ---------------------------------------------------------- */
int mio_is_bch_type (mio_bch_t c, mio_bch_prop_t type)
{
switch (type)
{
case MIO_OOCH_PROP_UPPER:
return mio_is_bch_upper(c);
case MIO_OOCH_PROP_LOWER:
return mio_is_bch_lower(c);
case MIO_OOCH_PROP_ALPHA:
return mio_is_bch_alpha(c);
case MIO_OOCH_PROP_DIGIT:
return mio_is_bch_digit(c);
case MIO_OOCH_PROP_XDIGIT:
return mio_is_bch_xdigit(c);
case MIO_OOCH_PROP_ALNUM:
return mio_is_bch_alnum(c);
case MIO_OOCH_PROP_SPACE:
return mio_is_bch_space(c);
case MIO_OOCH_PROP_PRINT:
return mio_is_bch_print(c);
case MIO_OOCH_PROP_GRAPH:
return mio_is_bch_graph(c);
case MIO_OOCH_PROP_CNTRL:
return mio_is_bch_cntrl(c);
case MIO_OOCH_PROP_PUNCT:
return mio_is_bch_punct(c);
case MIO_OOCH_PROP_BLANK:
return mio_is_bch_blank(c);
}
/* must not reach here */
return 0;
}
#if !defined(mio_to_bch_upper)
mio_bch_t mio_to_bch_upper (mio_bch_t c)
{
if(mio_is_bch_lower(c)) return c & 95;
return c;
}
#endif
#if !defined(mio_to_bch_lower)
mio_bch_t mio_to_bch_lower (mio_bch_t c)
{
if(mio_is_bch_upper(c)) return c | 32;
return c;
}
#endif
/* ---------------------------------------------------------- */
static struct prop_tab_t
{
const mio_bch_t* name;
int class;
} prop_tab[] =
{
{ "alnum", MIO_OOCH_PROP_ALNUM },
{ "alpha", MIO_OOCH_PROP_ALPHA },
{ "blank", MIO_OOCH_PROP_BLANK },
{ "cntrl", MIO_OOCH_PROP_CNTRL },
{ "digit", MIO_OOCH_PROP_DIGIT },
{ "graph", MIO_OOCH_PROP_GRAPH },
{ "lower", MIO_OOCH_PROP_LOWER },
{ "print", MIO_OOCH_PROP_PRINT },
{ "punct", MIO_OOCH_PROP_PUNCT },
{ "space", MIO_OOCH_PROP_SPACE },
{ "upper", MIO_OOCH_PROP_UPPER },
{ "xdigit", MIO_OOCH_PROP_XDIGIT }
};
/* ---------------------------------------------------------- */
int mio_ucstr_to_uch_prop (const mio_uch_t* name, mio_uch_prop_t* id)
{
int left = 0, right = MIO_COUNTOF(prop_tab) - 1, mid;
while (left <= right)
{
int n;
struct prop_tab_t* kwp;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
kwp = &prop_tab[mid];
n = mio_comp_ucstr_bcstr(name, kwp->name, 0);
if (n > 0)
{
/* if left, right, mid were of mio_oow_t,
* you would need the following line.
if (mid == 0) break;
*/
right = mid - 1;
}
else if (n < 0) left = mid + 1;
else
{
*id = kwp->class;
return 0;
}
}
return -1;
}
int mio_uchars_to_uch_prop (const mio_uch_t* name, mio_oow_t len, mio_uch_prop_t* id)
{
int left = 0, right = MIO_COUNTOF(prop_tab) - 1, mid;
while (left <= right)
{
int n;
struct prop_tab_t* kwp;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
kwp = &prop_tab[mid];
n = mio_comp_uchars_bcstr(name, len, kwp->name, 0);
if (n < 0)
{
/* if left, right, mid were of mio_oow_t,
* you would need the following line.
if (mid == 0) break;
*/
right = mid - 1;
}
else if (n > 0) left = mid + 1;
else
{
*id = kwp->class;
return 0;
}
}
return -1;
}
/* ---------------------------------------------------------- */
int mio_bcstr_to_bch_prop (const mio_bch_t* name, mio_bch_prop_t* id)
{
int left = 0, right = MIO_COUNTOF(prop_tab) - 1, mid;
while (left <= right)
{
int n;
struct prop_tab_t* kwp;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
kwp = &prop_tab[mid];
n = mio_comp_bcstr(name, kwp->name, 0);
if (n > 0)
{
/* if left, right, mid were of mio_oow_t,
* you would need the following line.
if (mid == 0) break;
*/
right = mid - 1;
}
else if (n < 0) left = mid + 1;
else
{
*id = kwp->class;
return 0;
}
}
return -1;
}
int mio_bchars_to_bch_prop (const mio_bch_t* name, mio_oow_t len, mio_bch_prop_t* id)
{
int left = 0, right = MIO_COUNTOF(prop_tab) - 1, mid;
while (left <= right)
{
int n;
struct prop_tab_t* kwp;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
kwp = &prop_tab[mid];
n = mio_comp_bchars_bcstr(name, len, kwp->name, 0);
if (n < 0)
{
/* if left, right, mid were of mio_oow_t,
* you would need the following line.
if (mid == 0) break;
*/
right = mid - 1;
}
else if (n > 0) left = mid + 1;
else
{
*id = kwp->class;
return 0;
}
}
return -1;
}
/* ----------------------------------------------------------------------- */
/*
* See http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
*/
struct interval
{
int first;
int last;
};
/* auxiliary function for binary search in interval table */
static int bisearch(mio_uch_t ucs, const struct interval *table, int max)
{
int min = 0;
int mid;
if (ucs < table[0].first || ucs > table[max].last) return 0;
while (max >= min)
{
mid = (min + max) / 2;
if (ucs > table[mid].last) min = mid + 1;
else if (ucs < table[mid].first) max = mid - 1;
else return 1;
}
return 0;
}
/* The following two functions define the column width of an ISO 10646
* character as follows:
*
* - The null character (U+0000) has a column width of 0.
*
* - Other C0/C1 control characters and DEL will lead to a return
* value of -1.
*
* - Non-spacing and enclosing combining characters (general
* category code Mn or Me in the Unicode database) have a
* column width of 0.
*
* - SOFT HYPHEN (U+00AD) has a column width of 1.
*
* - Other format characters (general category code Cf in the Unicode
* database) and ZERO WIDTH SPACE (U+200B) have a column width of 0.
*
* - Hangul Jamo medial vowels and final consonants (U+1160-U+11FF)
* have a column width of 0.
*
* - Spacing characters in the East Asian Wide (W) or East Asian
* Full-width (F) category as defined in Unicode Technical
* Report #11 have a column width of 2.
*
* - All remaining characters (including all printable
* ISO 8859-1 and WGL4 characters, Unicode control characters,
* etc.) have a column width of 1.
*
* This implementation assumes that wchar_t characters are encoded
* in ISO 10646.
*/
int mio_get_ucwidth (mio_uch_t uc)
{
/* sorted list of non-overlapping intervals of non-spacing characters */
/* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */
static const struct interval combining[] = {
{ 0x0300, 0x036F }, { 0x0483, 0x0486 }, { 0x0488, 0x0489 },
{ 0x0591, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 },
{ 0x05C4, 0x05C5 }, { 0x05C7, 0x05C7 }, { 0x0600, 0x0603 },
{ 0x0610, 0x0615 }, { 0x064B, 0x065E }, { 0x0670, 0x0670 },
{ 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED },
{ 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A },
{ 0x07A6, 0x07B0 }, { 0x07EB, 0x07F3 }, { 0x0901, 0x0902 },
{ 0x093C, 0x093C }, { 0x0941, 0x0948 }, { 0x094D, 0x094D },
{ 0x0951, 0x0954 }, { 0x0962, 0x0963 }, { 0x0981, 0x0981 },
{ 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD },
{ 0x09E2, 0x09E3 }, { 0x0A01, 0x0A02 }, { 0x0A3C, 0x0A3C },
{ 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D },
{ 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC },
{ 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD },
{ 0x0AE2, 0x0AE3 }, { 0x0B01, 0x0B01 }, { 0x0B3C, 0x0B3C },
{ 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, { 0x0B4D, 0x0B4D },
{ 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, { 0x0BC0, 0x0BC0 },
{ 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, { 0x0C46, 0x0C48 },
{ 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0CBC, 0x0CBC },
{ 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD },
{ 0x0CE2, 0x0CE3 }, { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D },
{ 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 },
{ 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E },
{ 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC },
{ 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 },
{ 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E },
{ 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 },
{ 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 },
{ 0x1032, 0x1032 }, { 0x1036, 0x1037 }, { 0x1039, 0x1039 },
{ 0x1058, 0x1059 }, { 0x1160, 0x11FF }, { 0x135F, 0x135F },
{ 0x1712, 0x1714 }, { 0x1732, 0x1734 }, { 0x1752, 0x1753 },
{ 0x1772, 0x1773 }, { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD },
{ 0x17C6, 0x17C6 }, { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD },
{ 0x180B, 0x180D }, { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 },
{ 0x1927, 0x1928 }, { 0x1932, 0x1932 }, { 0x1939, 0x193B },
{ 0x1A17, 0x1A18 }, { 0x1B00, 0x1B03 }, { 0x1B34, 0x1B34 },
{ 0x1B36, 0x1B3A }, { 0x1B3C, 0x1B3C }, { 0x1B42, 0x1B42 },
{ 0x1B6B, 0x1B73 }, { 0x1DC0, 0x1DCA }, { 0x1DFE, 0x1DFF },
{ 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x2060, 0x2063 },
{ 0x206A, 0x206F }, { 0x20D0, 0x20EF }, { 0x302A, 0x302F },
{ 0x3099, 0x309A }, { 0xA806, 0xA806 }, { 0xA80B, 0xA80B },
{ 0xA825, 0xA826 }, { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F },
{ 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB },
{ 0x10A01, 0x10A03 }, { 0x10A05, 0x10A06 }, { 0x10A0C, 0x10A0F },
{ 0x10A38, 0x10A3A }, { 0x10A3F, 0x10A3F }, { 0x1D167, 0x1D169 },
{ 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD },
{ 0x1D242, 0x1D244 }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F },
{ 0xE0100, 0xE01EF }
};
/* test for 8-bit control characters */
if (uc == 0) return 0;
if (uc < 32 || (uc >= 0x7f && uc < 0xa0)) return -1;
/* binary search in table of non-spacing characters */
if (bisearch(uc, combining, sizeof(combining) / sizeof(struct interval) - 1)) return 0;
/* if we arrive here, uc is not a combining or C0/C1 control character */
if (uc >= 0x1100)
{
if (uc <= 0x115f || /* Hangul Jamo init. consonants */
uc == 0x2329 || uc == 0x232a ||
(uc >= 0x2e80 && uc <= 0xa4cf && uc != 0x303f) || /* CJK ... Yi */
(uc >= 0xac00 && uc <= 0xd7a3) || /* Hangul Syllables */
(uc >= 0xf900 && uc <= 0xfaff) || /* CJK Compatibility Ideographs */
(uc >= 0xfe10 && uc <= 0xfe19) || /* Vertical forms */
(uc >= 0xfe30 && uc <= 0xfe6f) || /* CJK Compatibility Forms */
(uc >= 0xff00 && uc <= 0xff60) || /* Fullwidth Forms */
(uc >= 0xffe0 && uc <= 0xffe6)
#if (MIO_SIZEOF_UCH_T > 2)
||
(uc >= 0x20000 && uc <= 0x2fffd) ||
(uc >= 0x30000 && uc <= 0x3fffd)
#endif
)
{
return 2;
}
}
return 1;
}

View File

@ -25,16 +25,16 @@
*/
str_t* FN(open) (mio_t* gem, mio_oow_t xtnsize, mio_oow_t capa)
str_t* FN(open) (mio_t* mio, mio_oow_t xtnsize, mio_oow_t capa)
{
str_t* str;
str = (str_t*)mio_allocmem(gem, MIO_SIZEOF(str_t) + xtnsize);
str = (str_t*)mio_allocmem(mio, MIO_SIZEOF(str_t) + xtnsize);
if (str)
{
if (FN(init)(str, gem, capa) <= -1)
if (FN(init)(str, mio, capa) <= -1)
{
mio_freemem (gem, str);
mio_freemem (mio, str);
str = MIO_NULL;
}
else
@ -48,20 +48,20 @@ str_t* FN(open) (mio_t* gem, mio_oow_t xtnsize, mio_oow_t capa)
void FN(close) (str_t* str)
{
FN(fini) (str);
mio_freemem (str->gem, str);
mio_freemem (str->mio, str);
}
int FN(init) (str_t* str, mio_t* gem, mio_oow_t capa)
int FN(init) (str_t* str, mio_t* mio, mio_oow_t capa)
{
MIO_MEMSET (str, 0, MIO_SIZEOF(str_t));
str->gem = gem;
str->mio = mio;
str->sizer = MIO_NULL;
if (capa == 0) str->val.ptr = MIO_NULL;
else
{
str->val.ptr = (char_t*)mio_allocmem(gem, MIO_SIZEOF(char_t) * (capa + 1));
str->val.ptr = (char_t*)mio_allocmem(mio, MIO_SIZEOF(char_t) * (capa + 1));
if (!str->val.ptr) return -1;
str->val.ptr[0] = '\0';
}
@ -74,7 +74,7 @@ int FN(init) (str_t* str, mio_t* gem, mio_oow_t capa)
void FN(fini) (str_t* str)
{
if (str->val.ptr) mio_freemem (str->gem, str->val.ptr);
if (str->val.ptr) mio_freemem (str->mio, str->val.ptr);
}
int FN(yield) (str_t* str, cstr_t* buf, mio_oow_t newcapa)
@ -84,7 +84,7 @@ int FN(yield) (str_t* str, cstr_t* buf, mio_oow_t newcapa)
if (newcapa == 0) tmp = MIO_NULL;
else
{
tmp = (char_t*)mio_allocmem(str->gem, MIO_SIZEOF(char_t) * (newcapa + 1));
tmp = (char_t*)mio_allocmem(str->mio, MIO_SIZEOF(char_t) * (newcapa + 1));
if (!tmp) return -1;
tmp[0] = '\0';
}
@ -112,7 +112,7 @@ mio_oow_t FN(setcapa) (str_t* str, mio_oow_t capa)
if (capa == str->capa) return capa;
tmp = (char_t*)mio_reallocmem(str->gem, str->val.ptr, MIO_SIZEOF(char_t) * (capa+1));
tmp = (char_t*)mio_reallocmem(str->mio, str->val.ptr, MIO_SIZEOF(char_t) * (capa+1));
if (!tmp) return (mio_oow_t)-1;
if (capa < str->val.len)
@ -152,7 +152,7 @@ void FN(clear) (str_t* str)
str->val.len = 0;
if (str->val.ptr)
{
MIO_ASSERT (str->gem, str->capa >= 1);
MIO_ASSERT (str->mio, str->capa >= 1);
str->val.ptr[0] = '\0';
}
}
@ -164,17 +164,17 @@ void FN(swap) (str_t* str, str_t* str1)
tmp.val.ptr = str->val.ptr;
tmp.val.len = str->val.len;
tmp.capa = str->capa;
tmp.gem = str->gem;
tmp.mio = str->mio;
str->val.ptr = str1->val.ptr;
str->val.len = str1->val.len;
str->capa = str1->capa;
str->gem = str1->gem;
str->mio = str1->mio;
str1->val.ptr = tmp.val.ptr;
str1->val.len = tmp.val.len;
str1->capa = tmp.capa;
str1->gem = tmp.gem;
str1->mio = tmp.mio;
}
@ -251,8 +251,8 @@ static int FN(resize_for_ncat) (str_t* str, mio_oow_t len)
}
else if (str->capa <= 0 && len <= 0)
{
MIO_ASSERT (str->gem, str->val.ptr == MIO_NULL);
MIO_ASSERT (str->gem, str->val.len <= 0);
MIO_ASSERT (str->mio, str->val.ptr == MIO_NULL);
MIO_ASSERT (str->mio, str->val.len <= 0);
if (FN(setcapa)(str, 1) == (mio_oow_t)-1) return -1;
}
@ -364,12 +364,11 @@ mio_oow_t FN(amend) (str_t* str, mio_oow_t pos, mio_oow_t len, const char_t* rep
return str->val.len;
}
#if 0
static int FN(put_bchars) (mio_fmtout_t* fmtout, const mio_bch_t* ptr, mio_oow_t len)
{
#if defined(BUILD_UECS)
mio_uecs_t* uecs = (mio_uecs_t*)fmtout->ctx;
if (mio_uecs_ncatbchars(uecs, ptr, len, uecs->gem->cmgr, 1) == (mio_oow_t)-1) return -1;
if (mio_uecs_ncatbchars(uecs, ptr, len, uecs->mio->_cmgr, 1) == (mio_oow_t)-1) return -1;
#else
mio_becs_t* becs = (mio_becs_t*)fmtout->ctx;
if (mio_becs_ncat(becs, ptr, len) == (mio_oow_t)-1) return -1;
@ -384,7 +383,7 @@ static int FN(put_uchars) (mio_fmtout_t* fmtout, const mio_uch_t* ptr, mio_oow_t
if (mio_uecs_ncat(uecs, ptr, len) == (mio_oow_t)-1) return -1;
#else
mio_becs_t* becs = (mio_becs_t*)fmtout->ctx;
if (mio_becs_ncatuchars(becs, ptr, len, becs->gem->cmgr) == (mio_oow_t)-1) return -1;
if (mio_becs_ncatuchars(becs, ptr, len, becs->mio->_cmgr) == (mio_oow_t)-1) return -1;
#endif
return 1; /* success. carry on */
}
@ -394,7 +393,7 @@ mio_oow_t FN(vfcat) (str_t* str, const char_t* fmt, va_list ap)
mio_fmtout_t fo;
MIO_MEMSET (&fo, 0, MIO_SIZEOF(fo));
fo.mmgr = str->gem->mmgr;
//fo.mmgr = str->mio->_mmgr;
fo.putbchars = FN(put_bchars);
fo.putuchars = FN(put_uchars);
fo.ctx = str;
@ -424,7 +423,7 @@ mio_oow_t FN(vfmt) (str_t* str, const char_t* fmt, va_list ap)
mio_fmtout_t fo;
MIO_MEMSET (&fo, 0, MIO_SIZEOF(fo));
fo.mmgr = str->gem->mmgr;
//fo.mmgr = str->mio->_mmgr;
fo.putbchars = FN(put_bchars);
fo.putuchars = FN(put_uchars);
fo.ctx = str;
@ -450,4 +449,3 @@ mio_oow_t FN(fmt) (str_t* str, const char_t* fmt, ...)
return x;
}
#endif

View File

@ -25,6 +25,7 @@
*/
#include "mio-ecs.h"
#include "mio-fmt.h"
#include "mio-prv.h"
#define _FN(type,verb) mio_ ## type ## _ ## verb

View File

@ -165,8 +165,8 @@ void mio_seterrbfmt (mio_t* mio, mio_errnum_t errnum, const mio_bch_t* fmt, ...)
mio->errmsg.len = 0;
MIO_MEMSET (&fo, 0, MIO_SIZEOF(fo));
fo.putbcs = err_bcs;
fo.putucs = err_ucs;
fo.putbchars = err_bcs;
fo.putuchars = err_ucs;
fo.ctx = mio;
va_start (ap, fmt);
@ -185,8 +185,8 @@ void mio_seterrufmt (mio_t* mio, mio_errnum_t errnum, const mio_uch_t* fmt, ...)
mio->errmsg.len = 0;
MIO_MEMSET (&fo, 0, MIO_SIZEOF(fo));
fo.putbcs = err_bcs;
fo.putucs = err_ucs;
fo.putbchars = err_bcs;
fo.putuchars = err_ucs;
fo.ctx = mio;
va_start (ap, fmt);
@ -206,8 +206,8 @@ void mio_seterrbfmtv (mio_t* mio, mio_errnum_t errnum, const mio_bch_t* fmt, va_
mio->errmsg.len = 0;
MIO_MEMSET (&fo, 0, MIO_SIZEOF(fo));
fo.putbcs = err_bcs;
fo.putucs = err_ucs;
fo.putbchars = err_bcs;
fo.putuchars = err_ucs;
fo.ctx = mio;
mio_bfmt_outv (&fo, fmt, ap);
@ -223,8 +223,8 @@ void mio_seterrufmtv (mio_t* mio, mio_errnum_t errnum, const mio_uch_t* fmt, va_
mio->errmsg.len = 0;
MIO_MEMSET (&fo, 0, MIO_SIZEOF(fo));
fo.putbcs = err_bcs;
fo.putucs = err_ucs;
fo.putbchars = err_bcs;
fo.putuchars = err_ucs;
fo.ctx = mio;
mio_ufmt_outv (&fo, fmt, ap);

View File

@ -211,7 +211,7 @@ static mio_bch_t* sprintn_upper (mio_bch_t* nbuf, mio_uintmax_t num, int base, m
for (_yy = 0; _yy < n; _yy++) \
{ \
int _xx; \
if ((_xx = fmtout->putbcs(fmtout, &_cc, 1)) <= -1) goto oops; \
if ((_xx = fmtout->putbchars(fmtout, &_cc, 1)) <= -1) goto oops; \
if (_xx == 0) goto done; \
fmtout->count++; \
} \
@ -221,7 +221,7 @@ static mio_bch_t* sprintn_upper (mio_bch_t* nbuf, mio_uintmax_t num, int base, m
#define PUT_BCS(fmtout,ptr,len) do { \
if (len > 0) { \
int _xx; \
if ((_xx = fmtout->putbcs(fmtout, ptr, len)) <= -1) goto oops; \
if ((_xx = fmtout->putbchars(fmtout, ptr, len)) <= -1) goto oops; \
if (_xx == 0) goto done; \
fmtout->count += len; \
} \
@ -234,7 +234,7 @@ static mio_bch_t* sprintn_upper (mio_bch_t* nbuf, mio_uintmax_t num, int base, m
for (_yy = 0; _yy < n; _yy++) \
{ \
int _xx; \
if ((_xx = fmtout->putucs(fmtout, &_cc, 1)) <= -1) goto oops; \
if ((_xx = fmtout->putuchars(fmtout, &_cc, 1)) <= -1) goto oops; \
if (_xx == 0) goto done; \
fmtout->count++; \
} \
@ -244,7 +244,7 @@ static mio_bch_t* sprintn_upper (mio_bch_t* nbuf, mio_uintmax_t num, int base, m
#define PUT_UCS(fmtout,ptr,len) do { \
if (len > 0) { \
int _xx; \
if ((_xx = fmtout->putucs(fmtout, ptr, len)) <= -1) goto oops; \
if ((_xx = fmtout->putuchars(fmtout, ptr, len)) <= -1) goto oops; \
if (_xx == 0) goto done; \
fmtout->count += len; \
} \
@ -1106,7 +1106,7 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
#endif
}
#else
num = va_arg (ap, mio_uintmax_t);
num = va_arg(ap, mio_uintmax_t);
#endif
}
#if 0
@ -1142,15 +1142,15 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
for (i = 0, num = 0; i < MIO_SIZEOF(mio_intmax_t) / MIO_SIZEOF(mio_oow_t); i++)
{
#if defined(MIO_ENDIAN_BIG)
num = num << (8 * MIO_SIZEOF(mio_oow_t)) | (va_arg (ap, mio_oow_t));
num = num << (8 * MIO_SIZEOF(mio_oow_t)) | (va_arg(ap, mio_oow_t));
#else
register int shift = i * MIO_SIZEOF(mio_oow_t);
mio_oow_t x = va_arg (ap, mio_oow_t);
mio_oow_t x = va_arg(ap, mio_oow_t);
num |= (mio_uintmax_t)x << (shift * MIO_BITS_PER_BYTE);
#endif
}
#else
num = va_arg (ap, mio_intmax_t);
num = va_arg(ap, mio_intmax_t);
#endif
}
@ -1159,19 +1159,19 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
num = va_arg(ap, mio_ptrdiff_t);
#endif
else if (lm_flag & LF_Z)
num = va_arg (ap, mio_ooi_t);
num = va_arg(ap, mio_ooi_t);
#if (MIO_SIZEOF_LONG_LONG > 0)
else if (lm_flag & LF_Q)
num = va_arg (ap, long long int);
num = va_arg(ap, long long int);
#endif
else if (lm_flag & (LF_L | LF_LD))
num = va_arg (ap, long int);
num = va_arg(ap, long int);
else if (lm_flag & LF_H)
num = (short int)va_arg (ap, int);
num = (short int)va_arg(ap, int);
else if (lm_flag & LF_C)
num = (char)va_arg (ap, int);
num = (char)va_arg(ap, int);
else
num = va_arg (ap, int);
num = va_arg(ap, int);
number:
if (sign && (mio_intmax_t)num < 0)
@ -1537,8 +1537,8 @@ mio_ooi_t mio_logbfmtv (mio_t* mio, mio_bitmask_t mask, const mio_bch_t* fmt, va
fo.fmt_str = fmt;
fo.ctx = mio;
fo.mask = mask;
fo.putbcs = log_bcs;
fo.putucs = log_ucs;
fo.putbchars = log_bcs;
fo.putuchars = log_ucs;
x = fmt_outv(&fo, ap);
@ -1590,8 +1590,8 @@ mio_ooi_t mio_logufmtv (mio_t* mio, mio_bitmask_t mask, const mio_uch_t* fmt, va
fo.fmt_str = fmt;
fo.ctx = mio;
fo.mask = mask;
fo.putbcs = log_bcs;
fo.putucs = log_ucs;
fo.putbchars = log_bcs;
fo.putuchars = log_ucs;
x = fmt_outv(&fo, ap);

View File

@ -126,16 +126,16 @@ static MIO_INLINE void clear_feed (mio_htrd_t* htrd)
MIO_MEMSET (&htrd->fed.s, 0, MIO_SIZEOF(htrd->fed.s));
}
mio_htrd_t* mio_htrd_open (mio_mmgr_t* mmgr, mio_oow_t xtnsize)
mio_htrd_t* mio_htrd_open (mio_t* mio, mio_oow_t xtnsize)
{
mio_htrd_t* htrd;
htrd = (mio_htrd_t*)MIO_MMGR_ALLOC(mmgr, MIO_SIZEOF(mio_htrd_t) + xtnsize);
htrd = (mio_htrd_t*)mio_allocmem(mio, MIO_SIZEOF(mio_htrd_t) + xtnsize);
if (htrd)
{
if (mio_htrd_init (htrd, mmgr) <= -1)
if (mio_htrd_init(htrd, mio) <= -1)
{
MIO_MMGR_FREE (mmgr, htrd);
mio_freemem (mio, htrd);
return MIO_NULL;
}
else MIO_MEMSET (MIO_XTN(htrd), 0, xtnsize);
@ -146,27 +146,27 @@ mio_htrd_t* mio_htrd_open (mio_mmgr_t* mmgr, mio_oow_t xtnsize)
void mio_htrd_close (mio_htrd_t* htrd)
{
mio_htrd_fini (htrd);
MIO_MMGR_FREE (htrd->mmgr, htrd);
mio_freemem (htrd->mio, htrd);
}
int mio_htrd_init (mio_htrd_t* htrd, mio_mmgr_t* mmgr)
int mio_htrd_init (mio_htrd_t* htrd, mio_t* mio)
{
MIO_MEMSET (htrd, 0, MIO_SIZEOF(*htrd));
htrd->mmgr = mmgr;
htrd->mio = mio;
htrd->option = MIO_HTRD_REQUEST | MIO_HTRD_RESPONSE;
#if 0
mio_mbs_init (&htrd->tmp.qparam, htrd->mmgr, 0);
mio_becs_init (&htrd->tmp.qparam, htrd->mio, 0);
#endif
mio_mbs_init (&htrd->fed.b.raw, htrd->mmgr, 0);
mio_mbs_init (&htrd->fed.b.tra, htrd->mmgr, 0);
mio_becs_init (&htrd->fed.b.raw, htrd->mio, 0);
mio_becs_init (&htrd->fed.b.tra, htrd->mio, 0);
if (mio_htre_init (&htrd->re, mmgr) <= -1)
if (mio_htre_init(&htrd->re, mio) <= -1)
{
mio_mbs_fini (&htrd->fed.b.tra);
mio_mbs_fini (&htrd->fed.b.raw);
mio_becs_fini (&htrd->fed.b.tra);
mio_becs_fini (&htrd->fed.b.raw);
#if 0
mio_mbs_fini (&htrd->tmp.qparam);
mio_becs_fini (&htrd->tmp.qparam);
#endif
return -1;
}
@ -481,11 +481,6 @@ void mio_htrd_clear (mio_htrd_t* htrd)
htrd->flags = 0;
}
mio_mmgr_t* mio_htrd_getmmgr (mio_htrd_t* htrd)
{
return htrd->mmgr;
}
void* mio_htrd_getxtn (mio_htrd_t* htrd)
{
return MIO_XTN (htrd);
@ -727,8 +722,8 @@ static mio_htb_pair_t* hdr_cbserter (
mio_htb_pair_t* p;
mio_htre_hdrval_t *val;
val = MIO_MMGR_ALLOC (htb->mmgr, MIO_SIZEOF(*val));
if (val == MIO_NULL)
val = mio_allocmem(htb->mio, MIO_SIZEOF(*val));
if (HAWK_UNLIKELY(!val))
{
tx->htrd->errnum = MIO_HTRD_ENOMEM;
return MIO_NULL;
@ -742,7 +737,7 @@ static mio_htb_pair_t* hdr_cbserter (
p = mio_htb_allocpair (htb, kptr, klen, val, 0);
if (p == MIO_NULL)
{
MIO_MMGR_FREE (htb->mmgr, val);
mio_freemem (htb->mio, val);
tx->htrd->errnum = MIO_HTRD_ENOMEM;
}
else
@ -791,9 +786,8 @@ static mio_htb_pair_t* hdr_cbserter (
mio_htre_hdrval_t* val;
mio_htre_hdrval_t* tmp;
val = (mio_htre_hdrval_t*) MIO_MMGR_ALLOC (
tx->htrd->mmgr, MIO_SIZEOF(*val));
if (val == MIO_NULL)
val = (mio_htre_hdrval_t*)mio_allocmem(tx->htrd->mio, MIO_SIZEOF(*val));
if (HAWK_UNLIKELY(!val))
{
tx->htrd->errnum = MIO_HTRD_ENOMEM;
return MIO_NULL;

View File

@ -285,8 +285,8 @@ int mio_htre_perdecqpath (mio_htre_t* re)
re->orgqpath.capa = 0;
}
re->orgqpath.buf = mio_mbsxdup(re->u.q.path.ptr, re->u.q.path.len, re->mio);
if (!re->orgqpath.buf) return -1;
re->orgqpath.buf = mio_dupbchars(re->mio, re->u.q.path.ptr, re->u.q.path.len);
if (MIO_UNLIKELY(!re->orgqpath.buf)) return -1;
re->orgqpath.capa = re->u.q.path.len;
re->orgqpath.ptr = re->orgqpath.buf;

View File

@ -22,18 +22,19 @@
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <mio-http.h>
#include "mio-http.h"
#include "mio-chr.h"
#include "mio-utl.h"
#include "mio-prv.h"
#include <time.h>
int mio_comparehttpversions (
const mio_http_version_t* v1,
const mio_http_version_t* v2)
int mio_comp_http_versions (const mio_http_version_t* v1, const mio_http_version_t* v2)
{
if (v1->major == v2->major) return v1->minor - v2->minor;
return v1->major - v2->major;
}
const mio_bch_t* mio_httpstatustombs (int code)
const mio_bch_t* mio_http_status_to_bcstr (int code)
{
const mio_bch_t* msg;
@ -95,7 +96,7 @@ const mio_bch_t* mio_httpstatustombs (int code)
return msg;
}
const mio_bch_t* mio_httpmethodtombs (mio_http_method_t type)
const mio_bch_t* mio_http_method_to_bcstr (mio_http_method_t type)
{
/* keep this table in the same order as mio_httpd_method_t enumerators */
static mio_bch_t* names[] =
@ -151,7 +152,7 @@ mio_http_method_t mio_bcstr_to_http_method (const mio_bch_t* name)
mid = left + (right - left) / 2;
entry = &mtab[mid];
n = mio_comp_bcstr(name, entry->name);
n = mio_comp_bcstr(name, entry->name, 1);
if (n < 0)
{
/* if left, right, mid were of mio_oow_t,
@ -184,7 +185,7 @@ mio_http_method_t mio_bchars_to_http_method (const mio_bch_t* nameptr, mio_oow_t
mid = left + (right - left) / 2;
entry = &mtab[mid];
n = mio_mbsxcmp(nameptr, namelen, entry->name);
n = mio_comp_bchars_bcstr(nameptr, namelen, entry->name, 1);
if (n < 0)
{
/* if left, right, mid were of mio_oow_t,
@ -218,21 +219,21 @@ int mio_parse_http_range_bcstr (const mio_bch_t* str, mio_http_range_t* range)
str += 6;
from = 0;
if (MIO_ISMDIGIT(*str))
if (mio_is_bch_digit(*str))
{
do
{
from = from * 10 + (*str - '0');
str++;
}
while (MIO_ISMDIGIT(*str));
while (mio_is_bch_digit(*str));
}
else type = MIO_HTTP_RANGE_SUFFIX;
if (*str != '-') return -1;
str++;
if (MIO_ISMDIGIT(*str))
if (mio_is_bch_digit(*str))
{
to = 0;
do
@ -240,7 +241,7 @@ int mio_parse_http_range_bcstr (const mio_bch_t* str, mio_http_range_t* range)
to = to * 10 + (*str - '0');
str++;
}
while (MIO_ISMDIGIT(*str));
while (mio_is_bch_digit(*str));
}
else to = MIO_TYPE_MAX(mio_http_range_int_t);
@ -288,7 +289,7 @@ static mname_t mon_name[] =
int mio_parse_http_time_bcstr (const mio_bch_t* str, mio_ntime_t* nt)
{
mio_btime_t bt;
struct tm bt;
const mio_bch_t* word;
mio_oow_t wlen, i;
@ -297,98 +298,108 @@ int mio_parse_http_time_bcstr (const mio_bch_t* str, mio_ntime_t* nt)
MIO_MEMSET (&bt, 0, MIO_SIZEOF(bt));
/* weekday */
while (MIO_ISMSPACE(*str)) str++;
for (word = str; MIO_ISMALPHA(*str); str++);
while (mio_is_bch_space(*str)) str++;
for (word = str; mio_is_bch_alpha(*str); str++);
wlen = str - word;
for (i = 0; i < MIO_COUNTOF(wday_name); i++)
{
if (mio_mbsxcmp(word, wlen, wday_name[i].s) == 0)
if (mio_comp_bchars_bcstr(word, wlen, wday_name[i].s, 1) == 0)
{
bt.wday = i;
bt.tm_wday = i;
break;
}
}
if (i >= MIO_COUNTOF(wday_name)) return -1;
/* comma - i'm just loose as i don't care if it doesn't exist */
while (MIO_ISMSPACE(*str)) str++;
while (mio_is_bch_space(*str)) str++;
if (*str == ',') str++;
/* day */
while (MIO_ISMSPACE(*str)) str++;
if (!MIO_ISMDIGIT(*str)) return -1;
do bt.mday = bt.mday * 10 + *str++ - '0'; while (MIO_ISMDIGIT(*str));
while (mio_is_bch_space(*str)) str++;
if (!mio_is_bch_digit(*str)) return -1;
do bt.tm_mday = bt.tm_mday * 10 + *str++ - '0'; while (mio_is_bch_digit(*str));
/* month */
while (MIO_ISMSPACE(*str)) str++;
for (word = str; MIO_ISMALPHA(*str); str++);
while (mio_is_bch_space(*str)) str++;
for (word = str; mio_is_bch_alpha(*str); str++);
wlen = str - word;
for (i = 0; i < MIO_COUNTOF(mon_name); i++)
{
if (mio_mbsxcmp(word, wlen, mon_name[i].s) == 0)
if (mio_comp_bchars_bcstr(word, wlen, mon_name[i].s, 1) == 0)
{
bt.mon = i;
bt.tm_mon = i;
break;
}
}
if (i >= MIO_COUNTOF(mon_name)) return -1;
/* year */
while (MIO_ISMSPACE(*str)) str++;
if (!MIO_ISMDIGIT(*str)) return -1;
do bt.year = bt.year * 10 + *str++ - '0'; while (MIO_ISMDIGIT(*str));
bt.year -= MIO_BTIME_YEAR_BASE;
while (mio_is_bch_space(*str)) str++;
if (!mio_is_bch_digit(*str)) return -1;
do bt.tm_year = bt.tm_year * 10 + *str++ - '0'; while (mio_is_bch_digit(*str));
bt.tm_year -= 1900;
/* hour */
while (MIO_ISMSPACE(*str)) str++;
if (!MIO_ISMDIGIT(*str)) return -1;
do bt.hour = bt.hour * 10 + *str++ - '0'; while (MIO_ISMDIGIT(*str));
while (mio_is_bch_space(*str)) str++;
if (!mio_is_bch_digit(*str)) return -1;
do bt.tm_hour = bt.tm_hour * 10 + *str++ - '0'; while (mio_is_bch_digit(*str));
if (*str != ':') return -1;
str++;
/* min */
while (MIO_ISMSPACE(*str)) str++;
if (!MIO_ISMDIGIT(*str)) return -1;
do bt.min = bt.min * 10 + *str++ - '0'; while (MIO_ISMDIGIT(*str));
while (mio_is_bch_space(*str)) str++;
if (!mio_is_bch_digit(*str)) return -1;
do bt.tm_min = bt.tm_min * 10 + *str++ - '0'; while (mio_is_bch_digit(*str));
if (*str != ':') return -1;
str++;
/* sec */
while (MIO_ISMSPACE(*str)) str++;
if (!MIO_ISMDIGIT(*str)) return -1;
do bt.sec = bt.sec * 10 + *str++ - '0'; while (MIO_ISMDIGIT(*str));
while (mio_is_bch_space(*str)) str++;
if (!mio_is_bch_digit(*str)) return -1;
do bt.tm_sec = bt.tm_sec * 10 + *str++ - '0'; while (mio_is_bch_digit(*str));
/* GMT */
while (MIO_ISMSPACE(*str)) str++;
for (word = str; MIO_ISMALPHA(*str); str++);
while (mio_is_bch_space(*str)) str++;
for (word = str; mio_is_bch_alpha(*str); str++);
wlen = str - word;
if (mio_mbsxcmp(word, wlen, "GMT") != 0) return -1;
if (mio_comp_bchars_bcstr(word, wlen, "GMT", 1) != 0) return -1;
while (MIO_ISMSPACE(*str)) str++;
while (mio_is_bch_space(*str)) str++;
if (*str != '\0') return -1;
return mio_timegm(&bt, nt);
nt->sec = timegm(&bt);
nt->nsec = 0;
return 0;
}
mio_bch_t* mio_fmthttptime (const mio_ntime_t* nt, mio_bch_t* buf, mio_oow_t bufsz)
mio_bch_t* mio_fmt_http_time_to_bcstr (const mio_ntime_t* nt, mio_bch_t* buf, mio_oow_t bufsz)
{
mio_btime_t bt;
time_t t;
struct tm bt;
mio_gmtime (nt, &bt);
t = nt->sec;
gmtime_r (&t, &bt);
mio_mbsxfmt (
buf, bufsz,
"%s, %d %s %d %02d:%02d:%02d GMT",
wday_name[bt.wday].s,
bt.mday,
mon_name[bt.mon].s,
bt.year + MIO_BTIME_YEAR_BASE,
bt.hour, bt.min, bt.sec
/* mio_fmttobcstr() works well with MIO_NULL in mio if formatting doesn't involve cross-encoding */
mio_fmttobcstr (MIO_NULL, buf, bufsz,
"%hs, %d %hs %d %02d:%02d:%02d GMT",
wday_name[bt.tm_wday].s,
bt.tm_mday,
mon_name[bt.tm_mon].s,
bt.tm_year + 1900,
bt.tm_hour, bt.tm_min, bt.tm_sec
);
return buf;
}
#define XDIGIT_TO_NUM(c) \
(((c) >= '0' && (c) <= '9')? ((c) - '0'): \
((c) >= 'A' && (c) <= 'F')? ((c) - 'A' + 10): \
((c) >= 'a' && (c) <= 'f')? ((c) - 'a' + 10): -1)
int mio_is_perenced_http_bcstr (const mio_bch_t* str)
{
const mio_bch_t* p = str;
@ -397,11 +408,11 @@ int mio_is_perenced_http_bcstr (const mio_bch_t* str)
{
if (*p == '%' && *(p + 1) != '\0' && *(p + 2) != '\0')
{
int q = MIO_MXDIGITTONUM (*(p + 1));
int q = XDIGIT_TO_NUM(*(p + 1));
if (q >= 0)
{
/* return true if the first valid percent-encoded sequence is found */
int w = MIO_MXDIGITTONUM (*(p + 2));
int w = XDIGIT_TO_NUM(*(p + 2));
if (w >= 0) return 1;
}
}
@ -422,10 +433,10 @@ mio_oow_t mio_perdechttpstr (const mio_bch_t* str, mio_bch_t* buf, mio_oow_t* nd
{
if (*p == '%' && *(p + 1) != '\0' && *(p + 2) != '\0')
{
int q = MIO_MXDIGITTONUM (*(p + 1));
int q = XDIGIT_TO_NUM(*(p + 1));
if (q >= 0)
{
int w = MIO_MXDIGITTONUM (*(p + 2));
int w = XDIGIT_TO_NUM(*(p + 2));
if (w >= 0)
{
/* we don't care if it contains a null character */

370
mio/lib/mio-chr.h Normal file
View File

@ -0,0 +1,370 @@
/*
* $Id$
*
Copyright (c) 2006-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _MIO_CHR_H_
#define _MIO_CHR_H_
#include <mio-cmn.h>
enum mio_ooch_prop_t
{
MIO_OOCH_PROP_UPPER = (1 << 0),
#define MIO_UCH_PROP_UPPER MIO_OOCH_PROP_UPPER
#define MIO_BCH_PROP_UPPER MIO_OOCH_PROP_UPPER
MIO_OOCH_PROP_LOWER = (1 << 1),
#define MIO_UCH_PROP_LOWER MIO_OOCH_PROP_LOWER
#define MIO_BCH_PROP_LOWER MIO_OOCH_PROP_LOWER
MIO_OOCH_PROP_ALPHA = (1 << 2),
#define MIO_UCH_PROP_ALPHA MIO_OOCH_PROP_ALPHA
#define MIO_BCH_PROP_ALPHA MIO_OOCH_PROP_ALPHA
MIO_OOCH_PROP_DIGIT = (1 << 3),
#define MIO_UCH_PROP_DIGIT MIO_OOCH_PROP_DIGIT
#define MIO_BCH_PROP_DIGIT MIO_OOCH_PROP_DIGIT
MIO_OOCH_PROP_XDIGIT = (1 << 4),
#define MIO_UCH_PROP_XDIGIT MIO_OOCH_PROP_XDIGIT
#define MIO_BCH_PROP_XDIGIT MIO_OOCH_PROP_XDIGIT
MIO_OOCH_PROP_ALNUM = (1 << 5),
#define MIO_UCH_PROP_ALNUM MIO_OOCH_PROP_ALNUM
#define MIO_BCH_PROP_ALNUM MIO_OOCH_PROP_ALNUM
MIO_OOCH_PROP_SPACE = (1 << 6),
#define MIO_UCH_PROP_SPACE MIO_OOCH_PROP_SPACE
#define MIO_BCH_PROP_SPACE MIO_OOCH_PROP_SPACE
MIO_OOCH_PROP_PRINT = (1 << 8),
#define MIO_UCH_PROP_PRINT MIO_OOCH_PROP_PRINT
#define MIO_BCH_PROP_PRINT MIO_OOCH_PROP_PRINT
MIO_OOCH_PROP_GRAPH = (1 << 9),
#define MIO_UCH_PROP_GRAPH MIO_OOCH_PROP_GRAPH
#define MIO_BCH_PROP_GRAPH MIO_OOCH_PROP_GRAPH
MIO_OOCH_PROP_CNTRL = (1 << 10),
#define MIO_UCH_PROP_CNTRL MIO_OOCH_PROP_CNTRL
#define MIO_BCH_PROP_CNTRL MIO_OOCH_PROP_CNTRL
MIO_OOCH_PROP_PUNCT = (1 << 11),
#define MIO_UCH_PROP_PUNCT MIO_OOCH_PROP_PUNCT
#define MIO_BCH_PROP_PUNCT MIO_OOCH_PROP_PUNCT
MIO_OOCH_PROP_BLANK = (1 << 12)
#define MIO_UCH_PROP_BLANK MIO_OOCH_PROP_BLANK
#define MIO_BCH_PROP_BLANK MIO_OOCH_PROP_BLANK
};
typedef enum mio_ooch_prop_t mio_ooch_prop_t;
typedef enum mio_ooch_prop_t mio_uch_prop_t;
typedef enum mio_ooch_prop_t mio_bch_prop_t;
#if defined(__cplusplus)
extern "C" {
#endif
MIO_EXPORT int mio_is_uch_type (mio_uch_t c, mio_uch_prop_t type);
MIO_EXPORT int mio_is_uch_upper (mio_uch_t c);
MIO_EXPORT int mio_is_uch_lower (mio_uch_t c);
MIO_EXPORT int mio_is_uch_alpha (mio_uch_t c);
MIO_EXPORT int mio_is_uch_digit (mio_uch_t c);
MIO_EXPORT int mio_is_uch_xdigit (mio_uch_t c);
MIO_EXPORT int mio_is_uch_alnum (mio_uch_t c);
MIO_EXPORT int mio_is_uch_space (mio_uch_t c);
MIO_EXPORT int mio_is_uch_print (mio_uch_t c);
MIO_EXPORT int mio_is_uch_graph (mio_uch_t c);
MIO_EXPORT int mio_is_uch_cntrl (mio_uch_t c);
MIO_EXPORT int mio_is_uch_punct (mio_uch_t c);
MIO_EXPORT int mio_is_uch_blank (mio_uch_t c);
MIO_EXPORT mio_uch_t mio_to_uch_upper (mio_uch_t c);
MIO_EXPORT mio_uch_t mio_to_uch_lower (mio_uch_t c);
/* ------------------------------------------------------------------------- */
MIO_EXPORT int mio_is_bch_type (mio_bch_t c, mio_bch_prop_t type);
#if defined(__has_builtin)
# if __has_builtin(__builtin_isupper)
# define mio_is_bch_upper __builtin_isupper
# endif
# if __has_builtin(__builtin_islower)
# define mio_is_bch_lower __builtin_islower
# endif
# if __has_builtin(__builtin_isalpha)
# define mio_is_bch_alpha __builtin_isalpha
# endif
# if __has_builtin(__builtin_isdigit)
# define mio_is_bch_digit __builtin_isdigit
# endif
# if __has_builtin(__builtin_isxdigit)
# define mio_is_bch_xdigit __builtin_isxdigit
# endif
# if __has_builtin(__builtin_isalnum)
# define mio_is_bch_alnum __builtin_isalnum
# endif
# if __has_builtin(__builtin_isspace)
# define mio_is_bch_space __builtin_isspace
# endif
# if __has_builtin(__builtin_isprint)
# define mio_is_bch_print __builtin_isprint
# endif
# if __has_builtin(__builtin_isgraph)
# define mio_is_bch_graph __builtin_isgraph
# endif
# if __has_builtin(__builtin_iscntrl)
# define mio_is_bch_cntrl __builtin_iscntrl
# endif
# if __has_builtin(__builtin_ispunct)
# define mio_is_bch_punct __builtin_ispunct
# endif
# if __has_builtin(__builtin_isblank)
# define mio_is_bch_blank __builtin_isblank
# endif
# if __has_builtin(__builtin_toupper)
# define mio_to_bch_upper __builtin_toupper
# endif
# if __has_builtin(__builtin_tolower)
# define mio_to_bch_lower __builtin_tolower
# endif
#elif (__GNUC__ >= 14)
# define mio_is_bch_upper __builtin_isupper
# define mio_is_bch_lower __builtin_islower
# define mio_is_bch_alpha __builtin_isalpha
# define mio_is_bch_digit __builtin_isdigit
# define mio_is_bch_xdigit __builtin_isxdigit
# define mio_is_bch_alnum __builtin_isalnum
# define mio_is_bch_space __builtin_isspace
# define mio_is_bch_print __builtin_isprint
# define mio_is_bch_graph __builtin_isgraph
# define mio_is_bch_cntrl __builtin_iscntrl
# define mio_is_bch_punct __builtin_ispunct
# define mio_is_bch_blank __builtin_isblank
# define mio_to_bch_upper __builtin_toupper
# define mio_to_bch_lower __builtin_tolower
#endif
/* the bch class functions support no locale.
* these implemenent latin-1 only */
#if !defined(mio_is_bch_upper) && defined(MIO_HAVE_INLINE)
static MIO_INLINE int mio_is_bch_upper (mio_bch_t c) { return (mio_bcu_t)c - 'A' < 26; }
#elif !defined(mio_is_bch_upper)
# define mio_is_bch_upper(c) ((mio_bcu_t)(c) - 'A' < 26)
#endif
#if !defined(mio_is_bch_lower) && defined(MIO_HAVE_INLINE)
static MIO_INLINE int mio_is_bch_lower (mio_bch_t c) { return (mio_bcu_t)c - 'a' < 26; }
#elif !defined(mio_is_bch_lower)
# define mio_is_bch_lower(c) ((mio_bcu_t)(c) - 'a' < 26)
#endif
#if !defined(mio_is_bch_alpha) && defined(MIO_HAVE_INLINE)
static MIO_INLINE int mio_is_bch_alpha (mio_bch_t c) { return ((mio_bcu_t)c | 32) - 'a' < 26; }
#elif !defined(mio_is_bch_alpha)
# define mio_is_bch_alpha(c) (((mio_bcu_t)(c) | 32) - 'a' < 26)
#endif
#if !defined(mio_is_bch_digit) && defined(MIO_HAVE_INLINE)
static MIO_INLINE int mio_is_bch_digit (mio_bch_t c) { return (mio_bcu_t)c - '0' < 10; }
#elif !defined(mio_is_bch_digit)
# define mio_is_bch_digit(c) ((mio_bcu_t)(c) - '0' < 10)
#endif
#if !defined(mio_is_bch_xdigit) && defined(MIO_HAVE_INLINE)
static MIO_INLINE int mio_is_bch_xdigit (mio_bch_t c) { return mio_is_bch_digit(c) || ((mio_bcu_t)c | 32) - 'a' < 6; }
#elif !defined(mio_is_bch_xdigit)
# define mio_is_bch_xdigit(c) (mio_is_bch_digit(c) || ((mio_bcu_t)(c) | 32) - 'a' < 6)
#endif
#if !defined(mio_is_bch_alnum) && defined(MIO_HAVE_INLINE)
static MIO_INLINE int mio_is_bch_alnum (mio_bch_t c) { return mio_is_bch_alpha(c) || mio_is_bch_digit(c); }
#elif !defined(mio_is_bch_alnum)
# define mio_is_bch_alnum(c) (mio_is_bch_alpha(c) || mio_is_bch_digit(c))
#endif
#if !defined(mio_is_bch_space) && defined(MIO_HAVE_INLINE)
static MIO_INLINE int mio_is_bch_space (mio_bch_t c) { return c == ' ' || (mio_bcu_t)c - '\t' < 5; }
#elif !defined(mio_is_bch_space)
# define mio_is_bch_space(c) ((c) == ' ' || (mio_bcu_t)(c) - '\t' < 5)
#endif
#if !defined(mio_is_bch_print) && defined(MIO_HAVE_INLINE)
static MIO_INLINE int mio_is_bch_print (mio_bch_t c) { return (mio_bcu_t)c - ' ' < 95; }
#elif !defined(mio_is_bch_print)
# define mio_is_bch_print(c) ((mio_bcu_t)(c) - ' ' < 95)
#endif
#if !defined(mio_is_bch_graph) && defined(MIO_HAVE_INLINE)
static MIO_INLINE int mio_is_bch_graph (mio_bch_t c) { return (mio_bcu_t)c - '!' < 94; }
#elif !defined(mio_is_bch_graph)
# define mio_is_bch_graph(c) ((mio_bcu_t)(c) - '!' < 94)
#endif
#if !defined(mio_is_bch_cntrl) && defined(MIO_HAVE_INLINE)
static MIO_INLINE int mio_is_bch_cntrl (mio_bch_t c) { return (mio_bcu_t)c < ' ' || (mio_bcu_t)c == 127; }
#elif !defined(mio_is_bch_cntrl)
# define mio_is_bch_cntrl(c) ((mio_bcu_t)(c) < ' ' || (mio_bcu_t)(c) == 127)
#endif
#if !defined(mio_is_bch_punct) && defined(MIO_HAVE_INLINE)
static MIO_INLINE int mio_is_bch_punct (mio_bch_t c) { return mio_is_bch_graph(c) && !mio_is_bch_alnum(c); }
#elif !defined(mio_is_bch_punct)
# define mio_is_bch_punct(c) (mio_is_bch_graph(c) && !mio_is_bch_alnum(c))
#endif
#if !defined(mio_is_bch_blank) && defined(MIO_HAVE_INLINE)
static MIO_INLINE int mio_is_bch_blank (mio_bch_t c) { return c == ' ' || c == '\t'; }
#elif !defined(mio_is_bch_blank)
# define mio_is_bch_blank(c) ((c) == ' ' || (c) == '\t')
#endif
#if !defined(mio_to_bch_upper)
MIO_EXPORT mio_bch_t mio_to_bch_upper (mio_bch_t c);
#endif
#if !defined(mio_to_bch_lower)
MIO_EXPORT mio_bch_t mio_to_bch_lower (mio_bch_t c);
#endif
#if defined(MIO_OOCH_IS_UCH)
# define mio_is_ooch_type mio_is_uch_type
# define mio_is_ooch_upper mio_is_uch_upper
# define mio_is_ooch_lower mio_is_uch_lower
# define mio_is_ooch_alpha mio_is_uch_alpha
# define mio_is_ooch_digit mio_is_uch_digit
# define mio_is_ooch_xdigit mio_is_uch_xdigit
# define mio_is_ooch_alnum mio_is_uch_alnum
# define mio_is_ooch_space mio_is_uch_space
# define mio_is_ooch_print mio_is_uch_print
# define mio_is_ooch_graph mio_is_uch_graph
# define mio_is_ooch_cntrl mio_is_uch_cntrl
# define mio_is_ooch_punct mio_is_uch_punct
# define mio_is_ooch_blank mio_is_uch_blank
# define mio_to_ooch_upper mio_to_uch_upper
# define mio_to_ooch_lower mio_to_uch_lower
#else
# define mio_is_ooch_type mio_is_bch_type
# define mio_is_ooch_upper mio_is_bch_upper
# define mio_is_ooch_lower mio_is_bch_lower
# define mio_is_ooch_alpha mio_is_bch_alpha
# define mio_is_ooch_digit mio_is_bch_digit
# define mio_is_ooch_xdigit mio_is_bch_xdigit
# define mio_is_ooch_alnum mio_is_bch_alnum
# define mio_is_ooch_space mio_is_bch_space
# define mio_is_ooch_print mio_is_bch_print
# define mio_is_ooch_graph mio_is_bch_graph
# define mio_is_ooch_cntrl mio_is_bch_cntrl
# define mio_is_ooch_punct mio_is_bch_punct
# define mio_is_ooch_blank mio_is_bch_blank
# define mio_to_ooch_upper mio_to_bch_upper
# define mio_to_ooch_lower mio_to_bch_lower
#endif
MIO_EXPORT int mio_ucstr_to_uch_prop (
const mio_uch_t* name,
mio_uch_prop_t* id
);
MIO_EXPORT int mio_uchars_to_uch_prop (
const mio_uch_t* name,
mio_oow_t len,
mio_uch_prop_t* id
);
MIO_EXPORT int mio_bcstr_to_bch_prop (
const mio_bch_t* name,
mio_bch_prop_t* id
);
MIO_EXPORT int mio_bchars_to_bch_prop (
const mio_bch_t* name,
mio_oow_t len,
mio_bch_prop_t* id
);
#if defined(MIO_OOCH_IS_UCH)
# define mio_oocstr_to_ooch_prop mio_ucstr_to_uch_prop
# define mio_oochars_to_ooch_prop mio_uchars_to_uch_prop
#else
# define mio_oocstr_to_ooch_prop mio_bcstr_to_bch_prop
# define mio_oochars_to_ooch_prop mio_bchars_to_bch_prop
#endif
/* ------------------------------------------------------------------------- */
MIO_EXPORT int mio_get_ucwidth (
mio_uch_t uc
);
/* ------------------------------------------------------------------------- */
MIO_EXPORT mio_oow_t mio_uc_to_utf8 (
mio_uch_t uc,
mio_bch_t* utf8,
mio_oow_t size
);
MIO_EXPORT mio_oow_t mio_utf8_to_uc (
const mio_bch_t* utf8,
mio_oow_t size,
mio_uch_t* uc
);
/* ------------------------------------------------------------------------- */
MIO_EXPORT mio_oow_t mio_uc_to_utf16 (
mio_uch_t uc,
mio_bch_t* utf16,
mio_oow_t size
);
MIO_EXPORT mio_oow_t mio_utf16_to_uc (
const mio_bch_t* utf16,
mio_oow_t size,
mio_uch_t* uc
);
/* ------------------------------------------------------------------------- */
MIO_EXPORT mio_oow_t mio_uc_to_mb8 (
mio_uch_t uc,
mio_bch_t* mb8,
mio_oow_t size
);
MIO_EXPORT mio_oow_t mio_mb8_to_uc (
const mio_bch_t* mb8,
mio_oow_t size,
mio_uch_t* uc
);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -101,7 +101,7 @@ typedef mio_oow_t (*mio_uecs_sizer_t) (
*/
struct mio_becs_t
{
mio_t* gem;
mio_t* mio;
mio_becs_sizer_t sizer; /**< buffer resizer function */
mio_bcs_t val; /**< buffer/string pointer and lengh */
mio_oow_t capa; /**< buffer capacity */
@ -112,7 +112,7 @@ struct mio_becs_t
*/
struct mio_uecs_t
{
mio_t* gem;
mio_t* mio;
mio_uecs_sizer_t sizer; /**< buffer resizer function */
mio_ucs_t val; /**< buffer/string pointer and lengh */
mio_oow_t capa; /**< buffer capacity */
@ -127,7 +127,7 @@ extern "C" {
* The mio_becs_open() function creates a dynamically resizable multibyte string.
*/
MIO_EXPORT mio_becs_t* mio_becs_open (
mio_t* gem,
mio_t* mio,
mio_oow_t xtnsize,
mio_oow_t capa
);
@ -144,7 +144,7 @@ MIO_EXPORT void mio_becs_close (
*/
MIO_EXPORT int mio_becs_init (
mio_becs_t* becs,
mio_t* gem,
mio_t* mio,
mio_oow_t capa
);
@ -341,7 +341,7 @@ MIO_EXPORT mio_oow_t mio_becs_fmt (
* The mio_uecs_open() function creates a dynamically resizable multibyte string.
*/
MIO_EXPORT mio_uecs_t* mio_uecs_open (
mio_t* gem,
mio_t* mio,
mio_oow_t xtnsize,
mio_oow_t capa
);
@ -358,7 +358,7 @@ MIO_EXPORT void mio_uecs_close (
*/
MIO_EXPORT int mio_uecs_init (
mio_uecs_t* uecs,
mio_t* gem,
mio_t* mio,
mio_oow_t capa
);
@ -526,7 +526,6 @@ MIO_EXPORT mio_oow_t mio_uecs_amend (
const mio_uch_t* repl
);
#if 0
MIO_EXPORT mio_oow_t mio_uecs_vfcat (
mio_uecs_t* str,
const mio_uch_t* fmt,
@ -550,7 +549,6 @@ MIO_EXPORT mio_oow_t mio_uecs_fmt (
const mio_uch_t* fmt,
...
);
#endif
#if defined(MIO_OOCH_IS_UCH)
# define mio_ooecs_open mio_uecs_open
@ -577,12 +575,11 @@ MIO_EXPORT mio_oow_t mio_uecs_fmt (
# define mio_ooecs_nccat mio_uecs_nccat
# define mio_ooecs_del mio_uecs_del
# define mio_ooecs_amend mio_uecs_amend
#if 0
# define mio_ooecs_vfcat mio_uecs_vfcat
# define mio_ooecs_fcat mio_uecs_fcat
# define mio_ooecs_vfmt mio_uecs_vfmt
# define mio_ooecs_fmt mio_uecs_fmt
#endif
#else
# define mio_ooecs_open mio_becs_open
# define mio_ooecs_close mio_becs_close
@ -609,12 +606,10 @@ MIO_EXPORT mio_oow_t mio_uecs_fmt (
# define mio_ooecs_del mio_becs_del
# define mio_ooecs_amend mio_becs_amend
#if 0
# define mio_ooecs_vfcat mio_becs_vfcat
# define mio_ooecs_fcat mio_becs_fcat
# define mio_ooecs_vfmt mio_becs_vfmt
# define mio_ooecs_fmt mio_becs_fmt
#endif
#endif

View File

@ -39,13 +39,13 @@
* ========================================================================= */
typedef struct mio_fmtout_t mio_fmtout_t;
typedef int (*mio_fmtout_putbcs_t) (
typedef int (*mio_fmtout_putbchars_t) (
mio_fmtout_t* fmtout,
const mio_bch_t* ptr,
mio_oow_t len
);
typedef int (*mio_fmtout_putucs_t) (
typedef int (*mio_fmtout_putuchars_t) (
mio_fmtout_t* fmtout,
const mio_uch_t* ptr,
mio_oow_t len
@ -63,11 +63,13 @@ struct mio_fmtout_t
{
mio_oow_t count; /* out */
mio_fmtout_putbcs_t putbcs; /* in */
mio_fmtout_putucs_t putucs; /* in */
mio_bitmask_t mask; /* in */
void* ctx; /* in */
//mio_mmgr_t* mmgr;
mio_fmtout_putbchars_t putbchars; /* in */
mio_fmtout_putuchars_t putuchars; /* in */
mio_bitmask_t mask; /* in */
void* ctx; /* in */
/* internally set a input */
mio_fmtout_fmt_type_t fmt_type;
const void* fmt_str;
};

View File

@ -163,16 +163,16 @@ typedef enum mio_perenchttpstr_opt_t mio_perenchttpstr_opt_t;
extern "C" {
#endif
MIO_EXPORT int mio_comparehttpversions (
MIO_EXPORT int mio_comp_http_versions (
const mio_http_version_t* v1,
const mio_http_version_t* v2
);
MIO_EXPORT const mio_bch_t* mio_httpstatustombs (
MIO_EXPORT const mio_bch_t* mio_http_status_to_bcstr (
int code
);
MIO_EXPORT const mio_bch_t* mio_httpmethodtombs (
MIO_EXPORT const mio_bch_t* mio_http_method_to_bcstr (
mio_http_method_t type
);
@ -195,7 +195,7 @@ MIO_EXPORT int mio_parse_http_time_bcstr (
mio_ntime_t* nt
);
MIO_EXPORT mio_bch_t* mio_fmthttptime (
MIO_EXPORT mio_bch_t* mio_fmt_http_time_to_bcstr (
const mio_ntime_t* nt,
mio_bch_t* buf,
mio_oow_t bufsz

View File

@ -250,53 +250,62 @@ MIO_EXPORT int mio_comp_uchars (
const mio_uch_t* str1,
mio_oow_t len1,
const mio_uch_t* str2,
mio_oow_t len2
mio_oow_t len2,
int ignorecase
);
MIO_EXPORT int mio_comp_bchars (
const mio_bch_t* str1,
mio_oow_t len1,
const mio_bch_t* str2,
mio_oow_t len2
mio_oow_t len2,
int ignorecase
);
MIO_EXPORT int mio_comp_ucstr (
const mio_uch_t* str1,
const mio_uch_t* str2
const mio_uch_t* str2,
int ignorecase
);
MIO_EXPORT int mio_comp_bcstr (
const mio_bch_t* str1,
const mio_bch_t* str2
const mio_bch_t* str2,
int ignorecase
);
MIO_EXPORT int mio_comp_ucstr_bcstr (
const mio_uch_t* str1,
const mio_bch_t* str2
const mio_bch_t* str2,
int ignorecase
);
MIO_EXPORT int mio_comp_uchars_ucstr (
const mio_uch_t* str1,
mio_oow_t len,
const mio_uch_t* str2
const mio_uch_t* str2,
int ignorecase
);
MIO_EXPORT int mio_comp_uchars_bcstr (
const mio_uch_t* str1,
mio_oow_t len,
const mio_bch_t* str2
const mio_bch_t* str2,
int ignorecase
);
MIO_EXPORT int mio_comp_bchars_bcstr (
const mio_bch_t* str1,
mio_oow_t len,
const mio_bch_t* str2
const mio_bch_t* str2,
int ignorecase
);
MIO_EXPORT int mio_comp_bchars_ucstr (
const mio_bch_t* str1,
mio_oow_t len,
const mio_uch_t* str2
const mio_uch_t* str2,
int ignorecase
);
MIO_EXPORT void mio_copy_uchars (

View File

@ -25,6 +25,7 @@
*/
#include "mio-prv.h"
#include "mio-fmt.h"
#include <stdlib.h>
#define DEV_CAP_ALL_WATCHED (MIO_DEV_CAP_IN_WATCHED | MIO_DEV_CAP_OUT_WATCHED | MIO_DEV_CAP_PRI_WATCHED)
@ -1573,3 +1574,191 @@ void mio_freemem (mio_t* mio, void* ptr)
{
MIO_MMGR_FREE (mio->_mmgr, ptr);
}
/* ------------------------------------------------------------------------ */
struct fmt_uch_buf_t
{
mio_t* mio;
mio_uch_t* ptr;
mio_oow_t len;
mio_oow_t capa;
};
typedef struct fmt_uch_buf_t fmt_uch_buf_t;
static int fmt_put_bchars_to_uch_buf (mio_fmtout_t* fmtout, const mio_bch_t* ptr, mio_oow_t len)
{
fmt_uch_buf_t* b = (fmt_uch_buf_t*)fmtout->ctx;
mio_oow_t bcslen, ucslen;
int n;
if (!b->mio) return -1; /* no mio, no cross encoding formatting */
bcslen = len;
ucslen = b->capa - b->len;
n = mio_conv_bchars_to_uchars_with_cmgr(ptr, &bcslen, &b->ptr[b->len], &ucslen, b->mio->_cmgr, 1);
b->len += ucslen;
if (n <= -1)
{
if (n == -2)
{
return 0; /* buffer full. stop */
}
else
{
if (b->mio) mio_seterrnum (b->mio, MIO_EECERR);
return -1;
}
}
return 1; /* success. carry on */
}
static int fmt_put_uchars_to_uch_buf (mio_fmtout_t* fmtout, const mio_uch_t* ptr, mio_oow_t len)
{
fmt_uch_buf_t* b = (fmt_uch_buf_t*)fmtout->ctx;
mio_oow_t n;
/* this function null-terminates the destination. so give the restored buffer size */
n = mio_copy_uchars_to_ucstr(&b->ptr[b->len], b->capa - b->len + 1, ptr, len);
b->len += n;
if (n < len)
{
if (b->mio) mio_seterrnum (b->mio, MIO_EBUFFULL);
return 0; /* stop. insufficient buffer */
}
return 1; /* success */
}
mio_oow_t mio_vfmttoucstr (mio_t* mio, mio_uch_t* buf, mio_oow_t bufsz, const mio_uch_t* fmt, va_list ap)
{
mio_fmtout_t fo;
fmt_uch_buf_t fb;
if (bufsz <= 0) return 0;
MIO_MEMSET (&fo, 0, MIO_SIZEOF(fo));
//fo.mmgr = mio->mmgr;
fo.putbchars = fmt_put_bchars_to_uch_buf;
fo.putuchars = fmt_put_uchars_to_uch_buf;
fo.ctx = &fb;
MIO_MEMSET (&fb, 0, MIO_SIZEOF(fb));
fb.mio = mio;
fb.ptr = buf;
fb.capa = bufsz - 1;
if (mio_ufmt_outv(&fo, fmt, ap) <= -1) return -1;
buf[fb.len] = '\0';
return fb.len;
}
mio_oow_t mio_fmttoucstr (mio_t* mio, mio_uch_t* buf, mio_oow_t bufsz, const mio_uch_t* fmt, ...)
{
mio_oow_t x;
va_list ap;
va_start (ap, fmt);
x = mio_vfmttoucstr(mio, buf, bufsz, fmt, ap);
va_end (ap);
return x;
}
/* ------------------------------------------------------------------------ */
struct fmt_bch_buf_t
{
mio_t* mio;
mio_bch_t* ptr;
mio_oow_t len;
mio_oow_t capa;
};
typedef struct fmt_bch_buf_t fmt_bch_buf_t;
static int fmt_put_bchars_to_bch_buf (mio_fmtout_t* fmtout, const mio_bch_t* ptr, mio_oow_t len)
{
fmt_bch_buf_t* b = (fmt_bch_buf_t*)fmtout->ctx;
mio_oow_t n;
/* this function null-terminates the destination. so give the restored buffer size */
n = mio_copy_bchars_to_bcstr(&b->ptr[b->len], b->capa - b->len + 1, ptr, len);
b->len += n;
if (n < len)
{
if (b->mio) mio_seterrnum (b->mio, MIO_EBUFFULL);
return 0; /* stop. insufficient buffer */
}
return 1; /* success */
}
static int fmt_put_uchars_to_bch_buf (mio_fmtout_t* fmtout, const mio_uch_t* ptr, mio_oow_t len)
{
fmt_bch_buf_t* b = (fmt_bch_buf_t*)fmtout->ctx;
mio_oow_t bcslen, ucslen;
int n;
if (!b->mio) return -1; /* no mio, no cross encoding formatting */
bcslen = b->capa - b->len;
ucslen = len;
n = mio_conv_uchars_to_bchars_with_cmgr(ptr, &ucslen, &b->ptr[b->len], &bcslen, b->mio->_cmgr);
b->len += bcslen;
if (n <= -1)
{
if (n == -2)
{
return 0; /* buffer full. stop */
}
else
{
if (b->mio) mio_seterrnum (b->mio, MIO_EECERR);
return -1;
}
}
return 1; /* success. carry on */
}
mio_oow_t mio_vfmttobcstr (mio_t* mio, mio_bch_t* buf, mio_oow_t bufsz, const mio_bch_t* fmt, va_list ap)
{
mio_fmtout_t fo;
fmt_bch_buf_t fb;
if (bufsz <= 0) return 0;
MIO_MEMSET (&fo, 0, MIO_SIZEOF(fo));
//fo.mmgr = mio->mmgr;
fo.putbchars = fmt_put_bchars_to_bch_buf;
fo.putuchars = fmt_put_uchars_to_bch_buf;
fo.ctx = &fb;
MIO_MEMSET (&fb, 0, MIO_SIZEOF(fb));
fb.mio = mio;
fb.ptr = buf;
fb.capa = bufsz - 1;
if (mio_bfmt_outv(&fo, fmt, ap) <= -1) return -1;
buf[fb.len] = '\0';
return fb.len;
}
mio_oow_t mio_fmttobcstr (mio_t* mio, mio_bch_t* buf, mio_oow_t bufsz, const mio_bch_t* fmt, ...)
{
mio_oow_t x;
va_list ap;
va_start (ap, fmt);
x = mio_vfmttobcstr(mio, buf, bufsz, fmt, ap);
va_end (ap);
return x;
}
/* ------------------------------------------------------------------------ */

View File

@ -1122,6 +1122,49 @@ MIO_EXPORT mio_bch_t* mio_dupbcstr (
# define mio_dupoocstr(mio,oocs,oocslen) mio_dupbcstr(mio,oocs,oocslen)
#endif
/* =========================================================================
* STRING FORMATTING
* ========================================================================= */
MIO_EXPORT mio_oow_t mio_vfmttoucstr (
mio_t* mio,
mio_uch_t* buf,
mio_oow_t bufsz,
const mio_uch_t* fmt,
va_list ap
);
MIO_EXPORT mio_oow_t mio_fmttoucstr (
mio_t* mio,
mio_uch_t* buf,
mio_oow_t bufsz,
const mio_uch_t* fmt,
...
);
MIO_EXPORT mio_oow_t mio_vfmttobcstr (
mio_t* mio,
mio_bch_t* buf,
mio_oow_t bufsz,
const mio_bch_t* fmt,
va_list ap
);
MIO_EXPORT mio_oow_t mio_fmttobcstr (
mio_t* mio,
mio_bch_t* buf,
mio_oow_t bufsz,
const mio_bch_t* fmt,
...
);
#if defined(MIO_OOCH_IS_UCH)
# define mio_vfmttooocstr mio_vfmttoucstr
# define mio_fmttooocstr mio_fmttoucstr
#else
# define mio_vfmttooocstr mio_vfmttobcstr
# define mio_fmttooocstr mio_fmttobcstr
#endif
/* =========================================================================
* MIO VM LOGGING

View File

@ -188,7 +188,7 @@ int mio_bcstrtoifindex (mio_t* mio, const mio_bch_t* ptr, unsigned int* index)
num = ifc.ifc_len / MIO_SIZEOF(struct ifreq);
for (i = 0; i < num; i++)
{
if (mio_comp_bcstr(ptr, ifc.ifc_req[i].ifr_name) == 0)
if (mio_comp_bcstr(ptr, ifc.ifc_req[i].ifr_name, 0) == 0)
{
free_sco_ifconf (mio, &ifc);
*index = i + 1;
@ -363,7 +363,7 @@ int mio_ucstrtoifindex (mio_t* mio, const mio_uch_t* ptr, unsigned int* index)
num = ifc.ifc_len / MIO_SIZEOF(struct ifreq);
for (i = 0; i < num; i++)
{
if (mio_comp_bcstr(tmp, ifc.ifc_req[i].ifr_name) == 0)
if (mio_comp_bcstr(tmp, ifc.ifc_req[i].ifr_name, 0) == 0)
{
free_sco_ifconf (mio, &ifc);
*index = i + 1;
@ -457,7 +457,7 @@ int mio_ucharstoifindex (mio_t* mio, const mio_uch_t* ptr, mio_oow_t len, unsign
num = ifc.ifc_len / MIO_SIZEOF(struct ifreq);
for (i = 0; i < num; i++)
{
if (mio_comp_bcstr(tmp, ifc.ifc_req[i].ifr_name) == 0)
if (mio_comp_bcstr(tmp, ifc.ifc_req[i].ifr_name, 0) == 0)
{
free_sco_ifconf (mio, &ifc);
*index = i + 1;

View File

@ -1506,7 +1506,7 @@ int mio_equal_skads (const mio_skad_t* addr1, const mio_skad_t* addr2, int stric
#if defined(AF_UNIX) && (MIO_SIZEOF_STRUCT_SOCKADDR_UN > 0)
case AF_UNIX:
return mio_comp_bcstr(((struct sockaddr_un*)addr1)->sun_path, ((struct sockaddr_un*)addr2)->sun_path) == 0;
return mio_comp_bcstr(((struct sockaddr_un*)addr1)->sun_path, ((struct sockaddr_un*)addr2)->sun_path, 0) == 0;
#endif
default:

7367
mio/lib/uch-case.h Normal file

File diff suppressed because it is too large Load Diff

15603
mio/lib/uch-prop.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,7 @@
*/
#include "mio-prv.h"
#include <mio-chr.h>
/* ========================================================================= */
@ -58,73 +59,135 @@ int mio_equal_bchars (const mio_bch_t* str1, const mio_bch_t* str2, mio_oow_t le
return 1;
}
int mio_comp_uchars (const mio_uch_t* str1, mio_oow_t len1, const mio_uch_t* str2, mio_oow_t len2)
int mio_comp_uchars (const mio_uch_t* str1, mio_oow_t len1, const mio_uch_t* str2, mio_oow_t len2, int ignorecase)
{
mio_uchu_t c1, c2;
const mio_uch_t* end1 = str1 + len1;
const mio_uch_t* end2 = str2 + len2;
while (str1 < end1)
if (ignorecase)
{
c1 = *str1;
if (str2 < end2)
while (str1 < end1)
{
c2 = *str2;
if (c1 > c2) return 1;
if (c1 < c2) return -1;
c1 = mio_to_uch_lower(*str1);
if (str2 < end2)
{
c2 = mio_to_uch_lower(*str2);
if (c1 > c2) return 1;
if (c1 < c2) return -1;
}
else return 1;
str1++; str2++;
}
}
else
{
while (str1 < end1)
{
c1 = *str1;
if (str2 < end2)
{
c2 = *str2;
if (c1 > c2) return 1;
if (c1 < c2) return -1;
}
else return 1;
str1++; str2++;
}
else return 1;
str1++; str2++;
}
return (str2 < end2)? -1: 0;
}
int mio_comp_bchars (const mio_bch_t* str1, mio_oow_t len1, const mio_bch_t* str2, mio_oow_t len2)
int mio_comp_bchars (const mio_bch_t* str1, mio_oow_t len1, const mio_bch_t* str2, mio_oow_t len2, int ignorecase)
{
mio_bchu_t c1, c2;
const mio_bch_t* end1 = str1 + len1;
const mio_bch_t* end2 = str2 + len2;
while (str1 < end1)
if (ignorecase)
{
c1 = *str1;
if (str2 < end2)
while (str1 < end1)
{
c2 = *str2;
if (c1 > c2) return 1;
if (c1 < c2) return -1;
c1 = mio_to_bch_lower(*str1);
if (str2 < end2)
{
c2 = mio_to_bch_lower(*str2);
if (c1 > c2) return 1;
if (c1 < c2) return -1;
}
else return 1;
str1++; str2++;
}
}
else
{
while (str1 < end1)
{
c1 = *str1;
if (str2 < end2)
{
c2 = *str2;
if (c1 > c2) return 1;
if (c1 < c2) return -1;
}
else return 1;
str1++; str2++;
}
else return 1;
str1++; str2++;
}
return (str2 < end2)? -1: 0;
}
int mio_comp_ucstr (const mio_uch_t* str1, const mio_uch_t* str2)
int mio_comp_ucstr (const mio_uch_t* str1, const mio_uch_t* str2, int ignorecase)
{
while (*str1 == *str2)
if (ignorecase)
{
if (*str1 == '\0') return 0;
str1++; str2++;
}
while (mio_to_uch_lower(*str1) == mio_to_uch_lower(*str2))
{
if (*str1 == '\0') return 0;
str1++; str2++;
}
return ((mio_uchu_t)*str1 > (mio_uchu_t)*str2)? 1: -1;
return ((mio_uchu_t)mio_to_uch_lower(*str1) > (mio_uchu_t)mio_to_uch_lower(*str2))? 1: -1;
}
else
{
while (*str1 == *str2)
{
if (*str1 == '\0') return 0;
str1++; str2++;
}
return ((mio_uchu_t)*str1 > (mio_uchu_t)*str2)? 1: -1;
}
}
int mio_comp_bcstr (const mio_bch_t* str1, const mio_bch_t* str2)
int mio_comp_bcstr (const mio_bch_t* str1, const mio_bch_t* str2, int ignorecase)
{
while (*str1 == *str2)
if (ignorecase)
{
if (*str1 == '\0') return 0;
str1++; str2++;
}
while (mio_to_bch_lower(*str1) == mio_to_bch_lower(*str2))
{
if (*str1 == '\0') return 0;
str1++; str2++;
}
return ((mio_bchu_t)*str1 > (mio_bchu_t)*str2)? 1: -1;
return ((mio_bchu_t)mio_to_bch_lower(*str1) > (mio_bchu_t)mio_to_bch_lower(*str2))? 1: -1;
}
else
{
while (*str1 == *str2)
{
if (*str1 == '\0') return 0;
str1++; str2++;
}
return ((mio_bchu_t)*str1 > (mio_bchu_t)*str2)? 1: -1;
}
}
int mio_comp_ucstr_bcstr (const mio_uch_t* str1, const mio_bch_t* str2)
int mio_comp_ucstr_bcstr (const mio_uch_t* str1, const mio_bch_t* str2, int ignorecase)
{
while (*str1 == *str2)
{
@ -135,7 +198,7 @@ int mio_comp_ucstr_bcstr (const mio_uch_t* str1, const mio_bch_t* str2)
return ((mio_uchu_t)*str1 > (mio_bchu_t)*str2)? 1: -1;
}
int mio_comp_uchars_ucstr (const mio_uch_t* str1, mio_oow_t len, const mio_uch_t* str2)
int mio_comp_uchars_ucstr (const mio_uch_t* str1, mio_oow_t len, const mio_uch_t* str2, int ignorecase)
{
/* for "abc\0" of length 4 vs "abc", the fourth character
* of the first string is equal to the terminating null of
@ -150,7 +213,7 @@ int mio_comp_uchars_ucstr (const mio_uch_t* str1, mio_oow_t len, const mio_uch_t
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
int mio_comp_uchars_bcstr (const mio_uch_t* str1, mio_oow_t len, const mio_bch_t* str2)
int mio_comp_uchars_bcstr (const mio_uch_t* str1, mio_oow_t len, const mio_bch_t* str2, int ignorecase)
{
const mio_uch_t* end = str1 + len;
while (str1 < end && *str2 != '\0')
@ -161,7 +224,7 @@ int mio_comp_uchars_bcstr (const mio_uch_t* str1, mio_oow_t len, const mio_bch_t
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
int mio_comp_bchars_bcstr (const mio_bch_t* str1, mio_oow_t len, const mio_bch_t* str2)
int mio_comp_bchars_bcstr (const mio_bch_t* str1, mio_oow_t len, const mio_bch_t* str2, int ignorecase)
{
const mio_bch_t* end = str1 + len;
while (str1 < end && *str2 != '\0')
@ -172,7 +235,7 @@ int mio_comp_bchars_bcstr (const mio_bch_t* str1, mio_oow_t len, const mio_bch_t
return (str1 < end)? 1: (*str2 == '\0'? 0: -1);
}
int mio_comp_bchars_ucstr (const mio_bch_t* str1, mio_oow_t len, const mio_uch_t* str2)
int mio_comp_bchars_ucstr (const mio_bch_t* str1, mio_oow_t len, const mio_uch_t* str2, int ignorecase)
{
const mio_bch_t* end = str1 + len;
while (str1 < end && *str2 != '\0')