apple2_gumball/dump_list.c

87 lines
1.9 KiB
C
Raw Normal View History

2018-04-19 15:41:55 +00:00
// Includes
#include <stdio.h> // printf()
#include <stdlib.h> // malloc()
// Util
size_t FileSize( FILE *file )
{
if( !file )
return 0;
// Yes, this is insecure
// and we should use stat()
// but that isn't available under Windows
fseek( file, 0, SEEK_END );
size_t size = ftell( file );
fseek( file, 0, SEEK_SET );
return size;
}
// Main
2018-04-19 16:01:32 +00:00
int main( const int nArg, const char *aArg[] )
2018-04-19 15:41:55 +00:00
{
const char *name = "gumball.fragment.1.1800";
2018-04-19 16:01:32 +00:00
if( nArg > 1 )
2018-04-19 17:05:59 +00:00
{
name = aArg[1];
printf( "Filename: %s\n", name );
}
FILE *in = fopen( name, "rb" );
2018-04-19 16:01:32 +00:00
2018-04-19 15:41:55 +00:00
if( in )
{
size_t size = FileSize( in );
//printf( "Size: %lld\n", size );
if( size )
{
char *buffer = (char*) malloc( size );
int i;
int n = (int) size;
char c;
size_t read = fread( buffer, 1, size, in );
if( read != size )
printf( "ERROR: Only read %lld / %lld bytes\n", read, size );
for( i = 0; i < n; i++ )
{
c = buffer[ i ] & 0x7F;
if( c == 0x0D )
{
printf( "\n" );
c = buffer[ ++i ];
if( (c == 0x13) || (c == 0x0B) )
printf( "\t" );
else
printf( " " );
}
else
if( c < 0x20 )
;
else
printf( "%c", c );
}
free( buffer );
}
fclose( in );
}
else
printf( "ERROR: Couldn't open: '%s'\n", name );
return 0;
}