comparison tools/mod2wav.c @ 958:985225a93aeb

Add error code parameter to dmError() and dmErrorVA().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 27 Feb 2015 03:58:25 +0200
parents daebbf28953d
children a79edf59d5d8
comparison
equal deleted inserted replaced
957:b66653c9acb3 958:985225a93aeb
96 optPlayTime = atoi(optArg); 96 optPlayTime = atoi(optArg);
97 optUsePlayTime = TRUE; 97 optUsePlayTime = TRUE;
98 break; 98 break;
99 99
100 default: 100 default:
101 dmError("Unknown argument '%s'.\n", currArg); 101 dmErrorMsg("Unknown argument '%s'.\n", currArg);
102 return FALSE; 102 return FALSE;
103 } 103 }
104 104
105 return TRUE; 105 return TRUE;
106 } 106 }
113 else 113 else
114 if (!optOutFilename) 114 if (!optOutFilename)
115 optOutFilename = currArg; 115 optOutFilename = currArg;
116 else 116 else
117 { 117 {
118 dmError("Too many filename arguments (only source and dest needed) '%s'\n", currArg); 118 dmErrorMsg("Too many filename arguments (only source and dest needed) '%s'\n", currArg);
119 return FALSE; 119 return FALSE;
120 } 120 }
121 121
122 return TRUE; 122 return TRUE;
123 } 123 }
143 exit(1); 143 exit(1);
144 144
145 // Check arguments 145 // Check arguments
146 if (optInFilename == NULL || optOutFilename == NULL) 146 if (optInFilename == NULL || optOutFilename == NULL)
147 { 147 {
148 dmError("Input or output file not specified. Try --help.\n"); 148 dmErrorMsg("Input or output file not specified. Try --help.\n");
149 return 1; 149 return 1;
150 } 150 }
151 151
152 // Initialize miniJSS 152 // Initialize miniJSS
153 jssInit(); 153 jssInit();
154 154
155 // Open the source file 155 // Open the source file
156 if ((result = dmf_create_stdio(optInFilename, "rb", &inFile)) != DMERR_OK) 156 if ((result = dmf_create_stdio(optInFilename, "rb", &inFile)) != DMERR_OK)
157 { 157 {
158 dmError("Error opening input file '%s', %d: %s\n", 158 dmErrorMsg("Error opening input file '%s', %d: %s\n",
159 optInFilename, result, dmErrorStr(result)); 159 optInFilename, result, dmErrorStr(result));
160 return 1; 160 return 1;
161 } 161 }
162 162
163 // Read module file 163 // Read module file
175 } 175 }
176 #endif 176 #endif
177 dmf_close(inFile); 177 dmf_close(inFile);
178 if (result != DMERR_OK) 178 if (result != DMERR_OK)
179 { 179 {
180 dmError("Error loading module file, %d: %s\n", 180 dmErrorMsg("Error loading module file, %d: %s\n",
181 result, dmErrorStr(result)); 181 result, dmErrorStr(result));
182 return 3; 182 return 3;
183 } 183 }
184 184
185 // Try to convert it 185 // Try to convert it
186 if ((result = jssConvertModuleForPlaying(mod)) != DMERR_OK) 186 if ((result = jssConvertModuleForPlaying(mod)) != DMERR_OK)
187 { 187 {
188 dmError("Could not convert module for playing, %d: %s\n", 188 dmErrorMsg("Could not convert module for playing, %d: %s\n",
189 result, dmErrorStr(result)); 189 result, dmErrorStr(result));
190 return 3; 190 return 3;
191 } 191 }
192 192
193 // Open mixer 193 // Open mixer
194 dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO); 194 dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO);
195 if (dev == NULL) 195 if (dev == NULL)
196 { 196 {
197 dmError("jvmInit() returned NULL\n"); 197 dmErrorMsg("jvmInit() returned NULL\n");
198 return 4; 198 return 4;
199 } 199 }
200 200
201 sampSize = jvmGetSampleSize(dev); 201 sampSize = jvmGetSampleSize(dev);
202 if ((mb = dmMalloc(bufLen * sampSize)) == NULL) 202 if ((mb = dmMalloc(bufLen * sampSize)) == NULL)
203 { 203 {
204 dmError("Could not allocate mixing buffer\n"); 204 dmErrorMsg("Could not allocate mixing buffer\n");
205 return 5; 205 return 5;
206 } 206 }
207 207
208 dmMsg(1, "Using fmt=%d, bits=%d, channels=%d, freq=%d [%d / sample]\n", 208 dmMsg(1, "Using fmt=%d, bits=%d, channels=%d, freq=%d [%d / sample]\n",
209 optOutFormat, jvmGetSampleRes(dev), optOutChannels, optOutFreq, 209 optOutFormat, jvmGetSampleRes(dev), optOutChannels, optOutFreq,
210 sampSize); 210 sampSize);
211 211
212 // Initialize player 212 // Initialize player
213 if ((plr = jmpInit(dev)) == NULL) 213 if ((plr = jmpInit(dev)) == NULL)
214 { 214 {
215 dmError("jmpInit() returned NULL.\n"); 215 dmErrorMsg("jmpInit() returned NULL.\n");
216 return 6; 216 return 6;
217 } 217 }
218 218
219 // Set callback 219 // Set callback
220 jvmSetCallback(dev, jmpExec, plr); 220 jvmSetCallback(dev, jmpExec, plr);
239 } 239 }
240 240
241 // Open output file 241 // Open output file
242 if ((outFile = fopen(optOutFilename, "wb")) == NULL) 242 if ((outFile = fopen(optOutFilename, "wb")) == NULL)
243 { 243 {
244 dmError("Error opening output file '%s'. (%s)\n", 244 dmErrorMsg("Error opening output file '%s'. (%s)\n",
245 optInFilename, strerror(errno)); 245 optInFilename, strerror(errno));
246 return 7; 246 return 7;
247 } 247 }
248 248
249 // Write initial header 249 // Write initial header
271 jssEncodeSample16((Uint16 *)mb, writeLen * optOutChannels, jsampSwapEndianess); 271 jssEncodeSample16((Uint16 *)mb, writeLen * optOutChannels, jsampSwapEndianess);
272 #endif 272 #endif
273 dataWritten = fwrite(mb, sampSize, writeLen, outFile); 273 dataWritten = fwrite(mb, sampSize, writeLen, outFile);
274 if (dataWritten < writeLen) 274 if (dataWritten < writeLen)
275 { 275 {
276 dmError("Error writing data!\n"); 276 dmErrorMsg("Error writing data!\n");
277 fclose(outFile); 277 fclose(outFile);
278 return 8; 278 return 8;
279 } 279 }
280 dataTotal += dataWritten; 280 dataTotal += dataWritten;
281 } 281 }
285 } 285 }
286 286
287 // Write the correct header 287 // Write the correct header
288 if (fseek(outFile, 0L, SEEK_SET) != 0) 288 if (fseek(outFile, 0L, SEEK_SET) != 0)
289 { 289 {
290 dmError("Error rewinding to header position!\n"); 290 dmErrorMsg("Error rewinding to header position!\n");
291 return 9; 291 return 9;
292 } 292 }
293 293
294 dmWriteWAVHeader(outFile, jvmGetSampleRes(dev), optOutFreq, optOutChannels, dataTotal); 294 dmWriteWAVHeader(outFile, jvmGetSampleRes(dev), optOutFreq, optOutChannels, dataTotal);
295 295