allow other channel for non-dsp sounds (2D oneshots)
[vg.git] / src / msgdump.c
1 // Copyright (C) 2021-2023 Harry Godden (hgn) - All Rights Reserved
2
3 #define VG_TOOLS
4 #include "vg/vg.h"
5 #include "vg/vg_msg.h"
6
7 #define CHUNK_SIZE 4096
8
9 int main( int argc, char *argv[] ){
10 assert(argc);
11
12 if( argc < 2 ){
13 vg_error( "Usage: %s <file>\n", argv[0] );
14 return 0;
15 }
16
17 for( int i=0; i<argc-1; i++ ){
18 FILE *f = fopen( argv[i+1], "rb" );
19 if( !f ){
20 vg_error( "vg_disk_open_read: %s\n", strerror(errno) );
21 }
22
23 void *buffer = NULL;
24 u64 current = 0;
25
26 /* read in chunks */
27 for( u32 i=0; 1; i++ ){
28 buffer = realloc( buffer, current + CHUNK_SIZE );
29 u64 l = fread( buffer + current, 1, CHUNK_SIZE, f );
30 current += l;
31
32 if( l != CHUNK_SIZE ){
33 if( feof( f ) ){
34 break;
35 }
36 else{
37 if( ferror( f ) ){
38 fclose(f);
39 vg_fatal_error( "read error" );
40 }
41 else{
42 fclose(f);
43 vg_fatal_error( "unknown error codition" );
44 }
45 }
46 }
47 }
48
49 fclose( f );
50
51 printf( "%s (%u bytes):", argv[i+1], (u32)current );
52
53 vg_msg msg;
54 vg_msg_init( &msg, buffer, current );
55 vg_msg_print( &msg, current );
56
57 free( buffer );
58 }
59 }