Add printing the read base64 code

Signed-off-by: Piotr Nowicki <piotr.nowicki@arm.com>
This commit is contained in:
Piotr Nowicki 2020-03-16 17:52:56 +01:00
parent 14d3105f78
commit 6842c9bde8

View file

@ -145,6 +145,26 @@ void parse_arguments( int argc, char *argv[] )
} }
} }
/*
* This function prints base64 code to the stdout
*/
void print_b64( const char *b, const size_t len )
{
size_t i = 0;
const char *end = b + len;
while( b < end )
{
if( ++i > 70 )
{
printf( "\n" );
i = 0;
}
printf( "%c", *b++ );
}
printf( "\n" );
fflush( stdout );
}
/* /*
* Read next base64 code from the 'b64_file'. The 'b64_file' must be opened * Read next base64 code from the 'b64_file'. The 'b64_file' must be opened
* previously. After each call to this function, the internal file position * previously. After each call to this function, the internal file position
@ -229,6 +249,8 @@ int main( int argc, char *argv[] )
{ {
enum { B64BUF_LEN = 4 * 1024 }; enum { B64BUF_LEN = 4 * 1024 };
char b64[ B64BUF_LEN ]; char b64[ B64BUF_LEN ];
uint32_t b64_counter = 0;
parse_arguments( argc, argv ); parse_arguments( argc, argv );
while( NULL != b64_file ) while( NULL != b64_file )
@ -236,8 +258,17 @@ int main( int argc, char *argv[] )
size_t len = read_next_b64_code( b64, B64BUF_LEN ); size_t len = read_next_b64_code( b64, B64BUF_LEN );
if( len > 0) if( len > 0)
{ {
b64_counter++;
if( debug )
{
printf( "%u.\n", b64_counter );
print_b64( b64, len );
}
/* TODO: deserializing */ /* TODO: deserializing */
printf( "\n" );
} }
else else
{ {
@ -246,5 +277,7 @@ int main( int argc, char *argv[] )
} }
} }
printf( "Finish. Found %u base64 codes\n", b64_counter );
return 0; return 0;
} }