Browse Source

removed some more compiler warnings

master
Sven Oliver Moll 1 month ago
parent
commit
20399e282a
2 changed files with 62 additions and 29 deletions
  1. 37
    8
      makewav.c
  2. 25
    21
      makewav.h

+ 37
- 8
makewav.c View File

@@ -37,6 +37,28 @@ unsigned char  buffer[260],
37 37
 float flength,
38 38
       wavFlength;
39 39
 
40
+void freadall( void *b, size_t size, FILE *f )
41
+{
42
+   char   *c    = (char*)b;
43
+   size_t pos   = 0;
44
+   size_t dread = 0;
45
+
46
+   for( pos = 0; pos < size; pos += size )
47
+   {
48
+      dread = fread( c + pos, 1, size - pos, f );
49
+      if( dread == 0 )
50
+      {
51
+         break;
52
+      }
53
+   }
54
+   if( pos != size )
55
+   {
56
+      fprintf( stderr, "short read: could only get %u bytes out of %u\n",
57
+                       (unsigned int)pos, (unsigned int)size );
58
+      exit( 2 );
59
+   }
60
+}
61
+
40 62
 void processByte( streambuffer_t *buffer, unsigned char pByte, int mode )
41 63
 {
42 64
    int p;
@@ -69,7 +91,7 @@ void getPage(unsigned int page, int display)
69 91
       printf("%02x\b\b",page);
70 92
    }
71 93
    fseek(binFile,(long) page * 256,SEEK_SET);
72
-   fread(buffer,256,1,binFile);
94
+   freadall(buffer,256,binFile);
73 95
 }
74 96
 
75 97
 unsigned char setVolume(unsigned int amplitude, int volume)
@@ -319,10 +341,15 @@ int processParms( int argc, char *argv[], struct parmFlags *parms )
319 341
             fprintf(stderr,"Illegal start address!\n");
320 342
             exit(1);
321 343
          }
322
-         if (sscanf(*argv,"s%2hhx%2hhx",&parms->startHi,&parms->startLo) == EOF)
323 344
          {
324
-            fprintf(stderr,"Illegal start address!\n");
325
-            exit(1);
345
+            unsigned int start;
346
+            if (sscanf(*argv,"s%04x",&start) == EOF)
347
+            {
348
+               fprintf(stderr,"Illegal start address!\n");
349
+               exit(1);
350
+            }
351
+            parms->startHi = (start >> 8) & 0xff;
352
+            parms->startLo = start & 0xff;
326 353
          }
327 354
          parms->sflag = 1;
328 355
          break;
@@ -679,10 +706,12 @@ int main( int argc, char *argv[] )
679 706
       char answer;
680 707
 
681 708
       fprintf(stderr,"Warning! %d .wav files will be created, Continue? (Y/N)", parms.binFileCount);
682
-      scanf("%c",&answer);
683
-      if (answer != 'y' && answer != 'Y')
709
+      while( scanf("%c",&answer) < 1 )
684 710
       {
685
-         exit(1);
711
+         if (answer != 'y' && answer != 'Y')
712
+         {
713
+            exit(1);
714
+         }
686 715
       }
687 716
    }
688 717
 
@@ -734,7 +763,7 @@ int main( int argc, char *argv[] )
734 763
          fseek(binFile,0,SEEK_END);
735 764
          fsize = ftell(binFile);
736 765
          fseek(binFile,0,SEEK_SET);
737
-         fread(fileBuffer,fsize,1,binFile);
766
+         freadall(fileBuffer,fsize,binFile);
738 767
          if (parms.tflag == 's' && fsize != 8448 && fsize != 6144 && fsize != 2048 && fsize != 4096 && fsize != 32767)
739 768
          {
740 769
             fprintf(stderr,"Invalid file size for Supercharger, skipping\n");

+ 25
- 21
makewav.h View File

@@ -45,9 +45,13 @@
45 45
 #define DISPLAY_DETAILS  3
46 46
 
47 47
 #define _MAX_FNAME 256
48
+#ifndef _MAX_PATH
48 49
 #define _MAX_PATH  256
50
+#endif
49 51
 #define _MAX_DIR   256
52
+#ifndef _MAX_DRIVE
50 53
 #define _MAX_DRIVE 256
54
+#endif
51 55
 #define _MAX_EXT   256
52 56
 
53 57
 typedef unsigned long int   dd;
@@ -78,7 +82,7 @@ struct parmFlags
78 82
     float   clearingSeconds;
79 83
     float   hlength;
80 84
     char    wavFileName[_MAX_FNAME+5];
81
-    char    fullPath[_MAX_PATH];
85
+    char    fullPath[_MAX_PATH+5];
82 86
     char    *audioDevName;
83 87
 
84 88
     struct   qnode *binFileQ;
@@ -89,32 +93,32 @@ struct parmFlags
89 93
 };
