67
67
static char compile[256]="";
69
69
static int ishex(char *s) {
71
if (*s!='0') return 0;
73
if (*s!='x') return 0;
77
if ((('A'<=c)&&(c<='F'))||
78
(('a'<=c)&&(c<='f'))||
79
(('0'<=c)&&(c<='9'))) s++;
71
if (*s!='0') return 0;
73
if (*s!='x') return 0;
77
if ((('A'<=c)&&(c<='F'))||
78
(('a'<=c)&&(c<='f'))||
79
(('0'<=c)&&(c<='9'))) s++;
85
85
static int isnum(char *s) {
89
if (('0'<=c)&&(c<='9')) s++;
89
if (('0'<=c)&&(c<='9')) s++;
95
95
int numeric(char *s) {
98
if (s==NULL) return 0;
100
r=strtol(s, NULL, 16);
101
} else if (isnum(s)) {
102
r=strtol(s, NULL, 10);
104
sprintf(msg, "Expected a number, got %s instead", s);
98
if (s==NULL) return 0;
100
r=strtol(s, NULL, 16);
101
} else if (isnum(s)) {
102
r=strtol(s, NULL, 10);
104
sprintf(msg, "Expected a number, got %s instead", s);
111
111
static int get_device(char *s) {
113
if (s==NULL) report("Device expected!");
114
if (strcmp(s, "joyaxis")==0) return DEVICE_JOYSTICK;
115
if (strcmp(s, "joybtn")==0) return DEVICE_JOYSTICK;
116
if (strcmp(s, "joystick")==0) return DEVICE_JOYSTICK;
117
if (strcmp(s, "kbd")==0) return DEVICE_KBD;
118
if (strcmp(s, "mouse")==0) return DEVICE_MOUSE;
119
sprintf(msg, "Expecting a device type:joyaxis,joybtn,joystick,kbd,mouse. Found %s instead", s);
113
if (s==NULL) report("Device expected!");
114
if (strcmp(s, "joyaxis")==0) return DEVICE_JOYSTICK;
115
if (strcmp(s, "joybtn")==0) return DEVICE_JOYSTICK;
116
if (strcmp(s, "joystick")==0) return DEVICE_JOYSTICK;
117
if (strcmp(s, "kbd")==0) return DEVICE_KBD;
118
if (strcmp(s, "mouse")==0) return DEVICE_MOUSE;
119
sprintf(msg, "Expecting a device type:joyaxis,joybtn,joystick,kbd,mouse. Found %s instead", s);
124
124
static int get_type(char *s, dictionary d) {
126
if (s==NULL) return 255;
127
if (strcmp(s, "joyaxis")==0) return TYPE_AXIS;
128
if (strcmp(s, "joybtn")==0) return TYPE_BUTTON;
129
button=lookup_dictionary(d, "button");
130
axis=lookup_dictionary(d, "axis");
131
if ((button!=NULL)&&(axis!=NULL)) {
132
report("Only one of the keys 'button' and 'axis' may be specified");
135
if (button!=NULL) return TYPE_BUTTON;
136
if (axis!=NULL) return TYPE_AXIS;
126
if (s==NULL) return 255;
127
if (strcmp(s, "joyaxis")==0) return TYPE_AXIS;
128
if (strcmp(s, "joybtn")==0) return TYPE_BUTTON;
129
button=lookup_dictionary(d, "button");
130
axis=lookup_dictionary(d, "axis");
131
if ((button!=NULL)&&(axis!=NULL)) {
132
report("Only one of the keys 'button' and 'axis' may be specified");
135
if (button!=NULL) return TYPE_BUTTON;
136
if (axis!=NULL) return TYPE_AXIS;
140
140
static int parse_flags(char *s) {
145
if (s==NULL) return flags;
147
while ((*p!='\0')&&(*p!=',')&&(*p!=';')) p++;
148
if (*p=='\0') more=0;
150
if (strcmp(s, "autorelease")==0) flags|=FLAG_AUTO_RELEASE;
151
else if (strcmp(s, "release")==0) flags|=FLAG_RELEASE;
152
else if (strcmp(s, "press")==0) flags|=FLAG_PRESS;
153
else if (strcmp(s, "shift")==0) flags|=FLAG_SHIFT;
154
else if (strcmp(s, "invert")==0) flags|=FLAG_INVERT;
156
sprintf(msg, "Unknown flag %s", s);
145
if (s==NULL) return flags;
147
while ((*p!='\0')&&(*p!=',')&&(*p!=';')) p++;
148
if (*p=='\0') more=0;
150
if (strcmp(s, "autorelease")==0) flags|=FLAG_AUTO_RELEASE;
151
else if (strcmp(s, "release")==0) flags|=FLAG_RELEASE;
152
else if (strcmp(s, "press")==0) flags|=FLAG_PRESS;
153
else if (strcmp(s, "shift")==0) flags|=FLAG_SHIFT;
154
else if (strcmp(s, "invert")==0) flags|=FLAG_INVERT;
156
sprintf(msg, "Unknown flag %s", s);
164
164
static void parse_sequence(__u16 *sequence, char *s, int base, int type) {
173
if ((base==DEVICE_JOYSTICK)&&(type==TYPE_BUTTON)) {
175
} else if ((base==DEVICE_MOUSE)&&(type==TYPE_BUTTON)) {
178
sequence[0]=numeric(s)+base;
179
sequence[1]=SEQUENCE_DONE;
184
while ((*p!='\0')&&(isspace(*p))) p++;
186
while ((*p!='\0')&&(!(isspace(*p)))) p++;
192
if (strcmp(s, "REL")==0) releaseflag=RELEASEMASK;
195
while (keymap[i].value!=-1) {
196
if (strcmp(keymap[i].key, s)==0)
197
value=keymap[i].value;
202
sprintf(msg, "Unknown key %s", s);
205
sequence[n]=value|releaseflag;
212
sequence[n]=SEQUENCE_DONE;
173
if ((base==DEVICE_JOYSTICK)&&(type==TYPE_BUTTON)) {
175
} else if ((base==DEVICE_MOUSE)&&(type==TYPE_BUTTON)) {
178
sequence[0]=numeric(s)+base;
179
sequence[1]=SEQUENCE_DONE;
184
while ((*p!='\0')&&(isspace(*p))) p++;
186
while ((*p!='\0')&&(!(isspace(*p)))) p++;
192
if (strcmp(s, "REL")==0) releaseflag=RELEASEMASK;
195
while (keymap[i].value!=-1) {
196
if (strcmp(keymap[i].key, s)==0)
197
value=keymap[i].value;
202
sprintf(msg, "Unknown key %s", s);
205
sequence[n]=value|releaseflag;
212
sequence[n]=SEQUENCE_DONE;
216
216
static void show_dictionary(dictionary dict) {
219
entry=get_current(d);
220
while (entry!=NULL) {
221
printf("%s ", entry);
223
entry=get_current(d);
219
entry=get_current(d);
220
while (entry!=NULL) {
221
printf("%s ", entry);
223
entry=get_current(d);
227
227
static int has_required(dictionary dict, ...) {
234
s=va_arg(ap, char *);
236
entry=lookup_dictionary(dict, s);
238
sprintf(msg, "Missing key:%s", s);
240
printf("Defined keys: ");
241
show_dictionary(dict);
246
s=va_arg(ap, char *);
234
s=va_arg(ap, char *);
236
entry=lookup_dictionary(dict, s);
238
sprintf(msg, "Missing key:%s", s);
240
printf("Defined keys: ");
241
show_dictionary(dict);
246
s=va_arg(ap, char *);
252
252
void report(char *message) {
254
fprintf(stderr, "%d:%d %s.\n", line, cpos, message);
254
fprintf(stderr, "%d:%d %s.\n", line, cpos, message);
257
257
void reportline(int line, int cpos, char *message) {
259
fprintf(stderr, "%d:%d %s.\n", line, cpos, message);
259
fprintf(stderr, "%d:%d %s.\n", line, cpos, message);
263
if (nextchar!=NONE) return nextchar;
264
nextchar=fgetc(pfile);
263
if (nextchar!=NONE) return nextchar;
264
nextchar=fgetc(pfile);
269
if (nextchar=='\n') {
269
if (nextchar=='\n') {
283
283
static struct token newline() {
288
strcpy(t.value, "\n");
288
strcpy(t.value, "\n");
293
293
static struct token eof() {
298
strcpy(t.value, "end of file");
298
strcpy(t.value, "end of file");
302
302
static void parse_comment() {
303
//first character was #
307
while ((nc!='\n')&&(nc!=EOF)) {
303
//first character was #
307
while ((nc!='\n')&&(nc!=EOF)) {
313
313
static void skipwhite() {
315
while (isspace(nc)&&(nc!='\n')) {
315
while (isspace(nc)&&(nc!='\n')) {
321
321
static struct token parse_string() {
322
//opening quote has been read
323
//read until closing quote
322
//opening quote has been read
323
//read until closing quote
335
report("Unexpected end of file while parsing a string literal");
335
report("Unexpected end of file while parsing a string literal");
345
345
static struct token parse_value(struct token t, int pos) {
350
while (isalnum(nc)||(nc==',')||(nc==';')) {
358
while (reserved[nc].token!=NULL) {
359
if (strcmp(reserved[nc].token, t.value)==0) {
360
t.type=reserved[nc].value;
350
while (isalnum(nc)||(nc==',')||(nc==';')) {
358
while (reserved[nc].token!=NULL) {
359
if (strcmp(reserved[nc].token, t.value)==0) {
360
t.type=reserved[nc].value;
368
368
static struct token parse_id(struct token t, int pos) {
372
while (isalnum(nc)||(nc=='_')) {
380
report("Expected an \"=\"");
372
while (isalnum(nc)||(nc=='_')) {
380
report("Expected an \"=\"");
386
386
static struct token parse_id_or_value() {
395
if (nc=='_') return parse_id(t, pos);
396
if (nc=='=') return parse_id(t, pos);
397
if (nc==',') return parse_value(t, pos);
398
if (nc==';') return parse_value(t, pos);
402
if (nc=='=') return parse_id(t, pos);
405
return parse_value(t, pos);
410
sprintf(message, "Unexpected character \"%c\".", nc);
395
if (nc=='_') return parse_id(t, pos);
396
if (nc=='=') return parse_id(t, pos);
397
if (nc==',') return parse_value(t, pos);
398
if (nc==';') return parse_value(t, pos);
402
if (nc=='=') return parse_id(t, pos);
405
return parse_value(t, pos);
410
sprintf(message, "Unexpected character \"%c\".", nc);
424
424
static struct token maptoken() {
433
else if ((nc!='\n')&&isspace(nc))
437
if (nc=='\n') return newline();
438
if (nc==EOF) return eof();
439
if (nc=='"') return parse_string();
440
if (nc==',') return parse_value(t,0);
441
if (nc==';') return parse_value(t,0);
442
if (nc=='_') return parse_value(t,0);
443
if (isdigit(nc)) return parse_value(t,0);
444
if (isalnum(nc)) return parse_id_or_value();
445
sprintf(message, "Unexpected character \"%c\".", nc);
433
else if ((nc!='\n')&&isspace(nc))
437
if (nc=='\n') return newline();
438
if (nc==EOF) return eof();
439
if (nc=='"') return parse_string();
440
if (nc==',') return parse_value(t,0);
441
if (nc==';') return parse_value(t,0);
442
if (nc=='_') return parse_value(t,0);
443
if (isdigit(nc)) return parse_value(t,0);
444
if (isalnum(nc)) return parse_id_or_value();
445
sprintf(message, "Unexpected character \"%c\".", nc);
456
456
struct token (*tokenizer)()=NULL;
457
457
static struct token nexttoken;
458
458
struct token peektoken() {
459
if (nexttoken.type!=NONE) return nexttoken;
460
nexttoken=tokenizer();
459
if (nexttoken.type!=NONE) return nexttoken;
460
nexttoken=tokenizer();
464
464
void eattoken() {
465
if (nexttoken.type!=EOF) nexttoken.type=NONE;
465
if (nexttoken.type!=EOF) nexttoken.type=NONE;
468
468
struct token readtoken() {
475
475
void init_tokenizer() {
482
482
static int known_key(char *s) {
485
while (known_keys[i]!=NULL) {
486
if (strcmp(known_keys[i], s)==0) return 1;
485
while (known_keys[i]!=NULL) {
486
if (strcmp(known_keys[i], s)==0) return 1;
492
492
static void parse_valuepairs() {
497
while ((key.type!=NL)||(key.type!=EOF)) {
498
if (key.type==NL) break;
499
if (key.type==EOF) break;
501
if (!known_key(key.value)) {
502
sprintf(message, "Unknown key \"%s\"", key.value);
503
reportline(key.line, key.pos, message);
506
if ((value.type==STRING)||(value.type==VALUE)) {
507
dict=add_entry(dict, key.value, value.value);
509
sprintf(message, "Unexpected token \"%s\"", value.value);
510
reportline(value.line, value.pos, message);
513
sprintf(message, "Unexpected token \"%s\"", key.value);
514
reportline(key.line, key.pos, message);
497
while ((key.type!=NL)||(key.type!=EOF)) {
498
if (key.type==NL) break;
499
if (key.type==EOF) break;
501
if (!known_key(key.value)) {
502
sprintf(message, "Unknown key \"%s\"", key.value);
503
reportline(key.line, key.pos, message);
506
if ((value.type==STRING)||(value.type==VALUE)) {
507
dict=add_entry(dict, key.value, value.value);
509
sprintf(message, "Unexpected token \"%s\"", value.value);
510
reportline(value.line, value.pos, message);
513
sprintf(message, "Unexpected token \"%s\"", key.value);
514
reportline(key.line, key.pos, message);
520
520
static void parse_shift() {
525
//show_dictionary(dict);
527
id=lookup_dictionary(dict, "id");
528
vendor=lookup_dictionary(dict, "vendor");
529
product=lookup_dictionary(dict, "product");
530
src=lookup_dictionary(dict, "src");
531
if ((id==NULL)&&((vendor==NULL)||(product==NULL))) {
532
reportline(t.line, t.pos, "Must have id, or vendor and product");
534
if (has_required(dict, "src", NULL)) {
535
map.program=PROGRAM_BUTTON_REMAP;
537
map.joystick=numeric(id);
540
map.vendor=numeric(vendor);
541
map.product=numeric(product);
542
map.srcbutton=numeric(src);
545
buttons[nbuttons]=map;
549
free_dictionary(dict);
525
//show_dictionary(dict);
527
id=lookup_dictionary(dict, "id");
528
vendor=lookup_dictionary(dict, "vendor");
529
product=lookup_dictionary(dict, "product");
530
src=lookup_dictionary(dict, "src");
531
if ((id==NULL)&&((vendor==NULL)||(product==NULL))) {
532
reportline(t.line, t.pos, "Must have id, or vendor and product");
534
if (has_required(dict, "src", NULL)) {
535
map.program=PROGRAM_BUTTON_REMAP;
537
map.joystick=numeric(id);
540
map.vendor=numeric(vendor);
541
map.product=numeric(product);
542
map.srcbutton=numeric(src);
545
buttons[nbuttons]=map;
549
free_dictionary(dict);
553
553
static void parse_script() {
558
//show_dictionary(dict);
560
id=lookup_dictionary(dict, "id");
561
vendor=lookup_dictionary(dict, "vendor");
562
product=lookup_dictionary(dict, "product");
563
device=lookup_dictionary(dict, "device");
564
if ((id==NULL)&&((vendor==NULL)||(product==NULL))) {
565
reportline(t.line, t.pos, "Must have id, or vendor and product");
567
if (has_required(dict, "device", NULL)) {
569
script.id=numeric(id);
572
script.vendor=numeric(vendor);
573
script.product=numeric(product);
574
script.device=numeric(device);
575
scriptassign[nscript]=script;
579
free_dictionary(dict);
558
//show_dictionary(dict);
560
id=lookup_dictionary(dict, "id");
561
vendor=lookup_dictionary(dict, "vendor");
562
product=lookup_dictionary(dict, "product");
563
device=lookup_dictionary(dict, "device");
564
if ((id==NULL)&&((vendor==NULL)||(product==NULL))) {
565
reportline(t.line, t.pos, "Must have id, or vendor and product");
567
if (has_required(dict, "device", NULL)) {
569
script.id=numeric(id);
572
script.vendor=numeric(vendor);
573
script.product=numeric(product);
574
script.device=numeric(device);
575
scriptassign[nscript]=script;
579
free_dictionary(dict);
583
583
static void parse_button() {
588
id=lookup_dictionary(dict, "id");
589
vendor=lookup_dictionary(dict, "vendor");
590
product=lookup_dictionary(dict, "product");
591
src=lookup_dictionary(dict, "src");
592
target=lookup_dictionary(dict, "target");
593
button=lookup_dictionary(dict, "button");
594
axis=lookup_dictionary(dict, "axis");
595
device=lookup_dictionary(dict, "device");
596
flags=lookup_dictionary(dict, "flags");
597
if ((id==NULL)&&((vendor==NULL)||(product==NULL))) {
598
reportline(t.line, t.pos, "Must have id, or vendor and product");
600
if (has_required(dict, "src", "target", NULL)) {
602
//show_dictionary(dict);
604
map.program=PROGRAM_BUTTON_REMAP;
606
map.joystick=numeric(id);
609
map.vendor=numeric(vendor);
610
map.product=numeric(product);
611
base=get_device(target);
612
map.device=base+(numeric(device)&0xF);
613
map.type=get_type(target,dict);
614
if (base==DEVICE_JOYSTICK) {
617
report("Maximum of 8 joysticks allowed");
619
if (num>=njoysticks) {
622
if (map.type==TYPE_AXIS) {
623
if (joysticks[num].axes<=numeric(axis))
624
joysticks[num].axes=numeric(axis)+1;
626
if (map.type==TYPE_BUTTON) {
627
if (joysticks[num].buttons<=numeric(button))
628
joysticks[num].buttons=numeric(button)+1;
632
map.srcbutton=numeric(src)+BTN_JOYSTICK;
633
map.flags=parse_flags(flags);
635
parse_sequence(map.sequence, button, base, map.type);
637
parse_sequence(map.sequence, axis, base, map.type);
638
buttons[nbuttons]=map;
640
if (!((map.flags&FLAG_PRESS)||(map.flags&FLAG_RELEASE))&&
641
(map.sequence[1]==SEQUENCE_DONE)) {
642
if (map.sequence[0]&RELEASEMASK) {
643
map.sequence[0]&=~RELEASEMASK;
645
map.sequence[0]|=RELEASEMASK;
647
map.flags|=FLAG_RELEASE;
648
buttons[nbuttons]=map;
653
free_dictionary(dict);
588
id=lookup_dictionary(dict, "id");
589
vendor=lookup_dictionary(dict, "vendor");
590
product=lookup_dictionary(dict, "product");
591
src=lookup_dictionary(dict, "src");
592
target=lookup_dictionary(dict, "target");
593
button=lookup_dictionary(dict, "button");
594
axis=lookup_dictionary(dict, "axis");
595
device=lookup_dictionary(dict, "device");
596
flags=lookup_dictionary(dict, "flags");
597
if ((id==NULL)&&((vendor==NULL)||(product==NULL))) {
598
reportline(t.line, t.pos, "Must have id, or vendor and product");
600
if (has_required(dict, "src", "target", NULL)) {
602
//show_dictionary(dict);
604
map.program=PROGRAM_BUTTON_REMAP;
606
map.joystick=numeric(id);
609
map.vendor=numeric(vendor);
610
map.product=numeric(product);
611
base=get_device(target);
612
map.device=base+(numeric(device)&0xF);
613
map.type=get_type(target,dict);
614
if (base==DEVICE_JOYSTICK) {
617
report("Maximum of 8 joysticks allowed");
619
if (num>=njoysticks) {
622
if (map.type==TYPE_AXIS) {
623
if (joysticks[num].axes<=numeric(axis))
624
joysticks[num].axes=numeric(axis)+1;
626
if (map.type==TYPE_BUTTON) {
627
if (joysticks[num].buttons<=numeric(button))
628
joysticks[num].buttons=numeric(button)+1;
632
map.srcbutton=numeric(src)+BTN_JOYSTICK;
633
map.flags=parse_flags(flags);
635
parse_sequence(map.sequence, button, base, map.type);
637
parse_sequence(map.sequence, axis, base, map.type);
638
buttons[nbuttons]=map;
640
if (!((map.flags&FLAG_PRESS)||(map.flags&FLAG_RELEASE))&&
641
(map.sequence[1]==SEQUENCE_DONE)) {
642
if (map.sequence[0]&RELEASEMASK) {
643
map.sequence[0]&=~RELEASEMASK;
645
map.sequence[0]|=RELEASEMASK;
647
map.flags|=FLAG_RELEASE;
648
buttons[nbuttons]=map;
653
free_dictionary(dict);
657
657
static void parse_axis() {
663
//show_dictionary(dict);
665
id=lookup_dictionary(dict, "id");
666
vendor=lookup_dictionary(dict, "vendor");
667
product=lookup_dictionary(dict, "product");
668
src=lookup_dictionary(dict, "src");
669
target=lookup_dictionary(dict, "target");
670
axis=lookup_dictionary(dict, "axis");
671
plus=lookup_dictionary(dict, "plus");
672
minus=lookup_dictionary(dict, "minus");
673
device=lookup_dictionary(dict, "device");
674
flags=lookup_dictionary(dict, "flags");
675
if ((id==NULL)&&((vendor==NULL)||(product==NULL))) {
676
reportline(t.line, t.pos, "Must have id, or vendor and product");
678
if (has_required(dict, "src", "target", NULL)) {
679
amap.program=PROGRAM_AXIS_REMAP;
681
amap.joystick=numeric(id);
684
amap.vendor=numeric(vendor);
685
amap.product=numeric(product);
686
amap.srcaxis=numeric(src);
687
base=get_device(target);
688
amap.device=base+(numeric(device)&0xF);
689
amap.type=get_type(target,dict);
690
if (base==DEVICE_JOYSTICK) {
693
report("Maximum of 8 joysticks allowed");
695
if (num>=njoysticks) {
698
if (amap.type==TYPE_AXIS) {
699
if (joysticks[num].axes<=numeric(axis))
700
joysticks[num].axes=numeric(axis)+1;
702
if (amap.type==TYPE_BUTTON) {
703
if (joysticks[num].buttons<=numeric(plus))
704
joysticks[num].buttons=numeric(plus)+1;
705
if (joysticks[num].buttons<=numeric(minus))
706
joysticks[num].buttons=numeric(minus)+1;
710
if ((base==DEVICE_JOYSTICK)&&(amap.type==TYPE_BUTTON)) {
712
} else if ((base==DEVICE_MOUSE)&&(amap.type==TYPE_BUTTON)) {
715
amap.plus=numeric(plus)+base;
716
amap.minus=numeric(minus)+base;
717
amap.axis=numeric(axis);
718
amap.flags=parse_flags(flags);
723
free_dictionary(dict);
663
//show_dictionary(dict);
665
id=lookup_dictionary(dict, "id");
666
vendor=lookup_dictionary(dict, "vendor");
667
product=lookup_dictionary(dict, "product");
668
src=lookup_dictionary(dict, "src");
669
target=lookup_dictionary(dict, "target");
670
axis=lookup_dictionary(dict, "axis");
671
plus=lookup_dictionary(dict, "plus");
672
minus=lookup_dictionary(dict, "minus");
673
device=lookup_dictionary(dict, "device");
674
flags=lookup_dictionary(dict, "flags");
675
if ((id==NULL)&&((vendor==NULL)||(product==NULL))) {
676
reportline(t.line, t.pos, "Must have id, or vendor and product");
678
if (has_required(dict, "src", "target", NULL)) {
679
amap.program=PROGRAM_AXIS_REMAP;
681
amap.joystick=numeric(id);
684
amap.vendor=numeric(vendor);
685
amap.product=numeric(product);
686
amap.srcaxis=numeric(src);
687
base=get_device(target);
688
amap.device=base+(numeric(device)&0xF);
689
amap.type=get_type(target,dict);
690
if (base==DEVICE_JOYSTICK) {
693
report("Maximum of 8 joysticks allowed");
695
if (num>=njoysticks) {
698
if (amap.type==TYPE_AXIS) {
699
if (joysticks[num].axes<=numeric(axis))
700
joysticks[num].axes=numeric(axis)+1;
702
if (amap.type==TYPE_BUTTON) {
703
if (joysticks[num].buttons<=numeric(plus))
704
joysticks[num].buttons=numeric(plus)+1;
705
if (joysticks[num].buttons<=numeric(minus))
706
joysticks[num].buttons=numeric(minus)+1;
710
if ((base==DEVICE_JOYSTICK)&&(amap.type==TYPE_BUTTON)) {
712
} else if ((base==DEVICE_MOUSE)&&(amap.type==TYPE_BUTTON)) {
715
amap.plus=numeric(plus)+base;
716
amap.minus=numeric(minus)+base;
717
amap.axis=numeric(axis);
718
amap.flags=parse_flags(flags);
723
free_dictionary(dict);
727
727
static void parse_joystick() {
729
char *axes; char *buttons;
733
axes=lookup_dictionary(dict, "axes");
734
buttons=lookup_dictionary(dict, "buttons");
735
device=lookup_dictionary(dict, "device");
737
reportline(t.line, t.pos, "Must have device");
740
if ((num<0)||(num>7)) reportline(t.line, t.pos, "Joystick must be 0-7");
741
//printf("joystick ");
742
//show_dictionary(dict);
744
if (num>=njoysticks) njoysticks=num+1;
746
joysticks[num].axes=numeric(axes);
748
joysticks[num].axes=0;
750
joysticks[num].buttons=numeric(buttons);
752
joysticks[num].buttons=0;
754
free_dictionary(dict);
729
char *axes; char *buttons;
733
axes=lookup_dictionary(dict, "axes");
734
buttons=lookup_dictionary(dict, "buttons");
735
device=lookup_dictionary(dict, "device");
737
reportline(t.line, t.pos, "Must have device");
740
if ((num<0)||(num>7)) reportline(t.line, t.pos, "Joystick must be 0-7");
741
//printf("joystick ");
742
//show_dictionary(dict);
744
if (num>=njoysticks) njoysticks=num+1;
746
joysticks[num].axes=numeric(axes);
748
joysticks[num].axes=0;
750
joysticks[num].buttons=numeric(buttons);
752
joysticks[num].buttons=0;
754
free_dictionary(dict);
758
758
static void parse_code() {
763
if (t.type!=STRING) {
764
reportline(t.line, t.pos, "String expected");
765
} else strcpy(compile, t.value);
767
while ((t.type!=NL)&&(t.type!=EOF)) {
768
reportline(t.line, t.pos, "No further token expected on this line");
770
//printf("\"%s\"\n", compile);
763
if (t.type!=STRING) {
764
reportline(t.line, t.pos, "String expected");
765
} else strcpy(compile, t.value);
767
while ((t.type!=NL)&&(t.type!=EOF)) {
768
reportline(t.line, t.pos, "No further token expected on this line");
770
//printf("\"%s\"\n", compile);
773
773
static void parse_joysticks() {
778
printf("joysticks ");
780
reportline(t.line, t.pos, "Value expected");
781
} else num=numeric(t.value);
783
while ((t.type!=NL)&&(t.type!=EOF)) {
784
reportline(t.line, t.pos, "No further token expected on this line");
786
if (num<0) reportline(t.line, t.pos, "Only positive numbers allowed");
787
if (num>8) reportline(t.line, t.pos, "Maximum 8 joysticks allowed");
789
printf("\"%d\"\n", num);
778
printf("joysticks ");
780
reportline(t.line, t.pos, "Value expected");
781
} else num=numeric(t.value);
783
while ((t.type!=NL)&&(t.type!=EOF)) {
784
reportline(t.line, t.pos, "No further token expected on this line");
786
if (num<0) reportline(t.line, t.pos, "Only positive numbers allowed");
787
if (num>8) reportline(t.line, t.pos, "Maximum 8 joysticks allowed");
789
printf("\"%d\"\n", num);
792
792
static void parse_lines();
793
793
static void parse_include() {
795
char include[256]="";
799
//printf("include ");
800
if (t.type!=STRING) {
801
reportline(t.line, t.pos, "String expected");
802
} else strcpy(include, t.value);
804
while ((t.type!=NL)&&(t.type!=EOF)) {
805
reportline(t.line, t.pos, "No further token expected on this line");
807
//printf("\"%s\"\n", include);
809
pfile=fopen(include, "r");
810
if (pfile==NULL) reportline(t.line, t.pos, "Could not find specified file");
795
char include[256]="";
799
//printf("include ");
800
if (t.type!=STRING) {
801
reportline(t.line, t.pos, "String expected");
802
} else strcpy(include, t.value);
804
while ((t.type!=NL)&&(t.type!=EOF)) {
805
reportline(t.line, t.pos, "No further token expected on this line");
807
//printf("\"%s\"\n", include);
809
pfile=fopen(include, "r");
810
if (pfile==NULL) reportline(t.line, t.pos, "Could not find specified file");
815
815
static void parse_lines() {
819
while (t.type!=EOF) {
823
} else if (t.type==EOF) {
826
} else if (t.type==CODE) {
828
} else if (t.type==BUTTON) {
830
} else if (t.type==AXIS) {
832
} else if (t.type==SHIFT) {
834
} else if (t.type==SCRIPT) {
836
} else if (t.type==JOYSTICK) {
838
} else if (t.type==JOYSTICKS) {
840
} else if (t.type==INCLUDE) {
846
sprintf(message, "Unexpected token \"%s\"", t.value);
847
reportline(t.line, t.pos, message);
848
while ((t.type!=EOF)&&(t.type!=NL)) {
819
while (t.type!=EOF) {
823
} else if (t.type==EOF) {
826
} else if (t.type==CODE) {
828
} else if (t.type==BUTTON) {
830
} else if (t.type==AXIS) {
832
} else if (t.type==SHIFT) {
834
} else if (t.type==SCRIPT) {
836
} else if (t.type==JOYSTICK) {
838
} else if (t.type==JOYSTICKS) {
840
} else if (t.type==INCLUDE) {
846
sprintf(message, "Unexpected token \"%s\"", t.value);
847
reportline(t.line, t.pos, message);
848
while ((t.type!=EOF)&&(t.type!=NL)) {
857
857
int parse_map(void) {
862
free_dictionary(dict);
864
if (fmap!=stdin) fclose(fmap);
865
if (strlen(compile)>0) {
866
fprintf(stderr, "parsing program %s\n", compile);
867
if (parse_program(compile, &program)!=0) error=1;
862
free_dictionary(dict);
864
if (fmap!=stdin) fclose(fmap);
865
if (strlen(compile)>0) {
866
fprintf(stderr, "parsing program %s\n", compile);
867
if (parse_program(compile, &program)!=0) error=1;