From 3f60b8e4e8fbe6bf981587b86e8fae5f967a5601 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 31 May 2019 14:31:40 +0000 Subject: [PATCH] refactored the formatter code --- mio/bin/Makefile.in | 113 ++--- mio/lib/Makefile.am | 3 +- mio/lib/Makefile.in | 18 +- mio/lib/err.c | 122 +++++ mio/lib/fmtout.c | 707 -------------------------- mio/lib/fmtoutv.h | 1172 ------------------------------------------- mio/lib/mio-prv.h | 19 - mio/lib/mio-utl.h | 71 ++- mio/lib/mio.h | 17 +- 9 files changed, 272 insertions(+), 1970 deletions(-) delete mode 100644 mio/lib/fmtout.c delete mode 100644 mio/lib/fmtoutv.h diff --git a/mio/bin/Makefile.in b/mio/bin/Makefile.in index a23c143..176c8af 100644 --- a/mio/bin/Makefile.in +++ b/mio/bin/Makefile.in @@ -88,7 +88,7 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -bin_PROGRAMS = mio-execd$(EXEEXT) mio-t01$(EXEEXT) +bin_PROGRAMS = execd$(EXEEXT) t01$(EXEEXT) subdir = bin ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ @@ -106,26 +106,22 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) -am_mio_execd_OBJECTS = mio_execd-execd.$(OBJEXT) -mio_execd_OBJECTS = $(am_mio_execd_OBJECTS) +am_execd_OBJECTS = execd-execd.$(OBJEXT) +execd_OBJECTS = $(am_execd_OBJECTS) am__DEPENDENCIES_1 = am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) -mio_execd_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = -mio_execd_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ +execd_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(mio_execd_LDFLAGS) $(LDFLAGS) -o $@ -am_mio_t01_OBJECTS = mio_t01-t01.$(OBJEXT) -mio_t01_OBJECTS = $(am_mio_t01_OBJECTS) -mio_t01_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) -mio_t01_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(execd_LDFLAGS) $(LDFLAGS) -o $@ +am_t01_OBJECTS = t01-t01.$(OBJEXT) +t01_OBJECTS = $(am_t01_OBJECTS) +t01_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(mio_t01_LDFLAGS) $(LDFLAGS) -o $@ + $(t01_LDFLAGS) $(LDFLAGS) -o $@ AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -160,8 +156,8 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = $(mio_execd_SOURCES) $(mio_t01_SOURCES) -DIST_SOURCES = $(mio_execd_SOURCES) $(mio_t01_SOURCES) +SOURCES = $(execd_SOURCES) $(t01_SOURCES) +DIST_SOURCES = $(execd_SOURCES) $(t01_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -327,6 +323,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -341,24 +338,22 @@ CPPFLAGS_ALL_COMMON = \ -I$(abs_builddir)/../lib \ -I$(abs_srcdir) \ -I$(abs_srcdir)/../lib \ - -I$(includedir) + -I$(includedir) LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(abs_builddir)/../lib -L$(libdir) - -################################################## -# MAIN LIBRARY -################################################## -CPPFLAGS_LIB_COMMON = $(CPPFLAGS_ALL_COMMON) -LDFLAGS_LIB_COMMON = $(LDFLAGS_ALL_COMMON) -version-info 1:0:0 -no-undefined -LIBADD_LIB_COMMON = $(LIBM) -mio_execd_SOURCES = execd.c -mio_execd_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -mio_execd_LDFLAGS = $(LDFLAGS_LIB_COMMON) -mio_execd_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS) -mio_t01_SOURCES = t01.c -mio_t01_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -mio_t01_LDFLAGS = $(LDFLAGS_LIB_COMMON) -mio_t01_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS) +CPPFLAGS_BIN_COMMON = $(CPPFLAGS_ALL_COMMON) +LDFLAGS_BIN_COMMON = $(LDFLAGS_ALL_COMMON) -version-info 1:0:0 -no-undefined +LIBADD_BIN_COMMON = $(LIBM) +execd_SOURCES = execd.c +execd_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) +execd_LDFLAGS = $(LDFLAGS_ALL_COMMON) +execd_LDADD = $(LIBADD_BIN_COMMON) -lmio +execd_DEPENDENCIES = ../lib/libmio.la +t01_SOURCES = t01.c +t01_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) +t01_LDFLAGS = $(LDFLAGS_ALL_COMMON) +t01_LDADD = $(LIBADD_BIN_COMMON) -lmio +t01_DEPENDENCIES = ../lib/libmio.la all: all-am .SUFFIXES: @@ -442,13 +437,13 @@ clean-binPROGRAMS: echo " rm -f" $$list; \ rm -f $$list -mio-execd$(EXEEXT): $(mio_execd_OBJECTS) $(mio_execd_DEPENDENCIES) $(EXTRA_mio_execd_DEPENDENCIES) - @rm -f mio-execd$(EXEEXT) - $(AM_V_CCLD)$(mio_execd_LINK) $(mio_execd_OBJECTS) $(mio_execd_LDADD) $(LIBS) +execd$(EXEEXT): $(execd_OBJECTS) $(execd_DEPENDENCIES) $(EXTRA_execd_DEPENDENCIES) + @rm -f execd$(EXEEXT) + $(AM_V_CCLD)$(execd_LINK) $(execd_OBJECTS) $(execd_LDADD) $(LIBS) -mio-t01$(EXEEXT): $(mio_t01_OBJECTS) $(mio_t01_DEPENDENCIES) $(EXTRA_mio_t01_DEPENDENCIES) - @rm -f mio-t01$(EXEEXT) - $(AM_V_CCLD)$(mio_t01_LINK) $(mio_t01_OBJECTS) $(mio_t01_LDADD) $(LIBS) +t01$(EXEEXT): $(t01_OBJECTS) $(t01_DEPENDENCIES) $(EXTRA_t01_DEPENDENCIES) + @rm -f t01$(EXEEXT) + $(AM_V_CCLD)$(t01_LINK) $(t01_OBJECTS) $(t01_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -456,8 +451,8 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_execd-execd.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_t01-t01.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/execd-execd.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t01-t01.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @@ -483,33 +478,33 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< -mio_execd-execd.o: execd.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_execd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mio_execd-execd.o -MD -MP -MF $(DEPDIR)/mio_execd-execd.Tpo -c -o mio_execd-execd.o `test -f 'execd.c' || echo '$(srcdir)/'`execd.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mio_execd-execd.Tpo $(DEPDIR)/mio_execd-execd.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='execd.c' object='mio_execd-execd.o' libtool=no @AMDEPBACKSLASH@ +execd-execd.o: execd.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(execd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT execd-execd.o -MD -MP -MF $(DEPDIR)/execd-execd.Tpo -c -o execd-execd.o `test -f 'execd.c' || echo '$(srcdir)/'`execd.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/execd-execd.Tpo $(DEPDIR)/execd-execd.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='execd.c' object='execd-execd.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_execd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mio_execd-execd.o `test -f 'execd.c' || echo '$(srcdir)/'`execd.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(execd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o execd-execd.o `test -f 'execd.c' || echo '$(srcdir)/'`execd.c -mio_execd-execd.obj: execd.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_execd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mio_execd-execd.obj -MD -MP -MF $(DEPDIR)/mio_execd-execd.Tpo -c -o mio_execd-execd.obj `if test -f 'execd.c'; then $(CYGPATH_W) 'execd.c'; else $(CYGPATH_W) '$(srcdir)/execd.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mio_execd-execd.Tpo $(DEPDIR)/mio_execd-execd.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='execd.c' object='mio_execd-execd.obj' libtool=no @AMDEPBACKSLASH@ +execd-execd.obj: execd.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(execd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT execd-execd.obj -MD -MP -MF $(DEPDIR)/execd-execd.Tpo -c -o execd-execd.obj `if test -f 'execd.c'; then $(CYGPATH_W) 'execd.c'; else $(CYGPATH_W) '$(srcdir)/execd.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/execd-execd.Tpo $(DEPDIR)/execd-execd.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='execd.c' object='execd-execd.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_execd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mio_execd-execd.obj `if test -f 'execd.c'; then $(CYGPATH_W) 'execd.c'; else $(CYGPATH_W) '$(srcdir)/execd.c'; fi` +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(execd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o execd-execd.obj `if test -f 'execd.c'; then $(CYGPATH_W) 'execd.c'; else $(CYGPATH_W) '$(srcdir)/execd.c'; fi` -mio_t01-t01.o: t01.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t01_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mio_t01-t01.o -MD -MP -MF $(DEPDIR)/mio_t01-t01.Tpo -c -o mio_t01-t01.o `test -f 't01.c' || echo '$(srcdir)/'`t01.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mio_t01-t01.Tpo $(DEPDIR)/mio_t01-t01.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='t01.c' object='mio_t01-t01.o' libtool=no @AMDEPBACKSLASH@ +t01-t01.o: t01.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(t01_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT t01-t01.o -MD -MP -MF $(DEPDIR)/t01-t01.Tpo -c -o t01-t01.o `test -f 't01.c' || echo '$(srcdir)/'`t01.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/t01-t01.Tpo $(DEPDIR)/t01-t01.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='t01.c' object='t01-t01.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t01_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mio_t01-t01.o `test -f 't01.c' || echo '$(srcdir)/'`t01.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(t01_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o t01-t01.o `test -f 't01.c' || echo '$(srcdir)/'`t01.c -mio_t01-t01.obj: t01.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t01_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mio_t01-t01.obj -MD -MP -MF $(DEPDIR)/mio_t01-t01.Tpo -c -o mio_t01-t01.obj `if test -f 't01.c'; then $(CYGPATH_W) 't01.c'; else $(CYGPATH_W) '$(srcdir)/t01.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mio_t01-t01.Tpo $(DEPDIR)/mio_t01-t01.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='t01.c' object='mio_t01-t01.obj' libtool=no @AMDEPBACKSLASH@ +t01-t01.obj: t01.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(t01_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT t01-t01.obj -MD -MP -MF $(DEPDIR)/t01-t01.Tpo -c -o t01-t01.obj `if test -f 't01.c'; then $(CYGPATH_W) 't01.c'; else $(CYGPATH_W) '$(srcdir)/t01.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/t01-t01.Tpo $(DEPDIR)/t01-t01.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='t01.c' object='t01-t01.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t01_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mio_t01-t01.obj `if test -f 't01.c'; then $(CYGPATH_W) 't01.c'; else $(CYGPATH_W) '$(srcdir)/t01.c'; fi` +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(t01_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o t01-t01.obj `if test -f 't01.c'; then $(CYGPATH_W) 't01.c'; else $(CYGPATH_W) '$(srcdir)/t01.c'; fi` mostlyclean-libtool: -rm -f *.lo diff --git a/mio/lib/Makefile.am b/mio/lib/Makefile.am index f3d4fc7..76c4149 100644 --- a/mio/lib/Makefile.am +++ b/mio/lib/Makefile.am @@ -34,8 +34,7 @@ lib_LTLIBRARIES = libmio.la libmio_la_SOURCES = \ dns.c \ err.c \ - fmtout.c \ - fmtoutv.h \ + fmt.c \ mio-prv.h \ mio-sys.h \ mio.c \ diff --git a/mio/lib/Makefile.in b/mio/lib/Makefile.in index 6a2789a..27e0b89 100644 --- a/mio/lib/Makefile.in +++ b/mio/lib/Makefile.in @@ -139,7 +139,7 @@ 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-err.lo \ - libmio_la-fmtout.lo libmio_la-mio.lo libmio_la-pro.lo \ + libmio_la-fmt.lo libmio_la-mio.lo libmio_la-pro.lo \ libmio_la-sck.lo libmio_la-sck-addr.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 libmio_la-tmr.lo \ @@ -356,6 +356,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -397,8 +398,7 @@ lib_LTLIBRARIES = libmio.la libmio_la_SOURCES = \ dns.c \ err.c \ - fmtout.c \ - fmtoutv.h \ + fmt.c \ mio-prv.h \ mio-sys.h \ mio.c \ @@ -515,7 +515,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-dns.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-err.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-fmtout.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-fmt.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-mio.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-pro.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-sck-addr.Plo@am__quote@ @@ -568,12 +568,12 @@ libmio_la-err.lo: err.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-err.lo `test -f 'err.c' || echo '$(srcdir)/'`err.c -libmio_la-fmtout.lo: fmtout.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-fmtout.lo -MD -MP -MF $(DEPDIR)/libmio_la-fmtout.Tpo -c -o libmio_la-fmtout.lo `test -f 'fmtout.c' || echo '$(srcdir)/'`fmtout.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-fmtout.Tpo $(DEPDIR)/libmio_la-fmtout.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='fmtout.c' object='libmio_la-fmtout.lo' libtool=yes @AMDEPBACKSLASH@ +libmio_la-fmt.lo: fmt.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-fmt.lo -MD -MP -MF $(DEPDIR)/libmio_la-fmt.Tpo -c -o libmio_la-fmt.lo `test -f 'fmt.c' || echo '$(srcdir)/'`fmt.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-fmt.Tpo $(DEPDIR)/libmio_la-fmt.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='fmt.c' object='libmio_la-fmt.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-fmtout.lo `test -f 'fmtout.c' || echo '$(srcdir)/'`fmtout.c +@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-fmt.lo `test -f 'fmt.c' || echo '$(srcdir)/'`fmt.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 diff --git a/mio/lib/err.c b/mio/lib/err.c index 8a03a5d..c1a95ad 100644 --- a/mio/lib/err.c +++ b/mio/lib/err.c @@ -108,6 +108,127 @@ void mio_seterrnum (mio_t* mio, mio_errnum_t errnum) mio->errmsg.len = 0; } +static int err_bcs (mio_fmtout_t* fmtout, const mio_bch_t* ptr, mio_oow_t len) +{ + mio_t* mio = (mio_t*)fmtout->ctx; + mio_oow_t max; + + max = MIO_COUNTOF(mio->errmsg.buf) - mio->errmsg.len - 1; + +#if defined(MIO_OOCH_IS_UCH) + if (max <= 0) return 1; + mio_conv_bchars_to_uchars_with_cmgr (ptr, &len, &mio->errmsg.buf[mio->errmsg.len], &max, mio->cmgr, 1); + mio->errmsg.len += max; +#else + if (len > max) len = max; + if (len <= 0) return 1; + MIO_MEMCPY (&mio->errmsg.buf[mio->errmsg.len], ptr, len * MIO_SIZEOF(*ptr)); + mio->errmsg.len += len; +#endif + + mio->errmsg.buf[mio->errmsg.len] = '\0'; + + return 1; /* success */ +} + +static int err_ucs (mio_fmtout_t* fmtout, const mio_uch_t* ptr, mio_oow_t len) +{ + mio_t* mio = (mio_t*)fmtout->ctx; + mio_oow_t max; + + max = MIO_COUNTOF(mio->errmsg.buf) - mio->errmsg.len - 1; + +#if defined(MIO_OOCH_IS_UCH) + if (len > max) len = max; + if (len <= 0) return 1; + MIO_MEMCPY (&mio->errmsg.buf[mio->errmsg.len], ptr, len * MIO_SIZEOF(*ptr)); + mio->errmsg.len += len; +#else + if (max <= 0) return 1; + mio_conv_uchars_to_bchars_with_cmgr (ptr, &len, &mio->errmsg.buf[mio->errmsg.len], &max, mio->cmgr); + mio->errmsg.len += max; +#endif + mio->errmsg.buf[mio->errmsg.len] = '\0'; + return 1; /* success */ +} + +void mio_seterrbfmt (mio_t* mio, mio_errnum_t errnum, const mio_bch_t* fmt, ...) +{ + va_list ap; + mio_fmtout_t fo; + + if (mio->shuterr) return; + mio->errmsg.len = 0; + + MIO_MEMSET (&fo, 0, MIO_SIZEOF(fo)); + fo.putbcs = err_bcs; + fo.putucs = err_ucs; + fo.ctx = mio; + + va_start (ap, fmt); + mio_bfmt_outv (&fo, fmt, ap); + va_end (ap); + + mio->errnum = errnum; +} + +void mio_seterrufmt (mio_t* mio, mio_errnum_t errnum, const mio_uch_t* fmt, ...) +{ + va_list ap; + mio_fmtout_t fo; + + if (mio->shuterr) return; + mio->errmsg.len = 0; + + MIO_MEMSET (&fo, 0, MIO_SIZEOF(fo)); + fo.putbcs = err_bcs; + fo.putucs = err_ucs; + fo.ctx = mio; + + va_start (ap, fmt); + mio_ufmt_outv (&fo, fmt, ap); + va_end (ap); + + mio->errnum = errnum; +} + + +void mio_seterrbfmtv (mio_t* mio, mio_errnum_t errnum, const mio_bch_t* fmt, va_list ap) +{ + mio_fmtout_t fo; + + if (mio->shuterr) return; + + mio->errmsg.len = 0; + + MIO_MEMSET (&fo, 0, MIO_SIZEOF(fo)); + fo.putbcs = err_bcs; + fo.putucs = err_ucs; + fo.ctx = mio; + + mio_bfmt_outv (&fo, fmt, ap); + mio->errnum = errnum; +} + +void mio_seterrufmtv (mio_t* mio, mio_errnum_t errnum, const mio_uch_t* fmt, va_list ap) +{ + mio_fmtout_t fo; + + if (mio->shuterr) return; + + mio->errmsg.len = 0; + + MIO_MEMSET (&fo, 0, MIO_SIZEOF(fo)); + fo.putbcs = err_bcs; + fo.putucs = err_ucs; + fo.ctx = mio; + + mio_ufmt_outv (&fo, fmt, ap); + mio->errnum = errnum; +} + + + void mio_seterrwithsyserr (mio_t* mio, int syserr_type, int syserr_code) { mio_errnum_t errnum; @@ -242,3 +363,4 @@ void mio_seterrufmtwithsyserr (mio_t* mio, int syserr_type, int syserr_code, con } }*/ } + diff --git a/mio/lib/fmtout.c b/mio/lib/fmtout.c deleted file mode 100644 index 73b3999..0000000 --- a/mio/lib/fmtout.c +++ /dev/null @@ -1,707 +0,0 @@ -/* - * $Id$ - * - Copyright (c) 2015-2016 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-prv.h" - -/*#include */ /* for snprintf(). used for floating-point number formatting */ - -#if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200)) -# define snprintf _snprintf -# if !defined(HAVE_SNPRINTF) -# define HAVE_SNPRINTF -# endif -#endif -#if defined(HAVE_QUADMATH_H) -# include /* for quadmath_snprintf() */ -#endif -/* TODO: remove stdio.h and quadmath.h once snprintf gets replaced by own -floting-point conversion implementation*/ - -/* Max number conversion buffer length: - * mio_intmax_t in base 2, plus NUL byte. */ -#define MAXNBUF (MIO_SIZEOF(mio_intmax_t) * MIO_BITS_PER_BYTE + 1) - -enum -{ - /* integer */ - LF_C = (1 << 0), - LF_H = (1 << 1), - LF_J = (1 << 2), - LF_L = (1 << 3), - LF_Q = (1 << 4), - LF_T = (1 << 5), - LF_Z = (1 << 6), - - /* long double */ - LF_LD = (1 << 7), - /* __float128 */ - LF_QD = (1 << 8) -}; - -static struct -{ - mio_uint8_t flag; /* for single occurrence */ - mio_uint8_t dflag; /* for double occurrence */ -} lm_tab[26] = -{ - { 0, 0 }, /* a */ - { 0, 0 }, /* b */ - { 0, 0 }, /* c */ - { 0, 0 }, /* d */ - { 0, 0 }, /* e */ - { 0, 0 }, /* f */ - { 0, 0 }, /* g */ - { LF_H, LF_C }, /* h */ - { 0, 0 }, /* i */ - { LF_J, 0 }, /* j */ - { 0, 0 }, /* k */ - { LF_L, LF_Q }, /* l */ - { 0, 0 }, /* m */ - { 0, 0 }, /* n */ - { 0, 0 }, /* o */ - { 0, 0 }, /* p */ - { LF_Q, 0 }, /* q */ - { 0, 0 }, /* r */ - { 0, 0 }, /* s */ - { LF_T, 0 }, /* t */ - { 0, 0 }, /* u */ - { 0, 0 }, /* v */ - { 0, 0 }, /* w */ - { 0, 0 }, /* z */ - { 0, 0 }, /* y */ - { LF_Z, 0 }, /* z */ -}; - - -enum -{ - FLAGC_DOT = (1 << 0), - FLAGC_SPACE = (1 << 1), - FLAGC_SHARP = (1 << 2), - FLAGC_SIGN = (1 << 3), - FLAGC_LEFTADJ = (1 << 4), - FLAGC_ZEROPAD = (1 << 5), - FLAGC_WIDTH = (1 << 6), - FLAGC_PRECISION = (1 << 7), - FLAGC_STAR1 = (1 << 8), - FLAGC_STAR2 = (1 << 9), - FLAGC_LENMOD = (1 << 10) /* length modifier */ -}; - -static const mio_bch_t hex2ascii_lower[] = -{ - '0','1','2','3','4','5','6','7','8','9', - 'a','b','c','d','e','f','g','h','i','j','k','l','m', - 'n','o','p','q','r','s','t','u','v','w','x','y','z' -}; - -static const mio_bch_t hex2ascii_upper[] = -{ - '0','1','2','3','4','5','6','7','8','9', - 'A','B','C','D','E','F','G','H','I','J','K','L','M', - 'N','O','P','Q','R','S','T','U','V','W','X','H','Z' -}; - -static mio_uch_t uch_nullstr[] = { '(','n','u','l','l', ')','\0' }; -static mio_bch_t bch_nullstr[] = { '(','n','u','l','l', ')','\0' }; - -typedef int (*mio_fmtout_putch_t) ( - mio_t* mio, - mio_bitmask_t mask, - mio_ooch_t c, - mio_oow_t len -); - -typedef int (*mio_fmtout_putcs_t) ( - mio_t* mio, - mio_bitmask_t mask, - const mio_ooch_t* ptr, - mio_oow_t len -); - -typedef struct mio_fmtout_data_t mio_fmtout_data_t; -struct mio_fmtout_data_t -{ - mio_oow_t count; /* out */ - mio_bitmask_t mask; /* in */ - mio_fmtout_putch_t putch; /* in */ - mio_fmtout_putcs_t putcs; /* in */ -}; - -/* ------------------------------------------------------------------------- */ -/* - * Put a NUL-terminated ASCII number (base <= 36) in a buffer in reverse - * order; return an optional length and a pointer to the last character - * written in the buffer (i.e., the first character of the string). - * The buffer pointed to by `nbuf' must have length >= MAXNBUF. - */ - -static mio_bch_t* sprintn_lower (mio_bch_t* nbuf, mio_uintmax_t num, int base, mio_ooi_t* lenp) -{ - mio_bch_t* p; - - p = nbuf; - *p = '\0'; - do { *++p = hex2ascii_lower[num % base]; } while (num /= base); - - if (lenp) *lenp = p - nbuf; - return p; /* returns the end */ -} - -static mio_bch_t* sprintn_upper (mio_bch_t* nbuf, mio_uintmax_t num, int base, mio_ooi_t* lenp) -{ - mio_bch_t* p; - - p = nbuf; - *p = '\0'; - do { *++p = hex2ascii_upper[num % base]; } while (num /= base); - - if (lenp) *lenp = p - nbuf; - return p; /* returns the end */ -} - -/* ------------------------------------------------------------------------- */ -static int put_ooch (mio_t* mio, mio_bitmask_t mask, mio_ooch_t ch, mio_oow_t len) -{ - /* this is not equivalent to put_oocs(mio,mask,&ch, 1); - * this function is to emit a single character multiple times */ - mio_oow_t rem; - - if (len <= 0) return 1; - - if (mio->log.len > 0 && mio->log.last_mask != mask) - { - /* the mask has changed. commit the buffered text */ - -/* TODO: HANDLE LINE ENDING CONVENTION BETTER... */ - if (mio->log.ptr[mio->log.len - 1] != '\n') - { - /* no line ending - append a line terminator */ - mio->log.ptr[mio->log.len++] = '\n'; - } - prim_write_log (mio, mio->log.last_mask, mio->log.ptr, mio->log.len); - mio->log.len = 0; - } - -redo: - rem = 0; - if (len > mio->log.capa - mio->log.len) - { - mio_oow_t newcapa, max; - mio_ooch_t* tmp; - - max = MIO_TYPE_MAX(mio_oow_t) - mio->log.len; - if (len > max) - { - /* data too big. */ - rem += len - max; - len = max; - } - - newcapa = MIO_ALIGN_POW2(mio->log.len + len, MIO_LOG_CAPA_ALIGN); /* TODO: adjust this capacity */ - if (newcapa > mio->option.log_maxcapa) - { - /* [NOTE] - * it doesn't adjust newcapa to mio->option.log_maxcapa. - * nor does it cut the input to fit it into the adjusted capacity. - * if maxcapa set is not aligned to MIO_LOG_CAPA_ALIGN, - * the largest buffer capacity may be suboptimal */ - goto make_do; - } - - /* +1 to handle line ending injection more easily */ - tmp = mio_reallocmem(mio, mio->log.ptr, (newcapa + 1) * MIO_SIZEOF(*tmp)); - if (!tmp) - { - make_do: - if (mio->log.len > 0) - { - /* can't expand the buffer. just flush the existing contents */ - /* TODO: HANDLE LINE ENDING CONVENTION BETTER... */ - if (mio->log.ptr[mio->log.len - 1] != '\n') - { - /* no line ending - append a line terminator */ - mio->log.ptr[mio->log.len++] = '\n'; - } - prim_write_log (mio, mio->log.last_mask, mio->log.ptr, mio->log.len); - mio->log.len = 0; - } - - if (len > mio->log.capa) - { - rem += len - mio->log.capa; - len = mio->log.capa; - } - - } - else - { - mio->log.ptr = tmp; - mio->log.capa = newcapa; - } - } - - while (len > 0) - { - mio->log.ptr[mio->log.len++] = ch; - len--; - } - mio->log.last_mask = mask; - - if (rem > 0) - { - len = rem; - goto redo; - } - - - return 1; /* success */ -} - -static int put_oocs (mio_t* mio, mio_bitmask_t mask, const mio_ooch_t* ptr, mio_oow_t len) -{ - mio_oow_t rem; - - if (len <= 0) return 1; - - if (mio->log.len > 0 && mio->log.last_mask != mask) - { - /* the mask has changed. commit the buffered text */ -/* TODO: HANDLE LINE ENDING CONVENTION BETTER... */ - if (mio->log.ptr[mio->log.len - 1] != '\n') - { - /* no line ending - append a line terminator */ - mio->log.ptr[mio->log.len++] = '\n'; - } - - prim_write_log (mio, mio->log.last_mask, mio->log.ptr, mio->log.len); - mio->log.len = 0; - } - -redo: - rem = 0; - if (len > mio->log.capa - mio->log.len) - { - mio_oow_t newcapa, max; - mio_ooch_t* tmp; - - max = MIO_TYPE_MAX(mio_oow_t) - mio->log.len; - if (len > max) - { - /* data too big. */ - rem += len - max; - len = max; - } - - newcapa = MIO_ALIGN_POW2(mio->log.len + len, 512); /* TODO: adjust this capacity */ - if (newcapa > mio->option.log_maxcapa) - { - /* [NOTE] - * it doesn't adjust newcapa to mio->option.log_maxcapa. - * nor does it cut the input to fit it into the adjusted capacity. - * if maxcapa set is not aligned to MIO_LOG_CAPA_ALIGN, - * the largest buffer capacity may be suboptimal */ - goto make_do; - } - - /* +1 to handle line ending injection more easily */ - tmp = mio_reallocmem(mio, mio->log.ptr, (newcapa + 1) * MIO_SIZEOF(*tmp)); - if (!tmp) - { - make_do: - if (mio->log.len > 0) - { - /* can't expand the buffer. just flush the existing contents */ - /* TODO: HANDLE LINE ENDING CONVENTION BETTER... */ - if (mio->log.ptr[mio->log.len - 1] != '\n') - { - /* no line ending - append a line terminator */ - mio->log.ptr[mio->log.len++] = '\n'; - } - prim_write_log (mio, mio->log.last_mask, mio->log.ptr, mio->log.len); - mio->log.len = 0; - } - - if (len > mio->log.capa) - { - rem += len - mio->log.capa; - len = mio->log.capa; - } - } - else - { - mio->log.ptr = tmp; - mio->log.capa = newcapa; - } - } - - MIO_MEMCPY (&mio->log.ptr[mio->log.len], ptr, len * MIO_SIZEOF(*ptr)); - mio->log.len += len; - mio->log.last_mask = mask; - - if (rem > 0) - { - ptr += len; - len = rem; - goto redo; - } - - return 1; /* success */ -} - -/* ------------------------------------------------------------------------- */ - - -/* ------------------------------------------------------------------------- */ - -#undef FMTCHAR_IS_BCH -#undef FMTCHAR_IS_UCH -#undef FMTCHAR_IS_OOCH -#undef fmtchar_t -#undef fmtoutv -#define fmtchar_t mio_bch_t -#define fmtoutv __logbfmtv -#define FMTCHAR_IS_BCH -#if defined(MIO_OOCH_IS_BCH) -# define FMTCHAR_IS_OOCH -#endif -#include "fmtoutv.h" - -#undef FMTCHAR_IS_BCH -#undef FMTCHAR_IS_UCH -#undef FMTCHAR_IS_OOCH -#undef fmtchar_t -#undef fmtoutv -#define fmtchar_t mio_uch_t -#define fmtoutv __logufmtv -#define FMTCHAR_IS_UCH -#if defined(MIO_OOCH_IS_UCH) -# define FMTCHAR_IS_OOCH -#endif -#include "fmtoutv.h" - - -static int _logbfmtv (mio_t* mio, const mio_bch_t* fmt, mio_fmtout_data_t* data, va_list ap) -{ - return __logbfmtv(mio, fmt, data, ap); -} - -static int _logufmtv (mio_t* mio, const mio_uch_t* fmt, mio_fmtout_data_t* data, va_list ap) -{ - return __logufmtv(mio, fmt, data, ap); -} - -mio_ooi_t mio_logbfmt (mio_t* mio, mio_bitmask_t mask, const mio_bch_t* fmt, ...) -{ - int x; - va_list ap; - mio_fmtout_data_t fo; - - if (mio->log.default_type_mask & MIO_LOG_ALL_TYPES) - { - /* if a type is given, it's not untyped any more. - * mask off the UNTYPED bit */ - mask &= ~MIO_LOG_UNTYPED; - - /* if the default_type_mask has the UNTYPED bit on, - * it'll get turned back on */ - mask |= (mio->log.default_type_mask & MIO_LOG_ALL_TYPES); - } - else if (!(mask & MIO_LOG_ALL_TYPES)) - { - /* no type is set in the given mask and no default type is set. - * make it UNTYPED. */ - mask |= MIO_LOG_UNTYPED; - } - - fo.mask = mask; - fo.putch = put_ooch; - fo.putcs = put_oocs; - - va_start (ap, fmt); - x = _logbfmtv(mio, fmt, &fo, ap); - va_end (ap); - - if (mio->log.len > 0 && mio->log.ptr[mio->log.len - 1] == '\n') - { - prim_write_log (mio, mio->log.last_mask, mio->log.ptr, mio->log.len); - mio->log.len = 0; - } - return (x <= -1)? -1: fo.count; -} - -mio_ooi_t mio_logufmt (mio_t* mio, mio_bitmask_t mask, const mio_uch_t* fmt, ...) -{ - int x; - va_list ap; - mio_fmtout_data_t fo; - - if (mio->log.default_type_mask & MIO_LOG_ALL_TYPES) - { - mask &= ~MIO_LOG_UNTYPED; - mask |= (mio->log.default_type_mask & MIO_LOG_ALL_TYPES); - } - else if (!(mask & MIO_LOG_ALL_TYPES)) - { - mask |= MIO_LOG_UNTYPED; - } - - fo.mask = mask; - fo.putch = put_ooch; - fo.putcs = put_oocs; - - va_start (ap, fmt); - x = _logufmtv(mio, fmt, &fo, ap); - va_end (ap); - - if (mio->log.len > 0 && mio->log.ptr[mio->log.len - 1] == '\n') - { - prim_write_log (mio, mio->log.last_mask, mio->log.ptr, mio->log.len); - mio->log.len = 0; - } - - return (x <= -1)? -1: fo.count; -} - - -/* -------------------------------------------------------------------------- - * ERROR MESSAGE FORMATTING - * -------------------------------------------------------------------------- */ - -static int put_errch (mio_t* mio, mio_bitmask_t mask, mio_ooch_t ch, mio_oow_t len) -{ - mio_oow_t max; - - max = MIO_COUNTOF(mio->errmsg.buf) - mio->errmsg.len - 1; - if (len > max) len = max; - - if (len <= 0) return 1; - - while (len > 0) - { - mio->errmsg.buf[mio->errmsg.len++] = ch; - len--; - } - mio->errmsg.buf[mio->errmsg.len] = '\0'; - - return 1; /* success */ -} - -static int put_errcs (mio_t* mio, mio_bitmask_t mask, const mio_ooch_t* ptr, mio_oow_t len) -{ - mio_oow_t max; - - max = MIO_COUNTOF(mio->errmsg.buf) - mio->errmsg.len - 1; - if (len > max) len = max; - - if (len <= 0) return 1; - - MIO_MEMCPY (&mio->errmsg.buf[mio->errmsg.len], ptr, len * MIO_SIZEOF(*ptr)); - mio->errmsg.len += len; - mio->errmsg.buf[mio->errmsg.len] = '\0'; - - return 1; /* success */ -} - - -static int _errbfmtv (mio_t* mio, const mio_bch_t* fmt, mio_fmtout_data_t* data, va_list ap) -{ - return __logbfmtv(mio, fmt, data, ap); -} - -static int _errufmtv (mio_t* mio, const mio_uch_t* fmt, mio_fmtout_data_t* data, va_list ap) -{ - return __logufmtv(mio, fmt, data, ap); -} - -void mio_seterrbfmt (mio_t* mio, mio_errnum_t errnum, const mio_bch_t* fmt, ...) -{ - va_list ap; - mio_fmtout_data_t fo; - - if (mio->shuterr) return; - mio->errmsg.len = 0; - - fo.mask = 0; /* not used */ - fo.putch = put_errch; - fo.putcs = put_errcs; - - va_start (ap, fmt); - _errbfmtv (mio, fmt, &fo, ap); - va_end (ap); - - mio->errnum = errnum; -} - -void mio_seterrufmt (mio_t* mio, mio_errnum_t errnum, const mio_uch_t* fmt, ...) -{ - va_list ap; - mio_fmtout_data_t fo; - - if (mio->shuterr) return; - mio->errmsg.len = 0; - - fo.mask = 0; /* not used */ - fo.putch = put_errch; - fo.putcs = put_errcs; - - va_start (ap, fmt); - _errufmtv (mio, fmt, &fo, ap); - va_end (ap); - - mio->errnum = errnum; -} - - -void mio_seterrbfmtv (mio_t* mio, mio_errnum_t errnum, const mio_bch_t* fmt, va_list ap) -{ - mio_fmtout_data_t fo; - - if (mio->shuterr) return; - - mio->errmsg.len = 0; - - fo.mask = 0; /* not used */ - fo.putch = put_errch; - fo.putcs = put_errcs; - - _errbfmtv (mio, fmt, &fo, ap); - mio->errnum = errnum; -} - -void mio_seterrufmtv (mio_t* mio, mio_errnum_t errnum, const mio_uch_t* fmt, va_list ap) -{ - mio_fmtout_data_t fo; - - if (mio->shuterr) return; - - mio->errmsg.len = 0; - - fo.mask = 0; /* not used */ - fo.putch = put_errch; - fo.putcs = put_errcs; - - _errufmtv (mio, fmt, &fo, ap); - mio->errnum = errnum; -} - -/* -------------------------------------------------------------------------- - * SUPPORT FOR THE BUILTIN SPRINTF PRIMITIVE FUNCTION - * -------------------------------------------------------------------------- */ -static int put_sprcs (mio_t* mio, mio_bitmask_t mask, const mio_ooch_t* ptr, mio_oow_t len) -{ - if (len > mio->sprintf.xbuf.capa - mio->sprintf.xbuf.len) - { - mio_ooch_t* tmp; - mio_oow_t newcapa; - - newcapa = mio->sprintf.xbuf.len + len + 1; - newcapa = MIO_ALIGN_POW2(newcapa, 256); - - tmp = (mio_ooch_t*)mio_reallocmem(mio, mio->sprintf.xbuf.ptr, newcapa * MIO_SIZEOF(*tmp)); - if (!tmp) return -1; - - mio->sprintf.xbuf.ptr = tmp; - mio->sprintf.xbuf.capa = newcapa; - } - - MIO_MEMCPY (&mio->sprintf.xbuf.ptr[mio->sprintf.xbuf.len], ptr, len * MIO_SIZEOF(*ptr)); - mio->sprintf.xbuf.len += len; - return 1; /* success */ -} - -static int put_sprch (mio_t* mio, mio_bitmask_t mask, mio_ooch_t ch, mio_oow_t len) -{ - if (len > mio->sprintf.xbuf.capa - mio->sprintf.xbuf.len) - { - mio_ooch_t* tmp; - mio_oow_t newcapa; - - newcapa = mio->sprintf.xbuf.len + len + 1; - newcapa = MIO_ALIGN_POW2(newcapa, 256); - - tmp = (mio_ooch_t*)mio_reallocmem(mio, mio->sprintf.xbuf.ptr, newcapa * MIO_SIZEOF(*tmp)); - if (!tmp) return -1; - - mio->sprintf.xbuf.ptr = tmp; - mio->sprintf.xbuf.capa = newcapa; - } - - while (len > 0) - { - --len; - mio->sprintf.xbuf.ptr[mio->sprintf.xbuf.len++] = ch; - } - - return 1; /* success */ -} - -static int _sprbfmtv (mio_t* mio, const mio_bch_t* fmt, mio_fmtout_data_t* data, va_list ap) -{ - return __logbfmtv (mio, fmt, data, ap); -} - -/* -static int _sprufmtv (mio_t* mio, const mio_uch_t* fmt, mio_fmtout_data_t* data, va_list ap) -{ - return __logufmtv (mio, fmt, data, ap, __sprbfmtv); -}*/ - -mio_ooi_t mio_sproutbfmt (mio_t* mio, mio_bitmask_t mask, const mio_bch_t* fmt, ...) -{ - int x; - va_list ap; - mio_fmtout_data_t fo; - - fo.mask = mask; - fo.putch = put_sprch; - fo.putcs = put_sprcs; - - va_start (ap, fmt); - x = _sprbfmtv(mio, fmt, &fo, ap); - va_end (ap); - - return (x <= -1)? -1: fo.count; -} - -/* -mio_ooi_t mio_sproutufmt (mio_t* mio, mio_bitmask_t mask, const mio_uch_t* fmt, ...) -{ - int x; - va_list ap; - mio_fmtout_data_t fo; - - fo.mask = mask; - fo.putch = put_sprch; - fo.putcs = put_sprcs; - - va_start (ap, fmt); - x = _sprufmtv (mio, fmt, &fo, ap); - va_end (ap); - - return (x <= -1)? -1: fo.count; -}*/ - diff --git a/mio/lib/fmtoutv.h b/mio/lib/fmtoutv.h deleted file mode 100644 index 8518f5c..0000000 --- a/mio/lib/fmtoutv.h +++ /dev/null @@ -1,1172 +0,0 @@ -/* - * $Id$ - * - Copyright (c) 2015-2016 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. - */ - -/* - * This file contains a formatted output routine derived from kvprintf() - * of FreeBSD. It has been heavily modified and bug-fixed. - */ - -/* - * Copyright (c) 1986, 1988, 1991, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * 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. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. - * - */ - - -/* NOTE: data output is aborted if the data limit is reached or - * I/O error occurs */ - -#undef PUT_OOCH -#undef PUT_OOCS -#undef PUT_BYTE_IN_HEX -#undef BYTE_PRINTABLE - -#define PUT_OOCH(c,n) do { \ - if (n > 0) { \ - int xx; \ - if ((xx = data->putch(mio, data->mask, c, n)) <= -1) goto oops; \ - if (xx == 0) goto done; \ - data->count += n; \ - } \ -} while (0) - -#define PUT_OOCS(ptr,len) do { \ - if (len > 0) { \ - int xx; \ - if ((xx = data->putcs(mio, data->mask, ptr, len)) <= -1) goto oops; \ - if (xx == 0) goto done; \ - data->count += len; \ - } \ -} while (0) - -#define PUT_BYTE_IN_HEX(byte,extra_flags) do { \ - mio_bch_t __xbuf[3]; \ - mio_byte_to_bcstr ((byte), __xbuf, MIO_COUNTOF(__xbuf), (16 | (extra_flags)), '0'); \ - PUT_OOCH(__xbuf[0], 1); \ - PUT_OOCH(__xbuf[1], 1); \ -} while (0) - -/* TODO: redefine this */ -#define BYTE_PRINTABLE(x) ((x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z') || (x >= '0' && x <= '9') || (x == ' ')) - -static int fmtoutv (mio_t* mio, const fmtchar_t* fmt, mio_fmtout_data_t* data, va_list ap) -{ - const fmtchar_t* percent; - const fmtchar_t* checkpoint; - mio_bch_t nbuf[MAXNBUF], bch; - const mio_bch_t* nbufp; - int n, base, neg, sign; - mio_ooi_t tmp, width, precision; - mio_ooch_t ch, padc; -#if !defined(FMTCHAR_IS_OOCH) - fmtchar_t fch; -#endif - int lm_flag, lm_dflag, flagc, numlen; - mio_uintmax_t num = 0; - int stop = 0; - -#if 0 - mio_bchbuf_t* fltfmt; - mio_oochbuf_t* fltout; -#endif - mio_bch_t* (*sprintn) (mio_bch_t* nbuf, mio_uintmax_t num, int base, mio_ooi_t* lenp); - - data->count = 0; - -#if 0 - fltfmt = &mio->d->fltfmt; - fltout = &mio->d->fltout; - - fltfmt->ptr = fltfmt->buf; - fltfmt->capa = MIO_COUNTOF(fltfmt->buf) - 1; - - fltout->ptr = fltout->buf; - fltout->capa = MIO_COUNTOF(fltout->buf) - 1; -#endif - - while (1) - { - #if defined(FMTCHAR_IS_OOCH) - checkpoint = fmt; - while ((ch = *fmt++) != '%' || stop) - { - if (ch == '\0') - { - PUT_OOCS (checkpoint, fmt - checkpoint - 1); - goto done; - } - } - PUT_OOCS (checkpoint, fmt - checkpoint - 1); - #else - #if defined(MIO_OOCH_IS_UCH) - /* fmtchar is bch. ooch is uch. convert bch to uch */ - checkpoint = fmt; - while ((fch = *fmt++) != '%' || stop) - { - if (fch == '\0') break; - } - while (checkpoint < fmt - 1) - { - mio_oow_t cvlen, bclen; - bclen = fmt - checkpoint - 1; - cvlen = mio->cmgr->bctouc(checkpoint, bclen, &ch); - if (cvlen == 0 || cvlen > bclen) goto oops; - checkpoint += cvlen; - PUT_OOCH (ch, 1); - } - if (fch == '\0') goto done; - #else - while ((fch = *fmt++) != '%' || stop) - { - mio_bch_t bcsbuf[MIO_MBLEN_MAX + 1]; - mio_oow_t ucslen, bcslen; - - if (fch == '\0') goto done; - - /* fmtchar is uch. ooch is bch. convert uch to bch */ - ucslen = 1; - bcslen = MIO_COUNTOF(bcsbuf); - if (mio_conv_uchars_to_bchars_with_cmgr(&fch, &ucslen, bcsbuf, &bcslen, mio->cmgr) <= -1) goto oops; - PUT_OOCS (bcsbuf, bcslen); - } - #endif - #endif - percent = fmt - 1; - - padc = ' '; - width = 0; precision = 0; - neg = 0; sign = 0; - - lm_flag = 0; lm_dflag = 0; flagc = 0; - sprintn = sprintn_lower; - - reswitch: - switch (ch = *fmt++) - { - case '%': /* %% */ - bch = ch; - goto print_lowercase_c; - - /* flag characters */ - case '.': - if (flagc & FLAGC_DOT) goto invalid_format; - flagc |= FLAGC_DOT; - goto reswitch; - - case '#': - if (flagc & (FLAGC_WIDTH | FLAGC_DOT | FLAGC_LENMOD)) goto invalid_format; - flagc |= FLAGC_SHARP; - goto reswitch; - - case ' ': - if (flagc & (FLAGC_WIDTH | FLAGC_DOT | FLAGC_LENMOD)) goto invalid_format; - flagc |= FLAGC_SPACE; - goto reswitch; - - case '+': /* place sign for signed conversion */ - if (flagc & (FLAGC_WIDTH | FLAGC_DOT | FLAGC_LENMOD)) goto invalid_format; - flagc |= FLAGC_SIGN; - goto reswitch; - - case '-': /* left adjusted */ - if (flagc & (FLAGC_WIDTH | FLAGC_DOT | FLAGC_LENMOD)) goto invalid_format; - if (flagc & FLAGC_DOT) - { - goto invalid_format; - } - else - { - flagc |= FLAGC_LEFTADJ; - if (flagc & FLAGC_ZEROPAD) - { - padc = ' '; - flagc &= ~FLAGC_ZEROPAD; - } - } - - goto reswitch; - - case '*': /* take the length from the parameter */ - if (flagc & FLAGC_DOT) - { - if (flagc & (FLAGC_STAR2 | FLAGC_PRECISION)) goto invalid_format; - flagc |= FLAGC_STAR2; - - precision = va_arg(ap, mio_ooi_t); /* this deviates from the standard printf that accepts 'int' */ - if (precision < 0) - { - /* if precision is less than 0, - * treat it as if no .precision is specified */ - flagc &= ~FLAGC_DOT; - precision = 0; - } - } - else - { - if (flagc & (FLAGC_STAR1 | FLAGC_WIDTH)) goto invalid_format; - flagc |= FLAGC_STAR1; - - width = va_arg(ap, mio_ooi_t); /* it deviates from the standard printf that accepts 'int' */ - if (width < 0) - { - /* - if (flagc & FLAGC_LEFTADJ) - flagc &= ~FLAGC_LEFTADJ; - else - */ - flagc |= FLAGC_LEFTADJ; - width = -width; - } - } - goto reswitch; - - case '0': /* zero pad */ - if (flagc & FLAGC_LENMOD) goto invalid_format; - if (!(flagc & (FLAGC_DOT | FLAGC_LEFTADJ))) - { - padc = '0'; - flagc |= FLAGC_ZEROPAD; - goto reswitch; - } - /* end of flags characters */ - - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - if (flagc & FLAGC_LENMOD) goto invalid_format; - for (n = 0;; ++fmt) - { - n = n * 10 + ch - '0'; - ch = *fmt; - if (ch < '0' || ch > '9') break; - } - if (flagc & FLAGC_DOT) - { - if (flagc & FLAGC_STAR2) goto invalid_format; - precision = n; - flagc |= FLAGC_PRECISION; - } - else - { - if (flagc & FLAGC_STAR1) goto invalid_format; - width = n; - flagc |= FLAGC_WIDTH; - } - goto reswitch; - - /* length modifiers */ - case 'h': /* short int */ - case 'l': /* long int */ - case 'q': /* long long int */ - case 'j': /* mio_intmax_t/mio_uintmax_t */ - case 'z': /* mio_ooi_t/mio_oow_t */ - case 't': /* ptrdiff_t */ - if (lm_flag & (LF_LD | LF_QD)) goto invalid_format; - - flagc |= FLAGC_LENMOD; - if (lm_dflag) - { - /* error */ - goto invalid_format; - } - else if (lm_flag) - { - if (lm_tab[ch - 'a'].dflag && lm_flag == lm_tab[ch - 'a'].flag) - { - lm_flag &= ~lm_tab[ch - 'a'].flag; - lm_flag |= lm_tab[ch - 'a'].dflag; - lm_dflag |= lm_flag; - goto reswitch; - } - else - { - /* error */ - goto invalid_format; - } - } - else - { - lm_flag |= lm_tab[ch - 'a'].flag; - goto reswitch; - } - break; - - case 'L': /* long double */ - if (flagc & FLAGC_LENMOD) - { - /* conflict with other length modifier */ - goto invalid_format; - } - flagc |= FLAGC_LENMOD; - lm_flag |= LF_LD; - goto reswitch; - - case 'Q': /* __float128 */ - if (flagc & FLAGC_LENMOD) - { - /* conflict with other length modifier */ - goto invalid_format; - } - flagc |= FLAGC_LENMOD; - lm_flag |= LF_QD; - goto reswitch; - /* end of length modifiers */ - - case 'n': /* number of characters printed so far */ - if (lm_flag & LF_J) /* j */ - *(va_arg(ap, mio_intmax_t*)) = data->count; - else if (lm_flag & LF_Z) /* z */ - *(va_arg(ap, mio_ooi_t*)) = data->count; - #if (MIO_SIZEOF_LONG_LONG > 0) - else if (lm_flag & LF_Q) /* ll */ - *(va_arg(ap, long long int*)) = data->count; - #endif - else if (lm_flag & LF_L) /* l */ - *(va_arg(ap, long int*)) = data->count; - else if (lm_flag & LF_H) /* h */ - *(va_arg(ap, short int*)) = data->count; - else if (lm_flag & LF_C) /* hh */ - *(va_arg(ap, char*)) = data->count; - else if (flagc & FLAGC_LENMOD) - goto invalid_format; - else - *(va_arg(ap, int*)) = data->count; - break; - - /* signed integer conversions */ - case 'd': - case 'i': /* signed conversion */ - base = 10; - sign = 1; - goto handle_sign; - /* end of signed integer conversions */ - - /* unsigned integer conversions */ - case 'o': - base = 8; - goto handle_nosign; - case 'u': - base = 10; - goto handle_nosign; - case 'X': - sprintn = sprintn_upper; - case 'x': - base = 16; - goto handle_nosign; - case 'b': - base = 2; - goto handle_nosign; - /* end of unsigned integer conversions */ - - case 'p': /* pointer */ - base = 16; - - if (width == 0) flagc |= FLAGC_SHARP; - else flagc &= ~FLAGC_SHARP; - - num = (mio_uintptr_t)va_arg(ap, void*); - goto number; - - case 'c': - { - /* zeropad must not take effect for 'c' */ - if (flagc & FLAGC_ZEROPAD) padc = ' '; - if (lm_flag & LF_L) goto uppercase_c; - #if defined(MIO_OOCH_IS_UCH) - if (lm_flag & LF_J) goto uppercase_c; - #endif - lowercase_c: - bch = MIO_SIZEOF(mio_bch_t) < MIO_SIZEOF(int)? va_arg(ap, int): va_arg(ap, mio_bch_t); - - print_lowercase_c: - /* precision 0 doesn't kill the letter */ - width--; - if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - PUT_OOCH (bch, 1); - if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - break; - } - - case 'C': - { - mio_uch_t ooch; - - /* zeropad must not take effect for 'C' */ - if (flagc & FLAGC_ZEROPAD) padc = ' '; - if (lm_flag & LF_H) goto lowercase_c; - #if defined(MIO_OOCH_IS_BCH) - if (lm_flag & LF_J) goto lowercase_c; - #endif - uppercase_c: - ooch = MIO_SIZEOF(mio_uch_t) < MIO_SIZEOF(int)? va_arg(ap, int): va_arg(ap, mio_uch_t); - - /* precision 0 doesn't kill the letter */ - width--; - if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - PUT_OOCH (ooch, 1); - if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - break; - } - - case 's': - { - const mio_bch_t* bsp; - mio_oow_t bslen, slen; - - /* zeropad must not take effect for 'S' */ - if (flagc & FLAGC_ZEROPAD) padc = ' '; - if (lm_flag & LF_L) goto uppercase_s; - #if defined(MIO_OOCH_IS_UCH) - if (lm_flag & LF_J) goto uppercase_s; - #endif - lowercase_s: - - bsp = va_arg(ap, mio_bch_t*); - if (bsp == MIO_NULL) bsp = bch_nullstr; - - #if defined(MIO_OOCH_IS_UCH) - /* get the length */ - if (flagc & FLAGC_DOT) - { - for (bslen = 0; bslen < precision && bsp[bslen]; bslen++); - } - else - { - for (bslen = 0; bsp[bslen]; bslen++); - } - - if (mio_conv_bchars_to_uchars_with_cmgr(bsp, &bslen, MIO_NULL, &slen, mio->cmgr, 0) <= -1) goto oops; - - /* slen holds the length after conversion */ - n = slen; - if ((flagc & FLAGC_DOT) && precision < slen) n = precision; - width -= n; - - if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - - { - mio_ooch_t conv_buf[32]; - mio_oow_t conv_len, src_len, tot_len = 0; - while (n > 0) - { - MIO_ASSERT (mio, bslen > tot_len); - - src_len = bslen - tot_len; - conv_len = MIO_COUNTOF(conv_buf); - - /* this must not fail since the dry-run above was successful */ - mio_conv_bchars_to_uchars_with_cmgr(&bsp[tot_len], &src_len, conv_buf, &conv_len, mio->cmgr, 0); - tot_len += src_len; - - if (conv_len > n) conv_len = n; - PUT_OOCS (conv_buf, conv_len); - - n -= conv_len; - } - } - - if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - #else - if (flagc & FLAGC_DOT) - { - for (n = 0; n < precision && bsp[n]; n++); - } - else - { - for (n = 0; bsp[n]; n++); - } - - width -= n; - - if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - PUT_OOCS (bsp, n); - if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - #endif - break; - } - - case 'S': - { - const mio_uch_t* usp; - mio_oow_t uslen, slen; - - /* zeropad must not take effect for 's' */ - if (flagc & FLAGC_ZEROPAD) padc = ' '; - if (lm_flag & LF_H) goto lowercase_s; - #if defined(MIO_OOCH_IS_UCH) - if (lm_flag & LF_J) goto lowercase_s; - #endif - uppercase_s: - usp = va_arg (ap, mio_uch_t*); - if (usp == MIO_NULL) usp = uch_nullstr; - - #if defined(MIO_OOCH_IS_BCH) - /* get the length */ - if (flagc & FLAGC_DOT) - { - for (uslen = 0; uslen < precision && usp[uslen]; uslen++); - } - else - { - for (uslen = 0; usp[uslen]; uslen++); - } - - if (mio_conv_uchars_to_bchars_with_cmgr(usp, &uslen, MIO_NULL, &slen, mio->cmgr) <= -1) goto oops; - - /* slen holds the length after conversion */ - n = slen; - if ((flagc & FLAGC_DOT) && precision < slen) n = precision; - width -= n; - - if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - { - mio_ooch_t conv_buf[32]; - mio_oow_t conv_len, src_len, tot_len = 0; - while (n > 0) - { - MIO_ASSERT (mio, uslen > tot_len); - - src_len = uslen - tot_len; - conv_len = MIO_COUNTOF(conv_buf); - - /* this must not fail since the dry-run above was successful */ - mio_conv_uchars_to_bchars_with_cmgr (&usp[tot_len], &src_len, conv_buf, &conv_len, mio->cmgr); - tot_len += src_len; - - if (conv_len > n) conv_len = n; - PUT_OOCS (conv_buf, conv_len); - - n -= conv_len; - } - } - if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - #else - if (flagc & FLAGC_DOT) - { - for (n = 0; n < precision && usp[n]; n++); - } - else - { - for (n = 0; usp[n]; n++); - } - - width -= n; - - if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - PUT_OOCS (usp, n); - if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - #endif - break; - } - - case 'k': - case 'K': - { - /* byte or multibyte character string in escape sequence */ - - const mio_uint8_t* bsp; - mio_oow_t k_hex_width; - - /* zeropad must not take effect for 'k' and 'K' - * - * 'h' & 'l' is not used to differentiate qse_mchar_t and qse_wchar_t - * because 'k' means qse_byte_t. - * 'l', results in uppercase hexadecimal letters. - * 'h' drops the leading \x in the output - * -------------------------------------------------------- - * hk -> \x + non-printable in lowercase hex - * k -> all in lowercase hex - * lk -> \x + all in lowercase hex - * -------------------------------------------------------- - * hK -> \x + non-printable in uppercase hex - * K -> all in uppercase hex - * lK -> \x + all in uppercase hex - * -------------------------------------------------------- - * with 'k' or 'K', i don't substitute "(null)" for the NULL pointer - */ - if (flagc & FLAGC_ZEROPAD) padc = ' '; - - bsp = va_arg(ap, mio_uint8_t*); - k_hex_width = (lm_flag & (LF_H | LF_L))? 4: 2; - - if (lm_flag& LF_H) - { - if (flagc & FLAGC_DOT) - { - /* if precision is specifed, it doesn't stop at the value of zero unlike 's' or 'S' */ - for (n = 0; n < precision; n++) width -= BYTE_PRINTABLE(bsp[n])? 1: k_hex_width; - } - else - { - for (n = 0; bsp[n]; n++) width -= BYTE_PRINTABLE(bsp[n])? 1: k_hex_width; - } - } - else - { - if (flagc & FLAGC_DOT) - { - /* if precision is specifed, it doesn't stop at the value of zero unlike 's' or 'S' */ - for (n = 0; n < precision; n++) /* nothing */; - } - else - { - for (n = 0; bsp[n]; n++) /* nothing */; - } - width -= (n * k_hex_width); - } - - if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - - while (n--) - { - if ((lm_flag & LF_H) && BYTE_PRINTABLE(*bsp)) - { - PUT_OOCH(*bsp, 1); - } - else - { - mio_bch_t xbuf[3]; - mio_byte_to_bcstr (*bsp, xbuf, MIO_COUNTOF(xbuf), (16 | (ch == 'k'? MIO_BYTE_TO_BCSTR_LOWERCASE: 0)), '0'); - if (lm_flag & (LF_H | LF_L)) - { - PUT_OOCH('\\', 1); - PUT_OOCH('x', 1); - } - PUT_OOCH(xbuf[0], 1); - PUT_OOCH(xbuf[1], 1); - } - bsp++; - } - - if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - break; - } - - case 'w': - case 'W': - { - /* unicode string in unicode escape sequence. - * - * hw -> \uXXXX, \UXXXXXXXX, printable-byte(only in ascii range) - * w -> \uXXXX, \UXXXXXXXX - * lw -> all in \UXXXXXXXX - */ - const mio_uch_t* usp; - mio_oow_t uwid; - - if (flagc & FLAGC_ZEROPAD) padc = ' '; - usp = va_arg(ap, mio_uch_t*); - - if (flagc & FLAGC_DOT) - { - /* if precision is specifed, it doesn't stop at the value of zero unlike 's' or 'S' */ - for (n = 0; n < precision; n++) - { - if ((lm_flag & LF_H) && BYTE_PRINTABLE(usp[n])) uwid = 1; - else if (!(lm_flag & LF_L) && usp[n] <= 0xFFFF) uwid = 6; - else uwid = 10; - width -= uwid; - } - } - else - { - for (n = 0; usp[n]; n++) - { - if ((lm_flag & LF_H) && BYTE_PRINTABLE(usp[n])) uwid = 1; - else if (!(lm_flag & LF_L) && usp[n] <= 0xFFFF) uwid = 6; - else uwid = 10; - width -= uwid; - } - } - - if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - - while (n--) - { - if ((lm_flag & LF_H) && BYTE_PRINTABLE(*usp)) - { - PUT_OOCH(*usp, 1); - } - else if (!(lm_flag & LF_L) && *usp <= 0xFFFF) - { - mio_uint16_t u16 = *usp; - int extra_flags = ((ch) == 'w'? MIO_BYTE_TO_BCSTR_LOWERCASE: 0); - PUT_OOCH('\\', 1); - PUT_OOCH('u', 1); - PUT_BYTE_IN_HEX((u16 >> 8) & 0xFF, extra_flags); - PUT_BYTE_IN_HEX(u16 & 0xFF, extra_flags); - } - else - { - mio_uint32_t u32 = *usp; - int extra_flags = ((ch) == 'w'? MIO_BYTE_TO_BCSTR_LOWERCASE: 0); - PUT_OOCH('\\', 1); - PUT_OOCH('U', 1); - PUT_BYTE_IN_HEX((u32 >> 24) & 0xFF, extra_flags); - PUT_BYTE_IN_HEX((u32 >> 16) & 0xFF, extra_flags); - PUT_BYTE_IN_HEX((u32 >> 8) & 0xFF, extra_flags); - PUT_BYTE_IN_HEX(u32 & 0xFF, extra_flags); - } - usp++; - } - - if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); - break; - } -#if 0 - case 'e': - case 'E': - case 'f': - case 'F': - case 'g': - case 'G': - /* - case 'a': - case 'A': - */ - { - /* let me rely on snprintf until i implement float-point to string conversion */ - int q; - mio_oow_t fmtlen; - #if (MIO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) - __float128 v_qd; - #endif - long double v_ld; - double v_d; - int dtype = 0; - mio_oow_t newcapa; - - if (lm_flag & LF_J) - { - #if (MIO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) && (MIO_SIZEOF_FLTMAX_T == MIO_SIZEOF___FLOAT128) - v_qd = va_arg (ap, mio_fltmax_t); - dtype = LF_QD; - #elif MIO_SIZEOF_FLTMAX_T == MIO_SIZEOF_DOUBLE - v_d = va_arg (ap, mio_fltmax_t); - #elif MIO_SIZEOF_FLTMAX_T == MIO_SIZEOF_LONG_DOUBLE - v_ld = va_arg (ap, mio_fltmax_t); - dtype = LF_LD; - #else - #error Unsupported mio_flt_t - #endif - } - else if (lm_flag & LF_Z) - { - /* mio_flt_t is limited to double or long double */ - - /* precedence goes to double if sizeof(double) == sizeof(long double) - * for example, %Lf didn't work on some old platforms. - * so i prefer the format specifier with no modifier. - */ - #if MIO_SIZEOF_FLT_T == MIO_SIZEOF_DOUBLE - v_d = va_arg (ap, mio_flt_t); - #elif MIO_SIZEOF_FLT_T == MIO_SIZEOF_LONG_DOUBLE - v_ld = va_arg (ap, mio_flt_t); - dtype = LF_LD; - #else - #error Unsupported mio_flt_t - #endif - } - else if (lm_flag & (LF_LD | LF_L)) - { - v_ld = va_arg (ap, long double); - dtype = LF_LD; - } - #if (MIO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) - else if (lm_flag & (LF_QD | LF_Q)) - { - v_qd = va_arg (ap, __float128); - dtype = LF_QD; - } - #endif - else if (flagc & FLAGC_LENMOD) - { - goto invalid_format; - } - else - { - v_d = va_arg (ap, double); - } - - fmtlen = fmt - percent; - if (fmtlen > fltfmt->capa) - { - if (fltfmt->ptr == fltfmt->buf) - { - fltfmt->ptr = MIO_MMGR_ALLOC (MIO_MMGR_GETDFL(), MIO_SIZEOF(*fltfmt->ptr) * (fmtlen + 1)); - if (fltfmt->ptr == MIO_NULL) goto oops; - } - else - { - mio_mchar_t* tmpptr; - - tmpptr = MIO_MMGR_REALLOC (MIO_MMGR_GETDFL(), fltfmt->ptr, MIO_SIZEOF(*fltfmt->ptr) * (fmtlen + 1)); - if (tmpptr == MIO_NULL) goto oops; - fltfmt->ptr = tmpptr; - } - - fltfmt->capa = fmtlen; - } - - /* compose back the format specifier */ - fmtlen = 0; - fltfmt->ptr[fmtlen++] = '%'; - if (flagc & FLAGC_SPACE) fltfmt->ptr[fmtlen++] = ' '; - if (flagc & FLAGC_SHARP) fltfmt->ptr[fmtlen++] = '#'; - if (flagc & FLAGC_SIGN) fltfmt->ptr[fmtlen++] = '+'; - if (flagc & FLAGC_LEFTADJ) fltfmt->ptr[fmtlen++] = '-'; - if (flagc & FLAGC_ZEROPAD) fltfmt->ptr[fmtlen++] = '0'; - - if (flagc & FLAGC_STAR1) fltfmt->ptr[fmtlen++] = '*'; - else if (flagc & FLAGC_WIDTH) - { - fmtlen += mio_fmtuintmaxtombs ( - &fltfmt->ptr[fmtlen], fltfmt->capa - fmtlen, - width, 10, -1, '\0', MIO_NULL); - } - if (flagc & FLAGC_DOT) fltfmt->ptr[fmtlen++] = '.'; - if (flagc & FLAGC_STAR2) fltfmt->ptr[fmtlen++] = '*'; - else if (flagc & FLAGC_PRECISION) - { - fmtlen += mio_fmtuintmaxtombs ( - &fltfmt->ptr[fmtlen], fltfmt->capa - fmtlen, - precision, 10, -1, '\0', MIO_NULL); - } - - if (dtype == LF_LD) - fltfmt->ptr[fmtlen++] = 'L'; - #if (MIO_SIZEOF___FLOAT128 > 0) - else if (dtype == LF_QD) - fltfmt->ptr[fmtlen++] = 'Q'; - #endif - - fltfmt->ptr[fmtlen++] = ch; - fltfmt->ptr[fmtlen] = '\0'; - - #if defined(HAVE_SNPRINTF) - /* nothing special here */ - #else - /* best effort to avoid buffer overflow when no snprintf is available. - * i really can't do much if it happens. */ - newcapa = precision + width + 32; - if (fltout->capa < newcapa) - { - MIO_ASSERT (mio, fltout->ptr == fltout->buf); - - fltout->ptr = MIO_MMGR_ALLOC (MIO_MMGR_GETDFL(), MIO_SIZEOF(char_t) * (newcapa + 1)); - if (fltout->ptr == MIO_NULL) goto oops; - fltout->capa = newcapa; - } - #endif - - while (1) - { - - if (dtype == LF_LD) - { - #if defined(HAVE_SNPRINTF) - q = snprintf ((mio_mchar_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_ld); - #else - q = sprintf ((mio_mchar_t*)fltout->ptr, fltfmt->ptr, v_ld); - #endif - } - #if (MIO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) - else if (dtype == LF_QD) - { - q = quadmath_snprintf ((mio_mchar_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_qd); - } - #endif - else - { - #if defined(HAVE_SNPRINTF) - q = snprintf ((mio_mchar_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_d); - #else - q = sprintf ((mio_mchar_t*)fltout->ptr, fltfmt->ptr, v_d); - #endif - } - if (q <= -1) goto oops; - if (q <= fltout->capa) break; - - newcapa = fltout->capa * 2; - if (newcapa < q) newcapa = q; - - if (fltout->ptr == fltout->sbuf) - { - fltout->ptr = MIO_MMGR_ALLOC (MIO_MMGR_GETDFL(), MIO_SIZEOF(char_t) * (newcapa + 1)); - if (fltout->ptr == MIO_NULL) goto oops; - } - else - { - char_t* tmpptr; - - tmpptr = MIO_MMGR_REALLOC (MIO_MMGR_GETDFL(), fltout->ptr, MIO_SIZEOF(char_t) * (newcapa + 1)); - if (tmpptr == MIO_NULL) goto oops; - fltout->ptr = tmpptr; - } - fltout->capa = newcapa; - } - - if (MIO_SIZEOF(char_t) != MIO_SIZEOF(mio_mchar_t)) - { - fltout->ptr[q] = '\0'; - while (q > 0) - { - q--; - fltout->ptr[q] = ((mio_mchar_t*)fltout->ptr)[q]; - } - } - - sp = fltout->ptr; - flagc &= ~FLAGC_DOT; - width = 0; - precision = 0; - goto print_lowercase_s; - } -#endif - - - handle_nosign: - sign = 0; - if (lm_flag & LF_J) - { - #if defined(__GNUC__) && \ - (MIO_SIZEOF_UINTMAX_T > MIO_SIZEOF_OOW_T) && \ - (MIO_SIZEOF_UINTMAX_T != MIO_SIZEOF_LONG_LONG) && \ - (MIO_SIZEOF_UINTMAX_T != MIO_SIZEOF_LONG) - /* GCC-compiled binaries crashed when getting mio_uintmax_t with va_arg. - * This is just a work-around for it */ - int i; - for (i = 0, num = 0; i < MIO_SIZEOF(mio_uintmax_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)); - #else - register int shift = i * MIO_SIZEOF(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_uintmax_t); - #endif - } -#if 0 - else if (lm_flag & LF_T) - num = va_arg (ap, mio_ptrdiff_t); -#endif - else if (lm_flag & LF_Z) - num = va_arg (ap, mio_oow_t); - #if (MIO_SIZEOF_LONG_LONG > 0) - else if (lm_flag & LF_Q) - num = va_arg (ap, unsigned long long int); - #endif - else if (lm_flag & (LF_L | LF_LD)) - num = va_arg (ap, unsigned long int); - else if (lm_flag & LF_H) - num = (unsigned short int)va_arg (ap, int); - else if (lm_flag & LF_C) - num = (unsigned char)va_arg (ap, int); - else - num = va_arg (ap, unsigned int); - goto number; - - handle_sign: - if (lm_flag & LF_J) - { - #if defined(__GNUC__) && \ - (MIO_SIZEOF_INTMAX_T > MIO_SIZEOF_OOI_T) && \ - (MIO_SIZEOF_UINTMAX_T != MIO_SIZEOF_LONG_LONG) && \ - (MIO_SIZEOF_UINTMAX_T != MIO_SIZEOF_LONG) - /* GCC-compiled binraries crashed when getting mio_uintmax_t with va_arg. - * This is just a work-around for it */ - int i; - 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)); - #else - register int shift = i * MIO_SIZEOF(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); - #endif - } - -#if 0 - else if (lm_flag & LF_T) - num = va_arg(ap, mio_ptrdiff_t); -#endif - else if (lm_flag & LF_Z) - 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); - #endif - else if (lm_flag & (LF_L | LF_LD)) - num = va_arg (ap, long int); - else if (lm_flag & LF_H) - num = (short int)va_arg (ap, int); - else if (lm_flag & LF_C) - num = (char)va_arg (ap, int); - else - num = va_arg (ap, int); - - number: - if (sign && (mio_intmax_t)num < 0) - { - neg = 1; - num = -(mio_intmax_t)num; - } - - nbufp = sprintn (nbuf, num, base, &tmp); - if ((flagc & FLAGC_SHARP) && num != 0) - { - if (base == 2 || base == 8) tmp += 2; - else if (base == 16) tmp += 3; - } - if (neg) tmp++; - else if (flagc & FLAGC_SIGN) tmp++; - else if (flagc & FLAGC_SPACE) tmp++; - - numlen = (int)((const mio_bch_t*)nbufp - (const mio_bch_t*)nbuf); - if ((flagc & FLAGC_DOT) && precision > numlen) - { - /* extra zeros for precision specified */ - tmp += (precision - numlen); - } - - if (!(flagc & FLAGC_LEFTADJ) && !(flagc & FLAGC_ZEROPAD) && width > 0 && (width -= tmp) > 0) - { - PUT_OOCH (padc, width); - width = 0; - } - - if (neg) PUT_OOCH ('-', 1); - else if (flagc & FLAGC_SIGN) PUT_OOCH ('+', 1); - else if (flagc & FLAGC_SPACE) PUT_OOCH (' ', 1); - - if ((flagc & FLAGC_SHARP) && num != 0) - { - if (base == 2) - { - PUT_OOCH ('2', 1); - PUT_OOCH ('r', 1); - } - if (base == 8) - { - PUT_OOCH ('8', 1); - PUT_OOCH ('r', 1); - } - else if (base == 16) - { - PUT_OOCH ('1', 1); - PUT_OOCH ('6', 1); - PUT_OOCH ('r', 1); - } - } - - if ((flagc & FLAGC_DOT) && precision > numlen) - { - /* extra zeros for precision specified */ - PUT_OOCH ('0', precision - numlen); - } - - if (!(flagc & FLAGC_LEFTADJ) && width > 0 && (width -= tmp) > 0) - { - PUT_OOCH (padc, width); - } - - while (*nbufp) PUT_OOCH (*nbufp--, 1); /* output actual digits */ - - if ((flagc & FLAGC_LEFTADJ) && width > 0 && (width -= tmp) > 0) - { - PUT_OOCH (padc, width); - } - break; - - invalid_format: - #if defined(FMTCHAR_IS_OOCH) - PUT_OOCS (percent, fmt - percent); - #else - while (percent < fmt) PUT_OOCH (*percent++, 1); - #endif - break; - - default: - #if defined(FMTCHAR_IS_OOCH) - PUT_OOCS (percent, fmt - percent); - #else - while (percent < fmt) PUT_OOCH (*percent++, 1); - #endif - /* - * Since we ignore an formatting argument it is no - * longer safe to obey the remaining formatting - * arguments as the arguments will no longer match - * the format specs. - */ - stop = 1; - break; - } - } - -done: - return 0; - -oops: - return -1; -} -#undef PUT_OOCH diff --git a/mio/lib/mio-prv.h b/mio/lib/mio-prv.h index 05818b4..9a0259d 100644 --- a/mio/lib/mio-prv.h +++ b/mio/lib/mio-prv.h @@ -29,7 +29,6 @@ #include "mio.h" #include "mio-utl.h" -#include #if defined(__has_builtin) @@ -160,24 +159,6 @@ int mio_gettmrtmout ( mio_ntime_t* tmout ); -/* ========================================================================= */ -/* err.c */ -/* ========================================================================= */ - -void mio_seterrbfmtv ( - mio_t* mio, - mio_errnum_t errnum, - const mio_bch_t* fmt, - va_list ap -); - -void mio_seterrufmtv ( - mio_t* mio, - mio_errnum_t errnum, - const mio_uch_t* fmt, - va_list ap -); - /* ========================================================================== */ /* system intefaces */ /* ========================================================================== */ diff --git a/mio/lib/mio-utl.h b/mio/lib/mio-utl.h index 897f8ac..4adfa5b 100644 --- a/mio/lib/mio-utl.h +++ b/mio/lib/mio-utl.h @@ -28,6 +28,7 @@ #define _MIO_UTL_H_ #include "mio-cmn.h" +#include /* ========================================================================= * ENDIAN CHANGE OF A CONSTANT @@ -154,6 +155,44 @@ # error UNKNOWN ENDIAN #endif +/* ========================================================================= + * FORMATTED OUTPUT + * ========================================================================= */ +typedef struct mio_fmtout_t mio_fmtout_t; + +typedef int (*mio_fmtout_putbcs_t) ( + mio_fmtout_t* fmtout, + const mio_bch_t* ptr, + mio_oow_t len +); + +typedef int (*mio_fmtout_putucs_t) ( + mio_fmtout_t* fmtout, + const mio_uch_t* ptr, + mio_oow_t len +); + +enum mio_fmtout_fmt_type_t +{ + MIO_FMTOUT_FMT_TYPE_BCH = 0, + MIO_FMTOUT_FMT_TYPE_UCH +}; +typedef enum mio_fmtout_fmt_type_t mio_fmtout_fmt_type_t; + + +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_fmtout_fmt_type_t fmt_type; + const void* fmt_str; +}; + #ifdef __cplusplus extern "C" { @@ -510,8 +549,38 @@ MIO_EXPORT mio_oow_t mio_utf8_to_uc ( mio_uch_t* uc ); -/* ------------------------------------------------------------------------- */ +/* ========================================================================= + * FORMATTED OUTPUT + * ========================================================================= */ +MIO_EXPORT int mio_bfmt_outv ( + mio_fmtout_t* fmtout, + const mio_bch_t* fmt, + va_list ap +); + +MIO_EXPORT int mio_ufmt_outv ( + mio_fmtout_t* fmtout, + const mio_uch_t* fmt, + va_list ap +); + + +MIO_EXPORT int mio_bfmt_out ( + mio_fmtout_t* fmtout, + const mio_bch_t* fmt, + ... +); + +MIO_EXPORT int mio_ufmt_out ( + mio_fmtout_t* fmtout, + const mio_uch_t* fmt, + ... +); + +/* ========================================================================= + * BIT SWAP + * ========================================================================= */ #if defined(MIO_HAVE_INLINE) #if defined(MIO_HAVE_UINT16_T) diff --git a/mio/lib/mio.h b/mio/lib/mio.h index c28c9b0..7f7f8af 100644 --- a/mio/lib/mio.h +++ b/mio/lib/mio.h @@ -27,7 +27,8 @@ #ifndef _MIO_H_ #define _MIO_H_ -#include +#include "mio-cmn.h" +#include #if defined(_WIN32) typedef mio_uintptr_t qse_syshnd_t; @@ -679,6 +680,20 @@ MIO_EXPORT void mio_seterrufmt ( ... ); +MIO_EXPORT void mio_seterrbfmtv ( + mio_t* mio, + mio_errnum_t errnum, + const mio_bch_t* fmt, + va_list ap +); + +MIO_EXPORT void mio_seterrufmtv ( + mio_t* mio, + mio_errnum_t errnum, + const mio_uch_t* fmt, + va_list ap +); + MIO_EXPORT void mio_seterrbfmtwithsyserr ( mio_t* mio, int syserr_type,