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\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" />

View File

@ -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>

View File

@ -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
{
Usage();
}
argv++;
}
if( argc == 5 )
{
if( strcmp( argv[1], "--zstd" ) != 0 ) Usage();
break;
case 'z':
clev = tracy::FileWrite::Compression::Zstd;
zstdLevel = atoi( argv[2] );
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 );
}
argv += 2;
break;
default:
Usage();
break;
}
}
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 );