removed the containing subdir
This commit is contained in:
109
mod/Makefile.am
Normal file
109
mod/Makefile.am
Normal file
@ -0,0 +1,109 @@
|
||||
AUTOMAKE_OPTIONS = nostdinc
|
||||
|
||||
CPPFLAGS_COMMON = \
|
||||
-I$(abs_builddir) \
|
||||
-I$(abs_builddir)/../lib \
|
||||
-I$(abs_srcdir) \
|
||||
-I$(abs_srcdir)/../lib \
|
||||
-I$(includedir)
|
||||
|
||||
if ENABLE_STATIC_MODULE
|
||||
|
||||
##################################################
|
||||
# STATIC MODULES BUILT INTO MAIN LIBRARY
|
||||
##################################################
|
||||
LDFLAGS_COMMON =-L$(libdir)
|
||||
LIBADD_COMMON =
|
||||
|
||||
noinst_LTLIBRARIES =
|
||||
|
||||
if ENABLE_MOD_CON
|
||||
noinst_LTLIBRARIES += libmoo-con.la
|
||||
endif
|
||||
|
||||
if ENABLE_MOD_FFI
|
||||
noinst_LTLIBRARIES += libmoo-ffi.la
|
||||
endif
|
||||
|
||||
noinst_LTLIBRARIES += libmoo-io.la
|
||||
|
||||
if ENABLE_MOD_SCK
|
||||
noinst_LTLIBRARIES += libmoo-sck.la
|
||||
endif
|
||||
|
||||
noinst_LTLIBRARIES += libmoo-stdio.la
|
||||
|
||||
if ENABLE_MOD_X11
|
||||
noinst_LTLIBRARIES += libmoo-x11.la
|
||||
endif
|
||||
|
||||
else
|
||||
|
||||
##################################################
|
||||
# DYNAMIC MODULES
|
||||
##################################################
|
||||
LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir) -version-info 1:0:0 -no-undefined
|
||||
LIBADD_COMMON = ../lib/libmoo.la
|
||||
|
||||
pkgmodexecdir = $(libdir)
|
||||
pkgmodexec_LTLIBRARIES =
|
||||
|
||||
if ENABLE_MOD_CON
|
||||
pkgmodexec_LTLIBRARIES += libmoo-con.la
|
||||
endif
|
||||
|
||||
if ENABLE_MOD_FFI
|
||||
pkgmodexec_LTLIBRARIES += libmoo-ffi.la
|
||||
endif
|
||||
|
||||
pkgmodexec_LTLIBRARIES += libmoo-io.la
|
||||
|
||||
if ENABLE_MOD_SCK
|
||||
pkgmodexec_LTLIBRARIES += libmoo-sck.la
|
||||
endif
|
||||
|
||||
pkgmodexec_LTLIBRARIES += libmoo-stdio.la
|
||||
|
||||
if ENABLE_MOD_X11
|
||||
pkgmodexec_LTLIBRARIES += libmoo-x11.la
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
if ENABLE_MOD_CON
|
||||
libmoo_con_la_SOURCES = _con.c _con.h
|
||||
libmoo_con_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libmoo_con_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libmoo_con_la_LIBADD = $(LIBADD_COMMON) $(TERMINAL_LIBS)
|
||||
endif
|
||||
|
||||
if ENABLE_MOD_FFI
|
||||
libmoo_ffi_la_SOURCES = ffi.c _ffi.h
|
||||
libmoo_ffi_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libmoo_ffi_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libmoo_ffi_la_LIBADD = $(LIBADD_COMMON) $(DYNCALL_LIBS) $(FFI_LIBS)
|
||||
endif
|
||||
|
||||
libmoo_io_la_SOURCES = io.c io-file.c _io.h
|
||||
libmoo_io_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libmoo_io_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libmoo_io_la_LIBADD = $(LIBADD_COMMON)
|
||||
|
||||
if ENABLE_MOD_SCK
|
||||
libmoo_sck_la_SOURCES = sck.c sck-addr.c _sck.h
|
||||
libmoo_sck_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libmoo_sck_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libmoo_sck_la_LIBADD = $(LIBADD_COMMON) $(SOCKET_LIBS)
|
||||
endif
|
||||
|
||||
libmoo_stdio_la_SOURCES = stdio.c _stdio.h
|
||||
libmoo_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libmoo_stdio_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libmoo_stdio_la_LIBADD = $(LIBADD_COMMON)
|
||||
|
||||
if ENABLE_MOD_X11
|
||||
libmoo_x11_la_SOURCES = x11.c _x11.h
|
||||
libmoo_x11_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libmoo_x11_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libmoo_x11_la_LIBADD = $(LIBADD_COMMON) -lX11
|
||||
endif
|
919
mod/Makefile.in
Normal file
919
mod/Makefile.in
Normal file
@ -0,0 +1,919 @@
|
||||
# Makefile.in generated by automake 1.16.1 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994-2018 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@
|
||||
am__is_gnu_make = { \
|
||||
if test -z '$(MAKELEVEL)'; then \
|
||||
false; \
|
||||
elif test -n '$(MAKE_HOST)'; then \
|
||||
true; \
|
||||
elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
|
||||
true; \
|
||||
else \
|
||||
false; \
|
||||
fi; \
|
||||
}
|
||||
am__make_running_with_option = \
|
||||
case $${target_option-} in \
|
||||
?) ;; \
|
||||
*) echo "am__make_running_with_option: internal error: invalid" \
|
||||
"target option '$${target_option-}' specified" >&2; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
has_opt=no; \
|
||||
sane_makeflags=$$MAKEFLAGS; \
|
||||
if $(am__is_gnu_make); then \
|
||||
sane_makeflags=$$MFLAGS; \
|
||||
else \
|
||||
case $$MAKEFLAGS in \
|
||||
*\\[\ \ ]*) \
|
||||
bs=\\; \
|
||||
sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
|
||||
| sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
|
||||
esac; \
|
||||
fi; \
|
||||
skip_next=no; \
|
||||
strip_trailopt () \
|
||||
{ \
|
||||
flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
|
||||
}; \
|
||||
for flg in $$sane_makeflags; do \
|
||||
test $$skip_next = yes && { skip_next=no; continue; }; \
|
||||
case $$flg in \
|
||||
*=*|--*) continue;; \
|
||||
-*I) strip_trailopt 'I'; skip_next=yes;; \
|
||||
-*I?*) strip_trailopt 'I';; \
|
||||
-*O) strip_trailopt 'O'; skip_next=yes;; \
|
||||
-*O?*) strip_trailopt 'O';; \
|
||||
-*l) strip_trailopt 'l'; skip_next=yes;; \
|
||||
-*l?*) strip_trailopt 'l';; \
|
||||
-[dEDm]) skip_next=yes;; \
|
||||
-[JT]) skip_next=yes;; \
|
||||
esac; \
|
||||
case $$flg in \
|
||||
*$$target_option*) has_opt=yes; break;; \
|
||||
esac; \
|
||||
done; \
|
||||
test $$has_opt = yes
|
||||
am__make_dryrun = (target_option=n; $(am__make_running_with_option))
|
||||
am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkglibexecdir = $(libexecdir)/@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@
|
||||
@ENABLE_MOD_CON_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_1 = libmoo-con.la
|
||||
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_2 = libmoo-ffi.la
|
||||
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_3 = libmoo-sck.la
|
||||
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am__append_4 = libmoo-x11.la
|
||||
@ENABLE_MOD_CON_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_5 = libmoo-con.la
|
||||
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_6 = libmoo-ffi.la
|
||||
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_7 = libmoo-sck.la
|
||||
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_FALSE@am__append_8 = libmoo-x11.la
|
||||
subdir = mod
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
|
||||
$(top_srcdir)/m4/ax_numval.m4 $(top_srcdir)/m4/ax_pthread.m4 \
|
||||
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
|
||||
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
|
||||
$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/lib/moo-cfg.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
CONFIG_CLEAN_VPATH_FILES =
|
||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||
am__vpath_adj = case $$p in \
|
||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
*) f=$$p;; \
|
||||
esac;
|
||||
am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
|
||||
am__install_max = 40
|
||||
am__nobase_strip_setup = \
|
||||
srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
|
||||
am__nobase_strip = \
|
||||
for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
|
||||
am__nobase_list = $(am__nobase_strip_setup); \
|
||||
for p in $$list; do echo "$$p $$p"; done | \
|
||||
sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
|
||||
$(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
|
||||
if (++n[$$2] == $(am__install_max)) \
|
||||
{ print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
|
||||
END { for (dir in files) print dir, files[dir] }'
|
||||
am__base_list = \
|
||||
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
|
||||
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
|
||||
am__uninstall_files_from_dir = { \
|
||||
test -z "$$files" \
|
||||
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|
||||
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
|
||||
$(am__cd) "$$dir" && rm -f $$files; }; \
|
||||
}
|
||||
am__installdirs = "$(DESTDIR)$(pkgmodexecdir)"
|
||||
LTLIBRARIES = $(noinst_LTLIBRARIES) $(pkgmodexec_LTLIBRARIES)
|
||||
@ENABLE_STATIC_MODULE_FALSE@am__DEPENDENCIES_1 = ../lib/libmoo.la
|
||||
am__DEPENDENCIES_2 =
|
||||
@ENABLE_MOD_CON_TRUE@libmoo_con_la_DEPENDENCIES = \
|
||||
@ENABLE_MOD_CON_TRUE@ $(am__DEPENDENCIES_1) \
|
||||
@ENABLE_MOD_CON_TRUE@ $(am__DEPENDENCIES_2)
|
||||
am__libmoo_con_la_SOURCES_DIST = _con.c _con.h
|
||||
@ENABLE_MOD_CON_TRUE@am_libmoo_con_la_OBJECTS = libmoo_con_la-_con.lo
|
||||
libmoo_con_la_OBJECTS = $(am_libmoo_con_la_OBJECTS)
|
||||
AM_V_lt = $(am__v_lt_@AM_V@)
|
||||
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
|
||||
am__v_lt_0 = --silent
|
||||
am__v_lt_1 =
|
||||
libmoo_con_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(libmoo_con_la_LDFLAGS) $(LDFLAGS) -o $@
|
||||
@ENABLE_MOD_CON_TRUE@@ENABLE_STATIC_MODULE_FALSE@am_libmoo_con_la_rpath = \
|
||||
@ENABLE_MOD_CON_TRUE@@ENABLE_STATIC_MODULE_FALSE@ -rpath \
|
||||
@ENABLE_MOD_CON_TRUE@@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
|
||||
@ENABLE_MOD_CON_TRUE@@ENABLE_STATIC_MODULE_TRUE@am_libmoo_con_la_rpath =
|
||||
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_DEPENDENCIES = \
|
||||
@ENABLE_MOD_FFI_TRUE@ $(am__DEPENDENCIES_1) \
|
||||
@ENABLE_MOD_FFI_TRUE@ $(am__DEPENDENCIES_2) \
|
||||
@ENABLE_MOD_FFI_TRUE@ $(am__DEPENDENCIES_2)
|
||||
am__libmoo_ffi_la_SOURCES_DIST = ffi.c _ffi.h
|
||||
@ENABLE_MOD_FFI_TRUE@am_libmoo_ffi_la_OBJECTS = libmoo_ffi_la-ffi.lo
|
||||
libmoo_ffi_la_OBJECTS = $(am_libmoo_ffi_la_OBJECTS)
|
||||
libmoo_ffi_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(libmoo_ffi_la_LDFLAGS) $(LDFLAGS) -o $@
|
||||
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_FALSE@am_libmoo_ffi_la_rpath = \
|
||||
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_FALSE@ -rpath \
|
||||
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
|
||||
@ENABLE_MOD_FFI_TRUE@@ENABLE_STATIC_MODULE_TRUE@am_libmoo_ffi_la_rpath =
|
||||
libmoo_io_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am_libmoo_io_la_OBJECTS = libmoo_io_la-io.lo libmoo_io_la-io-file.lo
|
||||
libmoo_io_la_OBJECTS = $(am_libmoo_io_la_OBJECTS)
|
||||
libmoo_io_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(libmoo_io_la_LDFLAGS) $(LDFLAGS) -o $@
|
||||
@ENABLE_STATIC_MODULE_FALSE@am_libmoo_io_la_rpath = -rpath \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
|
||||
@ENABLE_STATIC_MODULE_TRUE@am_libmoo_io_la_rpath =
|
||||
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_DEPENDENCIES = \
|
||||
@ENABLE_MOD_SCK_TRUE@ $(am__DEPENDENCIES_1) \
|
||||
@ENABLE_MOD_SCK_TRUE@ $(am__DEPENDENCIES_2)
|
||||
am__libmoo_sck_la_SOURCES_DIST = sck.c sck-addr.c _sck.h
|
||||
@ENABLE_MOD_SCK_TRUE@am_libmoo_sck_la_OBJECTS = libmoo_sck_la-sck.lo \
|
||||
@ENABLE_MOD_SCK_TRUE@ libmoo_sck_la-sck-addr.lo
|
||||
libmoo_sck_la_OBJECTS = $(am_libmoo_sck_la_OBJECTS)
|
||||
libmoo_sck_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(libmoo_sck_la_LDFLAGS) $(LDFLAGS) -o $@
|
||||
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_FALSE@am_libmoo_sck_la_rpath = \
|
||||
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_FALSE@ -rpath \
|
||||
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
|
||||
@ENABLE_MOD_SCK_TRUE@@ENABLE_STATIC_MODULE_TRUE@am_libmoo_sck_la_rpath =
|
||||
libmoo_stdio_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am_libmoo_stdio_la_OBJECTS = libmoo_stdio_la-stdio.lo
|
||||
libmoo_stdio_la_OBJECTS = $(am_libmoo_stdio_la_OBJECTS)
|
||||
libmoo_stdio_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
|
||||
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
|
||||
$(AM_CFLAGS) $(CFLAGS) $(libmoo_stdio_la_LDFLAGS) $(LDFLAGS) \
|
||||
-o $@
|
||||
@ENABLE_STATIC_MODULE_FALSE@am_libmoo_stdio_la_rpath = -rpath \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
|
||||
@ENABLE_STATIC_MODULE_TRUE@am_libmoo_stdio_la_rpath =
|
||||
@ENABLE_MOD_X11_TRUE@libmoo_x11_la_DEPENDENCIES = \
|
||||
@ENABLE_MOD_X11_TRUE@ $(am__DEPENDENCIES_1)
|
||||
am__libmoo_x11_la_SOURCES_DIST = x11.c _x11.h
|
||||
@ENABLE_MOD_X11_TRUE@am_libmoo_x11_la_OBJECTS = libmoo_x11_la-x11.lo
|
||||
libmoo_x11_la_OBJECTS = $(am_libmoo_x11_la_OBJECTS)
|
||||
libmoo_x11_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(libmoo_x11_la_LDFLAGS) $(LDFLAGS) -o $@
|
||||
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_FALSE@am_libmoo_x11_la_rpath = \
|
||||
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_FALSE@ -rpath \
|
||||
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
|
||||
@ENABLE_MOD_X11_TRUE@@ENABLE_STATIC_MODULE_TRUE@am_libmoo_x11_la_rpath =
|
||||
AM_V_P = $(am__v_P_@AM_V@)
|
||||
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
||||
am__v_P_0 = false
|
||||
am__v_P_1 = :
|
||||
AM_V_GEN = $(am__v_GEN_@AM_V@)
|
||||
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
|
||||
am__v_GEN_0 = @echo " GEN " $@;
|
||||
am__v_GEN_1 =
|
||||
AM_V_at = $(am__v_at_@AM_V@)
|
||||
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
|
||||
am__v_at_0 = @
|
||||
am__v_at_1 =
|
||||
DEFAULT_INCLUDES =
|
||||
depcomp = $(SHELL) $(top_srcdir)/ac/depcomp
|
||||
am__maybe_remake_depfiles = depfiles
|
||||
am__depfiles_remade = ./$(DEPDIR)/libmoo_con_la-_con.Plo \
|
||||
./$(DEPDIR)/libmoo_ffi_la-ffi.Plo \
|
||||
./$(DEPDIR)/libmoo_io_la-io-file.Plo \
|
||||
./$(DEPDIR)/libmoo_io_la-io.Plo \
|
||||
./$(DEPDIR)/libmoo_sck_la-sck-addr.Plo \
|
||||
./$(DEPDIR)/libmoo_sck_la-sck.Plo \
|
||||
./$(DEPDIR)/libmoo_stdio_la-stdio.Plo \
|
||||
./$(DEPDIR)/libmoo_x11_la-x11.Plo
|
||||
am__mv = mv -f
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
|
||||
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
|
||||
$(AM_CFLAGS) $(CFLAGS)
|
||||
AM_V_CC = $(am__v_CC_@AM_V@)
|
||||
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
|
||||
am__v_CC_0 = @echo " CC " $@;
|
||||
am__v_CC_1 =
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
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 = $(libmoo_con_la_SOURCES) $(libmoo_ffi_la_SOURCES) \
|
||||
$(libmoo_io_la_SOURCES) $(libmoo_sck_la_SOURCES) \
|
||||
$(libmoo_stdio_la_SOURCES) $(libmoo_x11_la_SOURCES)
|
||||
DIST_SOURCES = $(am__libmoo_con_la_SOURCES_DIST) \
|
||||
$(am__libmoo_ffi_la_SOURCES_DIST) $(libmoo_io_la_SOURCES) \
|
||||
$(am__libmoo_sck_la_SOURCES_DIST) $(libmoo_stdio_la_SOURCES) \
|
||||
$(am__libmoo_x11_la_SOURCES_DIST)
|
||||
am__can_run_installinfo = \
|
||||
case $$AM_UPDATE_INFO_DIR in \
|
||||
n|no|NO) false;; \
|
||||
*) (install-info --version) >/dev/null 2>&1;; \
|
||||
esac
|
||||
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
|
||||
# Read a list of newline-separated strings from the standard input,
|
||||
# and print each of them once, without duplicates. Input order is
|
||||
# *not* preserved.
|
||||
am__uniquify_input = $(AWK) '\
|
||||
BEGIN { nonempty = 0; } \
|
||||
{ items[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in items) print i; }; } \
|
||||
'
|
||||
# Make sure the list of sources is unique. This is necessary because,
|
||||
# e.g., the same source file might be shared among _SOURCES variables
|
||||
# for different programs/libraries.
|
||||
am__define_uniq_tagged_files = \
|
||||
list='$(am__tagged_files)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | $(am__uniquify_input)`
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/ac/depcomp
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMTAR = @AMTAR@
|
||||
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
|
||||
AR = @AR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
BUILD_MODE = @BUILD_MODE@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DLLTOOL = @DLLTOOL@
|
||||
DL_LIBS = @DL_LIBS@
|
||||
DSYMUTIL = @DSYMUTIL@
|
||||
DUMPBIN = @DUMPBIN@
|
||||
DYNCALL_LIBS = @DYNCALL_LIBS@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
FFI_LIBS = @FFI_LIBS@
|
||||
FGREP = @FGREP@
|
||||
GREP = @GREP@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LD = @LD@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBM = @LIBM@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LIBTOOL_DEPS = @LIBTOOL_DEPS@
|
||||
LIPO = @LIPO@
|
||||
LN_S = @LN_S@
|
||||
LTDL_LIBS = @LTDL_LIBS@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MANIFEST_TOOL = @MANIFEST_TOOL@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
MOO_PROJECT_AUTHOR = @MOO_PROJECT_AUTHOR@
|
||||
MOO_PROJECT_URL = @MOO_PROJECT_URL@
|
||||
NM = @NM@
|
||||
NMEDIT = @NMEDIT@
|
||||
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_URL = @PACKAGE_URL@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PACKAGE_VERSION_MAJOR = @PACKAGE_VERSION_MAJOR@
|
||||
PACKAGE_VERSION_MINOR = @PACKAGE_VERSION_MINOR@
|
||||
PACKAGE_VERSION_PATCH = @PACKAGE_VERSION_PATCH@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
PTHREAD_CC = @PTHREAD_CC@
|
||||
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
|
||||
PTHREAD_LIBS = @PTHREAD_LIBS@
|
||||
QUADMATH_LIBS = @QUADMATH_LIBS@
|
||||
RANLIB = @RANLIB@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
SOCKET_LIBS = @SOCKET_LIBS@
|
||||
STRIP = @STRIP@
|
||||
TERMINAL_LIBS = @TERMINAL_LIBS@
|
||||
UNICOWS_LIBS = @UNICOWS_LIBS@
|
||||
UNWIND_LIBS = @UNWIND_LIBS@
|
||||
VERSION = @VERSION@
|
||||
abs_builddir = @abs_builddir@
|
||||
abs_srcdir = @abs_srcdir@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
abs_top_srcdir = @abs_top_srcdir@
|
||||
ac_ct_AR = @ac_ct_AR@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
ax_pthread_config = @ax_pthread_config@
|
||||
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@
|
||||
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@
|
||||
AUTOMAKE_OPTIONS = nostdinc
|
||||
CPPFLAGS_COMMON = \
|
||||
-I$(abs_builddir) \
|
||||
-I$(abs_builddir)/../lib \
|
||||
-I$(abs_srcdir) \
|
||||
-I$(abs_srcdir)/../lib \
|
||||
-I$(includedir)
|
||||
|
||||
|
||||
##################################################
|
||||
# DYNAMIC MODULES
|
||||
##################################################
|
||||
@ENABLE_STATIC_MODULE_FALSE@LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir) -version-info 1:0:0 -no-undefined
|
||||
|
||||
##################################################
|
||||
# STATIC MODULES BUILT INTO MAIN LIBRARY
|
||||
##################################################
|
||||
@ENABLE_STATIC_MODULE_TRUE@LDFLAGS_COMMON = -L$(libdir)
|
||||
@ENABLE_STATIC_MODULE_FALSE@LIBADD_COMMON = ../lib/libmoo.la
|
||||
@ENABLE_STATIC_MODULE_TRUE@LIBADD_COMMON =
|
||||
@ENABLE_STATIC_MODULE_TRUE@noinst_LTLIBRARIES = $(am__append_1) \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_2) libmoo-io.la \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_3) libmoo-stdio.la \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ $(am__append_4)
|
||||
@ENABLE_STATIC_MODULE_FALSE@pkgmodexecdir = $(libdir)
|
||||
@ENABLE_STATIC_MODULE_FALSE@pkgmodexec_LTLIBRARIES = $(am__append_5) \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ $(am__append_6) libmoo-io.la \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ $(am__append_7) libmoo-stdio.la \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ $(am__append_8)
|
||||
@ENABLE_MOD_CON_TRUE@libmoo_con_la_SOURCES = _con.c _con.h
|
||||
@ENABLE_MOD_CON_TRUE@libmoo_con_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
@ENABLE_MOD_CON_TRUE@libmoo_con_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
@ENABLE_MOD_CON_TRUE@libmoo_con_la_LIBADD = $(LIBADD_COMMON) $(TERMINAL_LIBS)
|
||||
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_SOURCES = ffi.c _ffi.h
|
||||
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
@ENABLE_MOD_FFI_TRUE@libmoo_ffi_la_LIBADD = $(LIBADD_COMMON) $(DYNCALL_LIBS) $(FFI_LIBS)
|
||||
libmoo_io_la_SOURCES = io.c io-file.c _io.h
|
||||
libmoo_io_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libmoo_io_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libmoo_io_la_LIBADD = $(LIBADD_COMMON)
|
||||
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_SOURCES = sck.c sck-addr.c _sck.h
|
||||
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
@ENABLE_MOD_SCK_TRUE@libmoo_sck_la_LIBADD = $(LIBADD_COMMON) $(SOCKET_LIBS)
|
||||
libmoo_stdio_la_SOURCES = stdio.c _stdio.h
|
||||
libmoo_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libmoo_stdio_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libmoo_stdio_la_LIBADD = $(LIBADD_COMMON)
|
||||
@ENABLE_MOD_X11_TRUE@libmoo_x11_la_SOURCES = x11.c _x11.h
|
||||
@ENABLE_MOD_X11_TRUE@libmoo_x11_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
@ENABLE_MOD_X11_TRUE@libmoo_x11_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
@ENABLE_MOD_X11_TRUE@libmoo_x11_la_LIBADD = $(LIBADD_COMMON) -lX11
|
||||
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 mod/Makefile'; \
|
||||
$(am__cd) $(top_srcdir) && \
|
||||
$(AUTOMAKE) --foreign mod/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__maybe_remake_depfiles)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
|
||||
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
|
||||
$(am__aclocal_m4_deps):
|
||||
|
||||
clean-noinstLTLIBRARIES:
|
||||
-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
|
||||
@list='$(noinst_LTLIBRARIES)'; \
|
||||
locs=`for p in $$list; do echo $$p; done | \
|
||||
sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
|
||||
sort -u`; \
|
||||
test -z "$$locs" || { \
|
||||
echo rm -f $${locs}; \
|
||||
rm -f $${locs}; \
|
||||
}
|
||||
|
||||
install-pkgmodexecLTLIBRARIES: $(pkgmodexec_LTLIBRARIES)
|
||||
@$(NORMAL_INSTALL)
|
||||
@list='$(pkgmodexec_LTLIBRARIES)'; test -n "$(pkgmodexecdir)" || list=; \
|
||||
list2=; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
list2="$$list2 $$p"; \
|
||||
else :; fi; \
|
||||
done; \
|
||||
test -z "$$list2" || { \
|
||||
echo " $(MKDIR_P) '$(DESTDIR)$(pkgmodexecdir)'"; \
|
||||
$(MKDIR_P) "$(DESTDIR)$(pkgmodexecdir)" || exit 1; \
|
||||
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(pkgmodexecdir)'"; \
|
||||
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(pkgmodexecdir)"; \
|
||||
}
|
||||
|
||||
uninstall-pkgmodexecLTLIBRARIES:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(pkgmodexec_LTLIBRARIES)'; test -n "$(pkgmodexecdir)" || list=; \
|
||||
for p in $$list; do \
|
||||
$(am__strip_dir) \
|
||||
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(pkgmodexecdir)/$$f'"; \
|
||||
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(pkgmodexecdir)/$$f"; \
|
||||
done
|
||||
|
||||
clean-pkgmodexecLTLIBRARIES:
|
||||
-test -z "$(pkgmodexec_LTLIBRARIES)" || rm -f $(pkgmodexec_LTLIBRARIES)
|
||||
@list='$(pkgmodexec_LTLIBRARIES)'; \
|
||||
locs=`for p in $$list; do echo $$p; done | \
|
||||
sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
|
||||
sort -u`; \
|
||||
test -z "$$locs" || { \
|
||||
echo rm -f $${locs}; \
|
||||
rm -f $${locs}; \
|
||||
}
|
||||
|
||||
libmoo-con.la: $(libmoo_con_la_OBJECTS) $(libmoo_con_la_DEPENDENCIES) $(EXTRA_libmoo_con_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(libmoo_con_la_LINK) $(am_libmoo_con_la_rpath) $(libmoo_con_la_OBJECTS) $(libmoo_con_la_LIBADD) $(LIBS)
|
||||
|
||||
libmoo-ffi.la: $(libmoo_ffi_la_OBJECTS) $(libmoo_ffi_la_DEPENDENCIES) $(EXTRA_libmoo_ffi_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(libmoo_ffi_la_LINK) $(am_libmoo_ffi_la_rpath) $(libmoo_ffi_la_OBJECTS) $(libmoo_ffi_la_LIBADD) $(LIBS)
|
||||
|
||||
libmoo-io.la: $(libmoo_io_la_OBJECTS) $(libmoo_io_la_DEPENDENCIES) $(EXTRA_libmoo_io_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(libmoo_io_la_LINK) $(am_libmoo_io_la_rpath) $(libmoo_io_la_OBJECTS) $(libmoo_io_la_LIBADD) $(LIBS)
|
||||
|
||||
libmoo-sck.la: $(libmoo_sck_la_OBJECTS) $(libmoo_sck_la_DEPENDENCIES) $(EXTRA_libmoo_sck_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(libmoo_sck_la_LINK) $(am_libmoo_sck_la_rpath) $(libmoo_sck_la_OBJECTS) $(libmoo_sck_la_LIBADD) $(LIBS)
|
||||
|
||||
libmoo-stdio.la: $(libmoo_stdio_la_OBJECTS) $(libmoo_stdio_la_DEPENDENCIES) $(EXTRA_libmoo_stdio_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(libmoo_stdio_la_LINK) $(am_libmoo_stdio_la_rpath) $(libmoo_stdio_la_OBJECTS) $(libmoo_stdio_la_LIBADD) $(LIBS)
|
||||
|
||||
libmoo-x11.la: $(libmoo_x11_la_OBJECTS) $(libmoo_x11_la_DEPENDENCIES) $(EXTRA_libmoo_x11_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(libmoo_x11_la_LINK) $(am_libmoo_x11_la_rpath) $(libmoo_x11_la_OBJECTS) $(libmoo_x11_la_LIBADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_con_la-_con.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_ffi_la-ffi.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_io_la-io-file.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_io_la-io.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_sck_la-sck-addr.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_sck_la-sck.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_stdio_la-stdio.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_x11_la-x11.Plo@am__quote@ # am--include-marker
|
||||
|
||||
$(am__depfiles_remade):
|
||||
@$(MKDIR_P) $(@D)
|
||||
@echo '# dummy' >$@-t && $(am__mv) $@-t $@
|
||||
|
||||
am--depfiles: $(am__depfiles_remade)
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
|
||||
|
||||
.c.obj:
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
|
||||
.c.lo:
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
|
||||
@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
libmoo_con_la-_con.lo: _con.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_con_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_con_la-_con.lo -MD -MP -MF $(DEPDIR)/libmoo_con_la-_con.Tpo -c -o libmoo_con_la-_con.lo `test -f '_con.c' || echo '$(srcdir)/'`_con.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_con_la-_con.Tpo $(DEPDIR)/libmoo_con_la-_con.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='_con.c' object='libmoo_con_la-_con.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_con_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_con_la-_con.lo `test -f '_con.c' || echo '$(srcdir)/'`_con.c
|
||||
|
||||
libmoo_ffi_la-ffi.lo: ffi.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_ffi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_ffi_la-ffi.lo -MD -MP -MF $(DEPDIR)/libmoo_ffi_la-ffi.Tpo -c -o libmoo_ffi_la-ffi.lo `test -f 'ffi.c' || echo '$(srcdir)/'`ffi.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_ffi_la-ffi.Tpo $(DEPDIR)/libmoo_ffi_la-ffi.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ffi.c' object='libmoo_ffi_la-ffi.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_ffi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_ffi_la-ffi.lo `test -f 'ffi.c' || echo '$(srcdir)/'`ffi.c
|
||||
|
||||
libmoo_io_la-io.lo: io.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_io_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_io_la-io.lo -MD -MP -MF $(DEPDIR)/libmoo_io_la-io.Tpo -c -o libmoo_io_la-io.lo `test -f 'io.c' || echo '$(srcdir)/'`io.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_io_la-io.Tpo $(DEPDIR)/libmoo_io_la-io.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='io.c' object='libmoo_io_la-io.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_io_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_io_la-io.lo `test -f 'io.c' || echo '$(srcdir)/'`io.c
|
||||
|
||||
libmoo_io_la-io-file.lo: io-file.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_io_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_io_la-io-file.lo -MD -MP -MF $(DEPDIR)/libmoo_io_la-io-file.Tpo -c -o libmoo_io_la-io-file.lo `test -f 'io-file.c' || echo '$(srcdir)/'`io-file.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_io_la-io-file.Tpo $(DEPDIR)/libmoo_io_la-io-file.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='io-file.c' object='libmoo_io_la-io-file.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_io_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_io_la-io-file.lo `test -f 'io-file.c' || echo '$(srcdir)/'`io-file.c
|
||||
|
||||
libmoo_sck_la-sck.lo: sck.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_sck_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_sck_la-sck.lo -MD -MP -MF $(DEPDIR)/libmoo_sck_la-sck.Tpo -c -o libmoo_sck_la-sck.lo `test -f 'sck.c' || echo '$(srcdir)/'`sck.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_sck_la-sck.Tpo $(DEPDIR)/libmoo_sck_la-sck.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='sck.c' object='libmoo_sck_la-sck.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_sck_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_sck_la-sck.lo `test -f 'sck.c' || echo '$(srcdir)/'`sck.c
|
||||
|
||||
libmoo_sck_la-sck-addr.lo: sck-addr.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_sck_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_sck_la-sck-addr.lo -MD -MP -MF $(DEPDIR)/libmoo_sck_la-sck-addr.Tpo -c -o libmoo_sck_la-sck-addr.lo `test -f 'sck-addr.c' || echo '$(srcdir)/'`sck-addr.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_sck_la-sck-addr.Tpo $(DEPDIR)/libmoo_sck_la-sck-addr.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='sck-addr.c' object='libmoo_sck_la-sck-addr.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_sck_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_sck_la-sck-addr.lo `test -f 'sck-addr.c' || echo '$(srcdir)/'`sck-addr.c
|
||||
|
||||
libmoo_stdio_la-stdio.lo: stdio.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_stdio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_stdio_la-stdio.lo -MD -MP -MF $(DEPDIR)/libmoo_stdio_la-stdio.Tpo -c -o libmoo_stdio_la-stdio.lo `test -f 'stdio.c' || echo '$(srcdir)/'`stdio.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_stdio_la-stdio.Tpo $(DEPDIR)/libmoo_stdio_la-stdio.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stdio.c' object='libmoo_stdio_la-stdio.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_stdio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_stdio_la-stdio.lo `test -f 'stdio.c' || echo '$(srcdir)/'`stdio.c
|
||||
|
||||
libmoo_x11_la-x11.lo: x11.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_x11_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_x11_la-x11.lo -MD -MP -MF $(DEPDIR)/libmoo_x11_la-x11.Tpo -c -o libmoo_x11_la-x11.lo `test -f 'x11.c' || echo '$(srcdir)/'`x11.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_x11_la-x11.Tpo $(DEPDIR)/libmoo_x11_la-x11.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='x11.c' object='libmoo_x11_la-x11.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_x11_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_x11_la-x11.lo `test -f 'x11.c' || echo '$(srcdir)/'`x11.c
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
|
||||
ID: $(am__tagged_files)
|
||||
$(am__define_uniq_tagged_files); mkid -fID $$unique
|
||||
tags: tags-am
|
||||
TAGS: tags
|
||||
|
||||
tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
|
||||
set x; \
|
||||
here=`pwd`; \
|
||||
$(am__define_uniq_tagged_files); \
|
||||
shift; \
|
||||
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
if test $$# -gt 0; then \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
"$$@" $$unique; \
|
||||
else \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$unique; \
|
||||
fi; \
|
||||
fi
|
||||
ctags: ctags-am
|
||||
|
||||
CTAGS: ctags
|
||||
ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
|
||||
$(am__define_uniq_tagged_files); \
|
||||
test -z "$(CTAGS_ARGS)$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& $(am__cd) $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) "$$here"
|
||||
cscopelist: cscopelist-am
|
||||
|
||||
cscopelist-am: $(am__tagged_files)
|
||||
list='$(am__tagged_files)'; \
|
||||
case "$(srcdir)" in \
|
||||
[\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
|
||||
*) sdir=$(subdir)/$(srcdir) ;; \
|
||||
esac; \
|
||||
for i in $$list; do \
|
||||
if test -f "$$i"; then \
|
||||
echo "$(subdir)/$$i"; \
|
||||
else \
|
||||
echo "$$sdir/$$i"; \
|
||||
fi; \
|
||||
done >> $(top_builddir)/cscope.files
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(BUILT_SOURCES)
|
||||
$(MAKE) $(AM_MAKEFLAGS) distdir-am
|
||||
|
||||
distdir-am: $(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 "$(distdir)/$$file"; then \
|
||||
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
|
||||
fi; \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
|
||||
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
|
||||
fi; \
|
||||
cp -fpR $$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 $(LTLIBRARIES)
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(pkgmodexecdir)"; 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:
|
||||
if test -z '$(STRIP)'; then \
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
install; \
|
||||
else \
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
|
||||
fi
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_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-generic clean-libtool clean-noinstLTLIBRARIES \
|
||||
clean-pkgmodexecLTLIBRARIES mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -f ./$(DEPDIR)/libmoo_con_la-_con.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_ffi_la-ffi.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_io_la-io-file.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_io_la-io.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_sck_la-sck-addr.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_sck_la-sck.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_stdio_la-stdio.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_x11_la-x11.Plo
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
html-am:
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am:
|
||||
|
||||
install-dvi: install-dvi-am
|
||||
|
||||
install-dvi-am:
|
||||
|
||||
install-exec-am: install-pkgmodexecLTLIBRARIES
|
||||
|
||||
install-html: install-html-am
|
||||
|
||||
install-html-am:
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-info-am:
|
||||
|
||||
install-man:
|
||||
|
||||
install-pdf: install-pdf-am
|
||||
|
||||
install-pdf-am:
|
||||
|
||||
install-ps: install-ps-am
|
||||
|
||||
install-ps-am:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -f ./$(DEPDIR)/libmoo_con_la-_con.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_ffi_la-ffi.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_io_la-io-file.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_io_la-io.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_sck_la-sck-addr.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_sck_la-sck.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_stdio_la-stdio.Plo
|
||||
-rm -f ./$(DEPDIR)/libmoo_x11_la-x11.Plo
|
||||
-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-pkgmodexecLTLIBRARIES
|
||||
|
||||
.MAKE: install-am install-strip
|
||||
|
||||
.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
|
||||
clean-generic clean-libtool clean-noinstLTLIBRARIES \
|
||||
clean-pkgmodexecLTLIBRARIES cscopelist-am ctags ctags-am \
|
||||
distclean distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags distdir dvi dvi-am html \
|
||||
html-am info info-am install install-am 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-pkgmodexecLTLIBRARIES 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 tags-am uninstall uninstall-am \
|
||||
uninstall-pkgmodexecLTLIBRARIES
|
||||
|
||||
.PRECIOUS: Makefile
|
||||
|
||||
|
||||
# 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:
|
293
mod/_con.c
Normal file
293
mod/_con.c
Normal file
@ -0,0 +1,293 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2017 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 "_con.h"
|
||||
#include <moo-utl.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <windows.h>
|
||||
#elif defined(__DOS__)
|
||||
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
# include <stdlib.h> /* getenv */
|
||||
# include <curses.h>
|
||||
# include <term.h>
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
typedef struct console_t console_t;
|
||||
struct console_t
|
||||
{
|
||||
int fd;
|
||||
int fd_opened;
|
||||
char* cup;
|
||||
char* clear;
|
||||
};
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
static moo_pfrc_t pf_open (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
HANDLE h;
|
||||
moo_ooi_t immv;
|
||||
|
||||
h = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (h == INVALID_HANDLE_VALUE) return 0;
|
||||
if (h == NULL)
|
||||
{
|
||||
/* the program doens't have an associated handle for stdin. is it a service? */
|
||||
}
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMPTR_TO_OOP(h));
|
||||
|
||||
#elif defined(__DOS__)
|
||||
moo->errnum = MOO_ENOIMPL;
|
||||
return -1;
|
||||
#else
|
||||
|
||||
console_t* con;
|
||||
int err;
|
||||
char* term;
|
||||
|
||||
con = (console_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
|
||||
|
||||
if (isatty(1))
|
||||
{
|
||||
con->fd = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
con->fd = open("/dev/tty", O_RDWR, 0);
|
||||
if (con->fd == -1)
|
||||
{
|
||||
/* TODO: failed to open /dev/stdout */
|
||||
moo_freemem (moo, con);
|
||||
return 0;
|
||||
}
|
||||
|
||||
con->fd_opened = 1;
|
||||
}
|
||||
|
||||
term = getenv("TERM");
|
||||
if (term && setupterm(term, con->fd, &err) == OK)
|
||||
{
|
||||
}
|
||||
|
||||
con->cup = tigetstr("cup"); /* TODO: error check */
|
||||
con->clear = tigetstr("clear");
|
||||
|
||||
#if 0
|
||||
{
|
||||
const char* cup, * clear;
|
||||
struct winsize wsz;
|
||||
|
||||
cup = tigetstr ("cup");
|
||||
clear = tigetstr ("clear");
|
||||
ioctl (fd, TIOCGWINSZ, &wsz);
|
||||
|
||||
write (fd, clear, strlen(clear));
|
||||
/*write (fd, tparm (cup, wsz.ws_row - 1, 0), strlen(tparm (cup, wsz.ws_row - 1, 0)));*/
|
||||
/*write (fd, tiparm (cup, 0, 0), strlen(tiparm (cup, 0, 0)));*/
|
||||
write (fd, tparm (cup, 0, 0, 0, 0, 0, 0, 0, 0, 0), strlen(tparm (cup, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
|
||||
}
|
||||
#endif
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(con->fd));
|
||||
#endif
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_close (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
moo_oop_t arg;
|
||||
HANDLE h;
|
||||
|
||||
con = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
h = MOO_OOP_TO_SMPTR(con);
|
||||
|
||||
/*if (h != XXX)
|
||||
{
|
||||
CloseHandle (h);
|
||||
}*/
|
||||
#elif defined(__DOS__)
|
||||
|
||||
/* TODO */
|
||||
|
||||
#else
|
||||
console_t* con;
|
||||
|
||||
con = (console_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
|
||||
|
||||
if (con->fd_opened) close (con->fd);
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_write (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
/* TODO: */
|
||||
#elif defined(__DOS__)
|
||||
/* TODO: */
|
||||
#else
|
||||
console_t* con;
|
||||
moo_oop_char_t msg;
|
||||
|
||||
moo_oow_t ucspos, ucsrem, ucslen, bcslen;
|
||||
moo_bch_t bcs[1024];
|
||||
int n;
|
||||
|
||||
con = (console_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
|
||||
msg = (moo_oop_char_t)MOO_STACK_GETARG (moo, nargs, 0);
|
||||
|
||||
if (!MOO_OBJ_IS_CHAR_POINTER(msg)) goto einval;
|
||||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
ucspos = 0;
|
||||
ucsrem = MOO_OBJ_GET_SIZE(msg);
|
||||
while (ucsrem > 0)
|
||||
{
|
||||
ucslen = ucsrem;
|
||||
bcslen = MOO_COUNTOF(bcs);
|
||||
if ((n = moo_convootobchars(moo, &msg->slot[ucspos], &ucslen, bcs, &bcslen)) <= -1)
|
||||
{
|
||||
if (n != -2 || ucslen <= 0) return MOO_PF_HARD_FAILURE;
|
||||
}
|
||||
|
||||
write (con->fd, bcs, bcslen); /* TODO: error handling */
|
||||
/* TODO: abort looping for async processing???? */
|
||||
ucspos += ucslen;
|
||||
ucsrem -= ucslen;
|
||||
}
|
||||
#else
|
||||
write (con->fd, MOO_OBJ_GET_CHAR_SLOT(msg), MOO_OBJ_GET_SIZE(msg)); /* TODO: error handling. incomplete write handling */
|
||||
#endif
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs); /* TODO: change return code */
|
||||
return MOO_PF_SUCCESS;
|
||||
|
||||
einval:
|
||||
MOO_STACK_SETRETTOERRNUM (moo, nargs); /* TODO: be more specific about the error code */
|
||||
return MOO_PF_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_clear (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
#elif defined(__DOS__)
|
||||
|
||||
#else
|
||||
console_t* con;
|
||||
|
||||
con = (console_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
|
||||
|
||||
write (con->fd, con->clear, strlen(con->clear));
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_setcursor (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
#elif defined(__DOS__)
|
||||
|
||||
#else
|
||||
console_t* con;
|
||||
moo_oop_t x, y;
|
||||
char* cup;
|
||||
|
||||
con = (console_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
|
||||
x = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
y = MOO_STACK_GETARG(moo, nargs, 1);
|
||||
|
||||
if (!MOO_OOP_IS_SMOOI(x) || !MOO_OOP_IS_SMOOI(y)) goto einval;
|
||||
|
||||
/*cup = tiparm (con->cup, MOO_OOP_TO_SMOOI(y), MOO_OOP_TO_SMOOI(x));*/
|
||||
cup = tparm (con->cup, MOO_OOP_TO_SMOOI(y), MOO_OOP_TO_SMOOI(x), 0, 0, 0, 0, 0, 0, 0);
|
||||
write (con->fd, cup, strlen(cup)); /* TODO: error check */
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
|
||||
einval:
|
||||
MOO_STACK_SETRETTOERRNUM (moo, nargs); /* TODO: be more specific about the error code */
|
||||
return MOO_PF_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
#define C MOO_METHOD_CLASS
|
||||
#define I MOO_METHOD_INSTANCE
|
||||
|
||||
static moo_pfinfo_t pfinfos[] =
|
||||
{
|
||||
{ I, "clear", { pf_clear, 0, 0 } },
|
||||
{ I, "close", { pf_close, 0, 0 } },
|
||||
{ I, "open", { pf_open, 0, 0 } },
|
||||
{ I, "setcursor", { pf_setcursor, 2, 2 } },
|
||||
{ I, "write", { pf_write, 1, 1 } }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
|
||||
{
|
||||
if (moo_setclasstrsize(moo, _class, MOO_SIZEOF(console_t), MOO_NULL) <= -1) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static moo_pfbase_t* querypf (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
|
||||
{
|
||||
return moo_findpfbase(moo, pfinfos, MOO_COUNTOF(pfinfos), name, namelen);
|
||||
}
|
||||
|
||||
|
||||
static void unload (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
/* TODO: close all open handle?? */
|
||||
}
|
||||
|
||||
int moo_mod_con (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
mod->import = import;
|
||||
mod->querypf = querypf;
|
||||
mod->querypv = MOO_NULL;
|
||||
mod->unload = unload;
|
||||
mod->ctx = MOO_NULL;
|
||||
return 0;
|
||||
}
|
43
mod/_con.h
Normal file
43
mod/_con.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2017 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _MOO_MOD_CON_H_
|
||||
#define _MOO_MOD_CON_H_
|
||||
|
||||
#include <moo.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MOO_EXPORT int moo_mod_con (moo_t* moo, moo_mod_t* mod);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
43
mod/_ffi.h
Normal file
43
mod/_ffi.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2017 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _MOO_MOD_FFI_H_
|
||||
#define _MOO_MOD_FFI_H_
|
||||
|
||||
#include <moo.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MOO_EXPORT int moo_mod_ffi (moo_t* moo, moo_mod_t* mod);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
52
mod/_io.h
Normal file
52
mod/_io.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2019 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _MOO_MOD_IO_H_
|
||||
#define _MOO_MOD_IO_H_
|
||||
|
||||
#include <moo.h>
|
||||
|
||||
typedef struct io_t* oop_io_t;
|
||||
struct io_t
|
||||
{
|
||||
MOO_OBJ_HEADER;
|
||||
moo_oop_t handle; /* SmallInteger or SmallPointer/LargePointer depending on operating systems */
|
||||
/* there are more fields in the actual object */
|
||||
};
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MOO_EXPORT int moo_mod_io (moo_t* moo, moo_mod_t* mod);
|
||||
MOO_EXPORT int moo_mod_io_file (moo_t* moo, moo_mod_t* mod);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
128
mod/_sck.h
Normal file
128
mod/_sck.h
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2019 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _MOO_MOD_SCK_H_
|
||||
#define _MOO_MOD_SCK_H_
|
||||
|
||||
#include <moo.h>
|
||||
|
||||
typedef struct sck_t* oop_sck_t;
|
||||
struct sck_t
|
||||
{
|
||||
MOO_OBJ_HEADER;
|
||||
|
||||
moo_oop_t handle; /* SmallInteger */
|
||||
/* there are more fields in the actual object */
|
||||
};
|
||||
|
||||
#if (MOO_SIZEOF_SOCKLEN_T == 1)
|
||||
#if defined(MOO_SOCKLEN_T_IS_SIGNED)
|
||||
typedef moo_int8_t sck_len_t;
|
||||
#else
|
||||
typedef moo_uint8_t sck_len_t;
|
||||
#endif
|
||||
#elif (MOO_SIZEOF_SOCKLEN_T == 2)
|
||||
#if defined(MOO_SOCKLEN_T_IS_SIGNED)
|
||||
typedef moo_int16_t sck_len_t;
|
||||
#else
|
||||
typedef moo_uint16_t sck_len_t;
|
||||
#endif
|
||||
#elif (MOO_SIZEOF_SOCKLEN_T == 4)
|
||||
#if defined(MOO_SOCKLEN_T_IS_SIGNED)
|
||||
typedef moo_int32_t sck_len_t;
|
||||
#else
|
||||
typedef moo_uint32_t sck_len_t;
|
||||
#endif
|
||||
#elif (MOO_SIZEOF_SOCKLEN_T == 8)
|
||||
#if defined(MOO_SOCKLEN_T_IS_SIGNED)
|
||||
typedef moo_int64_t sck_len_t;
|
||||
#else
|
||||
typedef moo_uint64_t sck_len_t;
|
||||
#endif
|
||||
#else
|
||||
# undef MOO_SIZEOF_SOCKLEN_T
|
||||
# define MOO_SIZEOF_SOCKLEN_T MOO_SIZEOF_INT
|
||||
# define MOO_SOCKLEN_T_IS_SIGNED
|
||||
typedef int sck_len_t;
|
||||
#endif
|
||||
|
||||
#if (MOO_SIZEOF_SA_FAMILY_T == 1)
|
||||
#if defined(MOO_SA_FAMILY_T_IS_SIGNED)
|
||||
typedef moo_int8_t sck_addr_family_t;
|
||||
#else
|
||||
typedef moo_uint8_t sck_addr_family_t;
|
||||
#endif
|
||||
#elif (MOO_SIZEOF_SA_FAMILY_T == 2)
|
||||
#if defined(MOO_SA_FAMILY_T_IS_SIGNED)
|
||||
typedef moo_int16_t sck_addr_family_t;
|
||||
#else
|
||||
typedef moo_uint16_t sck_addr_family_t;
|
||||
#endif
|
||||
#elif (MOO_SIZEOF_SA_FAMILY_T == 4)
|
||||
#if defined(MOO_SA_FAMILY_T_IS_SIGNED)
|
||||
typedef moo_int32_t sck_addr_family_t;
|
||||
#else
|
||||
typedef moo_uint32_t sck_addr_family_t;
|
||||
#endif
|
||||
#elif (MOO_SIZEOF_SA_FAMILY_T == 8)
|
||||
#if defined(MOO_SA_FAMILY_T_IS_SIGNED)
|
||||
typedef moo_int64_t sck_addr_family_t;
|
||||
#else
|
||||
typedef moo_uint64_t sck_addr_family_t;
|
||||
#endif
|
||||
#else
|
||||
# undef MOO_SIZEOF_SA_FAMILY_T
|
||||
# define MOO_SIZEOF_SA_FAMILY_T MOO_SIZEOF_SHORT
|
||||
# undef MOO_SA_FAMILY_T_IS_SIGNED
|
||||
typedef unsigned short int sck_addr_family_t;
|
||||
#endif
|
||||
|
||||
struct sck_addr_t
|
||||
{
|
||||
#if defined(MOO_OFFSETOF_SA_FAMILY) && (MOO_OFFSETOF_SA_FAMILY > 0)
|
||||
moo_uint8_t filler[MOO_OFFSETOF_SA_FAMILY];
|
||||
#endif
|
||||
sck_addr_family_t family;
|
||||
moo_uint8_t data[1];
|
||||
};
|
||||
typedef struct sck_addr_t sck_addr_t;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MOO_EXPORT int moo_mod_sck (moo_t* moo, moo_mod_t* mod);
|
||||
MOO_EXPORT int moo_mod_sck_addr (moo_t* moo, moo_mod_t* mod);
|
||||
|
||||
|
||||
sck_len_t moo_sck_addr_len (sck_addr_t* addr);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
43
mod/_stdio.h
Normal file
43
mod/_stdio.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2017 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _MOO_MOD_STDIO_H_
|
||||
#define _MOO_MOD_STDIO_H_
|
||||
|
||||
#include <moo.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MOO_EXPORT int moo_mod_stdio (moo_t* moo, moo_mod_t* mod);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
108
mod/_x11.h
Normal file
108
mod/_x11.h
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2019 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _MOO_MOD_X11_H_
|
||||
#define _MOO_MOD_X11_H_
|
||||
|
||||
#include <moo.h>
|
||||
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
/* [NOTE] this header is for internal use only.
|
||||
* so most of the declarations here don't have the moo_ prefix */
|
||||
|
||||
#define MC MOO_METHOD_CLASS
|
||||
#define MI MOO_METHOD_INSTANCE
|
||||
|
||||
typedef struct x11_llevent_t* oop_x11_llevent_t;
|
||||
struct x11_llevent_t
|
||||
{
|
||||
MOO_OBJ_HEADER;
|
||||
moo_oop_t type;
|
||||
moo_oop_t window;
|
||||
moo_oop_t x, y, width, height;
|
||||
};
|
||||
|
||||
typedef struct x11_gc_t* oop_x11_gc_t;
|
||||
struct x11_gc_t
|
||||
{
|
||||
MOO_OBJ_HEADER;
|
||||
|
||||
moo_oop_t widget;
|
||||
moo_oop_t gc_handle;
|
||||
|
||||
moo_oop_t foreground;
|
||||
moo_oop_t background;
|
||||
moo_oop_t line_width;
|
||||
moo_oop_t line_style;
|
||||
moo_oop_t fill_style;
|
||||
moo_oop_t font_name;
|
||||
|
||||
moo_oop_t font_ptr;
|
||||
moo_oop_t font_set; /* XFontSet */
|
||||
};
|
||||
|
||||
typedef struct x11_widget_t* oop_x11_widget_t;
|
||||
struct x11_widget_t
|
||||
{
|
||||
MOO_OBJ_HEADER;
|
||||
|
||||
moo_oop_t window_handle; /* SmallInteger */
|
||||
moo_oop_t parent;
|
||||
|
||||
/* more fields below */
|
||||
};
|
||||
|
||||
typedef struct x11_t* oop_x11_t;
|
||||
struct x11_t
|
||||
{
|
||||
MOO_OBJ_HEADER;
|
||||
|
||||
moo_oop_t display; /* SMPTR of Display */
|
||||
/* in fact, there are more fields */
|
||||
};
|
||||
|
||||
typedef struct x11_trailer_t x11_trailer_t;
|
||||
struct x11_trailer_t
|
||||
{
|
||||
XEvent* event;
|
||||
moo_ooi_t connection_number;
|
||||
Atom wm_delete_window;
|
||||
};
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MOO_EXPORT int moo_mod_x11 (moo_t* moo, moo_mod_t* mod);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
26
mod/icc.mak
Normal file
26
mod/icc.mak
Normal file
@ -0,0 +1,26 @@
|
||||
#
|
||||
# Intel 386(tm)/486(tm) C Code Builder(tm) Kit, Version 1.0
|
||||
#
|
||||
|
||||
CFLAGS := /D__DOS__ /DMOO_ENABLE_STATIC_MODULE /DNDEBUG /I..\lib
|
||||
|
||||
SRCS := \
|
||||
_con.c \
|
||||
ffi.c \
|
||||
stdio.c
|
||||
|
||||
OBJS := $(SRCS:.c=.obj)
|
||||
|
||||
MODFILE=moomod.lib
|
||||
RSPFILE := $(MODFILE,B,S/.*/&.RSP/)
|
||||
|
||||
all: $(OBJS)
|
||||
echo > $(RSPFILE)
|
||||
!foreach x $(.NEWER)
|
||||
modname /r $x >> $(RSPFILE)
|
||||
!end
|
||||
echo compress >> $(RSPFILE)
|
||||
echo update >> $(RSPFILE)
|
||||
echo quit exit >> $(RSPFILE)
|
||||
del $(MODFILE)
|
||||
lib32 $(MODFILE) batch < $(RSPFILE)
|
377
mod/io-file.c
Normal file
377
mod/io-file.c
Normal file
@ -0,0 +1,377 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2019 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 "_io.h"
|
||||
#include "../lib/moo-prv.h"
|
||||
#include "../lib/moo-utl.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
#if !defined(O_CLOEXEC)
|
||||
# define O_CLOEXEC 0 /* since it's not defined, 0 results in no effect when bitwise-ORed. */
|
||||
#endif
|
||||
|
||||
static moo_pfrc_t pf_open_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_io_t io;
|
||||
moo_oop_t path, flags, mode;
|
||||
int fd = -1, fl;
|
||||
moo_bch_t* tmp;
|
||||
|
||||
io = (oop_io_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(io) &&
|
||||
MOO_OBJ_BYTESOF(io) >= (MOO_SIZEOF(*io) - MOO_SIZEOF(moo_obj_t))
|
||||
);
|
||||
|
||||
if (nargs == 1)
|
||||
{
|
||||
/* special form of opening. the socket handle is given */
|
||||
io->handle = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
path = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
flags = MOO_STACK_GETARG(moo, nargs, 1);
|
||||
mode = (nargs < 3)? MOO_SMOOI_TO_OOP(0644): MOO_STACK_GETARG(moo, nargs, 2);
|
||||
|
||||
/* TODO: always set O_LARGEFILE on flags if necessary */
|
||||
|
||||
MOO_PF_CHECK_ARGS (moo, nargs, MOO_OBJ_IS_CHAR_POINTER(path) && MOO_OOP_IS_SMOOI(flags) && MOO_OOP_IS_SMOOI(mode));
|
||||
MOO_PF_CHECK_ARGS (moo, nargs, moo_count_oocstr(MOO_OBJ_GET_CHAR_SLOT(path)) == MOO_OBJ_GET_SIZE(path));
|
||||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
tmp = moo_dupootobcstr(moo, MOO_OBJ_GET_CHAR_SLOT(path), MOO_NULL);
|
||||
if (!tmp) goto oops;
|
||||
fd = open(tmp, MOO_OOP_TO_SMOOI(flags), MOO_OOP_TO_SMOOI(mode));
|
||||
moo_freemem (moo, tmp);
|
||||
#else
|
||||
fd = open(MOO_OBJ_GET_CHAR_SLOT(path), MOO_OOP_TO_SMOOI(flags), MOO_OOP_TO_SMOOI(mode));
|
||||
#endif
|
||||
if (fd == -1)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
if (!MOO_IN_SMOOI_RANGE(fd))
|
||||
{
|
||||
/* the io descriptor is too big to be represented as a small integer */
|
||||
moo_seterrbfmt (moo, MOO_ERANGE, "IO handle %d not in the permitted range", fd);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
#if defined(O_NONBLOCK) && defined(O_CLOEXEC)
|
||||
fl = fcntl(fd, F_GETFL, 0);
|
||||
if (fl == -1)
|
||||
{
|
||||
fcntl_failure:
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
fl |= O_NONBLOCK | O_CLOEXEC;
|
||||
|
||||
if (fcntl(fd, F_SETFL, fl) == -1) goto fcntl_failure;
|
||||
#endif
|
||||
|
||||
io->handle = MOO_SMOOI_TO_OOP(fd);
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
|
||||
return MOO_PF_SUCCESS;
|
||||
|
||||
oops:
|
||||
if (fd >= 0) close (fd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
#define RCV_TO_FD(moo, nargs, fd_) \
|
||||
do \
|
||||
{ \
|
||||
oop_io_t rcv_; \
|
||||
rcv_ = (oop_io_t)MOO_STACK_GETRCV(moo, nargs); \
|
||||
MOO_PF_CHECK_RCV (moo, \
|
||||
MOO_OOP_IS_POINTER(rcv_) && \
|
||||
MOO_OBJ_BYTESOF(rcv_) >= (MOO_SIZEOF(*rcv_) - MOO_SIZEOF(moo_obj_t)) && \
|
||||
MOO_OOP_IS_SMOOI(rcv_->handle) \
|
||||
); \
|
||||
fd_ = MOO_OOP_TO_SMOOI(rcv_->handle); \
|
||||
if (fd_ <= -1) \
|
||||
{ \
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "bad IO handle - %d", fd_); \
|
||||
return MOO_PF_FAILURE; \
|
||||
} \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#define SETRET_WITH_SYSCALL(moo, nargs, n) \
|
||||
do { \
|
||||
int x_ = (n); \
|
||||
if (x_ <= -1) \
|
||||
{ \
|
||||
moo_seterrwithsyserr (moo, 0, errno); \
|
||||
return MOO_PF_FAILURE; \
|
||||
} \
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(x_)); \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
static moo_pfrc_t pf_chmod_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
moo_seterrnum (moo, MOO_ENOIMPL);
|
||||
return MOO_PF_FAILURE;
|
||||
#else
|
||||
moo_oop_t tmp;
|
||||
int fd;
|
||||
moo_oow_t mode;
|
||||
|
||||
RCV_TO_FD (moo, nargs, fd);
|
||||
|
||||
MOO_STATIC_ASSERT (MOO_TYPE_IS_UNSIGNED(mode_t));
|
||||
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
if (moo_inttooow_noseterr(moo, tmp, &mode) == 0 || mode > MOO_TYPE_MAX(mode_t))
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid mode - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
SETRET_WITH_SYSCALL (moo, nargs, fchmod(fd, mode));
|
||||
return MOO_PF_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static moo_pfrc_t pf_chown_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
moo_seterrnum (moo, MOO_ENOIMPL);
|
||||
return MOO_PF_FAILURE;
|
||||
#else
|
||||
moo_oop_t tmp;
|
||||
int fd;
|
||||
moo_ooi_t uid, gid;
|
||||
|
||||
RCV_TO_FD (moo, nargs, fd);
|
||||
|
||||
MOO_STATIC_ASSERT (MOO_TYPE_IS_UNSIGNED(uid_t));
|
||||
MOO_STATIC_ASSERT (MOO_TYPE_IS_UNSIGNED(gid_t));
|
||||
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
if (moo_inttoooi_noseterr(moo, tmp, &uid) == 0 || uid > MOO_TYPE_MAX(uid_t))
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid uid - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 1);
|
||||
if (moo_inttoooi_noseterr(moo, tmp, &gid) == 0 || gid > MOO_TYPE_MAX(gid_t))
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid gid - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (uid <= -1) uid = (uid_t)-1;
|
||||
if (gid <= -1) gid = (gid_t)-1;
|
||||
|
||||
SETRET_WITH_SYSCALL (moo, nargs, fchown(fd, uid, gid));
|
||||
return MOO_PF_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_lock_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
moo_seterrnum (moo, MOO_ENOIMPL);
|
||||
return MOO_PF_FAILURE;
|
||||
#else
|
||||
moo_oop_t tmp;
|
||||
int fd;
|
||||
|
||||
RCV_TO_FD (moo, nargs, fd);
|
||||
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
if (!MOO_OOP_IS_SMOOI(tmp))
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid operation code - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
SETRET_WITH_SYSCALL (moo, nargs, flock(fd, MOO_OOP_TO_SMOOI(tmp)));
|
||||
return MOO_PF_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_seek_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
moo_oop_t tmp;
|
||||
moo_intmax_t offset;
|
||||
moo_ooi_t whence;
|
||||
int fd;
|
||||
off_t n;
|
||||
|
||||
RCV_TO_FD (moo, nargs, fd);
|
||||
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
if (moo_inttointmax_noseterr(moo, tmp, &offset) == 0 || offset < MOO_TYPE_MIN(off_t) || offset > MOO_TYPE_MAX(off_t))
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 1);
|
||||
if (moo_inttoooi_noseterr(moo, tmp, &whence) == 0)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid whence - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
n = lseek(fd, offset, whence);
|
||||
if (n == (off_t)-1)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
tmp = moo_uintmaxtoint(moo, (moo_uintmax_t)n);
|
||||
if (!tmp) return MOO_PF_FAILURE;
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, tmp);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_truncate_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
moo_oop_t tmp;
|
||||
moo_intmax_t size;
|
||||
int fd, n;
|
||||
|
||||
RCV_TO_FD (moo, nargs, fd);
|
||||
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
if (moo_inttointmax_noseterr(moo, tmp, &size) == 0 || size < MOO_TYPE_MIN(off_t) || size > MOO_TYPE_MAX(off_t))
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid size - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
SETRET_WITH_SYSCALL (moo, nargs, ftruncate(fd, size));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
/* TODO: posix_fallocate(), posix_fadvise(), fallocate() */
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
#define C MOO_METHOD_CLASS
|
||||
#define I MOO_METHOD_INSTANCE
|
||||
|
||||
#define MA MOO_TYPE_MAX(moo_oow_t)
|
||||
|
||||
static moo_pfinfo_t pfinfos[] =
|
||||
{
|
||||
{ I, "chmod:", { pf_chmod_file, 1, 1 } },
|
||||
{ I, "chown:group:", { pf_chown_file, 2, 2 } },
|
||||
{ I, "lock:", { pf_lock_file, 1, 1 } },
|
||||
{ I, "open:flags:", { pf_open_file, 2, 2 } },
|
||||
{ I, "open:flags:mode:", { pf_open_file, 3, 3 } },
|
||||
{ I, "seek:whence:", { pf_seek_file, 2, 2 } },
|
||||
{ I, "truncate:", { pf_truncate_file, 1, 1 } }
|
||||
};
|
||||
|
||||
#if defined(_WIN32)
|
||||
# define LOCK_EX 0
|
||||
# define LOCK_NB 0
|
||||
# define LOCK_SH 0
|
||||
# define LOCK_UN 0
|
||||
# define O_NOFOLLOW 0
|
||||
# define O_NONBLOCK 0
|
||||
#endif
|
||||
static moo_pvinfo_t pvinfos[] =
|
||||
{
|
||||
/*
|
||||
{ "F_RDLCK", { MOO_PV_OOI, (const void*)F_RDLCK } },
|
||||
{ "F_UNLCK", { MOO_PV_OOI, (const void*)F_UNLCK } },
|
||||
{ "F_WRLCK", { MOO_PV_OOI, (const void*)F_WRLCK } },
|
||||
*/
|
||||
{ "LOCK_EX", { MOO_PV_OOI, (const void*)LOCK_EX } },
|
||||
{ "LOCK_NB", { MOO_PV_OOI, (const void*)LOCK_NB } },
|
||||
{ "LOCK_SH", { MOO_PV_OOI, (const void*)LOCK_SH } },
|
||||
{ "LOCK_UN", { MOO_PV_OOI, (const void*)LOCK_UN } },
|
||||
|
||||
{ "O_APPEND", { MOO_PV_OOI, (const void*)O_APPEND } },
|
||||
{ "O_CLOEXEC", { MOO_PV_OOI, (const void*)O_CLOEXEC } },
|
||||
{ "O_CREAT", { MOO_PV_OOI, (const void*)O_CREAT } },
|
||||
{ "O_EXCL", { MOO_PV_OOI, (const void*)O_EXCL } },
|
||||
{ "O_NOFOLLOW", { MOO_PV_OOI, (const void*)O_NOFOLLOW } },
|
||||
{ "O_NONBLOCK", { MOO_PV_OOI, (const void*)O_NONBLOCK } },
|
||||
{ "O_RDONLY", { MOO_PV_OOI, (const void*)O_RDONLY } },
|
||||
{ "O_RDWR", { MOO_PV_OOI, (const void*)O_RDWR } },
|
||||
{ "O_TRUNC", { MOO_PV_OOI, (const void*)O_TRUNC } },
|
||||
{ "O_WRONLY", { MOO_PV_OOI, (const void*)O_WRONLY } },
|
||||
|
||||
{ "SEEK_CUR", { MOO_PV_OOI, (const void*)SEEK_CUR } },
|
||||
{ "SEEK_END", { MOO_PV_OOI, (const void*)SEEK_SET } },
|
||||
{ "SEEK_SET", { MOO_PV_OOI, (const void*)SEEK_SET } }
|
||||
};
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static moo_pfbase_t* querypf (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
|
||||
{
|
||||
return moo_findpfbase(moo, pfinfos, MOO_COUNTOF(pfinfos), name, namelen);
|
||||
}
|
||||
|
||||
static moo_pvbase_t* querypv (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
|
||||
{
|
||||
return moo_findpvbase(moo, pvinfos, MOO_COUNTOF(pvinfos), name, namelen);
|
||||
}
|
||||
|
||||
static void unload (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
}
|
||||
|
||||
int moo_mod_io_file (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
mod->import = import;
|
||||
mod->querypf = querypf;
|
||||
mod->querypv = querypv;
|
||||
mod->unload = unload;
|
||||
mod->ctx = MOO_NULL;
|
||||
return 0;
|
||||
}
|
255
mod/io.c
Normal file
255
mod/io.c
Normal file
@ -0,0 +1,255 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2019 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 "_io.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
static moo_pfrc_t pf_close_io (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_io_t io;
|
||||
int fd;
|
||||
|
||||
io = (oop_io_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(io) &&
|
||||
MOO_OBJ_BYTESOF(io) >= (MOO_SIZEOF(*io) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(io->handle)
|
||||
);
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(io->handle);
|
||||
if (fd >= 0)
|
||||
{
|
||||
moo_releaseiohandle (moo, MOO_OOP_TO_SMOOI(io->handle));
|
||||
/* TODO: win32 CloseHandle if handle is HANDLE */
|
||||
if (close(MOO_OOP_TO_SMOOI(io->handle)) == -1)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
io->handle = MOO_SMOOI_TO_OOP(-1);
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
moo_seterrbfmt (moo, MOO_EBADHND, "bad IO handle - %O", io->handle);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_read_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_io_t io;
|
||||
moo_oop_byte_t buf;
|
||||
moo_oow_t offset, length, maxlen;
|
||||
int fd;
|
||||
ssize_t n;
|
||||
|
||||
io = (oop_io_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(io) &&
|
||||
MOO_OBJ_BYTESOF(io) >= (MOO_SIZEOF(*io) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(io->handle)
|
||||
);
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(io->handle);
|
||||
if (fd <= -1)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "bad IO handle - %d", fd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
buf = (moo_oop_byte_t)MOO_STACK_GETARG (moo, nargs, 0);
|
||||
if (!MOO_OBJ_IS_BYTE_POINTER(buf))
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "buffer not a byte array - %O", buf);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
offset = 0;
|
||||
maxlen = MOO_OBJ_GET_SIZE(buf);
|
||||
length = maxlen;
|
||||
|
||||
if (nargs >= 2)
|
||||
{
|
||||
moo_oop_t tmp;
|
||||
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 1);
|
||||
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (nargs >= 3)
|
||||
{
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 2);
|
||||
if (moo_inttooow_noseterr(moo, tmp, &length) <= 0)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid length - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (offset >= maxlen) offset = maxlen - 1;
|
||||
if (length > maxlen - offset) length = maxlen - offset;
|
||||
}
|
||||
|
||||
n = read(fd, MOO_OBJ_GET_BYTE_PTR(buf, offset), length);
|
||||
if (n <= -1 && errno != EWOULDBLOCK && errno != EAGAIN)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
/* [NOTE] on EWOULDBLOCK or EGAIN, -1 is returned */
|
||||
|
||||
MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(n));
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(n));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_write_bytes (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_io_t io;
|
||||
moo_oop_byte_t buf;
|
||||
moo_oow_t offset, length, maxlen;
|
||||
int fd;
|
||||
ssize_t n;
|
||||
|
||||
io = (oop_io_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(io) &&
|
||||
MOO_OBJ_BYTESOF(io) >= (MOO_SIZEOF(*io) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(io->handle)
|
||||
);
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(io->handle);
|
||||
if (fd <= -1)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "bad IO handle - %d", fd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
buf = (moo_oop_byte_t)MOO_STACK_GETARG (moo, nargs, 0);
|
||||
if (!MOO_OBJ_IS_BYTE_POINTER(buf))
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "buffer not a byte array - %O", buf);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
offset = 0;
|
||||
maxlen = MOO_OBJ_GET_SIZE(buf);
|
||||
length = maxlen;
|
||||
|
||||
if (nargs >= 2)
|
||||
{
|
||||
moo_oop_t tmp;
|
||||
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 1);
|
||||
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (nargs >= 3)
|
||||
{
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 2);
|
||||
if (moo_inttooow_noseterr(moo, tmp, &length) <= 0)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid length - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (offset >= maxlen) offset = maxlen - 1;
|
||||
if (length > maxlen - offset) length = maxlen - offset;
|
||||
}
|
||||
|
||||
n = write(fd, MOO_OBJ_GET_BYTE_PTR(buf, offset), length);
|
||||
if (n <= -1 && errno != EWOULDBLOCK && errno != EAGAIN)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
/* [NOTE] on EWOULDBLOCK or EGAIN, -1 is returned */
|
||||
MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(n));
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(n));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
#define C MOO_METHOD_CLASS
|
||||
#define I MOO_METHOD_INSTANCE
|
||||
|
||||
#define MA MOO_TYPE_MAX(moo_oow_t)
|
||||
|
||||
static moo_pfinfo_t pfinfos[] =
|
||||
{
|
||||
{ I, "close", { pf_close_io, 0, 0 } },
|
||||
{ I, "readBytesInto:", { pf_read_bytes, 1, 1 } },
|
||||
{ I, "readBytesInto:startingAt:for:", { pf_read_bytes, 3, 3 } },
|
||||
{ I, "writeBytesFrom:", { pf_write_bytes, 1, 1 } },
|
||||
{ I, "writeBytesFrom:startingAt:for:", { pf_write_bytes, 3, 3 } }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
|
||||
{
|
||||
/*if (moo_setclasstrsize(moo, _class, MOO_SIZEOF(io_t), MOO_NULL) <= -1) return -1;*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
static moo_pfbase_t* querypf (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
|
||||
{
|
||||
return moo_findpfbase(moo, pfinfos, MOO_COUNTOF(pfinfos), name, namelen);
|
||||
}
|
||||
|
||||
static void unload (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
/* TODO: anything? close open open dll handles? For that, pf_open must store the value it returns to mod->ctx or somewhere..*/
|
||||
if (mod->ctx) moo_freemem (moo, mod->ctx);
|
||||
}
|
||||
|
||||
int moo_mod_io (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
mod->import = import;
|
||||
mod->querypf = querypf;
|
||||
mod->querypv = MOO_NULL;
|
||||
mod->unload = unload;
|
||||
return 0;
|
||||
}
|
568
mod/sck-addr.c
Normal file
568
mod/sck-addr.c
Normal file
@ -0,0 +1,568 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2019 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 "_sck.h"
|
||||
#include "../lib/moo-prv.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(HAVE_NETINET_IN_H)
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
#if defined(HAVE_SYS_UN_H)
|
||||
# include <sys/un.h>
|
||||
#endif
|
||||
#if defined(HAVE_NETPACKET_PACKET_H)
|
||||
# include <netpacket/packet.h>
|
||||
#endif
|
||||
#if defined(HAVE_NET_IF_DL_H)
|
||||
# include <net/if_dl.h>
|
||||
#endif
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define C MOO_METHOD_CLASS
|
||||
#define I MOO_METHOD_INSTANCE
|
||||
|
||||
#define MA MOO_TYPE_MAX(moo_oow_t)
|
||||
|
||||
union sockaddr_t
|
||||
{
|
||||
struct sockaddr sa;
|
||||
#if (MOO_SIZEOF_STRUCT_SOCKADDR_IN > 0)
|
||||
struct sockaddr_in in4;
|
||||
#endif
|
||||
#if (MOO_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
struct sockaddr_in6 in6;
|
||||
#endif
|
||||
#if (MOO_SIZEOF_STRUCT_SOCKADDR_LL > 0)
|
||||
struct sockaddr_ll ll;
|
||||
#endif
|
||||
#if (MOO_SIZEOF_STRUCT_SOCKADDR_UN > 0)
|
||||
struct sockaddr_un un;
|
||||
#endif
|
||||
};
|
||||
typedef union sockaddr_t sockaddr_t;
|
||||
|
||||
static int str_to_ipv4 (const moo_ooch_t* str, moo_oow_t len, struct in_addr* inaddr)
|
||||
{
|
||||
const moo_ooch_t* end;
|
||||
int dots = 0, digits = 0;
|
||||
moo_uint32_t acc = 0, addr = 0;
|
||||
moo_ooch_t c;
|
||||
|
||||
end = str + len;
|
||||
|
||||
do
|
||||
{
|
||||
if (str >= end)
|
||||
{
|
||||
if (dots < 3 || digits == 0) return -1;
|
||||
addr = (addr << 8) | acc;
|
||||
break;
|
||||
}
|
||||
|
||||
c = *str++;
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
if (digits > 0 && acc == 0) return -1;
|
||||
acc = acc * 10 + (c - '0');
|
||||
if (acc > 255) return -1;
|
||||
digits++;
|
||||
}
|
||||
else if (c == '.')
|
||||
{
|
||||
if (dots >= 3 || digits == 0) return -1;
|
||||
addr = (addr << 8) | acc;
|
||||
dots++; acc = 0; digits = 0;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
while (1);
|
||||
|
||||
inaddr->s_addr = moo_hton32(addr);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#if (MOO_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
static int str_to_ipv6 (const moo_ooch_t* src, moo_oow_t len, struct in6_addr* inaddr)
|
||||
{
|
||||
moo_uint8_t* tp, * endp, * colonp;
|
||||
const moo_ooch_t* curtok;
|
||||
moo_ooch_t ch;
|
||||
int saw_xdigit;
|
||||
unsigned int val;
|
||||
const moo_ooch_t* src_end;
|
||||
|
||||
src_end = src + len;
|
||||
|
||||
MOO_MEMSET (inaddr, 0, MOO_SIZEOF(*inaddr));
|
||||
tp = &inaddr->s6_addr[0];
|
||||
endp = &inaddr->s6_addr[MOO_COUNTOF(inaddr->s6_addr)];
|
||||
colonp = MOO_NULL;
|
||||
|
||||
/* Leading :: requires some special handling. */
|
||||
if (src < src_end && *src == ':')
|
||||
{
|
||||
src++;
|
||||
if (src >= src_end || *src != ':') return -1;
|
||||
}
|
||||
|
||||
curtok = src;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
|
||||
while (src < src_end)
|
||||
{
|
||||
int v1;
|
||||
|
||||
ch = *src++;
|
||||
|
||||
if (ch >= '0' && ch <= '9')
|
||||
v1 = ch - '0';
|
||||
else if (ch >= 'A' && ch <= 'F')
|
||||
v1 = ch - 'A' + 10;
|
||||
else if (ch >= 'a' && ch <= 'f')
|
||||
v1 = ch - 'a' + 10;
|
||||
else v1 = -1;
|
||||
if (v1 >= 0)
|
||||
{
|
||||
val <<= 4;
|
||||
val |= v1;
|
||||
if (val > 0xffff) return -1;
|
||||
saw_xdigit = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch == ':')
|
||||
{
|
||||
curtok = src;
|
||||
if (!saw_xdigit)
|
||||
{
|
||||
if (colonp) return -1;
|
||||
colonp = tp;
|
||||
continue;
|
||||
}
|
||||
else if (src >= src_end)
|
||||
{
|
||||
/* a colon can't be the last character */
|
||||
return -1;
|
||||
}
|
||||
|
||||
*tp++ = (moo_uint8_t)(val >> 8) & 0xff;
|
||||
*tp++ = (moo_uint8_t)val & 0xff;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch == '.' && ((tp + MOO_SIZEOF(struct in_addr)) <= endp) &&
|
||||
str_to_ipv4(curtok, src_end - curtok, (struct in_addr*)tp) == 0)
|
||||
{
|
||||
tp += MOO_SIZEOF(struct in_addr*);
|
||||
saw_xdigit = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (saw_xdigit)
|
||||
{
|
||||
if (tp + MOO_SIZEOF(moo_uint16_t) > endp) return -1;
|
||||
*tp++ = (moo_uint8_t)(val >> 8) & 0xff;
|
||||
*tp++ = (moo_uint8_t)val & 0xff;
|
||||
}
|
||||
if (colonp != MOO_NULL)
|
||||
{
|
||||
/*
|
||||
* Since some memmove()'s erroneously fail to handle
|
||||
* overlapping regions, we'll do the shift by hand.
|
||||
*/
|
||||
moo_oow_t n = tp - colonp;
|
||||
moo_oow_t i;
|
||||
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
endp[-i] = colonp[n - i];
|
||||
colonp[n - i] = 0;
|
||||
}
|
||||
tp = endp;
|
||||
}
|
||||
|
||||
if (tp != endp) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static int str_to_sockaddr (moo_t* moo, const moo_ooch_t* str, moo_oow_t len, sockaddr_t* nwad)
|
||||
{
|
||||
const moo_ooch_t* p;
|
||||
const moo_ooch_t* end;
|
||||
moo_oocs_t tmp;
|
||||
|
||||
p = str;
|
||||
end = str + len;
|
||||
|
||||
if (p >= end)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "blank address");
|
||||
return -1;
|
||||
}
|
||||
|
||||
MOO_MEMSET (nwad, 0, MOO_SIZEOF(*nwad));
|
||||
|
||||
#if defined(AF_UNIX)
|
||||
if (*p == '/' && len >= 2)
|
||||
{
|
||||
#if defined(MOO_OOCH_IS_BCH)
|
||||
moo_copy_bcstr (nwad->un.sun_path, MOO_COUNTOF(nwad->un.sun_path), str);
|
||||
#else
|
||||
moo_oow_t dstlen;
|
||||
|
||||
dstlen = MOO_COUNTOF(nwad->un.sun_path) - 1;
|
||||
if (moo_convutobchars (moo, p, &len, nwad->un.sun_path, &dstlen) <= -1)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "unable to convert encoding");
|
||||
return -1;
|
||||
}
|
||||
nwad->un.sun_path[dstlen] = '\0';
|
||||
#endif
|
||||
nwad->un.sun_family = AF_UNIX;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (MOO_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
if (*p == '[')
|
||||
{
|
||||
/* IPv6 address */
|
||||
tmp.ptr = (moo_ooch_t*)++p; /* skip [ and remember the position */
|
||||
while (p < end && *p != '%' && *p != ']') p++;
|
||||
|
||||
if (p >= end) goto no_rbrack;
|
||||
|
||||
tmp.len = p - tmp.ptr;
|
||||
if (*p == '%')
|
||||
{
|
||||
/* handle scope id */
|
||||
moo_uint32_t x;
|
||||
|
||||
p++; /* skip % */
|
||||
|
||||
if (p >= end)
|
||||
{
|
||||
/* premature end */
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "scope id blank");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*p >= '0' && *p <= '9')
|
||||
{
|
||||
/* numeric scope id */
|
||||
nwad->in6.sin6_scope_id = 0;
|
||||
do
|
||||
{
|
||||
x = nwad->in6.sin6_scope_id * 10 + (*p - '0');
|
||||
if (x < nwad->in6.sin6_scope_id)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "scope id too large");
|
||||
return -1; /* overflow */
|
||||
}
|
||||
nwad->in6.sin6_scope_id = x;
|
||||
p++;
|
||||
}
|
||||
while (p < end && *p >= '0' && *p <= '9');
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
TODO:
|
||||
/* interface name as a scope id? */
|
||||
const moo_ooch_t* stmp = p;
|
||||
unsigned int index;
|
||||
do p++; while (p < end && *p != ']');
|
||||
if (moo_nwifwcsntoindex (stmp, p - stmp, &index) <= -1) return -1;
|
||||
tmpad.u.in6.scope = index;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (p >= end || *p != ']') goto no_rbrack;
|
||||
}
|
||||
p++; /* skip ] */
|
||||
|
||||
if (str_to_ipv6(tmp.ptr, tmp.len, &nwad->in6.sin6_addr) <= -1) goto unrecog;
|
||||
nwad->in6.sin6_family = AF_INET6;
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
/* IPv4 address */
|
||||
tmp.ptr = (moo_ooch_t*)p;
|
||||
while (p < end && *p != ':') p++;
|
||||
tmp.len = p - tmp.ptr;
|
||||
|
||||
if (str_to_ipv4(tmp.ptr, tmp.len, &nwad->in4.sin_addr) <= -1)
|
||||
{
|
||||
#if (MOO_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
/* check if it is an IPv6 address not enclosed in [].
|
||||
* the port number can't be specified in this format. */
|
||||
if (p >= end || *p != ':')
|
||||
{
|
||||
/* without :, it can't be an ipv6 address */
|
||||
goto unrecog;
|
||||
}
|
||||
|
||||
|
||||
while (p < end && *p != '%') p++;
|
||||
tmp.len = p - tmp.ptr;
|
||||
|
||||
if (str_to_ipv6(tmp.ptr, tmp.len, &nwad->in6.sin6_addr) <= -1) goto unrecog;
|
||||
|
||||
if (p < end && *p == '%')
|
||||
{
|
||||
/* handle scope id */
|
||||
moo_uint32_t x;
|
||||
|
||||
p++; /* skip % */
|
||||
|
||||
if (p >= end)
|
||||
{
|
||||
/* premature end */
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "scope id blank");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*p >= '0' && *p <= '9')
|
||||
{
|
||||
/* numeric scope id */
|
||||
nwad->in6.sin6_scope_id = 0;
|
||||
do
|
||||
{
|
||||
x = nwad->in6.sin6_scope_id * 10 + (*p - '0');
|
||||
if (x < nwad->in6.sin6_scope_id)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "scope id too large");
|
||||
return -1; /* overflow */
|
||||
}
|
||||
nwad->in6.sin6_scope_id = x;
|
||||
p++;
|
||||
}
|
||||
while (p < end && *p >= '0' && *p <= '9');
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
TODO
|
||||
/* interface name as a scope id? */
|
||||
const moo_ooch_t* stmp = p;
|
||||
unsigned int index;
|
||||
do p++; while (p < end);
|
||||
if (moo_nwifwcsntoindex (stmp, p - stmp, &index) <= -1) return -1;
|
||||
nwad->in6.sin6_scope_id = index;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (p < end) goto unrecog; /* some gargage after the end? */
|
||||
|
||||
nwad->in6.sin6_family = AF_INET6;
|
||||
return 0;
|
||||
#else
|
||||
goto unrecog;
|
||||
#endif
|
||||
}
|
||||
|
||||
nwad->in4.sin_family = AF_INET;
|
||||
#if (MOO_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (p < end && *p == ':')
|
||||
{
|
||||
/* port number */
|
||||
moo_uint32_t port = 0;
|
||||
|
||||
p++; /* skip : */
|
||||
|
||||
tmp.ptr = (moo_ooch_t*)p;
|
||||
while (p < end && *p >= '0' && *p <= '9')
|
||||
{
|
||||
port = port * 10 + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
|
||||
tmp.len = p - tmp.ptr;
|
||||
if (tmp.len <= 0 || tmp.len >= 6 ||
|
||||
port > MOO_TYPE_MAX(moo_uint16_t))
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "port number blank or too large");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if (MOO_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
if (nwad->in4.sin_family == AF_INET)
|
||||
nwad->in4.sin_port = moo_hton16(port);
|
||||
else
|
||||
nwad->in6.sin6_port = moo_hton16(port);
|
||||
#else
|
||||
nwad->in4.sin_port = moo_hton16(port);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
unrecog:
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "unrecognized address");
|
||||
return -1;
|
||||
|
||||
no_rbrack:
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "missing right bracket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_get_family (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
moo_oop_t rcv;
|
||||
moo_oop_t v;
|
||||
struct sockaddr* sa;
|
||||
|
||||
rcv = (moo_oop_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo, MOO_OBJ_IS_BYTE_POINTER(rcv) && MOO_OBJ_GET_SIZE(rcv) >= MOO_SIZEOF(sockaddr_t));
|
||||
|
||||
sa = (struct sockaddr*)MOO_OBJ_GET_BYTE_SLOT(rcv);
|
||||
v = MOO_SMOOI_TO_OOP(sa->sa_family);
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, v);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_from_string (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
moo_oop_t rcv;
|
||||
moo_oop_t str;
|
||||
|
||||
rcv = (moo_oop_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
str = (moo_oop_t)MOO_STACK_GETARG(moo, nargs, 0);
|
||||
|
||||
MOO_PF_CHECK_RCV (moo, MOO_OBJ_IS_BYTE_POINTER(rcv) && MOO_OBJ_GET_SIZE(rcv) >= MOO_SIZEOF(sockaddr_t));
|
||||
MOO_PF_CHECK_ARGS (moo, nargs, MOO_OBJ_IS_CHAR_POINTER(str));
|
||||
|
||||
if (str_to_sockaddr(moo, MOO_OBJ_GET_CHAR_SLOT(str), MOO_OBJ_GET_SIZE(str), (sockaddr_t*)MOO_OBJ_GET_BYTE_SLOT(rcv)) <= -1)
|
||||
{
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static moo_pfinfo_t pfinfos[] =
|
||||
{
|
||||
{ I, "family", { pf_get_family, 0, 0 } },
|
||||
{ I, "fromString:", { pf_from_string, 1, 1 } }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
|
||||
{
|
||||
moo_ooi_t spec;
|
||||
|
||||
spec = MOO_OOP_TO_SMOOI(_class->spec);
|
||||
if (!MOO_CLASS_SPEC_IS_INDEXED(spec) || MOO_CLASS_SPEC_INDEXED_TYPE(spec) != MOO_OBJ_TYPE_BYTE || MOO_CLASS_SPEC_NAMED_INSTVARS(spec) != 0)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "%O not a plain #byte class", _class);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* change the number of the fixed fields forcibly.
|
||||
* the check against the superclass is done by the main compiler
|
||||
* after this import. so i perform no check about the superclass. */
|
||||
spec = MOO_CLASS_SPEC_MAKE(MOO_SIZEOF(sockaddr_t), MOO_CLASS_SPEC_FLAGS(spec), MOO_CLASS_SPEC_INDEXED_TYPE(spec));
|
||||
_class->spec = MOO_SMOOI_TO_OOP(spec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static moo_pfbase_t* querypf (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
|
||||
{
|
||||
return moo_findpfbase (moo, pfinfos, MOO_COUNTOF(pfinfos), name, namelen);
|
||||
}
|
||||
|
||||
static void unload (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
/* TODO: anything? close open open dll handles? For that, pf_open must store the value it returns to mod->ctx or somewhere..*/
|
||||
}
|
||||
|
||||
int moo_mod_sck_addr (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
mod->import = import;
|
||||
mod->querypf = querypf;
|
||||
mod->querypv = MOO_NULL;
|
||||
mod->unload = unload;
|
||||
mod->ctx = MOO_NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
sck_len_t moo_sck_addr_len (sck_addr_t* addr)
|
||||
{
|
||||
switch (addr->family)
|
||||
{
|
||||
#if defined(AF_INET) && (MOO_SIZEOF_STRUCT_SOCKADDR_IN > 0)
|
||||
case AF_INET:
|
||||
return MOO_SIZEOF(struct sockaddr_in);
|
||||
#endif
|
||||
#if defined(AF_INET6) && (MOO_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
case AF_INET6:
|
||||
return MOO_SIZEOF(struct sockaddr_in6);
|
||||
#endif
|
||||
#if defined(AF_PACKET) && (MOO_SIZEOF_STRUCT_SOCKADDR_LL > 0)
|
||||
case AF_PACKET:
|
||||
return MOO_SIZEOF(struct sockaddr_ll);
|
||||
#endif
|
||||
#if defined(AF_UNIX) && (MOO_SIZEOF_STRUCT_SOCKADDR_UN > 0)
|
||||
case AF_UNIX:
|
||||
return MOO_SIZEOF(struct sockaddr_un);
|
||||
#endif
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
657
mod/sck.c
Normal file
657
mod/sck.c
Normal file
@ -0,0 +1,657 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2019 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 "_sck.h"
|
||||
|
||||
#if defined(HAVE_ACCEPT4)
|
||||
# define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct sck_modctx_t sck_modctx_t;
|
||||
struct sck_modctx_t
|
||||
{
|
||||
moo_oop_class_t sck_class;
|
||||
};
|
||||
|
||||
static moo_pfrc_t pf_open_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_sck_t sck;
|
||||
moo_oop_t dom, type, proto;
|
||||
int fd = -1, typev;
|
||||
|
||||
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(sck) &&
|
||||
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t))
|
||||
);
|
||||
|
||||
if (nargs == 1)
|
||||
{
|
||||
/* special form of opening. the socket handle is given */
|
||||
sck->handle = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
dom = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
type = MOO_STACK_GETARG(moo, nargs, 1);
|
||||
proto = (nargs < 3)? 0: MOO_STACK_GETARG(moo, nargs, 2);
|
||||
|
||||
MOO_PF_CHECK_ARGS (moo, nargs, MOO_OOP_IS_SMOOI(dom) && MOO_OOP_IS_SMOOI(type) && MOO_OOP_IS_SMOOI(proto));
|
||||
|
||||
typev = MOO_OOP_TO_SMOOI(type);
|
||||
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
|
||||
typev |= SOCK_NONBLOCK | SOCK_CLOEXEC;
|
||||
create_socket:
|
||||
#endif
|
||||
|
||||
fd = socket(MOO_OOP_TO_SMOOI(dom), typev, MOO_OOP_TO_SMOOI(proto));
|
||||
if (fd == -1)
|
||||
{
|
||||
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
|
||||
if (errno == EINVAL && (typev & (SOCK_NONBLOCK | SOCK_CLOEXEC)))
|
||||
{
|
||||
typev &= ~(SOCK_NONBLOCK | SOCK_CLOEXEC);
|
||||
goto create_socket;
|
||||
}
|
||||
#endif
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
if (!MOO_IN_SMOOI_RANGE(fd))
|
||||
{
|
||||
/* the file descriptor is too big to be represented as a small integer */
|
||||
moo_seterrbfmt (moo, MOO_ERANGE, "socket handle %d not in the permitted range", fd);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
|
||||
if (!(typev & (SOCK_NONBLOCK | SOCK_CLOEXEC)))
|
||||
#endif
|
||||
{
|
||||
int fl;
|
||||
|
||||
fl = fcntl(fd, F_GETFL, 0);
|
||||
if (fl == -1)
|
||||
{
|
||||
fcntl_failure:
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
fl |= O_NONBLOCK;
|
||||
#if defined(O_CLOEXEC)
|
||||
fl |= O_CLOEXEC;
|
||||
#endif
|
||||
|
||||
if (fcntl(fd, F_SETFL, fl) == -1) goto fcntl_failure;
|
||||
}
|
||||
|
||||
sck->handle = MOO_SMOOI_TO_OOP(fd);
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
|
||||
return MOO_PF_SUCCESS;
|
||||
|
||||
oops:
|
||||
if (fd >= 0) close (fd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_close_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_sck_t sck;
|
||||
int fd;
|
||||
|
||||
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(sck) &&
|
||||
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(sck->handle)
|
||||
);
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(sck->handle);
|
||||
if (fd >= 0)
|
||||
{
|
||||
moo_releaseiohandle (moo, MOO_OOP_TO_SMOOI(sck->handle));
|
||||
if (close(MOO_OOP_TO_SMOOI(sck->handle)) == -1)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
sck->handle = MOO_SMOOI_TO_OOP(-1);
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
moo_seterrbfmt (moo, MOO_EBADHND, "bad socket handle - %O", sck->handle);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_bind_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_sck_t sck;
|
||||
moo_oop_t arg;
|
||||
int fd, enable;
|
||||
|
||||
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
arg = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(sck) &&
|
||||
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(sck->handle));
|
||||
MOO_PF_CHECK_ARGS (moo, nargs, MOO_OBJ_IS_BYTE_POINTER(arg));
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(sck->handle);
|
||||
if (fd <= -1)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "bad socket handle - %d", fd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
enable = 1;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, MOO_SIZEOF(int)) == -1 ||
|
||||
bind(fd, (struct sockaddr*)MOO_OBJ_GET_BYTE_SLOT(arg), moo_sck_addr_len((sck_addr_t*)MOO_OBJ_GET_BYTE_SLOT(arg))) == -1)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_accept_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_sck_t sck, newsck;
|
||||
moo_oop_t arg;
|
||||
sck_len_t addrlen;
|
||||
int fd, newfd, fl;
|
||||
|
||||
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
arg = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(sck) &&
|
||||
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(sck->handle));
|
||||
MOO_PF_CHECK_ARGS (moo, nargs, MOO_OBJ_IS_BYTE_POINTER(arg));
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(sck->handle);
|
||||
if (fd <= -1)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "bad socket handle - %d", fd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
addrlen = MOO_OBJ_GET_SIZE(arg);
|
||||
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC) && defined(HAVE_ACCEPT4)
|
||||
newfd = accept4(fd, (struct sockaddr*)MOO_OBJ_GET_BYTE_SLOT(arg), &addrlen, SOCK_NONBLOCK | SOCK_CLOEXEC);
|
||||
if (newfd == -1)
|
||||
{
|
||||
if (errno == ENOSYS) goto normal_accept;
|
||||
|
||||
if (errno != EWOULDBLOCK && errno != EAGAIN)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
/* return nil if accept() is not ready to accept a socket */
|
||||
MOO_STACK_SETRET (moo, nargs, moo->_nil);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
goto accept_done;
|
||||
}
|
||||
normal_accept:
|
||||
#endif
|
||||
|
||||
newfd = accept(fd, (struct sockaddr*)MOO_OBJ_GET_BYTE_SLOT(arg), &addrlen);
|
||||
if (newfd == -1)
|
||||
{
|
||||
if (errno != EWOULDBLOCK && errno != EAGAIN)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
/* return nil if accept() is not ready to accept a socket */
|
||||
MOO_STACK_SETRET (moo, nargs, moo->_nil);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
fl = fcntl(newfd, F_GETFL, 0);
|
||||
if (fl == -1)
|
||||
{
|
||||
fcntl_failure:
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
close (newfd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
fl |= O_NONBLOCK;
|
||||
#if defined(O_CLOEXEC)
|
||||
fl |= O_CLOEXEC;
|
||||
#endif
|
||||
if (fcntl(newfd, F_SETFL, fl) == -1) goto fcntl_failure;
|
||||
|
||||
#if 0
|
||||
accept_done:
|
||||
/*newsck = (oop_sck_t)moo_instantiate(moo, MOO_OBJ_GET_CLASS(sck), MOO_NULL, 0);*/
|
||||
newsck = (oop_sck_t)moo_instantiate(moo, ((sck_modctx_t*)mod->ctx)->sck_class, MOO_NULL, 0);
|
||||
if (!newsck)
|
||||
{
|
||||
close (newfd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (!MOO_IN_SMOOI_RANGE(newfd))
|
||||
{
|
||||
/* the file descriptor is too big to be represented as a small integer */
|
||||
moo_seterrbfmt (moo, MOO_ERANGE, "socket handle %d not in the permitted range", newfd);
|
||||
close (newfd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
newsck->handle = MOO_SMOOI_TO_OOP(newfd);
|
||||
|
||||
/* return the partially initialized socket object. the handle field is set to the new file
|
||||
* descriptor. however all other fields are just set to nil. so the user of this primitive
|
||||
* method should call application-level initializer. */
|
||||
MOO_STACK_SETRET (moo, nargs, (moo_oop_t)newsck);
|
||||
return MOO_PF_SUCCESS;
|
||||
#else
|
||||
accept_done:
|
||||
if (!MOO_IN_SMOOI_RANGE(newfd))
|
||||
{
|
||||
/* the file descriptor is too big to be represented as a small integer */
|
||||
moo_seterrbfmt (moo, MOO_ERANGE, "socket handle %d not in the permitted range", newfd);
|
||||
close (newfd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(newfd));
|
||||
return MOO_PF_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_listen_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_sck_t sck;
|
||||
moo_oop_t arg;
|
||||
int fd, n;
|
||||
|
||||
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
arg = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(sck) &&
|
||||
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(sck->handle));/*newsck = (oop_sck_t)moo_instantiate(moo, MOO_OBJ_GET_CLASS(sck), MOO_NULL, 0);*/
|
||||
MOO_PF_CHECK_ARGS (moo, nargs, MOO_OOP_IS_SMOOI(arg));
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(sck->handle);
|
||||
if (fd <= -1)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "bad socket handle - %d", fd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
n = listen(fd, MOO_OOP_TO_SMOOI(arg));
|
||||
if (n == -1)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static moo_pfrc_t pf_connect_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_sck_t sck;
|
||||
int fd, n;
|
||||
moo_oop_t arg;
|
||||
|
||||
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
arg = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(sck) &&
|
||||
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(sck->handle));
|
||||
MOO_PF_CHECK_ARGS (moo, nargs, MOO_OBJ_IS_BYTE_POINTER(arg));
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(sck->handle);
|
||||
if (fd <= -1)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "bad socket handle - %d", fd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
n = connect(fd, (struct sockaddr*)MOO_OBJ_GET_BYTE_SLOT(arg), moo_sck_addr_len((sck_addr_t*)MOO_OBJ_GET_BYTE_SLOT(arg)));
|
||||
if (n == -1)
|
||||
{
|
||||
if (errno == EINPROGRESS)
|
||||
{
|
||||
/* have the primitive function to return -1 */
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(-1));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(0));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_get_socket_error (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_sck_t sck;
|
||||
int fd, ret;
|
||||
sck_len_t len;
|
||||
|
||||
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(sck) &&
|
||||
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(sck->handle)
|
||||
);
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(sck->handle);
|
||||
if (fd <= -1)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "bad socket handle - %d", fd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
len = MOO_SIZEOF(ret);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*)&ret, &len) == -1)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (ret == EINPROGRESS) ret = -1; /* map EINPROGRESS to -1. all others are returned without change */
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(ret));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_read_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_sck_t sck;
|
||||
moo_oop_byte_t buf;
|
||||
moo_oow_t offset, length, maxlen;
|
||||
int fd;
|
||||
ssize_t n;
|
||||
|
||||
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(sck) &&
|
||||
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(sck->handle)
|
||||
);
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(sck->handle);
|
||||
if (fd <= -1)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "bad socket handle - %d", fd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
buf = (moo_oop_byte_t)MOO_STACK_GETARG (moo, nargs, 0);
|
||||
if (!MOO_OBJ_IS_BYTE_POINTER(buf))
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "buffer not a byte array - %O", buf);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
offset = 0;
|
||||
maxlen = MOO_OBJ_GET_SIZE(buf);
|
||||
length = maxlen;
|
||||
|
||||
if (nargs >= 2)
|
||||
{
|
||||
moo_oop_t tmp;
|
||||
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 1);
|
||||
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (nargs >= 3)
|
||||
{
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 2);
|
||||
if (moo_inttooow_noseterr(moo, tmp, &length) <= 0)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid length - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (offset >= maxlen) offset = maxlen - 1;
|
||||
if (length > maxlen - offset) length = maxlen - offset;
|
||||
}
|
||||
|
||||
n = recv(fd, MOO_OBJ_GET_BYTE_PTR(buf, offset), length, 0);
|
||||
if (n <= -1 && errno != EWOULDBLOCK && errno != EAGAIN)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
/* [NOTE] on EWOULDBLOCK or EGAIN, -1 is returned */
|
||||
|
||||
MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(n));
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(n));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_write_socket (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_sck_t sck;
|
||||
moo_oop_byte_t buf;
|
||||
moo_oow_t offset, length, maxlen;
|
||||
int fd;
|
||||
ssize_t n;
|
||||
|
||||
sck = (oop_sck_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
MOO_PF_CHECK_RCV (moo,
|
||||
MOO_OOP_IS_POINTER(sck) &&
|
||||
MOO_OBJ_BYTESOF(sck) >= (MOO_SIZEOF(*sck) - MOO_SIZEOF(moo_obj_t)) &&
|
||||
MOO_OOP_IS_SMOOI(sck->handle)
|
||||
);
|
||||
|
||||
fd = MOO_OOP_TO_SMOOI(sck->handle);
|
||||
if (fd <= -1)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "bad socket handle - %d", fd);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
buf = (moo_oop_byte_t)MOO_STACK_GETARG (moo, nargs, 0);
|
||||
if (!MOO_OBJ_IS_BYTE_POINTER(buf))
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "buffer not a byte array - %O", buf);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
offset = 0;
|
||||
maxlen = MOO_OBJ_GET_SIZE(buf);
|
||||
length = maxlen;
|
||||
|
||||
if (nargs >= 2)
|
||||
{
|
||||
moo_oop_t tmp;
|
||||
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 1);
|
||||
if (moo_inttooow_noseterr(moo, tmp, &offset) <= 0)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid offset - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
if (nargs >= 3)
|
||||
{
|
||||
tmp = MOO_STACK_GETARG(moo, nargs, 2);
|
||||
if (moo_inttooow_noseterr(moo, tmp, &length) <= 0)
|
||||
{
|
||||
moo_seterrbfmt (moo, MOO_EINVAL, "invalid length - %O", tmp);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (offset >= maxlen) offset = maxlen - 1;
|
||||
if (length > maxlen - offset) length = maxlen - offset;
|
||||
}
|
||||
|
||||
n = send(fd, MOO_OBJ_GET_BYTE_PTR(buf, offset), length, 0);
|
||||
if (n <= -1 && errno != EWOULDBLOCK && errno != EAGAIN)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
return MOO_PF_FAILURE;
|
||||
}
|
||||
|
||||
/* [NOTE] on EWOULDBLOCK or EGAIN, -1 is returned */
|
||||
MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(n));
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(n));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
#define C MOO_METHOD_CLASS
|
||||
#define I MOO_METHOD_INSTANCE
|
||||
|
||||
#define MA MOO_TYPE_MAX(moo_oow_t)
|
||||
|
||||
static moo_pfinfo_t pfinfos[] =
|
||||
{
|
||||
{ I, "accept:", { pf_accept_socket, 1, 1 } },
|
||||
{ I, "bind:", { pf_bind_socket, 1, 1 } },
|
||||
{ I, "close", { pf_close_socket, 0, 0 } },
|
||||
{ I, "connect:", { pf_connect_socket, 1, 1 } },
|
||||
{ I, "listen:", { pf_listen_socket, 1, 1 } },
|
||||
{ I, "open", { pf_open_socket, 1, 3 } },
|
||||
{ I, "readBytesInto:", { pf_read_socket, 1, 1 } },
|
||||
{ I, "readBytesInto:startingAt:for:", { pf_read_socket, 3, 3 } },
|
||||
{ I, "socketError", { pf_get_socket_error, 0, 0 } },
|
||||
{ I, "writeBytesFrom:", { pf_write_socket, 1, 1 } },
|
||||
{ I, "writeBytesFrom:startingAt:for:", { pf_write_socket, 3, 3 } }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
|
||||
{
|
||||
/*if (moo_setclasstrsize(moo, _class, MOO_SIZEOF(sck_t), MOO_NULL) <= -1) return -1;*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
static moo_pfbase_t* querypf (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
|
||||
{
|
||||
return moo_findpfbase(moo, pfinfos, MOO_COUNTOF(pfinfos), name, namelen);
|
||||
}
|
||||
|
||||
static void unload (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
/* TODO: anything? close open open dll handles? For that, pf_open must store the value it returns to mod->ctx or somewhere..*/
|
||||
if (mod->ctx) moo_freemem (moo, mod->ctx);
|
||||
}
|
||||
|
||||
static void gc_mod_sck (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
sck_modctx_t* ctx = mod->ctx;
|
||||
|
||||
MOO_ASSERT (moo, ctx != MOO_NULL);
|
||||
if (ctx->sck_class)
|
||||
{
|
||||
ctx->sck_class = (moo_oop_class_t)moo_updateoopforgc(moo, (moo_oop_t)ctx->sck_class);
|
||||
}
|
||||
}
|
||||
|
||||
int moo_mod_sck (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
/*
|
||||
if (mod->hints & MOO_MOD_LOAD_FOR_IMPORT)
|
||||
{
|
||||
mod->gc = MOO_NULL;
|
||||
mod->ctx = MOO_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
sck_modctx_t* ctx;
|
||||
|
||||
static moo_ooch_t name_sck[] = { 'S','o','c','k','e','t','\0' };
|
||||
|
||||
ctx = moo_callocmem(moo, MOO_SIZEOF(*ctx));
|
||||
if (!ctx) return -1;
|
||||
|
||||
ctx->sck_class = (moo_oop_class_t)moo_findclass(moo, moo->sysdic, name_sck);
|
||||
if (!ctx->sck_class)
|
||||
{
|
||||
MOO_DEBUG0 (moo, "Socket class not found\n");
|
||||
moo_freemem (moo, ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mod->gc = gc_mod_sck;
|
||||
mod->ctx = ctx;
|
||||
}
|
||||
*/
|
||||
|
||||
mod->import = import;
|
||||
mod->querypf = querypf;
|
||||
mod->querypv = MOO_NULL;
|
||||
mod->unload = unload;
|
||||
return 0;
|
||||
}
|
258
mod/stdio.c
Normal file
258
mod/stdio.c
Normal file
@ -0,0 +1,258 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2019 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 "_stdio.h"
|
||||
#include <moo-utl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#if !defined(PATH_MAX)
|
||||
# define PATH_MAX 256
|
||||
#endif
|
||||
|
||||
typedef struct stdio_t stdio_t;
|
||||
struct stdio_t
|
||||
{
|
||||
FILE* fp;
|
||||
};
|
||||
|
||||
static moo_pfrc_t pf_open (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
moo_oop_char_t name;
|
||||
moo_oop_char_t mode;
|
||||
stdio_t* stdio;
|
||||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
moo_oow_t ucslen, bcslen;
|
||||
moo_bch_t namebuf[PATH_MAX];
|
||||
moo_bch_t modebuf[32]; /* TODO: mode should not be long but use dynamic-sized conversion?? */
|
||||
#endif
|
||||
|
||||
stdio = (stdio_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
|
||||
name = (moo_oop_char_t)MOO_STACK_GETARG(moo, nargs, 0);
|
||||
mode = (moo_oop_char_t)MOO_STACK_GETARG(moo, nargs, 1);
|
||||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
ucslen = MOO_OBJ_GET_SIZE(name);
|
||||
bcslen = MOO_COUNTOF(namebuf) - 1;
|
||||
if (moo_convootobchars(moo, MOO_OBJ_GET_CHAR_SLOT(name), &ucslen, namebuf, &bcslen) <= -1) goto softfail;
|
||||
namebuf[bcslen] = '\0';
|
||||
|
||||
ucslen = MOO_OBJ_GET_SIZE(mode);
|
||||
bcslen = MOO_COUNTOF(modebuf) - 1;
|
||||
if (moo_convootobchars(moo, MOO_OBJ_GET_CHAR_SLOT(mode), &ucslen, modebuf, &bcslen) <= -1) goto softfail;
|
||||
modebuf[bcslen] = '\0';
|
||||
|
||||
stdio->fp = fopen(namebuf, modebuf);
|
||||
#else
|
||||
stdio->fp = fopen(MOO_OBJ_GET_CHAR_SLOT(name), MOO_OBJ_GET_CHAR_SLOT(mode));
|
||||
#endif
|
||||
if (!stdio->fp)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
goto softfail;
|
||||
}
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
|
||||
softfail:
|
||||
MOO_STACK_SETRETTOERRNUM (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_close (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
stdio_t* stdio;
|
||||
|
||||
stdio = (stdio_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
|
||||
if (stdio->fp)
|
||||
{
|
||||
fclose (stdio->fp);
|
||||
stdio->fp = NULL;
|
||||
}
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_gets (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
/* TODO: ...*/
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t __pf_puts (moo_t* moo, moo_ooi_t nargs, moo_oow_t limit)
|
||||
{
|
||||
stdio_t* stdio;
|
||||
moo_ooi_t i;
|
||||
|
||||
stdio = (stdio_t*)moo_getobjtrailer(moo, MOO_STACK_GETRCV(moo, nargs), MOO_NULL);
|
||||
|
||||
for (i = 0; i < nargs; i++)
|
||||
{
|
||||
moo_oop_char_t x;
|
||||
moo_obj_char_t tmpc;
|
||||
|
||||
x = (moo_oop_char_t)MOO_STACK_GETARG(moo, nargs, i);
|
||||
if (MOO_OOP_IS_CHAR(x))
|
||||
{
|
||||
/* do some faking. */
|
||||
MOO_ASSERT (moo, MOO_SIZEOF(tmpc) >= MOO_SIZEOF(moo_obj_t) + MOO_SIZEOF(moo_ooch_t));
|
||||
|
||||
tmpc.slot[0] = MOO_OOP_TO_CHAR(x);
|
||||
x = (moo_oop_char_t)&tmpc;
|
||||
MOO_OBJ_SET_SIZE(x, 1);
|
||||
goto puts_string;
|
||||
}
|
||||
else if (MOO_OOP_IS_POINTER(x) && MOO_OBJ_GET_FLAGS_TYPE(x) == MOO_OBJ_TYPE_CHAR)
|
||||
{
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
int n;
|
||||
moo_oow_t ucspos, ucsrem, ucslen, bcslen;
|
||||
moo_bch_t bcs[1024]; /* TODO: choose a better buffer size */
|
||||
|
||||
puts_string:
|
||||
ucspos = 0;
|
||||
ucsrem = MOO_OBJ_GET_SIZE(x);
|
||||
if (ucsrem > limit) ucsrem = limit;
|
||||
|
||||
while (ucsrem > 0)
|
||||
{
|
||||
ucslen = ucsrem;
|
||||
bcslen = MOO_COUNTOF(bcs);
|
||||
|
||||
/* TODO: implement character conversion into stdio and use it instead of vm's conversion facility. */
|
||||
if ((n = moo_convootobchars (moo, MOO_OBJ_GET_CHAR_PTR(x, ucspos), &ucslen, bcs, &bcslen)) <= -1)
|
||||
{
|
||||
if (n != -2 || ucslen <= 0) goto softfail;
|
||||
}
|
||||
|
||||
if (fwrite (bcs, 1, bcslen, stdio->fp) < bcslen)
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
goto softfail;
|
||||
}
|
||||
|
||||
/* TODO: abort looping for async processing???? */
|
||||
ucspos += ucslen;
|
||||
ucsrem -= ucslen;
|
||||
}
|
||||
#else
|
||||
puts_string:
|
||||
if (fwrite (MOO_OBJ_GET_CHAR_SLOT(x), 1, MOO_OBJ_GET_SIZE(x), stdio->fp) < MOO_OBJ_GET_SIZE(x))
|
||||
{
|
||||
moo_seterrwithsyserr (moo, 0, errno);
|
||||
goto softfail;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
moo_seterrnum (moo, MOO_EINVAL);
|
||||
goto softfail;
|
||||
}
|
||||
}
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
|
||||
softfail:
|
||||
MOO_STACK_SETRETTOERRNUM (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_putc (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
return __pf_puts (moo, nargs, 1);
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_puts (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
return __pf_puts (moo, nargs, MOO_TYPE_MAX(moo_oow_t));
|
||||
}
|
||||
|
||||
/*TODO: add print function that can accept ByteArray
|
||||
* add format function for formatted output */
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
#define C MOO_METHOD_CLASS
|
||||
#define I MOO_METHOD_INSTANCE
|
||||
#define MA MOO_TYPE_MAX(moo_oow_t)
|
||||
|
||||
static moo_pfinfo_t pfinfos[] =
|
||||
{
|
||||
{ I, "close", { pf_close, 0, 0 } },
|
||||
{ I, "gets", { pf_gets, 0, 0 } },
|
||||
{ I, "open", { pf_open, 2, 2 } },
|
||||
{ I, "putc", { pf_putc, 0, MA } },
|
||||
{ I, "puts", { pf_puts, 0, MA } }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
static int import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
|
||||
{
|
||||
if (moo_setclasstrsize(moo, _class, MOO_SIZEOF(stdio_t), MOO_NULL) <= -1) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static moo_pfbase_t* querypf (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
|
||||
{
|
||||
return moo_findpfbase(moo, pfinfos, MOO_COUNTOF(pfinfos), name, namelen);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* TOOD: concept of a argument_check fucntion?
|
||||
* check if receiver is a certain object?
|
||||
* check if receiver is at a certain size?
|
||||
* etc...
|
||||
*/
|
||||
static int sanity_check (moo_t* moo)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
static void unload (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
/* TODO: close all open handle?? */
|
||||
}
|
||||
|
||||
int moo_mod_stdio (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
mod->import = import;
|
||||
mod->querypf = querypf;
|
||||
mod->querypv = MOO_NULL;
|
||||
mod->unload = unload;
|
||||
mod->ctx = MOO_NULL;
|
||||
return 0;
|
||||
}
|
||||
|
879
mod/x11.c
Normal file
879
mod/x11.c
Normal file
@ -0,0 +1,879 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2014-2019 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 "_x11.h"
|
||||
#include <moo-utl.h>
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
typedef struct x11_modctx_t x11_modctx_t;
|
||||
struct x11_modctx_t
|
||||
{
|
||||
moo_oop_class_t x11_class;
|
||||
};
|
||||
|
||||
/* TODO: bchars_to_xchar2bstr??? */
|
||||
static XChar2b* uchars_to_xchar2bstr (moo_t* moo, const moo_uch_t* inptr, moo_oow_t inlen, moo_oow_t* outlen)
|
||||
{
|
||||
moo_uch_t uch;
|
||||
const moo_uch_t* endptr;
|
||||
XChar2b* outbuf, * outptr;
|
||||
|
||||
outbuf = moo_allocmem(moo, (inlen + 1) * MOO_SIZEOF(*outptr));
|
||||
if (!outbuf) return MOO_NULL;
|
||||
|
||||
outptr = outbuf;
|
||||
endptr = inptr + inlen;
|
||||
while (inptr < endptr)
|
||||
{
|
||||
uch = *inptr++;
|
||||
|
||||
#if (MOO_SIZEOF_UCH_T > 2)
|
||||
if (uch > 0xFFFF) uch = 0xFFFD; /* unicode replacement character */
|
||||
#endif
|
||||
|
||||
outptr->byte1 = (uch >> 8) & 0xFF;
|
||||
outptr->byte2 = uch & 0xFF;
|
||||
outptr++;
|
||||
}
|
||||
|
||||
outptr->byte1 = 0;
|
||||
outptr->byte2 = 0;
|
||||
|
||||
if (outlen) *outlen = outptr - outbuf;
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
static moo_pfrc_t pf_open_display (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_x11_t x11;
|
||||
x11_trailer_t* tr;
|
||||
|
||||
Display* disp = MOO_NULL;
|
||||
XEvent* event = MOO_NULL;
|
||||
char* dispname = MOO_NULL;
|
||||
moo_ooi_t connno;
|
||||
|
||||
// TODO: CHECK if the receiver is an X11 object
|
||||
|
||||
if (nargs >= 1)
|
||||
{
|
||||
moo_oop_t np;
|
||||
|
||||
np = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
if (np != moo->_nil)
|
||||
{
|
||||
moo_oow_t bl;
|
||||
|
||||
if (!MOO_OBJ_IS_CHAR_POINTER(np))
|
||||
{
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
bl = MOO_OBJ_GET_SIZE(np);
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
dispname = moo_dupootobcstr(moo, MOO_OBJ_GET_CHAR_SLOT(np), &bl);
|
||||
if (!dispname)
|
||||
{
|
||||
MOO_DEBUG2 (moo, "<x11.connect> Cannot convert display name %.*js\n", MOO_OBJ_GET_SIZE(np), MOO_OBJ_GET_CHAR_SLOT(np));
|
||||
MOO_STACK_SETRETTOERRNUM (moo, nargs);
|
||||
goto oops;
|
||||
}
|
||||
#else
|
||||
dispname = MOO_OBJ_GET_CHAR_SLOT(np);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
event = moo_allocmem(moo, MOO_SIZEOF(*event));
|
||||
if (!event)
|
||||
{
|
||||
MOO_STACK_SETRETTOERRNUM (moo, nargs);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
disp = XOpenDisplay(dispname);
|
||||
if (!disp)
|
||||
{
|
||||
MOO_DEBUG1 (moo, "<x11.open_display> Cannot connect to X11 server %hs\n", XDisplayName(dispname));
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ESYSERR);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
if (!MOO_IN_SMPTR_RANGE(disp))
|
||||
{
|
||||
MOO_DEBUG1 (moo, "<x11.open_display> Display pointer to %hs not in small pointer range\n", XDisplayName(dispname));
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ERANGE);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
connno = ConnectionNumber(disp);
|
||||
if (!MOO_IN_SMOOI_RANGE(connno))
|
||||
{
|
||||
MOO_DEBUG1 (moo, "<x11.open_display> Connection number to %hs out of small integer range\n", XDisplayName(dispname));
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ERANGE);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
x11 = (oop_x11_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
|
||||
tr = (x11_trailer_t*)moo_getobjtrailer (moo, (moo_oop_t)x11, MOO_NULL);
|
||||
tr->event = event;
|
||||
tr->connection_number = connno;
|
||||
tr->wm_delete_window = XInternAtom (disp, "WM_DELETE_WINDOW", False);
|
||||
|
||||
MOO_ASSERT (moo, MOO_IN_SMPTR_RANGE(disp));
|
||||
x11->display = MOO_SMPTR_TO_OOP(disp);
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
if (dispname) moo_freemem (moo, dispname);
|
||||
#endif
|
||||
return MOO_PF_SUCCESS;
|
||||
|
||||
oops:
|
||||
if (disp) XCloseDisplay (disp);
|
||||
if (event) moo_freemem (moo, event);
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
if (dispname) moo_freemem (moo, dispname);
|
||||
#endif
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_close_display (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_x11_t x11;
|
||||
x11_trailer_t* tr;
|
||||
|
||||
// TODO: CHECK if the receiver is an X11 object
|
||||
|
||||
x11 = (oop_x11_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
if (x11->display != moo->_nil)
|
||||
{
|
||||
MOO_ASSERT (moo, MOO_OOP_IS_SMPTR(x11->display));
|
||||
XCloseDisplay (MOO_OOP_TO_SMPTR(x11->display));
|
||||
x11->display = moo->_nil;
|
||||
}
|
||||
|
||||
|
||||
tr = moo_getobjtrailer (moo, MOO_STACK_GETRCV(moo,nargs), MOO_NULL);
|
||||
if (tr->event)
|
||||
{
|
||||
moo_freemem (moo, tr->event);
|
||||
tr->event = MOO_NULL;
|
||||
}
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_get_fd (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
x11_trailer_t* tr;
|
||||
// TODO: CHECK if the receiver is an X11 object
|
||||
tr = moo_getobjtrailer (moo, MOO_STACK_GETRCV(moo,nargs), MOO_NULL);
|
||||
MOO_STACK_SETRET(moo, nargs, MOO_SMOOI_TO_OOP(tr->connection_number));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_get_llevent (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_x11_t x11;
|
||||
x11_trailer_t* tr;
|
||||
|
||||
Display* disp;
|
||||
XEvent* event;
|
||||
|
||||
// TODO: CHECK if the receiver is an X11 object
|
||||
x11 = (oop_x11_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
//MOO_ASSERT (moo, MOO_CLASSOF(moo,x11) == modctx->x11_class);
|
||||
tr = moo_getobjtrailer(moo, (moo_oop_t)x11, MOO_NULL);
|
||||
|
||||
disp = MOO_OOP_TO_SMPTR(x11->display);
|
||||
event = tr->event;
|
||||
if (XPending(disp))
|
||||
{
|
||||
oop_x11_llevent_t e;
|
||||
|
||||
XNextEvent (disp, event);
|
||||
|
||||
e = (oop_x11_llevent_t)MOO_STACK_GETARG(moo, nargs, 0);
|
||||
/* TOOD: check if e is an instance of X11.LLEvent */
|
||||
e->type = MOO_SMOOI_TO_OOP(event->type);
|
||||
e->window = MOO_SMOOI_TO_OOP(0);
|
||||
|
||||
/* if the following is going to trigger GC directly or indirectly,
|
||||
* e must be proteced with moo_pushvolat().
|
||||
* also x11, tr must be refetched from the stack. */
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case ClientMessage:
|
||||
if (event->xclient.data.l[0] == tr->wm_delete_window)
|
||||
{
|
||||
e->type = MOO_SMOOI_TO_OOP(65537); /* match SHELL_CLOSE in X11.LLEventType */
|
||||
e->window = MOO_SMOOI_TO_OOP(event->xclient.window);
|
||||
/* WINDOW CLSOE EVENT */
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case Expose:
|
||||
{
|
||||
XRectangle rect;
|
||||
|
||||
rect.x = event->xexpose.x;
|
||||
rect.y = event->xexpose.y;
|
||||
rect.width = event->xexpose.width;
|
||||
rect.height = event->xexpose.height;
|
||||
if (XCheckWindowEvent(disp, event->xexpose.window, ExposureMask, event))
|
||||
{
|
||||
Region reg;
|
||||
|
||||
/* merge all expose events in the event queue */
|
||||
reg = XCreateRegion();
|
||||
XUnionRectWithRegion (&rect, reg, reg);
|
||||
|
||||
do
|
||||
{
|
||||
rect.x = event->xexpose.x;
|
||||
rect.y = event->xexpose.y;
|
||||
rect.width = event->xexpose.width;
|
||||
rect.height = event->xexpose.height;
|
||||
XUnionRectWithRegion (&rect, reg, reg);
|
||||
}
|
||||
while (XCheckWindowEvent(disp, event->xexpose.window, ExposureMask, event));
|
||||
|
||||
XClipBox (reg, &rect);
|
||||
XDestroyRegion (reg);
|
||||
}
|
||||
|
||||
e->window = MOO_SMOOI_TO_OOP(event->xexpose.window);
|
||||
e->x = MOO_SMOOI_TO_OOP(rect.x);
|
||||
e->y = MOO_SMOOI_TO_OOP(rect.y);
|
||||
e->width = MOO_SMOOI_TO_OOP(rect.width);
|
||||
e->height = MOO_SMOOI_TO_OOP(rect.height);
|
||||
break;
|
||||
}
|
||||
|
||||
case ButtonPress:
|
||||
case ButtonRelease:
|
||||
{
|
||||
e->window = MOO_SMOOI_TO_OOP(event->xbutton.window);
|
||||
e->x = MOO_SMOOI_TO_OOP(event->xbutton.x);
|
||||
e->y = MOO_SMOOI_TO_OOP(event->xbutton.y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, (moo_oop_t)e);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* nil if there is no event */
|
||||
MOO_DEBUG0 (moo, "NO PENDING EVENT....\n");
|
||||
MOO_STACK_SETRET (moo, nargs, moo->_nil);
|
||||
}
|
||||
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_create_window (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
Display* disp;
|
||||
Window wind; /* Window -> XID, unsigned long */
|
||||
int scrn;
|
||||
Window parent;
|
||||
XSetWindowAttributes attrs;
|
||||
|
||||
oop_x11_t x11;
|
||||
x11_trailer_t* tr;
|
||||
moo_oop_t a0, a1, a2, a3, a4, a5, a6;
|
||||
|
||||
x11 = (oop_x11_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
|
||||
a0 = MOO_STACK_GETARG(moo, nargs, 0); /* parent window - Integer or nil (Window) */
|
||||
a1 = MOO_STACK_GETARG(moo, nargs, 1); /* x - SmallInteger */
|
||||
a2 = MOO_STACK_GETARG(moo, nargs, 2); /* y - SmallInteger */
|
||||
a3 = MOO_STACK_GETARG(moo, nargs, 3); /* width - SmallInteger */
|
||||
a4 = MOO_STACK_GETARG(moo, nargs, 4); /* height - SmallInteger */
|
||||
a5 = MOO_STACK_GETARG(moo, nargs, 5); /* fgcolor - SmallInteger */
|
||||
a6 = MOO_STACK_GETARG(moo, nargs, 6); /* bgcolor - SmallInteger */
|
||||
|
||||
if (!MOO_OOP_IS_SMOOI(a1) || !MOO_OOP_IS_SMOOI(a2) || !MOO_OOP_IS_SMOOI(a3) ||
|
||||
!MOO_OOP_IS_SMOOI(a4) || !MOO_OOP_IS_SMOOI(a5) || !MOO_OOP_IS_SMOOI(a6))
|
||||
{
|
||||
einval:
|
||||
MOO_DEBUG0 (moo, "<x11.create_window> Invalid parameters\n");
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
tr = moo_getobjtrailer (moo, (moo_oop_t)x11, MOO_NULL);
|
||||
disp = MOO_OOP_TO_SMPTR(x11->display);
|
||||
|
||||
/* ScreenCount (disp); -> the number of screens available in this display server */
|
||||
|
||||
if (a0 == moo->_nil)
|
||||
{
|
||||
scrn = DefaultScreen (disp);
|
||||
parent = RootWindow (disp, scrn);
|
||||
}
|
||||
else if (!MOO_OOP_IS_SMOOI(a0)) goto einval;
|
||||
else
|
||||
{
|
||||
XWindowAttributes wa;
|
||||
|
||||
parent = MOO_OOP_TO_SMOOI(a0);
|
||||
XGetWindowAttributes (disp, parent, &wa);
|
||||
scrn = XScreenNumberOfScreen(wa.screen);
|
||||
}
|
||||
|
||||
attrs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | ExposureMask/* | StructureNotifyMask*/; /* TODO: accept it as a parameter??? */
|
||||
attrs.border_pixel = BlackPixel (disp, scrn); /* TODO: use a6 */
|
||||
attrs.background_pixel = WhitePixel (disp, scrn);/* TODO: use a7 */
|
||||
|
||||
wind = XCreateWindow (
|
||||
disp,
|
||||
parent,
|
||||
MOO_OOP_TO_SMOOI(a1), /* x */
|
||||
MOO_OOP_TO_SMOOI(a2), /* y */
|
||||
MOO_OOP_TO_SMOOI(a3), /* width */
|
||||
MOO_OOP_TO_SMOOI(a4), /* height */
|
||||
0, /* border width */
|
||||
CopyFromParent, /* depth */
|
||||
InputOutput, /* class */
|
||||
CopyFromParent, /* visual */
|
||||
CWEventMask | CWBackPixel | CWBorderPixel, &attrs);
|
||||
if (!wind)
|
||||
{
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ESYSERR);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
if (parent == RootWindow(disp, scrn))
|
||||
{
|
||||
XSetWMProtocols (disp, wind, &tr->wm_delete_window, 1);
|
||||
}
|
||||
|
||||
/*if (!MOO_IN_SMOOI_RANGE ((moo_ooi_t)wind))*/
|
||||
if (wind > MOO_SMOOI_MAX)
|
||||
{
|
||||
XDestroyWindow (disp, wind);
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ERANGE);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
XMapWindow (disp, wind);
|
||||
XFlush (disp);
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(wind));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_destroy_window (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_x11_t x11;
|
||||
moo_oop_t a0;
|
||||
|
||||
x11 = (oop_x11_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
a0 = MOO_STACK_GETARG(moo, nargs, 0); /* window - Integer (Window) */
|
||||
|
||||
if (!MOO_OOP_IS_SMOOI(a0))
|
||||
{
|
||||
MOO_DEBUG0 (moo, "<x11.destroy_window> Invalid parameters\n");
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
Display* disp;
|
||||
Window wind;
|
||||
|
||||
disp = MOO_OOP_TO_SMPTR(x11->display);
|
||||
wind = MOO_OOP_TO_SMOOI(a0);
|
||||
|
||||
XUnmapWindow (disp, wind);
|
||||
XDestroyWindow (disp, wind);
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
}
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_create_gc (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
Display* disp;
|
||||
Window wind;
|
||||
GC gc;
|
||||
XWindowAttributes wa;
|
||||
|
||||
oop_x11_t x11;
|
||||
moo_oop_t a0;
|
||||
|
||||
x11 = (oop_x11_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
disp = MOO_OOP_TO_SMPTR(x11->display);
|
||||
|
||||
a0 = MOO_STACK_GETARG(moo, nargs, 0); /* Window - SmallInteger */
|
||||
|
||||
if (!MOO_OOP_IS_SMOOI(a0))
|
||||
{
|
||||
MOO_DEBUG0 (moo, "<x11.create_gc> Invalid parameters\n");
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
wind = MOO_OOP_TO_SMOOI(a0);
|
||||
|
||||
gc = XCreateGC (disp, wind, 0, MOO_NULL);
|
||||
if (!MOO_IN_SMPTR_RANGE(gc))
|
||||
{
|
||||
MOO_DEBUG0 (moo, "<x11.create_gc> GC pointer not in small pointer range\n");
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ERANGE);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
/* XGetWindowAttributes (disp, wind, &wa);
|
||||
XCopyGC (disp, DefaultGC(disp, XScreenNumberOfScreen(wa.screen)), GCForeground | GCBackground | GCLineWidth | GCLineStyle, gc);*/
|
||||
|
||||
MOO_STACK_SETRET (moo, nargs, MOO_SMPTR_TO_OOP(gc));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_destroy_gc (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_x11_t x11;
|
||||
oop_x11_gc_t gc;
|
||||
|
||||
Display* disp;
|
||||
|
||||
x11 = (oop_x11_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
gc = (oop_x11_gc_t)MOO_STACK_GETARG(moo, nargs, 0); /* GC object */
|
||||
|
||||
disp = MOO_OOP_TO_SMPTR(x11->display);
|
||||
if (MOO_OOP_IS_SMPTR(gc->font_ptr))
|
||||
{
|
||||
XFreeFont (disp, MOO_OOP_TO_SMPTR(gc->font_ptr));
|
||||
gc->font_ptr = moo->_nil;
|
||||
}
|
||||
|
||||
if (MOO_OOP_IS_SMPTR(gc->font_set))
|
||||
{
|
||||
XFreeFontSet (disp, MOO_OOP_TO_SMPTR(gc->font_set));
|
||||
gc->font_set = moo->_nil;
|
||||
MOO_DEBUG0 (moo, "Freed Font Set\n");
|
||||
}
|
||||
|
||||
if (MOO_OOP_IS_SMPTR(gc->gc_handle))
|
||||
{
|
||||
XFreeGC (disp, MOO_OOP_TO_SMPTR(gc->gc_handle));
|
||||
gc->gc_handle= moo->_nil;
|
||||
}
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_apply_gc (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_x11_t x11;
|
||||
oop_x11_gc_t a0;
|
||||
|
||||
Display* disp;
|
||||
GC gc;
|
||||
unsigned long int mask = 0;
|
||||
XGCValues v;
|
||||
|
||||
x11 = (oop_x11_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
a0 = (oop_x11_gc_t)MOO_STACK_GETARG(moo, nargs, 0);
|
||||
/* TODO check if a0 is an instance of X11.GC */
|
||||
|
||||
if (!MOO_OOP_IS_SMPTR(a0->gc_handle))
|
||||
{
|
||||
MOO_DEBUG0 (moo, "<x11.apply_gc> Invalid parameters\n");
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
disp = MOO_OOP_TO_SMPTR(x11->display);
|
||||
gc = MOO_OOP_TO_SMPTR(a0->gc_handle);
|
||||
|
||||
if (MOO_OBJ_IS_CHAR_POINTER(a0->font_name) && MOO_OBJ_GET_SIZE(a0->font_name) > 0)
|
||||
{
|
||||
XFontSet fs;
|
||||
char **missing_charsets;
|
||||
int num_missing_charsets = 0;
|
||||
char *default_string;
|
||||
|
||||
/* TODO: don't create this again and again */
|
||||
/* TODO: use font name */
|
||||
fs = XCreateFontSet (disp, "-adobe-*-medium-r-normal-*-14-*-*-*-*-*-*-*,-baekmuk-*-medium-r-normal-*-14-*-*-*-*-*-*-*,-*-*-medium-r-normal-*-*-*-*-*-*-*-*-*",
|
||||
&missing_charsets, &num_missing_charsets, &default_string);
|
||||
if (num_missing_charsets)
|
||||
{
|
||||
int i;
|
||||
|
||||
MOO_DEBUG0 (moo, "The following charsets are missing:\n");
|
||||
for(i = 0; i < num_missing_charsets; i++)
|
||||
MOO_DEBUG1 (moo, "\t%s\n", missing_charsets[i]);
|
||||
MOO_DEBUG1 (moo, "The string %s will be used in place of any characters from those set\n", default_string);
|
||||
XFreeStringList(missing_charsets);
|
||||
}
|
||||
|
||||
if (fs)
|
||||
{
|
||||
/* TODO: error handling. rollback upon failure... etc */
|
||||
MOO_ASSERT (moo, MOO_IN_SMPTR_RANGE(fs));
|
||||
if (MOO_OOP_IS_SMPTR(a0->font_set))
|
||||
{
|
||||
MOO_DEBUG0 (moo, "Freed Font Set ..\n");
|
||||
XFreeFontSet (disp, MOO_OOP_TO_SMPTR(a0->font_set));
|
||||
}
|
||||
a0->font_set = MOO_SMPTR_TO_OOP (fs);
|
||||
MOO_DEBUG0 (moo, "XCreateFontSet ok....\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
XFontStruct* font;
|
||||
|
||||
/* TODO: .... use font_name */
|
||||
font = XLoadQueryFont (disp, "-misc-fixed-medium-r-normal-ko-18-120-100-100-c-180-iso10646-1");
|
||||
if (font)
|
||||
{
|
||||
if (!MOO_IN_SMPTR_RANGE(font))
|
||||
{
|
||||
MOO_DEBUG0 (moo, "<x11.apply_gc> Font pointer not in small pointer range\n");
|
||||
XFreeFont (disp, font);
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ERANGE);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
XSetFont (disp, gc, font->fid);
|
||||
if (MOO_OOP_IS_SMPTR(a0->font_ptr)) XFreeFont (disp, MOO_OOP_TO_SMPTR(a0->font_ptr));
|
||||
a0->font_ptr = MOO_SMPTR_TO_OOP(font);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MOO_DEBUG2 (moo, "<x11.apply_gc> Cannot load font - %.*js\n", MOO_OBJ_GET_SIZE(a0->font_name), MOO_OBJ_GET_CHAR_SLOT(a0->font_name));
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ESYSERR);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: accept mask as an option parameter. then only apply fields that matches this given mask */
|
||||
if (MOO_OOP_IS_SMOOI(a0->foreground))
|
||||
{
|
||||
mask |= GCForeground;
|
||||
v.foreground = MOO_OOP_TO_SMOOI(a0->foreground);
|
||||
}
|
||||
if (MOO_OOP_IS_SMOOI(a0->background))
|
||||
{
|
||||
mask |= GCBackground;
|
||||
v.background = MOO_OOP_TO_SMOOI(a0->background);
|
||||
}
|
||||
if (MOO_OOP_IS_SMOOI(a0->line_width))
|
||||
{
|
||||
mask |= GCLineWidth;
|
||||
v.line_width = MOO_OOP_TO_SMOOI(a0->line_width);
|
||||
}
|
||||
if (MOO_OOP_IS_SMOOI(a0->line_style))
|
||||
{
|
||||
mask |= GCLineStyle;
|
||||
v.line_style = MOO_OOP_TO_SMOOI(a0->line_style);
|
||||
}
|
||||
if (MOO_OOP_IS_SMOOI(a0->fill_style))
|
||||
{
|
||||
mask |= GCFillStyle;
|
||||
v.fill_style = MOO_OOP_TO_SMOOI(a0->fill_style);
|
||||
}
|
||||
XChangeGC (disp, gc, mask, &v);
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_draw_rectangle (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_x11_t x11;
|
||||
Display* disp;
|
||||
moo_oop_t a0, a1, a2, a3, a4, a5;
|
||||
|
||||
x11 = (oop_x11_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
disp = MOO_OOP_TO_SMPTR(x11->display);
|
||||
|
||||
a0 = MOO_STACK_GETARG(moo, nargs, 0); /* Window - SmallInteger */
|
||||
a1 = MOO_STACK_GETARG(moo, nargs, 1); /* GC - SMPTR */
|
||||
a2 = MOO_STACK_GETARG(moo, nargs, 2); /* x - SmallInteger */
|
||||
a3 = MOO_STACK_GETARG(moo, nargs, 3); /* y - SmallInteger */
|
||||
a4 = MOO_STACK_GETARG(moo, nargs, 4); /* width - SmallInteger */
|
||||
a5 = MOO_STACK_GETARG(moo, nargs, 5); /* height - SmallInteger */
|
||||
|
||||
if (!MOO_OOP_IS_SMOOI(a0) || !MOO_OOP_IS_SMPTR(a1) ||
|
||||
!MOO_OOP_IS_SMOOI(a2) || !MOO_OOP_IS_SMOOI(a3) ||
|
||||
!MOO_OOP_IS_SMOOI(a4) || !MOO_OOP_IS_SMOOI(a5))
|
||||
{
|
||||
MOO_DEBUG0 (moo, "<x11.draw_rectangle> Invalid parameters\n");
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
XDrawRectangle (disp, (Window)MOO_OOP_TO_SMOOI(a0), (GC)MOO_OOP_TO_SMPTR(a1),
|
||||
MOO_OOP_TO_SMOOI(a2), MOO_OOP_TO_SMOOI(a3),
|
||||
MOO_OOP_TO_SMOOI(a4), MOO_OOP_TO_SMOOI(a5));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static moo_pfrc_t pf_fill_rectangle (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_x11_t x11;
|
||||
Display* disp;
|
||||
moo_oop_t a0, a1, a2, a3, a4, a5;
|
||||
|
||||
x11 = (oop_x11_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
disp = MOO_OOP_TO_SMPTR(x11->display);
|
||||
|
||||
a0 = MOO_STACK_GETARG(moo, nargs, 0); /* Window - SmallInteger */
|
||||
a1 = MOO_STACK_GETARG(moo, nargs, 1); /* GC - SMPTR */
|
||||
a2 = MOO_STACK_GETARG(moo, nargs, 2); /* x - SmallInteger */
|
||||
a3 = MOO_STACK_GETARG(moo, nargs, 3); /* y - SmallInteger */
|
||||
a4 = MOO_STACK_GETARG(moo, nargs, 4); /* width - SmallInteger */
|
||||
a5 = MOO_STACK_GETARG(moo, nargs, 5); /* height - SmallInteger */
|
||||
|
||||
if (!MOO_OOP_IS_SMOOI(a0) || !MOO_OOP_IS_SMPTR(a1) ||
|
||||
!MOO_OOP_IS_SMOOI(a2) || !MOO_OOP_IS_SMOOI(a3) ||
|
||||
!MOO_OOP_IS_SMOOI(a4) || !MOO_OOP_IS_SMOOI(a5))
|
||||
{
|
||||
MOO_DEBUG0 (moo, "<x11.fill_rectangle> Invalid parameters\n");
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
XFillRectangle (disp, (Window)MOO_OOP_TO_SMOOI(a0), (GC)MOO_OOP_TO_SMPTR(a1),
|
||||
MOO_OOP_TO_SMOOI(a2), MOO_OOP_TO_SMOOI(a3),
|
||||
MOO_OOP_TO_SMOOI(a4), MOO_OOP_TO_SMOOI(a5));
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static moo_pfrc_t pf_draw_string (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
{
|
||||
oop_x11_t x11;
|
||||
oop_x11_gc_t gc;
|
||||
moo_oop_t a1, a2, a3;
|
||||
|
||||
Display* disp;
|
||||
|
||||
x11 = (oop_x11_t)MOO_STACK_GETRCV(moo, nargs);
|
||||
disp = MOO_OOP_TO_SMPTR(x11->display);
|
||||
|
||||
gc = (oop_x11_gc_t)MOO_STACK_GETARG(moo, nargs, 0); /* GC object */
|
||||
a1 = MOO_STACK_GETARG(moo, nargs, 1); /* x - SmallInteger */
|
||||
a2 = MOO_STACK_GETARG(moo, nargs, 2); /* y - SmallInteger */
|
||||
a3 = MOO_STACK_GETARG(moo, nargs, 3); /* string */
|
||||
|
||||
/* TODO: check if gc is an instance of X11.GC */
|
||||
|
||||
if (!MOO_OOP_IS_SMOOI(a1) || !MOO_OOP_IS_SMOOI(a2) ||
|
||||
!MOO_OBJ_IS_CHAR_POINTER(a3))
|
||||
{
|
||||
MOO_DEBUG0 (moo, "<x11.draw_string> Invalid parameters\n");
|
||||
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EINVAL);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
if (MOO_OOP_IS_SMPTR(gc->font_set))
|
||||
{
|
||||
moo_oow_t bcslen;
|
||||
moo_bch_t* bb;
|
||||
int ascent = 10;
|
||||
XRectangle r;
|
||||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
moo_oow_t oocslen;
|
||||
|
||||
oocslen = MOO_OBJ_GET_SIZE(a3);
|
||||
if (moo_convootobchars(moo, MOO_OBJ_GET_CHAR_SLOT(a3), &oocslen, MOO_NULL, &bcslen) <= -1 ||
|
||||
!(bb = moo_allocmem(moo, MOO_SIZEOF(moo_bch_t) * bcslen)))
|
||||
{
|
||||
MOO_DEBUG0 (moo, "<x11.draw_string> Error in converting a string\n");
|
||||
MOO_STACK_SETRETTOERRNUM (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
moo_convootobchars (moo, MOO_OBJ_GET_CHAR_SLOT(a3), &oocslen, bb, &bcslen);
|
||||
#else
|
||||
bb = MOO_OBJ_GET_CHAR_SLOT(a3);
|
||||
bcslen = MOO_OBJ_GET_SIZE(a3);
|
||||
#endif
|
||||
|
||||
XmbTextExtents(MOO_OOP_TO_SMPTR(gc->font_set), bb, bcslen, MOO_NULL, &r);
|
||||
ascent = r.height;
|
||||
|
||||
/* what about Xutf8DrawString? */
|
||||
XmbDrawString (disp, (Window)MOO_OOP_TO_SMOOI(((oop_x11_widget_t)gc->widget)->window_handle),
|
||||
MOO_OOP_TO_SMPTR(gc->font_set), MOO_OOP_TO_SMPTR(gc->gc_handle),
|
||||
MOO_OOP_TO_SMOOI(a1), MOO_OOP_TO_SMOOI(a2) + ascent, bb, bcslen);
|
||||
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
moo_freemem (moo, bb);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MOO_OOCH_IS_UCH)
|
||||
XChar2b* stptr;
|
||||
moo_oow_t stlen;
|
||||
int ascent = 0;
|
||||
|
||||
/* TODO: draw string chunk by chunk to avoid memory allocation in uchars_to_xchars2bstr */
|
||||
stptr = uchars_to_xchar2bstr(moo, MOO_OBJ_GET_CHAR_SLOT(a3), MOO_OBJ_GET_SIZE(a3), &stlen);
|
||||
if (!stptr)
|
||||
{
|
||||
MOO_DEBUG0 (moo, "<x11.draw_string> Error in converting a string\n");
|
||||
MOO_STACK_SETRETTOERRNUM (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
if (MOO_OOP_IS_SMPTR(gc->font_ptr))
|
||||
{
|
||||
int direction, descent;
|
||||
XCharStruct overall;
|
||||
XTextExtents16 (MOO_OOP_TO_SMPTR(gc->font_ptr), stptr, stlen, &direction, &ascent, &descent, &overall);
|
||||
}
|
||||
|
||||
XDrawString16 (disp, (Window)MOO_OOP_TO_SMOOI(((oop_x11_widget_t)gc->widget)->window_handle), MOO_OOP_TO_SMPTR(gc->gc_handle),
|
||||
MOO_OOP_TO_SMOOI(a1), MOO_OOP_TO_SMOOI(a2) + ascent, stptr, stlen);
|
||||
|
||||
moo_freemem (moo, stptr);
|
||||
#else
|
||||
int ascent = 0;
|
||||
|
||||
if (MOO_OOP_IS_SMPTR(gc->font_ptr))
|
||||
{
|
||||
int direction, descent;
|
||||
XCharStruct overall;
|
||||
XTextExtents16 (MOO_OOP_TO_SMPTR(gc->font_ptr), MOO_OBJ_GET_CHAR_SLOT(a3), MOO_OBJ_GET_SIZE(a3), &direction, &ascent, &descent, &overall);
|
||||
}
|
||||
|
||||
XDrawString (disp, (Window)MOO_OOP_TO_SMOOI(((oop_x11_widget_t)gc->widget)->window_handle), MOO_OOP_TO_SMPTR(gc->gc_handle),
|
||||
MOO_OOP_TO_SMOOI(a1), MOO_OOP_TO_SMOOI(a2) + ascent, MOO_OBJ_GET_CHAR_SLOT(a3), MOO_OBJ_GET_SIZE(a3));
|
||||
#endif
|
||||
}
|
||||
|
||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
static moo_pfinfo_t x11_pfinfo[] =
|
||||
{
|
||||
{ MI, "apply_gc", { pf_apply_gc, 1, 1 } },
|
||||
{ MI, "close_display", { pf_close_display, 0, 0 } },
|
||||
{ MI, "create_gc", { pf_create_gc, 1, 1 } },
|
||||
{ MI, "create_window", { pf_create_window, 7, 7 } },
|
||||
{ MI, "destroy_gc", { pf_destroy_gc, 1, 1 } },
|
||||
{ MI, "destroy_window", { pf_destroy_window, 1, 1 } },
|
||||
|
||||
{ MI, "draw_rectangle", { pf_draw_rectangle, 6, 6 } },
|
||||
{ MI, "draw_string", { pf_draw_string, 4, 4 } },
|
||||
{ MI, "fill_rectangle", { pf_fill_rectangle, 6, 6 } },
|
||||
{ MI, "get_fd", { pf_get_fd, 0, 0 } },
|
||||
{ MI, "get_llevent", { pf_get_llevent, 1, 1 } },
|
||||
{ MI, "open_display", { pf_open_display, 0, 1 } }
|
||||
};
|
||||
|
||||
static int x11_import (moo_t* moo, moo_mod_t* mod, moo_oop_class_t _class)
|
||||
{
|
||||
if (moo_setclasstrsize(moo, _class, MOO_SIZEOF(x11_trailer_t), MOO_NULL) <= -1) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static moo_pfbase_t* x11_querypf (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name, moo_oow_t namelen)
|
||||
{
|
||||
return moo_findpfbase(moo, x11_pfinfo, MOO_COUNTOF(x11_pfinfo), name, namelen);
|
||||
}
|
||||
|
||||
static void x11_unload (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
/* TODO: anything else? close all open dll handles? For that, pf_open must store the value it returns to mod->ctx or somewhere..*/
|
||||
moo_freemem (moo, mod->ctx);
|
||||
}
|
||||
|
||||
static void gc_mod_x11 (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
x11_modctx_t* ctx = mod->ctx;
|
||||
|
||||
MOO_ASSERT (moo, ctx != MOO_NULL);
|
||||
ctx->x11_class = (moo_oop_class_t)moo_updateoopforgc(moo, (moo_oop_t)ctx->x11_class);
|
||||
}
|
||||
|
||||
int moo_mod_x11 (moo_t* moo, moo_mod_t* mod)
|
||||
{
|
||||
if (mod->hints & MOO_MOD_LOAD_FOR_IMPORT)
|
||||
{
|
||||
mod->gc = MOO_NULL;
|
||||
mod->ctx = MOO_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
x11_modctx_t* ctx;
|
||||
moo_oop_t tmp;
|
||||
|
||||
static moo_ooch_t name_x11[] = { 'X','1','1','\0' };
|
||||
|
||||
ctx = moo_callocmem (moo, MOO_SIZEOF(*ctx));
|
||||
if (!ctx) return -1;
|
||||
|
||||
tmp = moo_findclass(moo, moo->sysdic, name_x11);
|
||||
if (!tmp)
|
||||
{
|
||||
/* Not a single X11.XXX has been defined. */
|
||||
MOO_DEBUG0 (moo, "X11 class not found\n");
|
||||
moo_freemem (moo, ctx);
|
||||
return -1;
|
||||
}
|
||||
MOO_STORE_OOP (moo, (moo_oop_t*)&ctx->x11_class, tmp);
|
||||
|
||||
mod->gc = gc_mod_x11;
|
||||
mod->ctx = ctx;
|
||||
}
|
||||
|
||||
mod->import = x11_import;
|
||||
mod->querypf = x11_querypf;
|
||||
mod->querypv = MOO_NULL;
|
||||
mod->unload = x11_unload;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
Reference in New Issue
Block a user