File: JcfRegistrySettings.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (648 lines) | stat: -rw-r--r-- 18,698 bytes parent folder | download | duplicates (2)
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
unit JcfRegistrySettings;

{ AFS 2 Jan 2002
  Store Gui state in registry

  This is not the format options file, that lives in a file so that it can be shared
  This registry file is intended to
   - tell you where the format options file is
   - other GUI config settings that should not be shared, ie
   - logging
}

{(*}
(*------------------------------------------------------------------------------
 Delphi Code formatter source code 

The Original Code is JcfRegistrySettings, released May 2003.
The Initial Developer of the Original Code is Anthony Steele. 
Portions created by Anthony Steele are Copyright (C) 1999-2008 Anthony Steele.
All Rights Reserved. 
Contributor(s): Anthony Steele. 

The contents of this file are subject to the Mozilla Public License Version 1.1
(the "License"). you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.mozilla.org/NPL/

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied.
See the License for the specific language governing rights and limitations
under the License.

Alternatively, the contents of this file may be used under the terms of
the GNU General Public License Version 2 or later (the "GPL") 
See http://www.gnu.org/licenses/gpl.html
------------------------------------------------------------------------------*)
{*)}

{$I JcfGlobal.inc}

interface

uses
  { delphi }
  Registry, Classes,
  { local }
  ConvertTypes;

type
  TLogLevel = (eLogErrorsOnly, eLogFiles, eLogTokens);
  TLogPlace = (eLogTempDir, eLogAppDIr, eLogSpecifiedDir);
  TFormatFileWriteOption = (eAlwaysWrite, eQuietFail, eNeverWrite);


  TJCFRegistrySettings = class(TObject)
  private
    fcReg:     TRegIniFile;
    fbHasRead: boolean;

    { general settings }
    fShowParseTreeOption: TShowParseTreeOption;

    { ui settings }
    fsFormatConfigFileName: string;
    fbFormatConfigNameSpecified: boolean;

    fsLastSettingsPage: string;
    feFormatFileWriteOption: TFormatFileWriteOption;

    {notepad settings }
    fsInputDir:  string;
    fsOutputDir: string;

    { MRU files settings }
    fiMRUMaxItems: integer;

    { log settings }
    feLogLevel: TLogLevel;
    feLogPlace: TLogPlace;
    fsSpecifiedDirectory: string;
    fbViewLogAfterRun: boolean;
    fbLogTime:  boolean;
    fbLogStats: boolean;

    { file settings }
    feBackupMode:      TBackupMode;
    feSourceMode:      TSourceMode;
    fsBackupExtension, fsOutputExtension: string;
    fsInput:           string;
    fcExclusionsFiles: TStringList;
    fcExclusionsDirs:  TStringList;
    fbCheckMultiByteChars: boolean;

    { this is ref not owned }
    fcMRUFiles: TStrings;

    fbEditorIntegration: boolean;
    fbFormatBeforeSave:  boolean;
    fbFormatAfterLoad:   boolean;

    procedure ReadMRUFiles;
    procedure WriteMRUFiles;

    procedure ReadStrings(const psSection, psKey: string; pcStrings: TStrings);
    procedure WriteStrings(const psSection, psKey: string; pcStrings: TStrings);
    function GetBackupExtension: string;
    function GetOutputExtension: string;

  public
    constructor Create;
    destructor Destroy; override;

    function CanClearMRU: boolean;
    procedure ClearMRU;

    procedure ReadAll;
    procedure WriteAll;

    property HasRead: boolean Read fbHasRead;

    { general settings }
    property FormatConfigFileName: string Read fsFormatConfigFileName
      Write fsFormatConfigFileName;
    property FormatConfigNameSpecified: boolean Read fbFormatConfigNameSpecified;

    property FormatFileWriteOption: TFormatFileWriteOption
      Read feFormatFileWriteOption Write feFormatFileWriteOption;

    { ui settings }
    property ShowParseTreeOption: TShowParseTreeOption
      Read fShowParseTreeOption Write fShowParseTreeOption;
    property LastSettingsPage: string Read fsLastSettingsPage Write fsLastSettingsPage;

    { notepad settings }
    property InputDir: string Read fsInputDir Write fsInputDir;
    property OutputDir: string Read fsOutputDir Write fsOutputDir;

    { MRU files settings }
    property MRUMaxItems: integer Read fiMRUMaxItems Write fiMRUMaxItems;
    property MRUFiles: TStrings Read fcMRUFiles Write fcMRUFiles;

    { log settings }
    function LogDirectory: string;
    function LogFileName: string;

    property LogLevel: TLogLevel Read feLogLevel Write feLogLevel;
    property LogPlace: TLogPlace Read feLogPlace Write feLogPlace;
    property SpecifiedDirectory: string Read fsSpecifiedDirectory
      Write fsSpecifiedDirectory;

    property ViewLogAfterRun: boolean Read fbViewLogAfterRun Write fbViewLogAfterRun;
    property LogTime: boolean Read fbLogTime Write fbLogTime;
    property LogStats: boolean Read fbLogStats Write fbLogStats;

    procedure ViewLog;

    { files settings }
    property BackupMode: TBackupMode Read feBackupMode Write feBackupMode;
    property SourceMode: TSourceMode Read feSourceMode Write feSourceMode;
    property BackupExtension: string Read GetBackupExtension Write fsBackupExtension;
    property OutputExtension: string Read GetOutputExtension Write fsOutputExtension;
    property CheckMultiByteChars: boolean Read fbCheckMultiByteChars
      Write fbCheckMultiByteChars;

    function GetOutputFileName(const psIn: string): string; overload;
    function GetOutputFileName(const psIn: string; peMode: TBackupMode): string;
      overload;

    function Output: string;

    function FileIsExcluded(const psFile: string): boolean;
    function DirIsExcluded(const psDir: string): boolean;

    property Input: string Read fsInput Write fsInput;

    property ExclusionsFiles: TStringList Read fcExclusionsFiles;
    property ExclusionsDirs: TStringList Read fcExclusionsDirs;

    { IDE integration settings }
    property EditorIntegration: boolean Read fbEditorIntegration
      Write fbEditorIntegration;
    property FormatBeforeSave: boolean Read fbFormatBeforeSave Write fbFormatBeforeSave;
    property FormatAfterLoad: boolean Read fbFormatAfterLoad Write fbFormatAfterLoad;
  end;

