Compare commits

...

2 Commits

Author SHA1 Message Date
06a135f852 merged hclj to hclx
All checks were successful
continuous-integration/drone/push Build is passing
2024-04-27 21:33:34 +09:00
8dc884aa7e added hcl_get_base_name_from_path()
merged hclx server and client into a single command
2024-04-27 21:16:00 +09:00
13 changed files with 413 additions and 1134 deletions

View File

@ -24,28 +24,17 @@ LIBADD_COMMON += $(DL_LIBS)
endif
bin_PROGRAMS = hcl
hcl_SOURCES = main.c
hcl_SOURCES = hcl.c
hcl_CPPFLAGS = $(CPPFLAGS_COMMON)
hcl_LDFLAGS = $(LDFLAGS_COMMON)
hcl_LDADD = ../lib/libhcl.la $(LIBADD_COMMON)
if ENABLE_HCLX
bin_PROGRAMS += hcls
hcls_SOURCES = main-s.c
hcls_CPPFLAGS = $(CPPFLAGS_COMMON)
hcls_LDFLAGS = $(LDFLAGS_COMMON)
hcls_LDADD = ../lib/libhclx.la $(LIBADD_COMMON)
bin_PROGRAMS += hclx
hclx_SOURCES = hclx.c
hclx_CPPFLAGS = $(CPPFLAGS_COMMON)
hclx_LDFLAGS = $(LDFLAGS_COMMON)
hclx_LDADD = ../lib/libhclx.la $(LIBADD_COMMON)
bin_PROGRAMS += hclc
hclc_SOURCES = main-c.c
hclc_CPPFLAGS = $(CPPFLAGS_COMMON)
hclc_LDFLAGS = $(LDFLAGS_COMMON)
hclc_LDADD = ../lib/libhclx.la $(LIBADD_COMMON)
bin_PROGRAMS += hclj
hclj_SOURCES = main-j.c
hclj_CPPFLAGS = $(CPPFLAGS_COMMON)
hclj_LDFLAGS = $(LDFLAGS_COMMON)
hclj_LDADD = ../lib/libhclx.la $(LIBADD_COMMON)
endif

View File

