/
nrt_parse.c
76 lines (73 loc) · 1.71 KB
/
nrt_parse.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
69
70
71
72
73
74
75
76
#include "nrt_parse.h"
void printCSV(NRT_DATA *d)
{
NRT_NOTE *n = &d->note;
/* Make sure note isn't a rest first */
if(d->isRest == FALSE)
{
if(d->printNumber) {
fprintf(stdout, "%d%c", d->numNotes,
d->sep);
} fprintf(stdout, "%g%c%g%c%d\n",
n->time, d->sep, n->dur, d-> sep, n->solf);
}
}
int main(int argc, char **argv){
char *filename;
char *scorefile;
int c;
int index;
NRT_DATA d = createData(&printCSV);
nrtGlobalData = &d;
int csoundMode = FALSE;
int jsonMode = FALSE;
int readFromFile = TRUE;
char *expr;
while((c = getopt(argc, argv, "cjs:nF:")) != -1 )
{
switch(c)
{
case 'c': /* Deprecated */
csoundMode = TRUE;
break;
case 'j': /* Deprecated */
jsonMode = TRUE;
break;
case 's':
readFromFile = FALSE;
expr = optarg;
case 'n':
d.printNumber = TRUE;
break;
case 'F':
d.sep = optarg[0];
break;
}
}
if(readFromFile == TRUE)
{
filename = argv[optind];
if(csoundMode == TRUE){
scorefile = argv[optind + 1];
}
FILE *input = fopen(filename, "r");
if(!input)
{
//printf("Error! Cannot find file.\n");
nrtin = stdin;
readFromFile = FALSE;
//return -1;
}else{
nrtin = input;
}
do{
nrtparse();
}while(!feof(nrtin));
if(readFromFile) fclose(input);
}else{
nrt_scan_string(expr);
nrtparse();
}
printCSV(&d);
return 0;
}