forked from mandovinnie/Lute-Tab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_t.cc
241 lines (222 loc) · 5.57 KB
/
get_t.cc
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
This program is copyright 1991 by Wayne Cripps,
P.O. Box 677 Hanover N.H. 03755.
All rights reserved. It is supplied "as is"
without express or implied warranty.
Permission is granted to use, copy, modify and distribute
this software without fee, provided that this notice appears
in all copies, and that a copy of this notice is provided to
anyone who recieves a binary copy without sources.
This software may not be used for commercial purposes
without explicit, prior written permission.
Please mail bug reports, suggestions, and improvements
*/
#include "win.h"
#include "tab.h"
#include "file_in.h"
#include "i_buf.h"
#include "system.h"
void include(i_buf *ib, struct file_info *f, char file []);
int getsystem(file_in *fi, i_buf *ib, struct file_info *f, char buf[]);
void args_from_string(char *buf, struct file_info *f);
void get_tab_file(file_in *fi, i_buf *ib, struct file_info *f);
int setflag(file_info *f, char * string, pass pass);
int badchar(unsigned char p) {
if ( p == 255 )
return (0);
else if ((int)p > 127)
return (1);
else if ( p == '\n' )
return (0);
else if (strchr("{%PLJWw0123456xYyQqeMSkbBiIp8vV .-\n\r*$[F#CcRAT!", p))
return(0);
return(1);
}
/* static struct file_info *ff; */
void get_tab_file(file_in *fi, i_buf *ib, struct file_info *f)
{
char *p, *pp;
int r;
char buf[BUFSIZ];
int square_bracket=0;
/* ff = f; */
while (1) {
fi->GetLine(buf, sizeof(buf));
dbg1 (Flow, "tab: get_tab_file: %s", (void *)buf);
p = buf;
// test to see if this is valid tab file stuff
// printf("buf %s", buf );
if ( badchar((unsigned char)*p) ) {
dbg2(Error, "Bad character-%c-%x, this may not be a valid tab file\n",
(void *)*p, (void *)*p);
}
if (! strncmp(buf, "Content-Type: text/plain", 24 )) {
printf("get_t: get_tab_file: Content-Type: text/plain\n"/* , buf */);
continue;
}
if (! strncmp(buf, "Content-Type: text/html", 22 )) {
// we should not get text/html stuff
// we should exit here
printf("get_t: get_tab_file: Content-Type: text/html\n");
ib->PutByte(NEWLINE);
return;
}
if (! strncmp(buf, "Content-Transfer-Encoding: quoted-printable", 43 )) {
printf(
"get_t: get_tab_file: Content-Transfer-Encoding: quoted-printable\n" /*, buf */ );
continue;
}
switch (*p) {
case '-': /* these flags are set before inter file */
switch (buf[1]) { /* these flags are set for the whole */
case 'a':
// printf("get_t: buf %s\n", &buf[1]);
if (!strncmp(&buf[1], "autoKey", 7)) {
goto end;
}
else if (!strncmp(&buf[1], "allDsup", 7)) {
// printf("allDsup\n");
goto end;
}
else if (!strncmp(&buf[1], "allDsdown", 9)) {
// printf("allDsdown\n");
goto end;
}
do {
ib->PutByte(*p);
p++;
} while (*p != NEWLINE);
ib->PutByte(NEWLINE);
break;
case 't':
if (!strncmp(&buf[1], "twostaff", 8) ||
!strncmp(&buf[1], "twelvedots", 10) ||
!strncmp(&buf[1], "tuning", 6) ||
!strncmp(&buf[1], "thin", 4)) {
goto end;
}
break;
case 'e': /* printout! */
case 'b': /* baroque uses different font files */
case 'E':
case 'G': /* copyright */
case 'h': /* flakey behavior */
case 'H': /* h cant be turned off */
case 'j':
case '6':
case 'R':
case 'p':
case 'w':
case 'W':
case 'D':
// case '5':
// case '4':
end:
args_from_string(buf, f);
dbg2 ( Inter, "tab: get_tab_file: setting flag %s %c\n", buf, f);
p = buf;
break;
default:
do {
ib->PutByte(*p);
p++;
} while (*p != NEWLINE);
ib->PutByte(NEWLINE);
break;
}
break;
case 'V': /* pass this whole */
case 'F':
do {
ib->PutByte(*p);
p++;
} while (*p != NEWLINE );
ib->PutByte(NEWLINE);
break;
case '[':
square_bracket=1;
case '{':
do {
ib->PutByte(*p);
if (*p == NEWLINE) {
fi->GetLine(buf, sizeof(buf));
if ((unsigned)buf[0] == (unsigned)EOF) {
// surprise end of file
dbg0(Error, "Tab: Error: End of file within title\n");
}
p = buf;
}
else if ( *p == '\\') {
p++;
ib->PutByte(*p);
p++;
}
else
p++;
} while (*p != '}' && ! (square_bracket && *p==']') );
square_bracket=0;
ib->PutByte('}');
ib->PutByte(NEWLINE);
break;
case '\0':
case 'e':
if (!(f->flags & INCLUDE))
ib->PutByte('e');
ib->PutByte(NEWLINE);
return;
case 'p':
ib->PutByte('p'); ib->PutByte(NEWLINE);
break;
case NEWLINE:
case '\t':
case ' ':
break;
case '%':
break;
case 'I': /* include file */
{
p++; /* remove I */
while ( *p == ' ' )
p++;
pp = p;
while ( *pp != NEWLINE )
pp ++;
*pp = '\0';
include(/* fi, */ ib, f, p);
}
break;
case 'K':
ib->PutByte('K'); ib->PutByte(NEWLINE);
break;
case '$':
// code ripped out of getsystem.cc
{
int i, c, j=0;
char buffer[80];
char *bp;
bp = &buffer[0];
for (i=1; (c = buf[i]) != NEWLINE; i++) {
*bp=c;
bp++;
}
buffer[--i] = 0;
if (setflag(f, buffer, first))
break; // return if we set the flag
ib->PutByte('$');
while (j < i && buffer[j] != '\0') {
ib->PutByte(buffer[j++]);
}
ib->PutByte(NEWLINE);
}
break;
default: /* assume that it must be lines of chords */
r = getsystem(fi, ib, f, buf); /* get line tab */
f->cur_system++;
if (!r) {
return;
}
ib->PutByte(NEWLINE);
}
}
}