-
Notifications
You must be signed in to change notification settings - Fork 0
/
inifile.c
3720 lines (3268 loc) · 171 KB
/
inifile.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
//***************************************************************************
// NARS2000 -- INI File Routines
//***************************************************************************
/***************************************************************************
NARS2000 -- An Experimental APL Interpreter
Copyright (C) 2006-2016 Sudley Place Software
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 3 of the License, or
(at your option) any later 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, see <http://www.gnu.org/licenses/>.
***************************************************************************/
#define STRICT
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "headers.h"
////#include "bom.h"
// Section names
#define SECTNAME_GENERAL L"General"
#define SECTNAME_SYSVARS L"SysVars"
#define SECTNAME_FONTS L"Fonts"
#define SECTNAME_APLFONTS L"APL Fonts"
#define SECTNAME_OPTIONS L"Options"
#define SECTNAME_RANGELIMITS L"RangeLimits"
#define SECTNAME_RESETVARS L"ResetVars"
#define SECTNAME_SAMEFONTAS L"SameFontAs"
#define SECTNAME_COLORS L"Colors"
#define SECTNAME_TOOLBARS L"Toolbars"
#define SECTNAME_MIGRATION L"Migration"
#define SECTNAME_RECENTFILES L"RecentFiles"
#define SECTNAME_KEYBOARDS L"Keyboards"
#define SECTNAME_KEYBPREFIX L"KeybLayout-"
#define SECTNAME_LIBDIRS L"LibDirs"
// Key names
#define KEYNAME_VERSION L"Version"
#define KEYNAME_SIZESTATE L"SizeState"
#define KEYNAME_XPOS L"xPos"
#define KEYNAME_XSIZE L"xSize"
#define KEYNAME_YPOS L"yPos"
#define KEYNAME_YSIZE L"ySize"
#define KEYNAME_INITIALCAT L"InitialCategory"
#define KEYNAME_COUNT L"Count"
#define KEYNAME_UNIBASE L"Unibase"
#define KEYNAME_CHAR L"Char"
#define KEYNAME_KEYBTCNUM L"KeybTCNum"
#define KEYNAME_KEYBSTATE L"KeybState"
#define KEYNAME_KEYBLAYOUTNAME L"KeybLayoutName"
#define KEYNAME_KEYBSCANCODE L"KSC"
#define KEYNAME_KEYBSCANCODE2B L"KeybScanCode2B"
#define KEYNAME_KEYBEXTRAKEYROW3 L"KeybExtraKeyRow3"
#define KEYNAME_KEYBUSECXV L"KeybUseCXV"
#define KEYNAME_KEYBUSEZY L"KeybUseZY"
#define KEYNAME_KEYBUSESEQ L"KeybUseSEQ"
#define KEYNAME_LOGFONTKB L"LogFontKB"
#define KEYNAME_IC0LOG0 L"IC0LOG0"
#define KEYNAME_QUADALX L"QuadALX"
#define KEYNAME_QUADCT L"QuadCT"
#define KEYNAME_QUADDT L"QuadDT"
#define KEYNAME_QUADELX L"QuadELX"
#define KEYNAME_QUADFC L"QuadFC"
#define KEYNAME_QUADFEATURE L"QuadFEATURE"
#define KEYNAME_QUADFPC L"QuadFPC"
#define KEYNAME_QUADIC L"QuadIC"
#define KEYNAME_QUADIO L"QuadIO"
#define KEYNAME_QUADLX L"QuadLX"
#define KEYNAME_QUADMF L"QuadMF"
#define KEYNAME_QUADPP L"QuadPP"
#define KEYNAME_QUADPR L"QuadPR"
#define KEYNAME_QUADPW L"QuadPW"
#define KEYNAME_QUADRL L"QuadRL"
#define KEYNAME_QUADSA L"QuadSA"
#define KEYNAME_LOGFONTFE L"LogFontFE"
#define KEYNAME_LOGFONTPR L"LogFontPR"
#define KEYNAME_LOGFONTSM L"LogFontSM"
#define KEYNAME_LOGFONTTC L"LogFontTC"
#define KEYNAME_ADJUSTPW L"AdjustPW"
#define KEYNAME_UNDERBARTOLOWERCASE L"UnderbarToLowercase"
#define KEYNAME_NEWTABONCLEAR L"NewTabOnClear"
#define KEYNAME_NEWTABONLOAD L"NewTabOnload"
#define KEYNAME_USELOCALTIME L"UseLocalTime"
#define KEYNAME_BACKUPONLOAD L"BackupOnLoad"
#define KEYNAME_BACKUPONSAVE L"BackupOnSave"
#define KEYNAME_NOCOPYRIGHTMSG L"NoCopyrightMsg"
#define KEYNAME_DEFAULTPASTE L"DefaultPaste"
#define KEYNAME_DEFAULTCOPY L"DefaultCopy"
#define KEYNAME_SYNTCLRFCNS L"SyntClrFcns"
#define KEYNAME_SYNTCLRSESS L"SyntClrSess"
#define KEYNAME_SYNTCLRPRNT L"SyntClrPrnt"
#define KEYNAME_CHECKGROUP L"CheckGroup"
#define KEYNAME_INSSTATE L"InsState"
#define KEYNAME_REVDBLCLK L"RevDblClk"
#define KEYNAME_VIEWSTATUSBAR L"ViewStatusBar"
#define KEYNAME_DEFDISPFCNLINENUMS L"DefDispFcnLineNums"
#define KEYNAME_DISPMPSUF L"DisplayMPSuffix"
#define KEYNAME_OUTPUTDEBUG L"OutputDebug"
#define KEYNAME_SC_GLBNAME L"GlbName"
#define KEYNAME_SC_LCLNAME L"LclName"
#define KEYNAME_SC_LABEL L"Label"
#define KEYNAME_SC_PRIMFCN L"PrimFcn"
#define KEYNAME_SC_PRIMOP1 L"PrimOp1"
#define KEYNAME_SC_PRIMOP2 L"PrimOp2"
#define KEYNAME_SC_SYSFCN L"SysFcn"
#define KEYNAME_SC_GLBSYSVAR L"GlbSysVar"
#define KEYNAME_SC_LCLSYSVAR L"LclSysVar"
#define KEYNAME_SC_CTRLSTRUC L"CtrlStruc"
#define KEYNAME_SC_NUMCONST L"NumConst"
#define KEYNAME_SC_CHRCONST L"ChrConst"
#define KEYNAME_SC_PNSEP L"PNSep"
#define KEYNAME_SC_COMMENT L"Comment"
#define KEYNAME_SC_LINEDRAWING L"LineDrawing"
#define KEYNAME_SC_FCNLINENUMS L"FcnLineNums"
#define KEYNAME_SC_MATCHGRP1 L"MatchGrp1"
#define KEYNAME_SC_MATCHGRP2 L"MatchGrp2"
#define KEYNAME_SC_MATCHGRP3 L"MatchGrp3"
#define KEYNAME_SC_MATCHGRP4 L"MatchGrp4"
#define KEYNAME_SC_UNMATCHGRP L"UnmatchGrp"
#define KEYNAME_SC_UNNESTED L"UnnestedGrp"
#define KEYNAME_SC_UNK L"Unk"
#define KEYNAME_SC_LINECONT L"LineContinuation"
#define KEYNAME_SC_WINTEXT L"WinText"
#define KEYNAME_CUSTOMCOLORS L"CustomColors"
#define KEYNAME_TOOLBAR_WS L"Workspace"
#define KEYNAME_TOOLBAR_ED L"Edit"
#define KEYNAME_TOOLBAR_FN L"Objects"
#define KEYNAME_TOOLBAR_FW L"SMFont"
#define KEYNAME_TOOLBAR_LW L"Language"
#define KEYNAME_UPDFRQ L"UpdateFrequency"
#define KEYNAME_UPDCHK L"UpdateCheck"
// Format string for Keyboard Layout SCA Chars for each ScanCode
#define FMTSTR_KEYBCHARS L"%04X, %04X, %04X, %04X, %04X, %04X, %04X, %04X"
// Format string for [Fonts] section LOGFONTW
#define FMTSTR_LOGFONT_INP L"%d %d %d %d %d %d %d %d %d %d %d %d %d '%s'"
#define FMTSTR_LOGFONT_OUT L"%d %d %d %d %d %d %d %d %d %d %d %d %d '%s'"
// Format string for [Colors] section
#define FMTSTR_SYNTAXCOLOR L"%u, %u, %u"
#define FMTSTR_CUSTOMCOLORS L"%u, %u, %u, %u, " \
L"%u, %u, %u, %u, " \
L"%u, %u, %u, %u, " \
L"%u, %u, %u, %u"
// Array of keynames for use in [Colors] section
LPWCHAR aColorKeyNames[] =
{KEYNAME_SC_GLBNAME , // 00: Global Name
KEYNAME_SC_LCLNAME , // 01: Local ...
KEYNAME_SC_LABEL , // 02: Label
KEYNAME_SC_PRIMFCN , // 03: Primitive Function
KEYNAME_SC_PRIMOP1 , // 04: Primitive Monadic Operator
KEYNAME_SC_PRIMOP2 , // 05: Primitive Dyadic Operator
KEYNAME_SC_SYSFCN , // 06: System Function
KEYNAME_SC_GLBSYSVAR , // 07: Global System Variable
KEYNAME_SC_LCLSYSVAR , // 08: Local ...
KEYNAME_SC_CTRLSTRUC , // 09: Control Structure
KEYNAME_SC_NUMCONST , // 0A: Numeric constant
KEYNAME_SC_CHRCONST , // 0B: Character constant
KEYNAME_SC_PNSEP , // 0C: Point notation separator
KEYNAME_SC_COMMENT , // 0D: Comment
KEYNAME_SC_LINEDRAWING , // 0E: Line drawing chars
KEYNAME_SC_FCNLINENUMS , // 0F: Function line numbers
KEYNAME_SC_MATCHGRP1 , // 10: Matched Grouping Symbols [] () {}
KEYNAME_SC_MATCHGRP2 , // 11: Matched Grouping Symbols [] () {}
KEYNAME_SC_MATCHGRP3 , // 12: Matched Grouping Symbols [] () {}
KEYNAME_SC_MATCHGRP4 , // 13: Matched Grouping Symbols [] () {}
KEYNAME_SC_UNMATCHGRP , // 14: Unmatched Grouping Symbols [] () {} ' "
KEYNAME_SC_UNNESTED , // 15: Improperly Nested Grouping Symbols [] () {}
KEYNAME_SC_UNK , // 16: Unknown symbol
KEYNAME_SC_LINECONT , // 17: Line Continuation
KEYNAME_SC_WINTEXT , // 18: Window text
};
// Array of keynames for use in [Toolbars] section
LPWCHAR aToolbarNames[] =
{KEYNAME_TOOLBAR_WS, // Workspace
KEYNAME_TOOLBAR_ED, // Edit
KEYNAME_TOOLBAR_FN, // Objects
KEYNAME_TOOLBAR_FW, // SM Font
KEYNAME_TOOLBAR_LW, // Language
};
// Migration level struc
typedef struct tagMIGRATION
{
UINT IC0LOG0:2,
:31;
} MIGRATION, *LPMIGRATION;
// Default migration levels
MIGRATION uMigration = {0};
#define STRCNT_KEYBPREFIX strcountof (SECTNAME_KEYBPREFIX)
#define STRCNT_KEYBSCANCODE strcountof (KEYNAME_KEYBSCANCODE)
WCHAR wszSectName[STRCNT_KEYBPREFIX + 4], // Room for prefix, some digits, and a terminating zero
wszKeyName[STRCNT_KEYBSCANCODE + 2 + 1]; // Room for prefix, 2 hex digits, and a terminating zero
//***************************************************************************
// $CreateAppDataDirs
//
// Ensure the Application Data and workspaces
// directories are present
//***************************************************************************
UBOOL CreateAppDataDirs
(void)
{
static WCHAR wszAppData[2 * MAX_PATH];
DWORD cchSize;
WCHAR wszTemp[1024];
UINT uNxt;
#define TEMPBUFLEN countof (wszTemp)
#define WS_APPDATA L"APPDATA"
// If we didn't find it, ...
if (0 EQ GetEnvironmentVariableW (WS_APPDATA, wszAppData, TEMPBUFLEN))
{
MBW (L"Unable to find " WS_APPDATA L" in the environment.");
return FALSE;
} // End IF
#undef WS_APPDATA
// Append the "\\NARS2000" part
MyStrcatW (wszAppData, sizeof (wszAppData), WS_SLOPE WS_APPNAME);
// Ensure the "...\\Application Data\\NARS2000" directory is present
if (!CreateDirectoryW (wszAppData, NULL)
&& GetLastError () NE ERROR_ALREADY_EXISTS)
{
// Start with leading text
strcpyW (wszTemp, L"CreateAppDataDirs (wszAppData): ");
uNxt = lstrlenW (wszTemp);
// Format the error message
FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM, // Source and processing options
NULL, // Pointer to message source
GetLastError (), // Requested message identifier
0, // Language identifier for requested message
&wszTemp[uNxt], // Pointer to message buffer
TEMPBUFLEN - uNxt, // Maximum size of message buffer
NULL); // Address of array of message inserts
#ifdef DEBUG
DbgBrk (); // #ifdef DEBUG
#endif
MBW (wszTemp);
return FALSE;
} // End IF
// Get the size so we can append to it
cchSize = lstrlenW (wszAppData);
// Now append the .ini file name to get lpwszIniFile
strcpyW (&wszAppData[cchSize], WS_SLOPE WS_APPNAME L".ini");
lpwszIniFile = wszAppData;
// Get ptr to where the workspaces dir will be stored
// The "+ 1" is to skip over the terminating zero
lpwszWorkDir = &wszAppData[lstrlenW (lpwszIniFile) + 1];
// Append the AppData directory part so we can form the workspaces dir
// The "+ 1" is because strcpynW includes a terminating zero in the count
strcpynW (lpwszWorkDir, lpwszIniFile, cchSize + 1);
// Append the workspaces name
strcatW (lpwszWorkDir, WS_SLOPE WS_WKSNAME);
// Ensure the workspaces dir is present
if (!CreateDirectoryW (lpwszWorkDir, NULL)
&& GetLastError () NE ERROR_ALREADY_EXISTS)
{
// Start with leading text
strcpyW (wszTemp, L"CreateAppDataDirs (lpwszWorkDir): ");
uNxt = lstrlenW (wszTemp);
// Format the error message
FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM, // Source and processing options
NULL, // Pointer to message source
GetLastError (), // Requested message identifier
0, // Language identifier for requested message
&wszTemp[uNxt], // Pointer to message buffer
TEMPBUFLEN - uNxt, // Maximum size of message buffer
NULL); // Address of array of message inserts
#undef TEMPBUFLEN
#ifdef DEBUG
DbgBrk (); // #ifdef DEBUG
#endif
MBW (wszTemp);
return FALSE;
} // End IF
// Ensure there's a trailing backslash
strcatW (lpwszWorkDir, WS_SLOPE);
return TRUE;
} // End CreateAppDataDirs
//***************************************************************************
// $ReadAplFontNames
//
// Read the [APL Fonts] names and fill a ComboBox with them
//***************************************************************************
void ReadAplFontNames
(HWND hWndCB) // Window handle to ComboBox
{
int iNumFonts, // # APL Fonts
iCnt; // Loop counter
WCHAR wszTemp[1024], // Temporary storage for string results
wszCount[8]; // Save area for formatted APL Fonts counter
// If there's an [APL Fonts] section, ...
iNumFonts =
GetPrivateProfileIntW (SECTNAME_APLFONTS, // Ptr to the section name
KEYNAME_COUNT, // Ptr to the key name
-1, // Default value if not found
lpwszIniFile); // Ptr to the file name
// If there is no [APL Fonts] section, ...
if (iNumFonts <= 0)
{
// Fill with the default APL fonts
AppendAplFont (hWndCB, L"APL2 Unicode Italic" );
AppendAplFont (hWndCB, L"APL385 Unicode" );
AppendAplFont (hWndCB, L"APLX Upright" );
AppendAplFont (hWndCB, L"Courier APL2 Unicode" );
AppendAplFont (hWndCB, L"SImPL" );
AppendAplFont (hWndCB, L"SImPL medium" );
} else
// Loop through the Font Names
for (iCnt = 0; iCnt < iNumFonts; iCnt++)
{
// Format the counter
MySprintfW (wszCount,
sizeof (wszCount),
L"%d",
iCnt);
// Read in the Font Name
GetPrivateProfileStringW (SECTNAME_APLFONTS, // Ptr to the section name
wszCount, // Ptr to the key name
L"", // Ptr to the default value
wszTemp, // Ptr to the output buffer
countof (wszTemp), // Count of the output buffer
lpwszIniFile); // Ptr to the file name
// If the name is present, ...
if (wszTemp[0])
// Append it to the ComboBox
AppendAplFont (hWndCB, wszTemp);
} // End IF/ELSE/FOR
} // End ReadAplFontNames
//***************************************************************************
// $AppendAplFont
//
// Append an APL font to a ComboBox, first ensuring that it's present
//***************************************************************************
void AppendAplFont
(HWND hWndCB, // Window handle to ComboBox
LPWCHAR lpwFontName) // Ptr to APL font name
{
HDC hDC; // Temporary Device Context
// Initialize the global var
bAPLFont = FALSE;
hDC = MyGetDC (HWND_DESKTOP);
SetAttrs (hDC, NULL, DEF_SCN_BLACK, DEF_SCN_WHITE);
// Enumerate fonts to ensure our default font is installed
EnumFontsW (hDC,
lpwFontName,
(FONTENUMPROCW) EnumCallbackFindAplFont,
(LPARAM) lpwFontName);
// Release the DC
MyReleaseDC (HWND_DESKTOP, hDC); hDC = NULL;
// If we found the font name, ...
if (bAPLFont)
// Add the Font Name to our list
SendMessageW (hWndCB, CB_ADDSTRING, 0, (LPARAM) lpwFontName);
} // End AppendAplFont
//***************************************************************************
// $WriteAplFontNames
//
// Write out the APL Font Names from a given ComboBox
// to the [APL Fonts] section
//***************************************************************************
void WriteAplFontNames
(HWND hWndCB) // Window handle to ComboBox
{
UINT uNumFonts, // # APL Fonts
uCnt; // Loop counter
WCHAR wszTemp[1024], // Temporary storage for string results
wszCount[8]; // Save area for formatted APL Fonts counter
// Clear the [APL Fonts] section
WritePrivateProfileSectionW (SECTNAME_APLFONTS, // Ptr to the section name
NULL, // No data
lpwszIniFile); // Ptr to the file name
// Get the # APL Fonts
uNumFonts = (UINT)
SendMessageW (hWndCB, CB_GETCOUNT, 0, 0);
// Loop through the Font Names
for (uCnt = 0; uCnt < uNumFonts; uCnt++)
{
// Get the next Font Name
SendMessageW (hWndCB, CB_GETLBTEXT, uCnt, (LPARAM) wszTemp);
// Format the counter
MySprintfW (wszCount,
sizeof (wszCount),
L"%d",
uCnt);
// Write out the Font Name
WritePrivateProfileStringW (SECTNAME_APLFONTS, // Ptr to the section name
wszCount, // Ptr to the key name
wszTemp, // Ptr to the key value
lpwszIniFile); // Ptr to the file name
} // End FOR
// Format the counter
MySprintfW (wszCount,
sizeof (wszCount),
L"%d",
uNumFonts);
// Write out the count
WritePrivateProfileStringW (SECTNAME_APLFONTS, // Ptr to the section name
KEYNAME_COUNT, // Ptr to the key name
wszCount, // Ptr to the key value
lpwszIniFile); // Ptr to the file name
} // End WriteAplFontNames
//***************************************************************************
// $ReadIniFileGlb
//
// Read in global-specific .ini file settings
//***************************************************************************
#ifdef DEBUG
#define APPEND_NAME L" -- ReadIniFileGlb"
#else
#define APPEND_NAME
#endif
UBOOL ReadIniFileGlb
(void)
{
WCHAR wszTemp[1024], // Temporary storage for string results
wszKey[8 + 1], // Room for a keyname
*lpwszTemp; // Temporary ptr into wszTemp
UINT uCnt, // Loop counter
uCnt2, // ...
uCol; // ...
WCHAR (*lpwszRecentFiles)[][_MAX_PATH]; // Ptr to list of recent files
LPKEYBLAYOUTS lpKeybLayouts; // Ptr to keyboard layouts global memory
LPWSZLIBDIRS lpwszLibDirs; // Ptr to LibDirs
WORD hkl; // Default keyboard layout
LPWCHAR lpKeybLayout; // Ptr to default keyboard layout name
#define TEMPBUFLEN countof (wszTemp)
//***************************************************************
// Read in the [LibDirs] section
//***************************************************************
// Get the # LibDirs
uNumLibDirs =
GetPrivateProfileIntW (SECTNAME_LIBDIRS, // Ptr to the section name
KEYNAME_COUNT, // Ptr to the key name
0, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Allocate space for the LibDirs
hGlbLibDirs =
DbgGlobalAlloc (GHND, max (uNumLibDirs, 2) * _MAX_PATH * sizeof (WCHAR));
if (hGlbLibDirs EQ NULL)
{
MessageBoxW (hWndMF, L"Unable to allocate enough memory for Library Directories", WS_APPNAME, MB_OK | MB_ICONSTOP);
return FALSE;
} // End IF
// Lock the memory to get a ptr to it
lpwszLibDirs = MyGlobalLock000 (hGlbLibDirs);
// Check for no LibDirs
if (uNumLibDirs EQ 0)
{
// Use the default count
uNumLibDirs = 2;
// Append the two default dirs
strcpyW (lpwszLibDirs[0], L".");
strcpyW (lpwszLibDirs[1], lpwszWorkDir);
} else
// Loop through the LibDirs
for (uCnt = 0; uCnt < uNumLibDirs; uCnt++)
{
// Format the keyname
MySprintfW (wszKey,
sizeof (wszKey),
L"%u",
uCnt);
// Read in the next LibDir
GetPrivateProfileStringW (SECTNAME_LIBDIRS, // Ptr to the section name
wszKey, // Ptr to the key name
L"", // Ptr to the default value
lpwszLibDirs[uCnt], // Ptr to the output buffer
_MAX_PATH, // Count of the output buffer
lpwszIniFile); // Ptr to the file name
} // End IF/ELSE/FOR
// We no longer need this ptr
MyGlobalUnlock (hGlbLibDirs); lpwszLibDirs = NULL;
//***************************************************************
// Read in the [Fonts] section
//***************************************************************
// Read in the LOGFONTW strucs
GetPrivateProfileLogFontW (SECTNAME_FONTS, KEYNAME_LOGFONTFE, &lfFE);
GetPrivateProfileLogFontW (SECTNAME_FONTS, KEYNAME_LOGFONTPR, &lfPR);
GetPrivateProfileLogFontW (SECTNAME_FONTS, KEYNAME_LOGFONTSM, &lfSM);
GetPrivateProfileLogFontW (SECTNAME_FONTS, KEYNAME_LOGFONTTC, &lfTC);
//***************************************************************
// Read in the [SameFontAs] section
//***************************************************************
// Loop through the items of glbSameFontAs
for (uCnt = 0; uCnt < FONTENUM_LENGTH; uCnt++)
{
// Format the keyname
MySprintfW (wszTemp,
sizeof (wszTemp),
L"%u",
uCnt);
// Read in the glbSameFontAs value
glbSameFontAs[uCnt] =
GetPrivateProfileIntW (SECTNAME_SAMEFONTAS, // Ptr to the section name
wszTemp, // Ptr to the key name
uCnt, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Overcome a bug in which the saved glbSameFontAs value may be
// larger than the corresponding index
glbSameFontAs[uCnt] = min (glbSameFontAs[uCnt], (int) uCnt);
} // End FOR
//***************************************************************
// Read in the [Options] section
//***************************************************************
// Read in bAdjustPW
OptionFlags.bAdjustPW =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_ADJUSTPW, // Ptr to the key name
DEF_ADJUSTPW, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bUnderbarToLowercase
OptionFlags.bUnderbarToLowercase =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_UNDERBARTOLOWERCASE,// Ptr to the key name
DEF_UNDERBARTOLOWERCASE,// Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bNewTabOnClear
OptionFlags.bNewTabOnClear =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_NEWTABONCLEAR, // Ptr to the key name
DEF_NEWTABONCLEAR, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bNewTabOnLoad
OptionFlags.bNewTabOnLoad =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_NEWTABONLOAD, // Ptr to the key name
DEF_NEWTABONLOAD, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bUseLocalTime
OptionFlags.bUseLocalTime =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_USELOCALTIME, // Ptr to the key name
DEF_USELOCALTIME, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bBackupOnLoad
OptionFlags.bBackupOnLoad =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_BACKUPONLOAD, // Ptr to the key name
DEF_BACKUPONLOAD, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bBackupOnSave
OptionFlags.bBackupOnSave =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_BACKUPONSAVE, // Ptr to the key name
DEF_BACKUPONSAVE, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bNoCopyrightMsg
OptionFlags.bNoCopyrightMsg =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_NOCOPYRIGHTMSG,// Ptr to the key name
DEF_NOCOPYRIGHTMSG, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in uDefaultPaste
OptionFlags.uDefaultPaste =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_DEFAULTPASTE, // Ptr to the key name
DEF_DEFAULTPASTE, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in uDefaultCopy
OptionFlags.uDefaultCopy =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_DEFAULTCOPY, // Ptr to the key name
DEF_DEFAULTCOPY, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bSyntClrFcns
OptionFlags.bSyntClrFcns =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_SYNTCLRFCNS, // Ptr to the key name
DEF_SYNTCLRFCNS, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bSyntClrSess
OptionFlags.bSyntClrSess =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_SYNTCLRSESS, // Ptr to the key name
DEF_SYNTCLRSESS, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bSyntClrPrnt
OptionFlags.bSyntClrPrnt =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_SYNTCLRPRNT, // Ptr to the key name
DEF_SYNTCLRPRNT, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bCheckGroup
OptionFlags.bCheckGroup =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_CHECKGROUP, // Ptr to the key name
DEF_CHECKGROUP, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bInsState
OptionFlags.bInsState =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_INSSTATE, // Ptr to the key name
DEF_INSSTATE, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bRevDblClk
OptionFlags.bRevDblClk =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_REVDBLCLK, // Ptr to the key name
DEF_REVDBLCLK, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bViewStatusBar
OptionFlags.bViewStatusBar =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_VIEWSTATUSBAR, // Ptr to the key name
DEF_VIEWSTATUSBAR, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bDefDispFcnLineNums
OptionFlags.bDefDispFcnLineNums =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_DEFDISPFCNLINENUMS, // Ptr to the key name
DEF_DISPFCNLINENUMS, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bDispMPSuf
OptionFlags.bDispMPSuf =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_DISPMPSUF, // Ptr to the key name
DEF_DISPMPSUF, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bOutputDebug
OptionFlags.bOutputDebug =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_OUTPUTDEBUG, // Ptr to the key name
DEF_OUTPUTDEBUG, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in the Line Continuation char as an integer
uUserChar =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_CHAR, // Ptr to the key name
WC_LC, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in the Unicode base for typed chars (10 or 16)
uUserUnibase =
GetPrivateProfileIntW (SECTNAME_OPTIONS, // Ptr to the section name
KEYNAME_UNIBASE, // Ptr to the key name
16, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Ensure the Unicode base is either 10 or 16
if (uUserUnibase NE 10
&& uUserUnibase NE 16)
uUserUnibase = 16;
//***************************************************************
// Read in the [SysVars] section -- default values for system
// variables in a CLEAR WS
//***************************************************************
// Read in []ALX
hGlbQuadALX_CWS =
GetPrivateProfileGlbCharW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADALX, // Ptr to the key name
DEF_QUADALX_CWS, // Ptr to default value
DEF_QUADALX_GLB, // HGLOBAL of the default value
lpwszIniFile); // Ptr to the file name
// Read in []CT
fQuadCT_CWS =
GetPrivateProfileFloatW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADCT, // Ptr to the key name
DEF_QUADCT_CWS, // Ptr to the default value
lpwszIniFile); // Ptr to the file name
// Read in []DT
GetPrivateProfileStringW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADDT, // Ptr to the key name
DEF_QUADDT_CWS, // Ptr to the default value
wszTemp, // Ptr to the output buffer
TEMPBUFLEN, // Count of the output buffer
lpwszIniFile); // Ptr to the file name
// Convert any {name}s to symbols
ConvertNameInPlace (wszTemp);
cQuadDT_CWS = wszTemp[0];
// Read in []ELX
hGlbQuadELX_CWS =
GetPrivateProfileGlbCharW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADELX, // Ptr to the key name
DEF_QUADELX_CWS, // Ptr to default value
DEF_QUADELX_GLB, // HGLOBAL of the default value
lpwszIniFile); // Ptr to the file name
// Read in []FC
hGlbQuadFC_CWS =
GetPrivateProfileGlbCharW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADFC, // Ptr to the key name
DEF_QUADFC_CWS, // Ptr to default value
DEF_QUADFC_GLB, // HGLOBAL of the default value
lpwszIniFile); // Ptr to the file name
// Loop through the items of aplDefaultFEATURE
for (uCnt = 0, lpwszTemp = wszTemp; uCnt < FEATURENDX_LENGTH; uCnt++)
// Make the default wide-string form of aplDefaultFEATURE
lpwszTemp +=
wsprintfW (lpwszTemp,
L"%d ",
aplDefaultFEATURE[uCnt]);
// Read in []FEATURE
hGlbQuadFEATURE_CWS =
GetPrivateProfileGlbIntW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADFEATURE, // Ptr to the key name
wszTemp, // Ptr to default value
DEF_QUADFEATURE_GLB, // HGLOBAL of the default value
FEATURENDX_LENGTH, // Length of the default integer vector
lpwszIniFile); // Ptr to the file name
// Read in []FPC
uQuadFPC_CWS =
GetPrivateProfileIntW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADFPC, // Ptr to the key name
DEF_QUADFPC_CWS, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Loop through the items of aplDefaultIC
for (uCnt = 0, lpwszTemp = wszTemp; uCnt < ICNDX_LENGTH; uCnt++)
// Make the default wide-string form of aplDefaultIC
lpwszTemp +=
wsprintfW (lpwszTemp,
L"%d ",
aplDefaultIC[uCnt]);
// Read in []IC
hGlbQuadIC_CWS =
GetPrivateProfileGlbIntW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADIC, // Ptr to the key name
wszTemp, // Ptr to default value
DEF_QUADIC_GLB, // HGLOBAL of the default value
ICNDX_LENGTH, // Length of the default integer vector
lpwszIniFile); // Ptr to the file name
// Read in uMigration.IC0LOG0
uMigration.IC0LOG0 =
GetPrivateProfileIntW (SECTNAME_MIGRATION, // Ptr to the section name
KEYNAME_IC0LOG0, // Ptr to the key name
0, // Default value if not found
lpwszIniFile); // Ptr to the file name
// If it's unfixed, ...
if (uMigration.IC0LOG0 EQ 0)
{
LPAPLINT lpMemQuadIC;
// Lock the memory to get a ptr to it
lpMemQuadIC = MyGlobalLockVar (hGlbQuadIC_CWS);
// Skip over the header and dimensions to the data
lpMemQuadIC = VarArrayDataFmBase (lpMemQuadIC);
// Set the new value
lpMemQuadIC[ICNDX_0LOG0] = aplDefaultIC[ICNDX_0LOG0];
// We no longer need this ptr
MyGlobalUnlock (hGlbQuadIC_CWS); lpMemQuadIC = NULL;
// Increment the migration level for IC0LOG0
uMigration.IC0LOG0++;
} // End IF
// Read in []IO
bQuadIO_CWS = (APLBOOL)
GetPrivateProfileIntW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADIO, // Ptr to the key name
DEF_QUADIO_CWS, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in []LX
hGlbQuadLX_CWS =
GetPrivateProfileGlbCharW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADLX, // Ptr to the key name
DEF_QUADLX_CWS, // Ptr to default value
DEF_QUADLX_GLB, // HGLOBAL of the default value
lpwszIniFile); // Ptr to the file name
// Read in []MF
uQuadMF_CWS =
GetPrivateProfileIntW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADMF, // Ptr to the key name
DEF_QUADMF_CWS, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in []PP
uQuadPP_CWS =
GetPrivateProfileIntW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADPP, // Ptr to the key name
DEF_QUADPP_CWS, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in []PW
uQuadPW_CWS =
GetPrivateProfileIntW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADPW, // Ptr to the key name
DEF_QUADPW_CWS, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in []PR
GetPrivateProfileStringW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADPR, // Ptr to the key name
DEF_QUADPR_CWS, // Ptr to the default value
wszTemp, // Ptr to the output buffer
TEMPBUFLEN, // Count of the output buffer
lpwszIniFile); // Ptr to the file name
// Convert any {name}s to symbols
ConvertNameInPlace (wszTemp);
// If the value is empty (''), ...
if (wszTemp[0] EQ WC_EOS)
{
cQuadPR_CWS = CQUADPR_MT;
hGlbQuadPR_CWS = hGlbV0Char;
} else
cQuadPR_CWS = wszTemp[0];
// Read in []RL as a string as the IntW form doesn't support 64-bit integers
GetPrivateProfileStringW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADRL, // Ptr to the key name
DEF_QUADRL_CWS_WS, // Ptr to the default value
wszTemp, // Ptr to the output buffer
TEMPBUFLEN, // Count of the output buffer
lpwszIniFile); // Ptr to the file name
// Convert to a number
sscanfW (wszTemp, L"%I64u", &uQuadRL_CWS);
// A past bug in Customize set []RL to zero if it exceeded INT_MAX, so we check for that here
if (uQuadRL_CWS EQ 0)
// Set to the default value
uQuadRL_CWS = DEF_QUADRL_CWS;
// Read in []SA index
cQuadxSA_CWS = (APLCHAR)
GetPrivateProfileIntW (SECTNAME_SYSVARS, // Ptr to the section name
KEYNAME_QUADSA, // Ptr to the key name
DEF_QUADxSA_CWS, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Set the correct value for []SA
switch (cQuadxSA_CWS)
{
case 0: // ""
hGlbQuadSA_CWS = hGlbV0Char;
break;
case 1: // "CLEAR"
hGlbQuadSA_CWS = hGlbSAClear;
break;
case 2: // "ERROR"
hGlbQuadSA_CWS = hGlbSAError;
break;
case 3: // "EXIT"
hGlbQuadSA_CWS = hGlbSAExit;
break;
case 4: // "OFF"
hGlbQuadSA_CWS = hGlbSAOff;
break;
defstop
break;
} // End SWITCH
//***************************************************************
// Read in the [RangeLimits] section
//***************************************************************
// Read in bRangeLimit.CT
bRangeLimit.CT =
GetPrivateProfileIntW (SECTNAME_RANGELIMITS, // Ptr to the section name
KEYNAME_QUADCT, // Ptr to the key name
DEF_RANGELIMIT_CT, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bRangeLimit.FEATURE
bRangeLimit.FEATURE =
GetPrivateProfileIntW (SECTNAME_RANGELIMITS, // Ptr to the section name
KEYNAME_QUADFEATURE, // Ptr to the key name
DEF_RANGELIMIT_FEATURE,// Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bRangeLimit.FPC
bRangeLimit.FPC =
GetPrivateProfileIntW (SECTNAME_RANGELIMITS, // Ptr to the section name
KEYNAME_QUADFPC, // Ptr to the key name
DEF_RANGELIMIT_FPC, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bRangeLimit.IC
bRangeLimit.IC =
GetPrivateProfileIntW (SECTNAME_RANGELIMITS, // Ptr to the section name
KEYNAME_QUADIC, // Ptr to the key name
DEF_RANGELIMIT_IC, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bRangeLimit.IO
bRangeLimit.IO =
GetPrivateProfileIntW (SECTNAME_RANGELIMITS, // Ptr to the section name
KEYNAME_QUADIO, // Ptr to the key name
DEF_RANGELIMIT_IO, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bRangeLimit.PP
bRangeLimit.PP =
GetPrivateProfileIntW (SECTNAME_RANGELIMITS, // Ptr to the section name
KEYNAME_QUADPP, // Ptr to the key name
DEF_RANGELIMIT_PP, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bRangeLimit.PW
bRangeLimit.PW =
GetPrivateProfileIntW (SECTNAME_RANGELIMITS, // Ptr to the section name
KEYNAME_QUADPW, // Ptr to the key name
DEF_RANGELIMIT_PW, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bRangeLimit.RL
bRangeLimit.RL =
GetPrivateProfileIntW (SECTNAME_RANGELIMITS, // Ptr to the section name
KEYNAME_QUADRL, // Ptr to the key name
DEF_RANGELIMIT_RL, // Default value if not found
lpwszIniFile); // Ptr to the file name
//***************************************************************
// Read in the [ResetVars] section
//***************************************************************
// Read in bResetVars.CT
bResetVars.CT =
GetPrivateProfileIntW (SECTNAME_RESETVARS, // Ptr to the section name
KEYNAME_QUADCT, // Ptr to the key name
DEF_RESETVARS_CT, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bResetVars.DT
bResetVars.DT =
GetPrivateProfileIntW (SECTNAME_RESETVARS, // Ptr to the section name
KEYNAME_QUADDT, // Ptr to the key name
DEF_RESETVARS_DT, // Default value if not found
lpwszIniFile); // Ptr to the file name
// Read in bResetVars.FC