From 52d60ddf8ef31cdfa2c014e24733cd9bf8333564 Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 28 Nov 2015 05:08:48 -0500 Subject: initial commit. --- Makefile.in | 253 ++++++++++ config.project | 49 ++ config.usage | 77 +++ configure | 425 +++++++++++++++++ include/ntcon/ntcon.h | 884 +++++++++++++++++++++++++++++++++++ include/ntcon/ntcon_api.h | 32 ++ include/ntcon/ntcon_env.h | 22 + project/arch.mk | 0 project/common.mk | 4 + project/defs.mk | 31 ++ project/depends.mk | 0 project/extras.mk | 27 ++ project/headers.mk | 8 + project/overrides.mk | 0 project/tree.mk | 3 + src/ntcon.c | 146 ++++++ src/ntcon_entry_point.c | 13 + sysinfo/host/host.sh | 49 ++ sysinfo/host/i686-nt32-midipix.mk | 5 + sysinfo/host/i686-unknown-linux.mk | 5 + sysinfo/host/i686-w64-mingw32.mk | 5 + sysinfo/host/native.mk | 45 ++ sysinfo/host/x86_64-nt64-midipix.mk | 5 + sysinfo/host/x86_64-unknown-linux.mk | 5 + sysinfo/host/x86_64-w64-mingw32.mk | 5 + sysinfo/os/bsd.mk | 10 + sysinfo/os/darwin.mk | 10 + sysinfo/os/linux.mk | 10 + sysinfo/os/midipix.mk | 14 + sysinfo/os/mingw.mk | 15 + sysinfo/toolchain/clang.mk | 48 ++ sysinfo/toolchain/cparser.mk | 48 ++ sysinfo/toolchain/gcc.mk | 43 ++ 33 files changed, 2296 insertions(+) create mode 100644 Makefile.in create mode 100644 config.project create mode 100644 config.usage create mode 100755 configure create mode 100644 include/ntcon/ntcon.h create mode 100644 include/ntcon/ntcon_api.h create mode 100644 include/ntcon/ntcon_env.h create mode 100644 project/arch.mk create mode 100644 project/common.mk create mode 100644 project/defs.mk create mode 100644 project/depends.mk create mode 100644 project/extras.mk create mode 100644 project/headers.mk create mode 100644 project/overrides.mk create mode 100644 project/tree.mk create mode 100644 src/ntcon.c create mode 100644 src/ntcon_entry_point.c create mode 100755 sysinfo/host/host.sh create mode 100644 sysinfo/host/i686-nt32-midipix.mk create mode 100644 sysinfo/host/i686-unknown-linux.mk create mode 100644 sysinfo/host/i686-w64-mingw32.mk create mode 100644 sysinfo/host/native.mk create mode 100644 sysinfo/host/x86_64-nt64-midipix.mk create mode 100644 sysinfo/host/x86_64-unknown-linux.mk create mode 100644 sysinfo/host/x86_64-w64-mingw32.mk create mode 100644 sysinfo/os/bsd.mk create mode 100644 sysinfo/os/darwin.mk create mode 100644 sysinfo/os/linux.mk create mode 100644 sysinfo/os/midipix.mk create mode 100644 sysinfo/os/mingw.mk create mode 100644 sysinfo/toolchain/clang.mk create mode 100644 sysinfo/toolchain/cparser.mk create mode 100644 sysinfo/toolchain/gcc.mk diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 0000000..91425e9 --- /dev/null +++ b/Makefile.in @@ -0,0 +1,253 @@ +PACKAGE = @package@ +PROJECT_DIR = @project_dir@ + +BUILD = @build@ +HOST = @host@ +TARGET = @target@ +ARCH = @arch@ +TOOLCHAIN = @toolchain@ +SYSROOT = @sysroot@ +CROSS_COMPILE = @cross_compile@ +SHELL = @shell@ + +CFLAGS_DEBUG = @cflags_debug@ +CFLAGS_COMMON = @cflags_common@ +CFLAGS_CMDLINE = @cflags_cmdline@ +CFLAGS_CONFIG = @cflags_config@ +CFLAGS_SYSROOT = @cflags_sysroot@ +CFLAGS_PATH = @cflags_path@ + +LDFLAGS_DEBUG = @ldflags_debug@ +LDFLAGS_COMMON = @ldflags_common@ +LDFLAGS_CMDLINE = @ldflags_cmdline@ +LDFLAGS_CONFIG = @ldflags_config@ +LDFLAGS_SYSROOT = @ldflags_sysroot@ +LDFLAGS_PATH = @ldflags_path@ + +PE_SUBSYSTEM = @pe_subsystem@ +PE_IMAGE_BASE = @pe_image_base@ +PE_CONFIG_DEFS = @pe_config_defs@ + +ELF_EH_FRAME = @elf_eh_frame@ +ELF_HASH_STYLE = @elf_hash_style@ +ELF_CONFIG_DEFS = @elf_config_defs@ + +PREFIX = @prefix@ +BINDIR = @bindir@ +LIBDIR = @libdir@ +INCLUDEDIR = @includedir@ +SYSLIBDIR = @syslibdir@ +MANDIR = @mandir@ +DOCDIR = @docdir@ +LIBEXECDIR = @libexecdir@ + +NATIVE_CC = @native_cc@ +NATIVE_OS = @native_os@ +NATIVE_OS_BITS = @native_os_bits@ +NATIVE_OS_UNDERSCORE = @native_os_underscore@ + +USER_CC = @user_cc@ +USER_CPP = @user_cpp@ +USER_CXX = @user_cxx@ + + +all: +install: +shared: +static: + + + +include $(PROJECT_DIR)/sysinfo/host/$(HOST).mk +include $(PROJECT_DIR)/sysinfo/toolchain/$(TOOLCHAIN).mk + +include $(PROJECT_DIR)/project/defs.mk +include $(PROJECT_DIR)/project/tree.mk +include $(PROJECT_DIR)/project/depends.mk +include $(PROJECT_DIR)/project/headers.mk +include $(PROJECT_DIR)/project/common.mk +include $(PROJECT_DIR)/project/arch.mk +include $(PROJECT_DIR)/project/extras.mk +include $(PROJECT_DIR)/project/overrides.mk + + + +src/%.lo: $(PROJECT_DIR)/src/%.c $(ALL_HEADERS) host.tag tree.tag + $(CC) -c -o $@ $< $(CFLAGS_SHARED) + +src/%.o: $(PROJECT_DIR)/src/%.c $(ALL_HEADERS) host.tag tree.tag + $(CC) -c -o $@ $< $(CFLAGS_STATIC) + +$(LIBDIR)/%$(OS_LIB_SUFFIX): + $(CC) -shared -o $@ $^ $(LDFLAGS_SHARED) + +$(LIBDIR)/%$(OS_ARCHIVE_EXT): + rm -f $@ + $(AR) -rcs $@ $^ + + + +all: shared static + +install: install-libs install-headers + + +install-libs: install-shared install-static install-implib + +install-headers:shared static + mkdir -p $(DESTDIR)/./$(PREFIX)/./$(INCLUDEDIR)/$(PACKAGE) + cp $(API_HEADERS) $(DESTDIR)/./$(PREFIX)/./$(INCLUDEDIR)/$(PACKAGE) + +install-shared: shared install-implib + mkdir -p $(DESTDIR)/./$(PREFIX)/./$(LIBDIR) + cp $(SHARED_LIB) $(DESTDIR)/./$(PREFIX)/./$(LIBDIR) + +install-static: static + mkdir -p $(DESTDIR)/./$(PREFIX)/./$(LIBDIR) + cp $(STATIC_LIB) $(DESTDIR)/./$(PREFIX)/./$(LIBDIR) + + + +shared: shared-lib shared-implib + +static: static-lib + +shared-lib: shared-objs $(SHARED_LIB) + +static-lib: static-objs $(STATIC_LIB) + +shared-implib: shared-lib + + + +shared-objs: dirs $(SHARED_OBJS) + +static-objs: dirs $(STATIC_OBJS) + + + +$(SHARED_LIB): $(SHARED_OBJS) + +$(STATIC_LIB): $(STATIC_OBJS) + + +dirs: dirs.tag tree.tag + +dirs.tag: + mkdir -p $(LIBDIR) + touch dirs.tag + +host.tag: Makefile + $(PROJECT_DIR)/sysinfo/host/host.sh --compiler="$(CC)" --cflags="$(CFLAGS)" + touch host.tag + +distclean: clean + rm -f Makefile + +clean: + rm -f tree.tag + rm -f dirs.tag + rm -f host.tag + rm -f $(SHARED_OBJS) + rm -f $(STATIC_OBJS) + rm -f $(SHARED_LIB) + rm -f $(STATIC_LIB) + rm -f $(SHARED_IMPLIB) + + +.display: .display-env .display-tools .display-flags \ + .display-pe .display-elf .display-dirs .display-build + +.display-env: + @echo BUILD:' '$(BUILD) + @echo HOST:' '$(HOST) + @echo TARGET:' '$(TARGET) + @echo ARCH:' '$(ARCH) + @echo TOOLCHAIN:' '$(TOOLCHAIN) + @echo SYSROOT:' '$(SYSROOT) + @echo XCOMPILE:' '$(CROSS_COMPILE) + @echo SHELL:' '$(SHELL) + @echo + +.display-tools: + @echo CC:' '$(CC) + @echo CPP:' '$(CPP) + @echo CXX:' '$(CXX) + @echo + @echo AS:' '$(AS) + @echo AR:' '$(AR) + @echo LD:' '$(LD) + @echo NM:' '$(NM) + @echo OBJDUMP:' '$(OBJDUMP) + @echo RANLIB:' '$(RANLIB) + @echo SIZE:' '$(SIZE) + @echo STRIP:' '$(STRIP) + @echo STRINGS:' '$(STRINGS) + @echo + @echo ADDR2LINE:' '$(ADDR2LINE) + @echo COV:' '$(COV) + @echo CXXFILT' '$(CXXFILT) + @echo ELFEDIT:' '$(ELFEDIT) + @echo OBJCOPY:' '$(OBJCOPY) + @echo READELF:' '$(READELF) + @echo + +.display-flags: + @echo CFLAGS_DEBUG:' '$(CFLAGS_DEBUG) + @echo CFLAGS_COMMON:' '$(CFLAGS_COMMON) + @echo CFLAGS_CMDLINE:' '$(CFLAGS_CMDLINE) + @echo CFLAGS_CONFIG:' '$(CFLAGS_CONFIG) + @echo CFLAGS_SYSROOT:' '$(CFLAGS_SYSROOT) + @echo CFLAGS_PATH:' '$(CFLAGS_PATH) + @echo + @echo LDFLAGS_DEBUG:' '$(LDFLAGS_DEBUG) + @echo LDFLAGS_COMMON:' '$(LDFLAGS_COMMON) + @echo LDFLAGS_CMDLINE:' '$(LDFLAGS_CMDLINE) + @echo LDFLAGS_CONFIG:' '$(LDFLAGS_CONFIG) + @echo LDFLAGS_SYSROOT:' '$(LDFLAGS_SYSROOT) + @echo LDFLAGS_PATH:' '$(LDFLAGS_PATH) + @echo + +.display-pe: + @echo PE_SUBSYSTEM:' '$(PE_SUBSYSTEM) + @echo PE_IMAGE_BASE:' '$(PE_IMAGE_BASE) + @echo PE_CONFIG_DEFS:' '$(PE_CONFIG_DEFS) + @echo + +.display-elf: + @echo ELF_EH_FRAME:' '$(ELF_EH_FRAME) + @echo ELF_HASH_STYLE:' '$(ELF_HASH_STYLE) + @echo ELF_CONFIG_DEFS:' '$(ELF_CONFIG_DEFS) + @echo + +.display-dirs: + @echo PREFIX:' '$(PREFIX) + @echo BINDIR:' '$(BINDIR) + @echo LIBDIR:' '$(LIBDIR) + @echo INCLUDEDIR:' '$(INCLUDEDIR) + @echo SYSLIBDIR:' '$(SYSLIBDIR) + @echo MANDIR:' '$(MANDIR) + @echo DOCDIR:' '$(DOCDIR) + @echo LIBEXECDIR:' '$(LIBEXECDIR) + @echo + +.display-build: + @echo NATIVE_CC:' '$(NATIVE_CC) + @echo NATIVE_OS:' '$(NATIVE_OS) + @echo NATIVE_OS_BITS:' '$(NATIVE_OS_BITS) + @echo NATIVE_OS_UNDERSCORE:' '$(NATIVE_OS_UNDERSCORE) + @echo + @echo USER_CC:' '$(USER_CC) + @echo USER_CPP:' '$(USER_CPP) + @echo USER_CXX:' '$(USER_CXX) + @echo + + +.PHONY: all install shared static .display \ + shared-objs shared-lib shared-implib \ + static-objs static-lib \ + install-shared install-static install-implib \ + install-headers \ + clean distclean \ + .display-env .display-tools .display-flags \ + .display-pe .display-elf .display-dirs .display-build diff --git a/config.project b/config.project new file mode 100644 index 0000000..e1f78c1 --- /dev/null +++ b/config.project @@ -0,0 +1,49 @@ +# project +mb_package=ntcon +mb_require_out_of_tree=no + + +# dirs +mb_default_prefix= +mb_default_bindir=bin +mb_default_libdir=lib +mb_default_includedir=include +mb_default_syslibdir=lib +mb_default_mandir=man +mb_default_docdir=doc +mb_default_libexecdir=libexec + + +# build +mb_default_build= +mb_default_host= +mb_default_target= +mb_default_arch= +mb_default_toolchain= +mb_default_sysroot= +mb_default_cross_compile= +mb_default_shell=sh + + +# switches +mb_default_cflags_debug= +mb_default_cflags_common="-I\$(PROJECT_DIR)/src/internal -I\$(PROJECT_DIR)/include -Ibuild" +mb_default_cflags_cmdline= +mb_default_cflags_config= +mb_default_cflags_sysroot= +mb_default_cflags_path= + +mb_default_ldflags_debug= +mb_default_ldflags_common="-Llib" +mb_default_ldflags_cmdline= +mb_default_ldflags_config= +mb_default_ldflags_sysroot= +mb_default_ldflags_path= + +mb_default_pe_subsystem=windows +mb_default_pe_image_base= +mb_default_pe_config_defs= + +mb_default_elf_eh_frame= +mb_default_elf_hash_style= +mb_default_elf_config_defs= diff --git a/config.usage b/config.usage new file mode 100644 index 0000000..2175510 --- /dev/null +++ b/config.usage @@ -0,0 +1,77 @@ +configure: a skinny configuration script. + +supported switches: +------------------- + --help + + --prefix + --bindir + --libdir + --includedir + --syslibdir + --mandir + --libexecdir + + --build + --host + --target + --arch + --toolchain + --sysroot + --cross-compile + --shell + --debug + + +supported variables: +-------------------- + PREFIX + BINDIR + LIBDIR + INCLUDEDIR + LIBDIR + MANDIR + DOCDIR + LIBEXECDIR + + CC + CPP + CXX + + BUILD + HOST + TARGET + ARCH + TOOLCHAIN + SYSROOT + CROSS_COMPILE + SHELL + + CFLAGS + CFLAGS_DEBUG + CFLAGS_COMMON + CFLAGS_CMDLINE + CFLAGS_CONFIG + CFLAGS_SYSROOT + CFLAGS_PATH + + LDFLAGS + LDFLAGS_DEBUG + LDFLAGS_COMMON + LDFLAGS_CMDLINE + LDFLAGS_CONFIG + LDFLAGS_SYSROOT + LDFLAGS_PATH + + PE_SUBSYSTEM + PE_IMAGE_BASE + PE_CONFIG_DEFS + + ELF_EH_FRAME + ELF_HASH_STYLE + ELF_CONFIG_DEFS + + NATIVE_CC + NATIVE_OS + NATIVE_OS_BITS + NATIVE_OS_UNDERSCORE diff --git a/configure b/configure new file mode 100755 index 0000000..a21df9e --- /dev/null +++ b/configure @@ -0,0 +1,425 @@ +#!/bin/sh +# we are no longer lazy. + +# this script respects both CFLAGS and CFLAGS_CMDLINE, +# as well as both LDFLAGS and LDFLAGS_CMDLINE, however +# the latter variable of each pair should be preferred. + +usage() +{ + cat config.usage + exit $? +} + +error_msg() +{ + echo $@ >&2 +} + + +init_vars() +{ + mb_project_dir=$(cd `dirname $0` ; pwd) + mb_pwd=`pwd` + + if [ x"$mb_config" = x ]; then + . $mb_project_dir/config.project || exit 2 + else + . "$mb_config" || exit 2 + fi + + # dirs + mb_prefix=$PREFIX + mb_bindir=$BINDIR + mb_libdir=$LIBDIR + mb_includedir=$INCLUDEDIR + mb_syslibdir=$LIBDIR + mb_mandir=$MANDIR + mb_docdir=$DOCDIR + mb_libexecdir=$LIBEXECDIR + + + # build + mb_build=$BUILD + mb_host=$HOST + mb_target=$TARGET + mb_arch=$ARCH + mb_toolchain=$TOOLCHAIN + mb_sysroot=$SYSROOT + mb_cross_compile=$CROSS_COMPILE + mb_shell=$SHELL + + # switches + mb_cflags=$CFLAGS + mb_cflags_debug=$CFLAGS_DEBUG + mb_cflags_common=$CFLAGS_COMMON + mb_cflags_cmdline=$CFLAGS_CMDLINE + mb_cflags_config=$CFLAGS_CONFIG + mb_cflags_sysroot=$CFLAGS_SYSROOT + mb_cflags_path=$CFLAGS_PATH + + mb_ldflags=$LDFLAGS + mb_ldflags_debug=$LDFLAGS_DEBUG + mb_ldflags_common=$LDFLAGS_COMMON + mb_ldflags_cmdline=$LDFLAGS_CMDLINE + mb_ldflags_config=$LDFLAGS_CONFIG + mb_ldflags_sysroot=$LDFLAGS_SYSROOT + mb_ldflags_path=$LDFLAGS_PATH + + mb_pe_subsystem=$PE_SUBSYSTEM + mb_pe_image_base=$PE_IMAGE_BASE + mb_pe_config_defs=$PE_CONFIG_DEFS + + mb_elf_eh_frame=$ELF_EH_FRAME + mb_elf_hash_style=$ELF_HASH_STYLE + mb_elf_config_defs=$ELF_CONFIG_DEFS + + # overrides + mb_native_cc=$NATIVE_CC + mb_native_os=$NATIVE_OS + mb_native_os_bits=$NATIVE_OS_BITS + mb_native_os_underscore=$NATIVE_OS_UNDERSCORE + + mb_user_cc=$CC + mb_user_cpp=$CPP + mb_user_cxx=$CXX +} + + +verify_build_directory() +{ + if [ x"$mb_project_dir" = x"$mb_pwd" ]; then + if [ x"$mb_require_out_of_tree" = xyes ]; then + error_msg "$mb_package: out-of-tree builds are required." + error_msg "please invoke configure again from a clean build directory." + exit 2 + else + mb_project_dir='.' + fi + fi +} + + +common_defaults() +{ + # dirs + [ -z "$mb_prefix" ] && mb_prefix=$mb_default_prefix + [ -z "$mb_bindir" ] && mb_bindir=$mb_default_bindir + [ -z "$mb_libdir" ] && mb_libdir=$mb_default_libdir + [ -z "$mb_includedir" ] && mb_includedir=$mb_default_includedir + [ -z "$mb_syslibdir" ] && mb_syslibdir=$mb_default_syslibdir + [ -z "$mb_mandir" ] && mb_mandir=$mb_default_mandir + [ -z "$mb_docdir" ] && mb_docdir=$mb_default_docdir + [ -z "$mb_libexecdir" ] && mb_libexecdir=$mb_default_libexecdir + + # build + [ -z "$mb_build" ] && mb_build=$mb_default_build + [ -z "$mb_host" ] && mb_host=$mb_default_host + [ -z "$mb_target" ] && mb_target=$mb_default_target + [ -z "$mb_arch" ] && mb_arch=$mb_default_arch + [ -z "$mb_toolchain" ] && mb_toolchain=$mb_default_toolchain + [ -z "$mb_sysroot" ] && mb_sysroot=$mb_default_sysroot + [ -z "$mb_cross_compile" ] && mb_cross_compile=$mb_default_cross_compile + [ -z "$mb_shell" ] && mb_shell=$mb_default_shell + + # switches + [ -z "$mb_cflags_debug" ] && mb_cflags_debug=$mb_default_cflags_debug + [ -z "$mb_cflags_common" ] && mb_cflags_common=$mb_default_cflags_common + [ -z "$mb_cflags_cmdline" ] && mb_cflags_cmdline=$mb_default_cflags_cmdline + [ -z "$mb_cflags_config" ] && mb_cflags_config=$mb_default_cflags_config + [ -z "$mb_cflags_sysroot" ] && mb_cflags_sysroot=$mb_default_cflags_sysroot + [ -z "$mb_cflags_path" ] && mb_cflags_path=$mb_default_cflags_path + + [ -z "$mb_ldflags_debug" ] && mb_ldflags_debug=$mb_default_ldflags_debug + [ -z "$mb_ldflags_common" ] && mb_ldflags_common=$mb_default_ldflags_common + [ -z "$mb_ldflags_cmdline" ] && mb_ldflags_cmdline=$mb_default_ldflags_cmdline + [ -z "$mb_ldflags_config" ] && mb_ldflags_config=$mb_default_ldflags_config + [ -z "$mb_ldflags_sysroot" ] && mb_ldflags_sysroot=$mb_default_ldflags_sysroot + [ -z "$mb_ldflags_path" ] && mb_ldflags_path=$mb_default_ldflags_path + + [ -z "$mb_pe_subsystem" ] && mb_pe_subsystem=$mb_default_pe_subsystem + [ -z "$mb_pe_image_base" ] && mb_pe_image_base=$mb_default_pe_image_base + [ -z "$mb_pe_config_defs" ] && mb_pe_config_defs=$mb_default_pe_config_defs + + [ -z "$mb_elf_eh_frame" ] && mb_elf_eh_frame=$mb_default_elf_eh_frame + [ -z "$mb_elf_hash_style" ] && mb_elf_hash_style=$mb_default_elf_hash_style + [ -z "$mb_elf_config_defs" ] && mb_elf_config_defs=$mb_default_elf_config_defs + + # host/target + [ -z "$mb_host" ] && mb_host=$mb_target + + # sysroot + if [ x"$mb_sysroot" != x ]; then + if [ x"$mb_cflags_sysroot" = x ]; then + mb_cflags_sysroot="--sysroot=$mb_sysroot" + fi + + if [ x"$mb_ldflags_sysroot" = x ]; then + mb_ldflags_sysroot="-Wl,--sysroot,$mb_sysroot" + fi + fi + + # debug + if [ x"$mb_debug" = xyes ]; then + if [ x"$mb_cflags_debug" = x ]; then + mb_cflags_debug='-g3 -O0' + fi + fi + + # toolchain + if [ x"$mb_toolchain" != x ]; then + if [ x"$mb_native_cc" = x ]; then + mb_native_cc=$mb_toolchain + fi + fi +} + + +native_defaults() +{ + # CC (when set, must be valid) + if [ x"$CC" != x ]; then + $CC -dM -E - < /dev/null > /dev/null || exit 2 + fi + + # toolchain + [ -z "$mb_native_cc" ] && mb_native_cc=$CC + [ -z "$mb_native_cc" ] && mb_native_cc='cc' + $mb_native_cc -dM -E - < /dev/null > /dev/null 2>/dev/null || mb_native_cc= + + [ -z "$mb_native_cc" ] && mb_native_cc='gcc' + $mb_native_cc -dM -E - < /dev/null > /dev/null 2>/dev/null || mb_native_cc= + + [ -z "$mb_native_cc" ] && mb_native_cc='clang' + $mb_native_cc -dM -E - < /dev/null > /dev/null 2>/dev/null || mb_native_cc= + + [ -z "$mb_native_cc" ] && mb_native_cc='cparser' + $mb_native_cc -dM -E - < /dev/null > /dev/null 2>/dev/null || mb_native_cc= + + if [ x"$mb_native_cc" = x ]; then + error_msg "config error: could not find a working native compiler." + exit 2 + fi + + if [ x"$mb_toolchain" = x ]; then + $mb_native_cc -dM -E - < /dev/null | grep '__clang__' > /dev/null && mb_toolchain='clang' + fi + + if [ x"$mb_toolchain" = x ]; then + $mb_native_cc -dM -E - < /dev/null | grep '__GCC' > /dev/null && mb_toolchain='gcc' + fi + + if [ x"$mb_toolchain" = x ]; then + $mb_native_cc -dM -E - < /dev/null | grep '__CPARSER__' > /dev/null && mb_toolchain='cparser' + fi + + if [ x"$mb_toolchain" = x ]; then + error_msg "config error: could not identify the native compiler." + exit 2 + fi + + + # host + if [ x"$mb_host" = x ]; then + mb_host='native' + fi + + + # os + mb_native_os=`uname | tr '[:upper:]' '[:lower:]'` + + mb_native_os_sizeof_pointer=`$mb_native_cc -dM -E - < /dev/null \ + | grep __SIZEOF_POINTER__ \ + | cut -d ' ' -f3` + + mb_native_os_bits=`expr '8' '*' '0'"$mb_native_os_sizeof_pointer"` + + if [ $mb_native_os_bits = 32 ]; then + mb_native_os_underscore='_' + else + mb_native_os_underscore='' + fi + + if [ x"$mb_native_os_sizeof_pointer" = x ]; then + error_msg "config error: could not determine size of pointer on native system." + exit 2 + fi + + [ -z "$mb_native_os" ] && mb_native_os=$mb_native_os + [ -z "$mb_native_os_bits" ] && mb_native_os_bits=$mb_native_os_bits + [ -z "$mb_native_os_underscore" ] && mb_native_os_underscore=$mb_native_os_underscore +} + + +cross_defaults() +{ + if [ x"$mb_cross_compile" = x ] && [ x"$mb_host" != xnative ]; then + mb_cross_compile=$mb_host'-' + fi +} + + +config_copy() +{ + sed -e 's^@package@^'"$mb_package"'^g' \ + -e 's^@project_dir@^'"$mb_project_dir"'^g' \ + \ + -e 's^@build@^'"$mb_build"'^g' \ + -e 's^@host@^'"$mb_host"'^g' \ + -e 's^@target@^'"$mb_target"'^g' \ + -e 's^@arch@^'"$mb_arch"'^g' \ + -e 's^@toolchain@^'"$mb_toolchain"'^g' \ + -e 's^@sysroot@^'"$mb_sysroot"'^g' \ + -e 's^@cross_compile@^'"$mb_cross_compile"'^g' \ + -e 's^@shell@^'"$mb_shell"'^g' \ + \ + -e 's^@cflags@^'"$mb_cflags"'^g' \ + -e 's^@cflags_debug@^'"$mb_cflags_debug"'^g' \ + -e 's^@cflags_common@^'"$mb_cflags_common"'^g' \ + -e 's^@cflags_cmdline@^'"$mb_cflags $mb_cflags_cmdline"'^g' \ + -e 's^@cflags_config@^'"$mb_cflags_config"'^g' \ + -e 's^@cflags_sysroot@^'"$mb_cflags_sysroot"'^g' \ + -e 's^@cflags_path@^'"$mb_cflags_path"'^g' \ + \ + -e 's^@ldflags@^'"$mb_ldflags"'^g' \ + -e 's^@ldflags_debug@^'"$mb_ldflags_debug"'^g' \ + -e 's^@ldflags_common@^'"$mb_ldflags_common"'^g' \ + -e 's^@ldflags_cmdline@^'"$mb_ldflags $mb_ldflags_cmdline"'^g' \ + -e 's^@ldflags_config@^'"$mb_ldflags_config"'^g' \ + -e 's^@ldflags_sysroot@^'"$mb_ldflags_sysroot"'^g' \ + -e 's^@ldflags_path@^'"$mb_ldflags_path"'^g' \ + \ + -e 's^@pe_subsystem@^'"$mb_pe_subsystem"'^g' \ + -e 's^@pe_image\_base@^'"$mb_pe_image_base"'^g' \ + -e 's^@pe_config\_defs@^'"$mb_pe_config_defs"'^g' \ + \ + -e 's^@elf_eh\_frame@^'"$mb_elf_eh_frame"'^g' \ + -e 's^@elf_hash\_style@^'"$mb_elf_hash_style"'^g' \ + -e 's^@elf_config\_defs@^'"$mb_elf_config_defs"'^g' \ + \ + -e 's^@prefix@^'"$mb_prefix"'^g' \ + -e 's^@bindir@^'"$mb_bindir"'^g' \ + -e 's^@libdir@^'"$mb_libdir"'^g' \ + -e 's^@includedir@^'"$mb_includedir"'^g' \ + -e 's^@syslibdir@^'"$mb_syslibdir"'^g' \ + -e 's^@mandir@^'"$mb_mandir"'^g' \ + -e 's^@docdir@^'"$mb_docdir"'^g' \ + -e 's^@libexecdir@^'"$mb_libexecdir"'^g' \ + \ + -e 's^@native_cc@^'"$mb_native_cc"'^g' \ + -e 's^@native_os@^'"$mb_native_os"'^g' \ + -e 's^@native_os_bits@^'"$mb_native_os_bits"'^g' \ + -e 's^@native_os_underscore@^'"$mb_native_os_underscore"'^g' \ + \ + -e 's^@user_cc@^'"$mb_user_cc"'^g' \ + -e 's^@user_cpp@^'"$mb_user_cpp"'^g' \ + -e 's^@user_cxx@^'"$mb_user_cxx"'^g' \ + $mb_project_dir/Makefile.in > $mb_pwd/Makefile +} + + +config_host() +{ + make host.tag && return 0 + + error_msg "configure was able to generate a Makefile for the selected host," + error_msg "however the host-targeting toolchain was found to be missing" + error_msg "at least one of the required headers or features." + exit 2 +} + + +config_status() +{ + printf "\n\n" + make .display + printf "\nconfiguration completed successfully.\n\n" +} + +# one: init +init_vars +verify_build_directory + + +# two: args +for arg ; do + case "$arg" in + --help) usage + ;; + + # dirs + --prefix=*) + mb_prefix=${arg#*=} + ;; + --bindir=*) + mb_bindir=${arg#*=} + ;; + --libdir=*) + mb_libdir=${arg#*=} + ;; + --includedir=*) + mb_includedir=${arg#*=} + ;; + --syslibdir=*) + mb_syslibdir=${arg#*=} + ;; + --mandir=*) + mb_mandir=${arg#*=} + ;; + --libexecdir=*) + mb_libexecdir=${arg#*=} + ;; + + + # build + --build=*) + mb_build=${arg#*=} + ;; + --host=*) + mb_host=${arg#*=} + ;; + --target=*) + mb_target=${arg#*=} + ;; + --arch=*) + mb_arch=${arg#*=} + ;; + --toolchain=*) + mb_toolchain=${arg#*=} + ;; + --sysroot=*) + mb_sysroot=${arg#*=} + ;; + --cross-compile=*) + mb_cross_compile=${arg#*=} + ;; + --shell=*) + mb_shell=${arg#*=} + ;; + --debug) + mb_debug='yes' + ;; + *) + error_msg ${arg#}: "unsupported config argument." + exit 2 + ;; + esac +done + + + +# three: defaults +common_defaults +native_defaults +cross_defaults + + + +# four: config +config_copy +config_host +config_status + + +# all done +exit 0 diff --git a/include/ntcon/ntcon.h b/include/ntcon/ntcon.h new file mode 100644 index 0000000..cef11cf --- /dev/null +++ b/include/ntcon/ntcon.h @@ -0,0 +1,884 @@ +#ifndef NTCON_H +#define NTCON_H + +#include "ntcon_api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* console standard handles */ +#define NT_STD_INPUT_HANDLE (uint32_t)-10 +#define NT_STD_OUTPUT_HANDLE (uint32_t)-11 +#define NT_STD_ERROR_HANDLE (uint32_t)-12 + +/* console attachment */ +#define NT_ATTACH_PARENT_PROCESS (uint32_t)-1 + +/* console screen buffer flags */ +#define NT_CONSOLE_TEXTMODE_BUFFER (0x01) + +/* console control signals */ +#define NT_CTRL_C_EVENT (0x00) +#define NT_CTRL_BREAK_EVENT (0x01) +#define NT_CTRL_CLOSE_EVENT (0x02) +#define NT_CTRL_LOGOFF_EVENT (0x05) +#define NT_CTRL_SHUTDOWN_EVENT (0x06) + +/* console history flags */ +#define NT_HISTORY_NO_DUP_FLAG (0x0001) + +/* console event types */ +#define NT_KEY_EVENT (0x0001) +#define NT_MOUSE_EVENT (0x0002) +#define NT_WINDOW_BUFFER_SIZE_EVENT (0x0004) +#define NT_MENU_EVENT (0x0008) +#define NT_FOCUS_EVENT (0x0010) + +/* control key states */ +#define NT_RIGHT_ALT_PRESSED (0x0001) +#define NT_LEFT_ALT_PRESSED (0x0002) +#define NT_RIGHT_CTRL_PRESSED (0x0004) +#define NT_LEFT_CTRL_PRESSED (0x0008) +#define NT_SHIFT_PRESSED (0x0010) +#define NT_NUMLOCK_ON (0x0020) +#define NT_SCROLLLOCK_ON (0x0040) +#define NT_CAPSLOCK_ON (0x0080) +#define NT_ENHANCED_KEY (0x0100) + +/* console foreground color attributes */ +#define NT_FOREGROUND_BLACK (0x0000) +#define NT_FOREGROUND_BLUE (0x0001) +#define NT_FOREGROUND_GREEN (0x0002) +#define NT_FOREGROUND_CYAN (0x0003) +#define NT_FOREGROUND_RED (0x0004) +#define NT_FOREGROUND_MAGENTA (0x0005) +#define NT_FOREGROUND_YELLOW (0x0006) +#define NT_FOREGROUND_WHITE (0x0007) +#define NT_FOREGROUND_INTENSITY (0x0008) + +/* console background color attributes */ +#define NT_BACKGROUND_BLACK (0x0000) +#define NT_BACKGROUND_BLUE (0x0010) +#define NT_BACKGROUND_GREEN (0x0020) +#define NT_BACKGROUND_CYAN (0x0030) +#define NT_BACKGROUND_RED (0x0040) +#define NT_BACKGROUND_MAGENTA (0x0050) +#define NT_BACKGROUND_YELLOW (0x0060) +#define NT_BACKGROUND_WHITE (0x0070) +#define NT_BACKGROUND_INTENSITY (0x0080) + +/* console common lvb attributes */ +#define NT_COMMON_LVB_LEADING_BYTE (0x0100) +#define NT_COMMON_LVB_TRAILING_BYTE (0x0200) +#define NT_COMMON_LVB_GRID_HORIZONTAL (0x0400) +#define NT_COMMON_LVB_GRID_LVERTICAL (0x0800) +#define NT_COMMON_LVB_GRID_RVERTICAL (0x1000) +#define NT_COMMON_LVB_REVERSE_VIDEO (0x4000) +#define NT_COMMON_LVB_UNDERSCORE (0x8000) + +/* console font name length limit */ +#define NT_LF_FACESIZE (0x20) + +/* console font families */ +#define NT_FF_DONTCARE (0x0 << 4) +#define NT_FF_ROMAN (0x1 << 4) +#define NT_FF_SWISS (0x2 << 4) +#define NT_FF_MODERN (0x3 << 4) +#define NT_FF_SCRIPT (0x4 << 4) +#define NT_FF_DECORATIVE (0x5 << 4) + +/* console font weight */ +#define NT_FW_DONTCARE 0 +#define NT_FW_THIN 100 +#define NT_FW_EXTRALIGHT 200 +#define NT_FW_ULTRALIGHT 200 +#define NT_FW_LIGHT 300 +#define NT_FW_NORMAL 400 +#define NT_FW_REGULAR 400 +#define NT_FW_MEDIUM 500 +#define NT_FW_SEMIBOLD 600 +#define NT_FW_DEMIBOLD 600 +#define NT_FW_BOLD 700 +#define NT_FW_EXTRABOLD 800 +#define NT_FW_ULTRABOLD 800 +#define NT_FW_HEAVY 900 +#define NT_FW_BLACK 900 + +/* console selection bits */ +#define NT_CONSOLE_NO_SELECTION (0x0000) +#define NT_CONSOLE_SELECTION_IN_PROGRESS (0x0001) +#define NT_CONSOLE_SELECTION_NOT_EMPTY (0x0002) +#define NT_CONSOLE_MOUSE_SELECTION (0x0004) +#define NT_CONSOLE_MOUSE_DOWN (0x0008) + +/* console mode bits */ +#define NT_ENABLE_PROCESSED_INPUT (0x0001) +#define NT_ENABLE_LINE_INPUT (0x0002) +#define NT_ENABLE_ECHO_INPUT (0x0004) +#define NT_ENABLE_WINDOW_INPUT (0x0008) +#define NT_ENABLE_MOUSE_INPUT (0x0010) +#define NT_ENABLE_INSERT_MODE (0x0020) +#define NT_ENABLE_QUICK_EDIT_MODE (0x0040) + +/* console display modes */ +#define NT_CONSOLE_FULLSCREEN (0x0001) +#define NT_CONSOLE_FULLSCREEN_HARDWARE (0x0002) + + +/* console structures */ +typedef struct _nt_coord { + int16_t x; + int16_t y; +} nt_coord; + + +typedef struct _nt_small_rect { + int16_t left; + int16_t top; + int16_t right; + int16_t bottom; +} nt_small_rect; + + +typedef struct _nt_char_info { + union { + wchar16_t unicode_char; + char ascii_char; + } uchar; + + uint16_t attributes; +} nt_char_info; + + +typedef struct _nt_console_cursor_info { + uint32_t size; + int32_t visible; +} nt_console_cursor_info; + + +typedef struct _nt_console_font_info { + uint32_t font; + nt_coord font_size; +} nt_console_font_info; + + +typedef struct _nt_console_font_info_ex { + uint32_t info_size; + uint32_t font; + nt_coord font_size; + uint32_t font_family; + uint32_t font_weight; + wchar16_t face_name[NT_LF_FACESIZE]; +} nt_console_font_info_ex; + + +typedef struct _nt_console_history_info { + uint32_t info_size; + uint32_t history_buffer_size; + uint32_t history_buffer_count; + uint32_t flags; +} nt_console_history_info; + + +typedef struct _nt_key_event_record { + int32_t key_down; + uint16_t repeat_count; + uint16_t virtual_key_code; + uint16_t virtual_scan_code; + + union { + wchar16_t unicode_char; + char ascii_char; + } uchar; + + uint32_t control_key_state; +} nt_key_event_record; + + +typedef struct _nt_mouse_event_record { + nt_coord mouse_position; + uint32_t button_state; + uint32_t control_key_state; + uint32_t event_flags; +} nt_mouse_event_record; + + +typedef struct _nt_window_buffer_size_record { + nt_coord size; +} nt_window_buffer_size_record; + + +typedef struct _nt_menu_event_record { + uint32_t command_id; +} nt_menu_event_record; + + +typedef struct _nt_focus_event_record { + int32_t set_focus; +} nt_focus_event_record; + + +typedef struct _nt_input_record { + uint16_t event_type; + + union { + nt_key_event_record key_event; + nt_mouse_event_record mouse_event; + nt_window_buffer_size_record window_buffer_size_event; + nt_menu_event_record menu_event; + nt_focus_event_record focus_event; + } event; +} nt_input_record; + + +typedef struct _nt_console_screen_buffer_info { + nt_coord size; + nt_coord cursor_position; + uint16_t attributes; + nt_small_rect window; + nt_coord max_windows_size; +} nt_console_screen_buffer_info; + + +typedef struct _nt_console_screen_buffer_info_ex { + uint16_t info_size; + nt_coord size; + nt_coord cursor_position; + uint16_t attributes; + nt_small_rect window; + nt_coord max_windows_size; + uint16_t popup_attributes; + int32_t full_screen_supported; + uint32_t color_table[0x10]; +} nt_console_screen_buffer_info_ex; + + +typedef struct _nt_console_read_console_control { + uint32_t length; + uint32_t initial_chars; + uint32_t crtl_wakeup_mask; + uint32_t ctrl_key_state; +} nt_console_read_console_control; + + +typedef struct _nt_console_selection_info { + uint32_t flags; + nt_coord selection_anchor; + nt_small_rect selection; +} nt_console_selection_info; + + +/* console api: console handles */ +typedef int32_t __stdcall ntcon_alloc_console(void); + + +typedef int32_t __stdcall ntcon_attach_console(uint32_t pid); + + +typedef int32_t __stdcall ntcon_free_console(void); + + +typedef void * __stdcall ntcon_get_std_handle(uint32_t ntcon_std_type); + + +/* console api: read/write using std handles */ +typedef int32_t __stdcall ntcon_get_number_of_console_input_events( + __in void * hconin, + __out uint32_t * number_of_events); + + +typedef int32_t __stdcall ntcon_flush_console_input_buffer( + __in void * hconin); + + +typedef int32_t __stdcall ntcon_peek_console_input_ansi( + __in void * hconin, + __out nt_input_record * buffer, + __in uint32_t length, + __out uint32_t * events_read); + + +typedef int32_t __stdcall ntcon_peek_console_input_utf16( + __in void * hconin, + __out nt_input_record * buffer, + __in uint32_t length, + __out uint32_t * events_read); + + +typedef int32_t __stdcall ntcon_read_console_ansi( + __in void * hconsole, + __out char * buffer, + __in uint32_t chars_to_read, + __out uint32_t * chars_read, + __in void * input_control __optional); + + +typedef int32_t __stdcall ntcon_read_console_utf16( + __in void * hconsole, + __out wchar16_t * buffer, + __in uint32_t chars_to_read, + __out uint32_t * chars_read, + __in void * input_control __optional); + + +typedef int32_t __stdcall ntcon_read_console_input_ansi( + __in void * hconin, + __out nt_input_record * buffer, + __in uint32_t length, + __out uint32_t * events_read); + + +typedef int32_t __stdcall ntcon_read_console_input_utf16( + __in void * hconin, + __out nt_input_record * buffer, + __in uint32_t length, + __out uint32_t * events_read); + + +typedef int32_t __stdcall ntcon_read_console_output_ansi( + __in void * hconout, + __out nt_char_info * buffer, + __in nt_coord buffer_size, + __in nt_coord buffer_coord, + __in_out nt_small_rect * read_region); + + +typedef int32_t __stdcall ntcon_read_console_output_utf16( + __in void * hconout, + __out nt_char_info * buffer, + __in nt_coord buffer_size, + __in nt_coord buffer_coord, + __in_out nt_small_rect * read_region); + + +typedef int32_t __stdcall ntcon_write_console_ansi( + __in void * hconsole, + __in const void * buffer, + __in uint32_t bytes_sent, + __out uint32_t * bytes_written, + __in_out void * overlapped __optional); + +typedef int32_t __stdcall ntcon_write_console_utf16( + __in void * hconsole, + __in const void * buffer, + __in uint32_t bytes_sent, + __out uint32_t * bytes_written, + __in_out void * overlapped __optional); + + +typedef int32_t __stdcall ntcon_write_console_input_ansi( + __in void * hconin, + __in const nt_input_record * buffer, + __in uint32_t length, + __out uint32_t * events_written); + + +typedef int32_t __stdcall ntcon_write_console_input_utf16( + __in void * hconin, + __in const nt_input_record * buffer, + __in uint32_t length, + __out uint32_t * events_written); + + +typedef int32_t __stdcall ntcon_write_console_output_ansi( + __in void * hconout, + __in const nt_char_info * buffer, + __in nt_coord buffer_size, + __in nt_coord buffer_coord, + __in_out nt_small_rect * write_region); + + +typedef int32_t __stdcall ntcon_write_console_output_utf16( + __in void * hconout, + __in const nt_char_info * buffer, + __in nt_coord buffer_size, + __in nt_coord buffer_coord, + __in_out nt_small_rect * write_region); + + +/* console api: screen buffers */ +typedef struct _nt_security_attributes nt_security_attributes; + +typedef void * __stdcall ntcon_create_console_screen_buffer( + __in uint32_t desired_access, + __in uint32_t share_mode, + __in nt_security_attributes * sec_attr __optional, + __in uint32_t flags, + __in void * reserved); + + +typedef int32_t __stdcall ntcon_get_console_screen_buffer_info( + __in void * hconout, + __out nt_console_screen_buffer_info * con_screen_buffer_info); + + +typedef int32_t __stdcall ntcon_get_console_screen_buffer_info_ex( + __in void * hconout, + __out nt_console_screen_buffer_info_ex * con_screen_buffer_info_ex); + + +typedef int32_t __stdcall ntcon_set_console_screen_buffer_info_ex( + __in void * hconout, + __out nt_console_screen_buffer_info_ex * con_screen_buffer_info_ex); + + +typedef int32_t __stdcall ntcon_set_console_screen_buffer_size( + __in void * hconout, + __in nt_coord size); + + +typedef int32_t __stdcall ntcon_set_console_active_screen_buffer( + __in void * hconout); + + +typedef int32_t __stdcall ntcon_set_console_window_info( + __in void * hconout, + __in int32_t absolute, + __in const nt_small_rect * console_window); + + +typedef int32_t __stdcall ntcon_scroll_console_screen_buffer_ansi( + __in void * hconout, + __in const nt_small_rect * scroll_rect, + __in const nt_small_rect * clip_rect __optional, + __in nt_coord dest_origin, + __in const nt_char_info * fill); + + +typedef int32_t __stdcall ntcon_scroll_console_screen_buffer_utf16( + __in void * hconout, + __in const nt_small_rect * scroll_rect, + __in const nt_small_rect * clip_rect __optional, + __in nt_coord dest_origin, + __in const nt_char_info * fill); + + +/* console api: code page */ +typedef uint32_t __stdcall ntcon_get_console_code_page(void); + + +typedef int32_t __stdcall ntcon_set_console_code_page(uint32_t code_page); + + +/* console api: console control */ +typedef int32_t __stdcall nt_console_handler_routine( + __in uint32_t console_ctrl_type); + + +typedef int32_t __stdcall ntcon_generate_console_ctrl_event( + __in uint32_t ctrl_event, + __in uint32_t process_group_id); + + +typedef int32_t __stdcall ntcon_set_console_ctrl_handler( + __in nt_console_handler_routine * handler_routine __optional, + __in int32_t add_or_remove); + + +/* console api: interface mode */ +typedef int32_t __stdcall ntcon_get_console_mode( + __in void * hconsole, + __out uint32_t * mode); + + +typedef int32_t __stdcall ntcon_set_console_mode( + __in void * hconsole, + __in uint32_t mode); + + +/* console api: console process list */ +typedef uint32_t __stdcall ntcon_get_console_process_list( + __out uint32_t * process_list, + __in uint32_t process_count); + + +/* console api: aliases */ +typedef int32_t __stdcall ntcon_add_console_alias_ansi( + __in char * source, + __in char * target, + __in char * exe_name); + + +typedef int32_t __stdcall ntcon_add_console_alias_utf16( + __in wchar16_t * source, + __in wchar16_t * target, + __in wchar16_t * exe_name); + + +typedef uint32_t __stdcall ntcon_get_console_alias_ansi( + __in char * source, + __out char * target_buffer, + __in uint32_t target_buffer_length, + __in char * exe_name); + + +typedef uint32_t __stdcall ntcon_get_console_alias_utf16( + __in wchar16_t * source, + __out wchar16_t * target_buffer, + __in uint32_t target_buffer_length, + __in wchar16_t * exe_name); + + +typedef uint32_t __stdcall ntcon_get_console_aliases_ansi( + __out char * alias_buffer, + __in uint32_t alias_buffer_length, + __in char * exe_name); + + +typedef uint32_t __stdcall ntcon_get_console_aliases_utf16( + __out wchar16_t * alias_buffer, + __in uint32_t alias_buffer_length, + __in wchar16_t * exe_name); + + +typedef uint32_t __stdcall ntcon_get_console_aliases_length_ansi( + __in char * exe_name); + + +typedef uint32_t __stdcall ntcon_get_console_aliases_length_utf16( + __in wchar16_t * exe_name); + + +typedef uint32_t __stdcall ntcon_get_console_alias_exes_ansi( + __out char * exe_name_buffer, + __in uint32_t exe_name_buffer_length); + + +typedef uint32_t __stdcall ntcon_get_console_alias_exes_utf16( + __out wchar16_t * exe_name_buffer, + __in uint32_t exe_name_buffer_length); + + +typedef uint32_t __stdcall ntcon_get_console_alias_exes_length_ansi(void); + + +typedef uint32_t __stdcall ntcon_get_console_alias_exes_length_utf16(void); + + +/* console api: output attributes */ +typedef int32_t __stdcall ntcon_fill_console_output_attribute( + __in void * hconout, + __in uint16_t attribute, + __in uint32_t length, + __in nt_coord write_coord, + __out uint32_t * attrs_written); + + +typedef int32_t __stdcall ntcon_read_console_output_attribute( + __in void * hconout, + __in uint16_t * attribute, + __in uint32_t length, + __in nt_coord read_coord, + __out uint32_t * attrs_read); + + +typedef int32_t __stdcall ntcon_write_console_output_attribute( + __in void * hconout, + __in uint16_t * attribute, + __in uint32_t length, + __in nt_coord write_coord, + __out uint32_t * attrs_written); + + +/* console api: output characters */ +typedef int32_t __stdcall ntcon_fill_console_output_character_ansi( + __in void * hconout, + __in char character, + __in uint32_t length, + __in nt_coord write_coord, + __out uint32_t * chars_written); + + +typedef int32_t __stdcall ntcon_fill_console_output_character_utf16( + __in void * hconout, + __in wchar16_t character, + __in uint32_t length, + __in nt_coord write_coord, + __out uint32_t * chars_written); + + +typedef int32_t __stdcall ntcon_read_console_output_character_ansi( + __in void * hconout, + __in char * character, + __in uint32_t length, + __in nt_coord read_coord, + __out uint32_t * chars_read); + + +typedef int32_t __stdcall ntcon_read_console_output_character_utf16( + __in void * hconout, + __in wchar16_t * character, + __in uint32_t length, + __in nt_coord read_coord, + __out uint32_t * chars_read); + + +typedef int32_t __stdcall ntcon_write_console_output_character_ansi( + __in void * hconout, + __in char * character, + __in uint32_t length, + __in nt_coord write_coord, + __out uint32_t * chars_written); + + +typedef int32_t __stdcall ntcon_write_console_output_character_utf16( + __in void * hconout, + __in wchar16_t * character, + __in uint32_t length, + __in nt_coord write_coord, + __out uint32_t * chars_written); + + +/* console api: output code page */ +typedef uint32_t __stdcall ntcon_get_console_output_code_page(void); + + +typedef int32_t __stdcall ntcon_set_console_output_code_page( + __in uint32_t code_page_id); + + +/* console api: text attributes */ +typedef int32_t __stdcall ntcon_set_console_text_attribute( + __in void * hconout, + __in uint16_t attributes); + + +/* console api: cursor info */ +typedef int32_t __stdcall ntcon_get_console_cursor_info( + __in void * hconout, + __out nt_console_cursor_info * console_cursor_info); + + +typedef int32_t __stdcall ntcon_set_console_cursor_info( + __in void * hconout, + __in const nt_console_cursor_info * console_cursor_info); + + +typedef int32_t __stdcall ntcon_set_console_cursor_position( + __in void * hconout, + __out nt_coord cursor_position); + + +/* console api: selection info */ +typedef int32_t __stdcall ntcon_get_console_selection_info( + __out nt_console_selection_info * console_selection_info); + + +/* console api: history info */ +typedef int32_t __stdcall ntcon_get_console_history_info( + __out nt_console_history_info * console_history_info); + + +typedef int32_t __stdcall ntcon_set_console_history_info( + __in nt_console_history_info * console_history_info); + + +/* console api: font info */ +typedef nt_coord __stdcall ntcon_get_console_font_size( + __in void * hconout, + __in uint32_t font); + + +typedef int32_t __stdcall ntcon_get_current_console_font( + __in void * hconout, + __in int32_t maximum_window, + __out nt_console_font_info * console_current_font); + + +typedef int32_t __stdcall ntcon_get_current_console_font_ex( + __in void * hconout, + __in int32_t maximum_window, + __out nt_console_font_info_ex * console_current_font_ex); + + +typedef int32_t __stdcall ntcon_set_current_console_font_ex( + __in void * hconout, + __in int32_t maximum_window, + __in nt_console_font_info_ex * console_current_font_ex); + + +/* console api: mouse capabilities */ +typedef int32_t __stdcall ntcon_get_number_of_console_mouse_buttons( + __out uint32_t * number_of_mouse_buttons); + + +/* console api: window information */ +typedef void * __stdcall ntcon_get_console_window(void); + + +typedef nt_coord __stdcall ntcon_get_largest_console_window_size( + __in void * hconout); + + +/* console api: display mode */ +typedef int32_t __stdcall ntcon_get_console_display_mode( + __out uint32_t * mode_flags); + + +typedef int32_t __stdcall ntcon_set_console_display_mode( + __in void * hconsole, + __in uint32_t mode_flags, + __out nt_coord * new_screen_buffer_dimensions __optional); + + +/* console api: console title */ +typedef uint32_t __stdcall ntcon_get_console_title_ansi( + __out char * console_title, + __in uint32_t size); + + +typedef uint32_t __stdcall ntcon_get_console_title_utf16( + __out wchar16_t * console_title, + __in uint32_t size); + + +typedef int32_t __stdcall ntcon_set_console_title_ansi( + __in char * console_title); + + +typedef int32_t __stdcall ntcon_set_console_title_utf16( + __in wchar16_t * console_title); + + +typedef uint32_t __stdcall ntcon_get_console_original_title_ansi( + __out char * console_title, + __in uint32_t size); + + +typedef uint32_t __stdcall ntcon_get_console_original_title_utf16( + __out wchar16_t * console_title, + __in uint32_t size); + + +/* ntcon function vtbl */ +typedef struct _ntcon_vtbl { + /* console handles */ + ntcon_alloc_console * alloc_console; + ntcon_attach_console * attach_console; + ntcon_free_console * free_console; + ntcon_get_std_handle * get_std_handle; + + /* read/write using std handles */ + ntcon_get_number_of_console_input_events * get_number_of_console_input_events; + ntcon_flush_console_input_buffer * flush_console_input_buffer; + ntcon_peek_console_input_ansi * peek_console_input_ansi; + ntcon_peek_console_input_utf16 * peek_console_input_utf16; + ntcon_read_console_ansi * read_console_ansi; + ntcon_read_console_utf16 * read_console_utf16; + ntcon_read_console_input_ansi * read_console_input_ansi; + ntcon_read_console_input_utf16 * read_console_input_utf16; + ntcon_read_console_output_ansi * read_console_output_ansi; + ntcon_read_console_output_utf16 * read_console_output_utf16; + ntcon_write_console_ansi * write_console_ansi; + ntcon_write_console_utf16 * write_console_utf16; + ntcon_write_console_input_ansi * write_console_input_ansi; + ntcon_write_console_input_utf16 * write_console_input_utf16; + ntcon_write_console_output_ansi * write_console_output_ansi; + ntcon_write_console_output_utf16 * write_console_output_utf16; + + /* screen buffers */ + ntcon_create_console_screen_buffer * create_console_screen_buffer; + ntcon_get_console_screen_buffer_info * get_console_screen_buffer_info; + ntcon_get_console_screen_buffer_info_ex * get_console_screen_buffer_info_ex; + ntcon_set_console_screen_buffer_info_ex * set_console_screen_buffer_info_ex; + ntcon_set_console_screen_buffer_size * set_console_screen_buffer_size; + ntcon_set_console_active_screen_buffer * set_console_active_screen_buffer; + ntcon_set_console_window_info * set_console_window_info; + ntcon_scroll_console_screen_buffer_ansi * scroll_console_screen_buffer_ansi; + ntcon_scroll_console_screen_buffer_utf16 * scroll_console_screen_buffer_utf16; + + /* code page */ + ntcon_get_console_code_page * get_console_code_page; + ntcon_set_console_code_page * set_console_code_page; + + /* console control */ + ntcon_generate_console_ctrl_event * generate_console_ctrl_event; + ntcon_set_console_ctrl_handler * set_console_ctrl_handler; + + /* interface mode */ + ntcon_get_console_mode * get_console_mode; + ntcon_set_console_mode * set_console_mode; + + /* console process list */ + ntcon_get_console_process_list * get_console_process_list; + + /* aliases */ + ntcon_add_console_alias_ansi * add_console_alias_ansi; + ntcon_add_console_alias_utf16 * add_console_alias_utf16; + ntcon_get_console_alias_ansi * get_console_alias_ansi; + ntcon_get_console_alias_utf16 * get_console_alias_utf16; + ntcon_get_console_aliases_ansi * get_console_aliases_ansi; + ntcon_get_console_aliases_utf16 * get_console_aliases_utf16; + ntcon_get_console_aliases_length_ansi * get_console_aliases_length_ansi; + ntcon_get_console_aliases_length_utf16 * get_console_aliases_length_utf16; + ntcon_get_console_alias_exes_ansi * get_console_alias_exes_ansi; + ntcon_get_console_alias_exes_utf16 * get_console_alias_exes_utf16; + ntcon_get_console_alias_exes_length_ansi * get_console_alias_exes_length_ansi; + ntcon_get_console_alias_exes_length_utf16 * get_console_alias_exes_length_utf16; + + /* output attributes */ + ntcon_fill_console_output_attribute * fill_console_output_attribute; + ntcon_read_console_output_attribute * read_console_output_attribute; + ntcon_write_console_output_attribute * write_console_output_attribute; + + /* output characters */ + ntcon_fill_console_output_character_ansi * fill_console_output_character_ansi; + ntcon_fill_console_output_character_utf16 * fill_console_output_character_utf16; + ntcon_read_console_output_character_ansi * read_console_output_character_ansi; + ntcon_read_console_output_character_utf16 * read_console_output_character_utf16; + ntcon_write_console_output_character_ansi * write_console_output_character_ansi; + ntcon_write_console_output_character_utf16 * write_console_output_character_utf16; + + /* output code page */ + ntcon_get_console_output_code_page * get_console_output_code_page; + ntcon_set_console_output_code_page * set_console_output_code_page; + + /* text attributes */ + ntcon_set_console_text_attribute * set_console_text_attribute; + + /* cursor info */ + ntcon_get_console_cursor_info * get_console_cursor_info; + ntcon_set_console_cursor_info * set_console_cursor_info; + ntcon_set_console_cursor_position * set_console_cursor_position; + + /* selection info */ + ntcon_get_console_selection_info * get_console_selection_info; + + /* history info */ + ntcon_get_console_history_info * get_console_history_info; + ntcon_set_console_history_info * set_console_history_info; + + /* font info */ + ntcon_get_console_font_size * get_console_font_size; + ntcon_get_current_console_font * get_current_console_font; + ntcon_get_current_console_font_ex * get_current_console_font_ex; + ntcon_set_current_console_font_ex * set_current_console_font_ex; + + /* mouse capabilities */ + ntcon_get_number_of_console_mouse_buttons * get_number_of_console_mouse_buttons; + + /* window information */ + ntcon_get_console_window * get_console_window; + ntcon_get_largest_console_window_size * get_largest_console_window_size; + + /* display mode */ + ntcon_get_console_display_mode * get_console_display_mode; + ntcon_set_console_display_mode * set_console_display_mode; + + /* console title */ + ntcon_get_console_title_ansi * get_console_title_ansi; + ntcon_get_console_title_utf16 * get_console_title_utf16; + ntcon_set_console_title_ansi * set_console_title_ansi; + ntcon_set_console_title_utf16 * set_console_title_utf16; + ntcon_get_console_original_title_ansi * get_console_original_title_ansi; + ntcon_get_console_original_title_utf16 * get_console_original_title_utf16; +} ntcon_vtbl; + +ntcon_api +int32_t __fastcall ntcon_vtbl_init(ntcon_vtbl * pvtbl); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/ntcon/ntcon_api.h b/include/ntcon/ntcon_api.h new file mode 100644 index 0000000..15c89e8 --- /dev/null +++ b/include/ntcon/ntcon_api.h @@ -0,0 +1,32 @@ +#ifndef NTCON_API_H +#define NTCON_API_H + +/* host type (posix-libc/free-standing) */ +#include "ntcon_env.h" + +/* ntcon_export */ +#if defined(__attr_export__) +#define ntcon_export __attr_export__ +#else +#define ntcon_export +#endif + +/* ntcon_import */ +#if defined(__attr_import__) +#define ntcon_import __attr_import__ +#else +#define ntcon_import +#endif + +/* ntcon_api */ +#if defined (NTCON_BUILD) +#define ntcon_api ntcon_export +#elif defined (NTCON_SHARED) +#define ntcon_api ntcon_import +#elif defined (NTCON_STATIC) +#define ntcon_api +#else +#define ntcon_api +#endif + +#endif diff --git a/include/ntcon/ntcon_env.h b/include/ntcon/ntcon_env.h new file mode 100644 index 0000000..9257834 --- /dev/null +++ b/include/ntcon/ntcon_env.h @@ -0,0 +1,22 @@ +#ifndef NTCON_ENV_H +#define NTCON_ENV_H + +#if defined (MIDIPIX_FREESTANDING) + +#include + +#else + +#include + +#ifndef __cdecl +#define __cdecl +#endif + +#ifndef __stdcall +#define __stdcall +#endif + +#endif + +#endif diff --git a/project/arch.mk b/project/arch.mk new file mode 100644 index 0000000..e69de29 diff --git a/project/common.mk b/project/common.mk new file mode 100644 index 0000000..8b8af72 --- /dev/null +++ b/project/common.mk @@ -0,0 +1,4 @@ +COMMON_SRCS = \ + src/ntcon.c \ + src/ntcon_entry_point.c \ + diff --git a/project/defs.mk b/project/defs.mk new file mode 100644 index 0000000..d6212fe --- /dev/null +++ b/project/defs.mk @@ -0,0 +1,31 @@ +SHARED_LIB_DEPS = +SHARED_APP_DEPS = +STATIC_APP_DEPS = + +COMMON_LOBJS = $(COMMON_SRCS:.c=.lo) +COMMON_OBJS = $(COMMON_SRCS:.c=.o) + +ARCH_LOBJS = $(ARCH_SRCS:.c=.lo) +ARCH_OBJS = $(ARCH_SRCS:.c=.o) + +SHARED_OBJS = $(COMMON_LOBJS) $(ARCH_LOBJS) +STATIC_OBJS = $(COMMON_OBJS) $(ARCH_OBJS) + +SHARED_LIB = $(LIBDIR)/$(OS_LIB_PREFIX)$(PACKAGE)$(OS_LIB_SUFFIX) +STATIC_LIB = $(LIBDIR)/$(OS_LIB_PREFIX)$(PACKAGE)$(OS_ARCHIVE_EXT) +SHARED_IMPLIB = $(LIBDIR)/$(OS_LIB_PREFIX)$(PACKAGE)$(OS_IMPLIB_EXT) + +CFLAGS = $(CFLAGS_DEBUG) $(CFLAGS_CONFIG) $(CFLAGS_SYSROOT) \ + $(CFLAGS_COMMON) $(CFLAGS_CMDLINE) $(CFLAGS_HOST) \ + $(CFLAGS_PATH) + +CFLAGS_SHARED = $(CFLAGS) $(CFLAGS_PIC) $(CFLAGS_SHARED_ATTR) +CFLAGS_STATIC = $(CFLAGS) $(CFLAGS_OBJ) $(CFLAGS_STATIC_ATTR) + +LDFLAGS_SHARED = $(LDFLAGS_DEBUG) $(LDFLAGS_CONFIG) $(LDFLAGS_SYSROOT) \ + $(LDFLAGS_COMMON) $(LDFLAGS_CMDLINE) $(LDFLAGS_HOST) \ + $(LDFLAGS_PATH) $(SHARED_LIB_DEPS) $(LDFLAGS_LAST) + +LDFLAGS_STATIC = $(LDFLAGS_DEBUG) $(LDFLAGS_CONFIG) $(LDFLAGS_SYSROOT) \ + $(LDFLAGS_COMMON) $(LDFLAGS_CMDLINE) $(LDFLAGS_HOST) \ + $(LDFLAGS_PATH) $(STATIC_APP_DEPS) $(LDFLAGS_LAST) diff --git a/project/depends.mk b/project/depends.mk new file mode 100644 index 0000000..e69de29 diff --git a/project/extras.mk b/project/extras.mk new file mode 100644 index 0000000..57b0f11 --- /dev/null +++ b/project/extras.mk @@ -0,0 +1,27 @@ +CFLAGS_SHARED_ATTR += -DNTCON_BUILD +CFLAGS_STATIC_ATTR += -DNTCON_STATIC + +ifeq ($(OS),midipix) + HOST_FMT = pe +else ifeq ($(OS),mingw) + HOST_FMT = pe +else + HOST_FMT = unknown +endif + +ifeq ($(HOST_FMT),pe) + CFLAGS_CONFIG += -DMIDIPIX_FREESTANDING -ffreestanding -D__NT$(HOST_BITS) + CFLAGS_CONFIG += -UWIN32 -U_WIN32 -U__WIN32 -U__WIN32__ + CFLAGS_CONFIG += -UWIN64 -U_WIN64 -U__WIN64 -U__WIN64__ + + LDFLAGS_SHARED += -nostdlib + LDFLAGS_SHARED += -lpemagine + LDFLAGS_SHARED += -Wl,--out-implib,$(SHARED_IMPLIB) + LDFLAGS_SHARED += -Wl,--exclude-all-symbols + + ifeq ($(HOST_BITS),32) + LDFLAGS_SHARED += -Wl,--entry,$(HOST_UNDERSCORE)ntcon_entry_point@12 + else + LDFLAGS_SHARED += -Wl,--entry,$(HOST_UNDERSCORE)ntcon_entry_point + endif +endif diff --git a/project/headers.mk b/project/headers.mk new file mode 100644 index 0000000..cddbaf1 --- /dev/null +++ b/project/headers.mk @@ -0,0 +1,8 @@ +API_HEADERS = \ + $(PROJECT_DIR)/include/$(PACKAGE)/ntcon.h \ + $(PROJECT_DIR)/include/$(PACKAGE)/ntcon_api.h \ + $(PROJECT_DIR)/include/$(PACKAGE)/ntcon_env.h + +INTERNAL_HEADERS = + +ALL_HEADERS = $(API_HEADERS) $(INTERNAL_HEADERS) diff --git a/project/overrides.mk b/project/overrides.mk new file mode 100644 index 0000000..e69de29 diff --git a/project/tree.mk b/project/tree.mk new file mode 100644 index 0000000..20f0861 --- /dev/null +++ b/project/tree.mk @@ -0,0 +1,3 @@ +tree.tag: + mkdir -p src + touch tree.tag diff --git a/src/ntcon.c b/src/ntcon.c new file mode 100644 index 0000000..5ad9223 --- /dev/null +++ b/src/ntcon.c @@ -0,0 +1,146 @@ +/********************************************************/ +/* ntcon: free-standing console interface definitions */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTCON. */ +/********************************************************/ + +#include +#include + +#define NT_STATUS_SUCCESS 0x00000000 +#define NT_STATUS_INTERNAL_ERROR 0xC00000E5 + +#define NTCON_PTR_INIT(x,y) pvtbl->x = \ + (ntcon_##x *)pe_get_procedure_address(hkernel, #y) + +ntcon_api +int32_t __fastcall ntcon_vtbl_init(ntcon_vtbl * pvtbl) +{ + void * hkernel; + + if (!(hkernel = pe_get_kernel32_module_handle())) + return NT_STATUS_INTERNAL_ERROR; + + /* console handles */ + NTCON_PTR_INIT(alloc_console, AllocConsole); + NTCON_PTR_INIT(attach_console, AttachConsole); + NTCON_PTR_INIT(free_console, FreeConsole); + NTCON_PTR_INIT(get_std_handle, GetStdHandle); + + /* read/write using std handles */ + NTCON_PTR_INIT(get_number_of_console_input_events, GetNumberOfConsoleInputEvents); + NTCON_PTR_INIT(flush_console_input_buffer, FlushConsoleInputBuffer); + NTCON_PTR_INIT(peek_console_input_ansi, PeekConsoleInputA); + NTCON_PTR_INIT(peek_console_input_utf16, PeekConsoleInputW); + NTCON_PTR_INIT(read_console_ansi, ReadConsoleA); + NTCON_PTR_INIT(read_console_utf16, ReadConsoleW); + NTCON_PTR_INIT(read_console_input_ansi, ReadConsoleInputA); + NTCON_PTR_INIT(read_console_input_utf16, ReadConsoleInputW); + NTCON_PTR_INIT(read_console_output_ansi, ReadConsoleOutputA); + NTCON_PTR_INIT(read_console_output_utf16, ReadConsoleOutputW); + NTCON_PTR_INIT(write_console_ansi, WriteConsoleA); + NTCON_PTR_INIT(write_console_utf16, WriteConsoleW); + NTCON_PTR_INIT(write_console_input_ansi, WriteConsoleInputA); + NTCON_PTR_INIT(write_console_input_utf16, WriteConsoleInputW); + NTCON_PTR_INIT(write_console_output_ansi, WriteConsoleOutputA); + NTCON_PTR_INIT(write_console_output_utf16, WriteConsoleOutputW); + + /* screen buffers */ + NTCON_PTR_INIT(create_console_screen_buffer, CreateConsoleScreenBuffer); + NTCON_PTR_INIT(get_console_screen_buffer_info, GetConsoleScreenBufferInfo); + NTCON_PTR_INIT(get_console_screen_buffer_info_ex, GetConsoleScreenBufferInfoEx); + NTCON_PTR_INIT(set_console_screen_buffer_info_ex, SetConsoleScreenBufferInfoEx); + NTCON_PTR_INIT(set_console_screen_buffer_size, SetConsoleScreenBufferSize); + NTCON_PTR_INIT(set_console_active_screen_buffer, SetConsoleActiveScreenBuffer); + NTCON_PTR_INIT(set_console_window_info, SetConsoleWindowInfo); + NTCON_PTR_INIT(scroll_console_screen_buffer_ansi, ScrollConsoleScreenBufferA); + NTCON_PTR_INIT(scroll_console_screen_buffer_utf16, ScrollConsoleScreenBufferW); + + /* code page */ + NTCON_PTR_INIT(get_console_code_page, GetConsoleCP); + NTCON_PTR_INIT(set_console_code_page, SetConsoleCP); + + /* console control */ + NTCON_PTR_INIT(generate_console_ctrl_event, GenerateConsoleCtrlEvent); + NTCON_PTR_INIT(set_console_ctrl_handler, SetConsoleCtrlHandler); + + /* interface mode */ + NTCON_PTR_INIT(get_console_mode, GetConsoleMode); + NTCON_PTR_INIT(set_console_mode, SetConsoleMode); + + /* console process list */ + NTCON_PTR_INIT(get_console_process_list, GetConsoleProcessList); + + /* aliases */ + NTCON_PTR_INIT(add_console_alias_ansi, AddConsoleAliasA); + NTCON_PTR_INIT(add_console_alias_utf16, AddConsoleAliasW); + NTCON_PTR_INIT(get_console_alias_ansi, GetConsoleAliasA); + NTCON_PTR_INIT(get_console_alias_utf16, GetConsoleAliasW); + NTCON_PTR_INIT(get_console_aliases_ansi, GetConsoleAliasesA); + NTCON_PTR_INIT(get_console_aliases_utf16, GetConsoleAliasesW); + NTCON_PTR_INIT(get_console_aliases_length_ansi, GetConsoleAliasesLengthA); + NTCON_PTR_INIT(get_console_aliases_length_utf16, GetConsoleAliasesLengthW); + NTCON_PTR_INIT(get_console_alias_exes_ansi, GetConsoleAliasExesA); + NTCON_PTR_INIT(get_console_alias_exes_utf16, GetConsoleAliasExesW); + NTCON_PTR_INIT(get_console_alias_exes_length_ansi, GetConsoleAliasExesLengthA); + NTCON_PTR_INIT(get_console_alias_exes_length_utf16, GetConsoleAliasExesLengthW); + + /* output attributes */ + NTCON_PTR_INIT(fill_console_output_attribute, FillConsoleOutputAttribute); + NTCON_PTR_INIT(read_console_output_attribute, ReadConsoleOutputAttribute); + NTCON_PTR_INIT(write_console_output_attribute, WriteConsoleOutputAttribute); + + /* output characters */ + NTCON_PTR_INIT(fill_console_output_character_ansi, FillConsoleOutputCharacterA); + NTCON_PTR_INIT(fill_console_output_character_utf16, FillConsoleOutputCharacterW); + NTCON_PTR_INIT(read_console_output_character_ansi, ReadConsoleOutputCharacterA); + NTCON_PTR_INIT(read_console_output_character_utf16, ReadConsoleOutputCharacterW); + NTCON_PTR_INIT(write_console_output_character_ansi, WriteConsoleOutputCharacterA); + NTCON_PTR_INIT(write_console_output_character_utf16, WriteConsoleOutputCharacterW); + + /* output code page */ + NTCON_PTR_INIT(get_console_output_code_page, GetConsoleOutputCP); + NTCON_PTR_INIT(set_console_output_code_page, SetConsoleOutputCP); + + /* text attributes */ + NTCON_PTR_INIT(set_console_text_attribute, SetConsoleTextAttribute); + + /* cursor info */ + NTCON_PTR_INIT(get_console_cursor_info, GetConsoleCursorInfo); + NTCON_PTR_INIT(set_console_cursor_info, SetConsoleCursorInfo); + NTCON_PTR_INIT(set_console_cursor_position, SetConsoleCursorPosition); + + /* selection info */ + NTCON_PTR_INIT(get_console_selection_info, GetConsoleSelectionInfo); + + /* history info */ + NTCON_PTR_INIT(get_console_history_info, GetConsoleHistoryInfo); + NTCON_PTR_INIT(set_console_history_info, SetConsoleHistoryInfo); + + /* font info */ + NTCON_PTR_INIT(get_console_font_size, GetConsoleFontSize); + NTCON_PTR_INIT(get_current_console_font, GetCurrentConsoleFont); + NTCON_PTR_INIT(get_current_console_font_ex, GetCurrentConsoleFontEx); + NTCON_PTR_INIT(set_current_console_font_ex, SetCurrentConsoleFontEx); + + /* mouse capabilities */ + NTCON_PTR_INIT(get_number_of_console_mouse_buttons, GetNumberOfConsoleMouseButtons); + + /* window information */ + NTCON_PTR_INIT(get_console_window, GetConsoleWindow); + NTCON_PTR_INIT(get_largest_console_window_size, GetLargestConsoleWindowSize); + + /* console api: display mode */ + NTCON_PTR_INIT(get_console_display_mode, GetConsoleDisplayMode); + NTCON_PTR_INIT(set_console_display_mode, SetConsoleDisplayMode); + + /* console title */ + NTCON_PTR_INIT(get_console_title_ansi, GetConsoleTitleA); + NTCON_PTR_INIT(get_console_title_utf16, GetConsoleTitleW); + NTCON_PTR_INIT(set_console_title_ansi, SetConsoleTitleA); + NTCON_PTR_INIT(set_console_title_utf16, SetConsoleTitleW); + NTCON_PTR_INIT(get_console_original_title_ansi, GetConsoleOriginalTitleA); + NTCON_PTR_INIT(get_console_original_title_utf16, GetConsoleOriginalTitleW); + + return NT_STATUS_SUCCESS; +} diff --git a/src/ntcon_entry_point.c b/src/ntcon_entry_point.c new file mode 100644 index 0000000..cad654b --- /dev/null +++ b/src/ntcon_entry_point.c @@ -0,0 +1,13 @@ +#ifdef MIDIPIX_FREESTANDING + +#include + +int __stdcall ntcon_entry_point( + void * hinstance, + uint32_t reason, + void * reserved) +{ + return 1; +} + +#endif diff --git a/sysinfo/host/host.sh b/sysinfo/host/host.sh new file mode 100755 index 0000000..1fe2515 --- /dev/null +++ b/sysinfo/host/host.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +error_msg() +{ + echo $@ >&2 +} + +host_test() +{ + mb_hdrdir=$(pwd)/build + mkdir -p $mb_hdrdir || exit 2 + + if [ x"$mb_compiler" = x ]; then + echo "config error: compiler not set." + exit 2 + fi + + $mb_compiler -dM -E - < /dev/null > /dev/null && return 0 + + error_msg "config error: invalid compiler." + exit 2 +} + + +# one: args +for arg ; do + case "$arg" in + --help) usage + ;; + --compiler=*) + mb_compiler=${arg#*=} + ;; + --cflags=*) + mb_cflags=${arg#*=} + ;; + *) + error_msg ${arg#}: "unsupported config argument." + exit 2 + ;; + esac +done + + +# two: test +host_test + + +# all done +exit 0 diff --git a/sysinfo/host/i686-nt32-midipix.mk b/sysinfo/host/i686-nt32-midipix.mk new file mode 100644 index 0000000..df3185b --- /dev/null +++ b/sysinfo/host/i686-nt32-midipix.mk @@ -0,0 +1,5 @@ +include $(PROJECT_DIR)/sysinfo/os/midipix.mk + +ARCH = nt32 +HOST_BITS = 32 +HOST_UNDERSCORE = '_' diff --git a/sysinfo/host/i686-unknown-linux.mk b/sysinfo/host/i686-unknown-linux.mk new file mode 100644 index 0000000..79d497b --- /dev/null +++ b/sysinfo/host/i686-unknown-linux.mk @@ -0,0 +1,5 @@ +include $(PROJECT_DIR)/sysinfo/os/linux.mk + +ARCH = i386 +HOST_BITS = 32 +HOST_UNDERSCORE = '_' diff --git a/sysinfo/host/i686-w64-mingw32.mk b/sysinfo/host/i686-w64-mingw32.mk new file mode 100644 index 0000000..b8ba461 --- /dev/null +++ b/sysinfo/host/i686-w64-mingw32.mk @@ -0,0 +1,5 @@ +include $(PROJECT_DIR)/sysinfo/os/mingw.mk + +ARCH = w32 +HOST_BITS = 32 +HOST_UNDERSCORE = '_' diff --git a/sysinfo/host/native.mk b/sysinfo/host/native.mk new file mode 100644 index 0000000..08b02b6 --- /dev/null +++ b/sysinfo/host/native.mk @@ -0,0 +1,45 @@ +include $(PROJECT_DIR)/sysinfo/os/$(NATIVE_OS).mk + +OS = $(NATIVE_OS) +HOST_BITS = $(NATIVE_OS_BITS) +HOST_UNDERSCORE = $(NATIVE_OS_UNDERSCORE) + +ifeq ($(OS),linux) + ifeq ($(HOST_BITS),32) + ARCH = i386 + else ifeq ($(HOST_BITS),64) + ARCH = x86_64 + endif +endif + +ifeq ($(OS),midipix) + ifeq ($(HOST_BITS),32) + ARCH = nt32 + else ifeq ($(HOST_BITS),64) + ARCH = nt64 + endif +endif + +ifeq ($(OS),mingw) + ifeq ($(HOST_BITS),32) + ARCH = w32 + else ifeq ($(HOST_BITS),64) + ARCH = w64 + endif +endif + +ifeq ($(OS),bsd) + ifeq ($(HOST_BITS),32) + ARCH = bsd32 + else ifeq ($(HOST_BITS),64) + ARCH = bsd64 + endif +endif + +ifeq ($(OS),darwin) + ifeq ($(HOST_BITS),32) + ARCH = dw32 + else ifeq ($(HOST_BITS),64) + ARCH = dw64 + endif +endif diff --git a/sysinfo/host/x86_64-nt64-midipix.mk b/sysinfo/host/x86_64-nt64-midipix.mk new file mode 100644 index 0000000..fef6345 --- /dev/null +++ b/sysinfo/host/x86_64-nt64-midipix.mk @@ -0,0 +1,5 @@ +include $(PROJECT_DIR)/sysinfo/os/midipix.mk + +ARCH = nt64 +HOST_BITS = 64 +HOST_UNDERSCORE = '' diff --git a/sysinfo/host/x86_64-unknown-linux.mk b/sysinfo/host/x86_64-unknown-linux.mk new file mode 100644 index 0000000..76afb56 --- /dev/null +++ b/sysinfo/host/x86_64-unknown-linux.mk @@ -0,0 +1,5 @@ +include $(PROJECT_DIR)/sysinfo/os/linux.mk + +ARCH = x86_64 +HOST_BITS = 64 +HOST_UNDERSCORE = '' diff --git a/sysinfo/host/x86_64-w64-mingw32.mk b/sysinfo/host/x86_64-w64-mingw32.mk new file mode 100644 index 0000000..7cded15 --- /dev/null +++ b/sysinfo/host/x86_64-w64-mingw32.mk @@ -0,0 +1,5 @@ +include $(PROJECT_DIR)/sysinfo/os/mingw.mk + +ARCH = w64 +HOST_BITS = 64 +HOST_UNDERSCORE = '' diff --git a/sysinfo/os/bsd.mk b/sysinfo/os/bsd.mk new file mode 100644 index 0000000..3fe6711 --- /dev/null +++ b/sysinfo/os/bsd.mk @@ -0,0 +1,10 @@ +OS = bsd +OS_APP_PREFIX = +OS_APP_SUFFIX = +OS_LIB_PREFIX = lib +OS_LIB_SUFFIX = .so +OS_IMPLIB_EXT = .invalid +OS_LIBDEF_EXT = .invalid +OS_ARCHIVE_EXT = .a + +.PHONY: $(SHARED_IMPLIB) diff --git a/sysinfo/os/darwin.mk b/sysinfo/os/darwin.mk new file mode 100644 index 0000000..b27a486 --- /dev/null +++ b/sysinfo/os/darwin.mk @@ -0,0 +1,10 @@ +OS = darwin +OS_APP_PREFIX = +OS_APP_SUFFIX = +OS_LIB_PREFIX = lib +OS_LIB_SUFFIX = .dylib +OS_IMPLIB_EXT = .invalid +OS_LIBDEF_EXT = .invalid +OS_ARCHIVE_EXT = .a + +.PHONY: $(SHARED_IMPLIB) diff --git a/sysinfo/os/linux.mk b/sysinfo/os/linux.mk new file mode 100644 index 0000000..d6221cf --- /dev/null +++ b/sysinfo/os/linux.mk @@ -0,0 +1,10 @@ +OS = linux +OS_APP_PREFIX = +OS_APP_SUFFIX = +OS_LIB_PREFIX = lib +OS_LIB_SUFFIX = .so +OS_IMPLIB_EXT = .invalid +OS_LIBDEF_EXT = .invalid +OS_ARCHIVE_EXT = .a + +.PHONY: $(SHARED_IMPLIB) diff --git a/sysinfo/os/midipix.mk b/sysinfo/os/midipix.mk new file mode 100644 index 0000000..fded25e --- /dev/null +++ b/sysinfo/os/midipix.mk @@ -0,0 +1,14 @@ +OS = midipix +OS_APP_PREFIX = +OS_APP_SUFFIX = +OS_LIB_PREFIX = lib +OS_LIB_SUFFIX = .so +OS_IMPLIB_EXT = .lib.a +OS_LIBDEF_EXT = .so.def +OS_ARCHIVE_EXT = .a + +LDFLAGS_CONFIG += -mout-implib + +install-implib: shared-implib + mkdir -p $(DESTDIR)/./$(PREFIX)/./$(LIBDIR) + cp $(SHARED_IMPLIB) $(DESTDIR)/./$(PREFIX)/./$(LIBDIR) diff --git a/sysinfo/os/mingw.mk b/sysinfo/os/mingw.mk new file mode 100644 index 0000000..7a76235 --- /dev/null +++ b/sysinfo/os/mingw.mk @@ -0,0 +1,15 @@ +OS = mingw +OS_APP_PREFIX = +OS_APP_SUFFIX = .exe +OS_LIB_PREFIX = lib +OS_LIB_SUFFIX = .dll +OS_IMPLIB_EXT = .a +OS_LIBDEF_EXT = .def +OS_ARCHIVE_EXT = .a + +CFLAGS_PIC = +LDFLAGS_CONFIG += -Wl,--out-implib,$(SHARED_IMPLIB) + +install-implib: shared-implib + mkdir -p $(DESTDIR)/./$(PREFIX)/./$(LIBDIR) + cp $(SHARED_IMPLIB) $(DESTDIR)/./$(PREFIX)/./$(LIBDIR) diff --git a/sysinfo/toolchain/clang.mk b/sysinfo/toolchain/clang.mk new file mode 100644 index 0000000..3e4a795 --- /dev/null +++ b/sysinfo/toolchain/clang.mk @@ -0,0 +1,48 @@ +ifeq ($(CROSS_COMPILE)x,x) + CROSS_HOST = + CROSS_HOST_SPEC = +else + CROSS_HOST = $(HOST) + CROSS_HOST_SPEC = --target=$(HOST) +endif + + +ifeq ($(USER_CC)x,x) + CC = $(NATIVE_CC) $(CROSS_HOST_SPEC) +else + CC = $(USER_CC) $(CROSS_HOST_SPEC) +endif + +ifeq ($(USER_CPP)x,x) + CPP = $(NATIVE_CC) $(CROSS_HOST_SPEC) -E +else + CPP = $(USER_CPP) $(CROSS_HOST_SPEC) -E +endif + +ifeq ($(USER_CXX)x,x) + CXX = $(NATIVE_CC)++ $(CROSS_HOST_SPEC) +else + CXX = $(USER_CXX) $(CROSS_HOST_SPEC) +endif + + +AS = $(CROSS_COMPILE)as +AR = $(CROSS_COMPILE)ar +LD = $(CROSS_COMPILE)ld +NM = $(CROSS_COMPILE)nm +OBJDUMP = $(CROSS_COMPILE)objdump +RANLIB = $(CROSS_COMPILE)ranlib +SIZE = $(CROSS_COMPILE)size +STRIP = $(CROSS_COMPILE)strip +STRINGS = $(CROSS_COMPILE)strings + + +ADDR2LINE = $(CROSS_COMPILE)addr2line +COV = $(CROSS_COMPILE)gcov +CXXFILT = $(CROSS_COMPILE)c++filt +ELFEDIT = $(CROSS_COMPILE)elfedit +OBJCOPY = $(CROSS_COMPILE)objcopy +READELF = $(CROSS_COMPILE)readelf + + +CFLAGS_PIC = -fPIC diff --git a/sysinfo/toolchain/cparser.mk b/sysinfo/toolchain/cparser.mk new file mode 100644 index 0000000..762a6e6 --- /dev/null +++ b/sysinfo/toolchain/cparser.mk @@ -0,0 +1,48 @@ +ifeq ($(CROSS_COMPILE)x,x) + CROSS_HOST = + CROSS_HOST_SPEC = +else + CROSS_HOST = $(HOST) + CROSS_HOST_SPEC = --target=$(HOST) +endif + + +ifeq ($(USER_CC)x,x) + CC = $(NATIVE_CC) $(CROSS_HOST_SPEC) -Wno-experimental -integrated-cpp +else + CC = $(USER_CC) $(CROSS_HOST_SPEC) -Wno-experimental -integrated-cpp +endif + +ifeq ($(USER_CPP)x,x) + CPP = $(NATIVE_CC) $(CROSS_HOST_SPEC) -Wno-experimental -integrated-cpp -E +else + CPP = $(USER_CPP) $(CROSS_HOST_SPEC) -Wno-experimental -integrated-cpp -E +endif + +ifeq ($(USER_CXX)x,x) + CXX = $(NATIVE_CC) $(CROSS_HOST_SPEC) -Wno-experimental -integrated-cpp -std=c++ +else + CXX = $(USER_CXX) $(CROSS_HOST_SPEC) -Wno-experimental -integrated-cpp -std=c++ +endif + + +AS = $(CROSS_COMPILE)as +AR = $(CROSS_COMPILE)ar +LD = $(CROSS_COMPILE)ld +NM = $(CROSS_COMPILE)nm +OBJDUMP = $(CROSS_COMPILE)objdump +RANLIB = $(CROSS_COMPILE)ranlib +SIZE = $(CROSS_COMPILE)size +STRIP = $(CROSS_COMPILE)strip +STRINGS = $(CROSS_COMPILE)strings + + +ADDR2LINE = $(CROSS_COMPILE)addr2line +COV = $(CROSS_COMPILE)gcov +CXXFILT = $(CROSS_COMPILE)c++filt +ELFEDIT = $(CROSS_COMPILE)elfedit +OBJCOPY = $(CROSS_COMPILE)objcopy +READELF = $(CROSS_COMPILE)readelf + + +CFLAGS_PIC = -fPIC diff --git a/sysinfo/toolchain/gcc.mk b/sysinfo/toolchain/gcc.mk new file mode 100644 index 0000000..52a2545 --- /dev/null +++ b/sysinfo/toolchain/gcc.mk @@ -0,0 +1,43 @@ +ifeq ($(USER_CC)x,x) + ifeq ($(CROSS_COMPILE)x,x) + CC = $(CROSS_COMPILE)$(NATIVE_CC) + else + CC = $(CROSS_COMPILE)gcc + endif +else + CC = $(USER_CC) +endif + +ifeq ($(USER_CPP)x,x) + CPP = $(CROSS_COMPILE)cpp +else + CPP = $(USER_CPP) +endif + +ifeq ($(USER_CXX)x,x) + CXX = $(CROSS_COMPILE)c++ +else + CXX = $(USER_CXX) +endif + + +AS = $(CROSS_COMPILE)as +AR = $(CROSS_COMPILE)ar +LD = $(CROSS_COMPILE)ld +NM = $(CROSS_COMPILE)nm +OBJDUMP = $(CROSS_COMPILE)objdump +RANLIB = $(CROSS_COMPILE)ranlib +SIZE = $(CROSS_COMPILE)size +STRIP = $(CROSS_COMPILE)strip +STRINGS = $(CROSS_COMPILE)strings + + +ADDR2LINE = $(CROSS_COMPILE)addr2line +COV = $(CROSS_COMPILE)gcov +CXXFILT = $(CROSS_COMPILE)c++filt +ELFEDIT = $(CROSS_COMPILE)elfedit +OBJCOPY = $(CROSS_COMPILE)objcopy +READELF = $(CROSS_COMPILE)readelf + + +CFLAGS_PIC = -fPIC -- cgit v1.2.3