This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_config.cpp
1124 lines (981 loc) · 32.6 KB
/
c_config.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
/* c_config.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
typedef struct _CurPos {
int sz;
const char *a;
const char *c;
const char *z;
int line;
const char *name; // filename
} CurPos;
#ifdef CONFIG_INDENT_C
extern int C_Indent;
extern int C_BraceOfs;
extern int C_CaseOfs;
extern int C_CaseDelta;
extern int C_ClassOfs;
extern int C_ClassDelta;
extern int C_ColonOfs;
extern int C_CommentOfs;
extern int C_CommentDelta;
extern int C_FirstLevelWidth;
extern int C_FirstLevelIndent;
extern int C_Continuation;
extern int C_ParenDelta;
#endif
#ifdef CONFIG_INDENT_REXX
extern int REXX_Base_Indent;
extern int REXX_Do_Offset;
#endif
extern int ShowVScroll;
extern int ShowHScroll;
extern int ShowMenuBar;
int SystemClipboard = 0;
int ScreenSizeX = -1, ScreenSizeY = -1;
int ScrollBarWidth = 1;
int CursorInsSize[2] = { 90, 100 };
int CursorOverSize[2] = { 0, 100 };
int OpenAfterClose = 1;
int SelectPathname = 0;
char DefaultModeName[32] = "";
RxNode *CompletionFilter = NULL;
#if defined(DOS) || defined(DOSP32)
char PrintDevice[MAXPATH] = "PRN";
#else
char PrintDevice[MAXPATH] = "\\DEV\\PRN";
#endif
char CompileCommand[256] = "make";
int KeepHistory = 0;
int LoadDesktopOnEntry = 0;
int SaveDesktopOnExit = 0;
char WindowFont[64] = "";
int KeepMessages = 0;
int ScrollBorderX = 0;
int ScrollBorderY = 0;
int ScrollJumpX = 8;
int ScrollJumpY = 1;
int GUIDialogs = 1;
int PMDisableAccel = 0;
int SevenBit = 0;
int WeirdScroll = 0;
int LoadDesktopMode = 0;
char HelpCommand[128] = "man -a";
char *ConfigSourcePath = 0;
#ifdef CONFIG_SYNTAX_HILIT
int AddKeyword(ColorKeywords *tab, char color, const char *keyword) {
int len;
len = strlen(keyword);
if (len < 1 || len >= CK_MAXLEN) return 0;
if (tab->key[len]) {
int lx = strlen(tab->key[len]);
char *key;
key = (char *)realloc(tab->key[len], lx + len + 1 + 1);
assert(key != NULL);
tab->key[len] = key;
assert(tab->key[len] != 0);
strcpy(tab->key[len] + lx, keyword);
tab->key[len][lx + len] = color;
tab->key[len][lx + len + 1] = 0;
} else {
tab->key[len] = (char *)malloc(len + 2);
assert(tab->key[len] != 0);
strcpy(tab->key[len], keyword);
tab->key[len][len] = color;
tab->key[len][len + 1] = 0;
}
tab->count[len]++;
tab->TotalCount++;
return 1;
}
#endif
int SetModeNumber(EMode *mode, int what, int number) {
int j = what;
if (j == BFI_LeftMargin || j == BFI_RightMargin) number--;
mode->Flags.num[j] = number;
return 0;
}
int SetModeString(EMode *mode, int what, const char *string) {
int j = what;
#ifdef CONFIG_SYNTAX_HILIT
if (j == BFI_Colorizer) {
mode->fColorize = FindColorizer(string);
} else
#endif
if (j == BFI_EventMap) {
mode->fEventMap = FindEventMap(string);
} else if (j == BFI_IndentMode) {
mode->Flags.num[j] = GetIndentMode(string);
} else if (j == BFS_WordChars) {
SetWordChars(mode->Flags.WordChars, string);
} else if (j == BFS_CapitalChars) {
SetWordChars(mode->Flags.CapitalChars, string);
} else if (j == BFS_FileNameRx) {
if (mode->MatchName)
free(mode->MatchName);
if (mode->MatchNameRx)
RxFree(mode->MatchNameRx);
mode->MatchName = strdup(string);
mode->MatchNameRx = RxCompile(string);
} else if (j == BFS_FirstLineRx) {
if (mode->MatchLine)
free(mode->MatchLine);
if (mode->MatchLineRx)
RxFree(mode->MatchLineRx);
mode->MatchLine = strdup(string);
mode->MatchLineRx = RxCompile(string);
} else {
if (mode->Flags.str[j & 0xFF])
free(mode->Flags.str[j & 0xFF]);
mode->Flags.str[j & 0xFF] = strdup(string);
}
return 0;
}
int SetGlobalNumber(int what, int number) {
switch (what) {
#ifdef CONFIG_INDENT_C
case FLAG_C_Indent: C_Indent = number; break;
case FLAG_C_BraceOfs: C_BraceOfs = number; break;
case FLAG_C_CaseOfs: C_CaseOfs = number; break;
case FLAG_C_CaseDelta: C_CaseDelta = number; break;
case FLAG_C_ClassOfs: C_ClassOfs = number; break;
case FLAG_C_ClassDelta: C_ClassDelta = number; break;
case FLAG_C_ColonOfs: C_ColonOfs = number; break;
case FLAG_C_CommentOfs: C_CommentOfs = number; break;
case FLAG_C_CommentDelta: C_CommentDelta = number; break;
case FLAG_C_FirstLevelIndent: C_FirstLevelIndent = number; break;
case FLAG_C_FirstLevelWidth: C_FirstLevelWidth = number; break;
case FLAG_C_Continuation: C_Continuation = number; break;
case FLAG_C_ParenDelta: C_ParenDelta = number; break;
#endif
#ifdef CONFIG_INDENT_REXX
case FLAG_REXX_Indent: REXX_Base_Indent = number; break;
case FLAG_REXX_Do_Offset: REXX_Do_Offset = number; break;
#endif
case FLAG_ScreenSizeX: ScreenSizeX = number; break;
case FLAG_ScreenSizeY: ScreenSizeY = number; break;
case FLAG_CursorInsertStart: CursorInsSize[0] = number; break;
case FLAG_CursorInsertEnd: CursorInsSize[1] = number; break;
case FLAG_CursorOverStart: CursorOverSize[0] = number; break;
case FLAG_CursorOverEnd: CursorOverSize[1] = number; break;
case FLAG_SysClipboard: SystemClipboard = number; break;
case FLAG_OpenAfterClose: OpenAfterClose = number; break;
case FLAG_ShowVScroll: ShowVScroll = number; break;
case FLAG_ShowHScroll: ShowHScroll = number; break;
case FLAG_ScrollBarWidth: ScrollBarWidth = number; break;
case FLAG_SelectPathname: SelectPathname = number; break;
case FLAG_ShowMenuBar: ShowMenuBar = number; break;
case FLAG_ShowToolBar: ShowToolBar = number; break;
case FLAG_KeepHistory: KeepHistory = number; break;
case FLAG_LoadDesktopOnEntry: LoadDesktopOnEntry = number; break;
case FLAG_SaveDesktopOnExit: SaveDesktopOnExit = number; break;
case FLAG_KeepMessages: KeepMessages = number; break;
case FLAG_ScrollBorderX: ScrollBorderX = number; break;
case FLAG_ScrollBorderY: ScrollBorderY = number; break;
case FLAG_ScrollJumpX: ScrollJumpX = number; break;
case FLAG_ScrollJumpY: ScrollJumpY = number; break;
case FLAG_GUIDialogs: GUIDialogs = number; break;
case FLAG_PMDisableAccel: PMDisableAccel = number; break;
case FLAG_SevenBit: SevenBit = number; break;
case FLAG_WeirdScroll: WeirdScroll = number; break;
case FLAG_LoadDesktopMode: LoadDesktopMode = number; break;
default:
return -1;
}
return 0;
}
int SetGlobalString(long what, const char *string) {
switch (what) {
case FLAG_DefaultModeName: strcpy(DefaultModeName, string); break;
case FLAG_CompletionFilter: if ((CompletionFilter = RxCompile(string)) == NULL) return -1; break;
case FLAG_PrintDevice: strcpy(PrintDevice, string); break;
case FLAG_CompileCommand: strcpy(CompileCommand, string); break;
case FLAG_WindowFont: strcpy(WindowFont, string); break;
case FLAG_HelpCommand: strcpy(HelpCommand, string); break;
default:
return -1;
}
return 0;
}
int SetEventString(EEventMap *Map, long what, const char *string) {
switch (what) {
case EM_MainMenu:
case EM_LocalMenu:
Map->SetMenu(what, string);
break;
default:
return -1;
}
return 0;
}
#ifdef CONFIG_SYNTAX_HILIT
int SetColorizeString(EColorize *Colorize, long what, const char *string) {
switch (what) {
case COL_SyntaxParser:
Colorize->SyntaxParser = GetHilitMode(string);
break;
default:
return -1;
}
return 0;
}
#endif
unsigned char GetObj(CurPos &cp, unsigned short &len) {
len = 0;
if (cp.c + 3 <= cp.z) {
unsigned char c;
unsigned char l[2];
c = *cp.c++;
memcpy(l, cp.c, 2);
len = (l[1] << 8) + l[0];
cp.c += 2;
return c;
}
return 0xFF;
}
const char *GetCharStr(CurPos &cp, unsigned short len) {
const char *p = cp.c;
if (cp.c + len > cp.z)
return 0;
cp.c += len;
return p;
}
int GetNum(CurPos &cp, long &num) {
unsigned char n[4];
if (cp.c + 4 > cp.z) return 0;
memcpy(n, cp.c, 4);
num =
(n[3] << 24) +
(n[2] << 16) +
(n[1] << 8) +
n[0];
if ((n[3] > 127) && sizeof(long) > 4)
num = num | (~0xFFFFFFFFUL);
cp.c += 4;
return 1;
}
int ReadCommands(CurPos &cp, const char *Name) {
unsigned char obj;
unsigned short len;
long Cmd = NewCommand(Name);
long cmdno;
if (GetObj(cp, len) != CF_INT) return-1;
if (GetNum(cp, cmdno) == 0) return -1;
if (cmdno != (Cmd | CMD_EXT)) {
fprintf(stderr, "Bad Command map %s -> %ld != %ld\n", Name, Cmd, cmdno);
return -1;
}
while ((obj = GetObj(cp, len)) != 0xFF) {
switch (obj) {
case CF_COMMAND:
{
// char *s;
long cnt;
long ign;
long cmd;
// if ((s = GetCharStr(cp, len)) == 0) return -1;
if (GetNum(cp, cmd) == 0) return -1;
if (GetObj(cp, len) != CF_INT) return -1;
if (GetNum(cp, cnt) == 0) return -1;
if (GetObj(cp, len) != CF_INT) return -1;
if (GetNum(cp, ign) == 0) return -1;
// if (cmd != CmdNum(s)) {
// fprintf(stderr, "Bad Command Id: %s -> %d\n", s, cmd);
// return -1;
// }
if (AddCommand(Cmd, cmd, cnt, ign) == 0) {
if (Name == 0 || strcmp(Name, "xx") != 0) {
fprintf(stderr, "Bad Command Id: %ld\n", cmd);
return -1;
}
}
}
break;
case CF_STRING:
{
const char *s = GetCharStr(cp, len);
if (s == 0) return -1;
if (AddString(Cmd, s) == 0) return -1;
}
break;
case CF_INT:
{
long num;
if (GetNum(cp, num) == 0) return -1;
if (AddNumber(Cmd, num) == 0) return -1;
}
break;
case CF_VARIABLE:
{
long num;
if (GetNum(cp, num) == 0) return -1;
if (AddVariable(Cmd, num) == 0) return -1;
}
break;
case CF_CONCAT:
if (AddConcat(Cmd) == 0) return -1;
break;
case CF_END:
return Cmd;
default:
return -1;
}
}
return -1;
}
int ReadMenu(CurPos &cp, const char *MenuName) {
unsigned char obj;
unsigned short len;
int menu = -1, item = -1;
menu = NewMenu(MenuName);
while ((obj = GetObj(cp, len)) != 0xFF) {
switch (obj) {
case CF_ITEM:
{
if (len == 0) {
item = NewItem(menu, 0);
} else {
const char *s = GetCharStr(cp, len);
int Cmd;
if (s == 0) return -1;
item = NewItem(menu, s);
if ((obj = GetObj(cp, len)) != CF_MENUSUB) return -1;
if ((Cmd = ReadCommands(cp, 0)) == -1) return -1;
Menus[menu].Items[item].Cmd = Cmd + 65536;
}
}
break;
case CF_SUBMENU:
{
const char *s = GetCharStr(cp, len);
const char *w;
if ((obj = GetObj(cp, len)) != CF_STRING) return -1;
if ((w = GetCharStr(cp, len)) == 0) return -1;
item = NewSubMenu(menu, s, GetMenuId(w), SUBMENU_NORMAL);
}
break;
case CF_SUBMENUCOND:
{
const char *s = GetCharStr(cp, len);
const char *w;
if ((obj = GetObj(cp, len)) != CF_STRING) return -1;
if ((w = GetCharStr(cp, len)) == 0) return -1;
item = NewSubMenu(menu, s, GetMenuId(w), SUBMENU_CONDITIONAL);
}
break;
case CF_END:
return 0;
default:
return -1;
}
}
return -1;
}
int ReadColors(CurPos &cp, const char *ObjName) {
unsigned char obj;
unsigned short len;
while ((obj = GetObj(cp, len)) != 0xFF) {
switch (obj) {
case CF_STRING:
{
char cl[30];
const char *sname = GetCharStr(cp, len);
const char *svalue;
if (sname == 0) return -1;
if ((obj = GetObj(cp, len)) != CF_STRING) return -1;
if ((svalue = GetCharStr(cp, len)) == 0) return -1;
strcpy(cl, ObjName);
strcat(cl, ".");
strcat(cl, sname);
if (SetColor(cl, svalue) == 0) return -1;
}
break;
case CF_END:
return 0;
default:
return -1;
}
}
return -1;
}
#ifdef CONFIG_SYNTAX_HILIT
int ReadHilitColors(CurPos &cp, EColorize *Colorize, const char * /*ObjName*/) {
unsigned char obj;
unsigned short len;
while ((obj = GetObj(cp, len)) != 0xFF) {
switch (obj) {
case CF_INT:
{
long cidx;
const char *svalue;
if (GetNum(cp, cidx) == 0) return -1;
if ((obj = GetObj(cp, len)) != CF_STRING)
return -1;
if ((svalue = GetCharStr(cp, len)) == 0)
return -1;
if (Colorize->SetColor(cidx, svalue) == 0)
return -1;
}
break;
case CF_END:
return 0;
default:
return -1;
}
}
return -1;
}
int ReadKeywords(CurPos &cp, ColorKeywords *keywords, int color) {
unsigned char obj;
unsigned short len;
while ((obj = GetObj(cp, len)) != 0xFF) {
switch (obj) {
case CF_STRING:
{
const char *kname = GetCharStr(cp, len);
if (kname == 0) return -1;
if (AddKeyword(keywords, (char) color, kname) != 1) return -1;
}
break;
case CF_END:
return 0;
default:
return -1;
}
}
return -1;
}
#endif
int ReadEventMap(CurPos &cp, EEventMap *Map, const char * /*MapName*/) {
unsigned char obj;
unsigned short len;
while ((obj = GetObj(cp, len)) != 0xFF) {
switch (obj) {
case CF_KEY:
{
EKey *Key;
const char *s;
int Cmd;
if ((s = GetCharStr(cp, len)) == 0) return -1;
if ((Key = SetKey(Map, s)) == 0) return -1;
if ((obj = GetObj(cp, len)) != CF_KEYSUB) return -1;
if ((Cmd = ReadCommands(cp, 0)) == -1) return -1;
Key->Cmd = Cmd;
}
break;
#ifdef CONFIG_ABBREV
case CF_ABBREV:
{
EAbbrev *Ab;
const char *s;
const char *x;
int Cmd;
if ((s = GetCharStr(cp, len)) == 0) return -1;
obj = GetObj(cp, len);
if (obj == CF_KEYSUB) {
if ((Cmd = ReadCommands(cp, 0)) == -1) return -1;
Ab = new EAbbrev(s, Cmd);
} else if (obj == CF_STRING) {
x = GetCharStr(cp, len);
Ab = new EAbbrev(s, x);
} else
return -1;
if (Ab) {
Map->AddAbbrev(Ab);
}
}
break;
#endif
case CF_SETVAR:
{
long what;
if (GetNum(cp, what) == 0) return -1;
switch (GetObj(cp, len)) {
case CF_STRING:
{
const char *val = GetCharStr(cp, len);
if (len == 0) return -1;
if (SetEventString(Map, what, val) != 0) return -1;
}
break;
/* case CF_INT:
{
long num;
if (GetNum(cp, num) == 0) return -1;
if (SetModeNumber(Mode, what, num) != 0) return -1;
}
break;*/
default:
return -1;
}
}
break;
case CF_END:
return 0;
default:
return -1;
}
}
return -1;
}
#ifdef CONFIG_SYNTAX_HILIT
int ReadColorize(CurPos &cp, EColorize *Colorize, const char *ModeName) {
unsigned char obj;
unsigned short len;
long LastState = -1;
while ((obj = GetObj(cp, len)) != 0xFF) {
switch (obj) {
case CF_COLOR:
if (ReadHilitColors(cp, Colorize, ModeName) == -1) return -1;
break;
case CF_KEYWORD:
{
const char *colorstr;
if ((colorstr = GetCharStr(cp, len)) == 0) return -1;
unsigned int Col;
unsigned int ColBg, ColFg;
if (sscanf(colorstr, "%1X %1X", &ColFg, &ColBg) != 2)
return 0;
Col = ColFg | (ColBg << 4);
int color = ChColor(Col);
if (ReadKeywords(cp, &Colorize->Keywords, color) == -1) return -1;
}
break;
case CF_HSTATE:
{
long stateno;
long color;
if (Colorize->hm == 0)
Colorize->hm = new HMachine();
assert(Colorize->hm != 0);
if (GetNum(cp, stateno) == 0)
return -1;
assert(stateno == LastState + 1);
obj = GetObj(cp, len);
assert(obj == CF_INT);
if (GetNum(cp, color) == 0)
return -1;
HState newState;
newState.InitState();
newState.color = color;
Colorize->hm->AddState(newState);
LastState = stateno;
}
break;
case CF_HTRANS:
{
HTrans newTrans;
long nextState;
long matchFlags;
const char *match;
long color;
if (GetNum(cp, nextState) == 0)
return -1;
obj = GetObj(cp, len);
assert(obj == CF_INT);
if (GetNum(cp, matchFlags) == 0)
return -1;
obj = GetObj(cp, len);
assert(obj == CF_INT);
if (GetNum(cp, color) == 0)
return -1;
obj = GetObj(cp, len);
assert(obj == CF_STRING);
if ((match = GetCharStr(cp, len)) == 0)
return -1;
newTrans.InitTrans();
newTrans.matchFlags = matchFlags;
newTrans.nextState = nextState;
newTrans.color = color;
if ((newTrans.matchFlags & MATCH_SET) ||
(newTrans.matchFlags & MATCH_NOTSET))
{
newTrans.matchLen = 1;
newTrans.match = (char *)malloc(256/8);
assert(newTrans.match != NULL);
SetWordChars(newTrans.match, match);
} else {
newTrans.match = strdup(match);
newTrans.matchLen = strlen(match);
}
Colorize->hm->AddTrans(newTrans);
}
break;
case CF_HWTYPE:
{
long nextKwdMatchedState;
long nextKwdNotMatchedState;
long nextKwdNoCharState;
long options;
const char *wordChars;
obj = GetObj(cp, len);
assert(obj == CF_INT);
if (GetNum(cp, nextKwdMatchedState) == 0)
return -1;
obj = GetObj(cp, len);
assert(obj == CF_INT);
if (GetNum(cp, nextKwdNotMatchedState) == 0)
return -1;
obj = GetObj(cp, len);
assert(obj == CF_INT);
if (GetNum(cp, nextKwdNoCharState) == 0)
return -1;
obj = GetObj(cp, len);
assert(obj == CF_INT);
if (GetNum(cp, options) == 0)
return -1;
obj = GetObj(cp, len);
assert(obj == CF_STRING);
if ((wordChars = GetCharStr(cp, len)) == 0)
return -1;
Colorize->hm->LastState()->options = options;
Colorize->hm->LastState()->nextKwdMatchedState = nextKwdMatchedState;
Colorize->hm->LastState()->nextKwdNotMatchedState = nextKwdNotMatchedState;
Colorize->hm->LastState()->nextKwdNoCharState = nextKwdNoCharState;
if (wordChars && *wordChars) {
Colorize->hm->LastState()->wordChars = (char *)malloc(256/8);
assert(Colorize->hm->LastState()->wordChars != NULL);
SetWordChars(Colorize->hm->LastState()->wordChars, wordChars);
}
}
break;
case CF_HWORDS:
{
const char *colorstr;
int color;
if ((colorstr = GetCharStr(cp, len)) == 0) return -1;
color = hcPlain_Keyword;
if (strcmp(colorstr, "-") != 0) {
const char *Value = colorstr;
int Col;
if (*Value == '-') {
Value++;
if (sscanf(Value, "%1X", &Col) != 1) return -1;
Col |= (hcPlain_Background & 0xF0);
} else if (Value[1] == '-') {
if (sscanf(Value, "%1X", &Col) != 1) return -1;
Col <<= 4;
Col |= (hcPlain_Background & 0x0F);
} else {
if (sscanf(Value, "%2X", &Col) != 1) return -1;
}
color = Col;
}
if (ReadKeywords(cp, &Colorize->hm->LastState()->keywords, color) == -1) return -1;
}
break;
case CF_SETVAR:
{
long what;
if (GetNum(cp, what) == 0) return -1;
switch (GetObj(cp, len)) {
case CF_STRING:
{
const char *val = GetCharStr(cp, len);
if (len == 0) return -1;
if (SetColorizeString(Colorize, what, val) != 0) return -1;
}
break;
/* case CF_INT:
{
long num;
if (GetNum(cp, num) == 0) return -1;
if (SetModeNumber(Mode, what, num) != 0) return -1;
}
break;*/
default:
return -1;
}
}
break;
case CF_END:
return 0;
default:
return -1;
}
}
return -1;
}
#endif
int ReadMode(CurPos &cp, EMode *Mode, const char * /*ModeName*/) {
unsigned char obj;
unsigned short len;
while ((obj = GetObj(cp, len)) != 0xFF) {
switch (obj) {
case CF_SETVAR:
{
long what;
if (GetNum(cp, what) == 0) return -1;
switch (GetObj(cp, len)) {
case CF_STRING:
{
const char *val = GetCharStr(cp, len);
if (len == 0) return -1;
if (SetModeString(Mode, what, val) != 0) return -1;
}
break;
case CF_INT:
{
long num;
if (GetNum(cp, num) == 0) return -1;
if (SetModeNumber(Mode, what, num) != 0) return -1;
}
break;
default:
return -1;
}
}
break;
case CF_END:
return 0;
default:
return -1;
}
}
return -1;
}
int ReadObject(CurPos &cp, const char *ObjName) {
unsigned char obj;
unsigned short len;
while ((obj = GetObj(cp, len)) != 0xFF) {
switch (obj) {
case CF_COLOR:
if (ReadColors(cp, ObjName) == -1) return -1;
break;
#ifdef CONFIG_OBJ_MESSAGES
case CF_COMPRX:
{
long file, line, msg;
const char *regexp;
if (GetObj(cp, len) != CF_INT) return -1;
if (GetNum(cp, file) == 0) return -1;
if (GetObj(cp, len) != CF_INT) return -1;
if (GetNum(cp, line) == 0) return -1;
if (GetObj(cp, len) != CF_INT) return -1;
if (GetNum(cp, msg) == 0) return -1;
if (GetObj(cp, len) != CF_REGEXP) return -1;
if ((regexp = GetCharStr(cp, len)) == 0) return -1;
if (AddCRegexp(file, line, msg, regexp) == 0) return -1;
}
break;
#endif
case CF_SETVAR:
{
long what;
if (GetNum(cp, what) == 0) return -1;
switch (GetObj(cp, len)) {
case CF_STRING:
{
const char *val = GetCharStr(cp, len);
if (len == 0) return -1;
if (SetGlobalString(what, val) != 0) return -1;
}
break;
case CF_INT:
{
long num;
if (GetNum(cp, num) == 0) return -1;
if (SetGlobalNumber(what, num) != 0) return -1;
}
break;
default:
return -1;
}
}
break;
case CF_END:
return 0;
default:
return -1;
}
}
return -1;
}
int ReadConfigFile(CurPos &cp) {
unsigned char obj;
unsigned short len;
{
const char *p;
obj = GetObj(cp, len);
assert(obj == CF_STRING);
if ((p = GetCharStr(cp, len)) == 0)
return -1;
if (ConfigSourcePath)
free(ConfigSourcePath);
ConfigSourcePath = strdup(p);
}
while ((obj = GetObj(cp, len)) != 0xFF) {
switch (obj) {
case CF_SUB:
{
const char *CmdName = GetCharStr(cp, len);
if (ReadCommands(cp, CmdName) == -1) return -1;
}
break;
case CF_MENU:
{
const char *MenuName = GetCharStr(cp, len);
if (ReadMenu(cp, MenuName) == -1) return -1;
}
break;
case CF_EVENTMAP:
{
EEventMap *EventMap = 0;
const char *MapName = GetCharStr(cp, len);
const char *UpMap = 0;
if ((obj = GetObj(cp, len)) != CF_PARENT) return -1;
if (len > 0)
if ((UpMap = GetCharStr(cp, len)) == 0) return -1;
// add new mode
if ((EventMap = FindEventMap(MapName)) == 0) {
EEventMap *OrgMap = 0;
if (strcmp(UpMap, "") != 0)
OrgMap = FindEventMap(UpMap);
EventMap = new EEventMap(MapName, OrgMap);
} else {
if (EventMap->Parent == 0)
EventMap->Parent = FindEventMap(UpMap);
}
if (ReadEventMap(cp, EventMap, MapName) == -1) return -1;
}
break;
case CF_COLORIZE:
{
EColorize *Mode = 0;
const char *ModeName = GetCharStr(cp, len);
const char *UpMode = 0;
if ((obj = GetObj(cp, len)) != CF_PARENT) return -1;
if (len > 0)
if ((UpMode = GetCharStr(cp, len)) == 0) return -1;
// add new mode
if ((Mode = FindColorizer(ModeName)) == 0)
Mode = new EColorize(ModeName, UpMode);
else {
if (Mode->Parent == 0)
Mode->Parent = FindColorizer(UpMode);
}
if (ReadColorize(cp, Mode, ModeName) == -1)
return -1;
}
break;
case CF_MODE:
{
EMode *Mode = 0;
const char *ModeName = GetCharStr(cp, len);
const char *UpMode = 0;
if ((obj = GetObj(cp, len)) != CF_PARENT) return -1;
if (len > 0)
if ((UpMode = GetCharStr(cp, len)) == 0) return -1;
// add new mode
if ((Mode = FindMode(ModeName)) == 0) {