function GetRegSettings: TJCFRegistrySettings;

var
  GetDefaultSettingsFileName: function: String;

implementation

uses
  { delphi }
  {$ifndef fpc}Windows,{$endif} SysUtils, Dialogs,
  { jcf }
  JcfStringUtils, JcfSystemUtils, JcfMiscFunctions;

const
  REG_GENERAL_SECTION = 'General';
  REG_NOTEPAD_SECTION = 'NotepadSettings';
  REG_MRU_FILES_SECTION = 'MRUFiles';
  REG_LOG_SECTION = 'Log';
  REG_UI_SECTION  = 'UI';
  REG_FILES_SECTION = 'Files';
  REG_IDE_SECTION = 'IDE';

  REG_LOG_LEVEL = 'LogLevel';
  REG_LOG_PLACE = 'LogPlace';
  REG_SPECIFIED_DIRECTORY = 'SpecifiedDirectory';
  REG_VIEW_LOG_AFTER_RUN = 'ViewLogAfterRun';
  REG_LOG_TIME  = 'LogTime';
  REG_LOG_STATS = 'LogStats';

  REG_LAST_SETTINGS_PAGE = 'LastSettingsPage';

  REG_INPUT = 'Input';

  REG_BACKUP_MODE = 'BackupMode';
  REG_SOURCE_MODE = 'SourceMode';
  REG_BACKUP_EXT  = 'BackupExt';
  REG_OUTPUT_EXT  = 'OutputExt';

  REG_EXCLUSIONS_FILES = 'ExclusionsFiles';
  REG_EXCLUSIONS_DIRS  = 'ExclusionsDirs';

  REG_CHECK_MULTIBYTE_CHARS = 'CheckMultiByteChars';

  REG_EDITOR_INTEGRATION = 'EditorIntegration';
  REG_FORMAT_BEFORE_SAVE = 'FormatBeforeSave';
  REG_FORMAT_AFTER_LOAD  = 'FormatAfterLoad';

