-
Notifications
You must be signed in to change notification settings - Fork 2
/
pilrc.c
6321 lines (5667 loc) · 164 KB
/
pilrc.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
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
/*
* @(#)pilrc.c
*
* Copyright 1997-1999, Wes Cherry (mailto:[email protected])
* 2000-2005, Aaron Ardiri (mailto:[email protected])
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, please write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Revisions:
* ==========
*
* pre 18-Jun-2000 <numerous developers>
* creation
* 18-Jun-2000 Aaron Ardiri
* GNU GPL documentation additions
* 23-Jun-2000 Mark Garlanger
* Additions to support #ifdef/#ifndef/#else/#endif in
* both *.rcp files and *.h files.
* 24-Jun-2000 Kurt Spaugh
* Additions for tSTL resource support
* 27-Jul-2000 Michal Kouril
* Additions for slider control resource support
* 20-Nov-2000 Renaud Malaval
* Additions for PalmOS 3.5 support
* 30-Nov-2000 Renaud Malaval
* Debug tSTL resource support in LE32 generation
* 05-Dec-2000 Renaud Malaval
* Remove padding in ParseDumpApplicationIconName() (taic)
* Force padding to 16bpp in ParseDumpLauncherCategory() (tAIN)
* 30-Dec-2000 Ben Combee
* Added 'tint' resource support
* Jan-2001 Regis Nicolas
* Merged 68K and LE32 version into one binary
* 12-Jan-2001 Renaud Malaval
* Added 'wrdl' resource support
* 19-Jan-2001 Renaud Malaval
* Added 'tclt' resource support
* 02-Fev-2001 Renaud Malaval
* Added 'silk' resource support
* 14-Fev-2001 Renaud Malaval
* Added 'cnty' resource support
* 16-Fev-2001 Renaud Malaval
* Added 'feat' resource support
* 23-Fev-2001 Renaud Malaval
* Added 'tkbd' resource support
* 02-Mar-2001 Renaud Malaval
* Added 'DLST' & 'BLST' resource support
* 09-Mar-2001 Renaud Malaval
* Added 'MIDI' resource support
* 12-Mar-2001 Renaud Malaval
* Added 'Tbsb' resource support
* 20-Jun-2001 Renaud Malaval
* Added 'locs' resource support
* 26-Jun-2001 Renaud Malaval
* Added 'hsbd' resource support
* 13-Jui-2001 Renaud Malaval
* Added 'pref' resource support
* 23-Jui-2001 Renaud Malaval
* Added localisation support
* 31-Aug-2001 Laurent Dutour
* Re-Added recursive include support
* 08-Sep-2001 Renaud Malaval
* Added 'tSCH' resource support
* 04-Aug-2002 Michael McLagen
* Fixed BITMAPID/SELECTEDBITMAPID warnings
* 06-Aug-2002 Renaud Malaval
* Added 'nfnt' resource support
* 22-Sep-2002 Ben Combee
* Allow zero-item lists in forms
* Fix transparency handling for high density bitmaps
* Allow LABELs to have strings that span lines
* 1-Oct-2002 Ben Combee
* Patch from Joshua Buergel to not warn when using
* horizonal scroll bars at recommended height.
* 5-Nov-2002 Ben Combee
* Altered MENU SEPARATOR to allow specifying ID or AUTOID
* 22-Mar-2003 Bob Withers
* Added support for #define strings which can be used in
* place of string constants.
* Added support for preprocessor directives within MENU,
* FORM, and ALERT defintions.
* 25-Sep-2003 John Marshall
* Added support for Handspring's BITMAP syntax to the
* unified bitmap parser.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#ifndef strdup
char *strdup(const char *s);
/*lint -sem( strdup, @p == (1p ? malloc(1p) : 0) )*/
#endif
#define EMITRWT
#include "pilrc.h"
#undef EMITRWT
#include "bitmap.h"
#include "restype.h" // RMa
#ifdef PALM_INTERNAL
#include "PalmRC.h"
#endif
#define idDefaultAutoInit 9999
#define idDefaultDirection -1
#define idPalmOSReservedMin 10000
#define idPalmOSReservedMinWithEditIDs 10008
#define szMultipleLineMaxLength 65536
static void ParseDirectives(RCPFILE * prcpfile);
/*-----------------------------------------------------------------------------
| Globals
-------------------------------------------------------------WESC------------*/
/*
* Are we PilRCUI -- this was an attempt to merge pilrc and pilrcui
*/
BOOL vfWinGUI;
/*
* Variables to support #ifdef/#else/#endif
*/
int ifdefSkipping = 0;
int ifdefLevel = 0;
/*
* No default flag for form and object form
*/
BOOL vfPalmRez;
/*
* Allow edit ID's (10000-10007 inclusive)
*/
BOOL vfAllowEditIDs;
/*
* Allow icons that aren't properly sized
*/
BOOL vfAllowBadIconSizes;
/*
* Allow resources to exceed 64000 bytes
*/
BOOL vfAllowLargeResources;
/*
* Disables ellipsis processing
*/
BOOL vfNoEllipsis;
/*
* Quiet output
*/
BOOL vfQuiet;
/*
* M$ (VS-type) error/warning output
*/
BOOL vfVSErrors;
/*
* Translations
*/
int totalLanguages = 0;
const char *aszLanguage[MAXLANG] = { NULL };
TE *pteFirst;
/*
* RMa Localisation management
*/
char *szLocaleP;
/*
* RMa Localisation management
* Don't compile non localisable resources
*/
BOOL vfStripNoLocRes;
/*
* RTL For Hebrew
*/
BOOL vfRTL = fFalse;
/*
* next auto id
*/
BOOL vfAutoId = fFalse;
int vfAutoStartID = idDefaultAutoInit;
int idAutoMac = idDefaultAutoInit;
int idAutoDirection = idDefaultDirection;
/*
* output header file support
*/
static char *szOutputHeaderFile = NULL;
/*
* Warning about duplicates in forms and menus
*/
/*
* if == 2 then we warn about duplicate labels too
*/
BOOL vfCheckDupes;
/*
* Form globals
*/
FRM *vpfrm;
//RCFORM form; /* current form being parsed */
//#define cobjMax 256
//RCFORMOBJLIST rglt[cobjMax];
/*
* RMa Little or Big indian support
*/
BOOL vfLE32 = fFalse;
BOOL vfAppIcon68K = fFalse;
BOOL vfAutoAmdc = fFalse;
char *szDllNameP;
/*
* LDu Output a Prc File
*/
BOOL vfPrc = fFalse;
const char *vfPrcName;
const char *vfPrcCreator;
const char *vfPrcType;
BOOL vfPrcTimeStamp = fFalse;
/*
* LDu Ignore Include File In Header Files
*/
BOOL vfIFIH = fFalse;
/*
* Track dependencies
*/
BOOL vfTrackDepends = fFalse;
BOOL vfInhibitOutput = fFalse;
/*
* Menu globals
*/
RCMENUBAR menu;
#define imiMax 128
RCMENUITEM rgmi[imiMax];
#define impdMax 32
RCMENUPULLDOWN rgmpd[impdMax];
int imiMac;
int idMenu;
#define iidMenuMax 128
int iidMenuMac;
int rgidMenu[iidMenuMax];
#define iidStringMax 512
int iidStringMac;
int rgidString[iidStringMax];
#define iidStringTableMax 384 // RMa add for make difference between tSTR and tSTL string
int iidStringTableMac; // RMa add for make difference between tSTR and tSTL string
int rgidStringTable[iidStringTableMax]; // RMa add for make difference between tSTR and tSTL string
#define iidAlertMax 512
int iidAlertMac;
int rgidAlert[iidAlertMax];
#define iidAISMax 128
int iidAISMac;
int rgidAIS[iidAISMax];
/*
* Symbol table
*/
SYM *psymFirst;
/*
* Parse globals
*/
TOK tok;
INPUTCONTEXT vIn;
/*
* Rect for Prev* keywords
*/
RCRECT rcPrev;
/*-----------------------------------------------------------------------------
| AddSym
|
| Add symbol with value wVal to symbol table
|
| Note! no check is made for previous existence
-------------------------------------------------------------WESC------------*/
VOID
AddSym(const char *sz,
int wVal)
{
SYM *psym;
psym = calloc(1, sizeof(SYM));
if (psym == NULL) Error("out of memory");
psym->sz = strdup(sz);
psym->wVal = wVal;
psym->sVal = NULL;
psym->psymNext = psymFirst;
psymFirst = psym;
}
VOID AddSymString(const char* sz, const char* val)
{
auto SYM* psym;
psym = calloc(1, sizeof(SYM));
if (psym == NULL) Error("out of memory");
psym->sz = strdup(sz);
psym->wVal = 0;
psym->sVal = strdup(val);
psym->psymNext = psymFirst;
psymFirst = psym;
}
static VOID FreeSym(SYM *psym)
{
free(psym->sz);
free(psym->sVal);
free(psym);
}
VOID RemoveSym(const char *sz)
{
SYM *psym, *next;
SYM **prevNext = &psymFirst;
for (psym = psymFirst; psym != NULL; psym = next)
{
next = psym->psymNext;
if (strcmp(psym->sz, sz) == 0)
{
*prevNext = next;
FreeSym(psym);
}
else
prevNext = &(psym->psymNext);
}
}
/*-----------------------------------------------------------------------------
| PsymLookup
|
| Lookup symbol based on sz -- case sensitive
-------------------------------------------------------------WESC------------*/
static SYM *
PsymLookup(const char *sz)
{
SYM *psym;
for (psym = psymFirst; psym != NULL; psym = psym->psymNext)
if (strcmp(psym->sz, sz) == 0)
return psym;
return NULL;
}
static VOID
CheckNumericSymbol(const SYM* psym)
{
if (NULL != psym->sVal)
ErrorLine("Symbol %s should be numeric ID but is defined as string %s",
psym->sz, psym->sVal);
}
static int
IdGetAutoId()
{
idAutoMac += idAutoDirection;
return idAutoMac;
}
static SYM *
PsymAddSymAutoId(const char *sz)
{
SYM *psym;
AddSym(sz, IdGetAutoId());
psym = PsymLookup(tok.lex.szId);
psym->fAutoId = fTrue;
return psym;
}
/*-----------------------------------------------------------------------------
| FreeSymTable
|
| Free up all memory allocated for the symbol table
-------------------------------------------------------------WESC------------*/
static VOID
FreeSymTable()
{
SYM* psym;
SYM* psymNext;
for (psym = psymFirst; psym != NULL; psym = psymNext)
{
psymNext = psym->psymNext;
FreeSym(psym);
}
psymFirst = NULL;
}
/*-----------------------------------------------------------------------------
| PchFromRw
|
| Maps a reserved word into a string
-------------------------------------------------------------WESC------------*/
static const char *
PchFromRw(RW rw,
BOOL fTrySecondName)
{
RWT *prwt;
prwt = rgrwt;
while (prwt->sz1 != NULL)
{
if (prwt->rw == rw)
{
if (fTrySecondName && prwt->sz2 != NULL)
return prwt->sz2;
return prwt->sz1;
}
prwt++;
}
return NULL;
}
/*-----------------------------------------------------------------------------
| RwFromLex
|
| Looks up lex.id in reserved word table. returns rwNil if not found
-------------------------------------------------------------WESC------------*/
static RW
RwFromLex(const LEX * plex)
{
RWT *prwt;
if (plex->lt != ltId)
return rwNil;
prwt = rgrwt;
while (prwt->sz1 != NULL)
{
if (FSzEqI(plex->szId, prwt->sz1)
|| (prwt->sz2 != NULL && FSzEqI(plex->szId, prwt->sz2)))
return prwt->rw;
prwt++;
}
return rwNil;
}
/*-----------------------------------------------------------------------------
| PteFromSz
|
| Look up a language tranlation entry. All strings in the .rcp file
| potentially get translated
-------------------------------------------------------------WESC------------*/
static TE *
PteFromSz(const char *sz)
{
TE *pte;
for (pte = pteFirst; pte != NULL; pte = pte->pteNext)
if (strcmp(pte->szOrig, sz) == 0)
return pte;
return NULL;
}
/*-----------------------------------------------------------------------------
| FreeTranslations
|
| Free up the translation table
-------------------------------------------------------------WESC------------*/
static VOID
FreeTranslations()
{
TE *pte;
TE *pteNext;
for (pte = pteFirst; pte != NULL; pte = pteNext)
{
pteNext = pte->pteNext;
free(pte->szOrig);
free(pte->szTrans);
free(pte);
}
pteFirst = NULL;
}
/*-----------------------------------------------------------------------------
| NextLine
|
| Skip lexer ahead to the next line
-------------------------------------------------------------WESC------------*/
static BOOL
NextLine(void)
{
BOOL fEof;
char *pchNext;
char *eoln = strpbrk(vIn.pch, "\n\x0a\x0d");
if (eoln == NULL)
{
int buflen = strlen(vIn.pch);
memmove(vIn.buffer, vIn.pch, buflen + 1);
vIn.pch = vIn.buffer;
fgets(&vIn.buffer[buflen], sizeof vIn.buffer - buflen, vIn.file.fh);
eoln = strpbrk(vIn.pch, "\n\x0a\x0d");
if (eoln == NULL)
eoln = strrchr(vIn.pch, '\0');
}
if (eoln[0] == '\x0d' && eoln[1] == '\x0a')
pchNext = eoln + 2;
else if (*eoln == '\0')
pchNext = eoln;
else
pchNext = eoln + 1;
fEof = (*vIn.pch == '\0');
*eoln = '\0';
if (!fEof)
vIn.file.line++;
FInitLexer(vIn.pch, fTrue);
vIn.pch = pchNext;
return !fEof;
}
/*-----------------------------------------------------------------------------
| FGetTok
|
| Get the next token.
| Returns fFalse, .lex.lt=ltNil, and .rw=rwNil on EOF.
|
| Consistency issue -- takes a ptok, but some other other routines don't.
| only one global tok...
-------------------------------------------------------------WESC------------*/
BOOL
FGetTok(TOK *ptok)
{
BOOL fInComment;
if (vIn.fPendingTok)
{
*ptok = vIn.pendingTok;
vIn.fPendingTok = fFalse;
return ptok->lex.lt != ltNil;
}
ptok->rw = rwNil;
fInComment = fFalse;
for (;;)
{
while (!FGetLex(&ptok->lex, fInComment))
{
if (!NextLine())
{
if (fInComment)
ErrorLine("unexpected end of file during C-style comment");
ptok->lex.lt = ltNil;
vIn.pendingTok = *ptok;
return fFalse;
}
}
if (ptok->lex.lt == ltCComment)
fInComment = fTrue;
else if (ptok->lex.lt == ltEndCComment)
fInComment = fFalse;
else if (ptok->lex.lt == ltDoubleSlash)
NextLine();
else
break;
}
if (ptok->lex.lt == ltId)
{
/*
* check if it is a reserved word
*/
ptok->rw = RwFromLex(&ptok->lex);
}
else if (ptok->lex.lt == ltStr)
{
TE *pte;
/*
* attempt translation
*/
pte = PteFromSz(ptok->lex.szId);
if (pte != NULL)
strcpy(ptok->lex.szId, pte->szTrans);
}
vIn.pendingTok = *ptok;
return fTrue;
}
/*-----------------------------------------------------------------------------
| UngetTok
|
| Pushback one token. Note! that this is 1 level only!
-------------------------------------------------------------WESC------------*/
VOID
UngetTok(void)
{
vIn.fPendingTok = fTrue;
}
/*-----------------------------------------------------------------------------
| PeekTok
-------------------------------------------------------------JohnM-----------*/
const TOK *
PeekTok(void)
{
FGetTok(&tok);
UngetTok();
return &tok;
}
/*-----------------------------------------------------------------------------
| GetExpectLt
|
| Get a token and expect a particular lex type.
| Emit szErr if it isn't what's expected.
| DO NOT use with lt==ltStr; use PchGetString() instead.
-------------------------------------------------------------WESC------------*/
static VOID
GetExpectLt(TOK * ptok,
LT lt,
char *szErr)
{
FGetTok(ptok);
if (ptok->lex.lt != lt)
{
if (szErr == NULL)
{
if (lt == ltId)
ErrorLine("Syntax error : expecting identifier, got %s",ptok->lex.szId);
else if (lt == ltConst)
ErrorLine("Syntax error : expecting constant, got %s", ptok->lex.szId);
else
ErrorLine("syntax error: %s", ptok->lex.szId);
}
else
{
ErrorLine("expecting: %s, got %s", szErr, ptok->lex.szId);
}
}
}
/*-----------------------------------------------------------------------------
| GetExpectRw
|
| Get and expect a particular reserved word. Emit "Expecting..." if next
| token isn't rw
-------------------------------------------------------------WESC------------*/
VOID
GetExpectRw(RW rw)
{
TOK tok;
FGetTok(&tok);
if (tok.rw != rw)
ErrorLine("%s expected, got %s", PchFromRw(rw, fTrue), tok.lex.szId);
}
/*-----------------------------------------------------------------------------
| FIsString
|
| Returns true if the token could be the first token of
| a (possibly concatenated) string.
-------------------------------------------------------------JohnM-----------*/
BOOL
FIsString(const TOK *ptok)
{
if (ptok->lex.lt == ltStr)
return fTrue;
else if (ptok->lex.lt == ltId && ptok->rw == rwNil)
{
const SYM *psym = PsymLookup(ptok->lex.szId);
return psym && psym->sVal;
}
else
return fFalse;
}
/*-----------------------------------------------------------------------------
| PchGetString
|
| Get a string (which should be free()ed by the caller),
| which may include concatenation and/or string #defines.
-------------------------------------------------------------JohnM-----------*/
char *
PchGetString(const char *szErr)
{
char *szOut = NULL;
size_t outlen = 0;
for (;;)
{
const char *szSingle = NULL;
const TOK *ptok;
if (!FGetTok(&tok))
ErrorLine("end of file %s %s", szOut? "in" : "when expecting", szErr);
else if (tok.lex.lt == ltStr)
szSingle = tok.lex.szId;
else if (tok.lex.lt == ltId && tok.rw == rwNil)
{
const SYM *psym = PsymLookup(tok.lex.szId);
if (psym == NULL)
ErrorLine("undefined symbol '%s' in %s", tok.lex.szId, szErr);
else if (psym->sVal == NULL)
ErrorLine("numeric symbol '%s' in %s", tok.lex.szId, szErr);
else
szSingle = psym->sVal;
}
else
{
if (szOut)
ErrorLine("cannot concatenate '%s' onto %s", tok.lex.szId, szErr);
else
ErrorLine("expecting %s, got '%s'", szErr, tok.lex.szId);
}
if (szSingle)
{
size_t singlelen = strlen(szSingle);
char *sz = realloc(szOut, outlen + singlelen + 1);
if (sz == NULL)
Error("String is larger than available memory");
else
szOut = sz;
strcpy(szOut + outlen, szSingle);
outlen += singlelen;
}
ptok = PeekTok();
if (ptok->lex.lt == ltPlus || ptok->lex.lt == ltBSlash)
FGetTok(&tok);
else
break;
}
return szOut;
}
/*-----------------------------------------------------------------------------
| WGetConst
|
| Get an integer constant or one of the Prev* reserved words, returning
| valu e.
|
-------------------------------------------------------------WESC------------*/
int
WGetConst(char *szErr)
{
if (!FGetTok(&tok))
ErrorLine("unexpected end of file");
/*lint -e{788}*/
switch (tok.rw)
{
default:
if (tok.lex.lt == ltId)
{
SYM *psym;
psym = PsymLookup(tok.lex.szId);
if (psym)
{
CheckNumericSymbol(psym);
}
else
{
if (vfAutoId)
{
psym = PsymAddSymAutoId(tok.lex.szId);
}
else
{
ErrorLine("Expecting %s, got unknown symbol: %s",
szErr, tok.lex.szId);
}
}
return psym->wVal;
}
if (tok.lex.lt != ltConst)
{
ErrorLine("%s expected, got %s", szErr, tok.lex.szId);
}
return tok.lex.val;
case rwPrevLeft:
return rcPrev.topLeft.x;
case rwPrevRight:
return rcPrev.topLeft.x + rcPrev.extent.x;
case rwPrevWidth:
return rcPrev.extent.x;
case rwPrevTop:
return rcPrev.topLeft.y;
case rwPrevBottom:
return rcPrev.topLeft.y + rcPrev.extent.y;
case rwPrevHeight:
return rcPrev.extent.y;
}
}
/*-----------------------------------------------------------------------------
| WGetConstExFactor
|
| Get a constant expression -- parens allowed left to right associativity
-------------------------------------------------------------WESC------------*/
static int
WGetConstExFactor(char *szErr)
{
int wVal;
if (FGetTok(&tok))
{
if (tok.lex.lt == ltLParen)
{
wVal = WGetConstEx(szErr);
if (!FGetTok(&tok) || tok.lex.lt != ltRParen)
ErrorLine("Expected but didn't get ')'!");
}
else if (tok.lex.lt == ltMinus) /* RMa add support for negative value */
{
wVal = 0 - WGetConstEx(szErr);
} /* RMa add support for negative value */
else
{
UngetTok();
wVal = WGetConst(szErr);
}
}
else
{
wVal = WGetConst(szErr); /* aka hack */
}
return wVal;
}
/*-----------------------------------------------------------------------------
| WGetConstEx
|
| Get a constant expression -- parens allowed left to right associativity
-------------------------------------------------------------WESC------------*/
int
WGetConstEx(char *szErr)
{
int wValT;
int wVal;
LT ltOp;
wVal = WGetConstExFactor(szErr);
for (;;)
{
if (!FGetTok(&tok))
return wVal;
switch (tok.lex.lt)
{
default:
UngetTok();
return wVal;
case ltPlus:
case ltMinus:
case ltMult:
case ltDiv:
case ltPipe:
ltOp = tok.lex.lt;
wValT = WGetConstExFactor(szErr);
switch (ltOp)
{
case ltPlus:
wVal += wValT;
break;
case ltMinus:
wVal -= wValT;
break;
case ltMult:
wVal *= wValT;
break;
case ltDiv:
if (wValT == 0)
ErrorLine("Divide By Zero!");
wVal /= wValT;
break;
case ltPipe:
if (vfRTL)
wVal = wValT;
break;
}
}
}
}
VOID
AddDefineSymbol(void)
{
int wIdVal;
char szId[256];
int current_line;
GetExpectLt(&tok, ltId, "identifier");
strcpy(szId, tok.lex.szId);
if (NULL != PsymLookup(szId))
ErrorLine("Symbol %s is defined multiple times", szId);
// save current line and check to see if we parse into another
// line for the value -- if so, reject token and define as 0
current_line = vIn.file.line;
if (!FGetTok(&tok))
ErrorLine("unexpected end of file");
if (current_line != vIn.file.line)
{
UngetTok();
AddSym(szId, 0);
}
else
{
if (FIsString(&tok))
{
// support a string define that spans multiple lines
char *szText;
UngetTok();
szText = PchGetString("#define string");
AddSymString(szId, szText);
free(szText);
}
else
{
UngetTok();
wIdVal = WGetConstEx("Constant");
AddSym(szId, wIdVal);
}
}
}
/*-----------------------------------------------------------------------------
| KtGetK
|
| Get a Konstant, returning the type.
-------------------------------------------------------------WESC------------*/
static KT
KtGetK(K * pk,
char *szErr)
{
if (!FGetTok(&tok))
ErrorLine("Unexpected end of file");
/*lint -e{788}*/
switch (tok.rw)
{
default:
UngetTok();
pk->kt = ktConst;