90 94
 
91 95
 char bankSwitchList[][5] =
92
-    {"2K",  "CV",   "4K",    "28SC", "F8SC",    "28",    "F8",   "FE",
93
-     "3F",    "E0",   "FA",    "2A",    "3A",    "FANR",    "2ANR",    "3ANR",
94
-     "46SC","F6SC",    "26SC",    "36SC",    "46",    "F6",    "26",    "36",
95
-     "E7",  "E7NR", "F4SC", "24SC",    "34SC",    "44SC",    "F4",    "24",
96
-     "34",    "44",    "MB",   ""};
96
+    {"2K",   "CV",   "4K",   "28SC", "F8SC", "28",   "F8",   "FE",
97
+     "3F",   "E0",   "FA",   "2A",   "3A",   "FANR", "2ANR", "3ANR",
98
+     "46SC", "F6SC", "26SC", "36SC", "46",   "F6",   "26",   "36",
99
+     "E7",   "E7NR", "F4SC", "24SC", "34SC", "44SC", "F4",   "24",
100
+     "34",   "44",   "MB",   ""};
97 101
 
98 102
 unsigned int controlByteList[] =
99
-    {0xCA,  0xEA,   0xC8,   0xF6,    0xE6,    0xD6,   0xC6,   0xCC,
100
-     0xCE,  0xC1,   0xE0,   0xF0,   0x60,    0xC0,    0xD0,    0x40,
101
-     0x74,    0xE4,    0xF4,    0x64,    0x54,    0xC4,    0xD4,    0x44,
102
-     0xE3,  0xC3,   0xE2,   0xF2,    0x62,    0x72,    0xC2,    0xD2,
103
-     0x42,    0x52,    0xC9,   0x00};
103
+    {0xCA, 0xEA, 0xC8, 0xF6, 0xE6, 0xD6, 0xC6, 0xCC,
104
+     0xCE, 0xC1, 0xE0, 0xF0, 0x60, 0xC0, 0xD0, 0x40,
105
+     0x74, 0xE4, 0xF4, 0x64, 0x54, 0xC4, 0xD4, 0x44,
106
+     0xE3, 0xC3, 0xE2, 0xF2, 0x62, 0x72, 0xC2, 0xD2,
107
+     0x42, 0x52, 0xC9, 0x00};
104 108
 
105 109
 int fileSizeList[] =
106
-    {2048,  2048,   4096,   8192,    8192,    8192,   8192,   8192,
107
-     8192,  8192,   12288,  12288,  12288,    12288,    12288,    12288,
108
-     16384, 16384,    16384,    16384,    16384,    16384,    16384,    16384,
109
-     16384, 16384,  32768,  32768,  32768,    32768,    32768,    32768,
110
-     32768,    32768,    65536,  0};
110
+    { 2048,  2048,  4096,  8192,  8192,  8192,  8192,  8192,
111
+      8192,  8192, 12288, 12288, 12288, 12288, 12288, 12288,
112
+     16384, 16384, 16384, 16384, 16384, 16384, 16384, 16384,
113
+     16384, 16384, 32768, 32768, 32768, 32768, 32768, 32768,
114
+     32768, 32768, 65536,     0};
111 115
 
112 116
 int startPageList[] =
113
-    {7,     7,      15,     31,        15,     31,        15,     15,
114
-     31,    31,     15,     31,        47,        15,     31,        47,
115
-     63,    15,        31,        47,        63,        15,        31,        47,
116
-     63,    63,     15,        31,        47,        63,     15,        31,
117
-     47,    63,        15,     0};
117
+    { 7,  7, 15, 31, 15, 31, 15, 15,
118
+     31, 31, 15, 31, 47, 15, 31, 47,
119
+     63, 15, 31, 47, 63, 15, 31, 47,
120
+     63, 63, 15, 31, 47, 63, 15, 31,
121
+     47, 63, 15,  0};
118 122
 
119 123
 unsigned char clearingToneLength[2] = {26, 51};
120 124
 unsigned char clearingTone[256];

Loading…
Cancel
Save