{
  file-based settings,  ie
  - read from the settings file if it exists, else use the registry
  - always write to the file
 }
function DefGetDefaultSettingsFileName: string;
begin
  Result := IncludeTrailingPathDelimiter(GetApplicationFolder) + 'JCFSettings.cfg';
end;

constructor TJCFRegistrySettings.Create;
var
  Registry: TRegistry;
begin
  inherited;

  // Move old registry content to new registry location if applicable
  Registry := TRegistry.Create;
  try
    Registry.Access  := KEY_ALL_ACCESS;
    Registry.RootKey := HKEY_CURRENT_USER;
    if not (Registry.OpenKey(REG_ROOT_KEY, False)) then
    begin
      if (Registry.OpenKey(OLD_REG_ROOT_KEY, False)) then
      begin
        Registry.MoveKey(OLD_REG_ROOT_KEY, REG_ROOT_KEY, True);
        Registry.CloseKey;
        if (Registry.OpenKey('\Software\Jedi', False)) then
        begin
          if not Registry.HasSubKeys then
          begin
            Registry.CloseKey;
            if (Registry.OpenKey('\Software', False)) then
            begin
              Registry.DeleteKey('Jedi');
              Registry.CloseKey;
            end;
          end
          else
            Registry.CloseKey;
        end;
      end;
    end
    else
      Registry.CloseKey;
  finally
    Registry.Free;
  end;

  // New registry location
  fcReg := TRegIniFile.Create(REG_ROOT_KEY);

  fcExclusionsFiles := TStringList.Create;
  fcExclusionsDirs  := TStringList.Create;
end;

destructor TJCFRegistrySettings.Destroy;
begin
  FreeAndNil(fcExclusionsFiles);
  FreeAndNil(fcExclusionsDirs);

  FreeAndNil(fcReg);
  inherited;
end;

procedure TJCFRegistrySettings.ReadStrings(const psSection, psKey: string;
  pcStrings: TStrings);
var
  lsKey, lsValue: string;
  liCount: integer;
begin
  Assert(pcStrings <> nil);
  pcStrings.Clear;

  liCount := 0;

  while True do
  begin
    lsKey := psKey + IntToStr(liCount);
    lsValue := fcReg.ReadString(psSection, lsKey, '');
    if lsValue = '' then
      break // done
    else
      pcStrings.Add(lsValue);

    Inc(liCount);
  end;
end;


procedure TJCFRegistrySettings.WriteStrings(const psSection, psKey: string;
  pcStrings: TStrings);
var
  lsKey:  string;
  liLoop: integer;
begin
  Assert(pcStrings <> nil);

  for liLoop := 0 to pcStrings.Count - 1 do
  begin
    lsKey := psKey + IntToStr(liLoop);
    fcReg.WriteString(psSection, lsKey, pcStrings.Strings[liLoop]);
  end;

  // null-terminate the list
  lsKey := psKey + IntToStr(pcStrings.Count);
  fcReg.WriteString(psSection, lsKey, '');
end;


procedure TJCFRegistrySettings.ReadMRUFiles;
var
  lcItems: TStringList;
  liLoop:  integer;
begin
  if fcMRUFiles = nil then
    exit;

  fcMRUFiles.Clear;

  lcItems := TStringList.Create;
  try
    ReadStrings(REG_MRU_FILES_SECTION, 'MRUFile', lcItems);

    { add them in reverse order to work around a bug in TJvMRUManager
      where the order reverses every time it is read/written
    }
    for liLoop := lcItems.Count - 1 downto 0 do
    begin
      fcMRUFiles.Add(lcItems.Strings[liLoop]);
    end;

  finally
    lcItems.Free;
  end;
