1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5
6 #include "general.h"
7 #include "fileoutput.h"
8
9 /*
10
11 Ringtone Tools - Copyright 2001-2005 Michael Kohn (mike@mikekohn.net)
12 This falls under the Kohnian license. Please read
13 it at http://ringtonetools.mikekohn.net/
14
15 This program is NOT opensourced. You may not use any part
16 of this program for your own software.
17
18 */
19
getnext(FILE * in)20 int getnext(FILE *in)
21 {
22 int ch;
23
24 while(1)
25 {
26 ch=getc(in);
27
28 if (ch==' ' || ch=='\t' || ch=='\n' || ch=='\r')
29 { continue; }
30 else
31 { return tolower(ch); }
32 }
33
34 return 0;
35 }
36
parse_siemens(FILE * in,FILE * out,int out_type,struct note_t * note)37 int parse_siemens(FILE *in, FILE *out, int out_type, struct note_t *note)
38 {
39 char token[16];
40 int t,ch,ptr;
41
42 check_songname(in,note->songname);
43
44 #ifdef DEBUG
45 printf("\n Song Name: %s\n",note->songname);
46 #endif
47
48 header_route(out,note,7,out_type);
49 note->modifier=0;
50
51 while(1)
52 {
53 note->tone=-1;
54 note->scale=0;
55 note->length=2;
56
57 ch=getnext(in);
58 if (ch==EOF) break;
59
60 if (ch=='p') note->tone=0;
61 else
62 if (ch=='c') note->tone=1;
63 else
64 if (ch=='d') note->tone=3;
65 else
66 if (ch=='e') note->tone=5;
67 else
68 if (ch=='f') note->tone=6;
69 else
70 if (ch=='g') note->tone=8;
71 else
72 if (ch=='a') note->tone=10;
73 else
74 if (ch=='b' || ch=='h') note->tone=12;
75
76 ch=getnext(in);
77 if (note->tone!=0)
78 {
79 if (ch==EOF) break;
80
81 if (ch=='i')
82 {
83 ch=getnext(in);
84 if (ch==EOF) break;
85 if (ch!='s') printf("Error: expecting 's'\n");
86 note->tone++;
87
88 ch=getnext(in);
89 if (ch==EOF) break;
90 }
91
92 if (ch>='0' && ch<='9')
93 {
94 note->scale=(ch-'0');
95 ch=getnext(in);
96 if (ch==EOF) break;
97 }
98 else
99 { note->scale=0; }
100 }
101
102 if (ch=='(')
103 {
104 ptr=0;
105
106 while(1)
107 {
108 ch=getnext(in);
109 if (ch==EOF) break;
110 if (ch=='/' || ch==')') break;
111 }
112 if (ch==EOF) break;
113
114 ptr=0;
115 while(1)
116 {
117 ch=getnext(in);
118 if (ch==EOF) break;
119 if (ch==')') break;
120 if (ch>='0' && ch<='9') token[ptr++]=ch;
121 if (ptr>2) break;
122 }
123 token[ptr]=0;
124
125 t=atoi(token);
126 if (t>32) t=32;
127
128 if (t==1) note->length=0;
129 else
130 if (t==2) note->length=1;
131 else
132 if (t==4) note->length=2;
133 else
134 if (t==8) note->length=3;
135 else
136 if (t==16) note->length=4;
137 else
138 if (t==32) note->length=5;
139
140 if (ch==EOF) break;
141 }
142 else
143 {
144 ungetc(ch,in);
145 }
146
147 note_route(out,note,7,out_type);
148 }
149
150 if (note->tone!=-1) note_route(out,note,0,out_type);
151
152 footer_route(out,note,7,out_type);
153
154 return (0);
155 }
156
157
158
159