improved the standard console handler to handle when ARGV has been overridden in a script
This commit is contained in:
16
qse/samples/cmn/Makefile.am
Normal file
16
qse/samples/cmn/Makefile.am
Normal file
@ -0,0 +1,16 @@
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
|
||||
bin_PROGRAMS = chr str sll map lda fio pio sio time
|
||||
|
||||
LDFLAGS = -L../../lib/cmn
|
||||
LDADD = -lqsecmn
|
||||
|
||||
chr_SOURCES = chr.c
|
||||
str_SOURCES = str.c
|
||||
sll_SOURCES = sll.c
|
||||
map_SOURCES = map.c
|
||||
lda_SOURCES = lda.c
|
||||
fio_SOURCES = fio.c
|
||||
pio_SOURCES = pio.c
|
||||
sio_SOURCES = sio.c
|
||||
time_SOURCES = time.c
|
570
qse/samples/cmn/Makefile.in
Normal file
570
qse/samples/cmn/Makefile.in
Normal file
@ -0,0 +1,570 @@
|
||||
# Makefile.in generated by automake 1.10.2 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
bin_PROGRAMS = chr$(EXEEXT) str$(EXEEXT) sll$(EXEEXT) map$(EXEEXT) \
|
||||
lda$(EXEEXT) fio$(EXEEXT) pio$(EXEEXT) sio$(EXEEXT) \
|
||||
time$(EXEEXT)
|
||||
subdir = samples/cmn
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/ac/m4/libtool.m4 \
|
||||
$(top_srcdir)/ac/m4/ltoptions.m4 \
|
||||
$(top_srcdir)/ac/m4/ltsugar.m4 \
|
||||
$(top_srcdir)/ac/m4/ltversion.m4 \
|
||||
$(top_srcdir)/ac/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/include/qse/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
am__installdirs = "$(DESTDIR)$(bindir)"
|
||||
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
|
||||
PROGRAMS = $(bin_PROGRAMS)
|
||||
am_chr_OBJECTS = chr.$(OBJEXT)
|
||||
chr_OBJECTS = $(am_chr_OBJECTS)
|
||||
chr_LDADD = $(LDADD)
|
||||
chr_DEPENDENCIES =
|
||||
am_fio_OBJECTS = fio.$(OBJEXT)
|
||||
fio_OBJECTS = $(am_fio_OBJECTS)
|
||||
fio_LDADD = $(LDADD)
|
||||
fio_DEPENDENCIES =
|
||||
am_lda_OBJECTS = lda.$(OBJEXT)
|
||||
lda_OBJECTS = $(am_lda_OBJECTS)
|
||||
lda_LDADD = $(LDADD)
|
||||
lda_DEPENDENCIES =
|
||||
am_map_OBJECTS = map.$(OBJEXT)
|
||||
map_OBJECTS = $(am_map_OBJECTS)
|
||||
map_LDADD = $(LDADD)
|
||||
map_DEPENDENCIES =
|
||||
am_pio_OBJECTS = pio.$(OBJEXT)
|
||||
pio_OBJECTS = $(am_pio_OBJECTS)
|
||||
pio_LDADD = $(LDADD)
|
||||
pio_DEPENDENCIES =
|
||||
am_sio_OBJECTS = sio.$(OBJEXT)
|
||||
sio_OBJECTS = $(am_sio_OBJECTS)
|
||||
sio_LDADD = $(LDADD)
|
||||
sio_DEPENDENCIES =
|
||||
am_sll_OBJECTS = sll.$(OBJEXT)
|
||||
sll_OBJECTS = $(am_sll_OBJECTS)
|
||||
sll_LDADD = $(LDADD)
|
||||
sll_DEPENDENCIES =
|
||||
am_str_OBJECTS = str.$(OBJEXT)
|
||||
str_OBJECTS = $(am_str_OBJECTS)
|
||||
str_LDADD = $(LDADD)
|
||||
str_DEPENDENCIES =
|
||||
am_time_OBJECTS = time.$(OBJEXT)
|
||||
time_OBJECTS = $(am_time_OBJECTS)
|
||||
time_LDADD = $(LDADD)
|
||||
time_DEPENDENCIES =
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include/qse
|
||||
depcomp = $(SHELL) $(top_srcdir)/ac/au/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(chr_SOURCES) $(fio_SOURCES) $(lda_SOURCES) $(map_SOURCES) \
|
||||
$(pio_SOURCES) $(sio_SOURCES) $(sll_SOURCES) $(str_SOURCES) \
|
||||
$(time_SOURCES)
|
||||
DIST_SOURCES = $(chr_SOURCES) $(fio_SOURCES) $(lda_SOURCES) \
|
||||
$(map_SOURCES) $(pio_SOURCES) $(sio_SOURCES) $(sll_SOURCES) \
|
||||
$(str_SOURCES) $(time_SOURCES)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
BUILD_MODE = @BUILD_MODE@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CHAR_MODE = @CHAR_MODE@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CXX = @CXX@
|
||||
CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DSYMUTIL = @DSYMUTIL@
|
||||
DUMPBIN = @DUMPBIN@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
FGREP = @FGREP@
|
||||
GREP = @GREP@
|
||||
HAVE_CXX = @HAVE_CXX@
|
||||
HAVE_OBJC = @HAVE_OBJC@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LD = @LD@
|
||||
LDFLAGS = -L../../lib/cmn
|
||||
LIBM = @LIBM@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LIBTOOL_DEPS = @LIBTOOL_DEPS@
|
||||
LIPO = @LIPO@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
NM = @NM@
|
||||
NMEDIT = @NMEDIT@
|
||||
OBJC = @OBJC@
|
||||
OBJCDEPMODE = @OBJCDEPMODE@
|
||||
OBJCFLAGS = @OBJCFLAGS@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
OTOOL = @OTOOL@
|
||||
OTOOL64 = @OTOOL64@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
QSE_SIZEOF_CHAR = @QSE_SIZEOF_CHAR@
|
||||
QSE_SIZEOF_DOUBLE = @QSE_SIZEOF_DOUBLE@
|
||||
QSE_SIZEOF_FLOAT = @QSE_SIZEOF_FLOAT@
|
||||
QSE_SIZEOF_INT = @QSE_SIZEOF_INT@
|
||||
QSE_SIZEOF_LONG = @QSE_SIZEOF_LONG@
|
||||
QSE_SIZEOF_LONG_DOUBLE = @QSE_SIZEOF_LONG_DOUBLE@
|
||||
QSE_SIZEOF_LONG_LONG = @QSE_SIZEOF_LONG_LONG@
|
||||
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
|
||||
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
|
||||
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
|
||||
RANLIB = @RANLIB@
|
||||
RM = @RM@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
abs_builddir = @abs_builddir@
|
||||
abs_srcdir = @abs_srcdir@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
abs_top_srcdir = @abs_top_srcdir@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
|
||||
ac_ct_OBJC = @ac_ct_OBJC@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
builddir = @builddir@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
lt_ECHO = @lt_ECHO@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
LDADD = -lqsecmn
|
||||
chr_SOURCES = chr.c
|
||||
str_SOURCES = str.c
|
||||
sll_SOURCES = sll.c
|
||||
map_SOURCES = map.c
|
||||
lda_SOURCES = lda.c
|
||||
fio_SOURCES = fio.c
|
||||
pio_SOURCES = pio.c
|
||||
sio_SOURCES = sio.c
|
||||
time_SOURCES = time.c
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .lo .o .obj
|
||||
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
|
||||
&& { if test -f $@; then exit 0; else break; fi; }; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign samples/cmn/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --foreign samples/cmn/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
install-binPROGRAMS: $(bin_PROGRAMS)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
|
||||
@list='$(bin_PROGRAMS)'; for p in $$list; do \
|
||||
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
|
||||
if test -f $$p \
|
||||
|| test -f $$p1 \
|
||||
; then \
|
||||
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
|
||||
echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
|
||||
$(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-binPROGRAMS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(bin_PROGRAMS)'; for p in $$list; do \
|
||||
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
|
||||
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
|
||||
rm -f "$(DESTDIR)$(bindir)/$$f"; \
|
||||
done
|
||||
|
||||
clean-binPROGRAMS:
|
||||
@list='$(bin_PROGRAMS)'; for p in $$list; do \
|
||||
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
|
||||
echo " rm -f $$p $$f"; \
|
||||
rm -f $$p $$f ; \
|
||||
done
|
||||
chr$(EXEEXT): $(chr_OBJECTS) $(chr_DEPENDENCIES)
|
||||
@rm -f chr$(EXEEXT)
|
||||
$(LINK) $(chr_OBJECTS) $(chr_LDADD) $(LIBS)
|
||||
fio$(EXEEXT): $(fio_OBJECTS) $(fio_DEPENDENCIES)
|
||||
@rm -f fio$(EXEEXT)
|
||||
$(LINK) $(fio_OBJECTS) $(fio_LDADD) $(LIBS)
|
||||
lda$(EXEEXT): $(lda_OBJECTS) $(lda_DEPENDENCIES)
|
||||
@rm -f lda$(EXEEXT)
|
||||
$(LINK) $(lda_OBJECTS) $(lda_LDADD) $(LIBS)
|
||||
map$(EXEEXT): $(map_OBJECTS) $(map_DEPENDENCIES)
|
||||
@rm -f map$(EXEEXT)
|
||||
$(LINK) $(map_OBJECTS) $(map_LDADD) $(LIBS)
|
||||
pio$(EXEEXT): $(pio_OBJECTS) $(pio_DEPENDENCIES)
|
||||
@rm -f pio$(EXEEXT)
|
||||
$(LINK) $(pio_OBJECTS) $(pio_LDADD) $(LIBS)
|
||||
sio$(EXEEXT): $(sio_OBJECTS) $(sio_DEPENDENCIES)
|
||||
@rm -f sio$(EXEEXT)
|
||||
$(LINK) $(sio_OBJECTS) $(sio_LDADD) $(LIBS)
|
||||
sll$(EXEEXT): $(sll_OBJECTS) $(sll_DEPENDENCIES)
|
||||
@rm -f sll$(EXEEXT)
|
||||
$(LINK) $(sll_OBJECTS) $(sll_LDADD) $(LIBS)
|
||||
str$(EXEEXT): $(str_OBJECTS) $(str_DEPENDENCIES)
|
||||
@rm -f str$(EXEEXT)
|
||||
$(LINK) $(str_OBJECTS) $(str_LDADD) $(LIBS)
|
||||
time$(EXEEXT): $(time_OBJECTS) $(time_DEPENDENCIES)
|
||||
@rm -f time$(EXEEXT)
|
||||
$(LINK) $(time_OBJECTS) $(time_LDADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chr.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fio.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lda.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/map.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sio.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sll.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Po@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
|
||||
|
||||
.c.obj:
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
|
||||
|
||||
.c.lo:
|
||||
@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$tags $$unique; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$tags $$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& cd $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) $$here
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
list='$(DISTFILES)'; \
|
||||
dist_files=`for file in $$list; do echo $$file; done | \
|
||||
sed -e "s|^$$srcdirstrip/||;t" \
|
||||
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
|
||||
case $$dist_files in \
|
||||
*/*) $(MKDIR_P) `echo "$$dist_files" | \
|
||||
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
|
||||
sort -u` ;; \
|
||||
esac; \
|
||||
for file in $$dist_files; do \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
|
||||
fi; \
|
||||
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: Makefile $(PROGRAMS)
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(bindir)"; do \
|
||||
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
|
||||
done
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am:
|
||||
|
||||
install-dvi: install-dvi-am
|
||||
|
||||
install-exec-am: install-binPROGRAMS
|
||||
|
||||
install-html: install-html-am
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-man:
|
||||
|
||||
install-pdf: install-pdf-am
|
||||
|
||||
install-ps: install-ps-am
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
|
||||
mostlyclean-libtool
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-binPROGRAMS
|
||||
|
||||
.MAKE: install-am install-strip
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
|
||||
clean-generic clean-libtool ctags distclean distclean-compile \
|
||||
distclean-generic distclean-libtool distclean-tags distdir dvi \
|
||||
dvi-am html html-am info info-am install install-am \
|
||||
install-binPROGRAMS install-data install-data-am install-dvi \
|
||||
install-dvi-am install-exec install-exec-am install-html \
|
||||
install-html-am install-info install-info-am install-man \
|
||||
install-pdf install-pdf-am install-ps install-ps-am \
|
||||
install-strip installcheck installcheck-am installdirs \
|
||||
maintainer-clean maintainer-clean-generic mostlyclean \
|
||||
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
|
||||
pdf pdf-am ps ps-am tags uninstall uninstall-am \
|
||||
uninstall-binPROGRAMS
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
155
qse/samples/cmn/chr.c
Normal file
155
qse/samples/cmn/chr.c
Normal file
@ -0,0 +1,155 @@
|
||||
#include <qse/cmn/mem.h>
|
||||
#include <qse/cmn/chr.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/map.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
||||
if (f() == -1) return -1; \
|
||||
} while (0)
|
||||
|
||||
static int test1 (void)
|
||||
{
|
||||
qse_char_t c;
|
||||
|
||||
for (c = QSE_T('a'); c <= QSE_T('z'); c++)
|
||||
{
|
||||
qse_printf (QSE_T("%c => %c\n"), c, QSE_TOUPPER(c));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test2 (void)
|
||||
{
|
||||
int i;
|
||||
const qse_mchar_t* x[] =
|
||||
{
|
||||
"\0",
|
||||
"뛰어 올라봐",
|
||||
"Fly to the universe"
|
||||
};
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_size_t k = strlen(x[i]);
|
||||
qse_size_t j = 0;
|
||||
qse_wchar_t wc;
|
||||
|
||||
if (k == 0) k++; /* for x[0] */
|
||||
|
||||
qse_printf (QSE_T("["));
|
||||
while (j < k)
|
||||
{
|
||||
qse_size_t y = qse_mblen (&x[i][j], k-j);
|
||||
|
||||
if (y == 0)
|
||||
{
|
||||
qse_printf (QSE_T("***illegal sequence***"));
|
||||
break;
|
||||
}
|
||||
else if (y > k-j)
|
||||
{
|
||||
qse_printf (QSE_T("***incomplete sequence***"));
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_size_t y2 = qse_mbtowc (&x[i][j], y, &wc);
|
||||
if (y2 != y)
|
||||
{
|
||||
qse_printf (QSE_T("***y(%d) != y2(%d). something is wrong*** "), (int)y, (int)y2);
|
||||
break;
|
||||
}
|
||||
|
||||
if (wc == L'\0')
|
||||
{
|
||||
qse_printf (QSE_T("'\\0'"));
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("%C"), wc);
|
||||
#else
|
||||
qse_printf (QSE_T("%c"), wc);
|
||||
#endif
|
||||
}
|
||||
j += y;
|
||||
}
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("] => %d bytes\n"), (int)k);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test3 (void)
|
||||
{
|
||||
const qse_wchar_t* x[] =
|
||||
{
|
||||
L"\0",
|
||||
L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",
|
||||
L"Fly to the universe"
|
||||
};
|
||||
char buf[100];
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
int len = wcslen (x[i]);
|
||||
if (len == 0) len++; /* for x[0] */
|
||||
|
||||
qse_printf (QSE_T("["));
|
||||
for (j = 0; j < len; j++)
|
||||
{
|
||||
qse_size_t n = qse_wctomb (x[i][j], buf, sizeof(buf));
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
qse_printf (QSE_T("***illegal character***"));
|
||||
}
|
||||
else if (n > sizeof(buf))
|
||||
{
|
||||
qse_printf (QSE_T("***buffer too small***"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (n == 1 && buf[0] == '\0')
|
||||
{
|
||||
qse_printf (QSE_T("'\\0'"));
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("%.*s"), (int)n, buf);
|
||||
#else
|
||||
qse_printf (QSE_T("%.*S"), (int)n, buf);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
qse_printf (QSE_T("] => %d chars\n"), (int)len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
qse_printf (QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n"));
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
|
||||
R (test1);
|
||||
R (test2);
|
||||
R (test3);
|
||||
|
||||
return 0;
|
||||
}
|
263
qse/samples/cmn/fio.c
Normal file
263
qse/samples/cmn/fio.c
Normal file
@ -0,0 +1,263 @@
|
||||
#include <qse/cmn/fio.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
||||
if (f() == -1) return -1; \
|
||||
} while (0)
|
||||
|
||||
static int test1 (void)
|
||||
{
|
||||
qse_fio_t* fio;
|
||||
qse_ssize_t n;
|
||||
char x[] = "fio test";
|
||||
char x2[] = "fio test2";
|
||||
qse_fio_off_t off;
|
||||
char buf[1000];
|
||||
|
||||
fio = qse_fio_open (
|
||||
QSE_NULL,
|
||||
0,
|
||||
QSE_T("fio1.txt"),
|
||||
QSE_FIO_READ|QSE_FIO_WRITE|QSE_FIO_CREATE|QSE_FIO_TRUNCATE,
|
||||
QSE_FIO_RUSR|QSE_FIO_WUSR|QSE_FIO_RGRP|QSE_FIO_ROTH
|
||||
);
|
||||
if (fio == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open file\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
n = qse_fio_write (fio, x, strlen(x));
|
||||
qse_printf (QSE_T("written %d bytes\n"), (int)n);
|
||||
|
||||
|
||||
off = qse_fio_seek (fio, 0, QSE_FIO_CURRENT);
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("failed to get file offset\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("file offset at %lld\n"), (long long)off);
|
||||
}
|
||||
|
||||
off = qse_fio_seek (fio, 0, QSE_FIO_BEGIN);
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("failed to set file offset\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("moved file offset to %lld\n"), (long long)off);
|
||||
}
|
||||
|
||||
n = qse_fio_read (fio, buf, sizeof(buf));
|
||||
qse_printf (QSE_T("read %d bytes \n"), (int)n);
|
||||
if (n > 0)
|
||||
{
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("buf => [%.*s]\n"), (int)n, buf);
|
||||
#else
|
||||
qse_printf (QSE_T("buf => [%.*S]\n"), (int)n, buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
off = qse_fio_seek (fio, QSE_TYPE_MAX(int) * 3llu, QSE_FIO_BEGIN);
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("failed to set file offset\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("moved file offset to %lld\n"), (long long)off);
|
||||
}
|
||||
|
||||
n = qse_fio_write (fio, x2, strlen(x2));
|
||||
qse_printf (QSE_T("written %d bytes\n"), (int)n);
|
||||
|
||||
qse_fio_close (fio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test2 (void)
|
||||
{
|
||||
qse_fio_t* fio;
|
||||
qse_ssize_t n;
|
||||
char x[] = "fio test";
|
||||
char x2[] = "fio test2";
|
||||
qse_fio_off_t off;
|
||||
char buf[1000];
|
||||
int i;
|
||||
|
||||
fio = qse_fio_open (
|
||||
QSE_NULL,
|
||||
0,
|
||||
QSE_T("fio2.txt"),
|
||||
QSE_FIO_CREATE | QSE_FIO_TRUNCATE | QSE_FIO_APPEND,
|
||||
QSE_FIO_RUSR|QSE_FIO_WUSR|QSE_FIO_RGRP|QSE_FIO_ROTH
|
||||
);
|
||||
if (fio == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open file\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
n = qse_fio_write (fio, x, strlen(x));
|
||||
qse_printf (QSE_T("written %d bytes\n"), (int)n);
|
||||
|
||||
off = qse_fio_seek (fio, 0, QSE_FIO_CURRENT);
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("failed to get file offset\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("file offset at %lld\n"), (long long)off);
|
||||
}
|
||||
|
||||
off = qse_fio_seek (fio, 0, QSE_FIO_BEGIN);
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("failed to set file offset\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("moved file offset to %lld\n"), (long long)off);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
n = qse_fio_read (fio, buf, sizeof(buf));
|
||||
qse_printf (QSE_T("read %d bytes \n"), (int)n);
|
||||
if (n > 0)
|
||||
{
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("buf => [%.*s]\n"), (int)n, buf);
|
||||
#else
|
||||
qse_printf (QSE_T("buf => [%.*S]\n"), (int)n, buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
off = qse_fio_seek (fio, QSE_TYPE_MAX(int) * 2llu, QSE_FIO_BEGIN);
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("failed to set file offset\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("moved file offset to %lld\n"), (long long)off);
|
||||
}
|
||||
|
||||
n = qse_fio_write (fio, x2, strlen(x2));
|
||||
qse_printf (QSE_T("written %d bytes\n"), (int)n);
|
||||
|
||||
off = qse_fio_seek (fio, 0, QSE_FIO_CURRENT);
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("failed to get file offset\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("file offset at %lld\n"), (long long)off);
|
||||
}
|
||||
|
||||
if (qse_fio_truncate (fio, 20000) == -1)
|
||||
{
|
||||
qse_printf (QSE_T("failed to truncate the file\n"));
|
||||
}
|
||||
|
||||
n = qse_fio_write (fio, x2, strlen(x2));
|
||||
qse_printf (QSE_T("written %d bytes\n"), (int)n);
|
||||
|
||||
off = qse_fio_seek (fio, 0, QSE_FIO_CURRENT);
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("failed to get file offset\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("file offset at %lld\n"), (long long)off);
|
||||
}
|
||||
|
||||
qse_fio_chmod (fio, QSE_FIO_RUSR|QSE_FIO_RGRP);
|
||||
qse_fio_close (fio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test3 (void)
|
||||
{
|
||||
qse_fio_t* fio;
|
||||
qse_ssize_t n;
|
||||
const qse_char_t* x = QSE_T("\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?");
|
||||
qse_fio_off_t off;
|
||||
qse_char_t buf[1000];
|
||||
|
||||
fio = qse_fio_open (
|
||||
QSE_NULL,
|
||||
0,
|
||||
QSE_T("fio3.txt"),
|
||||
|
||||
QSE_FIO_TEXT | QSE_FIO_READ | QSE_FIO_WRITE |
|
||||
QSE_FIO_CREATE | QSE_FIO_TRUNCATE,
|
||||
|
||||
QSE_FIO_RUSR|QSE_FIO_WUSR|QSE_FIO_RGRP|QSE_FIO_ROTH
|
||||
);
|
||||
if (fio == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open file\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
n = qse_fio_write (fio, x, qse_strlen(x));
|
||||
qse_printf (QSE_T("written %d chars\n"), (int)n);
|
||||
|
||||
n = qse_fio_flush (fio);
|
||||
qse_printf (QSE_T("flushed %d chars\n"), (int)n);
|
||||
|
||||
off = qse_fio_seek (fio, 0, QSE_FIO_BEGIN);
|
||||
if (off == (qse_fio_off_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("failed to get file offset\n"));
|
||||
}
|
||||
|
||||
|
||||
n = qse_fio_read (fio, buf, QSE_COUNTOF(buf));
|
||||
qse_printf (QSE_T("read %d chars\n"), (int)n);
|
||||
if (n > 0)
|
||||
{
|
||||
qse_printf (QSE_T("[%.*s]\n"), (int)n, buf);
|
||||
}
|
||||
|
||||
|
||||
qse_fio_close (fio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
qse_printf (QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n"));
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
|
||||
R (test1);
|
||||
R (test2);
|
||||
R (test3);
|
||||
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
qse_printf (QSE_T("Run \"rm -f fio?.txt\" to delete garbages\n"));
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
|
||||
return 0;
|
||||
}
|
369
qse/samples/cmn/lda.c
Normal file
369
qse/samples/cmn/lda.c
Normal file
@ -0,0 +1,369 @@
|
||||
#include <qse/cmn/mem.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/lda.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
||||
if (f() == -1) return -1; \
|
||||
} while (0)
|
||||
|
||||
void keeper1 (qse_lda_t* lda, void* dptr, qse_size_t dlen)
|
||||
{
|
||||
qse_printf (QSE_T("[%.*s] has been kept\n"), (int)dlen, dptr);
|
||||
}
|
||||
|
||||
qse_lda_walk_t walker1 (qse_lda_t* lda, qse_size_t index, void* arg)
|
||||
{
|
||||
qse_printf (QSE_T("%d => [%.*s]\n"),
|
||||
index, (int)QSE_LDA_DLEN(lda,index), QSE_LDA_DPTR(lda,index));
|
||||
return QSE_LDA_WALK_FORWARD;
|
||||
}
|
||||
qse_lda_walk_t rwalker1 (qse_lda_t* lda, qse_size_t index, void* arg)
|
||||
{
|
||||
qse_printf (QSE_T("%d => [%.*s]\n"),
|
||||
index, (int)QSE_LDA_DLEN(lda,index), QSE_LDA_DPTR(lda,index));
|
||||
return QSE_LDA_WALK_BACKWARD;
|
||||
}
|
||||
|
||||
static int test1 ()
|
||||
{
|
||||
qse_lda_t* s1;
|
||||
qse_char_t* x[] =
|
||||
{
|
||||
QSE_T("this is so good"),
|
||||
QSE_T("what the fuck"),
|
||||
QSE_T("do you like it?"),
|
||||
QSE_T("oopsy!")
|
||||
};
|
||||
int i;
|
||||
|
||||
s1 = qse_lda_open (QSE_MMGR_GETDFL(), 0, 0);
|
||||
if (s1 == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open a string\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_lda_setcopier (s1, QSE_LDA_COPIER_INLINE);
|
||||
qse_lda_setkeeper (s1, keeper1);
|
||||
qse_lda_setscale (s1, QSE_SIZEOF(qse_char_t));
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
if (qse_lda_insert (s1, 0, x[i], qse_strlen(x[i])) == QSE_LDA_NIL)
|
||||
{
|
||||
qse_printf (QSE_T("failed to add at 0 => [%.*s]\n"),
|
||||
(int)qse_strlen(x[i]), x[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("add at 0 => [%.*s]\n"),
|
||||
(int)qse_strlen(x[i]), x[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (qse_lda_update (s1, 0, QSE_LDA_DPTR(s1,0), QSE_LDA_DLEN(s1,0)) == QSE_LDA_NIL)
|
||||
{
|
||||
qse_printf (QSE_T("failed to update index 0 with [%.*s]\n"), (int)QSE_LDA_DLEN(s1,0), QSE_LDA_DPTR(s1,0));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("updated index 0 with [%.*s]\n"), (int)QSE_LDA_DLEN(s1,0), QSE_LDA_DPTR(s1,0));
|
||||
}
|
||||
|
||||
if (qse_lda_update (s1, 0, QSE_LDA_DPTR(s1,1), QSE_LDA_DLEN(s1,1)) == QSE_LDA_NIL)
|
||||
{
|
||||
qse_printf (QSE_T("updated index 0 with [%.*s]\n"), (int)QSE_LDA_DLEN(s1,1), QSE_LDA_DPTR(s1,1));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("updated index 0 with [%.*s]\n"), (int)QSE_LDA_DLEN(s1,0), QSE_LDA_DPTR(s1,0));
|
||||
}
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
if (qse_lda_insert (s1, 10, x[i], qse_strlen(x[i])) == QSE_LDA_NIL)
|
||||
{
|
||||
qse_printf (QSE_T("failed to add at 10 => [%.*s]\n"),
|
||||
(int)qse_strlen(x[i]), x[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("add at 10 => [%.*s]\n"),
|
||||
(int)qse_strlen(x[i]), x[i]);
|
||||
}
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("lda size => %lu\n"), QSE_LDA_SIZE(s1));
|
||||
qse_lda_walk (s1, walker1, QSE_NULL);
|
||||
qse_printf (QSE_T("lda size => %lu\n"), QSE_LDA_SIZE(s1));
|
||||
qse_lda_rwalk (s1, rwalker1, QSE_NULL);
|
||||
|
||||
qse_lda_close (s1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test2 ()
|
||||
{
|
||||
qse_lda_t* s1;
|
||||
qse_lda_node_t* p;
|
||||
const qse_char_t* x[] =
|
||||
{
|
||||
QSE_T("this is so good"),
|
||||
QSE_T("what the fuck"),
|
||||
QSE_T("do you like it?"),
|
||||
QSE_T("oopsy!"),
|
||||
QSE_T("hello hello!"),
|
||||
QSE_T("oopsy!")
|
||||
};
|
||||
const qse_char_t* y[] =
|
||||
{
|
||||
QSE_T("tipsy!"),
|
||||
QSE_T("oopsy!")
|
||||
};
|
||||
int i, j;
|
||||
|
||||
s1 = qse_lda_open (QSE_MMGR_GETDFL(), 0, 0);
|
||||
if (s1 == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open a string\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_lda_setcopier (s1, QSE_LDA_COPIER_INLINE);
|
||||
qse_lda_setscale (s1, QSE_SIZEOF(qse_char_t));
|
||||
|
||||
for (j = 0; j < 20; j++)
|
||||
{
|
||||
qse_size_t index;
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
if (qse_lda_insert (s1, (i + 1) * j - 1, x[i], qse_strlen(x[i])) == QSE_LDA_NIL)
|
||||
{
|
||||
|
||||
qse_printf (QSE_T("failed to add at %u => [%.*s]\n"),
|
||||
(unsigned int)((i + 1) * j - 1),
|
||||
(int)qse_strlen(x[i]), x[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("add at %u => [%.*s]\n"),
|
||||
(unsigned int)((i + 1) * j - 1),
|
||||
(int)qse_strlen(x[i]), x[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < QSE_LDA_SIZE(s1); i++)
|
||||
{
|
||||
if (QSE_LDA_NODE(s1,i))
|
||||
{
|
||||
qse_printf (QSE_T("[%d] %d => [%.*s]\n"),
|
||||
j, i, (int)QSE_LDA_DLEN(s1,i), QSE_LDA_DPTR(s1,i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(y); i++)
|
||||
{
|
||||
index = qse_lda_search (s1, 0, y[i], qse_strlen(y[i]));
|
||||
if (index == QSE_LDA_NIL)
|
||||
{
|
||||
qse_printf (QSE_T("failed to find [%s]\n"), y[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("found [%.*s] at %lu\n"),
|
||||
(int)QSE_LDA_DLEN(s1,index), QSE_LDA_DPTR(s1,index), (unsigned long)index);
|
||||
}
|
||||
|
||||
index = qse_lda_rsearch (s1, QSE_LDA_SIZE(s1), y[i], qse_strlen(y[i]));
|
||||
if (index == QSE_LDA_NIL)
|
||||
{
|
||||
qse_printf (QSE_T("failed to find [%s]\n"), y[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("found [%.*s] at %lu\n"),
|
||||
(int)QSE_LDA_DLEN(s1,index), QSE_LDA_DPTR(s1,index), (unsigned long)index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
qse_lda_clear (s1);
|
||||
qse_printf (QSE_T("~~~~~~~~\n"));
|
||||
}
|
||||
|
||||
qse_lda_close (s1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test3 ()
|
||||
{
|
||||
qse_lda_t* s1;
|
||||
const qse_char_t* x[] =
|
||||
{
|
||||
QSE_T("this is so good"),
|
||||
QSE_T("what the fuck"),
|
||||
QSE_T("do you like it?"),
|
||||
QSE_T("oopsy!")
|
||||
};
|
||||
const qse_char_t* y =
|
||||
QSE_T("We Accept MasterCard, VISA, JCB, Dinner & eCheck");
|
||||
int i, j;
|
||||
|
||||
s1 = qse_lda_open (QSE_MMGR_GETDFL(), 0, 0);
|
||||
if (s1 == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open a string\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_lda_setcopier (s1, QSE_LDA_COPIER_INLINE);
|
||||
qse_lda_setscale (s1, QSE_SIZEOF(qse_char_t));
|
||||
|
||||
for (j = 0; j < 20; j++)
|
||||
{
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
if (qse_lda_insert (s1, (i + 1) * j - 1, x[i], qse_strlen(x[i])) == QSE_LDA_NIL)
|
||||
{
|
||||
|
||||
qse_printf (QSE_T("failed to add at %u => [%.*s]\n"),
|
||||
(unsigned int)((i + 1) * j - 1),
|
||||
(int)qse_strlen(x[i]), x[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("add at %u => [%.*s]\n"),
|
||||
(unsigned int)((i + 1) * j - 1),
|
||||
(int)qse_strlen(x[i]), x[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i = 2; i < 3; i++)
|
||||
{
|
||||
if (i < QSE_LDA_SIZE(s1))
|
||||
{
|
||||
if (QSE_LDA_NODE(s1,i))
|
||||
{
|
||||
qse_printf (QSE_T("deleted at %d => [%.*s]\n"),
|
||||
i, (int)QSE_LDA_DLEN(s1,i), QSE_LDA_DPTR(s1,i));
|
||||
}
|
||||
|
||||
qse_lda_delete (s1, i, 1);
|
||||
}
|
||||
|
||||
if (i < QSE_LDA_SIZE(s1))
|
||||
{
|
||||
if (qse_lda_update (s1, i, y, qse_strlen(y)) == QSE_LDA_NIL)
|
||||
{
|
||||
qse_printf (QSE_T("failed to update at %d => [%.*s]\n"),
|
||||
i, (int)qse_strlen(y), y);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("updated at %d => [%.*s]\n"),
|
||||
i, (int)QSE_LDA_DLEN(s1,i), QSE_LDA_DPTR(s1,i));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("array size => %lu\n"), (unsigned long)QSE_LDA_SIZE(s1));
|
||||
|
||||
for (i = 0; i < QSE_LDA_SIZE(s1); i++)
|
||||
{
|
||||
if (QSE_LDA_NODE(s1,i))
|
||||
{
|
||||
qse_printf (QSE_T("[%d] %d => [%.*s]\n"),
|
||||
j, i, (int)QSE_LDA_DLEN(s1,i), QSE_LDA_DPTR(s1,i));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
qse_size_t count = qse_lda_uplete (s1, 3, 20);
|
||||
qse_printf (QSE_T("upleted %lu items from index 3\n"), (unsigned long)count);
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("array size => %lu\n"), (unsigned long)QSE_LDA_SIZE(s1));
|
||||
|
||||
for (i = 0; i < QSE_LDA_SIZE(s1); i++)
|
||||
{
|
||||
if (QSE_LDA_NODE(s1,i))
|
||||
{
|
||||
qse_printf (QSE_T("[%d] %d => [%.*s]\n"),
|
||||
j, i, (int)QSE_LDA_DLEN(s1,i), QSE_LDA_DPTR(s1,i));
|
||||
}
|
||||
}
|
||||
|
||||
qse_lda_clear (s1);
|
||||
qse_printf (QSE_T("~~~~~~~~\n"));
|
||||
}
|
||||
|
||||
qse_lda_close (s1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
qse_size_t sizer1 (qse_lda_t* lda, qse_size_t hint)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int test4 ()
|
||||
{
|
||||
int i;
|
||||
qse_lda_t* s1;
|
||||
const qse_char_t* x[] =
|
||||
{
|
||||
QSE_T("this is so good"),
|
||||
QSE_T("what the fuck"),
|
||||
QSE_T("do you like it?"),
|
||||
QSE_T("oopsy!")
|
||||
};
|
||||
|
||||
s1 = qse_lda_open (QSE_MMGR_GETDFL(), 0, 3);
|
||||
if (s1 == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open a string\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_lda_setcopier (s1, QSE_LDA_COPIER_INLINE);
|
||||
qse_lda_setsizer (s1, sizer1);
|
||||
qse_lda_setscale (s1, QSE_SIZEOF(qse_char_t));
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
if (qse_lda_insert (s1, 0, x[i], qse_strlen(x[i])) == QSE_LDA_NIL)
|
||||
{
|
||||
qse_printf (QSE_T("failed to add at 0 => [%.*s]\n"),
|
||||
(int)qse_strlen(x[i]), x[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("add at 0 => [%.*s]\n"),
|
||||
(int)qse_strlen(x[i]), x[i]);
|
||||
}
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("lda size => %lu\n"), QSE_LDA_SIZE(s1));
|
||||
qse_lda_walk (s1, walker1, QSE_NULL);
|
||||
qse_printf (QSE_T("lda size => %lu\n"), QSE_LDA_SIZE(s1));
|
||||
qse_lda_rwalk (s1, rwalker1, QSE_NULL);
|
||||
|
||||
qse_lda_close (s1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
R (test1);
|
||||
R (test2);
|
||||
R (test3);
|
||||
R (test4);
|
||||
return 0;
|
||||
}
|
307
qse/samples/cmn/map.c
Normal file
307
qse/samples/cmn/map.c
Normal file
@ -0,0 +1,307 @@
|
||||
#include <qse/cmn/mem.h>
|
||||
#include <qse/cmn/chr.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/map.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
||||
if (f() == -1) return -1; \
|
||||
} while (0)
|
||||
|
||||
static int test1_build (qse_map_t* s1)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
for (i = 1; i < 50; i++)
|
||||
{
|
||||
int j = i * 2;
|
||||
qse_printf (QSE_T("inserting a key %d and a value %d: "), i, j);
|
||||
|
||||
if (qse_map_insert (s1, &i, sizeof(i), &j, sizeof(j)) == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("[FAILED]\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("[OK]\n"));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test1_delete (qse_map_t* s1)
|
||||
{
|
||||
int i;
|
||||
int t[] = { 20, 11, 13, 40 };
|
||||
int t2[] = { 22, 21, 31, 14, 48, 32, 29 };
|
||||
|
||||
for (i = 1; i < 53; i+=2)
|
||||
{
|
||||
qse_printf (QSE_T("deleting a key %d: "), i);
|
||||
if (qse_map_delete (s1, &i, sizeof(i)) == -1)
|
||||
qse_printf (QSE_T("[FAILED]\n"));
|
||||
else
|
||||
qse_printf (QSE_T("[OK]\n"));
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(t); i++)
|
||||
{
|
||||
int k = t[i];
|
||||
int v = k * 1000;
|
||||
|
||||
qse_printf (QSE_T("updating a key %d value %d: "), k, v);
|
||||
if (qse_map_update (s1, &k, sizeof(k), &v, sizeof(v)) == QSE_NULL)
|
||||
qse_printf (QSE_T("[FAILED]\n"));
|
||||
else
|
||||
qse_printf (QSE_T("[OK]\n"));
|
||||
}
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(t); i++)
|
||||
{
|
||||
int k = t[i];
|
||||
int v = k * 1000;
|
||||
|
||||
qse_printf (QSE_T("inserting a key %d value %d: "), k, v);
|
||||
if (qse_map_insert (s1, &k, sizeof(k), &v, sizeof(v)) == QSE_NULL)
|
||||
qse_printf (QSE_T("[FAILED]\n"));
|
||||
else
|
||||
qse_printf (QSE_T("[OK]\n"));
|
||||
}
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(t2); i++)
|
||||
{
|
||||
int k = t2[i];
|
||||
int v = k * 2000;
|
||||
|
||||
qse_printf (QSE_T("upserting a key %d value %d: "), k, v);
|
||||
if (qse_map_upsert (s1, &k, sizeof(k), &v, sizeof(v)) == QSE_NULL)
|
||||
qse_printf (QSE_T("[FAILED]\n"));
|
||||
else
|
||||
qse_printf (QSE_T("[OK]\n"));
|
||||
}
|
||||
}
|
||||
|
||||
static void test1_dump (qse_map_t* s1)
|
||||
{
|
||||
int i;
|
||||
|
||||
qse_printf (QSE_T("map contains %u pairs\n"), (unsigned)QSE_MAP_SIZE(s1));
|
||||
for (i = 1; i < 50; i++)
|
||||
{
|
||||
qse_map_pair_t* p = qse_map_search (s1, &i, sizeof(i));
|
||||
if (p == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("%d => unknown\n"), i);
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("%d => %d(%d)\n"),
|
||||
i, *(int*)QSE_MAP_VPTR(p), (int)QSE_MAP_VLEN(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int test1 ()
|
||||
{
|
||||
qse_map_t* s1;
|
||||
|
||||
s1 = qse_map_open (QSE_MMGR_GETDFL(), 0, 5, 70);
|
||||
if (s1 == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open a map\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_map_setcopier (s1, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
|
||||
qse_map_setcopier (s1, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE);
|
||||
|
||||
if (test1_build(s1) == -1)
|
||||
{
|
||||
qse_map_close (s1);
|
||||
return -1;
|
||||
}
|
||||
test1_dump (s1);
|
||||
|
||||
test1_delete (s1);
|
||||
test1_dump (s1);
|
||||
|
||||
qse_map_close (s1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
qse_map_walk_t print_map_pair (qse_map_t* map, qse_map_pair_t* pair, void* arg)
|
||||
{
|
||||
qse_printf (QSE_T("%.*s[%d] => %.*s[%d]\n"),
|
||||
(int)QSE_MAP_KLEN(pair), QSE_MAP_KPTR(pair), (int)QSE_MAP_KLEN(pair),
|
||||
(int)QSE_MAP_VLEN(pair), QSE_MAP_VPTR(pair), (int)QSE_MAP_VLEN(pair));
|
||||
|
||||
return QSE_MAP_WALK_FORWARD;
|
||||
}
|
||||
|
||||
static int test2 ()
|
||||
{
|
||||
qse_map_t* s1;
|
||||
int i;
|
||||
qse_char_t* keys[] =
|
||||
{
|
||||
QSE_T("if you ever happen"),
|
||||
QSE_T("to want to link againt"),
|
||||
QSE_T("installed libraries"),
|
||||
QSE_T("in a given directory")
|
||||
};
|
||||
|
||||
s1 = qse_map_open (QSE_MMGR_GETDFL(), 0, 1, 70);
|
||||
if (s1 == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open a map\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_map_setcopier (s1, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
|
||||
qse_map_setcopier (s1, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE);
|
||||
qse_map_setscale (s1, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t));
|
||||
qse_map_setscale (s1, QSE_MAP_VAL, QSE_SIZEOF(qse_char_t));
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(keys); i++)
|
||||
{
|
||||
int vi = QSE_COUNTOF(keys)-i-1;
|
||||
|
||||
qse_printf (QSE_T("inserting a key [%s] and a value [%s]: "), keys[i], keys[vi]);
|
||||
if (qse_map_insert (s1,
|
||||
keys[i], qse_strlen(keys[i]),
|
||||
keys[vi], qse_strlen(keys[vi])) == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("[FAILED]\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("[OK]\n"));
|
||||
}
|
||||
}
|
||||
|
||||
qse_map_walk (s1, print_map_pair, QSE_NULL);
|
||||
|
||||
qse_map_close (s1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int comp_key (qse_map_t* map,
|
||||
const void* kptr1, qse_size_t klen1,
|
||||
const void* kptr2, qse_size_t klen2)
|
||||
{
|
||||
return qse_strxncasecmp (kptr1, klen1, kptr2, klen2);
|
||||
}
|
||||
|
||||
qse_map_walk_t print_map_pair_3 (qse_map_t* map, qse_map_pair_t* pair, void* arg)
|
||||
{
|
||||
qse_printf (QSE_T("%.*s[%d] => %d\n"),
|
||||
(int)QSE_MAP_KLEN(pair), QSE_MAP_KPTR(pair), (int)QSE_MAP_KLEN(pair),
|
||||
*(int*)QSE_MAP_VPTR(pair));
|
||||
|
||||
return QSE_MAP_WALK_FORWARD;
|
||||
}
|
||||
|
||||
static int test3 ()
|
||||
{
|
||||
qse_map_t* s1;
|
||||
int i;
|
||||
qse_char_t* keys[] =
|
||||
{
|
||||
QSE_T("one"),
|
||||
QSE_T("two"),
|
||||
QSE_T("three"),
|
||||
QSE_T("four"),
|
||||
QSE_T("ONE"),
|
||||
QSE_T("Two"),
|
||||
QSE_T("thRee")
|
||||
};
|
||||
|
||||
s1 = qse_map_open (QSE_MMGR_GETDFL(), 0, 1, 70);
|
||||
if (s1 == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open a map\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_map_setcopier (s1, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
|
||||
qse_map_setcopier (s1, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE);
|
||||
qse_map_setcomper (s1, comp_key);
|
||||
qse_map_setscale (s1, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t));
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(keys); i++)
|
||||
{
|
||||
qse_printf (QSE_T("inserting a key [%s] and a value %d: "), keys[i], i);
|
||||
if (qse_map_insert (s1, keys[i], qse_strlen(keys[i]), &i, sizeof(i)) == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("[FAILED]\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("[OK]\n"));
|
||||
}
|
||||
}
|
||||
|
||||
qse_map_walk (s1, print_map_pair_3, QSE_NULL);
|
||||
|
||||
qse_map_close (s1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test4 ()
|
||||
{
|
||||
qse_map_t* s1;
|
||||
int i;
|
||||
qse_char_t* keys[] =
|
||||
{
|
||||
QSE_T("one"),
|
||||
QSE_T("two"),
|
||||
QSE_T("three"),
|
||||
QSE_T("four"),
|
||||
QSE_T("ONE"),
|
||||
QSE_T("Two"),
|
||||
QSE_T("thRee")
|
||||
};
|
||||
|
||||
s1 = qse_map_open (QSE_MMGR_GETDFL(), 0, 1, 70);
|
||||
if (s1 == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open a map\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_map_setcopier (s1, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
|
||||
qse_map_setcopier (s1, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE);
|
||||
qse_map_setcomper (s1, comp_key);
|
||||
qse_map_setscale (s1, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t));
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(keys); i++)
|
||||
{
|
||||
qse_printf (QSE_T("upserting a key [%s] and a value %d: "), keys[i], i);
|
||||
if (qse_map_upsert (s1, keys[i], qse_strlen(keys[i]), &i, sizeof(i)) == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("[FAILED]\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("[OK]\n"));
|
||||
}
|
||||
}
|
||||
|
||||
qse_map_walk (s1, print_map_pair_3, QSE_NULL);
|
||||
|
||||
qse_map_close (s1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
R (test1);
|
||||
R (test2);
|
||||
R (test3);
|
||||
R (test4);
|
||||
return 0;
|
||||
}
|
237
qse/samples/cmn/pio.c
Normal file
237
qse/samples/cmn/pio.c
Normal file
@ -0,0 +1,237 @@
|
||||
#include <qse/cmn/pio.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
||||
if (f() == -1) return -1; \
|
||||
} while (0)
|
||||
|
||||
static int pio1 (const qse_char_t* cmd, int oflags, qse_pio_hid_t rhid)
|
||||
{
|
||||
qse_pio_t* pio;
|
||||
int x;
|
||||
|
||||
pio = qse_pio_open (
|
||||
QSE_NULL,
|
||||
0,
|
||||
cmd,
|
||||
oflags
|
||||
);
|
||||
if (pio == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open program through pipe\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
qse_byte_t buf[128];
|
||||
|
||||
/*qse_pio_canread (pio, QSE_PIO_ERR, 1000)*/
|
||||
qse_ssize_t n = qse_pio_read (pio, buf, sizeof(buf), rhid);
|
||||
if (n == 0) break;
|
||||
if (n < 0)
|
||||
{
|
||||
qse_printf (QSE_T("qse_pio_read() returned error - %s\n"), qse_pio_geterrstr(pio));
|
||||
break;
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("N===> %d\n"), (int)n);
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("buf => [%.*s]\n"), (int)n, buf);
|
||||
#else
|
||||
qse_printf (QSE_T("buf => [%.*S]\n"), (int)n, buf);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
x = qse_pio_wait (pio);
|
||||
qse_printf (QSE_T("qse_pio_wait returns %d\n"), x);
|
||||
if (x == -1)
|
||||
{
|
||||
qse_printf (QSE_T("error code : %d, error string: %s\n"), (int)qse_pio_geterrnum(pio), qse_pio_geterrstr(pio));
|
||||
}
|
||||
|
||||
qse_pio_close (pio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pio2 (const qse_char_t* cmd, int oflags, qse_pio_hid_t rhid)
|
||||
{
|
||||
qse_pio_t* pio;
|
||||
int x;
|
||||
|
||||
pio = qse_pio_open (
|
||||
QSE_NULL,
|
||||
0,
|
||||
cmd,
|
||||
oflags | QSE_PIO_TEXT
|
||||
);
|
||||
if (pio == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open program through pipe\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
qse_char_t buf[128];
|
||||
|
||||
qse_ssize_t n = qse_pio_read (pio, buf, QSE_COUNTOF(buf), rhid);
|
||||
if (n == 0) break;
|
||||
if (n < 0)
|
||||
{
|
||||
qse_printf (QSE_T("qse_pio_read() returned error - %s\n"), qse_pio_geterrstr(pio));
|
||||
break;
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("N===> %d\n"), (int)n);
|
||||
qse_printf (QSE_T("buf => [%.*s]\n"), (int)n, buf);
|
||||
}
|
||||
|
||||
x = qse_pio_wait (pio);
|
||||
qse_printf (QSE_T("qse_pio_wait returns %d\n"), x);
|
||||
if (x == -1)
|
||||
{
|
||||
qse_printf (QSE_T("error code : %d, error string: %s\n"), (int)qse_pio_geterrnum(pio), qse_pio_geterrstr(pio));
|
||||
}
|
||||
|
||||
qse_pio_close (pio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int test1 (void)
|
||||
{
|
||||
return pio1 (QSE_T("ls -laF"), QSE_PIO_READOUT|QSE_PIO_WRITEIN|QSE_PIO_SHELL, QSE_PIO_OUT);
|
||||
}
|
||||
|
||||
static int test2 (void)
|
||||
{
|
||||
return pio1 (QSE_T("ls -laF"), QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN|QSE_PIO_SHELL, QSE_PIO_ERR);
|
||||
}
|
||||
|
||||
static int test3 (void)
|
||||
{
|
||||
return pio1 (QSE_T("/bin/ls -laF"), QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN, QSE_PIO_ERR);
|
||||
}
|
||||
|
||||
static int test4 (void)
|
||||
{
|
||||
return pio2 (QSE_T("ls -laF"), QSE_PIO_READOUT|QSE_PIO_WRITEIN|QSE_PIO_SHELL, QSE_PIO_OUT);
|
||||
}
|
||||
|
||||
static int test5 (void)
|
||||
{
|
||||
return pio2 (QSE_T("ls -laF"), QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN|QSE_PIO_SHELL, QSE_PIO_ERR);
|
||||
}
|
||||
|
||||
static int test6 (void)
|
||||
{
|
||||
return pio2 (QSE_T("/bin/ls -laF"), QSE_PIO_READERR|QSE_PIO_OUTTOERR|QSE_PIO_WRITEIN, QSE_PIO_ERR);
|
||||
}
|
||||
|
||||
static int test7 (void)
|
||||
{
|
||||
qse_pio_t* pio;
|
||||
int x;
|
||||
|
||||
pio = qse_pio_open (
|
||||
QSE_NULL,
|
||||
0,
|
||||
QSE_T("/bin/ls -laF"),
|
||||
QSE_PIO_READOUT|QSE_PIO_ERRTOOUT|QSE_PIO_WRITEIN
|
||||
);
|
||||
if (pio == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open program through pipe\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
qse_byte_t buf[128];
|
||||
|
||||
/*qse_pio_canread (pio, QSE_PIO_ERR, 1000)*/
|
||||
qse_ssize_t n = qse_pio_read (pio, buf, sizeof(buf), QSE_PIO_OUT);
|
||||
if (n == 0) break;
|
||||
if (n < 0)
|
||||
{
|
||||
qse_printf (QSE_T("qse_pio_read() returned error - %s\n"), qse_pio_geterrstr(pio));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
x = qse_pio_wait (pio);
|
||||
qse_printf (QSE_T("qse_pio_wait returns %d\n"), x);
|
||||
if (x == -1)
|
||||
{
|
||||
qse_printf (QSE_T("error code : %d, error string: %s\n"), (int)QSE_PIO_ERRNUM(pio), qse_pio_geterrstr(pio));
|
||||
}
|
||||
|
||||
qse_pio_close (pio);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test8 (void)
|
||||
{
|
||||
qse_pio_t* pio;
|
||||
int x;
|
||||
|
||||
pio = qse_pio_open (
|
||||
QSE_NULL,
|
||||
0,
|
||||
QSE_T("/bin/ls -laF"),
|
||||
QSE_PIO_READOUT|QSE_PIO_READERR|QSE_PIO_WRITEIN
|
||||
);
|
||||
if (pio == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open program through pipe\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
{
|
||||
int status;
|
||||
int n = 5;
|
||||
|
||||
qse_printf (QSE_T("sleeping for %d seconds\n"), n);
|
||||
sleep (n);
|
||||
qse_printf (QSE_T("waitpid...%d\n"), (int)waitpid (-1, &status, 0));
|
||||
}
|
||||
|
||||
x = qse_pio_wait (pio);
|
||||
qse_printf (QSE_T("qse_pio_wait returns %d\n"), x);
|
||||
if (x == -1)
|
||||
{
|
||||
qse_printf (QSE_T("error code : %d, error string: %s\n"), (int)QSE_PIO_ERRNUM(pio), qse_pio_geterrstr(pio));
|
||||
}
|
||||
|
||||
qse_pio_close (pio);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
qse_printf (QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n"));
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
|
||||
R (test1);
|
||||
R (test2);
|
||||
R (test3);
|
||||
R (test4);
|
||||
R (test5);
|
||||
R (test6);
|
||||
R (test7);
|
||||
R (test8);
|
||||
|
||||
return 0;
|
||||
}
|
86
qse/samples/cmn/sio.c
Normal file
86
qse/samples/cmn/sio.c
Normal file
@ -0,0 +1,86 @@
|
||||
#include <qse/cmn/sio.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
qse_sio_puts (qse_sio_out,QSE_T("== ")); \
|
||||
qse_sio_puts (qse_sio_out,QSE_T(#f)); \
|
||||
qse_sio_puts (qse_sio_out,QSE_T(" ==\n")); \
|
||||
if (f() == -1) return -1; \
|
||||
} while (0)
|
||||
|
||||
static int test1 (void)
|
||||
{
|
||||
qse_sio_t* sio;
|
||||
int i;
|
||||
const qse_wchar_t* x[] =
|
||||
{
|
||||
L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",
|
||||
L"Fly to the universe, kick you ass",
|
||||
L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",
|
||||
L"Fly to the universe, kick you ass",
|
||||
L"Fly to the universe, kick you ass",
|
||||
L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?"
|
||||
};
|
||||
|
||||
sio = qse_sio_open (QSE_NULL, 0, QSE_T("sio.txt"),
|
||||
QSE_SIO_WRITE | QSE_SIO_CREATE | QSE_SIO_TRUNCATE);
|
||||
|
||||
if (sio == QSE_NULL)
|
||||
{
|
||||
qse_sio_puts (qse_sio_err, QSE_T("cannot open file\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_sio_puts (qse_sio_out, QSE_T("written: ["));
|
||||
qse_sio_puts (qse_sio_out, x[i]);
|
||||
qse_sio_puts (qse_sio_out, QSE_T("]\n"));
|
||||
|
||||
qse_sio_puts (sio, x[i]);
|
||||
qse_sio_putc (sio, QSE_T('\n'));
|
||||
}
|
||||
|
||||
qse_sio_close (sio);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test2 (void)
|
||||
{
|
||||
qse_ssize_t n;
|
||||
qse_char_t buf[20];
|
||||
|
||||
qse_sio_puts (qse_sio_out, QSE_T("type somthing...\n"));
|
||||
while (1)
|
||||
{
|
||||
n = qse_sio_gets (qse_sio_in, buf, QSE_COUNTOF(buf));
|
||||
if (n == 0) break;
|
||||
if (n < 0)
|
||||
{
|
||||
qse_sio_puts (qse_sio_err, QSE_T("error ....\n"));
|
||||
break;
|
||||
}
|
||||
|
||||
qse_sio_puts (qse_sio_out, buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
qse_sio_puts (qse_sio_out, QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
qse_sio_puts (qse_sio_out, QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n"));
|
||||
qse_sio_puts (qse_sio_out, QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
|
||||
R (test1);
|
||||
R (test2);
|
||||
|
||||
return 0;
|
||||
}
|
65
qse/samples/cmn/sll.c
Normal file
65
qse/samples/cmn/sll.c
Normal file
@ -0,0 +1,65 @@
|
||||
#include <qse/cmn/mem.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/sll.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
||||
if (f() == -1) return -1; \
|
||||
} while (0)
|
||||
|
||||
static qse_sll_walk_t walk_sll (qse_sll_t* sll, qse_sll_node_t* n, void* arg)
|
||||
{
|
||||
qse_printf (QSE_T("[%.*s]\n"), (int)QSE_SLL_DLEN(n), QSE_SLL_DPTR(n));
|
||||
return QSE_SLL_WALK_FORWARD;
|
||||
}
|
||||
|
||||
static int test1 ()
|
||||
{
|
||||
qse_sll_t* s1;
|
||||
qse_sll_node_t* p;
|
||||
qse_char_t* x[] =
|
||||
{
|
||||
QSE_T("this is so good"),
|
||||
QSE_T("what the hack"),
|
||||
QSE_T("do you like it?")
|
||||
};
|
||||
int i;
|
||||
|
||||
s1 = qse_sll_open (QSE_MMGR_GETDFL(), 0);
|
||||
if (s1 == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open a string\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_sll_setcopier (s1, QSE_SLL_COPIER_INLINE);
|
||||
qse_sll_setscale (s1, QSE_SIZEOF(qse_char_t));
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_sll_pushtail (s1, x[i], qse_strlen(x[i]));
|
||||
}
|
||||
qse_printf (QSE_T("s1 holding [%d] nodes\n"), QSE_SLL_SIZE(s1));
|
||||
qse_sll_walk (s1, walk_sll, QSE_NULL);
|
||||
|
||||
|
||||
p = qse_sll_search (s1, QSE_NULL, x[0], qse_strlen(x[0]));
|
||||
if (p != QSE_NULL)
|
||||
{
|
||||
qse_sll_delete (s1, p);
|
||||
}
|
||||
qse_printf (QSE_T("s1 holding [%d] nodes\n"), QSE_SLL_SIZE(s1));
|
||||
qse_sll_walk (s1, walk_sll, QSE_NULL);
|
||||
|
||||
qse_sll_close (s1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
R (test1);
|
||||
return 0;
|
||||
}
|
576
qse/samples/cmn/str.c
Normal file
576
qse/samples/cmn/str.c
Normal file
@ -0,0 +1,576 @@
|
||||
#include <qse/cmn/mem.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
|
||||
#include <locale.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
||||
if (f() == -1) return -1; \
|
||||
} while (0)
|
||||
|
||||
static int test1 ()
|
||||
{
|
||||
qse_str_t* s1;
|
||||
|
||||
s1 = qse_str_open (QSE_MMGR_GETDFL(), 0, 5);
|
||||
if (s1 == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("cannot open a string\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("LEN=%u\n"),
|
||||
(unsigned)qse_str_ncat (s1, QSE_T("i love you this is great"), 24));
|
||||
qse_printf (QSE_T("LEN=%u CAPA=%u [%.*s]\n"),
|
||||
(unsigned)QSE_STR_LEN(s1), (unsigned)QSE_STR_CAPA(s1),
|
||||
(int)QSE_STR_LEN(s1), QSE_STR_PTR(s1));
|
||||
|
||||
qse_printf (QSE_T("LEN=%u\n"),
|
||||
(unsigned int)qse_str_setlen (s1, QSE_STR_LEN(s1)-1));
|
||||
qse_printf (QSE_T("LEN=%u CAPA=%u [%.*s]\n"),
|
||||
(unsigned)QSE_STR_LEN(s1), (unsigned)QSE_STR_CAPA(s1),
|
||||
(int)QSE_STR_LEN(s1), QSE_STR_PTR(s1));
|
||||
|
||||
qse_printf (QSE_T("LEN=%u\n"),
|
||||
(unsigned int)qse_str_setlen (s1, QSE_STR_CAPA(s1) + 5));
|
||||
qse_printf (QSE_T("LEN=%u CAPA=%u [%.*s]\n"),
|
||||
(unsigned)QSE_STR_LEN(s1), (unsigned)QSE_STR_CAPA(s1),
|
||||
(int)QSE_STR_LEN(s1), QSE_STR_PTR(s1));
|
||||
|
||||
qse_str_close (s1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test2 ()
|
||||
{
|
||||
qse_str_t s1;
|
||||
|
||||
qse_str_init (&s1, QSE_MMGR_GETDFL(), 5);
|
||||
|
||||
qse_printf (QSE_T("LEN=%u\n"),
|
||||
(unsigned)qse_str_ncat (&s1, QSE_T("i love you this is great"), 24));
|
||||
qse_printf (QSE_T("LEN=%u CAPA=%u [%.*s]\n"),
|
||||
(unsigned)QSE_STR_LEN(&s1), (unsigned)QSE_STR_CAPA(&s1),
|
||||
(int)QSE_STR_LEN(&s1), QSE_STR_PTR(&s1));
|
||||
|
||||
qse_str_fini (&s1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static qse_size_t resize_str_1 (qse_str_t* str, qse_size_t hint)
|
||||
{
|
||||
return QSE_STR_CAPA(str) + 1;
|
||||
}
|
||||
|
||||
static qse_size_t resize_str_2 (qse_str_t* str, qse_size_t hint)
|
||||
{
|
||||
return hint;
|
||||
}
|
||||
|
||||
static qse_size_t resize_str_3 (qse_str_t* str, qse_size_t hint)
|
||||
{
|
||||
return hint * 2 + hint / 2;
|
||||
}
|
||||
|
||||
static qse_size_t resize_str_4 (qse_str_t* str, qse_size_t hint)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test3 ()
|
||||
{
|
||||
qse_str_t s1;
|
||||
int i;
|
||||
|
||||
qse_str_init (&s1, QSE_MMGR_GETDFL(), 5);
|
||||
|
||||
for (i = 0; i < 9; i++)
|
||||
{
|
||||
if (i == 0) qse_str_setsizer (&s1, resize_str_1);
|
||||
if (i == 1)
|
||||
{
|
||||
qse_str_setsizer (&s1, resize_str_2);
|
||||
qse_str_clear (&s1);
|
||||
}
|
||||
if (i == 2) qse_str_setsizer (&s1, resize_str_3);
|
||||
if (i == 3) qse_str_setsizer (&s1, resize_str_4);
|
||||
if (i == 8) qse_str_setsizer (&s1, resize_str_2);
|
||||
|
||||
if (qse_str_ncat (&s1, QSE_T("i love you this is great"), 24) == (qse_size_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("cannot add string\n"));
|
||||
qse_str_fini (&s1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("LEN=%u CAPA=%u [%.*s]\n"),
|
||||
(unsigned)QSE_STR_LEN(&s1), (unsigned)QSE_STR_CAPA(&s1),
|
||||
(int)QSE_STR_LEN(&s1), QSE_STR_PTR(&s1));
|
||||
}
|
||||
|
||||
qse_str_fini (&s1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test4 ()
|
||||
{
|
||||
qse_str_t s1;
|
||||
qse_xstr_t out;
|
||||
|
||||
qse_str_init (&s1, QSE_MMGR_GETDFL(), 0);
|
||||
|
||||
if (qse_str_yield (&s1, &out, 0) == -1)
|
||||
{
|
||||
qse_printf (QSE_T("cannot yield string\n"));
|
||||
qse_str_fini (&s1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("out.ptr=%p LEN=%u [.*s]\n"),
|
||||
out.ptr, (unsigned)out.len, (int)out.len, out.ptr);
|
||||
|
||||
if (qse_str_ncat (&s1, QSE_T("i love you this is great"), 24) == (qse_size_t)-1)
|
||||
{
|
||||
qse_printf (QSE_T("cannot add string\n"));
|
||||
qse_str_fini (&s1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qse_str_yield (&s1, &out, 0) == -1)
|
||||
{
|
||||
qse_printf (QSE_T("cannot yield string\n"));
|
||||
qse_str_fini (&s1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("out.ptr=%p LEN=%u, [%.*s]\n"),
|
||||
out.ptr, (unsigned)out.len, (int)out.len, out.ptr);
|
||||
|
||||
qse_str_fini (&s1);
|
||||
|
||||
QSE_MMGR_FREE (QSE_MMGR_GETDFL(), out.ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test5 (void)
|
||||
{
|
||||
int i;
|
||||
const qse_mchar_t* x[] =
|
||||
{
|
||||
"\0\0\0",
|
||||
"뛰어 올라봐. 멀리멀리 잘난척하기는",
|
||||
"Fly to the universe"
|
||||
};
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_size_t k = strlen(x[i]);
|
||||
qse_size_t j = 0;
|
||||
qse_wchar_t wc;
|
||||
qse_wchar_t buf[10];
|
||||
|
||||
if (k == 0) k = 3; /* for x[0] */
|
||||
|
||||
qse_printf (QSE_T("["));
|
||||
|
||||
while (j < k)
|
||||
{
|
||||
qse_size_t wlen = QSE_COUNTOF(buf);
|
||||
qse_size_t y = qse_mbsntowcsn (&x[i][j], k-j, buf, &wlen);
|
||||
|
||||
if (y <= 0)
|
||||
{
|
||||
qse_printf (QSE_T("***illegal or incomplete sequence***"));
|
||||
break;
|
||||
}
|
||||
|
||||
if (wlen > 0 && buf[0] == QSE_T('\0'))
|
||||
{
|
||||
while (wlen > 0 && buf[--wlen] == QSE_T('\0'))
|
||||
{
|
||||
qse_printf (QSE_T("\\0"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("%.*s"), (int)wlen, buf);
|
||||
}
|
||||
|
||||
j += y;
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("] => %d bytes\n"), (int)k);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test6 (void)
|
||||
{
|
||||
int i;
|
||||
const qse_mchar_t* x[] =
|
||||
{
|
||||
"",
|
||||
"뛰어 올라봐. 멀리멀리 잘난척하기는",
|
||||
"Fly to the universe. eat my shorts."
|
||||
};
|
||||
qse_wchar_t buf[5];
|
||||
qse_wchar_t buf2[50];
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_size_t n;
|
||||
qse_size_t wlen = QSE_COUNTOF(buf);
|
||||
n = qse_mbstowcs (x[i], buf, &wlen);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("[%s]=>"), x[i]);
|
||||
#else
|
||||
qse_printf (QSE_T("[%S]=>"), x[i]);
|
||||
#endif
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("[%S] %d chars %d bytes\n"), buf, (int)wlen, (int)n);
|
||||
#else
|
||||
qse_printf (QSE_T("[%s] %d chars %d bytes\n"), buf, (int)wlen, (int)n);
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("-----------------\n"));
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_size_t n;
|
||||
qse_size_t wlen = QSE_COUNTOF(buf2);
|
||||
n = qse_mbstowcs (x[i], buf2, &wlen);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("[%S] %d chars %d bytes\n"), buf2, (int)wlen, (int)n);
|
||||
#else
|
||||
qse_printf (QSE_T("[%s] %d chars %d bytes\n"), buf2, (int)wlen, (int)n);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test7 (void)
|
||||
{
|
||||
const qse_wchar_t* x[] =
|
||||
{
|
||||
L"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
|
||||
L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",
|
||||
L"Fly to the universe, kick you ass"
|
||||
};
|
||||
qse_mchar_t buf[15];
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
size_t len = wcslen(x[i]);
|
||||
qse_size_t n;
|
||||
|
||||
if (len == 0) len = 20; /* for x[0] */
|
||||
|
||||
qse_printf (QSE_T("["));
|
||||
|
||||
for (j = 0; j < len; j += n)
|
||||
{
|
||||
qse_size_t mlen = sizeof(buf);
|
||||
n = qse_wcsntombsn (&x[i][j], len-j, buf, &mlen);
|
||||
|
||||
if (n <= 0)
|
||||
{
|
||||
qse_printf (QSE_T("***illegal character or buffer not large***"));
|
||||
break;
|
||||
}
|
||||
|
||||
if (mlen > 0 && buf[0] == QSE_T('\0'))
|
||||
{
|
||||
while (mlen > 0 && buf[--mlen] == QSE_T('\0'))
|
||||
{
|
||||
qse_printf (QSE_T("\\0"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("%.*s"), (int)mlen, buf);
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
qse_printf (QSE_T("%.*S"), (int)mlen, buf);
|
||||
#else
|
||||
/* at least on linux and macosx, wprintf seems
|
||||
* to taks preceision as the number of wide
|
||||
* characters with %s. */
|
||||
qse_printf (QSE_T("%.*S"), n, buf);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("] => %d chars\n"), (int)len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test8 (void)
|
||||
{
|
||||
const qse_wchar_t* x[] =
|
||||
{
|
||||
L"",
|
||||
L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",
|
||||
L"Fly to the universe, kick you ass"
|
||||
};
|
||||
qse_mchar_t buf[10];
|
||||
qse_mchar_t buf2[100];
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_size_t n;
|
||||
qse_size_t mlen = sizeof(buf);
|
||||
|
||||
memset (buf, 'A', sizeof(buf));
|
||||
n = qse_wcstombs (x[i], buf, &mlen);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("[%s] chars=%d bytes=%d\n"), buf, (int)n, (int)mlen);
|
||||
#else
|
||||
qse_printf (QSE_T("[%S] chars=%d bytes=%d\n"), buf, (int)n, (int)mlen);
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("-----------------\n"));
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_size_t n;
|
||||
qse_size_t mlen = sizeof(buf2);
|
||||
|
||||
memset (buf2, 'A', sizeof(buf2));
|
||||
n = qse_wcstombs (x[i], buf2, &mlen);
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("[%s] chars=%d bytes=%d\n"), buf2, (int)n, (int)mlen);
|
||||
#else
|
||||
qse_printf (QSE_T("[%S] chars=%d bytes=%d\n"), buf2, (int)n, (int)mlen);
|
||||
#endif
|
||||
}
|
||||
|
||||
qse_printf (QSE_T("-----------------\n"));
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_size_t n;
|
||||
const qse_wchar_t* p = x[i];
|
||||
|
||||
while (1)
|
||||
{
|
||||
memset (buf, 'A', sizeof(buf));
|
||||
qse_size_t mlen = sizeof(buf);
|
||||
n = qse_wcstombs (p, buf, &mlen);
|
||||
if (n == 0) break;
|
||||
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("[%s] chars=%d bytes=%d\n"), buf, (int)n, (int)mlen);
|
||||
#else
|
||||
qse_printf (QSE_T("[%S] chars=%d bytes=%d\n"), buf, (int)n, (int)mlen);
|
||||
#endif
|
||||
p += n;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test9 (void)
|
||||
{
|
||||
char buf[24];
|
||||
int i;
|
||||
|
||||
const qse_wchar_t* x[] =
|
||||
{
|
||||
L"",
|
||||
L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",
|
||||
L"A\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",
|
||||
L"AB\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",
|
||||
L"ABC\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",
|
||||
L"ABCD\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?",
|
||||
L"ABCDEFGHIJKLMNOPQRSTUV",
|
||||
L"ABCDEFGHIJKLMNOPQRSTUVW",
|
||||
L"ABCDEFGHIJKLMNOPQRSTUVWX",
|
||||
L"ABCDEFGHIJKLMNOPQRSTUVWXY",
|
||||
L"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
};
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("[%S] => "), x[i]);
|
||||
#else
|
||||
qse_printf (QSE_T("[%s] => "), x[i]);
|
||||
#endif
|
||||
|
||||
if (qse_wcstombs_strict (x[i], buf, QSE_COUNTOF(buf)) == -1)
|
||||
{
|
||||
qse_printf (QSE_T("ERROR\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef QSE_CHAR_IS_MCHAR
|
||||
qse_printf (QSE_T("[%s]\n"), buf);
|
||||
#else
|
||||
qse_printf (QSE_T("[%S]\n"), buf);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test10 (void)
|
||||
{
|
||||
qse_char_t buf[1000];
|
||||
const qse_char_t* arg3[] =
|
||||
{
|
||||
QSE_T("00000"),
|
||||
QSE_T("11111"),
|
||||
QSE_T("22222")
|
||||
};
|
||||
|
||||
const qse_char_t* arg12[] =
|
||||
{
|
||||
QSE_T("00000"), QSE_T("11111"), QSE_T("22222"),
|
||||
QSE_T("33333"), QSE_T("44444"), QSE_T("55555"),
|
||||
QSE_T("66666"), QSE_T("77777"), QSE_T("88888"),
|
||||
QSE_T("99999"), QSE_T("aaaaa"), QSE_T("bbbbb")
|
||||
};
|
||||
|
||||
qse_strfcpy (buf, QSE_T("${2}${1}${0}"), arg3);
|
||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||
|
||||
qse_strfcpy (buf, QSE_T("${2}/${1}/${0}"), arg3);
|
||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||
|
||||
qse_strfcpy (buf, QSE_T("/${2}/${1}/${0}/"), arg3);
|
||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||
|
||||
qse_strfcpy (buf, QSE_T("/$${2}/$${1}/$${0}/"), arg3);
|
||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||
|
||||
qse_strfcpy (buf, QSE_T("/${2/${1}/${0}/"), arg3);
|
||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||
|
||||
qse_strfcpy (buf, QSE_T("/$2}/${1}/${0}/"), arg3);
|
||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||
|
||||
qse_strfcpy (buf, QSE_T("/${2}/${1}/${0}/${3}/${4}/${5}/${6}/${7}/${8}/${9}/${10}/${11}/"), arg12);
|
||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||
|
||||
qse_strfcpy (buf, QSE_T("/${2}/${1}/${0}/${0}/${1}/${2}/"), arg3);
|
||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||
|
||||
qse_strfcpy (buf, QSE_T("/${002}/${001}/${000}/"), arg3);
|
||||
qse_printf (QSE_T("buf=[%s]\n"), buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test11 (void)
|
||||
{
|
||||
qse_char_t buf[20];
|
||||
int i, j;
|
||||
|
||||
const qse_char_t* arg3[] =
|
||||
{
|
||||
QSE_T("00000"),
|
||||
QSE_T("11111"),
|
||||
QSE_T("22222")
|
||||
};
|
||||
|
||||
for (i = 0; i <= QSE_COUNTOF(buf); i++)
|
||||
{
|
||||
qse_strcpy (buf, QSE_T("AAAAAAAAAAAAAAAAAAA"));
|
||||
qse_strxfcpy (buf, i, QSE_T("${2}${1}${0}"), arg3);
|
||||
qse_printf (QSE_T("bufsize=%02d, buf=[%-20s] "), i, buf);
|
||||
|
||||
qse_printf (QSE_T("["));
|
||||
for (j = 0; j < QSE_COUNTOF(buf); j++)
|
||||
{
|
||||
if (buf[j] == QSE_T('\0')) qse_printf (QSE_T("*"));
|
||||
else qse_printf (QSE_T("%c"), buf[j]);
|
||||
}
|
||||
qse_printf (QSE_T("]\n"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test12 (void)
|
||||
{
|
||||
qse_char_t a1[] = QSE_T(" this is a test string ");
|
||||
qse_char_t a2[] = QSE_T(" this is a test string ");
|
||||
qse_char_t a3[] = QSE_T(" this is a test string ");
|
||||
|
||||
qse_printf (QSE_T("[%s] =>"), a1);
|
||||
qse_printf (QSE_T("[%s]\n"), qse_strtrm (a1, QSE_STRTRM_LEFT));
|
||||
|
||||
qse_printf (QSE_T("[%s] =>"), a2);
|
||||
qse_printf (QSE_T("[%s]\n"), qse_strtrm (a2, QSE_STRTRM_RIGHT));
|
||||
|
||||
qse_printf (QSE_T("[%s] =>"), a3);
|
||||
qse_printf (QSE_T("[%s]\n"),
|
||||
qse_strtrm (a3, QSE_STRTRM_LEFT|QSE_STRTRM_RIGHT));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test13 (void)
|
||||
{
|
||||
qse_char_t a1[] = QSE_T("abcdefghijklmnopqrstuvwxyz");
|
||||
qse_str_t x;
|
||||
int i;
|
||||
|
||||
qse_str_init (&x, QSE_MMGR_GETDFL(), 5);
|
||||
|
||||
for (i = 1; i < 20; i++)
|
||||
{
|
||||
qse_str_cpy (&x, a1);
|
||||
qse_str_del (&x, 10, i);
|
||||
qse_printf (QSE_T("deleleted %d from 10 => %llu [%s]\n"),
|
||||
i,
|
||||
(unsigned long long)QSE_STR_LEN(&x),
|
||||
QSE_STR_PTR(&x));
|
||||
}
|
||||
|
||||
qse_str_fini (&x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main ()
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
qse_printf (QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n"));
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
|
||||
R (test1);
|
||||
R (test2);
|
||||
R (test3);
|
||||
R (test4);
|
||||
R (test5);
|
||||
R (test6);
|
||||
R (test7);
|
||||
R (test8);
|
||||
R (test9);
|
||||
R (test10);
|
||||
R (test11);
|
||||
R (test12);
|
||||
R (test13);
|
||||
|
||||
return 0;
|
||||
}
|
124
qse/samples/cmn/time.c
Normal file
124
qse/samples/cmn/time.c
Normal file
@ -0,0 +1,124 @@
|
||||
#include <qse/cmn/time.h>
|
||||
#include <qse/cmn/stdio.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define R(f) \
|
||||
do { \
|
||||
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
||||
if (f() == -1) return -1; \
|
||||
} while (0)
|
||||
|
||||
void print_time (qse_ntime_t nt, const qse_btime_t* bt)
|
||||
{
|
||||
qse_printf (QSE_T("TIME: %lld\n"), (long long)nt);
|
||||
qse_printf (QSE_T("year: %d\n"), bt->year + QSE_BTIME_YEAR_BASE);
|
||||
qse_printf (QSE_T("mon: %d\n"), bt->mon + 1);
|
||||
qse_printf (QSE_T("mday: %d\n"), bt->mday);
|
||||
qse_printf (QSE_T("wday: %d\n"), bt->wday);
|
||||
qse_printf (QSE_T("hour: %d\n"), bt->hour);
|
||||
qse_printf (QSE_T("min: %d\n"), bt->min);
|
||||
qse_printf (QSE_T("sec: %d\n"), bt->sec);
|
||||
qse_printf (QSE_T("msec: %d\n"), bt->msec);
|
||||
}
|
||||
|
||||
static int test1 (void)
|
||||
{
|
||||
qse_ntime_t nt;
|
||||
qse_btime_t bt;
|
||||
|
||||
if (qse_gettime (&nt) == -1)
|
||||
{
|
||||
qse_printf (QSE_T("cannot get the current time\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qse_gmtime (nt, &bt);
|
||||
print_time (nt, &bt);
|
||||
qse_printf (QSE_T("-------------------------------\n"));
|
||||
|
||||
nt = 9999999;
|
||||
if (qse_timegm (&bt, &nt) == -1)
|
||||
{
|
||||
qse_printf (QSE_T("cannot covert back to ntime\n"));
|
||||
qse_printf (QSE_T("-------------------------------\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_printf (QSE_T("back to ntime: %lld\n"), (long long)nt);
|
||||
qse_gmtime (nt, &bt);
|
||||
print_time (nt, &bt);
|
||||
qse_printf (QSE_T("-------------------------------\n"));
|
||||
}
|
||||
|
||||
nt *= -1;
|
||||
qse_gmtime (nt, &bt);
|
||||
print_time (nt, &bt);
|
||||
qse_printf (QSE_T("-------------------------------\n"));
|
||||
|
||||
|
||||
for (nt = (qse_ntime_t)QSE_TYPE_MIN(int);
|
||||
nt <= (qse_ntime_t)QSE_TYPE_MAX(int); nt += QSE_SECS_PER_DAY)
|
||||
{
|
||||
time_t t = (time_t)nt;
|
||||
qse_ntime_t qnt = nt * 1000;
|
||||
struct tm* tm;
|
||||
|
||||
if (qnt >= 0) qnt += rand() % 1000;
|
||||
else qnt -= rand() % 1000;
|
||||
|
||||
tm = gmtime (&t);
|
||||
|
||||
qse_gmtime (qnt, &bt);
|
||||
qse_printf (QSE_T(">>> time %lld: "), (long long)qnt);
|
||||
|
||||
if (tm->tm_year != bt.year ||
|
||||
tm->tm_mon != bt.mon ||
|
||||
tm->tm_mday != bt.mday ||
|
||||
tm->tm_wday != bt.wday ||
|
||||
tm->tm_hour != bt.hour ||
|
||||
tm->tm_min != bt.min ||
|
||||
tm->tm_sec != bt.sec)
|
||||
{
|
||||
qse_printf (QSE_T("[GMTIME ERROR %lld]\n"), (long long)t);
|
||||
print_time (qnt, &bt);
|
||||
qse_printf (QSE_T("-------------------------------\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_ntime_t xx;
|
||||
|
||||
qse_printf (QSE_T("[GMTIME OK]"));
|
||||
|
||||
if (qse_timegm (&bt, &xx) == -1)
|
||||
{
|
||||
qse_printf (QSE_T("[TIMEGM FAIL]\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xx == qnt)
|
||||
qse_printf (QSE_T("[TIMEGM OK %d/%d/%d %d:%d:%d]\n"), bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
|
||||
else qse_printf (QSE_T("[TIMEGM ERROR %lld, %d/%d/%d %d:%d:%d]\n"), (long long)xx, bt.year + QSE_BTIME_YEAR_BASE, bt.mon + 1, bt.mday, bt.hour, bt.min, bt.sec);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
qse_printf (QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n"));
|
||||
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
|
||||
|
||||
R (test1);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user