-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
68 lines (52 loc) · 1.34 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// mus2midi
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mus2midi.h"
typedef struct stat STATUS;
int main(int argc, char **argv)
{
STATUS status;
FILE *file;
BYTE *musData, *midData;
int size;
char *filename;
if (argc != 2)
{
printf("Usage: %s MUSFILE\nThe MIDI filename will use the MUS filename with .mid extension appended\n", argv[0]);
return 1;
}
if (stat(argv[1], &status) < 0)
{
printf("Cannot read %s\n", argv[1]);
return 1;
}
if ((file = fopen(argv[1], "rb")) == NULL)
{
printf("Cannot open %s\n", argv[1]);
return 1;
}
filename = malloc(strlen(argv[1]) + 5);
sprintf(filename, "%s.mid", argv[1]);
musData = malloc(status.st_size);
fread(musData, status.st_size, 1, file);
fclose(file);
size = status.st_size;
midData = mus2midi(musData, &size);
free(musData);
if (midData == NULL)
printf("MUS file is corrupted or invalid\n");
else
{
printf("Completed successfully\n");
file = fopen(filename, "wb");
fwrite(midData, size, 1, file);
fclose(file);
free(midData);
printf("MIDI file written to %s\n", filename);
}
free(filename);
return 0;
}
// mus2midi