@ -95,7 +95,7 @@ host_triplet = @host@
@ENABLE_LIBLTDL_TRUE@am__append_1 = $(LTDL_LIBS)
@ENABLE_LIBLTDL_FALSE@am__append_2 = $(DL_LIBS)
bin_PROGRAMS = hcl$(EXEEXT) $(am__EXEEXT_1)
@ENABLE_HCLX_TRUE@am__append_3 = hcls hclc hclj
@ENABLE_HCLX_TRUE@am__append_3 = hclx
subdir = bin
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
@ -110,11 +110,10 @@ mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/lib/hcl-cfg.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
@ENABLE_HCLX_TRUE@am__EXEEXT_1 = hcls$(EXEEXT) hclc$(EXEEXT) \
@ENABLE_HCLX_TRUE@ hclj$(EXEEXT)
@ENABLE_HCLX_TRUE@am__EXEEXT_1 = hclx$(EXEEXT)
am__installdirs = "$(DESTDIR)$(bindir)"
PROGRAMS = $(bin_PROGRAMS)
am_hcl_OBJECTS = hcl-main.$(OBJEXT)
am_hcl_OBJECTS = hcl-hcl.$(OBJEXT)
hcl_OBJECTS = $(am_hcl_OBJECTS)
am__DEPENDENCIES_1 =
@ENABLE_LIBLTDL_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
@ -128,30 +127,14 @@ am__v_lt_1 =
hcl_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(hcl_LDFLAGS) $(LDFLAGS) -o $@
am__hclc_SOURCES_DIST = main-c.c
@ENABLE_HCLX_TRUE@am_hclc_OBJECTS = hclc-main-c.$(OBJEXT)
hclc_OBJECTS = $(am_hclc_OBJECTS)
@ENABLE_HCLX_TRUE@hclc_DEPENDENCIES = ../lib/libhclx.la \
am__hclx_SOURCES_DIST = hclx.c
@ENABLE_HCLX_TRUE@am_hclx_OBJECTS = hclx-hclx.$(OBJEXT)
hclx_OBJECTS = $(am_hclx_OBJECTS)
@ENABLE_HCLX_TRUE@hclx_DEPENDENCIES = ../lib/libhclx.la \
@ENABLE_HCLX_TRUE@ $(am__DEPENDENCIES_4)
hclc_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
hclx_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(hclc_LDFLAGS) $(LDFLAGS) -o $@
am__hclj_SOURCES_DIST = main-j.c
@ENABLE_HCLX_TRUE@am_hclj_OBJECTS = hclj-main-j.$(OBJEXT)
hclj_OBJECTS = $(am_hclj_OBJECTS)
@ENABLE_HCLX_TRUE@hclj_DEPENDENCIES = ../lib/libhclx.la \
@ENABLE_HCLX_TRUE@ $(am__DEPENDENCIES_4)
hclj_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(hclj_LDFLAGS) $(LDFLAGS) -o $@
am__hcls_SOURCES_DIST = main-s.c
@ENABLE_HCLX_TRUE@am_hcls_OBJECTS = hcls-main-s.$(OBJEXT)
hcls_OBJECTS = $(am_hcls_OBJECTS)
@ENABLE_HCLX_TRUE@hcls_DEPENDENCIES = ../lib/libhclx.la \
@ENABLE_HCLX_TRUE@ $(am__DEPENDENCIES_4)
hcls_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(hcls_LDFLAGS) $(LDFLAGS) -o $@
$(hclx_LDFLAGS) $(LDFLAGS) -o $@
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
@ -167,9 +150,7 @@ am__v_at_1 =
DEFAULT_INCLUDES =
depcomp = $(SHELL) $(top_srcdir)/ac/depcomp
am__maybe_remake_depfiles = depfiles
am__depfiles_remade = ./$(DEPDIR)/hcl-main.Po \
./$(DEPDIR)/hclc-main-c.Po ./$(DEPDIR)/hclj-main-j.Po \
./$(DEPDIR)/hcls-main-s.Po
am__depfiles_remade = ./$(DEPDIR)/hcl-hcl.Po ./$(DEPDIR)/hclx-hclx.Po
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@ -189,10 +170,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 = $(hcl_SOURCES) $(hclc_SOURCES) $(hclj_SOURCES) \
$(hcls_SOURCES)
DIST_SOURCES = $(hcl_SOURCES) $(am__hclc_SOURCES_DIST) \
$(am__hclj_SOURCES_DIST) $(am__hcls_SOURCES_DIST)
SOURCES = $(hcl_SOURCES) $(hclx_SOURCES)
DIST_SOURCES = $(hcl_SOURCES) $(am__hclx_SOURCES_DIST)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@ -369,22 +348,14 @@ CPPFLAGS_COMMON = \
CFLAGS_COMMON =
LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir)
LIBADD_COMMON = $(am__append_1) $(am__append_2)
hcl_SOURCES = main.c
hcl_SOURCES = hcl.c
hcl_CPPFLAGS = $(CPPFLAGS_COMMON)
hcl_LDFLAGS = $(LDFLAGS_COMMON)
hcl_LDADD = ../lib/libhcl.la $(LIBADD_COMMON)
@ENABLE_HCLX_TRUE@hcls_SOURCES = main-s.c
@ENABLE_HCLX_TRUE@hcls_CPPFLAGS = $(CPPFLAGS_COMMON)
@ENABLE_HCLX_TRUE@hcls_LDFLAGS = $(LDFLAGS_COMMON)
@ENABLE_HCLX_TRUE@hcls_LDADD = ../lib/libhclx.la $(LIBADD_COMMON)
@ENABLE_HCLX_TRUE@hclc_SOURCES = main-c.c
@ENABLE_HCLX_TRUE@hclc_CPPFLAGS = $(CPPFLAGS_COMMON)
@ENABLE_HCLX_TRUE@hclc_LDFLAGS = $(LDFLAGS_COMMON)
@ENABLE_HCLX_TRUE@hclc_LDADD = ../lib/libhclx.la $(LIBADD_COMMON)
@ENABLE_HCLX_TRUE@hclj_SOURCES = main-j.c
@ENABLE_HCLX_TRUE@hclj_CPPFLAGS = $(CPPFLAGS_COMMON)
@ENABLE_HCLX_TRUE@hclj_LDFLAGS = $(LDFLAGS_COMMON)
@ENABLE_HCLX_TRUE@hclj_LDADD = ../lib/libhclx.la $(LIBADD_COMMON)
@ENABLE_HCLX_TRUE@hclx_SOURCES = hclx.c
@ENABLE_HCLX_TRUE@hclx_CPPFLAGS = $(CPPFLAGS_COMMON)
@ENABLE_HCLX_TRUE@hclx_LDFLAGS = $(LDFLAGS_COMMON)
@ENABLE_HCLX_TRUE@hclx_LDADD = ../lib/libhclx.la $(LIBADD_COMMON)
all: all-am
.SUFFIXES:
@ -472,17 +443,9 @@ hcl$(EXEEXT): $(hcl_OBJECTS) $(hcl_DEPENDENCIES) $(EXTRA_hcl_DEPENDENCIES)
@rm -f hcl$(EXEEXT)
$(AM_V_CCLD)$(hcl_LINK) $(hcl_OBJECTS) $(hcl_LDADD) $(LIBS)
hclc$(EXEEXT): $(hclc_OBJECTS) $(hclc_DEPENDENCIES) $(EXTRA_hclc_DEPENDENCIES)
@rm -f hclc$(EXEEXT)
$(AM_V_CCLD)$(hclc_LINK) $(hclc_OBJECTS) $(hclc_LDADD) $(LIBS)
hclj$(EXEEXT): $(hclj_OBJECTS) $(hclj_DEPENDENCIES) $(EXTRA_hclj_DEPENDENCIES)
@rm -f hclj$(EXEEXT)
$(AM_V_CCLD)$(hclj_LINK) $(hclj_OBJECTS) $(hclj_LDADD) $(LIBS)
hcls$(EXEEXT): $(hcls_OBJECTS) $(hcls_DEPENDENCIES) $(EXTRA_hcls_DEPENDENCIES)
@rm -f hcls$(EXEEXT)
$(AM_V_CCLD)$(hcls_LINK) $(hcls_OBJECTS) $(hcls_LDADD) $(LIBS)
hclx$(EXEEXT): $(hclx_OBJECTS) $(hclx_DEPENDENCIES) $(EXTRA_hclx_DEPENDENCIES)
@rm -f hclx$(EXEEXT)
$(AM_V_CCLD)$(hclx_LINK) $(hclx_OBJECTS) $(hclx_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@ -490,10 +453,8 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hcl-main.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hclc-main-c.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hclj-main-j.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hcls-main-s.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hcl-hcl.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hclx-hclx.Po@am__quote@ # am--include-marker
$(am__depfiles_remade):
@$(MKDIR_P) $(@D)
@ -525,61 +486,33 @@ am--depfiles: $(am__depfiles_remade)
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
hcl-main.o: main.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hcl-main.o -MD -MP -MF $(DEPDIR)/hcl-main.Tpo -c -o hcl-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hcl-main.Tpo $(DEPDIR)/hcl-main.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main.c' object='hcl-main.o' libtool=no @AMDEPBACKSLASH@
hcl-hcl.o: hcl.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hcl-hcl.o -MD -MP -MF $(DEPDIR)/hcl-hcl.Tpo -c -o hcl-hcl.o `test -f 'hcl.c' || echo '$(srcdir)/'`hcl.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hcl-hcl.Tpo $(DEPDIR)/hcl-hcl.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hcl.c' object='hcl-hcl.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hcl-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hcl-hcl.o `test -f 'hcl.c' || echo '$(srcdir)/'`hcl.c
hcl-main.obj: main.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hcl-main.obj -MD -MP -MF $(DEPDIR)/hcl-main.Tpo -c -o hcl-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hcl-main.Tpo $(DEPDIR)/hcl-main.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main.c' object='hcl-main.obj' libtool=no @AMDEPBACKSLASH@
hcl-hcl.obj: hcl.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hcl-hcl.obj -MD -MP -MF $(DEPDIR)/hcl-hcl.Tpo -c -o hcl-hcl.obj `if test -f 'hcl.c'; then $(CYGPATH_W) 'hcl.c'; else $(CYGPATH_W) '$(srcdir)/hcl.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hcl-hcl.Tpo $(DEPDIR)/hcl-hcl.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hcl.c' object='hcl-hcl.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hcl-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi`
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcl_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hcl-hcl.obj `if test -f 'hcl.c'; then $(CYGPATH_W) 'hcl.c'; else $(CYGPATH_W) '$(srcdir)/hcl.c'; fi`
hclc-main-c.o: main-c.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclc_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hclc-main-c.o -MD -MP -MF $(DEPDIR)/hclc-main-c.Tpo -c -o hclc-main-c.o `test -f 'main-c.c' || echo '$(srcdir)/'`main-c.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hclc-main-c.Tpo $(DEPDIR)/hclc-main-c.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main-c.c' object='hclc-main-c.o' libtool=no @AMDEPBACKSLASH@
hclx-hclx.o: hclx.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hclx-hclx.o -MD -MP -MF $(DEPDIR)/hclx-hclx.Tpo -c -o hclx-hclx.o `test -f 'hclx.c' || echo '$(srcdir)/'`hclx.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hclx-hclx.Tpo $(DEPDIR)/hclx-hclx.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hclx.c' object='hclx-hclx.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclc_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hclc-main-c.o `test -f 'main-c.c' || echo '$(srcdir)/'`main-c.c
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hclx-hclx.o `test -f 'hclx.c' || echo '$(srcdir)/'`hclx.c
hclc-main-c.obj: main-c.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclc_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hclc-main-c.obj -MD -MP -MF $(DEPDIR)/hclc-main-c.Tpo -c -o hclc-main-c.obj `if test -f 'main-c.c'; then $(CYGPATH_W) 'main-c.c'; else $(CYGPATH_W) '$(srcdir)/main-c.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hclc-main-c.Tpo $(DEPDIR)/hclc-main-c.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main-c.c' object='hclc-main-c.obj' libtool=no @AMDEPBACKSLASH@
hclx-hclx.obj: hclx.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hclx-hclx.obj -MD -MP -MF $(DEPDIR)/hclx-hclx.Tpo -c -o hclx-hclx.obj `if test -f 'hclx.c'; then $(CYGPATH_W) 'hclx.c'; else $(CYGPATH_W) '$(srcdir)/hclx.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hclx-hclx.Tpo $(DEPDIR)/hclx-hclx.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hclx.c' object='hclx-hclx.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclc_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hclc-main-c.obj `if test -f 'main-c.c'; then $(CYGPATH_W) 'main-c.c'; else $(CYGPATH_W) '$(srcdir)/main-c.c'; fi`
hclj-main-j.o: main-j.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclj_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hclj-main-j.o -MD -MP -MF $(DEPDIR)/hclj-main-j.Tpo -c -o hclj-main-j.o `test -f 'main-j.c' || echo '$(srcdir)/'`main-j.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hclj-main-j.Tpo $(DEPDIR)/hclj-main-j.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main-j.c' object='hclj-main-j.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclj_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hclj-main-j.o `test -f 'main-j.c' || echo '$(srcdir)/'`main-j.c
hclj-main-j.obj: main-j.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclj_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hclj-main-j.obj -MD -MP -MF $(DEPDIR)/hclj-main-j.Tpo -c -o hclj-main-j.obj `if test -f 'main-j.c'; then $(CYGPATH_W) 'main-j.c'; else $(CYGPATH_W) '$(srcdir)/main-j.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hclj-main-j.Tpo $(DEPDIR)/hclj-main-j.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main-j.c' object='hclj-main-j.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclj_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hclj-main-j.obj `if test -f 'main-j.c'; then $(CYGPATH_W) 'main-j.c'; else $(CYGPATH_W) '$(srcdir)/main-j.c'; fi`
hcls-main-s.o: main-s.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcls_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hcls-main-s.o -MD -MP -MF $(DEPDIR)/hcls-main-s.Tpo -c -o hcls-main-s.o `test -f 'main-s.c' || echo '$(srcdir)/'`main-s.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hcls-main-s.Tpo $(DEPDIR)/hcls-main-s.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main-s.c' object='hcls-main-s.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcls_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hcls-main-s.o `test -f 'main-s.c' || echo '$(srcdir)/'`main-s.c
hcls-main-s.obj: main-s.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcls_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT hcls-main-s.obj -MD -MP -MF $(DEPDIR)/hcls-main-s.Tpo -c -o hcls-main-s.obj `if test -f 'main-s.c'; then $(CYGPATH_W) 'main-s.c'; else $(CYGPATH_W) '$(srcdir)/main-s.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hcls-main-s.Tpo $(DEPDIR)/hcls-main-s.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main-s.c' object='hcls-main-s.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hcls_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hcls-main-s.obj `if test -f 'main-s.c'; then $(CYGPATH_W) 'main-s.c'; else $(CYGPATH_W) '$(srcdir)/main-s.c'; fi`
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hclx_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o hclx-hclx.obj `if test -f 'hclx.c'; then $(CYGPATH_W) 'hclx.c'; else $(CYGPATH_W) '$(srcdir)/hclx.c'; fi`
mostlyclean-libtool:
-rm -f *.lo
@ -713,10 +646,8 @@ clean: clean-am
clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
distclean: distclean-am
-rm -f ./$(DEPDIR)/hcl-main.Po
-rm -f ./$(DEPDIR)/hclc-main-c.Po
-rm -f ./$(DEPDIR)/hclj-main-j.Po
-rm -f ./$(DEPDIR)/hcls-main-s.Po
-rm -f ./$(DEPDIR)/hcl-hcl.Po
-rm -f ./$(DEPDIR)/hclx-hclx.Po
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
@ -762,10 +693,8 @@ install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/hcl-main.Po
-rm -f ./$(DEPDIR)/hclc-main-c.Po
-rm -f ./$(DEPDIR)/hclj-main-j.Po
-rm -f ./$(DEPDIR)/hcls-main-s.Po
-rm -f ./$(DEPDIR)/hcl-hcl.Po
-rm -f ./$(DEPDIR)/hclx-hclx.Po
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic

View File

@ -25,6 +25,7 @@
*/
#include "hcl-x.h"
#include "hcl-json.h"
#include "hcl-opt.h"
#include "hcl-utl.h"
#include "hcl-xutl.h"
@ -34,6 +35,8 @@
#include <string.h>
#include <errno.h>
#include <locale.h>
#include <unistd.h>
#include <fcntl.h>
#if defined(HAVE_TIME_H)
# include <time.h>
@ -48,8 +51,6 @@
# include <sys/uio.h>
#endif
#include <unistd.h>
#include <fcntl.h>
/* ========================================================================= */
@ -65,8 +66,16 @@ struct server_xtn_t
hcl_bch_t buf[4096];
hcl_oow_t len;
} logbuf;
/* used by the json submodule */
int json_depth;
};
typedef server_xtn_t client_xtn_t;
typedef server_xtn_t json_xtn_t;
/* ========================================================================= */
static void* sys_alloc (hcl_mmgr_t* mmgr, hcl_oow_t size)
@ -128,10 +137,8 @@ static int write_all (int fd, const hcl_bch_t* ptr, hcl_oow_t len)
}
static int write_log (hcl_server_t* server, int fd, const hcl_bch_t* ptr, hcl_oow_t len)
static int write_log (server_xtn_t* xtn, int fd, const hcl_bch_t* ptr, hcl_oow_t len)
{
server_xtn_t* xtn = (server_xtn_t*)hcl_server_getxtn(server);
while (len > 0)
{
if (xtn->logbuf.len > 0)
@ -177,10 +184,8 @@ static int write_log (hcl_server_t* server, int fd, const hcl_bch_t* ptr, hcl_oo
return 0;
}
static void flush_log (hcl_server_t* server, int fd)
static void flush_log (server_xtn_t* xtn, int fd)
{
server_xtn_t* xtn = (server_xtn_t*)hcl_server_getxtn(server);
if (xtn->logbuf.len > 0)
{
write_all (fd, xtn->logbuf.buf, xtn->logbuf.len);
@ -188,9 +193,8 @@ static void flush_log (hcl_server_t* server, int fd)
}
}
static void log_write (hcl_server_t* server, hcl_oow_t wid, hcl_bitmask_t mask, const hcl_ooch_t* msg, hcl_oow_t len)
static void log_write (server_xtn_t* xtn, hcl_oow_t wid, hcl_bitmask_t mask, const hcl_ooch_t* msg, hcl_oow_t len)
{
server_xtn_t* xtn = (server_xtn_t*)hcl_server_getxtn(server);
hcl_bch_t buf[256];
hcl_oow_t ucslen, bcslen;
hcl_oow_t msgidx;
@ -243,21 +247,21 @@ static void log_write (hcl_server_t* server, hcl_oow_t wid, hcl_bitmask_t mask,
tslen = 25;
}
write_log (server, logfd, ts, tslen);
write_log (xtn, logfd, ts, tslen);
if (wid != HCL_SERVER_WID_INVALID)
{
/* TODO: check if the underlying snprintf support %zd */
tslen = snprintf (ts, sizeof(ts), "[%zu] ", wid);
write_log (server, logfd, ts, tslen);
write_log (xtn, logfd, ts, tslen);
}
}
if (logfd == xtn->logfd && xtn->logfd_istty)
{
if (mask & HCL_LOG_FATAL) write_log (server, logfd, "\x1B[1;31m", 7);
else if (mask & HCL_LOG_ERROR) write_log (server, logfd, "\x1B[1;32m", 7);
else if (mask & HCL_LOG_WARN) write_log (server, logfd, "\x1B[1;33m", 7);
if (mask & HCL_LOG_FATAL) write_log (xtn, logfd, "\x1B[1;31m", 7);
else if (mask & HCL_LOG_ERROR) write_log (xtn, logfd, "\x1B[1;32m", 7);
else if (mask & HCL_LOG_WARN) write_log (xtn, logfd, "\x1B[1;33m", 7);
}
#if defined(HCL_OOCH_IS_UCH)
@ -280,7 +284,7 @@ static void log_write (hcl_server_t* server, hcl_oow_t wid, hcl_bitmask_t mask,
/*assert (ucslen > 0);*/
/* attempt to write all converted characters */
if (write_log(server, logfd, buf, bcslen) <= -1) break;
if (write_log(xtn, logfd, buf, bcslen) <= -1) break;
if (n == 0) break;
else
@ -293,26 +297,44 @@ static void log_write (hcl_server_t* server, hcl_oow_t wid, hcl_bitmask_t mask,
{
/* conversion error */
if (bcslen <= 0) break;
if (write_log(server, logfd, buf, bcslen) <= -1) break;
if (write_log(xtn, logfd, buf, bcslen) <= -1) break;
msgidx += ucslen;
len -= ucslen;
}
}
#else
write_log (server, logfd, msg, len);
write_log (xtn, logfd, msg, len);
#endif
if (logfd == xtn->logfd && xtn->logfd_istty)
{
if (mask & (HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN)) write_log (server, logfd, "\x1B[0m", 4);
if (mask & (HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN)) write_log (xtn, logfd, "\x1B[0m", 4);
}
flush_log (server, logfd);
flush_log (xtn, logfd);
}
/* ========================================================================= */
static void server_log_write (hcl_server_t* server, hcl_oow_t wid, hcl_bitmask_t mask, const hcl_ooch_t* msg, hcl_oow_t len)
{
log_write ((server_xtn_t*)hcl_server_getxtn(server), wid, mask, msg, len);
}
static void client_log_write (hcl_client_t* client, hcl_bitmask_t mask, const hcl_ooch_t* msg, hcl_oow_t len)
{
log_write ((client_xtn_t*)hcl_client_getxtn(client), HCL_SERVER_WID_INVALID, mask, msg, len);
}
static void json_log_write (hcl_json_t* json, hcl_bitmask_t mask, const hcl_ooch_t* msg, hcl_oow_t len)
{
log_write ((json_xtn_t*)hcl_json_getxtn(json), HCL_SERVER_WID_INVALID, mask, msg, len);
}
/* ========================================================================= */
static hcl_server_t* g_server = HCL_NULL;
static hcl_client_t* g_client = HCL_NULL;
/* ========================================================================= */
@ -321,6 +343,7 @@ typedef void (*signal_handler_t) (int, siginfo_t*, void*);
static void handle_sigint (int sig, siginfo_t* siginfo, void* ctx)
{
if (g_server) hcl_server_stop (g_server);
if (g_client) hcl_client_stop (g_client);
}
static void set_signal (int sig, signal_handler_t handler)
@ -362,14 +385,11 @@ static void set_signal_to_default (int sig)
/* ========================================================================= */
static int handle_logopt (hcl_server_t* server, const hcl_bch_t* str)
static int handle_logopt (server_xtn_t* xtn, const hcl_bch_t* str)
{
hcl_bch_t* xstr = (hcl_bch_t*)str;
hcl_bch_t* cm, * flt;
hcl_bitmask_t logmask;
server_xtn_t* xtn;
xtn = (server_xtn_t*)hcl_server_getxtn(server);
cm = hcl_find_bchar_in_bcstr(xstr, ',');
if (cm)
@ -448,6 +468,16 @@ static int handle_logopt (hcl_server_t* server, const hcl_bch_t* str)
return 0;
}
static int server_handle_logopt (hcl_server_t* server, const hcl_bch_t* str)
{
return handle_logopt((server_xtn_t*)hcl_server_getxtn(server), str);
}
static int client_handle_logopt (hcl_client_t* client, const hcl_bch_t* str)
{
return handle_logopt((client_xtn_t*)hcl_client_getxtn(client), str);
}
#if defined(HCL_BUILD_DEBUG)
static int handle_dbgopt (hcl_server_t* server, const char* str)
{
@ -498,7 +528,7 @@ static int handle_incpath (hcl_server_t* server, const char* str)
#define MIN_WORKER_STACK_SIZE 512000ul
#define MIN_ACTOR_HEAP_SIZE 512000ul
int server_main (const char* outer, int argc, char* argv[])
static int server_main (const char* outer, int argc, char* argv[])
{
hcl_bci_t c;
static hcl_bopt_lng_t lopt[] =
@ -540,7 +570,7 @@ int server_main (const char* outer, int argc, char* argv[])
if (argc < 2)
{
print_usage:
fprintf (stderr, "Usage: %s bind-address:port\n", argv[0]);
fprintf (stderr, "Usage: %s %s bind-address:port\n", outer, argv[0]);
return -1;
}
@ -604,7 +634,7 @@ int server_main (const char* outer, int argc, char* argv[])
if (opt.ind >= argc) goto print_usage;
memset (&server_prim, 0, HCL_SIZEOF(server_prim));
server_prim.log_write = log_write;
server_prim.log_write = server_log_write;
server = hcl_server_open(&sys_mmgr, HCL_SIZEOF(server_xtn_t), &server_prim, HCL_NULL);
if (!server)
@ -619,7 +649,7 @@ int server_main (const char* outer, int argc, char* argv[])
if (logopt)
{
if (handle_logopt(server, logopt) <= -1) goto oops;
if (handle_logopt(xtn, logopt) <= -1) goto oops;
}
else
{
@ -675,30 +705,263 @@ oops:
return -1;
}
/* -------------------------------------------------------------- */
static int client_on_packet (hcl_xproto_t* proto, hcl_xpkt_type_t type, const void* data, hcl_oow_t len)
{
if (type == HCL_XPKT_STDOUT)
{
if (len > 0) fprintf (stdout, "%.*s", (int)len, data);
}
else if (type == HCL_XPKT_STDERR)
{
if (len > 0) fprintf (stderr, "%.*s", (int)len, data);
}
else if (type == HCL_XPKT_ERROR)
{
/* error notification */
if (len > 0) fprintf (stderr, "ERROR: %.*s\n", (int)len, data);
}
return 1;
}
static int client_main (const char* outer, int argc, char* argv[])
{
hcl_bci_t c;
static hcl_bopt_lng_t lopt[] =
{
{ ":log", 'l' },
{ "reuseaddr", '\0' },
{ "shutwr", '\0' },
{ HCL_NULL, '\0' }
};
static hcl_bopt_t opt =
{
"l:",
lopt
};
hcl_client_t* client;
client_xtn_t* xtn;
hcl_client_prim_t client_prim;
int n;
const char* logopt = HCL_NULL;
int reuse_addr = 0;
int shut_wr_after_req = 0;
setlocale (LC_ALL, "");
if (argc < 2)
{
print_usage:
fprintf (stderr, "Usage: %s %s [options] bind-address:port script-to-run\n", outer, argv[0]);
fprintf (stderr, "Options are:\n");
fprintf (stderr, " -l/--log log-options\n");
fprintf (stderr, " --reuseaddr\n");
fprintf (stderr, " --shutwr\n");
return -1;
}
while ((c = hcl_getbopt(argc, argv, &opt)) != HCL_BCI_EOF)
{
switch (c)
{
case 'l':
logopt = opt.arg;
break;
case '\0':
if (hcl_comp_bcstr(opt.lngopt, "reuseaddr") == 0)
{
reuse_addr = 1;
}
else if (hcl_comp_bcstr(opt.lngopt, "shutwr") == 0)
{
shut_wr_after_req = 1;
}
else
{
goto print_usage;
}
break;
case ':':
if (opt.lngopt)
fprintf (stderr, "bad argument for '%s'\n", opt.lngopt);
else
fprintf (stderr, "bad argument for '%c'\n", opt.opt);
return -1;
default:
goto print_usage;
}
}
/* needs 2 fixed arguments */
if (opt.ind + 1 >= argc) goto print_usage;
memset (&client_prim, 0, HCL_SIZEOF(client_prim));
client_prim.log_write = client_log_write;
client_prim.on_packet = client_on_packet;
client = hcl_client_open(&sys_mmgr, HCL_SIZEOF(client_xtn_t), &client_prim, HCL_NULL);
if (!client)
{
fprintf (stderr, "cannot open client\n");
return -1;
}
xtn = (client_xtn_t*)hcl_client_getxtn(client);
xtn->logfd = -1;
xtn->logfd_istty = 0;
if (logopt)
{
if (handle_logopt(xtn, logopt) <= -1) goto oops;
}
else
{
/* default logging mask when no logging option is set */
xtn->logmask = HCL_LOG_ALL_TYPES | HCL_LOG_ERROR | HCL_LOG_FATAL;
}
g_client = client;
set_signal (SIGINT, handle_sigint);
set_signal_to_ignore (SIGPIPE);
n = hcl_client_start(client, argv[opt.ind], argv[opt.ind + 1], reuse_addr, shut_wr_after_req);
if (n <= -1)
{
fprintf (stderr, "ERROR: %s\n", hcl_client_geterrbmsg(client));
goto oops;
}
set_signal_to_default (SIGINT);
set_signal_to_default (SIGPIPE);
g_client = NULL;
if (xtn->logfd >= 0)
{
close (xtn->logfd);
xtn->logfd = -1;
xtn->logfd_istty = 0;
}
hcl_client_close (client);
return n;
oops:
if (client) hcl_client_close (client);
return -1;
}
/* -------------------------------------------------------------- */
static int json_inst_cb (hcl_json_t* json, hcl_json_inst_t it, const hcl_oocs_t* str)
{
json_xtn_t* json_xtn = (json_xtn_t*)hcl_json_getxtn(json);
switch (it)
{
case HCL_JSON_INST_START_ARRAY:
json_xtn->json_depth++;
hcl_json_logbfmt (json, HCL_LOG_INFO | HCL_LOG_APP, "[\n");
break;
case HCL_JSON_INST_END_ARRAY:
json_xtn->json_depth--;
hcl_json_logbfmt (json, HCL_LOG_INFO | HCL_LOG_APP, "]\n");
break;
case HCL_JSON_INST_START_DIC:
json_xtn->json_depth++;
hcl_json_logbfmt (json, HCL_LOG_INFO | HCL_LOG_APP, "{\n");
break;
case HCL_JSON_INST_END_DIC:
json_xtn->json_depth--;
hcl_json_logbfmt (json, HCL_LOG_INFO | HCL_LOG_APP, "}\n");
break;
case HCL_JSON_INST_KEY:
hcl_json_logbfmt (json, HCL_LOG_INFO | HCL_LOG_APP, "%.*js: ", str->len, str->ptr);
break;
case HCL_JSON_INST_CHARACTER:
case HCL_JSON_INST_STRING:
case HCL_JSON_INST_NUMBER:
case HCL_JSON_INST_TRUE:
case HCL_JSON_INST_FALSE:
case HCL_JSON_INST_NIL:
hcl_json_logbfmt (json, HCL_LOG_INFO | HCL_LOG_APP, "%.*js\n", str->len, str->ptr);
break;
}
return 0;
}
int json_main (const char* outer, int argc, char* argv[])
{
hcl_json_t* json;
hcl_json_prim_t json_prim;
json_xtn_t* json_xtn;
hcl_oow_t xlen;
const char* p;
/* TODO: enhance this to accept parameters from command line */
memset (&json_prim, 0, HCL_SIZEOF(json_prim));
json_prim.log_write = json_log_write;
json_prim.instcb = json_inst_cb;
json = hcl_json_open (&sys_mmgr, HCL_SIZEOF(json_xtn_t), &json_prim, NULL);
json_xtn = (json_xtn_t*)hcl_json_getxtn(json);
json_xtn->logmask = HCL_LOG_ALL_LEVELS | HCL_LOG_ALL_TYPES;
p = "[ \"ab\\xab\\uC88B\\uC544\\uC6A9c\", \"kaden\", \"iron\", true, { \"null\": \"a\\1bc\", \"123\": \"AA20AA\", \"10\": -0.123, \"way\": '\\uC88A' } ]";
/*p = "{ \"result\": \"SUCCESS\", \"message\": \"1 clients\", \"sessions\": [] }";*/
if (hcl_json_feed(json, p, strlen(p), &xlen) <= -1)
{
hcl_json_logbfmt (json, HCL_LOG_FATAL | HCL_LOG_APP, "ERROR: unable to process - %js\n", hcl_json_geterrmsg(json));
}
else if (json_xtn->json_depth != 0)
{
hcl_json_logbfmt (json, HCL_LOG_FATAL | HCL_LOG_APP, "ERROR: incomplete input\n");
}
hcl_json_close (json);
return 0;
}
/* -------------------------------------------------------------- */
static void print_main_usage (const char* argv0)
{
fprintf (stderr, "USAGE: %s server|client\n");
fprintf (stderr, "Usage: %s server|client|json\n", argv0);
}
int main (int argc, char* argv[])
{
int n;
const char* argv0;
argv0 = hcl_get_base_name_from_bcstr_path(argv[0]);
if (argc < 2)
{
print_main_usage (argv[0]);
print_main_usage (argv0);
n = -1;
}
else if (strcmp(argv[1], "server") == 0)
{
n = server_main(argv[0], argc -1, &argv[1]);
n = server_main(argv0, argc -1, &argv[1]);
}
else if (strcmp(argv[1], "client") == 0)
{
n = client_main(argv[0], argc -1, &argv[1]);
}
else if (strcmp(argv[1], "json") == 0)
{
n = json_main(argv[0], argc -1, &argv[1]);
}
else
{
print_main_usage (argv[0]);

View File

@ -1,601 +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-x.h"
#include "hcl-opt.h"
#include "hcl-utl.h"
#include "hcl-xutl.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <locale.h>
#if defined(HAVE_TIME_H)
# include <time.h>
#endif
#if defined(HAVE_SYS_TIME_H)
# include <sys/time.h>
#endif
#if defined(HAVE_SIGNAL_H)
# include <signal.h>
#endif
#if defined(HAVE_SYS_UIO_H)
# include <sys/uio.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
/* ========================================================================= */
typedef struct client_xtn_t client_xtn_t;
struct client_xtn_t
{
int logfd;
hcl_bitmask_t logmask;
int logfd_istty;
struct
{
hcl_bch_t buf[4096];
hcl_oow_t len;
} logbuf;
};
/* ========================================================================= */
static void* sys_alloc (hcl_mmgr_t* mmgr, hcl_oow_t size)
{
return malloc(size);
}
static void* sys_realloc (hcl_mmgr_t* mmgr, void* ptr, hcl_oow_t size)
{
return realloc(ptr, size);
}
static void sys_free (hcl_mmgr_t* mmgr, void* ptr)
{
free (ptr);
}
static hcl_mmgr_t sys_mmgr =
{
sys_alloc,
sys_realloc,
sys_free,
HCL_NULL
};
/* ========================================================================= */
static int write_all (int fd, const hcl_bch_t* ptr, hcl_oow_t len)
{
while (len > 0)
{
hcl_ooi_t wr;
wr = write(fd, ptr, len);
if (wr <= -1)
{
#if defined(EAGAIN) && defined(EWOULDBLOCK) && (EAGAIN == EWOULDBLOCK)
if (errno == EAGAIN) continue;
#else
#if defined(EAGAIN)
if (errno == EAGAIN) continue;
#elif defined(EWOULDBLOCK)
if (errno == EWOULDBLOCK) continue;
#endif
#endif
#if defined(EINTR)
/* TODO: would this interfere with non-blocking nature of this VM? */
if (errno == EINTR) continue;
#endif
return -1;
}
ptr += wr;
len -= wr;
}
return 0;
}
static int write_log (hcl_client_t* client, int fd, const hcl_bch_t* ptr, hcl_oow_t len)
{
client_xtn_t* xtn;
xtn = hcl_client_getxtn(client);
while (len > 0)
{
if (xtn->logbuf.len > 0)
{
hcl_oow_t rcapa, cplen;
rcapa = HCL_COUNTOF(xtn->logbuf.buf) - xtn->logbuf.len;
cplen = (len >= rcapa)? rcapa: len;
memcpy (&xtn->logbuf.buf[xtn->logbuf.len], ptr, cplen);
xtn->logbuf.len += cplen;
ptr += cplen;
len -= cplen;
if (xtn->logbuf.len >= HCL_COUNTOF(xtn->logbuf.buf))
{
write_all(fd, xtn->logbuf.buf, xtn->logbuf.len);
xtn->logbuf.len = 0;
}
}
else
{
hcl_oow_t rcapa;
rcapa = HCL_COUNTOF(xtn->logbuf.buf);
if (len >= rcapa)
{
write_all (fd, ptr, rcapa);
ptr += rcapa;
len -= rcapa;
}
else
{
memcpy (xtn->logbuf.buf, ptr, len);
xtn->logbuf.len += len;
ptr += len;
len -= len;
}
}
}
return 0;
}
static void flush_log (hcl_client_t* client, int fd)
{
client_xtn_t* xtn;
xtn = hcl_client_getxtn(client);
if (xtn->logbuf.len > 0)
{
write_all (fd, xtn->logbuf.buf, xtn->logbuf.len);
xtn->logbuf.len = 0;
}
}
static void log_write (hcl_client_t* client, hcl_bitmask_t mask, const hcl_ooch_t* msg, hcl_oow_t len)
{
hcl_bch_t buf[256];
hcl_oow_t ucslen, bcslen;
client_xtn_t* xtn;
hcl_oow_t msgidx;
int n, logfd;
xtn = hcl_client_getxtn(client);
if (mask & HCL_LOG_STDERR)
{
/* the messages that go to STDERR don't get masked out */
logfd = 2;
}
else
{
if (!(xtn->logmask & mask & ~HCL_LOG_ALL_LEVELS)) return; /* check log types */
if (!(xtn->logmask & mask & ~HCL_LOG_ALL_TYPES)) return; /* check log levels */
if (mask & HCL_LOG_STDOUT) logfd = 1;
else
{
logfd = xtn->logfd;
if (logfd <= -1) return;
}
}
/* TODO: beautify the log message.
* do classification based on mask. */
if (!(mask & (HCL_LOG_STDOUT | HCL_LOG_STDERR)))
{
time_t now;
char ts[32];
size_t tslen;
struct tm tm, *tmp;
now = time(NULL);
#if defined(__OS2__)
tmp = _localtime(&now, &tm);
#elif defined(HAVE_LOCALTIME_R)
tmp = localtime_r(&now, &tm);
#else
tmp = localtime(&now);
#endif
#if defined(HAVE_STRFTIME_SMALL_Z)
tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %z ", tmp);
#else
tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %Z ", tmp);
#endif
if (tslen == 0)
{
strcpy (ts, "0000-00-00 00:00:00 +0000");
tslen = 25;
}
write_log (client, logfd, ts, tslen);
}
if (logfd == xtn->logfd && xtn->logfd_istty)
{
if (mask & HCL_LOG_FATAL) write_log (client, logfd, "\x1B[1;31m", 7);
else if (mask & HCL_LOG_ERROR) write_log (client, logfd, "\x1B[1;32m", 7);
else if (mask & HCL_LOG_WARN) write_log (client, logfd, "\x1B[1;33m", 7);
}
#if defined(HCL_OOCH_IS_UCH)
msgidx = 0;
while (len > 0)
{
ucslen = len;
bcslen = HCL_COUNTOF(buf);
n = hcl_conv_oochars_to_bchars_with_cmgr(&msg[msgidx], &ucslen, buf, &bcslen, hcl_get_utf8_cmgr());
if (n == 0 || n == -2)
{
/* n = 0:
* converted all successfully
* n == -2:
* buffer not sufficient. not all got converted yet.
* write what have been converted this round. */
/*HCL_ASSERT (hcl, ucslen > 0); */ /* if this fails, the buffer size must be increased */
/*assert (ucslen > 0);*/
/* attempt to write all converted characters */
if (write_log(client, logfd, buf, bcslen) <= -1) break;
if (n == 0) break;
else
{
msgidx += ucslen;
len -= ucslen;
}
}
else if (n <= -1)
{
/* conversion error */
if (bcslen <= 0) break;
if (write_log(client, logfd, buf, bcslen) <= -1) break;
msgidx += ucslen;
len -= ucslen;
}
}
#else
write_log (client, logfd, msg, len);
#endif
if (logfd == xtn->logfd && xtn->logfd_istty)
{
if (mask & (HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN)) write_log (client, logfd, "\x1B[0m", 4);
}
flush_log (client, logfd);
}
/* ========================================================================= */
static hcl_client_t* g_client = HCL_NULL;
/* ========================================================================= */
typedef void (*signal_handler_t) (int, siginfo_t*, void*);
static void handle_sigint (int sig, siginfo_t* siginfo, void* ctx)
{
/*if (g_client) hcl_client_stop (g_client);*/
}
static void set_signal (int sig, signal_handler_t handler)
{
struct sigaction sa;
memset (&sa, 0, sizeof(sa));
/*sa.sa_handler = handler;*/
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = handler;
sigemptyset (&sa.sa_mask);
sigaction (sig, &sa, NULL);
}
static void set_signal_to_ignore (int sig)
{
struct sigaction sa;
memset (&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
sa.sa_flags = 0;
sigemptyset (&sa.sa_mask);
sigaction (sig, &sa, NULL);
}
static void set_signal_to_default (int sig)
{
struct sigaction sa;
memset (&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
sa.sa_flags = 0;
sigemptyset (&sa.sa_mask);
sigaction (sig, &sa, NULL);
}
/* ========================================================================= */
static int handle_logopt (hcl_client_t* client, const hcl_bch_t* str)
{
hcl_bch_t* xstr = (hcl_bch_t*)str;
hcl_bch_t* cm, * flt;
hcl_bitmask_t logmask;
client_xtn_t* xtn;
xtn = (client_xtn_t*)hcl_client_getxtn(client);
cm = hcl_find_bchar_in_bcstr(xstr, ',');
if (cm)
{
/* i duplicate this string for open() below as open() doesn't
* accept a length-bounded string */
xstr = strdup(str);
if (!xstr)
{
fprintf (stderr, "ERROR: out of memory in duplicating %s\n", str);
return -1;
}
cm = hcl_find_bchar_in_bcstr(xstr, ',');
*cm = '\0';
logmask = xtn->logmask;
do
{
flt = cm + 1;
cm = hcl_find_bchar_in_bcstr(flt, ',');
if (cm) *cm = '\0';
if (hcl_comp_bcstr(flt, "app") == 0) logmask |= HCL_LOG_APP;
else if (hcl_comp_bcstr(flt, "compiler") == 0) logmask |= HCL_LOG_COMPILER;
else if (hcl_comp_bcstr(flt, "vm") == 0) logmask |= HCL_LOG_VM;
else if (hcl_comp_bcstr(flt, "mnemonic") == 0) logmask |= HCL_LOG_MNEMONIC;
else if (hcl_comp_bcstr(flt, "gc") == 0) logmask |= HCL_LOG_GC;
else if (hcl_comp_bcstr(flt, "ic") == 0) logmask |= HCL_LOG_IC;
else if (hcl_comp_bcstr(flt, "primitive") == 0) logmask |= HCL_LOG_PRIMITIVE;
else if (hcl_comp_bcstr(flt, "fatal") == 0) logmask |= HCL_LOG_FATAL;
else if (hcl_comp_bcstr(flt, "error") == 0) logmask |= HCL_LOG_ERROR;
else if (hcl_comp_bcstr(flt, "warn") == 0) logmask |= HCL_LOG_WARN;
else if (hcl_comp_bcstr(flt, "info") == 0) logmask |= HCL_LOG_INFO;
else if (hcl_comp_bcstr(flt, "debug") == 0) logmask |= HCL_LOG_DEBUG;
else if (hcl_comp_bcstr(flt, "fatal+") == 0) logmask |= HCL_LOG_FATAL;
else if (hcl_comp_bcstr(flt, "error+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR;
else if (hcl_comp_bcstr(flt, "warn+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN;
else if (hcl_comp_bcstr(flt, "info+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO;
else if (hcl_comp_bcstr(flt, "debug+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO | HCL_LOG_DEBUG;
else
{
fprintf (stderr, "ERROR: unknown log option value - %s\n", flt);
if (str != xstr) free (xstr);
return -1;
}
}
while (cm);
if (!(logmask & HCL_LOG_ALL_TYPES)) logmask |= HCL_LOG_ALL_TYPES; /* no types specified. force to all types */
if (!(logmask & HCL_LOG_ALL_LEVELS)) logmask |= HCL_LOG_ALL_LEVELS; /* no levels specified. force to all levels */
}
else
{
logmask = HCL_LOG_ALL_LEVELS | HCL_LOG_ALL_TYPES;
}
xtn->logfd = open(xstr, O_CREAT | O_WRONLY | O_APPEND , 0644);
if (xtn->logfd == -1)
{
fprintf (stderr, "ERROR: cannot open a log file %s\n", xstr);
if (str != xstr) free (xstr);
return -1;
}
xtn->logmask = logmask;
#if defined(HAVE_ISATTY)
xtn->logfd_istty = isatty(xtn->logfd);
#endif
if (str != xstr) free (xstr);
return 0;
}
/* ========================================================================= */
static int client_on_packet (hcl_xproto_t* proto, hcl_xpkt_type_t type, const void* data, hcl_oow_t len)
{
if (type == HCL_XPKT_STDOUT)
{
/*if (len > 0) fwrite (data, 1, len, stdout); */
if (len > 0) fprintf (stdout, "%.*s", (int)len, data);
}
else if (type == HCL_XPKT_STDERR)
{
if (len > 0) fprintf (stderr, "%.*s", (int)len, data);
}
else if (type == HCL_XPKT_ERROR)
{
/* error notification */
if (len > 0) fprintf (stderr, "ERROR: %.*s\n", (int)len, data);
}
return 1;
}
/* ========================================================================= */
int main (int argc, char* argv[])
{
hcl_bci_t c;
static hcl_bopt_lng_t lopt[] =
{
{ ":log", 'l' },
{ "reuseaddr", '\0' },
{ "shutwr", '\0' },
{ HCL_NULL, '\0' }
};
static hcl_bopt_t opt =
{
"l:",
lopt
};
hcl_client_t* client;
client_xtn_t* xtn;
hcl_client_prim_t client_prim;
int n;
const char* logopt = HCL_NULL;
int reuse_addr = 0;
int shut_wr_after_req = 0;
setlocale (LC_ALL, "");
if (argc < 2)
{
print_usage:
fprintf (stderr, "Usage: %s [-l/--log log-options] [--reuseaddr] [--shutwr] bind-address:port script-to-run\n", argv[0]);
return -1;
}
while ((c = hcl_getbopt (argc, argv, &opt)) != HCL_BCI_EOF)
{
switch (c)
{
case 'l':
logopt = opt.arg;
break;
case '\0':
if (hcl_comp_bcstr(opt.lngopt, "reuseaddr") == 0)
{
reuse_addr = 1;
}
else if (hcl_comp_bcstr(opt.lngopt, "shutwr") == 0)
{
shut_wr_after_req = 1;
}
else
{
goto print_usage;
}
break;
case ':':
if (opt.lngopt)
fprintf (stderr, "bad argument for '%s'\n", opt.lngopt);
else
fprintf (stderr, "bad argument for '%c'\n", opt.opt);
return -1;
default:
goto print_usage;
}
}
/* needs 2 fixed arguments */
if (opt.ind + 1 >= argc) goto print_usage;
memset (&client_prim, 0, HCL_SIZEOF(client_prim));
client_prim.log_write = log_write;
client_prim.on_packet = client_on_packet;
client = hcl_client_open(&sys_mmgr, HCL_SIZEOF(client_xtn_t), &client_prim, HCL_NULL);
if (!client)
{
fprintf (stderr, "cannot open client\n");
return -1;
}
xtn = (client_xtn_t*)hcl_client_getxtn(client);
xtn->logfd = -1;
xtn->logfd_istty = 0;
if (logopt)
{
if (handle_logopt(client, logopt) <= -1) goto oops;
}
else
{
/* default logging mask when no logging option is set */
xtn->logmask = HCL_LOG_ALL_TYPES | HCL_LOG_ERROR | HCL_LOG_FATAL;
}
g_client = client;
set_signal (SIGINT, handle_sigint);
set_signal_to_ignore (SIGPIPE);
n = hcl_client_start(client, argv[opt.ind], argv[opt.ind + 1], reuse_addr, shut_wr_after_req);
if (n <= -1)
{
fprintf (stderr, "ERROR: %s\n", hcl_client_geterrbmsg(client));
goto oops;
}
set_signal_to_default (SIGINT);
set_signal_to_default (SIGPIPE);
g_client = NULL;
if (xtn->logfd >= 0)
{
close (xtn->logfd);
xtn->logfd = -1;
xtn->logfd_istty = 0;
}
hcl_client_close (client);
return n;
oops:
if (client) hcl_client_close (client);
return -1;
}

View File

@ -1,337 +0,0 @@
#include <hcl-json.h>
#include <hcl-utl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
/* ========================================================================= */
typedef struct json_xtn_t json_xtn_t;
struct json_xtn_t
{
int logfd;
hcl_bitmask_t logmask;
int logfd_istty;
struct
{
hcl_bch_t buf[4096];
hcl_oow_t len;
} logbuf;
int depth;
};
/* ========================================================================= */
static void* sys_alloc (hcl_mmgr_t* mmgr, hcl_oow_t size)
{
return malloc(size);
}
static void* sys_realloc (hcl_mmgr_t* mmgr, void* ptr, hcl_oow_t size)
{
return realloc(ptr, size);
}
static void sys_free (hcl_mmgr_t* mmgr, void* ptr)
{
free (ptr);
}
static hcl_mmgr_t sys_mmgr =
{
sys_alloc,
sys_realloc,
sys_free,
HCL_NULL
};
/* ========================================================================= */
static int write_all (int fd, const hcl_bch_t* ptr, hcl_oow_t len)
{
while (len > 0)
{
hcl_ooi_t wr;
wr = write(fd, ptr, len);
if (wr <= -1)
{
#if defined(EAGAIN) && defined(EWOULDBLOCK) && (EAGAIN == EWOULDBLOCK)
if (errno == EAGAIN) continue;
#else
#if defined(EAGAIN)
if (errno == EAGAIN) continue;
#elif defined(EWOULDBLOCK)
if (errno == EWOULDBLOCK) continue;
#endif
#endif
#if defined(EINTR)
/* TODO: would this interfere with non-blocking nature of this VM? */
if (errno == EINTR) continue;
#endif
return -1;
}
ptr += wr;
len -= wr;
}
return 0;
}
static int write_log (hcl_json_t* json, int fd, const hcl_bch_t* ptr, hcl_oow_t len)
{
json_xtn_t* xtn = (json_xtn_t*)hcl_json_getxtn(json);
while (len > 0)
{
if (xtn->logbuf.len > 0)
{
hcl_oow_t rcapa, cplen;
rcapa = HCL_COUNTOF(xtn->logbuf.buf) - xtn->logbuf.len;
cplen = (len >= rcapa)? rcapa: len;
memcpy (&xtn->logbuf.buf[xtn->logbuf.len], ptr, cplen);
xtn->logbuf.len += cplen;
ptr += cplen;
len -= cplen;
if (xtn->logbuf.len >= HCL_COUNTOF(xtn->logbuf.buf))
{
write_all(fd, xtn->logbuf.buf, xtn->logbuf.len);
xtn->logbuf.len = 0;
}
}
else
{
hcl_oow_t rcapa;
rcapa = HCL_COUNTOF(xtn->logbuf.buf);
if (len >= rcapa)
{
write_all (fd, ptr, rcapa);
ptr += rcapa;
len -= rcapa;
}
else
{
memcpy (xtn->logbuf.buf, ptr, len);
xtn->logbuf.len += len;
ptr += len;
len -= len;
}
}
}
return 0;
}
static void flush_log (hcl_json_t* json, int fd)
{
json_xtn_t* xtn = (json_xtn_t*)hcl_json_getxtn(json);
if (xtn->logbuf.len > 0)
{
write_all (fd, xtn->logbuf.buf, xtn->logbuf.len);
xtn->logbuf.len = 0;
}
}
static void log_write (hcl_json_t* json, hcl_bitmask_t mask, const hcl_ooch_t* msg, hcl_oow_t len)
{
json_xtn_t* xtn = (json_xtn_t*)hcl_json_getxtn(json);
hcl_bch_t buf[256];
hcl_oow_t ucslen, bcslen;
hcl_oow_t msgidx;
int n, logfd;
if (mask & HCL_LOG_STDERR)
{
/* the messages that go to STDERR don't get masked out */
logfd = 2;
}
else
{
if (!(xtn->logmask & mask & ~HCL_LOG_ALL_LEVELS)) return; /* check log types */
if (!(xtn->logmask & mask & ~HCL_LOG_ALL_TYPES)) return; /* check log levels */
if (mask & HCL_LOG_STDOUT) logfd = 1;
else
{
logfd = xtn->logfd;
if (logfd <= -1) return;
}
}
/* TODO: beautify the log message.
* do classification based on mask. */
if (!(mask & (HCL_LOG_STDOUT | HCL_LOG_STDERR)))
{
time_t now;
char ts[32];
size_t tslen;
struct tm tm, *tmp;
now = time(NULL);
#if defined(__OS2__)
tmp = _localtime(&now, &tm);
#elif defined(HAVE_LOCALTIME_R)
tmp = localtime_r(&now, &tm);
#else
tmp = localtime(&now);
#endif
#if defined(HAVE_STRFTIME_SMALL_Z)
tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %z ", tmp);
#else
tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %Z ", tmp);
#endif
if (tslen == 0)
{
strcpy (ts, "0000-00-00 00:00:00 +0000");
tslen = 25;
}
write_log (json, logfd, ts, tslen);
}
if (logfd == xtn->logfd && xtn->logfd_istty)
{
if (mask & HCL_LOG_FATAL) write_log (json, logfd, "\x1B[1;31m", 7);
else if (mask & HCL_LOG_ERROR) write_log (json, logfd, "\x1B[1;32m", 7);
else if (mask & HCL_LOG_WARN) write_log (json, logfd, "\x1B[1;33m", 7);
}
#if defined(HCL_OOCH_IS_UCH)
msgidx = 0;
while (len > 0)
{
ucslen = len;
bcslen = HCL_COUNTOF(buf);
n = hcl_conv_oochars_to_bchars_with_cmgr(&msg[msgidx], &ucslen, buf, &bcslen, hcl_get_utf8_cmgr());
if (n == 0 || n == -2)
{
/* n = 0:
* converted all successfully
* n == -2:
* buffer not sufficient. not all got converted yet.
* write what have been converted this round. */
/*HCL_ASSERT (hcl, ucslen > 0); */ /* if this fails, the buffer size must be increased */
/*assert (ucslen > 0);*/
/* attempt to write all converted characters */
if (write_log(json, logfd, buf, bcslen) <= -1) break;
if (n == 0) break;
else
{
msgidx += ucslen;
len -= ucslen;
}
}
else if (n <= -1)
{
/* conversion error */
if (bcslen <= 0) break;
if (write_log(json, logfd, buf, bcslen) <= -1) break;
msgidx += ucslen;
len -= ucslen;
}
}
#else
write_log (json, logfd, msg, len);
#endif
if (logfd == xtn->logfd && xtn->logfd_istty)
{
if (mask & (HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN)) write_log (json, logfd, "\x1B[0m", 4);
}
flush_log (json, logfd);
}
static int instcb (hcl_json_t* json, hcl_json_inst_t it, const hcl_oocs_t* str)
{
json_xtn_t* json_xtn = (json_xtn_t*)hcl_json_getxtn(json);
switch (it)
{
case HCL_JSON_INST_START_ARRAY:
json_xtn->depth++;
hcl_json_logbfmt (json, HCL_LOG_INFO | HCL_LOG_APP, "[\n");
break;
case HCL_JSON_INST_END_ARRAY:
json_xtn->depth--;
hcl_json_logbfmt (json, HCL_LOG_INFO | HCL_LOG_APP, "]\n");
break;
case HCL_JSON_INST_START_DIC:
json_xtn->depth++;
hcl_json_logbfmt (json, HCL_LOG_INFO | HCL_LOG_APP, "{\n");
break;
case HCL_JSON_INST_END_DIC:
json_xtn->depth--;
hcl_json_logbfmt (json, HCL_LOG_INFO | HCL_LOG_APP, "}\n");
break;
case HCL_JSON_INST_KEY:
hcl_json_logbfmt (json, HCL_LOG_INFO | HCL_LOG_APP, "%.*js: ", str->len, str->ptr);
break;
case HCL_JSON_INST_CHARACTER:
case HCL_JSON_INST_STRING:
case HCL_JSON_INST_NUMBER:
case HCL_JSON_INST_TRUE:
case HCL_JSON_INST_FALSE:
case HCL_JSON_INST_NIL:
hcl_json_logbfmt (json, HCL_LOG_INFO | HCL_LOG_APP, "%.*js\n", str->len, str->ptr);
break;
}
return 0;
}
/* ========================================================================= */
int main (int argc, char* argv[])
{
hcl_json_t* json;
hcl_json_prim_t json_prim;
json_xtn_t* json_xtn;
hcl_oow_t xlen;
const char* p;
memset (&json_prim, 0, HCL_SIZEOF(json_prim));
json_prim.log_write = log_write;
json_prim.instcb = instcb;
json = hcl_json_open (&sys_mmgr, HCL_SIZEOF(json_xtn_t), &json_prim, NULL);
json_xtn = (json_xtn_t*)hcl_json_getxtn(json);
json_xtn->logmask = HCL_LOG_ALL_LEVELS | HCL_LOG_ALL_TYPES;
p = "[ \"ab\\xab\\uC88B\\uC544\\uC6A9c\", \"kaden\", \"iron\", true, { \"null\": \"a\\1bc\", \"123\": \"AA20AA\", \"10\": -0.123, \"way\": '\\uC88A' } ]";
/*p = "{ \"result\": \"SUCCESS\", \"message\": \"1 clients\", \"sessions\": [] }";*/
if (hcl_json_feed(json, p, strlen(p), &xlen) <= -1)
{
hcl_json_logbfmt (json, HCL_LOG_FATAL | HCL_LOG_APP, "ERROR: unable to process - %js\n", hcl_json_geterrmsg(json));
}
else if (json_xtn->depth != 0)
{
hcl_json_logbfmt (json, HCL_LOG_FATAL | HCL_LOG_APP, "ERROR: incomplete input\n");
}
hcl_json_close (json);
return 0;
}

View File

@ -898,6 +898,12 @@ typedef struct hcl_t hcl_t;
# undef HCL_HAVE_INLINE
#endif
#if __has_attribute(__sentinel__) || (defined(__GNUC__) && (__GNUC__ >= 4))
# define HCL_SENTINEL(v) __attribute__((__sentinel__(x)))
#else
# define HCL_SENTINEL(v)
#endif
#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4))
# define HCL_UNUSED __attribute__((__unused__))
#else
@ -962,22 +968,24 @@ typedef struct hcl_t hcl_t;
/* =========================================================================
* COMPILER FEATURE TEST MACROS
* =========================================================================*/
#if !defined(__has_attribute)
#define __has_attribute(x) 0
#endif
#if !defined(__has_builtin) && defined(_INTELC32_)
/* intel c code builder 1.0 ended up with an error without this override */
#define __has_builtin(x) 0
#endif
/*
#if !defined(__has_feature)
#define __has_feature(x) 0
#endif
#if !defined(__is_identifier)
#define __is_identifier(x) 0
#endif
#if !defined(__has_attribute)
#define __has_attribute(x) 0
#endif
*/
#if defined(__has_builtin)
#if __has_builtin(__builtin_ctz)
#define HCL_HAVE_BUILTIN_CTZ

View File

@ -943,6 +943,24 @@ HCL_EXPORT void hcl_sub_ntime (
const hcl_ntime_t* y
);
/* =========================================================================
* PATH NAME
* ========================================================================= */
const hcl_bch_t* hcl_get_base_name_from_bcstr_path (
const hcl_bch_t* path
);
const hcl_uch_t* hcl_get_base_name_from_ucstr_path (
const hcl_uch_t* path
);
#if defined(HCL_OOCH_IS_UCH)
#define hcl_get_base_name_from_path(x) hcl_get_base_name_from_ucstr_path(x)
#else
#define hcl_get_base_name_from_path(x) hcl_get_base_name_from_bcstr_path(x)
#endif
/* =========================================================================
* BIT SWAP
* ========================================================================= */

View File

@ -323,6 +323,10 @@ HCL_EXPORT int hcl_client_start (
int shut_wr_after_req
);
HCL_EXPORT void hcl_client_stop (
hcl_client_t* client
);
HCL_EXPORT int hcl_client_setoption (
hcl_client_t* client,
hcl_client_option_t id,

View File

@ -3291,18 +3291,6 @@ struct bb_t
hcl_bch_t* fn;
};
static const hcl_bch_t* get_base_name (const hcl_bch_t* path)
{
const hcl_bch_t* p, * last = HCL_NULL;
for (p = path; *p != '\0'; p++)
{
if (HCL_IS_PATH_SEP(*p)) last = p;
}
return (last == HCL_NULL)? path: (last + 1);
}
#if defined(__DOS__) || defined(_WIN32) || defined(__OS2__)
#define FOPEN_R_FLAGS "rb"
#else
@ -3329,7 +3317,7 @@ static HCL_INLINE int open_cci_stream (hcl_t* hcl, hcl_io_cciarg_t* arg)
fn = ((bb_t*)arg->includer->handle)->fn;
fb = get_base_name(fn);
fb = hcl_get_base_name_from_bcstr_path(fn);
parlen = fb - fn;
bb = (bb_t*)hcl_callocmem(hcl, HCL_SIZEOF(*bb) + (HCL_SIZEOF(hcl_bch_t) * (parlen + bcslen + 1)));

View File

@ -1330,3 +1330,28 @@ void hcl_sub_ntime (hcl_ntime_t* z, const hcl_ntime_t* x, const hcl_ntime_t* y)
z->nsec = ns;
}
/* ----------------------------------------------------------------------- */
const hcl_bch_t* hcl_get_base_name_from_bcstr_path (const hcl_bch_t* path)
{
const hcl_bch_t* p, * last = HCL_NULL;
for (p = path; *p != '\0'; p++)
{
if (HCL_IS_PATH_SEP(*p)) last = p;
}
return (last == HCL_NULL)? path: (last + 1);
}
const hcl_uch_t* hcl_get_base_name_from_ucstr_path (const hcl_uch_t* path)
{
const hcl_uch_t* p, * last = HCL_NULL;
for (p = path; *p != '\0'; p++)
{
if (HCL_IS_PATH_SEP(*p)) last = p;
}
return (last == HCL_NULL)? path: (last + 1);
}

View File

@ -636,3 +636,8 @@ oops:
return -1;
}
void hcl_client_stop (hcl_client_t* client)
{
/* TODO: */
/* TODO: break the cleint loop */
}

View File

@ -254,18 +254,6 @@ static int send_stdout_chars (hcl_xproto_t* proto, int xpkt_code, const hcl_ooch
/* ========================================================================= */
static const hcl_bch_t* get_base_name (const hcl_bch_t* path)
{
const hcl_bch_t* p, * last = HCL_NULL;
for (p = path; *p != '\0'; p++)
{
if (HCL_IS_PATH_SEP(*p)) last = p;
}
return (last == HCL_NULL)? path: (last + 1);
}
static HCL_INLINE int open_read_stream (hcl_t* hcl, hcl_io_cciarg_t* arg)
{
worker_hcl_xtn_t* xtn = (worker_hcl_xtn_t*)hcl_getxtn(hcl);
@ -299,7 +287,7 @@ static HCL_INLINE int open_read_stream (hcl_t* hcl, hcl_io_cciarg_t* arg)
}
else
{
fb = get_base_name(fn);
fb = hcl_get_base_name_from_bcstr_path(fn);
parlen = fb - fn;
}