diff options
author | Bartosz Taudul <wolf.pld@gmail.com> | 2020-07-17 22:47:51 +0300 |
---|---|---|
committer | Bartosz Taudul <wolf.pld@gmail.com> | 2020-07-17 22:47:51 +0300 |
commit | 08c70cd6feffe8c31d71cb7f5a842c5124662665 (patch) | |
tree | a8c63817f98d52ccdb9b5bf2b320899c6856339e /update | |
parent | 08172556fcb748fc5be5130b956846ce239c0d5a (diff) |
Use getopt in the update utility.
Diffstat (limited to 'update')
-rw-r--r-- | update/build/win32/update.vcxproj | 2 | ||||
-rw-r--r-- | update/build/win32/update.vcxproj.filters | 9 | ||||
-rw-r--r-- | update/src/update.cpp | 54 |
3 files changed, 37 insertions, 28 deletions
diff --git a/update/build/win32/update.vcxproj b/update/build/win32/update.vcxproj index 46ed6aa9..45e39838 100644 --- a/update/build/win32/update.vcxproj +++ b/update/build/win32/update.vcxproj @@ -138,6 +138,7 @@ <ClCompile Include="..\..\..\common\TracySystem.cpp" /> <ClCompile Include="..\..\..\common\tracy_lz4.cpp" /> <ClCompile Include="..\..\..\common\tracy_lz4hc.cpp" /> + <ClCompile Include="..\..\..\getopt\getopt.c" /> <ClCompile Include="..\..\..\server\TracyMemory.cpp" /> <ClCompile Include="..\..\..\server\TracyMmap.cpp" /> <ClCompile Include="..\..\..\server\TracyPrint.cpp" /> @@ -183,6 +184,7 @@ <ClInclude Include="..\..\..\common\TracySystem.hpp" /> <ClInclude Include="..\..\..\common\tracy_lz4.hpp" /> <ClInclude Include="..\..\..\common\tracy_lz4hc.hpp" /> + <ClInclude Include="..\..\..\getopt\getopt.h" /> <ClInclude Include="..\..\..\server\TracyCharUtil.hpp" /> <ClInclude Include="..\..\..\server\TracyEvent.hpp" /> <ClInclude Include="..\..\..\server\TracyFileRead.hpp" /> diff --git a/update/build/win32/update.vcxproj.filters b/update/build/win32/update.vcxproj.filters index 95dbfec5..5f61cff9 100644 --- a/update/build/win32/update.vcxproj.filters +++ b/update/build/win32/update.vcxproj.filters @@ -13,6 +13,9 @@ <Filter Include="zstd"> <UniqueIdentifier>{2ec8dc96-8501-481f-8620-7f33bd8b2164}</UniqueIdentifier> </Filter> + <Filter Include="getopt"> + <UniqueIdentifier>{74a14f40-f52d-41c1-8b19-1f8bf2a7c9c7}</UniqueIdentifier> + </Filter> </ItemGroup> <ItemGroup> <ClCompile Include="..\..\..\common\tracy_lz4.cpp"> @@ -126,6 +129,9 @@ <ClCompile Include="..\..\..\server\TracyTextureCompression.cpp"> <Filter>server</Filter> </ClCompile> + <ClCompile Include="..\..\..\getopt\getopt.c"> + <Filter>getopt</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\..\common\tracy_lz4.hpp"> @@ -287,5 +293,8 @@ <ClInclude Include="..\..\..\server\TracyTextureCompression.hpp"> <Filter>server</Filter> </ClInclude> + <ClInclude Include="..\..\..\getopt\getopt.h"> + <Filter>getopt</Filter> + </ClInclude> </ItemGroup> </Project>
\ No newline at end of file diff --git a/update/src/update.cpp b/update/src/update.cpp index 66cbb442..71db378e 100644 --- a/update/src/update.cpp +++ b/update/src/update.cpp @@ -13,6 +13,7 @@ #include "../../server/TracyVersion.hpp" #include "../../server/TracyWorker.hpp" #include "../../zstd/zstd.h" +#include "../../getopt/getopt.h" #ifdef __CYGWIN__ # define ftello64(x) ftello(x) @@ -24,10 +25,10 @@ void Usage() { - printf( "Usage: update [--hc|--extreme] input.tracy output.tracy\n\n" ); - printf( " --hc: enable LZ4HC compression\n" ); - printf( " --extreme: enable extreme LZ4HC compression (very slow)\n" ); - printf( " --zstd level: use Zstd compression with given compression level\n" ); + printf( "Usage: update [options] input.tracy output.tracy\n\n" ); + printf( " -h: enable LZ4HC compression\n" ); + printf( " -e: enable extreme LZ4HC compression (very slow)\n" ); + printf( " -z level: use Zstd compression with given compression level\n" ); exit( 1 ); } @@ -44,38 +45,35 @@ int main( int argc, char** argv ) tracy::FileWrite::Compression clev = tracy::FileWrite::Compression::Fast; int zstdLevel = 1; - if( argc != 3 && argc != 4 && argc != 5 ) Usage(); - if( argc == 4 ) + int c; + while( ( c = getopt( argc, argv, "hez:" ) ) != -1 ) { - if( strcmp( argv[1], "--hc" ) == 0 ) + switch( c ) { + case 'h': clev = tracy::FileWrite::Compression::Slow; - } - else if( strcmp( argv[1], "--extreme" ) == 0 ) - { + break; + case 'e': clev = tracy::FileWrite::Compression::Extreme; - } - else - { + break; + case 'z': + clev = tracy::FileWrite::Compression::Zstd; + zstdLevel = atoi( optarg ); + if( zstdLevel > ZSTD_maxCLevel() || zstdLevel < ZSTD_minCLevel() ) + { + printf( "Available Zstd compression levels range: %i - %i\n", ZSTD_minCLevel(), ZSTD_maxCLevel() ); + exit( 1 ); + } + break; + default: Usage(); + break; } - argv++; - } - if( argc == 5 ) - { - if( strcmp( argv[1], "--zstd" ) != 0 ) Usage(); - clev = tracy::FileWrite::Compression::Zstd; - zstdLevel = atoi( argv[2] ); - if( zstdLevel > ZSTD_maxCLevel() || zstdLevel < ZSTD_minCLevel() ) - { - printf( "Available Zstd compression levels range: %i - %i\n", ZSTD_minCLevel(), ZSTD_maxCLevel() ); - exit( 1 ); - } - argv += 2; } + if( argc - optind != 2 ) Usage(); - const char* input = argv[1]; - const char* output = argv[2]; + const char* input = argv[optind]; + const char* output = argv[optind+1]; printf( "Loading...\r" ); fflush( stdout ); |