mirror of
https://github.com/Kaehvaman/OAIP.git
synced 2025-01-18 08:39:11 +04:00
clock and progressbar tests
This commit is contained in:
parent
92f7e73b20
commit
71a946ecf0
@ -1,135 +1,139 @@
|
||||
<?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>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{268761f2-af30-432d-91df-77542792a4ab}</ProjectGuid>
|
||||
<RootNamespace>clock</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</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" />
|
||||
</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" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.c" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
<?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>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{268761f2-af30-432d-91df-77542792a4ab}</ProjectGuid>
|
||||
<RootNamespace>clock</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</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" />
|
||||
</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" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\progressbar test\progressbar.c" />
|
||||
<ClCompile Include="main.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\progressbar test\progressbar.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@ -1,22 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Исходные файлы">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Файлы заголовков">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Файлы ресурсов">
|
||||
<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;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Исходные файлы">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Файлы заголовков">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Файлы ресурсов">
|
||||
<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;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\progressbar test\progressbar.c">
|
||||
<Filter>Исходные файлы</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\progressbar test\progressbar.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
64
clock/main.c
64
clock/main.c
@ -1,16 +1,50 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <Windows.h>
|
||||
|
||||
|
||||
int main() {
|
||||
int n = 10, sl = 10, last_clock = 0;
|
||||
clock_t start = clock();
|
||||
for (int i = 0; i < n; i++) {
|
||||
printf_s("%d\n", i);
|
||||
Sleep(sl);
|
||||
}
|
||||
printf_s("time = %.3lf seconds\nexpected %d seconds %lf", (double)(clock() - start) / (double)CLOCKS_PER_SEC, n * sl / 1000, 0.3300000000000000000000);
|
||||
return 0;
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <Windows.h>
|
||||
#include "../progressbar test/progressbar.h"
|
||||
|
||||
// \033[ = CSI, CSI ?25l hides the cursor, CSI ?25h shows the cursor
|
||||
// see ANSI escape code wiki for more info
|
||||
#define HIDE_CURSOR "\033[?25l"
|
||||
#define SHOW_CURSOR "\033[?25h"
|
||||
|
||||
void wait(int seconds) {
|
||||
clock_t t0 = clock();
|
||||
clock_t t1;
|
||||
while ((int)(((t1 = clock()) - t0) / CLOCKS_PER_SEC) < seconds) {
|
||||
Sleep(50);
|
||||
}
|
||||
printf(" wait for %d s is over, clock=%d", seconds, (int)t1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
#ifdef WIN32
|
||||
printf("ITS WINDOWS!\n");
|
||||
#endif
|
||||
|
||||
struct progressbar pb;
|
||||
int n = 5, sl = 1;
|
||||
printf(HIDE_CURSOR);
|
||||
progressbar_start(&pb, n * sl);
|
||||
|
||||
clock_t start = clock();
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
wait(sl);
|
||||
//printf("%d\n", i);
|
||||
progressbar_add(&pb, sl);
|
||||
}
|
||||
//progressbar_clear();
|
||||
printf(SHOW_CURSOR);
|
||||
printf("\n");
|
||||
printf_s("time = %.3lf seconds\nexpected %d seconds\n", (double)(clock() - start) / (double)CLOCKS_PER_SEC, n * sl);
|
||||
|
||||
progressbar_start(&pb, n * sl);
|
||||
for (int i = 0; i < n; i++) {
|
||||
wait(sl);
|
||||
//printf("%d\n", i);
|
||||
progressbar_add(&pb, sl);
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -44,6 +44,7 @@ int main() {
|
||||
printf("strchr_my_arr_res 's' = {%p} = '%c', index = %d\n", strchr_my_arr_res, *strchr_my_arr_res, (int)(strchr_my_arr_res - test3));
|
||||
char* strchr_my_arr_ptr = strchr_my_ptr(test3, 's');
|
||||
printf("strchr_my_arr_ptr 's' = {%p} = '%c', index = %d\n", strchr_my_arr_ptr, *strchr_my_arr_ptr, (int)(strchr_my_arr_ptr - test3));
|
||||
char dest[10];
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,66 +1,65 @@
|
||||
#include <stdio.h>
|
||||
#include "progressbar.h"
|
||||
|
||||
// see progressbar.h
|
||||
|
||||
static const unsigned progressbar_width = 70;
|
||||
|
||||
static unsigned get_to_print(unsigned current, unsigned max) {
|
||||
return progressbar_width * current / max;
|
||||
}
|
||||
|
||||
static unsigned get_percentage(unsigned current, unsigned max) {
|
||||
return 100 * current / max;
|
||||
}
|
||||
|
||||
static void progressbar_show(struct progressbar *pb) {
|
||||
unsigned to_print = get_to_print(pb->current, pb->max);
|
||||
unsigned percentage = get_percentage(pb->current, pb->max);
|
||||
|
||||
printf("\r[");
|
||||
for(unsigned i = 0; i < to_print; i++) {
|
||||
printf("#");
|
||||
}
|
||||
for(unsigned i = 0; i < progressbar_width - to_print; i++) {
|
||||
printf(" ");
|
||||
}
|
||||
printf("] %3u%%", percentage);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void progressbar_start(struct progressbar *pb, unsigned max) {
|
||||
pb->max = max;
|
||||
pb->current = 0;
|
||||
progressbar_show(pb);
|
||||
}
|
||||
|
||||
void progressbar_set(struct progressbar *pb, unsigned current) {
|
||||
unsigned old_to_print = get_to_print(pb->current, pb->max);
|
||||
unsigned old_percentage = get_percentage(pb->current, pb->max);
|
||||
unsigned to_print = get_to_print(current, pb->max);
|
||||
unsigned percentage = get_percentage(current, pb->max);
|
||||
pb->current = current;
|
||||
if(old_to_print == to_print && old_percentage == percentage) {
|
||||
return;
|
||||
}
|
||||
progressbar_show(pb);
|
||||
}
|
||||
|
||||
void progressbar_add(struct progressbar *pb, unsigned n) {
|
||||
progressbar_set(pb, pb->current + n);
|
||||
}
|
||||
|
||||
void progressbar_inc(struct progressbar *pb) {
|
||||
progressbar_add(pb, 1);
|
||||
}
|
||||
|
||||
void progressbar_clear(struct progressbar *pb) {
|
||||
(void)pb;
|
||||
printf("\r");
|
||||
for(unsigned i = 0; i < progressbar_width + 7; i++) {
|
||||
printf(" ");
|
||||
}
|
||||
fflush(stdout);
|
||||
printf("\r");
|
||||
fflush(stdout);
|
||||
}
|
||||
#include <stdio.h>
|
||||
#include "progressbar.h"
|
||||
|
||||
// see progressbar.h
|
||||
|
||||
static const unsigned progressbar_width = 80 - 7;
|
||||
|
||||
static unsigned get_to_print(unsigned current, unsigned max) {
|
||||
return progressbar_width * current / max;
|
||||
}
|
||||
|
||||
static unsigned get_percentage(unsigned current, unsigned max) {
|
||||
return 100 * current / max;
|
||||
}
|
||||
|
||||
static void progressbar_show(struct progressbar *pb) {
|
||||
unsigned to_print = get_to_print(pb->current, pb->max);
|
||||
unsigned percentage = get_percentage(pb->current, pb->max);
|
||||
|
||||
printf("\r[");
|
||||
for(unsigned i = 0; i < to_print; i++) {
|
||||
printf("#");
|
||||
}
|
||||
for(unsigned i = 0; i < progressbar_width - to_print; i++) {
|
||||
printf(" ");
|
||||
}
|
||||
printf("] %3u%%", percentage);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void progressbar_start(struct progressbar *pb, unsigned max) {
|
||||
pb->max = max;
|
||||
pb->current = 0;
|
||||
progressbar_show(pb);
|
||||
}
|
||||
|
||||
void progressbar_set(struct progressbar *pb, unsigned current) {
|
||||
unsigned old_to_print = get_to_print(pb->current, pb->max);
|
||||
unsigned old_percentage = get_percentage(pb->current, pb->max);
|
||||
unsigned to_print = get_to_print(current, pb->max);
|
||||
unsigned percentage = get_percentage(current, pb->max);
|
||||
pb->current = current;
|
||||
if(old_to_print == to_print && old_percentage == percentage) {
|
||||
return;
|
||||
}
|
||||
progressbar_show(pb);
|
||||
}
|
||||
|
||||
void progressbar_add(struct progressbar *pb, unsigned n) {
|
||||
progressbar_set(pb, pb->current + n);
|
||||
}
|
||||
|
||||
void progressbar_inc(struct progressbar *pb) {
|
||||
progressbar_add(pb, 1);
|
||||
}
|
||||
|
||||
void progressbar_clear() {
|
||||
printf("\r");
|
||||
for(unsigned i = 0; i < progressbar_width + 7; i++) {
|
||||
printf(" ");
|
||||
}
|
||||
fflush(stdout);
|
||||
printf("\r");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
#ifndef JPEG2PNG_PROGRESSBAR_H
|
||||
#define JPEG2PNG_PROGRESSBAR_H
|
||||
|
||||
struct progressbar {
|
||||
unsigned current;
|
||||
unsigned max;
|
||||
};
|
||||
|
||||
// initialize progressbar with maximum value
|
||||
void progressbar_start(struct progressbar *pb, unsigned max);
|
||||
// set current value
|
||||
void progressbar_set(struct progressbar *pb, unsigned current);
|
||||
// add to current value
|
||||
void progressbar_add(struct progressbar *pb, unsigned n);
|
||||
// add one to current value
|
||||
void progressbar_inc(struct progressbar *pb);
|
||||
// clear line of progress bar
|
||||
void progressbar_clear(struct progressbar *pb);
|
||||
|
||||
#endif
|
||||
#ifndef JPEG2PNG_PROGRESSBAR_H
|
||||
#define JPEG2PNG_PROGRESSBAR_H
|
||||
|
||||
struct progressbar {
|
||||
unsigned current;
|
||||
unsigned max;
|
||||
};
|
||||
|
||||
// initialize progressbar with maximum value
|
||||
void progressbar_start(struct progressbar *pb, unsigned max);
|
||||
// set current value
|
||||
void progressbar_set(struct progressbar *pb, unsigned current);
|
||||
// add to current value
|
||||
void progressbar_add(struct progressbar *pb, unsigned n);
|
||||
// add one to current value
|
||||
void progressbar_inc(struct progressbar *pb);
|
||||
// clear line of progress bar
|
||||
void progressbar_clear();
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user