[gaim-migrate @ 2952]
[pidgin-git.git] / sounds / au2h.c
blobe705168f4450b8510de414afe281828f5c931570
1 #include <stdio.h>
2 #if !(__GLIBC__ < 2)
3 #include <error.h>
4 #endif
5 #include <fcntl.h>
6 #include <unistd.h>
7 #include <stdlib.h>
8 #include <string.h>
10 #define BUF_SIZE 10
12 int main(int argc, char *argv[])
14 int fd;
15 FILE *f;
16 int res,x;
17 char buf[BUF_SIZE];
18 char file[256];
19 int offset = 0, cnt;
21 if (argc != 3) {
22 fprintf(stderr, "Too few arguments! Are you using gmake? If you're not, then you really should. :-) \n");
23 exit(1);
26 fd = open(argv[1], O_RDONLY);
27 if (fd < 0) {
28 perror("open");
29 exit(1);
31 f = fopen(argv[2], "w+");
32 if (!f) {
33 perror("fopen");
34 exit(1);
36 argv[1][strlen(argv[1])-3]='\0';
37 cnt = strlen(argv[1]);
38 while (offset != cnt) {
39 if (argv[1][cnt - offset] == '/') {
40 offset--;
41 break;
43 offset++;
45 sprintf(file, "%s", &argv[1][cnt - offset]);
46 fprintf(f, "static unsigned char %s[] = {\n", file);
47 read(fd, buf, 8); /* id & offset */
48 read(fd, buf, 8); /* len & encoding */
49 read(fd, buf, 8); /* rate & count */
50 /* no more click :) */
52 while((res = read(fd, buf, BUF_SIZE)) > 0) {
53 for (x=0;x<res;x++)
54 fprintf(f, "%#x, ", buf[x] & 0xff);
55 fprintf(f, "\n");
57 fprintf(f,"};\n");
58 fclose(f);
59 return 0;