#include "blade.h"
#include "tap.h"
-#ifdef _WIN32
-#define STDIO_FD(_fs) _fileno(_fs)
-#define READ(_fd, _buffer, _count) _read(_fd, _buffer, _count)
-#else
-#define STDIO_FD(_fs) fileno(_fs)
-#define READ(_fd, _buffer, _count) read(_fd, _buffer, _count)
-#endif
-
#define CONSOLE_INPUT_MAX 512
ks_bool_t g_shutdown = KS_FALSE;
-char g_console_input[CONSOLE_INPUT_MAX];
-size_t g_console_input_length = 0;
-size_t g_console_input_eol = 0;
void loop(blade_handle_t *bh);
void process_console_input(blade_handle_t *bh, char *line);
}
}
-void buffer_console_input(void)
-{
- ssize_t bytes = 0;
- struct pollfd poll[1];
- poll[0].fd = STDIO_FD(stdin);
- poll[0].events = POLLIN | POLLERR;
-
- if (ks_poll(poll, 1, 1) > 0) {
- if (poll[0].revents & POLLIN) {
- if ((bytes = READ(poll[0].fd, g_console_input + g_console_input_length, CONSOLE_INPUT_MAX - g_console_input_length)) <= 0) {
- // @todo error
- return;
- }
- g_console_input_length += bytes;
- }
- }
-}
-
void loop(blade_handle_t *bh)
{
+ char buf[CONSOLE_INPUT_MAX];
while (!g_shutdown) {
- ks_bool_t eol = KS_FALSE;
- buffer_console_input();
+ if (!fgets(buf, CONSOLE_INPUT_MAX, stdin)) break;
- for (; g_console_input_eol < g_console_input_length; ++g_console_input_eol) {
- char c = g_console_input[g_console_input_eol];
- if (c == '\r' || c == '\n') {
- eol = KS_TRUE;
+ for (int index = 0; buf[index]; ++index) {
+ if (buf[index] == '\r' || buf[index] == '\n') {
+ buf[index] = '\0';
break;
}
}
- if (eol) {
- g_console_input[g_console_input_eol] = '\0';
- process_console_input(bh, g_console_input);
- g_console_input_eol++;
- for (; g_console_input_eol < g_console_input_length; ++g_console_input_eol) {
- char c = g_console_input[g_console_input_eol];
- if (c != '\r' && c != '\n') break;
- }
- if (g_console_input_eol == g_console_input_length) g_console_input_eol = g_console_input_length = 0;
- else {
- memcpy(g_console_input, g_console_input + g_console_input_eol, g_console_input_length - g_console_input_eol);
- g_console_input_length -= g_console_input_eol;
- g_console_input_eol = 0;
- }
- }
- if (g_console_input_length == CONSOLE_INPUT_MAX) {
- // @todo lines must not exceed 512 bytes, treat as error and ignore buffer until next new line?
- ks_assert(0);
- }
+ process_console_input(bh, buf);
}
}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{4A70CDA9-AC5B-4818-BCF2-B0DD1B8F5F5F}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>bladec</RootNamespace>
+ <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="..\..\..\w32\openssl-version.props" />
+ <Import Project="..\..\..\w32\sodium.props" />
+ <Import Project="..\..\..\w32\config.props" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="..\..\..\w32\openssl-version.props" />
+ <Import Project="..\..\..\w32\sodium.props" />
+ <Import Project="..\..\..\w32\config.props" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="..\..\..\w32\openssl-version.props" />
+ <Import Project="..\..\..\w32\sodium.props" />
+ <Import Project="..\..\..\w32\config.props" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="..\..\..\w32\openssl-version.props" />
+ <Import Project="..\..\..\w32\sodium.props" />
+ <Import Project="..\..\..\w32\config.props" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LinkIncremental>true</LinkIncremental>
+ <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+ <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+ <IncludePath>$(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include;$(IncludePath)</IncludePath>
+ <LibraryPath>$(LibraryPath)</LibraryPath>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <LinkIncremental>true</LinkIncremental>
+ <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+ <IncludePath>$(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include64;$(IncludePath)</IncludePath>
+ <LibraryPath>$(LibraryPath)</LibraryPath>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+ <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
+ <IncludePath>$(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include;$(IncludePath)</IncludePath>
+ <LibraryPath>$(LibraryPath)</LibraryPath>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <LinkIncremental>false</LinkIncremental>
+ <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+ <IncludePath>$(SolutionDir);$(SolutionDir)..\libks\src\include;$(SolutionDir)..\libsodium-$(SodiumVersion)\src\libsodium\include;$(SolutionDir)..\libconfig-$(ConfigVersion)\lib;$(SolutionDir)\openssl\include64;$(IncludePath)</IncludePath>
+ <LibraryPath>$(LibraryPath)</LibraryPath>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x86;../src/include;.</AdditionalIncludeDirectories>
+ <DisableSpecificWarnings>4090</DisableSpecificWarnings>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
+ <MinimalRebuild>false</MinimalRebuild>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;.</AdditionalIncludeDirectories>
+ <DisableSpecificWarnings>4090</DisableSpecificWarnings>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
+ <MinimalRebuild>false</MinimalRebuild>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x86;../src/include;.</AdditionalIncludeDirectories>
+ <DisableSpecificWarnings>4090</DisableSpecificWarnings>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\win32\openssl\include;$(SolutionDir)..\win32\openssl\include_x64;../src/include;.</AdditionalIncludeDirectories>
+ <DisableSpecificWarnings>4090</DisableSpecificWarnings>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="tap.c" />
+ <ClCompile Include="bladec.c" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\libks\libks.vcxproj">
+ <Project>{70d178d8-1100-4152-86c0-809a91cff832}</Project>
+ </ProjectReference>
+ <ProjectReference Include="..\..\win32\libconfig\libconfig.2015.vcxproj">
+ <Project>{1a234565-926d-49b2-83e4-d56e0c38c9f2}</Project>
+ </ProjectReference>
+ <ProjectReference Include="..\..\win32\libsodium\libsodium.2015.vcxproj">
+ <Project>{a185b162-6cb6-4502-b03f-b56f7699a8d9}</Project>
+ </ProjectReference>
+ <ProjectReference Include="..\..\win32\openssl\libeay32.2015.vcxproj">
+ <Project>{d331904d-a00a-4694-a5a3-fcff64ab5dbe}</Project>
+ </ProjectReference>
+ <ProjectReference Include="..\..\win32\openssl\ssleay32.2015.vcxproj">
+ <Project>{b4b62169-5ad4-4559-8707-3d933ac5db39}</Project>
+ </ProjectReference>
+ <ProjectReference Include="..\libblade.vcxproj">
+ <Project>{a89d6d18-6203-4149-9051-f8e798e7a3e7}</Project>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file
#include "blade.h"
#include "tap.h"
-#ifdef _WIN32
-#define STDIO_FD(_fs) _fileno(_fs)
-#define READ(_fd, _buffer, _count) _read(_fd, _buffer, _count)
-#else
-#define STDIO_FD(_fs) fileno(_fs)
-#define READ(_fd, _buffer, _count) read(_fd, _buffer, _count)
-#endif
-
#define CONSOLE_INPUT_MAX 512
ks_bool_t g_shutdown = KS_FALSE;
-char g_console_input[CONSOLE_INPUT_MAX];
-size_t g_console_input_length = 0;
-size_t g_console_input_eol = 0;
void loop(blade_handle_t *bh);
void process_console_input(blade_handle_t *bh, char *line);
return 0;
}
-
-
-void buffer_console_input(void)
-{
- ssize_t bytes = 0;
- struct pollfd poll[1];
- poll[0].fd = STDIO_FD(stdin);
- poll[0].events = POLLIN | POLLERR;
-
- if (ks_poll(poll, 1, 1) > 0) {
- if (poll[0].revents & POLLIN) {
- if ((bytes = READ(poll[0].fd, g_console_input + g_console_input_length, CONSOLE_INPUT_MAX - g_console_input_length)) <= 0) {
- // @todo error
- return;
- }
- g_console_input_length += bytes;
- }
- }
-}
-
void loop(blade_handle_t *bh)
{
+ char buf[CONSOLE_INPUT_MAX];
while (!g_shutdown) {
- ks_bool_t eol = KS_FALSE;
- buffer_console_input();
+ if (!fgets(buf, CONSOLE_INPUT_MAX, stdin)) break;
- for (; g_console_input_eol < g_console_input_length; ++g_console_input_eol) {
- char c = g_console_input[g_console_input_eol];
- if (c == '\r' || c == '\n') {
- eol = KS_TRUE;
+ for (int index = 0; buf[index]; ++index) {
+ if (buf[index] == '\r' || buf[index] == '\n') {
+ buf[index] = '\0';
break;
}
}
- if (eol) {
- g_console_input[g_console_input_eol] = '\0';
- process_console_input(bh, g_console_input);
- g_console_input_eol++;
- for (; g_console_input_eol < g_console_input_length; ++g_console_input_eol) {
- char c = g_console_input[g_console_input_eol];
- if (c != '\r' && c != '\n') break;
- }
- if (g_console_input_eol == g_console_input_length) g_console_input_eol = g_console_input_length = 0;
- else {
- memcpy(g_console_input, g_console_input + g_console_input_eol, g_console_input_length - g_console_input_eol);
- g_console_input_length -= g_console_input_eol;
- g_console_input_eol = 0;
- }
- }
- if (g_console_input_length == CONSOLE_INPUT_MAX) {
- // @todo lines must not exceed 512 bytes, treat as error and ignore buffer until next new line?
- ks_assert(0);
- }
+ process_console_input(bh, buf);
}
}