Use getopt in the update utility.

This commit is contained in:
Bartosz Taudul 2020-07-17 21:47:51 +02:00
parent 08172556fc
commit 08c70cd6fe
3 changed files with 37 additions and 28 deletions

View File

@ -138,6 +138,7 @@
<ClCompile Include="..\..\..\common\TracySystem.cpp" /> <ClCompile Include="..\..\..\common\TracySystem.cpp" />
<ClCompile Include="..\..\..\common\tracy_lz4.cpp" /> <ClCompile Include="..\..\..\common\tracy_lz4.cpp" />
<ClCompile Include="..\..\..\common\tracy_lz4hc.cpp" /> <ClCompile Include="..\..\..\common\tracy_lz4hc.cpp" />
<ClCompile Include="..\..\..\getopt\getopt.c" />
<ClCompile Include="..\..\..\server\TracyMemory.cpp" /> <ClCompile Include="..\..\..\server\TracyMemory.cpp" />
<ClCompile Include="..\..\..\server\TracyMmap.cpp" /> <ClCompile Include="..\..\..\server\TracyMmap.cpp" />
<ClCompile Include="..\..\..\server\TracyPrint.cpp" /> <ClCompile Include="..\..\..\server\TracyPrint.cpp" />
@ -183,6 +184,7 @@
<ClInclude Include="..\..\..\common\TracySystem.hpp" /> <ClInclude Include="..\..\..\common\TracySystem.hpp" />
<ClInclude Include="..\..\..\common\tracy_lz4.hpp" /> <ClInclude Include="..\..\..\common\tracy_lz4.hpp" />
<ClInclude Include="..\..\..\common\tracy_lz4hc.hpp" /> <ClInclude Include="..\..\..\common\tracy_lz4hc.hpp" />
<ClInclude Include="..\..\..\getopt\getopt.h" />
<ClInclude Include="..\..\..\server\TracyCharUtil.hpp" /> <ClInclude Include="..\..\..\server\TracyCharUtil.hpp" />
<ClInclude Include="..\..\..\server\TracyEvent.hpp" /> <ClInclude Include="..\..\..\server\TracyEvent.hpp" />
<ClInclude Include="..\..\..\server\TracyFileRead.hpp" /> <ClInclude Include="..\..\..\server\TracyFileRead.hpp" />

View File

@ -13,6 +13,9 @@
<Filter Include="zstd"> <Filter Include="zstd">
<UniqueIdentifier>{2ec8dc96-8501-481f-8620-7f33bd8b2164}</UniqueIdentifier> <UniqueIdentifier>{2ec8dc96-8501-481f-8620-7f33bd8b2164}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="getopt">
<UniqueIdentifier>{74a14f40-f52d-41c1-8b19-1f8bf2a7c9c7}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\..\common\tracy_lz4.cpp"> <ClCompile Include="..\..\..\common\tracy_lz4.cpp">
@ -126,6 +129,9 @@
<ClCompile Include="..\..\..\server\TracyTextureCompression.cpp"> <ClCompile Include="..\..\..\server\TracyTextureCompression.cpp">
<Filter>server</Filter> <Filter>server</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\getopt\getopt.c">
<Filter>getopt</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\..\common\tracy_lz4.hpp"> <ClInclude Include="..\..\..\common\tracy_lz4.hpp">
@ -287,5 +293,8 @@
<ClInclude Include="..\..\..\server\TracyTextureCompression.hpp"> <ClInclude Include="..\..\..\server\TracyTextureCompression.hpp">
<Filter>server</Filter> <Filter>server</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\..\getopt\getopt.h">
<Filter>getopt</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -13,6 +13,7 @@
#include "../../server/TracyVersion.hpp" #include "../../server/TracyVersion.hpp"
#include "../../server/TracyWorker.hpp" #include "../../server/TracyWorker.hpp"
#include "../../zstd/zstd.h" #include "../../zstd/zstd.h"
#include "../../getopt/getopt.h"
#ifdef __CYGWIN__ #ifdef __CYGWIN__
# define ftello64(x) ftello(x) # define ftello64(x) ftello(x)
@ -24,10 +25,10 @@
void Usage() void Usage()
{ {
printf( "Usage: update [--hc|--extreme] input.tracy output.tracy\n\n" ); printf( "Usage: update [options] input.tracy output.tracy\n\n" );
printf( " --hc: enable LZ4HC compression\n" ); printf( " -h: enable LZ4HC compression\n" );
printf( " --extreme: enable extreme LZ4HC compression (very slow)\n" ); printf( " -e: enable extreme LZ4HC compression (very slow)\n" );
printf( " --zstd level: use Zstd compression with given compression level\n" ); printf( " -z level: use Zstd compression with given compression level\n" );
exit( 1 ); exit( 1 );
} }
@ -44,38 +45,35 @@ int main( int argc, char** argv )
tracy::FileWrite::Compression clev = tracy::FileWrite::Compression::Fast; tracy::FileWrite::Compression clev = tracy::FileWrite::Compression::Fast;
int zstdLevel = 1; int zstdLevel = 1;
if( argc != 3 && argc != 4 && argc != 5 ) Usage(); int c;
if( argc == 4 ) while( ( c = getopt( argc, argv, "hez:" ) ) != -1 )
{ {
if( strcmp( argv[1], "--hc" ) == 0 ) switch( c )
{ {
case 'h':
clev = tracy::FileWrite::Compression::Slow; clev = tracy::FileWrite::Compression::Slow;
} break;
else if( strcmp( argv[1], "--extreme" ) == 0 ) case 'e':
{
clev = tracy::FileWrite::Compression::Extreme; clev = tracy::FileWrite::Compression::Extreme;
} break;
else case 'z':
{
Usage();
}
argv++;
}
if( argc == 5 )
{
if( strcmp( argv[1], "--zstd" ) != 0 ) Usage();
clev = tracy::FileWrite::Compression::Zstd; clev = tracy::FileWrite::Compression::Zstd;
zstdLevel = atoi( argv[2] ); zstdLevel = atoi( optarg );
if( zstdLevel > ZSTD_maxCLevel() || zstdLevel < ZSTD_minCLevel() ) if( zstdLevel > ZSTD_maxCLevel() || zstdLevel < ZSTD_minCLevel() )
{ {
printf( "Available Zstd compression levels range: %i - %i\n", ZSTD_minCLevel(), ZSTD_maxCLevel() ); printf( "Available Zstd compression levels range: %i - %i\n", ZSTD_minCLevel(), ZSTD_maxCLevel() );
exit( 1 ); exit( 1 );
} }
argv += 2; break;
default:
Usage();
break;
} }
}
if( argc - optind != 2 ) Usage();
const char* input = argv[1]; const char* input = argv[optind];
const char* output = argv[2]; const char* output = argv[optind+1];
printf( "Loading...\r" ); printf( "Loading...\r" );
fflush( stdout ); fflush( stdout );