-
Notifications
You must be signed in to change notification settings - Fork 3
/
res.cpp
1686 lines (1636 loc) · 48.9 KB
/
res.cpp
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define _RES_
#include <fcntl.h> /* O_ constant definitions */
#include <sys/stat.h>
#ifndef _MSC_VER
#include <unistd.h>
#else
#include <io.h>
#endif
#ifdef __CONSOLE__
#include <windows.h>
#else
#include <wchar.h>
//#include <mbctype.h>
#endif
#include "misc.h"
#include "res.h"
#include "tok.h"
RES *listres; //таблица ресурсов
unsigned int numres = 0; //текущее число ресурсов
unsigned int maxres = 0; //максимальное число ресурсов
unsigned short *sortidx; //масив отсортированых индексов ресурсов
RES *curtres; //текущая таблица ресурсов
unsigned char *resbuf;
unsigned int cursizeresbuf;
unsigned int curposbuf = 0;
unsigned int iconcount = 0; //число иконок
unsigned int cursorcount = 0; //число курсоров
unsigned int numidres; //число ресурсов с разным id
unsigned int numlangres = 0; //число ресурсов с языками
unsigned int numhlangres = 0; //число узлов с языками
unsigned short langdef = 0;
unsigned short numzerotype = 0;
_STRINGS_ *strinfo = NULL;
unsigned int numstrtbl = 0;
struct TUSE {
unsigned short id;
unsigned short count;
char *tname; //имя типа
} *tuse = NULL;
unsigned int numtyperes = 0; //число типов ресурсов
void AddType(unsigned short type, char *tname = NULL) {
if (tuse == NULL) {
tuse = (TUSE *)MALLOC(sizeof(TUSE));
tuse->id = type;
tuse->count = 1;
if (type == 0)
tuse->tname = tname;
numtyperes = 1;
return;
}
for (unsigned int i = 0; i < numtyperes; i++) {
if (type == (tuse + i)->id) {
if (type == 0 && strcasecmp(tname, (tuse + i)->tname) != 0)
continue;
(tuse + i)->count++;
return;
}
}
tuse = (TUSE *)REALLOC(tuse, sizeof(TUSE) * (numtyperes + 1));
(tuse + numtyperes)->id = type;
(tuse + numtyperes)->count = 1;
if (type == 0)
(tuse + numtyperes)->tname = tname;
numtyperes++;
}
static unsigned int idnum;
static char idname[IDLENGTH];
static char resname[IDLENGTH];
static int restok;
void InitBufRes(); //инициализировать буфер для ресурса
void CheckResBuf(unsigned int size); //проверить и если надо увеличить буфер
void AddWString(unsigned char *name); //добавить строку в ресурс
void AddNumOrd(unsigned char *name); //добавить ординал/строку
void r_Accelerators();
void r_Dialog();
void r_Icon();
void r_Bitmap();
void r_Menu();
void r_Cursor();
void r_Accelerators();
void r_Font();
void r_Stringtable();
void r_Rcdata();
void GetFileName(char *name);
unsigned char *LoadFileBin(char *name);
unsigned short GetFlag(_STRINGS_ *type, int num);
void r_Language();
void r_Version();
void NewResourse();
void badformat(char *name) {
char buf[80];
sprintf(buf, "bad format in '%s'", name);
preerror(buf);
while (tok != tk_endline && tok != tk_eof)
nexttok();
}
void expectedrescommand() {
preerror("expected resourse command");
while (tok != tk_endline && tok != tk_eof)
nexttok();
}
void equalres() { preerror("two resource with equal 'id'"); }
void badico() {
preerror("not load binare image");
while (tok != tk_endline && tok != tk_eof)
nexttok();
}
extern int CheckResName(char *name);
/*
void SaveFile(char *name)
{
FILE *inih;
if((inih=fopen(name,"wb"))!=NULL){
fwrite(resbuf,1,curposbuf,inih);
fclose(inih);
}
} */
void input_res() {
scanlexmode = RESLEX;
nexttok();
while (tok != tk_eof) {
while (tok == tk_semicolon || tok == tk_endline)
nexttok();
while (tok == tk_question) {
directive(); //обработка директив
while (tok == tk_semicolon || tok == tk_endline)
nexttok();
}
if (scanlexmode != RESLEX || tok == tk_eof)
break;
idname[0] = 0;
resname[0] = 0;
idnum = 0;
restok = -1;
switch (tok) {
case tk_number:
idnum = itok.number;
nexttok();
break;
case tk_id:
case tk_ID:
strcpy(idname, itok.name);
cmm_strupr(idname);
nexttok();
break;
case tk_rescommand:
restok = itok.number;
nexttok();
break;
default:
// printf("line %u:
// tok=%u\n",linenumber,tok);
unuseableinput();
break;
}
if (restok == -1) {
if (tok == tk_number)
restok = CRT_NEWRESOURCE;
else if (tok != tk_rescommand) {
if (strlen(itok.name) /*&&tok2==tk_string*/) {
restok = 0;
strcpy(resname, itok.name);
nexttok();
NewResourse();
continue;
}
expectedrescommand();
} else {
restok = itok.number;
nexttok();
}
}
switch (restok) {
case rc_accelerators:
r_Accelerators();
break;
case rc_dialogex:
case rc_dialog:
r_Dialog();
break;
case rc_icon:
r_Icon();
break;
case rc_bitmap:
r_Bitmap();
break;
case rc_menuex:
case rc_menu:
r_Menu();
break;
case rc_cursor:
r_Cursor();
break;
case rc_font:
r_Font();
break;
case rc_stringtable:
r_Stringtable();
break;
case rc_rcdata:
r_Rcdata();
break;
case rc_language:
r_Language();
break;
case rc_versioninfo:
r_Version();
break;
case CRT_NEWRESOURCE:
restok = itok.number;
nexttok();
NewResourse();
break;
default:
expectedrescommand();
nexttok();
break;
}
}
}
void GetResBlock() {
if (numres == 0) {
maxres = DRESNUM;
listres = (RES *)MALLOC(DRESNUM * sizeof(RES));
memset(listres, 0, DRESNUM * sizeof(RES)); //очистить таблицу
} else {
if ((numres + 1) == maxres) {
listres = (RES *)REALLOC(listres, sizeof(RES) * (maxres + DRESNUM));
memset(listres + maxres, 0, DRESNUM * sizeof(RES)); //очистить таблицу
maxres += DRESNUM;
}
}
curtres = listres + numres;
curtres->lang = langdef;
numres++;
}
int OpenBlock() {
while (tok == tk_endline)
nexttok();
if (tok == tk_openbrace ||
(tok == tk_rescommand && itok.number == rc_begin)) {
nexttok();
while (tok == tk_endline)
nexttok();
return TRUE;
}
return FALSE;
}
int CloseBlock() {
while (tok == tk_endline)
nexttok();
if (tok == tk_closebrace || (tok == tk_rescommand && itok.number == rc_end)) {
nexttok();
while (tok == tk_endline)
nexttok();
return TRUE;
}
return FALSE;
}
unsigned int GetNumber(int par) {
unsigned int num = 0;
if (tok == tk_number || (tok == tk_minus && tok2 == tk_number))
num = doconstdwordmath();
else {
numexpected(par);
nexttok();
}
return num;
}
void GetOrdinal(unsigned char **name, int par) {
NameOrdinal Temp;
if (tok == tk_number) {
Temp.ordinal[0] = 0xffff;
Temp.ordinal[1] = (unsigned short)doconstdwordmath();
} else if (tok == tk_string) {
Temp.name = (unsigned char *)BackString((char *)string);
nexttok();
} else
numexpected(par);
*name = Temp.name;
}
void GetRectangle(unsigned char *buf, int par) {
int i;
for (i = 0; i < 4;) {
*(unsigned short *)&buf[i * 2] = (unsigned short)GetNumber(i + par);
i++;
if (tok == tk_endline)
break;
expecting(tk_camma);
}
if (i != 4)
preerror("expecting window rectangle (4 signed integers)");
}
void AddWString(unsigned char *name) {
unsigned int pos;
// unsigned char c;
if (name == NULL) {
CheckResBuf(2);
curposbuf += 2;
} else {
pos = (strlen((char *)name) + 1) * 3;
CheckResBuf(pos);
#ifdef __CONSOLE__
pos = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (char *)name, -1,
(wchar_t *)&resbuf[curposbuf], pos);
#else
pos = mbsrtowcs((wchar_t *)&resbuf[curposbuf], (char const **)&name, pos,
NULL) +
1;
#endif
curposbuf += pos * 2;
}
}
void AddNumOrd(unsigned char *name) {
NameOrdinal Temp;
Temp.name = name;
if (Temp.ordinal[0] == 0xFFFF) {
CheckResBuf(4);
*(unsigned short *)&resbuf[curposbuf] = Temp.ordinal[0];
*(unsigned short *)&resbuf[curposbuf + 2] = Temp.ordinal[1];
curposbuf += 4;
} else
AddWString(name);
}
void InitBufRes() {
resbuf = (unsigned char *)MALLOC(SIZERESBUF);
memset(resbuf, 0, SIZERESBUF); //очистить таблицу
curposbuf = 0;
cursizeresbuf = SIZERESBUF;
}
void CheckResBuf(unsigned int size) {
while ((size + curposbuf) >= cursizeresbuf) {
resbuf = (unsigned char *)REALLOC(resbuf, cursizeresbuf + SIZERESBUF);
memset(resbuf + cursizeresbuf, 0, SIZERESBUF); //очистить таблицу
cursizeresbuf += SIZERESBUF;
}
}
void FreeOrdinal(unsigned char *name) {
NameOrdinal Temp;
if (name) {
Temp.name = name;
if (Temp.ordinal[0] != 0xFFFF)
free(name);
}
}
unsigned short GetFlag(_STRINGS_ *type, int num) {
for (int i = 0; i < num; i++) {
if (strcasecmp(itok.name, (type + i)->id) == 0) {
return (type + i)->val;
}
}
return 0;
}
void r_Language() {
unsigned short langsec;
langdef = (unsigned short)GetNumber(1);
expecting(tk_camma);
langsec = (unsigned short)GetNumber(2) * langdef * 256;
langdef |= langsec;
while (tok != tk_endline && tok != tk_eof)
nexttok();
}
void r_Stringtable() {
#define MAXSTRTABINFO 64
static unsigned int maxstrinf = MAXSTRTABINFO;
int num;
unsigned int j;
if (strinfo == NULL)
strinfo = (_STRINGS_ *)MALLOC(sizeof(_STRINGS_) * MAXSTRTABINFO);
while (tok != tk_endline && tok != tk_eof)
nexttok();
if (!OpenBlock())
badformat("STRINGTABLE"); //добавить новую
do {
num = GetNumber(1);
for (j = 0; j < numstrtbl; j++) {
if (num == (strinfo + j)->val)
preerror("String ID is already used");
}
(strinfo + numstrtbl)->val = (short)num;
if (tok == tk_camma)
nexttok();
if (tok != tk_string)
badformat("STRINGTABLE");
(strinfo + numstrtbl)->id = BackString((char *)string);
nexttok();
numstrtbl++;
if (numstrtbl >= maxstrinf) {
maxstrinf += MAXSTRTABINFO;
strinfo = (_STRINGS_ *)REALLOC(strinfo, maxstrinf * sizeof(_STRINGS_));
}
} while (!CloseBlock() && tok != tk_eof);
}
void CreatStrTabRes() {
unsigned int i, j;
int idnum = 0;
int usesec;
for (i = 0; i < 65536;) {
idnum++;
usesec = FALSE;
for (unsigned int ii = 0; ii < 16; ii++, i++) {
for (j = 0; j < numstrtbl; j++) {
if (i == (strinfo + j)->val) {
if (usesec == FALSE) {
usesec = TRUE;
InitBufRes();
curposbuf = ii * 2;
}
char *name = (strinfo + j)->id;
*(unsigned short *)&resbuf[curposbuf] = (unsigned short)strlen(name);
curposbuf += 2;
AddWString((unsigned char *)name);
free(name);
curposbuf -= 4;
break;
}
}
curposbuf += 2;
}
if (usesec) {
GetResBlock();
curtres->type = CRT_STRING;
AddType(CRT_STRING);
curtres->res = (unsigned char *)REALLOC(resbuf, curposbuf);
curtres->size = curposbuf;
curtres->id = idnum;
}
}
free(strinfo);
}
void domenu(unsigned int exts) {
unsigned char *name;
unsigned int lastpos;
unsigned long help;
if (OpenBlock()) {
do {
if (tok != tk_rescommand)
badformat("MENU");
lastpos = (exts == TRUE ? curposbuf + 12 : curposbuf);
CheckResBuf(18);
restok = itok.number;
nexttok();
switch (restok) {
case rc_menuitem:
if (tok == tk_string) {
name = (unsigned char *)BackString((char *)string);
nexttok();
if (tok == tk_camma) {
nexttok();
if (exts) {
if (tok != tk_camma)
*(unsigned long *)&resbuf[curposbuf + 8] = GetNumber(2);
if (tok == tk_camma) {
nexttok();
if (tok != tk_camma)
*(unsigned long *)&resbuf[curposbuf] = GetNumber(3);
if (tok == tk_camma) {
do {
nexttok();
if (tok == tk_number)
*(unsigned long *)&resbuf[curposbuf + 4] |= itok.number;
else
*(unsigned long *)&resbuf[curposbuf + 4] |=
GetFlag((_STRINGS_ *)&typemenu, NUMMENUPOPUP);
nexttok();
} while (tok == tk_or);
}
}
} else {
if (tok != tk_camma)
*(unsigned short *)&resbuf[curposbuf + 2] =
(unsigned short)GetNumber(2);
if (tok == tk_camma) {
do {
nexttok();
if (tok == tk_number)
*(unsigned short *)&resbuf[curposbuf] |=
(unsigned short)itok.number;
else
*(unsigned short *)&resbuf[curposbuf] |=
GetFlag((_STRINGS_ *)&typemenu, NUMMENUPOPUP);
nexttok();
} while (tok == tk_or || tok == tk_camma);
}
}
}
curposbuf += (exts == FALSE ? 4 : 14);
AddWString(name);
if (exts) {
CheckResBuf(2);
curposbuf = Align(curposbuf, 4);
}
free(name);
} else if (strcasecmp(itok.name, "SEPARATOR") == 0) {
if (exts) {
*(unsigned long *)&resbuf[curposbuf] = 0x800;
curposbuf += 16;
} else
curposbuf += 6;
nexttok();
} else
badformat("MENU");
break;
case rc_popup:
help = 0;
if (tok != tk_string)
badformat("MENU");
name = (unsigned char *)BackString((char *)string);
*(unsigned short *)&resbuf[lastpos] = (exts == FALSE ? 0x10 : 1);
nexttok();
if (tok == tk_camma) {
if (exts) {
nexttok();
if (tok != tk_camma)
*(unsigned long *)&resbuf[curposbuf + 8] = GetNumber(2);
if (tok == tk_camma) {
nexttok();
if (tok != tk_camma)
*(unsigned long *)&resbuf[curposbuf] = GetNumber(3);
if (tok == tk_camma) {
do {
nexttok();
if (tok == tk_number)
*(unsigned long *)&resbuf[curposbuf + 4] |= itok.number;
else
*(unsigned long *)&resbuf[curposbuf + 4] |=
GetFlag((_STRINGS_ *)&typemenu, NUMMENUPOPUP);
nexttok();
} while (tok == tk_or);
}
if (tok == tk_camma) {
nexttok();
help = GetNumber(5);
}
}
} else {
do {
nexttok();
if (tok == tk_number)
*(unsigned short *)&resbuf[curposbuf] |=
(unsigned short)itok.number;
else
*(unsigned short *)&resbuf[curposbuf] |=
GetFlag((_STRINGS_ *)&typemenu, NUMMENUPOPUP);
nexttok();
} while (tok == tk_or);
}
}
curposbuf += (exts == FALSE ? 2 : 14);
AddWString(name);
if (exts) {
CheckResBuf(6);
curposbuf = Align(curposbuf, 4);
*(unsigned long *)&resbuf[curposbuf] = help;
curposbuf += 4;
}
if (name)
free(name);
domenu(exts);
break;
default:
badformat("MENU");
break;
}
} while (!CloseBlock() && tok != tk_eof);
resbuf[lastpos] |= 0x80;
} else
badformat("MENU");
}
void r_Menu() {
unsigned int exts = FALSE;
if (restok == rc_menuex)
exts = TRUE;
GetResBlock();
curtres->type = CRT_MENU;
if (idname[0] == 0)
curtres->id = idnum;
else
curtres->name = BackString(idname);
AddType(CRT_MENU);
InitBufRes();
while (tok != tk_endline)
nexttok();
if (tok == tk_rescommand && itok.number == rc_language) {
unsigned short olang;
olang = langdef;
nexttok();
r_Language();
curtres->lang = langdef;
langdef = olang;
}
if (exts) {
*(unsigned long *)&resbuf[0] = 0x00040001;
curposbuf = 8;
} else
curposbuf = 4;
domenu(exts);
curtres->res = (unsigned char *)REALLOC(resbuf, curposbuf);
curtres->size = curposbuf;
}
void r_Rcdata() {
GetResBlock();
curtres->type = CRT_RCDATA;
if (idname[0] == 0)
curtres->id = idnum;
else
curtres->name = BackString(idname);
AddType(CRT_RCDATA);
char name[256];
name[0] = 0;
GetFileName(name);
if (name[0] != 0)
resbuf = LoadFileBin(name);
else if (tok == tk_string)
resbuf = LoadFileBin((char *)string);
else {
InitBufRes();
if (!OpenBlock())
badformat("RCDATA");
do {
if (tok == tk_number || (tok == tk_minus && tok2 == tk_number)) {
CheckResBuf(2);
*(unsigned short *)&resbuf[curposbuf] = (unsigned short)GetNumber(0);
curposbuf += 2;
} else if (tok == tk_string) {
CheckResBuf(itok.number);
for (int i = 0; i < itok.number; i++)
resbuf[curposbuf++] = string[i];
nexttok();
} else if (tok == tk_id || tok == tk_ID) {
CheckResBuf(strlen(itok.name));
unsigned char c;
int j = 0;
for (;;) {
c = itok.name[j++];
if (c == 0)
break;
resbuf[curposbuf++] = c;
}
nexttok();
}
if (tok == tk_rescommand && itok.number == rc_characteristics) {
nexttok();
CheckResBuf(4);
*(unsigned long *)&resbuf[curposbuf] = GetNumber(0);
curposbuf += 4;
} else
badformat("RCDATA");
if (tok == tk_camma || tok == tk_semicolon)
nexttok();
} while (!CloseBlock() && tok != tk_eof);
}
curtres->res = (unsigned char *)REALLOC(resbuf, curposbuf);
curtres->size = curposbuf;
}
void GetVersPar(unsigned char *buf) {
nexttok();
*(unsigned short *)&buf[2] = (unsigned short)GetNumber(1);
expecting(tk_camma);
*(unsigned short *)&buf[0] = (unsigned short)GetNumber(2);
expecting(tk_camma);
*(unsigned short *)&buf[6] = (unsigned short)GetNumber(3);
expecting(tk_camma);
*(unsigned short *)&buf[4] = (unsigned short)GetNumber(4);
}
void GetBlockInfo() {
int startpos;
do {
startpos = curposbuf;
CheckResBuf(6);
curposbuf += 6;
if (strcasecmp("BLOCK", itok.name) == 0) {
nexttok();
if (tok != tk_string)
stringexpected();
CheckResBuf((itok.number + 1) * 2 + 2);
AddWString((unsigned char *)string);
curposbuf = Align(curposbuf, 4);
nexttok();
if (OpenBlock())
GetBlockInfo();
else
badformat("VERSIONINFO");
} else if (strcasecmp("VALUE", itok.name) == 0) {
nexttok();
if (tok != tk_string)
stringexpected();
CheckResBuf((itok.number + 1) * 2 + 2);
AddWString((unsigned char *)string);
curposbuf = Align(curposbuf, 4);
nexttok();
if (tok2 == tk_string) {
expecting(tk_camma);
CheckResBuf((itok.number + 1) * 2 + 2);
AddWString((unsigned char *)string);
*(unsigned short *)&resbuf[startpos + 4] = 1;
*(unsigned short *)&resbuf[startpos + 2] = (unsigned short)itok.number;
nexttok();
} else {
do {
nexttok();
CheckResBuf(4);
*(unsigned short *)&resbuf[curposbuf] = (unsigned short)GetNumber(0);
curposbuf += 2;
*(unsigned short *)&resbuf[startpos + 2] += 2;
} while (tok == tk_camma);
// nexttok();
}
} else
badformat("VERSIONINFO");
*(unsigned short *)&resbuf[startpos] =
(unsigned short)(curposbuf - startpos);
curposbuf = Align(curposbuf, 4);
} while (CloseBlock() == FALSE);
}
void r_Version() {
GetResBlock();
InitBufRes();
curtres->type = CRT_VERSION;
curtres->id = 1;
AddType(CRT_VERSION);
*(unsigned short *)&resbuf[2] = 0x34;
// if(idname[0]==0)stringexpected();
if (idname[0] == 0)
curtres->id = idnum;
else
curtres->name = BackString(idname);
curposbuf = 6;
AddWString((unsigned char *)"VS_VERSION_INFO");
curposbuf = Align(curposbuf, 4);
*(unsigned long *)&resbuf[curposbuf] = 0xfeef04bd;
*(unsigned long *)&resbuf[curposbuf + 4] = 0x00010000;
curposbuf += 8;
while (!OpenBlock() && tok != tk_eof) {
switch (GetFlag((_STRINGS_ *)&typeversion, 7)) {
case v_fv:
GetVersPar(resbuf + curposbuf);
break;
case v_pv:
GetVersPar(resbuf + curposbuf + 8);
break;
case v_ffm:
nexttok();
*(unsigned long *)&resbuf[curposbuf + 16] = (unsigned long)GetNumber(0);
break;
case v_ff:
nexttok();
*(unsigned long *)&resbuf[curposbuf + 20] = (unsigned long)GetNumber(0);
break;
case v_fo:
nexttok();
*(unsigned long *)&resbuf[curposbuf + 24] = (unsigned long)GetNumber(0);
break;
case v_ft:
nexttok();
*(unsigned long *)&resbuf[curposbuf + 28] = (unsigned long)GetNumber(0);
break;
case v_fs:
nexttok();
*(unsigned long *)&resbuf[curposbuf + 32] = (unsigned long)GetNumber(0);
break;
default:
badformat("VERSIONINFO");
break;
}
}
curposbuf += 44;
GetBlockInfo();
*(unsigned short *)&resbuf[0] = (unsigned short)curposbuf;
curtres->res = (unsigned char *)REALLOC(resbuf, curposbuf);
curtres->size = curposbuf;
}
void r_Dialog() {
unsigned char *name = NULL;
unsigned char *font = NULL;
int sizefont = 0, i;
NameOrdinal Menu;
NameOrdinal Class;
unsigned int poscount; //позиция счетчика элементов
unsigned int exts = FALSE;
// unsigned short id;
Menu.name = NULL;
Class.name = NULL;
if (restok == rc_dialogex)
exts = TRUE;
GetResBlock();
curtres->type = CRT_DIALOG;
if (idname[0] == 0)
curtres->id = idnum;
else
curtres->name = BackString(idname);
AddType(CRT_DIALOG);
InitBufRes();
if (exts) {
*(unsigned long *)&resbuf[0] = 0xFFFF0001;
curposbuf = 8;
poscount = 16;
*(unsigned long *)&resbuf[12] =
0x80880000; // WS_POPUP|WS_BORDER|WS_SYSMENU; //установки по умолчанию
} else {
*(unsigned long *)&resbuf[0] =
0x80880000; // WS_POPUP|WS_BORDER|WS_SYSMENU; //установки по умолчанию
curposbuf = 0;
poscount = 8;
}
if (tok2 != tk_camma) { //пропускаем возможные первые два параметра
nexttok();
if (tok2 != tk_camma) {
nexttok();
if (tok2 != tk_camma)
badformat("DIALOG");
}
}
GetRectangle(&resbuf[curposbuf + 10], 1);
//определить место для IDHelp
if (tok != tk_endline && exts) /**(unsigned long *)&resbuf[curposbuf]=*/
GetNumber(0);
while (!OpenBlock() && tok != tk_eof) {
if (tok != tk_rescommand)
expectedrescommand();
switch (itok.number) {
case rc_style:
nexttok();
*(unsigned long *)&resbuf[exts == TRUE ? 12 : 0] = GetNumber(1);
break;
case rc_caption:
nexttok();
if (tok != tk_string)
stringexpected();
name = (unsigned char *)BackString((char *)string);
nexttok();
break;
case rc_font:
nexttok();
sizefont = GetNumber(1);
expecting(tk_camma);
if (tok != tk_string)
stringexpected();
font = (unsigned char *)BackString((char *)string);
nexttok();
break;
case rc_class:
nexttok();
GetOrdinal(&Class.name, 1);
// if(tok!=tk_string)stringexpected();
// Class.name=(unsigned char
//*)BackString((char *)string); nexttok();
break;
case rc_exstyle:
nexttok();
*(unsigned long *)&resbuf[exts == TRUE ? 8 : 4] = GetNumber(1);
break;
case rc_language:
unsigned short olang;
olang = langdef;
nexttok();
r_Language();
curtres->lang = langdef;
langdef = olang;
break;
default:
if (exts && itok.number == rc_menu) {
nexttok();
GetOrdinal(&Menu.name, 1);
} else
badformat("DIALOG");
break;
}
while (tok == tk_endline)
nexttok();
}
//доформировываем диалог
curposbuf = exts == TRUE ? 26 : 18;
AddNumOrd(Menu.name);
FreeOrdinal(Menu.name);
AddNumOrd(Class.name);
FreeOrdinal(Class.name);
AddWString(name);
if (name)
free(name);
if (sizefont) {
resbuf[exts == TRUE ? 12 : 0] |= 0x40;
*(unsigned short *)&resbuf[curposbuf] = (unsigned short)sizefont;
curposbuf += 2;
if (exts) {
*(unsigned int *)&resbuf[curposbuf] = 0x01000000;
curposbuf += 4;
}
AddWString(font);
free(font);
}
while (!CloseBlock() && tok != tk_eof) {
// do{
if (tok != tk_rescommand)
expectedrescommand();
restok = itok.number;
nexttok();
curposbuf = Align(curposbuf, 4);
CheckResBuf(34);
name = Menu.name = NULL;
i = 1;
if (exts)
curposbuf += 8;
*(unsigned short *)&resbuf[curposbuf + (exts == TRUE ? 16 : 18)] = 0XFFFF;
*(unsigned short *)&resbuf[curposbuf + (exts == TRUE ? 18 : 20)] =
defdialog[restok].dclass;
*(unsigned long *)&resbuf[curposbuf] = defdialog[restok].style | 0x50000000;
switch (restok) {
case rc_control:
GetOrdinal(&Menu.name, 1);
expecting(tk_camma);
while (tok == tk_endline)
nexttok();
if (exts)
*(unsigned int *)&resbuf[curposbuf + 12] = (unsigned int)GetNumber(2);
else
*(unsigned short *)&resbuf[curposbuf + 16] =
(unsigned short)GetNumber(2);
expecting(tk_camma);
while (tok == tk_endline)
nexttok();
if (tok == tk_number)
*(unsigned short *)&resbuf[curposbuf + (exts == TRUE ? 18 : 20)] =
(unsigned short)itok.number;
else {
if (tok == tk_string)
strncpy(itok.name, (char *)string, IDLENGTH);
i = GetFlag((_STRINGS_ *)&typeclass, 6);
if (!i)
name = (unsigned char *)BackString((char *)string);
else
*(unsigned short *)&resbuf[curposbuf + (exts == TRUE ? 18 : 20)] =
(unsigned short)i;
}
nextexpecting2(tk_camma);
while (tok == tk_endline)
nexttok();
*(unsigned long *)&resbuf[curposbuf] |= GetNumber(4);
expecting(tk_camma);
while (tok == tk_endline)
nexttok();
GetRectangle(&resbuf[curposbuf + (exts == TRUE ? 4 : 8)], 5);
if (exts && tok == tk_number)
*(unsigned long *)&resbuf[curposbuf - 4] = GetNumber(9);
while (tok != tk_endline && tok != tk_eof && tok != tk_rescommand)
nexttok(); //пропуск излишних параметров
break;
case rc_auto3state:
case rc_autocheckbox:
case rc_autoradiobutton:
case rc_checkbox:
case rc_ctext:
case rc_defpushbutton:
case rc_groupbox:
case rc_ltext:
case rc_pushbox:
case rc_pushbutton:
case rc_radiobutton:
case rc_rtext:
case rc_state3:
if (tok != tk_string)
stringexpected();