end;


procedure TJCFRegistrySettings.WriteMRUFiles;
begin
  if fcMRUFiles = nil then
    exit;

  WriteStrings(REG_MRU_FILES_SECTION, 'MRUFile', fcMRUFiles);
end;

procedure TJCFRegistrySettings.ReadAll;
begin
  { general section }
  fsFormatConfigFileName := fcReg.ReadString(REG_GENERAL_SECTION,
    'FormatConfigFileName', '');
  // was a config file specified
  fbFormatConfigNameSpecified := (fsFormatConfigFileName <> '');

  if not fbFormatConfigNameSpecified then
  begin
    fsFormatConfigFileName := GetDefaultSettingsFileName;
  end;

  feFormatFileWriteOption := TFormatFileWriteOption(
    fcReg.ReadInteger(REG_GENERAL_SECTION, 'FormatFileWriteOption', Ord(eAlwaysWrite)));

  {notepad settings }
  InputDir  := fcReg.ReadString(REG_NOTEPAD_SECTION, 'InputDir', '');
  OutputDir := fcReg.ReadString(REG_NOTEPAD_SECTION, 'OutputDir', '');

  { MRU section }
  MRUMaxItems := fcReg.ReadInteger(REG_NOTEPAD_SECTION, 'MRUMaxItems', 6);
  ReadMRUFiles;

  { log section }
  feLogLevel := TLogLevel(fcReg.ReadInteger(REG_LOG_SECTION, REG_LOG_LEVEL,
    Ord(eLogFiles)));
  feLogPlace := TLogPlace(fcReg.ReadInteger(REG_LOG_SECTION, REG_LOG_PLACE,
    Ord(eLogTempDir)));
  fsSpecifiedDirectory := fcReg.ReadString(REG_LOG_SECTION,
    REG_SPECIFIED_DIRECTORY, 'c:\');
  fbViewLogAfterRun := fcReg.ReadBool(REG_LOG_SECTION, REG_VIEW_LOG_AFTER_RUN, False);
  fbLogTime  := fcReg.ReadBool(REG_LOG_SECTION, REG_LOG_TIME, False);
  fbLogStats := fcReg.ReadBool(REG_LOG_SECTION, REG_LOG_STATS, False);

  { ui }
  fsLastSettingsPage  := fcReg.ReadString(REG_UI_SECTION, REG_LAST_SETTINGS_PAGE, '');
  ShowParseTreeOption := TShowParseTreeOption(
    fcReg.ReadInteger(REG_UI_SECTION, 'ParseTreeOption', Ord(eShowOnError)));

  { files}
  feBackupMode := TBackupMode(fcReg.ReadInteger(REG_FILES_SECTION,
    REG_BACKUP_MODE, Ord(cmSeparateOutput)));
  feSourceMode := TSourceMode(fcReg.ReadInteger(REG_FILES_SECTION,
    REG_SOURCE_MODE, Ord(fmSingleFile)));
  fsInput := fcReg.ReadString(REG_FILES_SECTION, REG_INPUT, '');

  fsBackupExtension := fcReg.ReadString(REG_FILES_SECTION, REG_BACKUP_EXT, 'bak');
  fsOutputExtension := fcReg.ReadString(REG_FILES_SECTION, REG_OUTPUT_EXT, 'out');

  ReadStrings(REG_FILES_SECTION, REG_EXCLUSIONS_FILES, fcExclusionsFiles);
  ReadStrings(REG_FILES_SECTION, REG_EXCLUSIONS_DIRS, fcExclusionsDirs);

  fbCheckMultiByteChars := fcReg.ReadBool(REG_FILES_SECTION,
    REG_CHECK_MULTIBYTE_CHARS, False);

  { IDE }
  fbEditorIntegration := fcReg.ReadBool(REG_IDE_SECTION, REG_EDITOR_INTEGRATION, False);
  fbFormatBeforeSave := fcReg.ReadBool(REG_IDE_SECTION, REG_FORMAT_BEFORE_SAVE, False);
  fbFormatAfterLoad := fcReg.ReadBool(REG_IDE_SECTION, REG_FORMAT_AFTER_LOAD, False);

  fbHasRead := True;
end;


procedure TJCFRegistrySettings.WriteAll;
begin
  { general section }
  fcReg.WriteString(REG_GENERAL_SECTION, 'FormatConfigFileName', fsFormatConfigFileName);
  fcReg.WriteInteger(REG_GENERAL_SECTION, 'FormatFileWriteOption',
    Ord(feFormatFileWriteOption));

  { notepad section }
  fcReg.WriteString(REG_NOTEPAD_SECTION, 'InputDir', InputDir);
  fcReg.WriteString(REG_NOTEPAD_SECTION, 'OutputDir', OutputDir);

  { mru section}
  fcReg.WriteInteger(REG_MRU_FILES_SECTION, 'MRUMaxItems', MRUMaxItems);
  WriteMRUFiles;

  { log section }
  fcReg.WriteInteger(REG_LOG_SECTION, REG_LOG_LEVEL, Ord(feLogLevel));
  fcReg.WriteInteger(REG_LOG_SECTION, REG_LOG_PLACE, Ord(feLogPlace));
  fcReg.WriteString(REG_LOG_SECTION, REG_SPECIFIED_DIRECTORY, fsSpecifiedDirectory);
  fcReg.WriteBool(REG_LOG_SECTION, REG_VIEW_LOG_AFTER_RUN, fbViewLogAfterRun);
  fcReg.WriteBool(REG_LOG_SECTION, REG_LOG_TIME, fbLogTime);
  fcReg.WriteBool(REG_LOG_SECTION, REG_LOG_STATS, fbLogStats);

  { ui section }
  fcReg.WriteString(REG_UI_SECTION, REG_LAST_SETTINGS_PAGE, fsLastSettingsPage);
  fcReg.WriteInteger(REG_UI_SECTION, 'ParseTreeOption', Ord(ShowParseTreeOption));

  { files section }
  fcReg.WriteInteger(REG_FILES_SECTION, REG_BACKUP_MODE, Ord(feBackupMode));
  fcReg.WriteInteger(REG_FILES_SECTION, REG_SOURCE_MODE, Ord(feSourceMode));

  fcReg.WriteString(REG_FILES_SECTION, REG_INPUT, fsInput);
  fcReg.WriteString(REG_FILES_SECTION, REG_BACKUP_EXT, fsBackupExtension);
  fcReg.WriteString(REG_FILES_SECTION, REG_OUTPUT_EXT, fsOutputExtension);

  WriteStrings(REG_FILES_SECTION, REG_EXCLUSIONS_FILES, fcExclusionsFiles);
  WriteStrings(REG_FILES_SECTION, REG_EXCLUSIONS_DIRS, fcExclusionsDirs);

  fcReg.WriteBool(REG_FILES_SECTION, REG_CHECK_MULTIBYTE_CHARS, fbCheckMultiByteChars);

  { IDE }
  fcReg.WriteBool(REG_IDE_SECTION, REG_EDITOR_INTEGRATION, fbEditorIntegration);
  fcReg.WriteBool(REG_IDE_SECTION, REG_FORMAT_BEFORE_SAVE, fbFormatBeforeSave);
  fcReg.WriteBool(REG_IDE_SECTION, REG_FORMAT_AFTER_LOAD, fbFormatAfterLoad);
end;

function TJCFRegistrySettings.CanClearMRU: boolean;
begin
  Result := (MRUFiles <> nil) and (MRUFiles.Count > 0);
end;

procedure TJCFRegistrySettings.ClearMRU;
begin
  if MRUFiles <> nil then
    MRUFiles.Clear;
end;


function TJCFRegistrySettings.LogDirectory: string;
begin
  case feLogPlace of
    eLogTempDir:
      Result := GetWindowsTempFolder;
    eLogAppDir:
      Result := ExtractFileDir(ParamStr(0));
    eLogSpecifiedDir:
      Result := fsSpecifiedDirectory;
  end;

  Result := IncludeTrailingPathDelimiter(Result);
end;

function TJCFRegistrySettings.LogFileName: string;
begin
  Result := LogDirectory + 'JediCodeFormat.log';
end;

procedure TJCFRegistrySettings.ViewLog;
var
  lsFile: string;
begin
  lsFile := LogFileName;

  if FileExists(lsFile) then
  begin
    ShellExecEx('notepad.exe ', lsFile);
  end
  else
    ShowMessage('No log file found at ' + lsFile);
end;

function TJCFRegistrySettings.DirIsExcluded(const psDir: string): boolean;
var
  liPos: integer;
  lsBareDir: string;
begin
  { exact match  }
  Result := (fcExclusionsDirs.IndexOf(psDir) >= 0);

  if not Result then
  begin
    liPos := StrLastPos('/', psDir);
    if liPos > 0 then
    begin
      lsBareDir := StrRestOf(psDir, liPos + 1);
      Result := (fcExclusionsDirs.IndexOf(lsBareDir) >= 0);
    end;
  end;
end;

function TJCFRegistrySettings.FileIsExcluded(const psFile: string): boolean;
var
  lsBareFile: string;
begin
  { exact match  }
  Result := (fcExclusionsFiles.IndexOf(psFile) >= 0);

  if not Result then
  begin
    // no exact match? then extract the bare file name - no path or ext
    lsBareFile := PathExtractFileNameNoExt(psFile);
    Result := (fcExclusionsFiles.IndexOf(lsBareFile) >= 0);
  end;
end;

function TJCFRegistrySettings.GetOutputFileName(const psIn: string;
  peMode: TBackupMode): string;
var
  lsExt: string;
  liMainFileNameLength: integer;
begin
  if PathExtractFileNameNoExt(psIn) = '' then
  begin
    Result := '';
    exit;
  end;

  if (peMode = cmInPlace) then
  begin
    Result := '';
  end
  else if peMode in [cmInPlaceWithBackup, cmSeparateOutput] then
  begin
    lsExt  := ExtractFileExt(psIn);
    liMainFileNameLength := Length(psIn) - Length(lsExt);
    Result := StrLeft(psIn, liMainFileNameLength);

    if peMode = cmInPlaceWithBackup then
      Result := Result + '.' + BackupExtension
    else
      Result := Result + '.' + OutputExtension;
  end
  else
    raise Exception.Create('TCodeFormatSettings.Output: bad backup mode ');
end;

function TJCFRegistrySettings.GetOutputFileName(const psIn: string): string;
begin
  // use the currently selected mode
  Result := GetOutputFileName(psIn, BackupMode);
end;

function TJCFRegistrySettings.Output: string;
begin
  Result := GetOutputFileName(Input);
end;

function TJCFRegistrySettings.GetBackupExtension: string;
begin
  if fsBackupExtension = '' then
    Result := 'bak'
  else
    Result := fsBackupExtension;
end;

function TJCFRegistrySettings.GetOutputExtension: string;
begin
  if fsOutputExtension = '' then
    Result := 'out'
  else
    Result := fsOutputExtension;
end;

{--------------------------------------------
  singleton accessor }

var
  mcRegistrySettings: TJCFRegistrySettings = nil;

function GetRegSettings: TJCFRegistrySettings;
begin
  if mcRegistrySettings = nil then
  begin
    mcRegistrySettings := TJCFRegistrySettings.Create;
    mcRegistrySettings.ReadAll;
  end;

  Result := mcRegistrySettings;
end;

initialization
  GetDefaultSettingsFileName := DefGetDefaultSettingsFileName;

finalization
  FreeAndNil(mcRegistrySettings);
end.