clock and progressbar tests

This commit is contained in:
Kaehvaman 2024-12-02 23:19:52 +04:00
parent 92f7e73b20
commit 71a946ecf0
6 changed files with 302 additions and 256 deletions

View File

@ -1,135 +1,139 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32"> <ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64"> <ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
<Platform>x64</Platform> <Platform>x64</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Release|x64"> <ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>x64</Platform> <Platform>x64</Platform>
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion> <VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<ProjectGuid>{268761f2-af30-432d-91df-77542792a4ab}</ProjectGuid> <ProjectGuid>{268761f2-af30-432d-91df-77542792a4ab}</ProjectGuid>
<RootNamespace>clock</RootNamespace> <RootNamespace>clock</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
</ImportGroup> </ImportGroup>
<ImportGroup Label="Shared"> <ImportGroup Label="Shared">
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.c" /> <ClCompile Include="..\progressbar test\progressbar.c" />
</ItemGroup> <ClCompile Include="main.c" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> </ItemGroup>
<ImportGroup Label="ExtensionTargets"> <ItemGroup>
</ImportGroup> <ClInclude Include="..\progressbar test\progressbar.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project> </Project>

View File

@ -1,22 +1,30 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<Filter Include="Исходные файлы"> <Filter Include="Исходные файлы">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter> </Filter>
<Filter Include="Файлы заголовков"> <Filter Include="Файлы заголовков">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter> </Filter>
<Filter Include="Файлы ресурсов"> <Filter Include="Файлы ресурсов">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> <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> <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.c"> <ClCompile Include="main.c">
<Filter>Исходные файлы</Filter> <Filter>Исходные файлы</Filter>
</ClCompile> </ClCompile>
</ItemGroup> <ClCompile Include="..\progressbar test\progressbar.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\progressbar test\progressbar.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
</ItemGroup>
</Project> </Project>

View File

@ -1,16 +1,50 @@
#include <stdlib.h> #include <stdio.h>
#include <stdio.h> #include <time.h>
#include <time.h> #include <Windows.h>
#include <Windows.h> #include "../progressbar test/progressbar.h"
// \033[ = CSI, CSI ?25l hides the cursor, CSI ?25h shows the cursor
int main() { // see ANSI escape code wiki for more info
int n = 10, sl = 10, last_clock = 0; #define HIDE_CURSOR "\033[?25l"
clock_t start = clock(); #define SHOW_CURSOR "\033[?25h"
for (int i = 0; i < n; i++) {
printf_s("%d\n", i); void wait(int seconds) {
Sleep(sl); clock_t t0 = clock();
} clock_t t1;
printf_s("time = %.3lf seconds\nexpected %d seconds %lf", (double)(clock() - start) / (double)CLOCKS_PER_SEC, n * sl / 1000, 0.3300000000000000000000); while ((int)(((t1 = clock()) - t0) / CLOCKS_PER_SEC) < seconds) {
return 0; 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;
} }

View File

@ -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)); 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'); 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)); 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; return 0;
} }

View File

@ -1,66 +1,65 @@
#include <stdio.h> #include <stdio.h>
#include "progressbar.h" #include "progressbar.h"
// see progressbar.h // see progressbar.h
static const unsigned progressbar_width = 70; static const unsigned progressbar_width = 80 - 7;
static unsigned get_to_print(unsigned current, unsigned max) { static unsigned get_to_print(unsigned current, unsigned max) {
return progressbar_width * current / max; return progressbar_width * current / max;
} }
static unsigned get_percentage(unsigned current, unsigned max) { static unsigned get_percentage(unsigned current, unsigned max) {
return 100 * current / max; return 100 * current / max;
} }
static void progressbar_show(struct progressbar *pb) { static void progressbar_show(struct progressbar *pb) {
unsigned to_print = get_to_print(pb->current, pb->max); unsigned to_print = get_to_print(pb->current, pb->max);
unsigned percentage = get_percentage(pb->current, pb->max); unsigned percentage = get_percentage(pb->current, pb->max);
printf("\r["); printf("\r[");
for(unsigned i = 0; i < to_print; i++) { for(unsigned i = 0; i < to_print; i++) {
printf("#"); printf("#");
} }
for(unsigned i = 0; i < progressbar_width - to_print; i++) { for(unsigned i = 0; i < progressbar_width - to_print; i++) {
printf(" "); printf(" ");
} }
printf("] %3u%%", percentage); printf("] %3u%%", percentage);
fflush(stdout); fflush(stdout);
} }
void progressbar_start(struct progressbar *pb, unsigned max) { void progressbar_start(struct progressbar *pb, unsigned max) {
pb->max = max; pb->max = max;
pb->current = 0; pb->current = 0;
progressbar_show(pb); progressbar_show(pb);
} }
void progressbar_set(struct progressbar *pb, unsigned current) { void progressbar_set(struct progressbar *pb, unsigned current) {
unsigned old_to_print = get_to_print(pb->current, pb->max); unsigned old_to_print = get_to_print(pb->current, pb->max);
unsigned old_percentage = get_percentage(pb->current, pb->max); unsigned old_percentage = get_percentage(pb->current, pb->max);
unsigned to_print = get_to_print(current, pb->max); unsigned to_print = get_to_print(current, pb->max);
unsigned percentage = get_percentage(current, pb->max); unsigned percentage = get_percentage(current, pb->max);
pb->current = current; pb->current = current;
if(old_to_print == to_print && old_percentage == percentage) { if(old_to_print == to_print && old_percentage == percentage) {
return; return;
} }
progressbar_show(pb); progressbar_show(pb);
} }
void progressbar_add(struct progressbar *pb, unsigned n) { void progressbar_add(struct progressbar *pb, unsigned n) {
progressbar_set(pb, pb->current + n); progressbar_set(pb, pb->current + n);
} }
void progressbar_inc(struct progressbar *pb) { void progressbar_inc(struct progressbar *pb) {
progressbar_add(pb, 1); progressbar_add(pb, 1);
} }
void progressbar_clear(struct progressbar *pb) { void progressbar_clear() {
(void)pb; printf("\r");
printf("\r"); for(unsigned i = 0; i < progressbar_width + 7; i++) {
for(unsigned i = 0; i < progressbar_width + 7; i++) { printf(" ");
printf(" "); }
} fflush(stdout);
fflush(stdout); printf("\r");
printf("\r"); fflush(stdout);
fflush(stdout); }
}

View File

@ -1,20 +1,20 @@
#ifndef JPEG2PNG_PROGRESSBAR_H #ifndef JPEG2PNG_PROGRESSBAR_H
#define JPEG2PNG_PROGRESSBAR_H #define JPEG2PNG_PROGRESSBAR_H
struct progressbar { struct progressbar {
unsigned current; unsigned current;
unsigned max; unsigned max;
}; };
// initialize progressbar with maximum value // initialize progressbar with maximum value
void progressbar_start(struct progressbar *pb, unsigned max); void progressbar_start(struct progressbar *pb, unsigned max);
// set current value // set current value
void progressbar_set(struct progressbar *pb, unsigned current); void progressbar_set(struct progressbar *pb, unsigned current);
// add to current value // add to current value
void progressbar_add(struct progressbar *pb, unsigned n); void progressbar_add(struct progressbar *pb, unsigned n);
// add one to current value // add one to current value
void progressbar_inc(struct progressbar *pb); void progressbar_inc(struct progressbar *pb);
// clear line of progress bar // clear line of progress bar
void progressbar_clear(struct progressbar *pb); void progressbar_clear();
#endif #endif