diff --git a/bin/Makefile.am b/bin/Makefile.am index 8509e04..4ec1fc2 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -32,27 +32,27 @@ hcl_DEPENDENCIES = ../lib/libhcl.la if ENABLE_HCLEX -## cb-impl.c is included in libhclex. +## cb-impl.c is included in libhclx. ## so ../lib/cb-impl.h and ../lib/cb-impl.c are not listed as sources bin_PROGRAMS += hcls hcls_SOURCES = main-s.c hcls_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) hcls_LDFLAGS = $(LDFLAGS_ALL_COMMON) -hcls_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex -hcls_DEPENDENCIES = ../lib/libhclex.la +hcls_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhclx +hcls_DEPENDENCIES = ../lib/libhclx.la bin_PROGRAMS += hclc hclc_SOURCES = main-c.c hclc_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) hclc_LDFLAGS = $(LDFLAGS_ALL_COMMON) -hclc_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex -hclc_DEPENDENCIES = ../lib/libhclex.la +hclc_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhclx +hclc_DEPENDENCIES = ../lib/libhclx.la bin_PROGRAMS += hclj hclj_SOURCES = main-j.c hclj_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) hclj_LDFLAGS = $(LDFLAGS_ALL_COMMON) -hclj_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex -hclj_DEPENDENCIES = ../lib/libhclex.la +hclj_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhclx +hclj_DEPENDENCIES = ../lib/libhclx.la endif diff --git a/bin/Makefile.in b/bin/Makefile.in index 9374cdf..386604d 100644 --- a/bin/Makefile.in +++ b/bin/Makefile.in @@ -384,18 +384,18 @@ hcl_DEPENDENCIES = ../lib/libhcl.la @ENABLE_HCLEX_TRUE@hcls_SOURCES = main-s.c @ENABLE_HCLEX_TRUE@hcls_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) @ENABLE_HCLEX_TRUE@hcls_LDFLAGS = $(LDFLAGS_ALL_COMMON) -@ENABLE_HCLEX_TRUE@hcls_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex -@ENABLE_HCLEX_TRUE@hcls_DEPENDENCIES = ../lib/libhclex.la +@ENABLE_HCLEX_TRUE@hcls_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhclx +@ENABLE_HCLEX_TRUE@hcls_DEPENDENCIES = ../lib/libhclx.la @ENABLE_HCLEX_TRUE@hclc_SOURCES = main-c.c @ENABLE_HCLEX_TRUE@hclc_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) @ENABLE_HCLEX_TRUE@hclc_LDFLAGS = $(LDFLAGS_ALL_COMMON) -@ENABLE_HCLEX_TRUE@hclc_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex -@ENABLE_HCLEX_TRUE@hclc_DEPENDENCIES = ../lib/libhclex.la +@ENABLE_HCLEX_TRUE@hclc_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhclx +@ENABLE_HCLEX_TRUE@hclc_DEPENDENCIES = ../lib/libhclx.la @ENABLE_HCLEX_TRUE@hclj_SOURCES = main-j.c @ENABLE_HCLEX_TRUE@hclj_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) @ENABLE_HCLEX_TRUE@hclj_LDFLAGS = $(LDFLAGS_ALL_COMMON) -@ENABLE_HCLEX_TRUE@hclj_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -lhclex -@ENABLE_HCLEX_TRUE@hclj_DEPENDENCIES = ../lib/libhclex.la +@ENABLE_HCLEX_TRUE@hclj_LDADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhclx +@ENABLE_HCLEX_TRUE@hclj_DEPENDENCIES = ../lib/libhclx.la all: all-am .SUFFIXES: diff --git a/bin/main.c b/bin/main.c index 3b3a366..1a3ac71 100644 --- a/bin/main.c +++ b/bin/main.c @@ -1192,7 +1192,7 @@ count++; code_offset = hcl_getbclen(hcl); - if (verbose) hcl_proutbfmt (hcl, 0, "\n"); /* flush the output buffer by hcl_print above */ + if (verbose) hcl_prbfmt (hcl, "\n"); /* flush the output buffer by hcl_print above */ if (hcl_compile(hcl, obj) <= -1) { if (hcl->errnum == HCL_ESYNERR) diff --git a/lib/Makefile.am b/lib/Makefile.am index 976497b..4fa1e0c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -70,11 +70,10 @@ libhcl_la_SOURCES = \ dic.c \ err.c \ exec.c \ + fmt.c \ gc.c \ hcl.c \ heap.c \ - logfmtv.h \ - logfmt.c \ number.c \ obj.c \ opt-impl.h \ @@ -103,19 +102,19 @@ libhcl_la_DEPENDENCIES += $(abs_builddir)/../mod/libhcl-sys.la endif if ENABLE_HCLEX -pkglib_LTLIBRARIES += libhclex.la +pkglib_LTLIBRARIES += libhclx.la pkginclude_HEADERS += hcl-c.h hcl-s.h hcl-tmr.h hcl-xutl.h hcl-json.h -libhclex_la_SOURCES = \ +libhclx_la_SOURCES = \ tmr.c hcl-tmr.h \ xutl.c xutl-sa.h hcl-xutl.h \ json.c hcl-json.h \ cb-impl.h cb-impl.c \ hcl-s.c hcl-s.h \ hcl-c.c hcl-c.h -libhclex_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) $(CPPFLAGS_PFMOD) -libhclex_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) -libhclex_la_LIBADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -libhclex_la_DEPENDENCIES = libhcl.la +libhclx_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) $(CPPFLAGS_PFMOD) +libhclx_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) +libhclx_la_LIBADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl +libhclx_la_DEPENDENCIES = libhcl.la endif diff --git a/lib/Makefile.in b/lib/Makefile.in index c196b01..30427a8 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -98,7 +98,7 @@ host_triplet = @host@ @ENABLE_STATIC_MODULE_TRUE@ $(abs_builddir)/../mod/libhcl-dic.la \ @ENABLE_STATIC_MODULE_TRUE@ $(abs_builddir)/../mod/libhcl-str.la \ @ENABLE_STATIC_MODULE_TRUE@ $(abs_builddir)/../mod/libhcl-sys.la -@ENABLE_HCLEX_TRUE@am__append_8 = libhclex.la +@ENABLE_HCLEX_TRUE@am__append_8 = libhclx.la @ENABLE_HCLEX_TRUE@am__append_9 = hcl-c.h hcl-s.h hcl-tmr.h hcl-xutl.h hcl-json.h subdir = lib ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -154,8 +154,8 @@ am__DEPENDENCIES_5 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \ $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_4) am_libhcl_la_OBJECTS = libhcl_la-bigint.lo libhcl_la-comp.lo \ libhcl_la-debug.lo libhcl_la-decode.lo libhcl_la-dic.lo \ - libhcl_la-err.lo libhcl_la-exec.lo libhcl_la-gc.lo \ - libhcl_la-hcl.lo libhcl_la-heap.lo libhcl_la-logfmt.lo \ + libhcl_la-err.lo libhcl_la-exec.lo libhcl_la-fmt.lo \ + libhcl_la-gc.lo libhcl_la-hcl.lo libhcl_la-heap.lo \ libhcl_la-number.lo libhcl_la-obj.lo libhcl_la-opt.lo \ libhcl_la-prim.lo libhcl_la-print.lo libhcl_la-rbt.lo \ libhcl_la-read.lo libhcl_la-sym.lo libhcl_la-utf8.lo \ @@ -168,18 +168,18 @@ am__v_lt_1 = libhcl_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(libhcl_la_LDFLAGS) $(LDFLAGS) -o $@ -am__libhclex_la_SOURCES_DIST = tmr.c hcl-tmr.h xutl.c xutl-sa.h \ +am__libhclx_la_SOURCES_DIST = tmr.c hcl-tmr.h xutl.c xutl-sa.h \ hcl-xutl.h json.c hcl-json.h cb-impl.h cb-impl.c hcl-s.c \ hcl-s.h hcl-c.c hcl-c.h -@ENABLE_HCLEX_TRUE@am_libhclex_la_OBJECTS = libhclex_la-tmr.lo \ -@ENABLE_HCLEX_TRUE@ libhclex_la-xutl.lo libhclex_la-json.lo \ -@ENABLE_HCLEX_TRUE@ libhclex_la-cb-impl.lo libhclex_la-hcl-s.lo \ -@ENABLE_HCLEX_TRUE@ libhclex_la-hcl-c.lo -libhclex_la_OBJECTS = $(am_libhclex_la_OBJECTS) -libhclex_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ +@ENABLE_HCLEX_TRUE@am_libhclx_la_OBJECTS = libhclx_la-tmr.lo \ +@ENABLE_HCLEX_TRUE@ libhclx_la-xutl.lo libhclx_la-json.lo \ +@ENABLE_HCLEX_TRUE@ libhclx_la-cb-impl.lo libhclx_la-hcl-s.lo \ +@ENABLE_HCLEX_TRUE@ libhclx_la-hcl-c.lo +libhclx_la_OBJECTS = $(am_libhclx_la_OBJECTS) +libhclx_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(libhclex_la_LDFLAGS) $(LDFLAGS) -o $@ -@ENABLE_HCLEX_TRUE@am_libhclex_la_rpath = -rpath $(pkglibdir) + $(libhclx_la_LDFLAGS) $(LDFLAGS) -o $@ +@ENABLE_HCLEX_TRUE@am_libhclx_la_rpath = -rpath $(pkglibdir) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -214,8 +214,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 = $(libhcl_la_SOURCES) $(libhclex_la_SOURCES) -DIST_SOURCES = $(libhcl_la_SOURCES) $(am__libhclex_la_SOURCES_DIST) +SOURCES = $(libhcl_la_SOURCES) $(libhclx_la_SOURCES) +DIST_SOURCES = $(libhcl_la_SOURCES) $(am__libhclx_la_SOURCES_DIST) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -444,11 +444,10 @@ libhcl_la_SOURCES = \ dic.c \ err.c \ exec.c \ + fmt.c \ gc.c \ hcl.c \ heap.c \ - logfmtv.h \ - logfmt.c \ number.c \ obj.c \ opt-impl.h \ @@ -465,7 +464,7 @@ libhcl_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) libhcl_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) libhcl_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_6) libhcl_la_DEPENDENCIES = $(am__append_7) -@ENABLE_HCLEX_TRUE@libhclex_la_SOURCES = \ +@ENABLE_HCLEX_TRUE@libhclx_la_SOURCES = \ @ENABLE_HCLEX_TRUE@ tmr.c hcl-tmr.h \ @ENABLE_HCLEX_TRUE@ xutl.c xutl-sa.h hcl-xutl.h \ @ENABLE_HCLEX_TRUE@ json.c hcl-json.h \ @@ -473,10 +472,10 @@ libhcl_la_DEPENDENCIES = $(am__append_7) @ENABLE_HCLEX_TRUE@ hcl-s.c hcl-s.h \ @ENABLE_HCLEX_TRUE@ hcl-c.c hcl-c.h -@ENABLE_HCLEX_TRUE@libhclex_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) $(CPPFLAGS_PFMOD) -@ENABLE_HCLEX_TRUE@libhclex_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) -@ENABLE_HCLEX_TRUE@libhclex_la_LIBADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl -@ENABLE_HCLEX_TRUE@libhclex_la_DEPENDENCIES = libhcl.la +@ENABLE_HCLEX_TRUE@libhclx_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) $(CPPFLAGS_PFMOD) +@ENABLE_HCLEX_TRUE@libhclx_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) +@ENABLE_HCLEX_TRUE@libhclx_la_LIBADD = $(LIBADD_LIB_COMMON) $(PTHREAD_LIBS) -lhcl +@ENABLE_HCLEX_TRUE@libhclx_la_DEPENDENCIES = libhcl.la all: hcl-cfg.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -565,8 +564,8 @@ clean-pkglibLTLIBRARIES: libhcl.la: $(libhcl_la_OBJECTS) $(libhcl_la_DEPENDENCIES) $(EXTRA_libhcl_la_DEPENDENCIES) $(AM_V_CCLD)$(libhcl_la_LINK) -rpath $(pkglibdir) $(libhcl_la_OBJECTS) $(libhcl_la_LIBADD) $(LIBS) -libhclex.la: $(libhclex_la_OBJECTS) $(libhclex_la_DEPENDENCIES) $(EXTRA_libhclex_la_DEPENDENCIES) - $(AM_V_CCLD)$(libhclex_la_LINK) $(am_libhclex_la_rpath) $(libhclex_la_OBJECTS) $(libhclex_la_LIBADD) $(LIBS) +libhclx.la: $(libhclx_la_OBJECTS) $(libhclx_la_DEPENDENCIES) $(EXTRA_libhclx_la_DEPENDENCIES) + $(AM_V_CCLD)$(libhclx_la_LINK) $(am_libhclx_la_rpath) $(libhclx_la_OBJECTS) $(libhclx_la_LIBADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -581,10 +580,10 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-dic.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-err.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-exec.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-fmt.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-gc.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-hcl.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-heap.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-logfmt.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-number.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-obj.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-opt.Plo@am__quote@ @@ -595,12 +594,12 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-sym.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-utf8.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_la-utl.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhclex_la-cb-impl.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhclex_la-hcl-c.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhclex_la-hcl-s.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhclex_la-json.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhclex_la-tmr.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhclex_la-xutl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhclx_la-cb-impl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhclx_la-hcl-c.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhclx_la-hcl-s.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhclx_la-json.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhclx_la-tmr.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhclx_la-xutl.Plo@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @@ -675,6 +674,13 @@ libhcl_la-exec.lo: exec.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) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhcl_la-exec.lo `test -f 'exec.c' || echo '$(srcdir)/'`exec.c +libhcl_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) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhcl_la-fmt.lo -MD -MP -MF $(DEPDIR)/libhcl_la-fmt.Tpo -c -o libhcl_la-fmt.lo `test -f 'fmt.c' || echo '$(srcdir)/'`fmt.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhcl_la-fmt.Tpo $(DEPDIR)/libhcl_la-fmt.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='fmt.c' object='libhcl_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) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhcl_la-fmt.lo `test -f 'fmt.c' || echo '$(srcdir)/'`fmt.c + libhcl_la-gc.lo: gc.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhcl_la-gc.lo -MD -MP -MF $(DEPDIR)/libhcl_la-gc.Tpo -c -o libhcl_la-gc.lo `test -f 'gc.c' || echo '$(srcdir)/'`gc.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhcl_la-gc.Tpo $(DEPDIR)/libhcl_la-gc.Plo @@ -696,13 +702,6 @@ libhcl_la-heap.lo: heap.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) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhcl_la-heap.lo `test -f 'heap.c' || echo '$(srcdir)/'`heap.c -libhcl_la-logfmt.lo: logfmt.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhcl_la-logfmt.lo -MD -MP -MF $(DEPDIR)/libhcl_la-logfmt.Tpo -c -o libhcl_la-logfmt.lo `test -f 'logfmt.c' || echo '$(srcdir)/'`logfmt.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhcl_la-logfmt.Tpo $(DEPDIR)/libhcl_la-logfmt.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='logfmt.c' object='libhcl_la-logfmt.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) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhcl_la-logfmt.lo `test -f 'logfmt.c' || echo '$(srcdir)/'`logfmt.c - libhcl_la-number.lo: number.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhcl_la-number.lo -MD -MP -MF $(DEPDIR)/libhcl_la-number.Tpo -c -o libhcl_la-number.lo `test -f 'number.c' || echo '$(srcdir)/'`number.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhcl_la-number.Tpo $(DEPDIR)/libhcl_la-number.Plo @@ -773,47 +772,47 @@ libhcl_la-utl.lo: utl.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) $(libhcl_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhcl_la-utl.lo `test -f 'utl.c' || echo '$(srcdir)/'`utl.c -libhclex_la-tmr.lo: tmr.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhclex_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhclex_la-tmr.lo -MD -MP -MF $(DEPDIR)/libhclex_la-tmr.Tpo -c -o libhclex_la-tmr.lo `test -f 'tmr.c' || echo '$(srcdir)/'`tmr.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhclex_la-tmr.Tpo $(DEPDIR)/libhclex_la-tmr.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tmr.c' object='libhclex_la-tmr.lo' libtool=yes @AMDEPBACKSLASH@ +libhclx_la-tmr.lo: tmr.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhclx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhclx_la-tmr.lo -MD -MP -MF $(DEPDIR)/libhclx_la-tmr.Tpo -c -o libhclx_la-tmr.lo `test -f 'tmr.c' || echo '$(srcdir)/'`tmr.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhclx_la-tmr.Tpo $(DEPDIR)/libhclx_la-tmr.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tmr.c' object='libhclx_la-tmr.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) $(libhclex_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhclex_la-tmr.lo `test -f 'tmr.c' || echo '$(srcdir)/'`tmr.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) $(libhclx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhclx_la-tmr.lo `test -f 'tmr.c' || echo '$(srcdir)/'`tmr.c -libhclex_la-xutl.lo: xutl.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhclex_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhclex_la-xutl.lo -MD -MP -MF $(DEPDIR)/libhclex_la-xutl.Tpo -c -o libhclex_la-xutl.lo `test -f 'xutl.c' || echo '$(srcdir)/'`xutl.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhclex_la-xutl.Tpo $(DEPDIR)/libhclex_la-xutl.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xutl.c' object='libhclex_la-xutl.lo' libtool=yes @AMDEPBACKSLASH@ +libhclx_la-xutl.lo: xutl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhclx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhclx_la-xutl.lo -MD -MP -MF $(DEPDIR)/libhclx_la-xutl.Tpo -c -o libhclx_la-xutl.lo `test -f 'xutl.c' || echo '$(srcdir)/'`xutl.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhclx_la-xutl.Tpo $(DEPDIR)/libhclx_la-xutl.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xutl.c' object='libhclx_la-xutl.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) $(libhclex_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhclex_la-xutl.lo `test -f 'xutl.c' || echo '$(srcdir)/'`xutl.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) $(libhclx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhclx_la-xutl.lo `test -f 'xutl.c' || echo '$(srcdir)/'`xutl.c -libhclex_la-json.lo: json.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhclex_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhclex_la-json.lo -MD -MP -MF $(DEPDIR)/libhclex_la-json.Tpo -c -o libhclex_la-json.lo `test -f 'json.c' || echo '$(srcdir)/'`json.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhclex_la-json.Tpo $(DEPDIR)/libhclex_la-json.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='json.c' object='libhclex_la-json.lo' libtool=yes @AMDEPBACKSLASH@ +libhclx_la-json.lo: json.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhclx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhclx_la-json.lo -MD -MP -MF $(DEPDIR)/libhclx_la-json.Tpo -c -o libhclx_la-json.lo `test -f 'json.c' || echo '$(srcdir)/'`json.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhclx_la-json.Tpo $(DEPDIR)/libhclx_la-json.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='json.c' object='libhclx_la-json.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) $(libhclex_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhclex_la-json.lo `test -f 'json.c' || echo '$(srcdir)/'`json.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) $(libhclx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhclx_la-json.lo `test -f 'json.c' || echo '$(srcdir)/'`json.c -libhclex_la-cb-impl.lo: cb-impl.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhclex_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhclex_la-cb-impl.lo -MD -MP -MF $(DEPDIR)/libhclex_la-cb-impl.Tpo -c -o libhclex_la-cb-impl.lo `test -f 'cb-impl.c' || echo '$(srcdir)/'`cb-impl.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhclex_la-cb-impl.Tpo $(DEPDIR)/libhclex_la-cb-impl.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cb-impl.c' object='libhclex_la-cb-impl.lo' libtool=yes @AMDEPBACKSLASH@ +libhclx_la-cb-impl.lo: cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhclx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhclx_la-cb-impl.lo -MD -MP -MF $(DEPDIR)/libhclx_la-cb-impl.Tpo -c -o libhclx_la-cb-impl.lo `test -f 'cb-impl.c' || echo '$(srcdir)/'`cb-impl.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhclx_la-cb-impl.Tpo $(DEPDIR)/libhclx_la-cb-impl.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cb-impl.c' object='libhclx_la-cb-impl.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) $(libhclex_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhclex_la-cb-impl.lo `test -f 'cb-impl.c' || echo '$(srcdir)/'`cb-impl.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) $(libhclx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhclx_la-cb-impl.lo `test -f 'cb-impl.c' || echo '$(srcdir)/'`cb-impl.c -libhclex_la-hcl-s.lo: hcl-s.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhclex_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhclex_la-hcl-s.lo -MD -MP -MF $(DEPDIR)/libhclex_la-hcl-s.Tpo -c -o libhclex_la-hcl-s.lo `test -f 'hcl-s.c' || echo '$(srcdir)/'`hcl-s.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhclex_la-hcl-s.Tpo $(DEPDIR)/libhclex_la-hcl-s.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hcl-s.c' object='libhclex_la-hcl-s.lo' libtool=yes @AMDEPBACKSLASH@ +libhclx_la-hcl-s.lo: hcl-s.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhclx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhclx_la-hcl-s.lo -MD -MP -MF $(DEPDIR)/libhclx_la-hcl-s.Tpo -c -o libhclx_la-hcl-s.lo `test -f 'hcl-s.c' || echo '$(srcdir)/'`hcl-s.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhclx_la-hcl-s.Tpo $(DEPDIR)/libhclx_la-hcl-s.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hcl-s.c' object='libhclx_la-hcl-s.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) $(libhclex_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhclex_la-hcl-s.lo `test -f 'hcl-s.c' || echo '$(srcdir)/'`hcl-s.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) $(libhclx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhclx_la-hcl-s.lo `test -f 'hcl-s.c' || echo '$(srcdir)/'`hcl-s.c -libhclex_la-hcl-c.lo: hcl-c.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhclex_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhclex_la-hcl-c.lo -MD -MP -MF $(DEPDIR)/libhclex_la-hcl-c.Tpo -c -o libhclex_la-hcl-c.lo `test -f 'hcl-c.c' || echo '$(srcdir)/'`hcl-c.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhclex_la-hcl-c.Tpo $(DEPDIR)/libhclex_la-hcl-c.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hcl-c.c' object='libhclex_la-hcl-c.lo' libtool=yes @AMDEPBACKSLASH@ +libhclx_la-hcl-c.lo: hcl-c.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhclx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhclx_la-hcl-c.lo -MD -MP -MF $(DEPDIR)/libhclx_la-hcl-c.Tpo -c -o libhclx_la-hcl-c.lo `test -f 'hcl-c.c' || echo '$(srcdir)/'`hcl-c.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhclx_la-hcl-c.Tpo $(DEPDIR)/libhclx_la-hcl-c.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hcl-c.c' object='libhclx_la-hcl-c.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) $(libhclex_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhclex_la-hcl-c.lo `test -f 'hcl-c.c' || echo '$(srcdir)/'`hcl-c.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) $(libhclx_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhclx_la-hcl-c.lo `test -f 'hcl-c.c' || echo '$(srcdir)/'`hcl-c.c mostlyclean-libtool: -rm -f *.lo diff --git a/lib/err.c b/lib/err.c index 8eb0357..cf22251 100644 --- a/lib/err.c +++ b/lib/err.c @@ -191,6 +191,132 @@ void hcl_seterrnum (hcl_t* hcl, hcl_errnum_t errnum) hcl->errmsg.len = 0; } + +static int err_bcs (hcl_fmtout_t* fmtout, const hcl_bch_t* ptr, hcl_oow_t len) +{ + hcl_t* hcl = (hcl_t*)fmtout->ctx; + hcl_oow_t max; + + max = HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len - 1; + +#if defined(HCL_OOCH_IS_UCH) + if (max <= 0) return 1; + hcl_conv_bchars_to_uchars_with_cmgr (ptr, &len, &hcl->errmsg.buf[hcl->errmsg.len], &max, hcl->cmgr, 1); + hcl->errmsg.len += max; +#else + if (len > max) len = max; + if (len <= 0) return 1; + HCL_MEMCPY (&hcl->errmsg.buf[hcl->errmsg.len], ptr, len * HCL_SIZEOF(*ptr)); + hcl->errmsg.len += len; +#endif + + hcl->errmsg.buf[hcl->errmsg.len] = '\0'; + + return 1; /* success */ +} + +static int err_ucs (hcl_fmtout_t* fmtout, const hcl_uch_t* ptr, hcl_oow_t len) +{ + hcl_t* hcl = (hcl_t*)fmtout->ctx; + hcl_oow_t max; + + max = HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len - 1; + +#if defined(HCL_OOCH_IS_UCH) + if (len > max) len = max; + if (len <= 0) return 1; + HCL_MEMCPY (&hcl->errmsg.buf[hcl->errmsg.len], ptr, len * HCL_SIZEOF(*ptr)); + hcl->errmsg.len += len; +#else + if (max <= 0) return 1; + hcl_conv_uchars_to_bchars_with_cmgr (ptr, &len, &hcl->errmsg.buf[hcl->errmsg.len], &max, hcl->cmgr); + hcl->errmsg.len += max; +#endif + hcl->errmsg.buf[hcl->errmsg.len] = '\0'; + return 1; /* success */ +} + +void hcl_seterrbfmt (hcl_t* hcl, hcl_errnum_t errnum, const hcl_bch_t* fmt, ...) +{ + va_list ap; + hcl_fmtout_t fo; + + if (hcl->shuterr) return; + hcl->errmsg.len = 0; + + HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo)); + fo.putbcs = err_bcs; + fo.putucs = err_ucs; + fo.putobj = hcl_fmt_object_; + fo.ctx = hcl; + + va_start (ap, fmt); + hcl_bfmt_outv (&fo, fmt, ap); + va_end (ap); + + hcl->errnum = errnum; +} + +void hcl_seterrufmt (hcl_t* hcl, hcl_errnum_t errnum, const hcl_uch_t* fmt, ...) +{ + va_list ap; + hcl_fmtout_t fo; + + if (hcl->shuterr) return; + hcl->errmsg.len = 0; + + HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo)); + fo.putbcs = err_bcs; + fo.putucs = err_ucs; + fo.putobj = hcl_fmt_object_; + fo.ctx = hcl; + + va_start (ap, fmt); + hcl_ufmt_outv (&fo, fmt, ap); + va_end (ap); + + hcl->errnum = errnum; +} + + +void hcl_seterrbfmtv (hcl_t* hcl, hcl_errnum_t errnum, const hcl_bch_t* fmt, va_list ap) +{ + hcl_fmtout_t fo; + + if (hcl->shuterr) return; + + hcl->errmsg.len = 0; + + HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo)); + fo.putbcs = err_bcs; + fo.putucs = err_ucs; + fo.putobj = hcl_fmt_object_; + fo.ctx = hcl; + + hcl_bfmt_outv (&fo, fmt, ap); + hcl->errnum = errnum; +} + +void hcl_seterrufmtv (hcl_t* hcl, hcl_errnum_t errnum, const hcl_uch_t* fmt, va_list ap) +{ + hcl_fmtout_t fo; + + if (hcl->shuterr) return; + + hcl->errmsg.len = 0; + + HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo)); + fo.putbcs = err_bcs; + fo.putucs = err_ucs; + fo.putobj = hcl_fmt_object_; + fo.ctx = hcl; + + hcl_ufmt_outv (&fo, fmt, ap); + hcl->errnum = errnum; +} + + + void hcl_seterrwithsyserr (hcl_t* hcl, int syserr_type, int syserr_code) { hcl_errnum_t errnum; diff --git a/lib/hcl-cmn.h b/lib/hcl-cmn.h index 31c7fc2..0ceae09 100644 --- a/lib/hcl-cmn.h +++ b/lib/hcl-cmn.h @@ -421,6 +421,8 @@ typedef struct hcl_bcs_t hcl_bcs_t; # define HCL_SIZEOF_OOCH_T HCL_SIZEOF_BCH_T #endif +typedef unsigned int hcl_bitmask_t; + /* ========================================================================= * BASIC OOP ENCODING * ========================================================================= */ diff --git a/lib/hcl-prv.h b/lib/hcl-prv.h index 96a056e..f9755c9 100644 --- a/lib/hcl-prv.h +++ b/lib/hcl-prv.h @@ -1094,26 +1094,24 @@ hcl_pfbase_t* hcl_querymod ( ); /* ========================================================================= */ -/* logfmt.c */ +/* fmt.c */ /* ========================================================================= */ -int hcl_outfmtobj ( - hcl_t* hcl, - hcl_bitmask_t mask, - hcl_oop_t obj, - hcl_outbfmt_t outbfmt +int hcl_fmt_object_ ( + hcl_fmtout_t* fmtout, + hcl_oop_t oop ); -int hcl_printfmtst ( +int hcl_prfmtcallstack ( hcl_t* hcl, hcl_ooi_t nargs ); -int hcl_logfmtst ( +int hcl_logfmtcallstack ( hcl_t* hcl, hcl_ooi_t nargs ); -int hcl_sprintfmtst ( +int hcl_strfmtcallstack ( hcl_t* hcl, hcl_ooi_t nargs ); diff --git a/lib/hcl-s.c b/lib/hcl-s.c index 0e887b5..6d30405 100644 --- a/lib/hcl-s.c +++ b/lib/hcl-s.c @@ -1290,7 +1290,7 @@ static void show_server_workers (hcl_server_proto_t* proto) for (w = server->worker_list[HCL_SERVER_WORKER_STATE_ALIVE].head; w; w = w->next_worker) { /* TODO: implement this better... */ - hcl_proutbfmt (proto->hcl, 0, "%zu %d %d\n", w->wid, w->sck, 1000); + hcl_prbfmt (proto->hcl, "%zu %d %d\n", w->wid, w->sck, 1000); } pthread_mutex_unlock (&server->worker_mutex); } diff --git a/lib/hcl-utl.h b/lib/hcl-utl.h index bf27f36..d1291b6 100644 --- a/lib/hcl-utl.h +++ b/lib/hcl-utl.h @@ -28,6 +28,7 @@ #define _HCL_UTL_H_ #include "hcl-cmn.h" +#include /* ========================================================================= * DOUBLY LINKED LIST @@ -288,6 +289,51 @@ +/* ========================================================================= + * FORMATTED OUTPUT + * ========================================================================= */ +typedef struct hcl_fmtout_t hcl_fmtout_t; + +typedef int (*hcl_fmtout_putbcs_t) ( + hcl_fmtout_t* fmtout, + const hcl_bch_t* ptr, + hcl_oow_t len +); + +typedef int (*hcl_fmtout_putucs_t) ( + hcl_fmtout_t* fmtout, + const hcl_uch_t* ptr, + hcl_oow_t len +); + +typedef int (*hcl_fmtout_putobj_t) ( + hcl_fmtout_t* fmtout, + hcl_oop_t obj +); + +enum hcl_fmtout_fmt_type_t +{ + HCL_FMTOUT_FMT_TYPE_BCH = 0, + HCL_FMTOUT_FMT_TYPE_UCH +}; +typedef enum hcl_fmtout_fmt_type_t hcl_fmtout_fmt_type_t; + + +struct hcl_fmtout_t +{ + hcl_oow_t count; /* out */ + + hcl_fmtout_putbcs_t putbcs; /* in */ + hcl_fmtout_putucs_t putucs; /* in */ + hcl_fmtout_putobj_t putobj; /* in - %O is not handled if it's not set. */ + hcl_bitmask_t mask; /* in */ + void* ctx; /* in */ + + hcl_fmtout_fmt_type_t fmt_type; + const void* fmt_str; +}; + + #if defined(__cplusplus) extern "C" { #endif @@ -684,6 +730,33 @@ HCL_EXPORT int hcl_ucwidth ( hcl_uch_t uc ); +/* ========================================================================= + * FORMATTED OUTPUT + * ========================================================================= */ +HCL_EXPORT int hcl_bfmt_outv ( + hcl_fmtout_t* fmtout, + const hcl_bch_t* fmt, + va_list ap +); + +HCL_EXPORT int hcl_ufmt_outv ( + hcl_fmtout_t* fmtout, + const hcl_uch_t* fmt, + va_list ap +); + + +HCL_EXPORT int hcl_bfmt_out ( + hcl_fmtout_t* fmtout, + const hcl_bch_t* fmt, + ... +); + +HCL_EXPORT int hcl_ufmt_out ( + hcl_fmtout_t* fmtout, + const hcl_uch_t* fmt, + ... +); /* ========================================================================= * BIT SWAP diff --git a/lib/hcl.h b/lib/hcl.h index b875058..f31b162 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -37,7 +37,7 @@ /* ========================================================================== */ typedef struct hcl_mod_t hcl_mod_t; -typedef unsigned int hcl_bitmask_t; + /* ========================================================================== */ /** @@ -1819,6 +1819,17 @@ HCL_EXPORT hcl_ooi_t hcl_logufmtv ( # define hcl_logoofmtv hcl_logbfmtv #endif +HCL_EXPORT hcl_ooi_t hcl_prbfmt ( + hcl_t* hcl, + const hcl_bch_t* fmt, + ... +); + +HCL_EXPORT hcl_ooi_t hcl_prufmt ( + hcl_t* hcl, + const hcl_uch_t* fmt, + ... +); /* ========================================================================= * OBJECT MANAGEMENT diff --git a/lib/logfmt.c b/lib/logfmt.c deleted file mode 100644 index bd2e8ee..0000000 --- a/lib/logfmt.c +++ /dev/null @@ -1,1463 +0,0 @@ -/* - * $Id$ - * - Copyright (c) 2016-2018 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 "hcl-prv.h" - -/*#include */ /* for snrintf(). 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 - - -/* Max number conversion buffer length: - * hcl_intmax_t in base 2, plus NUL byte. */ -#define MAXNBUF (HCL_SIZEOF(hcl_intmax_t) * HCL_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 -{ - hcl_uint8_t flag; /* for single occurrence */ - hcl_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 hcl_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 hcl_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 hcl_uch_t uch_nullstr[] = { '(','n','u','l','l', ')','\0' }; -static hcl_bch_t bch_nullstr[] = { '(','n','u','l','l', ')','\0' }; - -typedef int (*hcl_fmtout_putch_t) ( - hcl_t* hcl, - hcl_bitmask_t mask, - hcl_ooch_t c, - hcl_oow_t len -); - -typedef int (*hcl_fmtout_putcs_t) ( - hcl_t* hcl, - hcl_bitmask_t mask, - const hcl_ooch_t* ptr, - hcl_oow_t len -); - -typedef struct hcl_fmtout_t hcl_fmtout_t; -struct hcl_fmtout_t -{ - hcl_oow_t count; /* out */ - hcl_bitmask_t mask; /* in */ - hcl_fmtout_putch_t putch; /* in */ - hcl_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 hcl_bch_t* sprintn_lower (hcl_bch_t* nbuf, hcl_uintmax_t num, int base, hcl_ooi_t* lenp) -{ - hcl_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 hcl_bch_t* sprintn_upper (hcl_bch_t* nbuf, hcl_uintmax_t num, int base, hcl_ooi_t* lenp) -{ - hcl_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_logch (hcl_t* hcl, hcl_bitmask_t mask, hcl_ooch_t ch, hcl_oow_t len) -{ - /* this is not equivalent to put_logcs(hcl,mask,&ch,1); - * this function is to emit a single character multiple times */ - hcl_oow_t rem; - - if (len <= 0) return 1; - if (hcl->log.len > 0 && hcl->log.last_mask != mask) - { - /* the mask has changed. commit the buffered text */ -/* TODO: HANDLE LINE ENDING CONVENTION BETTER... */ - if (hcl->log.ptr[hcl->log.len - 1] != '\n') - { - /* no line ending - append a line terminator */ - hcl->log.ptr[hcl->log.len++] = '\n'; - } - vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); - hcl->log.len = 0; - } - -redo: - rem = 0; - if (len > hcl->log.capa - hcl->log.len) - { - hcl_oow_t newcapa, max; - hcl_ooch_t* tmp; - - max = HCL_TYPE_MAX(hcl_oow_t) - hcl->log.len; - if (len > max) - { - /* data too big. */ - rem += len - max; - len = max; - } - - newcapa = HCL_ALIGN_POW2(hcl->log.len + len, HCL_LOG_CAPA_ALIGN); /* TODO: adjust this capacity */ - if (newcapa > hcl->option.log_maxcapa) - { - /* [NOTE] - * it doesn't adjust newcapa to hcl->option.log_maxcapa. - * nor does it cut the input to fit it into the adjusted capacity. - * if maxcapa set is not aligned to HCL_LOG_CAPA_ALIGN, - * the largest buffer capacity may be suboptimal */ - goto make_do; - } - - /* +1 to handle line ending injection more easily */ - tmp = (hcl_ooch_t*)hcl_reallocmem (hcl, hcl->log.ptr, (newcapa + 1) * HCL_SIZEOF(*tmp)); - if (!tmp) - { - make_do: - if (hcl->log.len > 0) - { - /* can't expand the buffer. just flush the existing contents */ - /* TODO: HANDLE LINE ENDING CONVENTION BETTER... */ - if (hcl->log.ptr[hcl->log.len - 1] != '\n') - { - /* no line ending - append a line terminator */ - hcl->log.ptr[hcl->log.len++] = '\n'; - } - vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); - hcl->log.len = 0; - } - - if (len > hcl->log.capa) - { - rem += len - hcl->log.capa; - len = hcl->log.capa; - } - - } - else - { - hcl->log.ptr = tmp; - hcl->log.capa = newcapa; - } - } - - while (len > 0) - { - hcl->log.ptr[hcl->log.len++] = ch; - len--; - } - hcl->log.last_mask = mask; - - if (rem > 0) - { - len = rem; - goto redo; - } - - return 1; /* success */ -} - -static int put_logcs (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* ptr, hcl_oow_t len) -{ - hcl_oow_t rem; - - if (len <= 0) return 1; - - if (hcl->log.len > 0 && hcl->log.last_mask != mask) - { - /* the mask has changed. commit the buffered text */ -/* TODO: HANDLE LINE ENDING CONVENTION BETTER... */ - if (hcl->log.ptr[hcl->log.len - 1] != '\n') - { - /* no line ending - append a line terminator */ - hcl->log.ptr[hcl->log.len++] = '\n'; - } - - vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); - hcl->log.len = 0; - } - -redo: - rem = 0; - if (len > hcl->log.capa - hcl->log.len) - { - hcl_oow_t newcapa, max; - hcl_ooch_t* tmp; - - max = HCL_TYPE_MAX(hcl_oow_t) - hcl->log.len; - if (len > max) - { - /* data too big. */ - rem += len - max; - len = max; - } - - newcapa = HCL_ALIGN_POW2(hcl->log.len + len, 512); /* TODO: adjust this capacity */ - if (newcapa > hcl->option.log_maxcapa) - { - /* [NOTE] - * it doesn't adjust newcapa to hcl->option.log_maxcapa. - * nor does it cut the input to fit it into the adjusted capacity. - * if maxcapa set is not aligned to HCL_LOG_CAPA_ALIGN, - * the largest buffer capacity may be suboptimal */ - goto make_do; - } - - /* +1 to handle line ending injection more easily */ - tmp = (hcl_ooch_t*)hcl_reallocmem (hcl, hcl->log.ptr, (newcapa + 1) * HCL_SIZEOF(*tmp)); - if (!tmp) - { - make_do: - if (hcl->log.len > 0) - { - /* can't expand the buffer. just flush the existing contents */ - /* TODO: HANDLE LINE ENDING CONVENTION BETTER... */ - if (hcl->log.ptr[hcl->log.len - 1] != '\n') - { - /* no line ending - append a line terminator */ - hcl->log.ptr[hcl->log.len++] = '\n'; - } - vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); - hcl->log.len = 0; - } - - if (len > hcl->log.capa) - { - rem += len - hcl->log.capa; - len = hcl->log.capa; - } - } - else - { - hcl->log.ptr = tmp; - hcl->log.capa = newcapa; - } - } - - HCL_MEMCPY (&hcl->log.ptr[hcl->log.len], ptr, len * HCL_SIZEOF(*ptr)); - hcl->log.len += len; - hcl->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 logfmtv -#define fmtchar_t hcl_bch_t -#define logfmtv __logbfmtv -#define FMTCHAR_IS_BCH -#if defined(HCL_OOCH_IS_BCH) -# define FMTCHAR_IS_OOCH -#endif -#include "logfmtv.h" - -#undef FMTCHAR_IS_BCH -#undef FMTCHAR_IS_UCH -#undef FMTCHAR_IS_OOCH -#undef fmtchar_t -#undef logfmtv -#define fmtchar_t hcl_uch_t -#define logfmtv __logufmtv -#define FMTCHAR_IS_UCH -#if defined(HCL_OOCH_IS_UCH) -# define FMTCHAR_IS_OOCH -#endif -#include "logfmtv.h" - - -static int _logbfmtv (hcl_t* hcl, const hcl_bch_t* fmt, hcl_fmtout_t* data, va_list ap) -{ - return __logbfmtv (hcl, fmt, data, ap, hcl_logbfmt); -} - -static int _logufmtv (hcl_t* hcl, const hcl_uch_t* fmt, hcl_fmtout_t* data, va_list ap) -{ - return __logufmtv (hcl, fmt, data, ap, hcl_logbfmt); -} - -hcl_ooi_t hcl_logbfmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_bch_t* fmt, va_list ap) -{ - int x; - hcl_fmtout_t fo; - - if (hcl->log.default_type_mask & HCL_LOG_ALL_TYPES) - { - /* if a type is given, it's not untyped any more. - * mask off the UNTYPED bit */ - mask &= ~HCL_LOG_UNTYPED; - - /* if the default_type_mask has the UNTYPED bit on, - * it'll get turned back on */ - mask |= (hcl->log.default_type_mask & HCL_LOG_ALL_TYPES); - } - else if (!(mask & HCL_LOG_ALL_TYPES)) - { - /* no type is set in the given mask and no default type is set. - * make it UNTYPED. */ - mask |= HCL_LOG_UNTYPED; - } - - fo.mask = mask; - fo.putch = put_logch; - fo.putcs = put_logcs; - - x = _logbfmtv(hcl, fmt, &fo, ap); - - if (hcl->log.len > 0 && hcl->log.ptr[hcl->log.len - 1] == '\n') - { - vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); - hcl->log.len = 0; - } - return (x <= -1)? -1: fo.count; -} - -hcl_ooi_t hcl_logbfmt (hcl_t* hcl, hcl_bitmask_t mask, const hcl_bch_t* fmt, ...) -{ - va_list ap; - hcl_ooi_t x; - - va_start (ap, fmt); - x = hcl_logbfmtv (hcl, mask, fmt, ap); - va_end (ap); - - return x; -} - -hcl_ooi_t hcl_logufmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_uch_t* fmt, va_list ap) -{ - int x; - hcl_fmtout_t fo; - - if (hcl->log.default_type_mask & HCL_LOG_ALL_TYPES) - { - mask &= ~HCL_LOG_UNTYPED; - mask |= (hcl->log.default_type_mask & HCL_LOG_ALL_TYPES); - } - else if (!(mask & HCL_LOG_ALL_TYPES)) - { - mask |= HCL_LOG_UNTYPED; - } - - fo.mask = mask; - fo.putch = put_logch; - fo.putcs = put_logcs; - - x = _logufmtv(hcl, fmt, &fo, ap); - - if (hcl->log.len > 0 && hcl->log.ptr[hcl->log.len - 1] == '\n') - { - vmprim_log_write (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len); - hcl->log.len = 0; - } - - return (x <= -1)? -1: fo.count; -} - -hcl_ooi_t hcl_logufmt (hcl_t* hcl, hcl_bitmask_t mask, const hcl_uch_t* fmt, ...) -{ - va_list ap; - hcl_ooi_t x; - - va_start (ap, fmt); - x = hcl_logufmtv (hcl, mask, fmt, ap); - va_end (ap); - - return x; -} - - -/* -------------------------------------------------------------------------- - * HELPER FOR PRINTING - * -------------------------------------------------------------------------- */ - -static int put_prcs (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* ptr, hcl_oow_t len) -{ - hcl_ooch_t* optr; - - optr = (hcl_ooch_t*)ptr; - while (len > 0) - { - hcl->c->outarg.ptr = optr; - hcl->c->outarg.len = len; - - if (hcl->c->printer(hcl, HCL_IO_WRITE, &hcl->c->outarg) <= -1) return -1; - if (hcl->c->outarg.xlen <= 0) return 0; /* end of stream. but not failure */ - - HCL_ASSERT (hcl, hcl->c->outarg.xlen <= len); - optr += hcl->c->outarg.xlen; - len -= hcl->c->outarg.xlen; - } - - return 1; /* success */ -} - -static int put_prch (hcl_t* hcl, hcl_bitmask_t mask, hcl_ooch_t ch, hcl_oow_t len) -{ - hcl_ooch_t str[256]; - hcl_oow_t seglen, i; - int n; - - while (len > 0) - { - seglen = (len > HCL_COUNTOF(str))? HCL_COUNTOF(str): len; - for (i = 0; i < seglen; i++) str[i] = ch; - - n = put_prcs (hcl, mask, str, seglen); - if (n <= 0) return n; - - len -= seglen; - } - - return 1; /* success */ -} - -static hcl_ooi_t __prbfmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_bch_t* fmt, ...); - -static int _prbfmtv (hcl_t* hcl, const hcl_bch_t* fmt, hcl_fmtout_t* data, va_list ap) -{ - return __logbfmtv (hcl, fmt, data, ap, __prbfmtv); -} - -static int _prufmtv (hcl_t* hcl, const hcl_uch_t* fmt, hcl_fmtout_t* data, va_list ap) -{ - return __logufmtv (hcl, fmt, data, ap, __prbfmtv); -} - -static hcl_ooi_t __prbfmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_bch_t* fmt, ...) -{ - va_list ap; - hcl_fmtout_t fo; - - fo.mask = mask; - fo.putch = put_prch; - fo.putcs = put_prcs; - - va_start (ap, fmt); - _prbfmtv (hcl, fmt, &fo, ap); - va_end (ap); - - return fo.count; -} - -hcl_ooi_t hcl_proutbfmt (hcl_t* hcl, hcl_bitmask_t mask, const hcl_bch_t* fmt, ...) -{ - int x; - va_list ap; - hcl_fmtout_t fo; - - fo.mask = mask; - fo.putch = put_prch; - fo.putcs = put_prcs; - - va_start (ap, fmt); - x = _prbfmtv(hcl, fmt, &fo, ap); - va_end (ap); - - return (x <= -1)? -1: fo.count; -} - -hcl_ooi_t hcl_proutufmt (hcl_t* hcl, hcl_bitmask_t mask, const hcl_uch_t* fmt, ...) -{ - int x; - va_list ap; - hcl_fmtout_t fo; - - fo.mask = mask; - fo.putch = put_prch; - fo.putcs = put_prcs; - - va_start (ap, fmt); - x = _prufmtv (hcl, fmt, &fo, ap); - va_end (ap); - - return (x <= -1)? -1: fo.count; -} - -/* -------------------------------------------------------------------------- - * ERROR MESSAGE FORMATTING - * -------------------------------------------------------------------------- */ - -static int put_errcs (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* ptr, hcl_oow_t len) -{ - hcl_oow_t max; - - max = HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len - 1; - if (len > max) len = max; - - if (len <= 0) return 1; - - HCL_MEMCPY (&hcl->errmsg.buf[hcl->errmsg.len], ptr, len * HCL_SIZEOF(*ptr)); - hcl->errmsg.len += len; - hcl->errmsg.buf[hcl->errmsg.len] = '\0'; - - return 1; /* success */ -} - -static int put_errch (hcl_t* hcl, hcl_bitmask_t mask, hcl_ooch_t ch, hcl_oow_t len) -{ - hcl_oow_t max; - - max = HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len - 1; - if (len > max) len = max; - - if (len <= 0) return 1; - - while (len > 0) - { - hcl->errmsg.buf[hcl->errmsg.len++] = ch; - len--; - } - hcl->errmsg.buf[hcl->errmsg.len] = '\0'; - - return 1; /* success */ -} - -static hcl_ooi_t __errbfmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_bch_t* fmt, ...); - -static int _errbfmtv (hcl_t* hcl, const hcl_bch_t* fmt, hcl_fmtout_t* data, va_list ap) -{ - return __logbfmtv (hcl, fmt, data, ap, __errbfmtv); -} - -static int _errufmtv (hcl_t* hcl, const hcl_uch_t* fmt, hcl_fmtout_t* data, va_list ap) -{ - return __logufmtv (hcl, fmt, data, ap, __errbfmtv); -} - -static hcl_ooi_t __errbfmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_bch_t* fmt, ...) -{ - va_list ap; - hcl_fmtout_t fo; - - fo.mask = mask; - fo.putch = put_errch; - fo.putcs = put_errcs; - - va_start (ap, fmt); - _errbfmtv (hcl, fmt, &fo, ap); - va_end (ap); - - return fo.count; -} - -void hcl_seterrbfmt (hcl_t* hcl, hcl_errnum_t errnum, const hcl_bch_t* fmt, ...) -{ - va_list ap; - hcl_fmtout_t fo; - - if (hcl->shuterr) return; - hcl->errmsg.len = 0; - - fo.mask = 0; /* not used */ - fo.putch = put_errch; - fo.putcs = put_errcs; - - va_start (ap, fmt); - _errbfmtv (hcl, fmt, &fo, ap); - va_end (ap); - - hcl->errnum = errnum; -} - -void hcl_seterrufmt (hcl_t* hcl, hcl_errnum_t errnum, const hcl_uch_t* fmt, ...) -{ - va_list ap; - hcl_fmtout_t fo; - - if (hcl->shuterr) return; - hcl->errmsg.len = 0; - - fo.mask = 0; /* not used */ - fo.putch = put_errch; - fo.putcs = put_errcs; - - va_start (ap, fmt); - _errufmtv (hcl, fmt, &fo, ap); - va_end (ap); - - hcl->errnum = errnum; -} - - -void hcl_seterrbfmtv (hcl_t* hcl, hcl_errnum_t errnum, const hcl_bch_t* fmt, va_list ap) -{ - hcl_fmtout_t fo; - - if (hcl->shuterr) return; - hcl->errmsg.len = 0; - - fo.mask = 0; /* not used */ - fo.putch = put_errch; - fo.putcs = put_errcs; - - _errbfmtv (hcl, fmt, &fo, ap); - hcl->errnum = errnum; -} - -void hcl_seterrufmtv (hcl_t* hcl, hcl_errnum_t errnum, const hcl_uch_t* fmt, va_list ap) -{ - hcl_fmtout_t fo; - - if (hcl->shuterr) return; - hcl->errmsg.len = 0; - - fo.mask = 0; /* not used */ - fo.putch = put_errch; - fo.putcs = put_errcs; - - _errufmtv (hcl, fmt, &fo, ap); - hcl->errnum = errnum; -} - -/* -------------------------------------------------------------------------- - * SUPPORT FOR FORMATTED OUTPUT TO BE USED BY BUILTIN PRIMITIVE FUNCTIONS - * -------------------------------------------------------------------------- */ - -#define PRINT_OOCH(c,n) do { \ - if (n > 0) { \ - int xx; \ - if ((xx = data->putch(hcl, data->mask, c, n)) <= -1) goto oops; \ - if (xx == 0) goto done; \ - data->count += n; \ - } \ -} while (0) - -#define PRINT_OOCS(ptr,len) do { \ - if (len > 0) { \ - int xx; \ - if ((xx = data->putcs(hcl, data->mask, ptr, len)) <= -1) goto oops; \ - if (xx == 0) goto done; \ - data->count += len; \ - } \ -} while(0) - -#define GET_NEXT_ARG_TO(hcl,nargs,arg_state,arg) do { \ - if ((arg_state)->idx >= nargs) { (arg_state)->stop = 1; goto invalid_format; } \ - arg = HCL_STACK_GETARG(hcl, nargs, (arg_state)->idx); \ - (arg_state)->idx++; \ -} while(0) - -#define GET_NEXT_CHAR_TO(hcl,fmt,fmtend,ch) do { \ - if (fmt >= fmtend) ch = HCL_OOCI_EOF; \ - else { ch = *(fmt); (fmt)++; }\ -} while(0) - -static HCL_INLINE int print_formatted (hcl_t* hcl, hcl_ooi_t nargs, hcl_fmtout_t* data, hcl_outbfmt_t outbfmt) -{ - const hcl_ooch_t* fmt, * fmtend; - const hcl_ooch_t* checkpoint, * percent; - - int n, radix, neg, sign, radix_flags; - hcl_ooi_t extra, width, precision; - hcl_ooch_t padc, ooch; - hcl_ooci_t ch; - int flagc; - - struct - { - hcl_ooi_t idx; - int stop; - } arg_state; - hcl_oop_t arg; - - arg = HCL_STACK_GETARG(hcl, nargs, 0); - if (!HCL_OOP_IS_POINTER(arg) || HCL_OBJ_GET_FLAGS_TYPE(arg) != HCL_OBJ_TYPE_CHAR) - { - hcl_ooi_t i; - /* if the first argument is not a valid formatting string, - * print all arguments as objects */ - if (hcl_outfmtobj(hcl, data->mask, arg, outbfmt) <= -1) goto oops; - for (i = 1; i < nargs; i++) - { - arg = HCL_STACK_GETARG(hcl, nargs, i); - if (hcl_outfmtobj(hcl, data->mask, arg, outbfmt) <= -1) goto oops; - } - return 0; - } - - fmt = HCL_OBJ_GET_CHAR_SLOT(arg); - fmtend = fmt + HCL_OBJ_GET_SIZE(arg); - - arg_state.idx = 1; - arg_state.stop = 0; - - data->count = 0; - - while (1) - { - checkpoint = fmt; - - while (1) - { - GET_NEXT_CHAR_TO (hcl, fmt, fmtend, ch); - if (ch == '%' && !arg_state.stop) break; - - if (ch == HCL_OOCI_EOF) - { - /* fmt is not advanced when it is length-bounded. - * so not fmt - checkpoint - 1 */ - PRINT_OOCS (checkpoint, fmt - checkpoint); - goto done; - } - } - PRINT_OOCS (checkpoint, fmt - checkpoint - 1); - - percent = fmt - 1; - - padc = ' '; - width = 0; precision = 0; - neg = 0; sign = 0; - - flagc = 0; - radix_flags = HCL_INTTOSTR_NONEWOBJ; - - reswitch: - GET_NEXT_CHAR_TO (hcl, fmt, fmtend, ch); - switch (ch) - { - case '%': /* %% */ - ooch = ch; - goto print_char; - - /* 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; - - GET_NEXT_ARG_TO (hcl, nargs, &arg_state, arg); - if (hcl_inttoooi(hcl, arg, &precision) <= -1) goto invalid_format; - 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; - - GET_NEXT_ARG_TO (hcl, nargs, &arg_state, arg); - if (hcl_inttoooi(hcl, arg, &width) <= -1) goto invalid_format; - if (width < 0) - { - 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; - - /* integer conversions */ - case 'd': - case 'i': /* signed conversion */ - radix = 10; - sign = 1; - goto print_integer; - case 'o': - radix = 8; - goto print_integer; - case 'u': - radix = 10; - goto print_integer; - - case 'x': - radix_flags |= HCL_INTTOSTR_LOWERCASE; - case 'X': - radix= 16; - goto print_integer; - - case 'b': - radix = 2; - goto print_integer; - /* end of integer conversions */ - - case 'f': - { - const hcl_ooch_t* nsptr; - hcl_oow_t nslen; - hcl_oow_t scale = 0; - - GET_NEXT_ARG_TO (hcl, nargs, &arg_state, arg); - if (HCL_OOP_IS_CHAR(arg)) - { - arg = HCL_SMOOI_TO_OOP(HCL_OOP_TO_CHAR(arg)); - } - else if (HCL_IS_FPDEC(hcl, arg)) - { - hcl_oop_fpdec_t fa = (hcl_oop_fpdec_t)arg; - scale = HCL_OOP_TO_SMOOI(fa->scale); - arg = fa->value; - } - - if (!hcl_inttostr(hcl, arg, 10 | HCL_INTTOSTR_NONEWOBJ)) - { - HCL_LOG1 (hcl, HCL_LOG_WARN | HCL_LOG_UNTYPED, "unable to convert %O to string \n", arg); - goto invalid_format; - } - - nsptr = hcl->inttostr.xbuf.ptr; - nslen = hcl->inttostr.xbuf.len; - HCL_ASSERT (hcl, nslen > 0); - - if (nsptr[0] == '-') - { - HCL_ASSERT (hcl, (HCL_OOP_IS_SMOOI(arg) && HCL_OOP_TO_SMOOI(arg) < 0) || HCL_IS_NBIGINT(hcl,arg)); - nsptr++; - nslen--; - neg = 1; - } - - if (!(flagc & FLAGC_DOT)) - { - precision = scale; - if (precision <= 0) precision = 1; - } - - if ((flagc & FLAGC_DOT) && precision < scale) - { - hcl_oow_t diff = scale - precision; - scale = precision; - nslen = (nslen < diff)? 0: (nslen - diff); - } - - if (nslen < scale + 1) - { - extra = 1; - if (precision > 0) extra += 1 + scale; - } - else - { - extra = 0; - if (nslen > 0) extra += nslen - scale; - if (precision > 0) - { - extra += 1; - if (nslen > 0) extra += scale; - } - } - - if (neg) extra++; - else if (flagc & FLAGC_SIGN) extra++; - else if (flagc & FLAGC_SPACE) extra++; - - if ((flagc & FLAGC_DOT) && precision > scale) - { - /* trailing zeros in the fractional part */ - extra += precision - scale; - } - - if (!(flagc & FLAGC_LEFTADJ) && !(flagc & FLAGC_ZEROPAD) && width > extra) - { - width -= extra; - PRINT_OOCH (padc, width); - width = 0; - } - if (neg) PRINT_OOCH ('-', 1); - else if (flagc & FLAGC_SIGN) PRINT_OOCH ('+', 1); - else if (flagc & FLAGC_SPACE) PRINT_OOCH (' ', 1); - - if (!(flagc & FLAGC_LEFTADJ) && width > extra) - { - width -= extra; - PRINT_OOCH (padc, width); - } - - if (nslen < scale + 1) - { - PRINT_OOCH ('0', 1); - if (precision > 0) - { - PRINT_OOCH ('.', 1); - PRINT_OOCH ('0', scale - nslen); - PRINT_OOCS (nsptr, nslen); - } - } - else - { - if (nslen > 0) PRINT_OOCS (nsptr, nslen - scale); - if (precision > 0) - { - PRINT_OOCH ('.', 1); - if (nslen > 0) PRINT_OOCS (&nsptr[nslen - scale], scale); - } - } - if (precision > scale) - { - /* trailing zeros in the fractional part */ - PRINT_OOCH ('0', precision - scale); - } - - if ((flagc & FLAGC_LEFTADJ) && width > extra) - { - width -= extra; - PRINT_OOCH (padc, width); - } - break; - } - - case 'c': - case 'C': - GET_NEXT_ARG_TO (hcl, nargs, &arg_state, arg); - if (HCL_OOP_IS_SMOOI(arg)) arg = HCL_CHAR_TO_OOP(HCL_OOP_TO_SMOOI(arg)); - if (!HCL_OOP_IS_CHAR(arg)) goto invalid_format; - ooch = HCL_OOP_TO_CHAR(arg); - - print_char: - /* zeropad must not take effect for 'c' */ - if (flagc & FLAGC_ZEROPAD) padc = ' '; - - /* precision 0 doesn't kill the letter */ - width--; - if (!(flagc & FLAGC_LEFTADJ) && width > 0) PRINT_OOCH (padc, width); - PRINT_OOCH (ooch, 1); - if ((flagc & FLAGC_LEFTADJ) && width > 0) PRINT_OOCH (padc, width); - break; - - case 's': - case 'S': - { - const hcl_ooch_t* oosp; - hcl_oow_t oosl; - - /* zeropad must not take effect for 'S' */ - if (flagc & FLAGC_ZEROPAD) padc = ' '; - - GET_NEXT_ARG_TO (hcl, nargs, &arg_state, arg); - if (!HCL_OOP_IS_POINTER(arg) || HCL_OBJ_GET_FLAGS_TYPE(arg) != HCL_OBJ_TYPE_CHAR) goto invalid_format; - - oosp = HCL_OBJ_GET_CHAR_SLOT(arg); - oosl = HCL_OBJ_GET_SIZE(arg); - - if (flagc & FLAGC_DOT) - { - if (oosl > precision) oosl = precision; - } - width -= oosl; - - if (!(flagc & FLAGC_LEFTADJ) && width > 0) PRINT_OOCH (padc, width); - PRINT_OOCS (oosp, oosl); - if ((flagc & FLAGC_LEFTADJ) && width > 0) PRINT_OOCH (padc, width); - break; - } - - case 'O': /* object - ignore precision, width, adjustment */ - GET_NEXT_ARG_TO (hcl, nargs, &arg_state, arg); - if (hcl_outfmtobj(hcl, (data->mask & ~HCL_LOG_PREFER_JSON), arg, outbfmt) <= -1) goto oops; - break; - - case 'J': - GET_NEXT_ARG_TO (hcl, nargs, &arg_state, arg); - if (hcl_outfmtobj(hcl, (data->mask | HCL_LOG_PREFER_JSON), arg, outbfmt) <= -1) goto oops; - break; - - print_integer: - { - const hcl_ooch_t* nsptr; - hcl_oow_t nslen; - - GET_NEXT_ARG_TO (hcl, nargs, &arg_state, arg); - if (HCL_OOP_IS_CHAR(arg)) - { - arg = HCL_SMOOI_TO_OOP(HCL_OOP_TO_CHAR(arg)); - } - else if (HCL_IS_FPDEC(hcl, arg)) - { - hcl_oop_t nv; - hcl_oop_fpdec_t fa = (hcl_oop_fpdec_t)arg; - - /* the given number for integer output is a fixed-point decimal. - * i will drop all digits after the fixed point */ - hcl_pushtmp (hcl, &arg); - nv = hcl_truncfpdecval(hcl, fa->value, HCL_OOP_TO_SMOOI(fa->scale), 0); - hcl_poptmp (hcl); - if (!nv) - { - HCL_LOG1 (hcl, HCL_LOG_WARN | HCL_LOG_UNTYPED, "unable to truncate a fixed-point number %O to an integer for output\n", arg); - goto invalid_format; - } - - arg = nv; - } - - if (!hcl_inttostr(hcl, arg, radix | radix_flags)) - { - /*hcl_seterrbfmt (hcl, HCL_EINVAL, "not a valid number - %O", arg); - goto oops;*/ - HCL_LOG1 (hcl, HCL_LOG_WARN | HCL_LOG_UNTYPED, "unable to convert integer %O to string \n", arg); - goto invalid_format; - } - - nsptr = hcl->inttostr.xbuf.ptr; - nslen = hcl->inttostr.xbuf.len; - - HCL_ASSERT (hcl, nslen > 0); - if (nsptr[0] == '-') - { - /* a negative number was given. i must skip the minus sign - * added by hcl_inttostr() for a negative number. */ - HCL_ASSERT (hcl, (HCL_OOP_IS_SMOOI(arg) && HCL_OOP_TO_SMOOI(arg) < 0) || HCL_IS_NBIGINT(hcl,arg)); - nsptr++; - nslen--; - } - - extra = nslen; - if (sign && ((HCL_OOP_IS_SMOOI(arg) && HCL_OOP_TO_SMOOI(arg) < 0) || HCL_IS_NBIGINT(hcl,arg))) neg = 1; - - if ((flagc & FLAGC_SHARP) && arg != HCL_SMOOI_TO_OOP(0)) - { - if (radix == 2 || radix == 8 || radix == 16 || radix == -16) extra += 2; - } - if (neg) extra++; - else if (flagc & FLAGC_SIGN) extra++; - else if (flagc & FLAGC_SPACE) extra++; - - if ((flagc & FLAGC_DOT) && precision > nslen) - { - /* extra zeros for precision specified */ - extra += (precision - nslen); - } - - if (!(flagc & FLAGC_LEFTADJ) && !(flagc & FLAGC_ZEROPAD) && width > 0 && (width -= extra) > 0) - { - PRINT_OOCH (padc, width); - width = 0; - } - - if (neg) PRINT_OOCH ('-', 1); - else if (flagc & FLAGC_SIGN) PRINT_OOCH ('+', 1); - else if (flagc & FLAGC_SPACE) PRINT_OOCH (' ', 1); - - if ((flagc & FLAGC_SHARP) && arg != HCL_SMOOI_TO_OOP(0)) - { - if (radix == 2) - { - PRINT_OOCH ('#', 1); - PRINT_OOCH ('b', 1); - } - if (radix == 8) - { - PRINT_OOCH ('#', 1); - PRINT_OOCH ('o', 1); - } - else if (radix == 16 || radix == -16) - { - PRINT_OOCH ('#', 1); - PRINT_OOCH ('x', 1); - } - } - - if ((flagc & FLAGC_DOT) && precision > nslen) - { - /* extra zeros for precision specified */ - PRINT_OOCH ('0', precision - nslen); - } - - if (!(flagc & FLAGC_LEFTADJ) && width > 0 && (width -= extra) > 0) - { - PRINT_OOCH (padc, width); - } - - PRINT_OOCS (nsptr, nslen); - - if ((flagc & FLAGC_LEFTADJ) && width > 0 && (width -= extra) > 0) - { - PRINT_OOCH (padc, width); - } - break; - } - - invalid_format: - PRINT_OOCS (percent, fmt - percent); - break; - - default: - PRINT_OOCS (percent, fmt - percent); - /* - * 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. - */ - arg_state.stop = 1; - break; - } - } - -done: - return 0; - -oops: - return -1; -} - -/* -------------------------------------------------------------------------- - * SUPPORT FOR THE BUILTIN PRINTF PRIMITIVE FUNCTION - * -------------------------------------------------------------------------- */ - -int hcl_printfmtst (hcl_t* hcl, hcl_ooi_t nargs) -{ - hcl_fmtout_t fo; - HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo)); - fo.putch = put_prch; - fo.putcs = put_prcs; - return print_formatted(hcl, nargs, &fo, hcl_proutbfmt); -} - -/* -------------------------------------------------------------------------- - * SUPPORT FOR THE BUILTIN LOGF PRIMITIVE FUNCTION - * -------------------------------------------------------------------------- */ - -int hcl_logfmtst (hcl_t* hcl, hcl_ooi_t nargs) -{ - hcl_fmtout_t fo; - - HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo)); - fo.mask = HCL_LOG_FATAL | HCL_LOG_APP; - - if (hcl->log.default_type_mask & HCL_LOG_ALL_TYPES) - { - /* if a type is given, it's not untyped any more. - * mask off the UNTYPED bit */ - fo.mask &= ~HCL_LOG_UNTYPED; - - /* if the default_type_mask has the UNTYPED bit on, - * it'll get turned back on */ - fo.mask |= (hcl->log.default_type_mask & HCL_LOG_ALL_TYPES); - } - - fo.putch = put_logch; - fo.putcs = put_logcs; - return print_formatted(hcl, nargs, &fo, hcl_logbfmt); -} - -/* -------------------------------------------------------------------------- - * SUPPORT FOR THE BUILTIN SPRINTF PRIMITIVE FUNCTION - * -------------------------------------------------------------------------- */ -static int put_sprcs (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* ptr, hcl_oow_t len) -{ - if (len > hcl->sprintf.xbuf.capa - hcl->sprintf.xbuf.len) - { - hcl_ooch_t* tmp; - hcl_oow_t newcapa; - - newcapa = hcl->sprintf.xbuf.len + len + 1; - newcapa = HCL_ALIGN_POW2(newcapa, 256); - - tmp = (hcl_ooch_t*)hcl_reallocmem(hcl, hcl->sprintf.xbuf.ptr, newcapa * HCL_SIZEOF(*tmp)); - if (!tmp) return -1; - - hcl->sprintf.xbuf.ptr = tmp; - hcl->sprintf.xbuf.capa = newcapa; - } - - HCL_MEMCPY (&hcl->sprintf.xbuf.ptr[hcl->sprintf.xbuf.len], ptr, len * HCL_SIZEOF(*ptr)); - hcl->sprintf.xbuf.len += len; - return 1; /* success */ -} - -static int put_sprch (hcl_t* hcl, hcl_bitmask_t mask, hcl_ooch_t ch, hcl_oow_t len) -{ - if (len > hcl->sprintf.xbuf.capa - hcl->sprintf.xbuf.len) - { - hcl_ooch_t* tmp; - hcl_oow_t newcapa; - - newcapa = hcl->sprintf.xbuf.len + len + 1; - newcapa = HCL_ALIGN_POW2(newcapa, 256); - - tmp = (hcl_ooch_t*)hcl_reallocmem(hcl, hcl->sprintf.xbuf.ptr, newcapa * HCL_SIZEOF(*tmp)); - if (!tmp) return -1; - - hcl->sprintf.xbuf.ptr = tmp; - hcl->sprintf.xbuf.capa = newcapa; - } - - while (len > 0) - { - --len; - hcl->sprintf.xbuf.ptr[hcl->sprintf.xbuf.len++] = ch; - } - - return 1; /* success */ -} - -static hcl_ooi_t __sprbfmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_bch_t* fmt, ...); - -static int _sprbfmtv (hcl_t* hcl, const hcl_bch_t* fmt, hcl_fmtout_t* data, va_list ap) -{ - return __logbfmtv (hcl, fmt, data, ap, __sprbfmtv); -} - -/* -static int _sprufmtv (hcl_t* hcl, const hcl_uch_t* fmt, hcl_fmtout_t* data, va_list ap) -{ - return __logufmtv (hcl, fmt, data, ap, __sprbfmtv); -}*/ - -static hcl_ooi_t __sprbfmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_bch_t* fmt, ...) -{ - va_list ap; - hcl_fmtout_t fo; - - fo.mask = mask; /* not used */ - fo.putch = put_sprch; - fo.putcs = put_sprcs; - - va_start (ap, fmt); - _sprbfmtv (hcl, fmt, &fo, ap); - va_end (ap); - - return fo.count; -} - -hcl_ooi_t hcl_sproutbfmt (hcl_t* hcl, hcl_bitmask_t mask, const hcl_bch_t* fmt, ...) -{ - int x; - va_list ap; - hcl_fmtout_t fo; - - fo.mask = mask; - fo.putch = put_sprch; - fo.putcs = put_sprcs; - - va_start (ap, fmt); - x = _sprbfmtv(hcl, fmt, &fo, ap); - va_end (ap); - - return (x <= -1)? -1: fo.count; -} - -/* -hcl_ooi_t hcl_sproutufmt (hcl_t* hcl, hcl_bitmask_t mask, const hcl_uch_t* fmt, ...) -{ - int x; - va_list ap; - hcl_fmtout_t fo; - - fo.mask = mask; - fo.putch = put_sprch; - fo.putcs = put_sprcs; - - va_start (ap, fmt); - x = _sprufmtv (hcl, fmt, &fo, ap); - va_end (ap); - - return (x <= -1)? -1: fo.count; -}*/ - -int hcl_sprintfmtst (hcl_t* hcl, hcl_ooi_t nargs) -{ - hcl_fmtout_t fo; - - HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo)); - fo.putch = put_sprch; - fo.putcs = put_sprcs; - hcl->sprintf.xbuf.len = 0; - return print_formatted(hcl, nargs, &fo, hcl_sproutbfmt); -} diff --git a/lib/logfmtv.h b/lib/logfmtv.h deleted file mode 100644 index 1acbff8..0000000 --- a/lib/logfmtv.h +++ /dev/null @@ -1,1186 +0,0 @@ -/*/* - * $Id$ - * - Copyright (c) 2016-2018 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(hcl, 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(hcl, 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 { \ - hcl_bch_t __xbuf[3]; \ - hcl_byte_to_bcstr ((byte), __xbuf, HCL_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 logfmtv (hcl_t* hcl, const fmtchar_t* fmt, hcl_fmtout_t* data, va_list ap, hcl_outbfmt_t outbfmt) -{ - const fmtchar_t* percent; - const fmtchar_t* checkpoint; - hcl_bch_t nbuf[MAXNBUF], bch; - const hcl_bch_t* nbufp; - int n, base, neg, sign; - hcl_ooi_t tmp, width, precision; - hcl_ooch_t ch, padc; -#if !defined(FMTCHAR_IS_OOCH) - fmtchar_t fch; -#endif - int lm_flag, lm_dflag, flagc, numlen; - hcl_uintmax_t num = 0; - int stop = 0; - -#if 0 - hcl_bchbuf_t* fltfmt; - hcl_oochbuf_t* fltout; -#endif - hcl_bch_t* (*sprintn) (hcl_bch_t* nbuf, hcl_uintmax_t num, int base, hcl_ooi_t* lenp); - - data->count = 0; - -#if 0 - fltfmt = &hcl->d->fltfmt; - fltout = &hcl->d->fltout; - - fltfmt->ptr = fltfmt->buf; - fltfmt->capa = HCL_COUNTOF(fltfmt->buf) - 1; - - fltout->ptr = fltout->buf; - fltout->capa = HCL_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(HCL_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) - { - hcl_oow_t cvlen, bclen; - bclen = fmt - checkpoint - 1; - cvlen = hcl->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) - { - hcl_bch_t bcsbuf[HCL_MBLEN_MAX + 1]; - hcl_oow_t ucslen, bcslen; - - if (fch == '\0') goto done; - - /* fmtchar is uch. ooch is bch. convert uch to bch */ - ucslen = 1; - bcslen = HCL_COUNTOF(bcsbuf); - /*if (hcl_convutooochars(hcl, &fch, &ucslen, bcsbuf, &bcslen) <= -1) goto oops;*/ - if (hcl_conv_uchars_to_bchars_with_cmgr( &fch, &ucslen, bcsbuf, &bcslen, hcl->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, hcl_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, hcl_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': /* hcl_intmax_t/hcl_uintmax_t */ - case 'z': /* hcl_ooi_t/hcl_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, hcl_intmax_t*)) = data->count; - else if (lm_flag & LF_Z) /* z */ - *(va_arg(ap, hcl_ooi_t*)) = data->count; - #if (HCL_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 = (hcl_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(HCL_OOCH_IS_UCH) - if (lm_flag & LF_J) goto uppercase_c; - #endif - lowercase_c: - - bch = HCL_SIZEOF(hcl_bch_t) < HCL_SIZEOF(int)? va_arg(ap, int): va_arg(ap, hcl_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': - { - hcl_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(HCL_OOCH_IS_BCH) - if (lm_flag & LF_J) goto lowercase_c; - #endif - uppercase_c: - ooch = HCL_SIZEOF(hcl_uch_t) < HCL_SIZEOF(int)? va_arg(ap, int): va_arg(ap, hcl_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 hcl_bch_t* bsp; - hcl_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(HCL_OOCH_IS_UCH) - if (lm_flag & LF_J) goto uppercase_s; - #endif - lowercase_s: - - bsp = va_arg (ap, hcl_bch_t*); - if (bsp == HCL_NULL) bsp = bch_nullstr; - - #if defined(HCL_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 (hcl_convbtooochars(hcl, bsp, &bslen, HCL_NULL, &slen) <= -1) goto oops;*/ - if (hcl_conv_bchars_to_uchars_with_cmgr(bsp, &bslen, HCL_NULL, &slen, hcl->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); - - { - hcl_ooch_t conv_buf[32]; - hcl_oow_t conv_len, src_len, tot_len = 0; - while (n > 0) - { - HCL_ASSERT (hcl, bslen > tot_len); - - src_len = bslen - tot_len; - conv_len = HCL_COUNTOF(conv_buf); - - /* this must not fail since the dry-run above was successful */ - /*hcl_convbtooochars (hcl, &bsp[tot_len], &src_len, conv_buf, &conv_len);*/ - hcl_conv_bchars_to_uchars_with_cmgr (&bsp[tot_len], &src_len, conv_buf, &conv_len, hcl->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 hcl_uch_t* usp; - hcl_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(HCL_OOCH_IS_UCH) - if (lm_flag & LF_J) goto lowercase_s; - #endif - uppercase_s: - usp = va_arg (ap, hcl_uch_t*); - if (usp == HCL_NULL) usp = uch_nullstr; - - #if defined(HCL_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 (hcl_convutooochars(hcl, usp, &uslen, HCL_NULL, &slen) <= -1) goto oops;*/ - if (hcl_conv_uchars_to_bchars_with_cmgr(usp, &uslen, HCL_NULL, &slen, hcl->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); - { - hcl_ooch_t conv_buf[32]; - hcl_oow_t conv_len, src_len, tot_len = 0; - while (n > 0) - { - HCL_ASSERT (hcl, uslen > tot_len); - - src_len = uslen - tot_len; - conv_len = HCL_COUNTOF(conv_buf); - - /* this must not fail since the dry-run above was successful */ - /*hcl_convutooochars (hcl, &usp[tot_len], &src_len, conv_buf, &conv_len);*/ - hcl_conv_uchars_to_bchars_with_cmgr (&usp[tot_len], &src_len, conv_buf, &conv_len, hcl->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 hcl_uint8_t* bsp; - hcl_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, hcl_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 - { - hcl_bch_t xbuf[3]; - hcl_byte_to_bcstr (*bsp, xbuf, HCL_COUNTOF(xbuf), (16 | (ch == 'k'? HCL_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 hcl_uch_t* usp; - hcl_oow_t uwid; - - if (flagc & FLAGC_ZEROPAD) padc = ' '; - usp = va_arg(ap, hcl_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) - { - hcl_uint16_t u16 = *usp; - int extra_flags = ((ch) == 'w'? HCL_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 - { - hcl_uint32_t u32 = *usp; - int extra_flags = ((ch) == 'w'? HCL_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; - } - - case 'O': /* object - ignore precision, width, adjustment */ - if (hcl_outfmtobj(hcl, (data->mask & ~HCL_LOG_PREFER_JSON), va_arg(ap, hcl_oop_t), outbfmt) <= -1) goto oops; - break; - - case 'J': - if (hcl_outfmtobj(hcl, (data->mask | HCL_LOG_PREFER_JSON), va_arg(ap, hcl_oop_t), outbfmt) <= -1) goto oops; - 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; - hcl_oow_t fmtlen; - #if (HCL_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) - __float128 v_qd; - #endif - long double v_ld; - double v_d; - int dtype = 0; - hcl_oow_t newcapa; - - if (lm_flag & LF_J) - { - #if (HCL_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) && (HCL_SIZEOF_FLTMAX_T == HCL_SIZEOF___FLOAT128) - v_qd = va_arg (ap, hcl_fltmax_t); - dtype = LF_QD; - #elif HCL_SIZEOF_FLTMAX_T == HCL_SIZEOF_DOUBLE - v_d = va_arg (ap, hcl_fltmax_t); - #elif HCL_SIZEOF_FLTMAX_T == HCL_SIZEOF_LONG_DOUBLE - v_ld = va_arg (ap, hcl_fltmax_t); - dtype = LF_LD; - #else - #error Unsupported hcl_flt_t - #endif - } - else if (lm_flag & LF_Z) - { - /* hcl_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 HCL_SIZEOF_FLT_T == HCL_SIZEOF_DOUBLE - v_d = va_arg (ap, hcl_flt_t); - #elif HCL_SIZEOF_FLT_T == HCL_SIZEOF_LONG_DOUBLE - v_ld = va_arg (ap, hcl_flt_t); - dtype = LF_LD; - #else - #error Unsupported hcl_flt_t - #endif - } - else if (lm_flag & (LF_LD | LF_L)) - { - v_ld = va_arg (ap, long double); - dtype = LF_LD; - } - #if (HCL_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 = HCL_MMGR_ALLOC (HCL_MMGR_GETDFL(), HCL_SIZEOF(*fltfmt->ptr) * (fmtlen + 1)); - if (fltfmt->ptr == HCL_NULL) goto oops; - } - else - { - hcl_mchar_t* tmpptr; - - tmpptr = HCL_MMGR_REALLOC (HCL_MMGR_GETDFL(), fltfmt->ptr, HCL_SIZEOF(*fltfmt->ptr) * (fmtlen + 1)); - if (tmpptr == HCL_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 += hcl_fmtuintmaxtombs ( - &fltfmt->ptr[fmtlen], fltfmt->capa - fmtlen, - width, 10, -1, '\0', HCL_NULL); - } - if (flagc & FLAGC_DOT) fltfmt->ptr[fmtlen++] = '.'; - if (flagc & FLAGC_STAR2) fltfmt->ptr[fmtlen++] = '*'; - else if (flagc & FLAGC_PRECISION) - { - fmtlen += hcl_fmtuintmaxtombs ( - &fltfmt->ptr[fmtlen], fltfmt->capa - fmtlen, - precision, 10, -1, '\0', HCL_NULL); - } - - if (dtype == LF_LD) - fltfmt->ptr[fmtlen++] = 'L'; - #if (HCL_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) - { - HCL_ASSERT (hcl, fltout->ptr == fltout->buf); - - fltout->ptr = HCL_MMGR_ALLOC (HCL_MMGR_GETDFL(), HCL_SIZEOF(char_t) * (newcapa + 1)); - if (fltout->ptr == HCL_NULL) goto oops; - fltout->capa = newcapa; - } - #endif - - while (1) - { - - if (dtype == LF_LD) - { - #if defined(HAVE_SNPRINTF) - q = snprintf ((hcl_mchar_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_ld); - #else - q = sprintf ((hcl_mchar_t*)fltout->ptr, fltfmt->ptr, v_ld); - #endif - } - #if (HCL_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) - else if (dtype == LF_QD) - { - q = quadmath_snprintf ((hcl_mchar_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_qd); - } - #endif - else - { - #if defined(HAVE_SNPRINTF) - q = snprintf ((hcl_mchar_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_d); - #else - q = sprintf ((hcl_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 = HCL_MMGR_ALLOC (HCL_MMGR_GETDFL(), HCL_SIZEOF(char_t) * (newcapa + 1)); - if (fltout->ptr == HCL_NULL) goto oops; - } - else - { - char_t* tmpptr; - - tmpptr = HCL_MMGR_REALLOC (HCL_MMGR_GETDFL(), fltout->ptr, HCL_SIZEOF(char_t) * (newcapa + 1)); - if (tmpptr == HCL_NULL) goto oops; - fltout->ptr = tmpptr; - } - fltout->capa = newcapa; - } - - if (HCL_SIZEOF(char_t) != HCL_SIZEOF(hcl_mchar_t)) - { - fltout->ptr[q] = '\0'; - while (q > 0) - { - q--; - fltout->ptr[q] = ((hcl_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__) && \ - (HCL_SIZEOF_UINTMAX_T > HCL_SIZEOF_OOW_T) && \ - (HCL_SIZEOF_UINTMAX_T != HCL_SIZEOF_LONG_LONG) && \ - (HCL_SIZEOF_UINTMAX_T != HCL_SIZEOF_LONG) - /* GCC-compiled binaries crashed when getting hcl_uintmax_t with va_arg. - * This is just a work-around for it */ - int i; - for (i = 0, num = 0; i < HCL_SIZEOF(hcl_uintmax_t) / HCL_SIZEOF(hcl_oow_t); i++) - { - #if defined(HCL_ENDIAN_BIG) - num = num << (8 * HCL_SIZEOF(hcl_oow_t)) | (va_arg (ap, hcl_oow_t)); - #else - register int shift = i * HCL_SIZEOF(hcl_oow_t); - hcl_oow_t x = va_arg (ap, hcl_oow_t); - num |= (hcl_uintmax_t)x << (shift * HCL_BITS_PER_BYTE); - #endif - } - #else - num = va_arg (ap, hcl_uintmax_t); - #endif - } -#if 0 - else if (lm_flag & LF_T) - num = va_arg (ap, hcl_ptrdiff_t); -#endif - else if (lm_flag & LF_Z) - num = va_arg (ap, hcl_oow_t); - #if (HCL_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__) && \ - (HCL_SIZEOF_INTMAX_T > HCL_SIZEOF_OOI_T) && \ - (HCL_SIZEOF_UINTMAX_T != HCL_SIZEOF_LONG_LONG) && \ - (HCL_SIZEOF_UINTMAX_T != HCL_SIZEOF_LONG) - /* GCC-compiled binraries crashed when getting hcl_uintmax_t with va_arg. - * This is just a work-around for it */ - int i; - for (i = 0, num = 0; i < HCL_SIZEOF(hcl_intmax_t) / HCL_SIZEOF(hcl_oow_t); i++) - { - #if defined(HCL_ENDIAN_BIG) - num = num << (8 * HCL_SIZEOF(hcl_oow_t)) | (va_arg (ap, hcl_oow_t)); - #else - register int shift = i * HCL_SIZEOF(hcl_oow_t); - hcl_oow_t x = va_arg (ap, hcl_oow_t); - num |= (hcl_uintmax_t)x << (shift * HCL_BITS_PER_BYTE); - #endif - } - #else - num = va_arg (ap, hcl_intmax_t); - #endif - } - -#if 0 - else if (lm_flag & LF_T) - num = va_arg(ap, hcl_ptrdiff_t); -#endif - else if (lm_flag & LF_Z) - num = va_arg (ap, hcl_ooi_t); - #if (HCL_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 && (hcl_intmax_t)num < 0) - { - neg = 1; - num = -(hcl_intmax_t)num; - } - - nbufp = sprintn (nbuf, num, base, &tmp); - if ((flagc & FLAGC_SHARP) && num != 0) - { - if (base == 2 || base == 8 || base == 16) tmp += 2; - } - if (neg) tmp++; - else if (flagc & FLAGC_SIGN) tmp++; - else if (flagc & FLAGC_SPACE) tmp++; - - numlen = (int)((const hcl_bch_t*)nbufp - (const hcl_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) - { - /* it follows the HCL's number notation, not C's */ - if (base == 2) - { - PUT_OOCH ('#', 1); - PUT_OOCH ('b', 1); - } - if (base == 8) - { - PUT_OOCH ('#', 1); - PUT_OOCH ('o', 1); - } - else if (base == 16) - { - PUT_OOCH ('#', 1); - PUT_OOCH ('x', 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/lib/prim.c b/lib/prim.c index ffa4cdf..99b99bb 100644 --- a/lib/prim.c +++ b/lib/prim.c @@ -169,7 +169,7 @@ static hcl_pfrc_t pf_log (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) static hcl_pfrc_t pf_logf (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) { - if (hcl_logfmtst(hcl, nargs) <= -1) + if (hcl_logfmtcallstack(hcl, nargs) <= -1) { HCL_STACK_SETRETTOERRNUM (hcl, nargs); } @@ -184,7 +184,7 @@ static hcl_pfrc_t pf_logf (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) static hcl_pfrc_t pf_printf (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) { - if (hcl_printfmtst(hcl, nargs) <= -1) + if (hcl_prfmtcallstack(hcl, nargs) <= -1) { HCL_STACK_SETRETTOERRNUM (hcl, nargs); } @@ -199,7 +199,7 @@ static hcl_pfrc_t pf_printf (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) static hcl_pfrc_t pf_sprintf (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) { - if (hcl_sprintfmtst(hcl, nargs) <= -1) + if (hcl_strfmtcallstack(hcl, nargs) <= -1) { HCL_STACK_SETRETTOERRNUM (hcl, nargs); } diff --git a/lib/print.c b/lib/print.c index 3f18e46..14536c4 100644 --- a/lib/print.c +++ b/lib/print.c @@ -113,12 +113,12 @@ static struct { 12, { '#','<','S','E','M','A','P','H','O','R','E','>' } } }; -static HCL_INLINE int print_single_char (hcl_t* hcl, hcl_bitmask_t mask, hcl_ooch_t ch, hcl_outbfmt_t outbfmt) +static HCL_INLINE int print_single_char (hcl_fmtout_t* fmtout, hcl_ooch_t ch) { hcl_oochu_t chu = (hcl_oochu_t)ch; if (chu == '\\' || chu == '\"') { - if (outbfmt(hcl, mask, "\\%jc", chu) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "\\%jc", chu) <= -1) return -1; } #if defined(HCL_OOCH_IS_UCH) else if (chu < ' ') @@ -164,7 +164,7 @@ static HCL_INLINE int print_single_char (hcl_t* hcl, hcl_bitmask_t mask, hcl_ooc #if (HCL_SIZEOF_OOCH_T >= 4) if (chu >= 0x10000u) { - if (outbfmt(hcl, mask, "\\U%08X", chu) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "\\U%08X", chu) <= -1) return -1; } else #endif @@ -172,30 +172,31 @@ static HCL_INLINE int print_single_char (hcl_t* hcl, hcl_bitmask_t mask, hcl_ooc #if (HCL_SIZEOF_OOCH_T >= 2) if (chu >= 0x100u) { - if (outbfmt(hcl, mask, "\\u%04X", chu) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "\\u%04X", chu) <= -1) return -1; } else #endif { - if (outbfmt(hcl, mask, "\\x%02X", chu) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "\\x%02X", chu) <= -1) return -1; } } } else { - if (outbfmt(hcl, mask, "\\%jc", escaped) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "\\%jc", escaped) <= -1) return -1; } } else { - if (outbfmt(hcl, mask, "%jc", ch) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "%jc", ch) <= -1) return -1; } return 0; } -static HCL_INLINE int outfmt_obj (hcl_t* hcl, hcl_bitmask_t mask, hcl_oop_t obj, hcl_outbfmt_t outbfmt) +int hcl_fmt_object_ (hcl_fmtout_t* fmtout, hcl_oop_t obj) { + hcl_t* hcl = (hcl_t*)fmtout->ctx; hcl_oop_t cur; print_stack_t ps; int brand; @@ -226,29 +227,29 @@ static HCL_INLINE int outfmt_obj (hcl_t* hcl, hcl_bitmask_t mask, hcl_oop_t obj, { " ", ":" } /* key value breaker */ }; - json = !!(mask & HCL_LOG_PREFER_JSON); + json = !!(fmtout->mask & HCL_LOG_PREFER_JSON); next: switch ((brand = HCL_BRANDOF(hcl, obj))) { case HCL_BRAND_SMOOI: - if (outbfmt(hcl, mask, "%zd", HCL_OOP_TO_SMOOI(obj)) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "%zd", HCL_OOP_TO_SMOOI(obj)) <= -1) return -1; goto done; case HCL_BRAND_SMPTR: - if (outbfmt(hcl, mask, "#p%zX", (hcl_oow_t)HCL_OOP_TO_SMPTR(obj)) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "#p%zX", (hcl_oow_t)HCL_OOP_TO_SMPTR(obj)) <= -1) return -1; goto done; case HCL_BRAND_ERROR: - if (outbfmt(hcl, mask, "#e%zd", (hcl_ooi_t)HCL_OOP_TO_ERROR(obj)) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "#e%zd", (hcl_ooi_t)HCL_OOP_TO_ERROR(obj)) <= -1) return -1; goto done; case HCL_BRAND_CHARACTER: { hcl_ooch_t ch = HCL_OOP_TO_CHAR(obj); - if (outbfmt(hcl, mask, "\'") <= -1 || - print_single_char(hcl, mask, ch, outbfmt) <= -1 || - outbfmt(hcl, mask, "\'") <= -1) return -1; + if (hcl_bfmt_out(fmtout, "\'") <= -1 || + print_single_char(fmtout, ch) <= -1 || + hcl_bfmt_out(fmtout, "\'") <= -1) return -1; goto done; } @@ -276,7 +277,7 @@ next: if (!tmp) return -1; HCL_ASSERT (hcl, (hcl_oop_t)tmp == hcl->_nil); - if (outbfmt(hcl, mask, "%.*js", hcl->inttostr.xbuf.len, hcl->inttostr.xbuf.ptr) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "%.*js", hcl->inttostr.xbuf.len, hcl->inttostr.xbuf.ptr) <= -1) return -1; break; } @@ -291,11 +292,11 @@ next: { if (scale == 0) { - if (outbfmt(hcl, mask, "0.") <= -1) return -1; + if (hcl_bfmt_out(fmtout, "0.") <= -1) return -1; } else { - if (outbfmt(hcl, mask, "0.%0*d", scale, 0) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "0.%0*d", scale, 0) <= -1) return -1; } } else @@ -313,13 +314,13 @@ next: { if (scale == len) { - if (outbfmt(hcl, mask, "%.*js0.%.*js", + if (hcl_bfmt_out(fmtout, "%.*js0.%.*js", adj, hcl->inttostr.xbuf.ptr, len, &hcl->inttostr.xbuf.ptr[adj]) <= -1) return -1; } else { - if (outbfmt(hcl, mask, "%.*js0.%0*d%.*js", + if (hcl_bfmt_out(fmtout, "%.*js0.%0*d%.*js", adj, hcl->inttostr.xbuf.ptr, scale - len, 0, len, &hcl->inttostr.xbuf.ptr[adj]) <= -1) return -1; @@ -329,7 +330,7 @@ next: { hcl_ooi_t ndigits; ndigits = hcl->inttostr.xbuf.len - scale; - if (outbfmt(hcl, mask, "%.*js.%.*js", ndigits, hcl->inttostr.xbuf.ptr, scale, &hcl->inttostr.xbuf.ptr[ndigits]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "%.*js.%.*js", ndigits, hcl->inttostr.xbuf.ptr, scale, &hcl->inttostr.xbuf.ptr[ndigits]) <= -1) return -1; } } break; @@ -359,7 +360,7 @@ next: /* Any needs for special action if SYNT(obj) is true? * I simply treat the syntax symbol as a normal symbol * for printing currently. */ - if (outbfmt(hcl, mask, "%.*js", HCL_OBJ_GET_SIZE(obj), HCL_OBJ_GET_CHAR_SLOT(obj)) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "%.*js", HCL_OBJ_GET_SIZE(obj), HCL_OBJ_GET_CHAR_SLOT(obj)) <= -1) return -1; break; case HCL_BRAND_STRING: @@ -380,17 +381,17 @@ next: if (escape) { - if (outbfmt(hcl, mask, "\"") <= -1) return -1; + if (hcl_bfmt_out(fmtout, "\"") <= -1) return -1; for (i = 0; i < HCL_OBJ_GET_SIZE(obj); i++) { ch = ((hcl_oop_char_t)obj)->slot[i]; - if (print_single_char(hcl, mask, ch, outbfmt) <= -1) return -1; + if (print_single_char(fmtout, ch) <= -1) return -1; } - if (outbfmt(hcl, mask, "\"") <= -1) return -1; + if (hcl_bfmt_out(fmtout, "\"") <= -1) return -1; } else { - if (outbfmt(hcl, mask, "\"%.*js\"", HCL_OBJ_GET_SIZE(obj), HCL_OBJ_GET_CHAR_SLOT(obj)) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "\"%.*js\"", HCL_OBJ_GET_SIZE(obj), HCL_OBJ_GET_CHAR_SLOT(obj)) <= -1) return -1; } break; } @@ -403,7 +404,7 @@ next: * request to output in the json format */ concode = HCL_OBJ_GET_FLAGS_SYNCODE(obj); - if (outbfmt(hcl, mask, opening_parens[concode][0]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, opening_parens[concode][0]) <= -1) return -1; cur = obj; do @@ -438,7 +439,7 @@ next: if (!HCL_OOP_IS_POINTER(cur) || HCL_OBJ_GET_FLAGS_BRAND(cur) != HCL_BRAND_CONS) { /* The CDR part does not point to a pair. */ - if (outbfmt(hcl, mask, " . ") <= -1) return -1; + if (hcl_bfmt_out(fmtout, " . ") <= -1) return -1; /* Push NIL so that the HCL_IS_NIL(hcl,p) test in * the 'if' statement above breaks the loop @@ -455,11 +456,11 @@ next: } /* The CDR part points to a pair. proceed to it */ - if (outbfmt(hcl, mask, breakers[0][0]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, breakers[0][0]) <= -1) return -1; } while (1); - if (outbfmt(hcl, mask, closing_parens[concode][0]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, closing_parens[concode][0]) <= -1) return -1; break; } @@ -467,11 +468,11 @@ next: { hcl_oow_t arridx; - if (outbfmt(hcl, mask, opening_parens[HCL_CONCODE_ARRAY][json]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, opening_parens[HCL_CONCODE_ARRAY][json]) <= -1) return -1; if (HCL_OBJ_GET_SIZE(obj) <= 0) { - if (outbfmt(hcl, mask, closing_parens[HCL_CONCODE_ARRAY][json]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, closing_parens[HCL_CONCODE_ARRAY][json]) <= -1) return -1; break; } arridx = 0; @@ -499,7 +500,7 @@ next: obj = ((hcl_oop_oop_t)obj)->slot[arridx]; if (arridx > 0) { - if (outbfmt(hcl, mask, breakers[0][json]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, breakers[0][json]) <= -1) return -1; } /* Jump to the 'next' label so that the object * pointed to by 'obj' is printed. Once it @@ -519,16 +520,16 @@ next: case HCL_BRAND_BYTE_ARRAY: { hcl_oow_t i; - if (outbfmt(hcl, mask, opening_parens[HCL_CONCODE_BYTEARRAY][json]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, opening_parens[HCL_CONCODE_BYTEARRAY][json]) <= -1) return -1; if (HCL_OBJ_GET_SIZE(obj) > 0) { - if (outbfmt(hcl, mask, "%d", ((hcl_oop_byte_t)obj)->slot[0]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "%d", ((hcl_oop_byte_t)obj)->slot[0]) <= -1) return -1; for (i = 1; i < HCL_OBJ_GET_SIZE(obj); i++) { - if (outbfmt(hcl, mask, "%hs%d", breakers[0][json], ((hcl_oop_byte_t)obj)->slot[i]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "%hs%d", breakers[0][json], ((hcl_oop_byte_t)obj)->slot[i]) <= -1) return -1; } } - if (outbfmt(hcl, mask, closing_parens[HCL_CONCODE_BYTEARRAY][json]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, closing_parens[HCL_CONCODE_BYTEARRAY][json]) <= -1) return -1; break; } @@ -537,13 +538,13 @@ next: hcl_oow_t bucidx, bucsize, buctally; hcl_oop_dic_t dic; - if (outbfmt(hcl, mask, opening_parens[HCL_CONCODE_DIC][json]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, opening_parens[HCL_CONCODE_DIC][json]) <= -1) return -1; dic = (hcl_oop_dic_t)obj; HCL_ASSERT (hcl, HCL_OOP_IS_SMOOI(dic->tally)); if (HCL_OOP_TO_SMOOI(dic->tally) <= 0) { - if (outbfmt(hcl, mask, closing_parens[HCL_CONCODE_DIC][json]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, closing_parens[HCL_CONCODE_DIC][json]) <= -1) return -1; break; } bucidx = 0; @@ -569,7 +570,7 @@ next: if (bucidx >= bucsize) { /* done. scanned the entire bucket */ - if (outbfmt(hcl, mask, closing_parens[HCL_CONCODE_DIC][json]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, closing_parens[HCL_CONCODE_DIC][json]) <= -1) return -1; break; } @@ -610,7 +611,7 @@ next: if (buctally > 0) { - if (outbfmt(hcl, mask, breakers[buctally & 1][json]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, breakers[buctally & 1][json]) <= -1) return -1; } /* Jump to the 'next' label so that the object @@ -636,15 +637,15 @@ next: { hcl_oow_t i; - if (outbfmt(hcl, mask, "|") <= -1) return -1; + if (hcl_bfmt_out(fmtout, "|") <= -1) return -1; for (i = 0; i < HCL_OBJ_GET_SIZE(obj); i++) { hcl_oop_t s; s = ((hcl_oop_oop_t)obj)->slot[i]; - if (outbfmt(hcl, mask, " %.*js", HCL_OBJ_GET_SIZE(s), HCL_OBJ_GET_CHAR_SLOT(s)) <= -1) return -1; + if (hcl_bfmt_out(fmtout, " %.*js", HCL_OBJ_GET_SIZE(s), HCL_OBJ_GET_CHAR_SLOT(s)) <= -1) return -1; } - if (outbfmt(hcl, mask, " |") <= -1) return -1; + if (hcl_bfmt_out(fmtout, " |") <= -1) return -1; break; } @@ -679,7 +680,7 @@ next: return -1; print_word: - if (outbfmt(hcl, mask, "%.*js", word[word_index].len, word[word_index].ptr) <= -1) return -1; + if (hcl_bfmt_out(fmtout, "%.*js", word[word_index].len, word[word_index].ptr) <= -1) return -1; break; } @@ -697,14 +698,14 @@ done: goto resume_array; case PRINT_STACK_ARRAY_END: - if (outbfmt(hcl, mask, closing_parens[HCL_CONCODE_ARRAY][json]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, closing_parens[HCL_CONCODE_ARRAY][json]) <= -1) return -1; break; case PRINT_STACK_DIC: goto resume_dic; case PRINT_STACK_DIC_END: - if (outbfmt(hcl, mask, closing_parens[HCL_CONCODE_DIC][json]) <= -1) return -1; + if (hcl_bfmt_out(fmtout, closing_parens[HCL_CONCODE_DIC][json]) <= -1) return -1; break; default: @@ -716,6 +717,7 @@ done: return 0; } +#if 0 int hcl_outfmtobj (hcl_t* hcl, hcl_bitmask_t mask, hcl_oop_t obj, hcl_outbfmt_t outbfmt) { int n; @@ -724,7 +726,7 @@ int hcl_outfmtobj (hcl_t* hcl, hcl_bitmask_t mask, hcl_oop_t obj, hcl_outbfmt_t HCL_ASSERT (hcl, hcl->p.s.size == 0); hcl->p.e = obj; /* remember the head of the object to print */ - n = outfmt_obj(hcl, mask, obj, outbfmt); + n = hcl_proutbfmt(hcl, mask, obj); hcl->p.e = hcl->_nil; /* reset what's remembered */ /* clear the printing stack if an error has occurred for GC not to keep @@ -736,9 +738,11 @@ int hcl_outfmtobj (hcl_t* hcl, hcl_bitmask_t mask, hcl_oop_t obj, hcl_outbfmt_t return n; } +#endif int hcl_print (hcl_t* hcl, hcl_oop_t obj) { HCL_ASSERT (hcl, hcl->c->printer != HCL_NULL); - return hcl_outfmtobj (hcl, HCL_LOG_APP | HCL_LOG_FATAL, obj, hcl_proutbfmt); + /*return hcl_outfmtobj(hcl, HCL_LOG_APP | HCL_LOG_FATAL, obj);*/ + return hcl_prbfmt(hcl, "%O", obj); }