main.c
3.46 KB
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
/*
* Main, initialization, error routines
*/
#include "ic.h"
#include "y.tab.h"
/* Global variables */
struct decl *errortype; /* for use as dummy decl when error in parse */
struct decl *errorvar;
struct id *returnid; /* fake return variable for functions. */
int verbose = FALSE; /* verbose output flag */
void initreserved(void)
{
enter(use, "use", 3);
enter(bank, "bank", 4);
enter(program, "program", 7);
enter(instrument, "instrument", 10);
enter(sound, "sound", 5);
enter(wavetable, "wavetable", 9);
enter(volume, "volume", 6);
enter(pan, "pan", 3);
enter(keymap, "keymap", 6);
enter(keyMin, "keyMin", 6);
enter(keyMax, "keyMax", 6);
enter(keyBase, "keyBase", 7);
enter(velocityMin, "velocityMin", 11);
enter(velocityMax, "velocityMax", 11);
enter(detune, "detune", 6);
enter(envelope, "envelope", 8);
enter(attackTime, "attackTime", 10);
enter(attackVolume, "attackVolume", 9);
enter(decayTime, "decayTime", 9);
enter(decayVolume, "decayVolume", 8);
enter(releaseTime, "releaseTime", 11);
enter(releaseVolume, "releaseVolume", 10);
}
void pline(void)
{
fprintf(stdout, "Line %d: ", yylineno);
}
void yyerror(char *s)
{
pline();
fprintf(stdout, "%s: ", s);
fprintf(stdout, "Last token was %s\n", yytext);
}
/* Initialize some base types. Set globals */
void inittypes(void)
{
}
void initoutput(void)
{
}
static char usage[] = "[-verbose] infile";
FILE *bnkFile;
FILE *tblFile;
main(int argc, char **argv)
{
extern char *optarg;
extern int optind;
int errflg=0;
int c;
int return_val;
char *ofile;
char *bfname;
char *tfname;
/*
* process command line arguments
*/
while ((c = getopt(argc, argv, "vo:")) != EOF) {
switch (c) {
case 'v':
verbose = TRUE;
break;
case 'o':
ofile = optarg;
break;
case '?':
errflg++;
break;
}
}
if (!freopen(argv[optind],"r", stdin)) {
fprintf(stderr, "%s: could not open [%s] for input\n",argv[0], argv[optind]);
exit(-1);
}
if (ofile == NULL){
bnkFile = fopen("tst.bnk", "w");
tblFile = fopen("tst.tbl", "w");
} else {
bfname = (char *) malloc(strlen(ofile)+5);
tfname = (char *) malloc(strlen(ofile)+5);
strcpy(bfname, ofile);
strcpy(tfname, ofile);
strcat(bfname, ".bnk");
strcat(tfname, ".tbl");
if ((bnkFile = fopen(bfname, "w")) == NULL){
fprintf(stderr,"%s: could not open [%s] for output\n",argv[0], bfname);
exit(-1);
}
if ((tblFile = fopen(tfname, "w")) == NULL){
fprintf(stderr,"%s: could not open [%s] for output\n",argv[0], tfname);
exit(-1);
}
}
/*
* init the world
*/
initLex();
initsymtab();
initreserved();
inittypes();
initoutput();
declInit();
/*
* parse the file
*/
return_val = yyparse();
/*
* lay out the file image by taking a pass through the data and
* marking the offsets
*/
doLayOut();
if (verbose) {
doPrint();
}
doWrite(bnkFile);
return(return_val);
}