diff options
author | Gavin Howard <yzena.tech@gmail.com> | 2021-04-04 19:13:24 -0600 |
---|---|---|
committer | Gavin Howard <yzena.tech@gmail.com> | 2021-04-04 19:13:24 -0600 |
commit | f7a6430c6abbfbc713eec85a54a1f19aab64dab9 (patch) | |
tree | 3d5c55fe4034c54ff1d269ab4f73e5ba3b0651e5 | |
parent | 40d0351155b4a36afe3541dd626d8b1eeaa7f714 (diff) | |
download | bc-f7a6430c6abbfbc713eec85a54a1f19aab64dab9.tar.gz |
Start the process of making bc/dc work on Windows
This requires some code to make things match POSIX and especially making
inline an empty string because Microsoft's compiler is picky about
functions marked inline.
-rw-r--r-- | .gitattributes | 3 | ||||
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | bc.sln | 31 | ||||
-rw-r--r-- | bc.vcxproj | 260 | ||||
-rw-r--r-- | bc.vcxproj.filters | 182 | ||||
-rw-r--r-- | bcl.sln | 31 | ||||
-rw-r--r-- | bcl.vcxproj | 161 | ||||
-rw-r--r-- | bcl.vcxproj.filters | 96 | ||||
-rw-r--r-- | gen/bc_help.txt | 13 | ||||
-rw-r--r-- | gen/dc_help.txt | 11 | ||||
-rw-r--r-- | gen/strgen.c | 56 | ||||
-rw-r--r-- | include/bcl.h | 102 | ||||
-rw-r--r-- | include/num.h | 3 | ||||
-rw-r--r-- | include/status.h | 59 | ||||
-rw-r--r-- | include/version.h | 2 | ||||
-rw-r--r-- | include/vm.h | 19 | ||||
-rw-r--r-- | src/args.c | 2 | ||||
-rw-r--r-- | src/file.c | 3 | ||||
-rw-r--r-- | src/main.c | 5 | ||||
-rw-r--r-- | src/num.c | 2 | ||||
-rw-r--r-- | src/program.c | 2 | ||||
-rw-r--r-- | src/rand.c | 36 | ||||
-rw-r--r-- | src/read.c | 20 | ||||
-rw-r--r-- | src/vm.c | 79 |
24 files changed, 1077 insertions, 105 deletions
diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..22d6e60b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +*.vcxproj eol=crlf +*.vcxproj.filters eol=crlf +*.sln eol= crlf @@ -68,3 +68,7 @@ core.* cscope*.out tags + +*.vcxproj.user +Debug/* +Release/* @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31129.286 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bc", "bc.vcxproj", "{D5086CFE-052C-4742-B005-E05DB983BBA2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D5086CFE-052C-4742-B005-E05DB983BBA2}.Debug|x64.ActiveCfg = Debug|x64 + {D5086CFE-052C-4742-B005-E05DB983BBA2}.Debug|x64.Build.0 = Debug|x64 + {D5086CFE-052C-4742-B005-E05DB983BBA2}.Debug|x86.ActiveCfg = Debug|Win32 + {D5086CFE-052C-4742-B005-E05DB983BBA2}.Debug|x86.Build.0 = Debug|Win32 + {D5086CFE-052C-4742-B005-E05DB983BBA2}.Release|x64.ActiveCfg = Release|x64 + {D5086CFE-052C-4742-B005-E05DB983BBA2}.Release|x64.Build.0 = Release|x64 + {D5086CFE-052C-4742-B005-E05DB983BBA2}.Release|x86.ActiveCfg = Release|Win32 + {D5086CFE-052C-4742-B005-E05DB983BBA2}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7869B1FB-A7C4-4FCF-8B99-F696DB2765EC} + EndGlobalSection +EndGlobal diff --git a/bc.vcxproj b/bc.vcxproj new file mode 100644 index 00000000..47d92a10 --- /dev/null +++ b/bc.vcxproj @@ -0,0 +1,260 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" 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"> + <VCProjectVersion>16.0</VCProjectVersion> + <ProjectGuid>{D5086CFE-052C-4742-B005-E05DB983BBA2}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + </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" /> + </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" /> + </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" /> + </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" /> + </ImportGroup> + <ItemGroup> + <CustomBuild Include="gen\strgen.c"> + <Message>Building strgen</Message> + <Command>CL /Fo:$(Configuration)\$(ProjectName)\ /Fe:$(Configuration)\$(ProjectName)\strgen.exe gen\strgen.c</Command> + <Inputs>gen\strgen.c</Inputs> + <Outputs>$(Configuration)\$(ProjectName)\strgen.exe</Outputs> + </CustomBuild> + <CustomBuild Include="gen\lib.bc"> + <Message>Generating $(Configuration)\$(ProjectName)/lib.c</Message> + <Command>START $(Configuration)\$(ProjectName)/strgen gen\lib.bc $(Configuration)\$(ProjectName)/lib.c bc_lib bc_lib_name BC_ENABLED 1</Command> + <Inputs>$(Configuration)\$(ProjectName)\strgen.exe;gen\lib.bc</Inputs> + <Outputs>$(Configuration)\$(ProjectName)\lib.c</Outputs> + </CustomBuild> + <CustomBuild Include="gen\lib2.bc"> + <Message>Generating $(Configuration)\$(ProjectName)/lib2.c</Message> + <Command>START $(Configuration)\$(ProjectName)/strgen gen\lib2.bc $(Configuration)\$(ProjectName)/lib2.c bc_lib2 bc_lib2_name BC_ENABLED 1</Command> + <Inputs>$(Configuration)\$(ProjectName)\strgen.exe;gen\lib2.bc</Inputs> + <Outputs>$(Configuration)\$(ProjectName)\lib2.c</Outputs> + </CustomBuild> + <CustomBuild Include="gen\bc_help.txt"> + <Message>Generating $(Configuration)\$(ProjectName)/bc_help.c</Message> + <Command>START $(Configuration)\$(ProjectName)/strgen gen\bc_help.txt $(Configuration)\$(ProjectName)\bc_help.c bc_help "" BC_ENABLED</Command> + <Inputs>$(Configuration)\$(ProjectName)\strgen.exe;gen\bc_help.txt</Inputs> + <Outputs>$(Configuration)\$(ProjectName)\bc_help.c</Outputs> + </CustomBuild> + <CustomBuild Include="gen\dc_help.txt"> + <Message>Generating $(Configuration)\$(ProjectName)/dc_help.c</Message> + <Command>START $(Configuration)\$(ProjectName)/strgen gen\dc_help.txt $(Configuration)\$(ProjectName)\dc_help.c dc_help "" DC_ENABLED</Command> + <Inputs>$(Configuration)\$(ProjectName)\strgen.exe;gen\dc_help.txt</Inputs> + <Outputs>$(Configuration)\$(ProjectName)\dc_help.c</Outputs> + </CustomBuild> + </ItemGroup> + <PropertyGroup> + <CustomBuildBeforeTargets>ClCompile</CustomBuildBeforeTargets> + </PropertyGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</OutDir> + <IntDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</IntDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</OutDir> + <IntDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</IntDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</OutDir> + <IntDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</IntDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</OutDir> + <IntDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</IntDir> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_ENABLE_PROMPT=1;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;EXECSUFFIX=.exe;BC_BUILD_TYPE=HN</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> + <WarningLevel>Level3</WarningLevel> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <Optimization>Disabled</Optimization> + <ExceptionHandling>false</ExceptionHandling> + <AdditionalOptions>/W3 %(AdditionalOptions)</AdditionalOptions> + </ClCompile> + <Link> + <TargetMachine>MachineX86</TargetMachine> + <GenerateDebugInformation>true</GenerateDebugInformation> + <SubSystem>Console</SubSystem> + <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;bcrypt.lib;ucrt.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_ENABLE_PROMPT=1;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;EXECSUFFIX=.exe;BUILD_TYPE=HN</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <WarningLevel>Level3</WarningLevel> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <Optimization>MaxSpeed</Optimization> + <ExceptionHandling>false</ExceptionHandling> + <AdditionalOptions>/W3 %(AdditionalOptions)</AdditionalOptions> + </ClCompile> + <Link> + <TargetMachine>MachineX86</TargetMachine> + <GenerateDebugInformation>false</GenerateDebugInformation> + <SubSystem>Console</SubSystem> + <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;bcrypt.lib;ucrt.lib;%(AdditionalDependencies)</AdditionalDependencies> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_ENABLE_PROMPT=1;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;EXECSUFFIX=.exe;BUILD_TYPE=HN</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> + <WarningLevel>Level3</WarningLevel> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <Optimization>Disabled</Optimization> + <ExceptionHandling>false</ExceptionHandling> + <AdditionalOptions>/W3 %(AdditionalOptions)</AdditionalOptions> + </ClCompile> + <Link> + <TargetMachine>MachineX64</TargetMachine> + <GenerateDebugInformation>true</GenerateDebugInformation> + <SubSystem>Console</SubSystem> + <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;bcrypt.lib;ucrt.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + <PostBuildEvent> + <Command>copy /b "$(SolutionDir)\$(Configuration)\$(ProjectName)\bc.exe" "$(SolutionDir)\$(Configuration)\$(ProjectName)\dc.exe"</Command> + </PostBuildEvent> + <PostBuildEvent> + <Message>Copying bc to dc...</Message> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_ENABLE_PROMPT=1;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=0;EXECSUFFIX=.exe;BUILD_TYPE=HN</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <WarningLevel>Level3</WarningLevel> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <Optimization>MaxSpeed</Optimization> + <ExceptionHandling>false</ExceptionHandling> + <AdditionalOptions>/W3 %(AdditionalOptions)</AdditionalOptions> + <BasicRuntimeChecks>Default</BasicRuntimeChecks> + </ClCompile> + <Link> + <TargetMachine>MachineX64</TargetMachine> + <GenerateDebugInformation>false</GenerateDebugInformation> + <SubSystem>Console</SubSystem> + <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;bcrypt.lib;ucrt.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="$(Configuration)\$(ProjectName)\lib.c" /> + <ClCompile Include="$(Configuration)\$(ProjectName)\lib2.c" /> + <ClCompile Include="$(Configuration)\$(ProjectName)\bc_help.c" /> + <ClCompile Include="$(Configuration)\$(ProjectName)\dc_help.c" /> + <ClCompile Include="src\args.c" /> + <ClCompile Include="src\bc.c" /> + <ClCompile Include="src\bc_lex.c" /> + <ClCompile Include="src\bc_parse.c" /> + <ClCompile Include="src\data.c" /> + <ClCompile Include="src\dc.c" /> + <ClCompile Include="src\dc_lex.c" /> + <ClCompile Include="src\dc_parse.c" /> + <ClCompile Include="src\file.c" /> + <ClCompile Include="src\history.c" /> + <ClCompile Include="src\lang.c" /> + <ClCompile Include="src\lex.c" /> + <ClCompile Include="src\main.c" /> + <ClCompile Include="src\num.c" /> + <ClCompile Include="src\opt.c" /> + <ClCompile Include="src\parse.c" /> + <ClCompile Include="src\program.c" /> + <ClCompile Include="src\rand.c" /> + <ClCompile Include="src\read.c" /> + <ClCompile Include="src\vector.c" /> + <ClCompile Include="src\vm.c" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="include\args.h" /> + <ClInclude Include="include\bc.h" /> + <ClInclude Include="include\bcl.h" /> + <ClInclude Include="include\dc.h" /> + <ClInclude Include="include\file.h" /> + <ClInclude Include="include\history.h" /> + <ClInclude Include="include\lang.h" /> + <ClInclude Include="include\lex.h" /> + <ClInclude Include="include\library.h" /> + <ClInclude Include="include\num.h" /> + <ClInclude Include="include\opt.h" /> + <ClInclude Include="include\parse.h" /> + <ClInclude Include="include\program.h" /> + <ClInclude Include="include\rand.h" /> + <ClInclude Include="include\read.h" /> + <ClInclude Include="include\status.h" /> + <ClInclude Include="include\vector.h" /> + <ClInclude Include="include\version.h" /> + <ClInclude Include="include\vm.h" /> + </ItemGroup> + <ItemGroup> + <Text Include="gen\bc_help.txt" /> + <Text Include="gen\dc_help.txt" /> + </ItemGroup> + <ItemGroup> + <None Include="gen\lib.bc" /> + <None Include="gen\lib2.bc" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/bc.vcxproj.filters b/bc.vcxproj.filters new file mode 100644 index 00000000..141ecb80 --- /dev/null +++ b/bc.vcxproj.filters @@ -0,0 +1,182 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="src\args.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\bc.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\bc_lex.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\bc_parse.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\data.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\dc.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\dc_lex.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\dc_parse.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\file.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\history.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\lang.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\lex.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\main.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\num.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\opt.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\parse.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\program.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\rand.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\read.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\vector.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\vm.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="gen\lib.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="gen\lib2.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="gen\bc_help.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="gen\dc_help.c"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="include\args.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\bc.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\bcl.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\dc.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\file.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\history.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\lang.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\lex.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\library.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\num.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\opt.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\parse.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\program.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\rand.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\read.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\status.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\vector.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\version.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\vm.h"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> + <ItemGroup> + <CustomBuild Include="gen\strgen.c"> + <Filter>Source Files</Filter> + </CustomBuild> + <CustomBuild Include="gen\lib.bc" /> + <CustomBuild Include="gen\lib2.bc" /> + <CustomBuild Include="gen\bc_help.txt" /> + <CustomBuild Include="gen\dc_help.txt" /> + <CustomBuild Include="gen\lib.bc" /> + <CustomBuild Include="gen\lib2.bc" /> + <CustomBuild Include="gen\bc_help.txt" /> + <CustomBuild Include="gen\dc_help.txt" /> + </ItemGroup> + <ItemGroup> + <Text Include="gen\bc_help.txt"> + <Filter>Resource Files</Filter> + </Text> + <Text Include="gen\dc_help.txt"> + <Filter>Resource Files</Filter> + </Text> + </ItemGroup> + <ItemGroup> + <None Include="gen\lib.bc"> + <Filter>Resource Files</Filter> + </None> + <None Include="gen\lib2.bc"> + <Filter>Resource Files</Filter> + </None> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/bcl.sln b/bcl.sln new file mode 100644 index 00000000..77009a43 --- /dev/null +++ b/bcl.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31129.286 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bcl", "bcl.vcxproj", "{D2CC3DCF-7919-4DEF-839D-E9B897EC3E8E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D2CC3DCF-7919-4DEF-839D-E9B897EC3E8E}.Debug|x64.ActiveCfg = Debug|x64 + {D2CC3DCF-7919-4DEF-839D-E9B897EC3E8E}.Debug|x64.Build.0 = Debug|x64 + {D2CC3DCF-7919-4DEF-839D-E9B897EC3E8E}.Debug|x86.ActiveCfg = Debug|Win32 + {D2CC3DCF-7919-4DEF-839D-E9B897EC3E8E}.Debug|x86.Build.0 = Debug|Win32 + {D2CC3DCF-7919-4DEF-839D-E9B897EC3E8E}.Release|x64.ActiveCfg = Release|x64 + {D2CC3DCF-7919-4DEF-839D-E9B897EC3E8E}.Release|x64.Build.0 = Release|x64 + {D2CC3DCF-7919-4DEF-839D-E9B897EC3E8E}.Release|x86.ActiveCfg = Release|Win32 + {D2CC3DCF-7919-4DEF-839D-E9B897EC3E8E}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {591735E0-C314-4BFF-A595-E9999B49CB25} + EndGlobalSection +EndGlobal diff --git a/bcl.vcxproj b/bcl.vcxproj new file mode 100644 index 00000000..3b79c8b9 --- /dev/null +++ b/bcl.vcxproj @@ -0,0 +1,161 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" 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"> + <VCProjectVersion>16.0</VCProjectVersion> + <ProjectGuid>{D2CC3DCF-7919-4DEF-839D-E9B897EC3E8E}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + </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" /> + </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" /> + </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" /> + </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" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</OutDir> + <IntDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</IntDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</OutDir> + <IntDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</IntDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</OutDir> + <IntDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</IntDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</OutDir> + <IntDir>$(SolutionDir)\$(Configuration)\$(ProjectName)\</IntDir> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_ENABLE_PROMPT=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=1</PreprocessorDefinitions> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> + <WarningLevel>Level3</WarningLevel> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <Optimization>Disabled</Optimization> + <AdditionalIncludeDirectories>$(SolutionDir)\include</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <TargetMachine>MachineX86</TargetMachine> + <GenerateDebugInformation>true</GenerateDebugInformation> + <SubSystem>Windows</SubSystem> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_ENABLE_PROMPT=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=1</PreprocessorDefinitions> + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> + <WarningLevel>Level3</WarningLevel> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <AdditionalIncludeDirectories>$(SolutionDir)\include</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <TargetMachine>MachineX86</TargetMachine> + <GenerateDebugInformation>true</GenerateDebugInformation> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_ENABLE_PROMPT=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=1</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\include</AdditionalIncludeDirectories> + </ClCompile> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);BC_ENABLED=1;DC_ENABLED=1;BC_ENABLE_EXTRA_MATH=1;BC_ENABLE_HISTORY=0;BC_ENABLE_NLS=0;BC_ENABLE_PROMPT=0;BC_DEBUG_CODE=0;BC_ENABLE_LIBRARY=1</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(SolutionDir)\include</AdditionalIncludeDirectories> + </ClCompile> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="src\data.c" /> + <ClCompile Include="src\library.c" /> + <ClCompile Include="src\num.c" /> + <ClCompile Include="src\rand.c" /> + <ClCompile Include="src\vector.c" /> + <ClCompile Include="src\vm.c" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="include\args.h" /> + <ClInclude Include="include\bc.h" /> + <ClInclude Include="include\bcl.h" /> + <ClInclude Include="include\dc.h" /> + <ClInclude Include="include\file.h" /> + <ClInclude Include="include\history.h" /> + <ClInclude Include="include\lang.h" /> + <ClInclude Include="include\lex.h" /> + <ClInclude Include="include\library.h" /> + <ClInclude Include="include\num.h" /> + <ClInclude Include="include\opt.h" /> + <ClInclude Include="include\parse.h" /> + <ClInclude Include="include\program.h" /> + <ClInclude Include="include\rand.h" /> + <ClInclude Include="include\read.h" /> + <ClInclude Include="include\status.h" /> + <ClInclude Include="include\vector.h" /> + <ClInclude Include="include\version.h" /> + <ClInclude Include="include\vm.h" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/bcl.vcxproj.filters b/bcl.vcxproj.filters new file mode 100644 index 00000000..f75e0331 --- /dev/null +++ b/bcl.vcxproj.filters @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="src\data.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\library.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\num.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\rand.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\vector.c"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="src\vm.c"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="include\args.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\bc.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\bcl.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\dc.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\file.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\history.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\lang.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\lex.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\library.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\num.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\opt.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\parse.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\program.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\rand.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\read.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\status.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\vector.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\version.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="include\vm.h"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/gen/bc_help.txt b/gen/bc_help.txt index 0da9021e..c9b0482d 100644 --- a/gen/bc_help.txt +++ b/gen/bc_help.txt @@ -36,7 +36,8 @@ usage: %s [options] [file...] bc is a command-line, arbitrary-precision calculator with a Turing-complete -language. For details, use `man %s`. +language. For details, use `man %s` or see the online documentation at +https://git.yzena.com/gavin/bc/src/tag/%s/manuals/bc/%s.1.md. This bc is compatible with both the GNU bc and the POSIX bc spec. See the GNU bc manual (https://www.gnu.org/software/bc/manual/bc.html) and bc spec @@ -56,7 +57,7 @@ This bc has three differences to the GNU bc: scripts to work while somewhat preserving expected behavior (versus C) and making parsing easier. 3) This bc has many more extensions than the GNU bc does. For details, see the - man page. + man page or online documentation. This bc also implements the dot (.) extension of the BSD bc. @@ -74,8 +75,8 @@ Options: -g --global-stacks Turn scale, ibase, and obase into stacks. This makes the value of each be - be restored on returning from functions. See the man page for more - details. + be restored on returning from functions. See the man page or online + documentation for more details. -h --help @@ -96,8 +97,8 @@ Options: e(expr) = raises e to the power of expr j(n, x) = Bessel function of integer order n of x - This bc may load more functions with these options. See the manpage for - details. + This bc may load more functions with these options. See the manpage or + online documentation for details. -P --no-prompt diff --git a/gen/dc_help.txt b/gen/dc_help.txt index 9fc8ee11..c573b967 100644 --- a/gen/dc_help.txt +++ b/gen/dc_help.txt @@ -36,12 +36,13 @@ usage: %s [options] [file...] dc is a reverse-polish notation command-line calculator which supports unlimited -precision arithmetic. For details, use `man %s`. +precision arithmetic. For details, use `man %s` or see the online documentation +at https://git.yzena.com/gavin/bc/src/tag/%s/manuals/bc/%s.1.md. -This dc is (mostly) compatible with the FreeBSD dc and the GNU dc. See the -FreeBSD man page (https://www.unix.com/man-page/FreeBSD/1/dc/) and the GNU dc -manual (https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html) for -details. +This dc is (mostly) compatible with the OpenBSD dc and the GNU dc. See the +OpenBSD man page (http://man.openbsd.org/OpenBSD-current/man1/dc.1) and the GNU +dc manual (https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html) +for details. This dc has a few differences from the two above: diff --git a/gen/strgen.c b/gen/strgen.c index 2d133ba5..a186eeec 100644 --- a/gen/strgen.c +++ b/gen/strgen.c @@ -40,7 +40,9 @@ #include <errno.h> +#ifndef _WIN32 #include <libgen.h> +#endif // _WIN32 static const char* const bc_gen_header = "// Copyright (c) 2018-2021 Gavin D. Howard and contributors.\n" @@ -60,6 +62,54 @@ static const char* const bc_gen_name_extern = "extern const char %s[];\n\n"; #define MAX_WIDTH (74) +void open_file(FILE** f, const char* filename, const char* mode) { + +#ifndef _WIN32 + *f = fopen(filename, mode); +#else // _WIN32 + *f = NULL; + fopen_s(f, filename, mode); +#endif // _WIN32 +} + +int output_label(FILE* out, const char* label, const char* name) { + +#ifndef _WIN32 + return fprintf(out, bc_gen_label, label, name); +#else // _WIN32 + + size_t i, count = 0, len = strlen(name); + char* buf; + int ret; + + for (i = 0; i < len; ++i) { + count += (name[i] == '\\'); + } + + buf = (char*) malloc(len + 1 + count); + if (buf == NULL) return -1; + + count = 0; + + for (i = 0; i < len; ++i) { + buf[i + count] = name[i]; + if (name[i] == '\\') { + count += 1; + buf[i + count] = name[i]; + } + } + + buf[i + count] = '\0'; + + ret = fprintf(out, bc_gen_label, label, buf); + + free(buf); + + return ret; + +#endif // _WIN32 +} + int main(int argc, char *argv[]) { FILE *in, *out; @@ -82,17 +132,17 @@ int main(int argc, char *argv[]) { remove_tabs = (argc > 6); - in = fopen(argv[1], "r"); + open_file(&in, argv[1], "r"); if (!in) return INVALID_INPUT_FILE; - out = fopen(argv[2], "w"); + open_file(&out, argv[2], "w"); if (!out) goto out_err; if (fprintf(out, bc_gen_header, argv[1]) < 0) goto err; if (has_label && fprintf(out, bc_gen_label_extern, label) < 0) goto err; if (fprintf(out, bc_gen_name_extern, name) < 0) goto err; if (has_define && fprintf(out, bc_gen_ifdef, define) < 0) goto err; - if (has_label && fprintf(out, bc_gen_label, label, argv[1]) < 0) goto err; + if (has_label && output_label(out, label, argv[1]) < 0) goto err; if (fprintf(out, bc_gen_name, name) < 0) goto err; c = count = slashes = 0; diff --git a/include/bcl.h b/include/bcl.h index 3c67beb2..3efb028b 100644 --- a/include/bcl.h +++ b/include/bcl.h @@ -36,6 +36,13 @@ #ifndef BC_BCL_H #define BC_BCL_H +#ifdef _WIN32 +#include <Windows.h> +#include <BaseTsd.h> +#include <stdio.h> +#include <io.h> +#endif // _WIN32 + #include <stdbool.h> #include <stdlib.h> #include <limits.h> @@ -74,6 +81,99 @@ typedef uint32_t BclRandInt; #error BC_LONG_BIT must be at least 32 #endif // BC_LONG_BIT >= 64 +#define BC_UNUSED(e) ((void) (e)) + +#ifndef BC_LIKELY +#define BC_LIKELY(e) (e) +#endif // BC_LIKELY + +#ifndef BC_UNLIKELY +#define BC_UNLIKELY(e) (e) +#endif // BC_UNLIKELY + +#define BC_ERR(e) BC_UNLIKELY(e) +#define BC_NO_ERR(s) BC_LIKELY(s) + +#ifndef BC_DEBUG_CODE +#define BC_DEBUG_CODE (0) +#endif // BC_DEBUG_CODE + +#if __STDC_VERSION__ >= 201100L +#include <stdnoreturn.h> +#define BC_NORETURN _Noreturn +#else // __STDC_VERSION__ +#define BC_NORETURN +#define BC_MUST_RETURN +#endif // __STDC_VERSION__ + +#if defined(__clang__) || defined(__GNUC__) +#if defined(__has_attribute) +#if __has_attribute(fallthrough) +#define BC_FALLTHROUGH __attribute__((fallthrough)); +#else // __has_attribute(fallthrough) +#define BC_FALLTHROUGH +#endif // __has_attribute(fallthrough) +#else // defined(__has_attribute) +#define BC_FALLTHROUGH +#endif // defined(__has_attribute) +#else // defined(__clang__) || defined(__GNUC__) +#define BC_FALLTHROUGH +#endif // defined(__clang__) || defined(__GNUC__) + +// Workarounds for AIX's POSIX incompatibility. +#ifndef SIZE_MAX +#define SIZE_MAX __SIZE_MAX__ +#endif // SIZE_MAX +#ifndef UINTMAX_C +#define UINTMAX_C __UINTMAX_C +#endif // UINTMAX_C +#ifndef UINT32_C +#define UINT32_C __UINT32_C +#endif // UINT32_C +#ifndef UINT_FAST32_MAX +#define UINT_FAST32_MAX __UINT_FAST32_MAX__ +#endif // UINT_FAST32_MAX +#ifndef UINT16_MAX +#define UINT16_MAX __UINT16_MAX__ +#endif // UINT16_MAX +#ifndef SIG_ATOMIC_MAX +#define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__ +#endif // SIG_ATOMIC_MAX + +// Windows has deprecated isatty() and the rest of these. +// Or doesn't have them. +#ifdef _WIN32 + +// This one is special. Windows did not like me defining an +// inline function that was not given a definition in a header +// file. This suppresses that by making inline functions non-inline. +#define inline + +#define restrict __restrict +#define strdup _strdup +#define write(f, b, s) _write((f), (b), (unsigned int) (s)) +#define read(f, b, s) _read((f), (b), (unsigned int) (s)) +#define close _close +#define open(f, n, m) _sopen_s(f, n, m, _SH_DENYNO, _S_IREAD | _S_IWRITE) +#define sigjmp_buf jmp_buf +#define sigsetjmp(j, s) setjmp(j) +#define siglongjmp longjmp +#define isatty _isatty +#define STDIN_FILENO (0) +#define STDOUT_FILENO (1) +#define STDERR_FILENO (2) +#define ssize_t SSIZE_T +#define S_ISDIR(m) ((m) & _S_IFDIR) +#define O_RDONLY _O_RDONLY +#define stat _stat +#define fstat _fstat +#define BC_FILE_SEP '\\' + +#else // _WIN32 +#define BC_FILE_SEP '/' +#endif // _WIN32 + +#if BC_ENABLE_LIBRARY typedef enum BclError { @@ -181,4 +281,6 @@ BclNumber bcl_rand_seed2num(void); BclRandInt bcl_rand_int(void); BclRandInt bcl_rand_bounded(BclRandInt bound); +#endif // BC_ENABLE_LIBRARY + #endif // BC_BCL_H diff --git a/include/num.h b/include/num.h index 2104f8b8..8beea001 100644 --- a/include/num.h +++ b/include/num.h @@ -172,9 +172,10 @@ struct BcRNG; #endif // BC_DEBUG_CODE typedef void (*BcNumBinaryOp)(BcNum*, BcNum*, BcNum*, size_t); +typedef void (*BcNumBinOp)(BcNum*, BcNum*, BcNum* restrict, size_t); typedef size_t (*BcNumBinaryOpReq)(const BcNum*, const BcNum*, size_t); typedef void (*BcNumDigitOp)(size_t, size_t, bool); -typedef void (*BcNumShiftAddOp)(BcDig*, const BcDig*, size_t); +typedef void (*BcNumShiftAddOp)(BcDig* restrict, const BcDig* restrict, size_t); void bc_num_init(BcNum *restrict n, size_t req); void bc_num_setup(BcNum *restrict n, BcDig *restrict num, size_t cap); diff --git a/include/status.h b/include/status.h index cf41a3ce..be235649 100644 --- a/include/status.h +++ b/include/status.h @@ -150,63 +150,4 @@ typedef enum BcErr { #define BC_ERR_IDX_WARN (BC_ERR_IDX_NELEMS) #endif // BC_ENABLED -#define BC_UNUSED(e) ((void) (e)) - -#ifndef BC_LIKELY -#define BC_LIKELY(e) (e) -#endif // BC_LIKELY - -#ifndef BC_UNLIKELY -#define BC_UNLIKELY(e) (e) -#endif // BC_UNLIKELY - -#define BC_ERR(e) BC_UNLIKELY(e) -#define BC_NO_ERR(s) BC_LIKELY(s) - -#ifndef BC_DEBUG_CODE -#define BC_DEBUG_CODE (0) -#endif // BC_DEBUG_CODE - -#if __STDC_VERSION__ >= 201100L -#include <stdnoreturn.h> -#define BC_NORETURN _Noreturn -#else // __STDC_VERSION__ -#define BC_NORETURN -#define BC_MUST_RETURN -#endif // __STDC_VERSION__ - -#if defined(__clang__) || defined(__GNUC__) -#if defined(__has_attribute) -#if __has_attribute(fallthrough) -#define BC_FALLTHROUGH __attribute__((fallthrough)); -#else // __has_attribute(fallthrough) -#define BC_FALLTHROUGH -#endif // __has_attribute(fallthrough) -#else // defined(__has_attribute) -#define BC_FALLTHROUGH -#endif // defined(__has_attribute) -#else // defined(__clang__) || defined(__GNUC__) -#define BC_FALLTHROUGH -#endif // defined(__clang__) || defined(__GNUC__) - -// Workarounds for AIX's POSIX incompatibility. -#ifndef SIZE_MAX -#define SIZE_MAX __SIZE_MAX__ -#endif // SIZE_MAX -#ifndef UINTMAX_C -#define UINTMAX_C __UINTMAX_C -#endif // UINTMAX_C -#ifndef UINT32_C -#define UINT32_C __UINT32_C -#endif // UINT32_C -#ifndef UINT_FAST32_MAX -#define UINT_FAST32_MAX __UINT_FAST32_MAX__ -#endif // UINT_FAST32_MAX -#ifndef UINT16_MAX -#define UINT16_MAX __UINT16_MAX__ -#endif // UINT16_MAX -#ifndef SIG_ATOMIC_MAX -#define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__ -#endif // SIG_ATOMIC_MAX - #endif // BC_STATUS_H diff --git a/include/version.h b/include/version.h index cb35c781..c1bcb135 100644 --- a/include/version.h +++ b/include/version.h @@ -38,4 +38,4 @@ #define VERSION 3.4.0 -#endif // BC_VERSION_H
\ No newline at end of file +#endif // BC_VERSION_H diff --git a/include/vm.h b/include/vm.h index 30938493..8d726ffe 100644 --- a/include/vm.h +++ b/include/vm.h @@ -78,22 +78,27 @@ #ifndef MAINEXEC #define MAINEXEC bc -#endif +#endif // MAINEXEC +#ifndef _WIN32 #ifndef EXECPREFIX #define EXECPREFIX -#endif +#endif // EXECPREFIX +#else // _WIN32 +#undef EXECPREFIX +#endif // _WIN32 #define GEN_STR(V) #V #define GEN_STR2(V) GEN_STR(V) #define BC_VERSION GEN_STR2(VERSION) -#define BC_EXECPREFIX GEN_STR2(EXECPREFIX) #define BC_MAINEXEC GEN_STR2(MAINEXEC) +#define BC_BUILD_TYPE GEN_STR2(BUILD_TYPE) -// Windows has deprecated isatty(). -#ifdef _WIN32 -#define isatty _isatty +#ifndef _WIN32 +#define BC_EXECPREFIX GEN_STR2(EXECPREFIX) +#else // _WIN32 +#define BC_EXECPREFIX "" #endif // _WIN32 #if !BC_ENABLE_LIBRARY @@ -435,6 +440,8 @@ size_t bc_vm_growSize(size_t a, size_t b); void* bc_vm_malloc(size_t n); void* bc_vm_realloc(void *ptr, size_t n); char* bc_vm_strdup(const char *str); +char* bc_vm_getenv(const char* var); +void bc_vm_getenvFree(char* var); #if BC_DEBUG_CODE void bc_vm_jmp(const char *f); @@ -39,7 +39,9 @@ #include <stdlib.h> #include <string.h> +#ifndef _WIN32 #include <unistd.h> +#endif // _WIN32 #include <vector.h> #include <read.h> @@ -36,7 +36,10 @@ #include <assert.h> #include <errno.h> #include <string.h> + +#ifndef _WIN32 #include <unistd.h> +#endif // _WIN32 #include <file.h> #include <vm.h> @@ -38,7 +38,10 @@ #include <string.h> #include <locale.h> + +#ifndef _WIN32 #include <libgen.h> +#endif // _WIN32 #include <setjmp.h> @@ -55,7 +58,7 @@ int main(int argc, char *argv[]) { vm.locale = setlocale(LC_ALL, ""); - name = strrchr(argv[0], '/'); + name = strrchr(argv[0], BC_FILE_SEP); vm.name = (name == NULL) ? argv[0] : name + 1; if (strlen(vm.name) > len) vm.name += len; @@ -1389,7 +1389,7 @@ static void bc_num_right(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) { #endif // BC_ENABLE_EXTRA_MATH static void bc_num_binary(BcNum *a, BcNum *b, BcNum *c, size_t scale, - BcNumBinaryOp op, size_t req) + BcNumBinOp op, size_t req) { BcNum *ptr_a, *ptr_b, num2; bool init = false; diff --git a/src/program.c b/src/program.c index 81d0746e..82735083 100644 --- a/src/program.c +++ b/src/program.c @@ -1468,7 +1468,7 @@ static void bc_program_nquit(BcProgram *p, uchar inst) { for (i = 0; val && i < p->tail_calls.len; ++i) { size_t calls = *((size_t*) bc_vec_item_rev(&p->tail_calls, i)) + 1; if (calls >= val) val = 0; - else val -= calls; + else val -= (BcBigDig) calls; } if (i == p->stack.len) { @@ -44,7 +44,13 @@ #include <string.h> #include <time.h> #include <fcntl.h> + +#ifndef _WIN32 #include <unistd.h> +#else // _WIN32 +#include <Windows.h> +#include <bcrypt.h> +#endif // _WIN32 #include <status.h> #include <rand.h> @@ -140,7 +146,8 @@ static void bc_rand_copy(BcRNGData *d, BcRNGData *s) { else if (!BC_RAND_NOTMODIFIED(s)) bc_rand_clearModified(d); } -static ulong bc_rand_frand(void *ptr) { +#ifndef _WIN32 +static ulong bc_rand_frand(void* ptr) { ulong buf[1]; int fd; @@ -148,14 +155,31 @@ static ulong bc_rand_frand(void *ptr) { assert(ptr != NULL); - fd = *((int*) ptr); + fd = *((int*)ptr); nread = read(fd, buf, sizeof(ulong)); if (BC_ERR(nread != sizeof(ulong))) bc_vm_fatalError(BC_ERR_FATAL_IO_ERR); - return *((ulong*) buf); + return *((ulong*)buf); } +#else // _WIN32 +static ulong bc_rand_winrand(void* ptr) { + + ulong buf[1]; + NTSTATUS s; + + BC_UNUSED(ptr); + + buf[0] = 0; + + s = BCryptGenRandom(NULL, (char*) buf, sizeof(ulong), BCRYPT_USE_SYSTEM_PREFERRED_RNG); + + if (BC_ERR(!BCRYPT_SUCCESS(s))) buf[0] = 0; + + return buf[0]; +} +#endif // _WIN32 static ulong bc_rand_rand(void *ptr) { @@ -252,10 +276,11 @@ static void bc_rand_seedZeroes(BcRNG *r, BcRNGData *rng, size_t idx) { void bc_rand_srand(BcRNGData *rng) { - int fd; + int fd = 0; BC_SIG_LOCK; +#ifndef _WIN32 fd = open("/dev/urandom", O_RDONLY); if (BC_NO_ERR(fd >= 0)) { @@ -271,6 +296,9 @@ void bc_rand_srand(BcRNGData *rng) { close(fd); } } +#else // _WIN32 + bc_rand_fill(rng, bc_rand_winrand, NULL); +#endif // _WIN32 while (BC_ERR(BC_RAND_ZERO(rng))) bc_rand_fill(rng, bc_rand_rand, NULL); @@ -43,13 +43,30 @@ #include <fcntl.h> #include <sys/stat.h> + +#ifndef _WIN32 #include <unistd.h> +#endif // _WIN32 #include <read.h> #include <history.h> #include <program.h> #include <vm.h> +static int bc_read_open(const char* path, int mode) { + + int fd; + +#ifndef _WIN32 + fd = open(path, mode); +#else // _WIN32 + fd = -1; + open(&fd, path, mode); +#endif + + return fd; +} + static bool bc_read_binary(const char *buf, size_t size) { size_t i; @@ -194,7 +211,8 @@ void bc_read_file(const char *path, char **buf) { assert(path != NULL); - fd = open(path, O_RDONLY); + fd = bc_read_open(path, O_RDONLY); + if (BC_ERR(fd < 0)) bc_vm_verr(BC_ERR_FATAL_FILE_ERR, path); if (BC_ERR(fstat(fd, &pstat) == -1)) goto malloc_err; @@ -56,6 +56,7 @@ #endif // _WIN32 +#include <status.h> #include <vector.h> #include <args.h> #include <vm.h> @@ -119,6 +120,31 @@ static void bc_vm_sig(int sig) { if (!vm.sig_lock) BC_VM_JMP; } +static void bc_vm_sigaction(void) { +#ifndef _WIN32 + + struct sigaction sa; + + sigemptyset(&sa.sa_mask); + sa.sa_handler = bc_vm_sig; + sa.sa_flags = SA_NODEFER; + + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGQUIT, &sa, NULL); + sigaction(SIGINT, &sa, NULL); + +#if BC_ENABLE_HISTORY + if (BC_TTY) sigaction(SIGHUP, &sa, NULL); +#endif // BC_ENABLE_HISTORY + +#else // _WIN32 + + signal(SIGTERM, bc_vm_sig); + signal(SIGINT, bc_vm_sig); + +#endif // _WIN32 +} + void bc_vm_info(const char* const help) { BC_SIG_ASSERT_LOCKED; @@ -131,7 +157,8 @@ void bc_vm_info(const char* const help) { if (help) { bc_file_putchar(&vm.fout, bc_flush_none, '\n'); - bc_file_printf(&vm.fout, help, vm.name, vm.name); + bc_file_printf(&vm.fout, help, vm.name, vm.name, + BC_VERSION, BC_BUILD_TYPE); } bc_file_flush(&vm.fout, bc_flush_err); @@ -260,14 +287,19 @@ void bc_vm_handleError(BcErr e, size_t line, ...) { static void bc_vm_envArgs(const char* const env_args_name) { - char *env_args = getenv(env_args_name), *buf, *start; + char *env_args = bc_vm_getenv(env_args_name), *buf, *start; char instr = '\0'; BC_SIG_ASSERT_LOCKED; if (env_args == NULL) return; + // Windows already allocates, so we don't need to. +#ifndef _WIN32 start = buf = vm.env_args_buffer = bc_vm_strdup(env_args); +#else // _WIN32 + start = buf = vm.env_args_buffer = env_args; +#endif // _WIN32 assert(buf != NULL); @@ -320,7 +352,7 @@ static void bc_vm_envArgs(const char* const env_args_name) { static size_t bc_vm_envLen(const char *var) { - char *lenv = getenv(var); + char *lenv = bc_vm_getenv(var); size_t i, len = BC_NUM_PRINT_WIDTH; int num; @@ -336,6 +368,8 @@ static size_t bc_vm_envLen(const char *var) { } else len = BC_NUM_PRINT_WIDTH; + bc_vm_getenvFree(lenv); + return len; } #endif // BC_ENABLE_LIBRARY @@ -464,6 +498,26 @@ void bc_vm_putchar(int c, BcFlushType type) { #endif // BC_ENABLE_LIBRARY } +char* bc_vm_getenv(const char* var) { + + char* ret; + +#ifndef _WIN32 + ret = getenv(var); +#else // _WIN32 + _dupenv_s(&ret, NULL, var); +#endif // _WIN32 + + return ret; +} + +void bc_vm_getenvFree(char* var) { + BC_UNUSED(var); +#ifdef _WIN32 + free(var); +#endif // _WIN32 +} + #if !BC_ENABLE_LIBRARY static void bc_vm_clean(void) { @@ -853,7 +907,6 @@ void bc_vm_boot(int argc, char *argv[], const char *env_len, const char* const env_args) { int ttyin, ttyout, ttyerr; - struct sigaction sa; BC_SIG_ASSERT_LOCKED; @@ -865,17 +918,7 @@ void bc_vm_boot(int argc, char *argv[], const char *env_len, vm.flags |= (ttyin != 0 && ttyout != 0 && ttyerr != 0) ? BC_FLAG_TTY : 0; vm.flags |= ttyin && ttyout ? BC_FLAG_I : 0; - sigemptyset(&sa.sa_mask); - sa.sa_handler = bc_vm_sig; - sa.sa_flags = SA_NODEFER; - - sigaction(SIGTERM, &sa, NULL); - sigaction(SIGQUIT, &sa, NULL); - sigaction(SIGINT, &sa, NULL); - -#if BC_ENABLE_HISTORY - if (BC_TTY) sigaction(SIGHUP, &sa, NULL); -#endif // BC_ENABLE_HISTORY + bc_vm_sigaction(); bc_vm_init(); @@ -901,7 +944,11 @@ void bc_vm_boot(int argc, char *argv[], const char *env_len, #endif // BC_ENABLE_HISTORY #if BC_ENABLED - if (BC_IS_BC) vm.flags |= BC_FLAG_S * (getenv("POSIXLY_CORRECT") != NULL); + if (BC_IS_BC) { + char* var = bc_vm_getenv("POSIXLY_CORRECT"); + vm.flags |= BC_FLAG_S * (var != NULL); + bc_vm_getenvFree(var); + } #endif // BC_ENABLED bc_vm_envArgs(env_args); |