Subversion Repositories oidplus

Rev

Rev 747 | Rev 749 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 747 Rev 748
Line 1... Line 1...
1
program OIDPLUS;
1
program OIDPLUS;
2
 
2
 
3
(************************************************)
3
(************************************************)
4
(* OIDPLUS.PAS                                  *)
4
(* OIDPLUS.PAS                                  *)
5
(* Author:   Daniel Marschall                   *)
5
(* Author:   Daniel Marschall                   *)
6
(* Revision: 2022-02-16                         *)
6
(* Revision: 2022-02-19                         *)
7
(* License:  Apache 2.0                         *)
7
(* License:  Apache 2.0                         *)
8
(* This file contains:                          *)
8
(* This file contains:                          *)
9
(* - "OIDplus for DOS" program                  *)
9
(* - "OIDplus for DOS" program                  *)
10
(************************************************)
10
(************************************************)
11
 
11
 
Line 16... Line 16...
16
(* The program "PatchCRT" by Kennedy Software                  *)
16
(* The program "PatchCRT" by Kennedy Software                  *)
17
(* WON'T work because it somehow breaks our "_Pause" function. *)
17
(* WON'T work because it somehow breaks our "_Pause" function. *)
18
(* Instead, use the tool "TPPATCH" by Andreas Bauer.           *)
18
(* Instead, use the tool "TPPATCH" by Andreas Bauer.           *)
19
 
19
 
20
uses
20
uses
21
  Dos, Crt, Drivers, StrList, VtsFuncs, VtsCui, OidFile, OidUtils;
21
  Dos, Crt, Drivers, StrList, VtsFuncs, VtsCui, OidFile, OidUtils,
-
 
22
  Weid;
22
 
23
 
23
const
24
const
24
  VERSIONINFO            = 'Revision: 2022-02-16';
25
  VERSIONINFO            = 'Revision: 2022-02-19';
25
  DEFAULT_STATUSBAR      = '(C)2020-2022 ViaThinkSoft. Licensed under the terms of the Apache 2.0 license.';
26
  DEFAULT_STATUSBAR      = '(C)2020-2022 ViaThinkSoft. Licensed under the terms of the Apache 2.0 license.';
26
  TITLEBAR_LEFT_TEXT     = 'OIDplus';
27
  TITLEBAR_LEFT_TEXT     = 'OIDplus';
27
  DISKIO_SOUND_DEBUGGING = false;
28
  DISKIO_SOUND_DEBUGGING = false;
28
  DISKIO_SOUND_DELAY     = 500;
29
  DISKIO_SOUND_DELAY     = 500;
29
  ASNEDIT_LINES          = 10;
30
  ASNEDIT_LINES          = 10;
Line 251... Line 252...
251
          CursorOff;
252
          CursorOff;
252
    end;
253
    end;
253
  until false;
254
  until false;
254
end;
255
end;
255
 
256
 
-
 
257
function UnicodeLabelAlreadyExisting(oid: POID; unicodeLabel: string): boolean;
-
 
258
begin
-
 
259
  UnicodeLabelAlreadyExisting := ListContains(oid^.UnicodeLabels, unicodeLabel);
-
 
260
end;
-
 
261
 
-
 
262
function IriEditor(oid: POID): boolean;
-
 
263
var
-
 
264
  iriList: PStringList;
-
 
265
  i: integer;
-
 
266
  x, y, w, h: integer;
-
 
267
  res: integer;
-
 
268
  sInput: string;
-
 
269
  menuIdNew, menuIdSave, menuIdExit: integer;
-
 
270
begin
-
 
271
  IriEditor := false;
-
 
272
 
-
 
273
  repeat
-
 
274
    CreateList(iriList);
-
 
275
 
-
 
276
    for i := 0 to ListCount(oid^.UnicodeLabels)-1 do
-
 
277
    begin
-
 
278
      ListAppend(iriList, ListGetElement(oid^.UnicodeLabels, i));
-
 
279
    end;
-
 
280
    menuIdNew  := ListAppend(iriList, '<NEW>');
-
 
281
    menuIdSave := ListAppend(iriList, '<SAVE>');
-
 
282
    menuIdExit := ListAppend(iriList, '<CANCEL>');
-
 
283
 
-
 
284
    DrawStatusBar(DEFAULT_STATUSBAR);
-
 
285
    x := SINGLE_LINE_BOX_PADDING;
-
 
286
    y := ScreenHeight div 2 - ASNEDIT_LINES div 2;
-
 
287
    w := ScreenWidth - (SINGLE_LINE_BOX_PADDING-1)*2;
-
 
288
    h := ASNEDIT_LINES;
-
 
289
    res := DrawSelectionList(x, y, w, h,
-
 
290
                             iriList, true,
-
 
291
                             'EDIT UNICODE LABELS',
-
 
292
                             2);
-
 
293
    FreeList(iriList);
-
 
294
 
-
 
295
    (* Change double-border to thin-border *)
-
 
296
    DrawThinBorder(x-1, y-1, w+2, h+2);
-
 
297
    GoToXY(x+1, y-1);
-
 
298
    Write('EDIT UNICODE LABELS');
-
 
299
 
-
 
300
    if res = -1 then
-
 
301
    begin
-
 
302
      exit;
-
 
303
    end
-
 
304
    else if res = menuIdNew then
-
 
305
    begin
-
 
306
      (* "NEW" item was selected *)
-
 
307
      sInput := '';
-
 
308
      CursorOn;
-
 
309
      repeat
-
 
310
        if QueryVal(sInput,
-
 
311
                    SINGLE_LINE_BOX_PADDING_INNER,
-
 
312
                    ScreenHeight div 2,
-
 
313
                    ScreenWidth - (SINGLE_LINE_BOX_PADDING_INNER-1)*2,
-
 
314
                    1,
-
 
315
                    'ADD SINGLE UNICODE LABEL',
-
 
316
                    2) then
-
 
317
        begin
-
 
318
          if sInput = '' then continue;
-
 
319
          if not UnicodeLabelValid(sInput) then
-
 
320
          begin
-
 
321
            ShowMessage('Invalid Unicode Label!', 'ERROR', true);
-
 
322
            _Pause;
-
 
323
          end
-
 
324
          else if UnicodeLabelAlreadyExisting(oid, sInput) then
-
 
325
          begin
-
 
326
            ShowMessage('Unicode Label is already existing on this arc', 'ERROR', true);
-
 
327
            _Pause;
-
 
328
          end
-
 
329
          else
-
 
330
          begin
-
 
331
            ListAppend(oid^.UnicodeLabels, sInput);
-
 
332
            break;
-
 
333
          end;
-
 
334
        end
-
 
335
        else break;
-
 
336
      until false;
-
 
337
      CursorOff;
-
 
338
    end
-
 
339
    else if res = menuIdSave then
-
 
340
    begin
-
 
341
      (* "SAVE" item was selected *)
-
 
342
      IriEditor := true;
-
 
343
      Exit;
-
 
344
    end
-
 
345
    else if res = menuIdExit then
-
 
346
    begin
-
 
347
      (* "CANCEL" item was selected *)
-
 
348
      IriEditor := false;
-
 
349
      Exit;
-
 
350
    end
-
 
351
    else
-
 
352
    begin
-
 
353
      DrawStatusBar('Note: Remove the text to delete the Unicode Label');
-
 
354
      sInput := ListGetElement(oid^.UnicodeLabels, res);
-
 
355
          CursorOn;
-
 
356
      repeat
-
 
357
        if QueryVal(sInput,
-
 
358
                    SINGLE_LINE_BOX_PADDING_INNER,
-
 
359
                    ScreenHeight div 2,
-
 
360
                    ScreenWidth - (SINGLE_LINE_BOX_PADDING_INNER-1)*2,
-
 
361
                    1,
-
 
362
                    'EDIT SINGLE UNICODE LABEL',
-
 
363
                    2) then
-
 
364
        begin
-
 
365
          if sInput = '' then
-
 
366
          begin
-
 
367
            (* Empty input = Delete Unicode label *)
-
 
368
            ListDeleteElementByIndex(oid^.UnicodeLabels, res);
-
 
369
            break;
-
 
370
          end
-
 
371
          else if not UnicodeLabelValid(sInput) then
-
 
372
          begin
-
 
373
            ShowMessage('Invalid Unicode Label!', 'ERROR', true);
-
 
374
            _Pause;
-
 
375
          end
-
 
376
          else if UnicodeLabelAlreadyExisting(oid, sInput) and
-
 
377
              not (ListGetElement(oid^.UnicodeLabels, res) = sInput) then
-
 
378
          begin
-
 
379
            ShowMessage('Unicode Label is already existing on this arc', 'ERROR', true);
-
 
380
            _Pause;
-
 
381
          end
-
 
382
          else
-
 
383
          begin
-
 
384
            ListSetElement(oid^.UnicodeLabels, res, sInput);
-
 
385
            break;
-
 
386
          end;
-
 
387
        end
-
 
388
        else break;
-
 
389
      until false;
-
 
390
          CursorOff;
-
 
391
    end;
-
 
392
  until false;
-
 
393
end;
-
 
394
 
256
function DescEditor(oid: POID): boolean;
395
function DescEditor(oid: POID): boolean;
257
var
396
var
258
  sInput: string;
397
  sInput: string;
259
begin
398
begin
260
  DescEditor := false;
399
  DescEditor := false;
Line 393... Line 532...
393
  newOID^.FileId := NextPossibleFileID;
532
  newOID^.FileId := NextPossibleFileID;
394
  newOID^.ParentFileId := oid^.FileId;
533
  newOID^.ParentFileId := oid^.FileId;
395
  newOID^.ParentDotNotation := oid^.DotNotation;
534
  newOID^.ParentDotNotation := oid^.DotNotation;
396
  if NumIdEditor(newOID, oid) and
535
  if NumIdEditor(newOID, oid) and
397
     AsnEditor(newOID) and
536
     AsnEditor(newOID) and
-
 
537
     IriEditor(newOID) and
398
     DescEditor(newOID) then
538
     DescEditor(newOID) then
399
  begin
539
  begin
400
    newfilename := newOID^.FileId + OID_EXTENSION;
540
    newfilename := newOID^.FileId + OID_EXTENSION;
401
    if _WriteOidFile(newfilename, newOID, true) then
541
    if _WriteOidFile(newfilename, newOID, true) then
402
    begin
542
    begin
Line 503... Line 643...
503
    DrawTitleBar('OID ROOT', TITLEBAR_LEFT_TEXT, filename)
643
    DrawTitleBar('OID ROOT', TITLEBAR_LEFT_TEXT, filename)
504
  else
644
  else
505
    DrawTitleBar('OID ' + oid^.DotNotation, TITLEBAR_LEFT_TEXT, filename);
645
    DrawTitleBar('OID ' + oid^.DotNotation, TITLEBAR_LEFT_TEXT, filename);
506
end;
646
end;
507
 
647
 
-
 
648
function DotNotation(oid: POid): string;
-
 
649
var
-
 
650
  res: string;
-
 
651
begin
-
 
652
  res := oid^.DotNotation;
-
 
653
  if res = '' then res := '.'; (* root *)
-
 
654
  DotNotation := res;
-
 
655
end;
-
 
656
 
-
 
657
function OidLastArc(oid: POid): string;
-
 
658
var
-
 
659
  s: string;
-
 
660
  p: integer;
-
 
661
begin
-
 
662
  s := oid^.DotNotation;
-
 
663
 
-
 
664
  while true do
-
 
665
  begin
-
 
666
    p := Pos('.', s);
-
 
667
    if p = 0 then break;
-
 
668
    Delete(s, 1, p);
-
 
669
  end;
-
 
670
 
-
 
671
  OidLastArc := s;
-
 
672
end;
-
 
673
 
-
 
674
function AsnNotation(oid: POid): string;
-
 
675
var
-
 
676
  prevOid, curOid: POid;
-
 
677
  res: string;
-
 
678
begin
-
 
679
  CreateOidDef(curOid);
-
 
680
  prevOid := oid;
-
 
681
  res := '';
-
 
682
 
-
 
683
  while true do
-
 
684
  begin
-
 
685
    (* Note: BackRef is not checked yet! Infinite loop is possible! (TODO) *)
-
 
686
    ReadOidFile(prevOid^.ParentFileId + '.OID', curOid);
-
 
687
    if curOid^.ParentFileId = '' then break;
-
 
688
    if curOid^.ParentFileId = curOid^.FileId then break;
-
 
689
    if ListCount(curOid^.AsnIds) > 0 then
-
 
690
      res := ListGetElement(curOid^.AsnIds, 0) + '('+OidLastArc(curOid)+') ' + res
-
 
691
    else
-
 
692
      res := OidLastArc(curOid) + ' ' + res;
-
 
693
    prevOid := curOid;
-
 
694
  end;
-
 
695
  FreeOidDef(curOid);
-
 
696
  if ListCount(oid^.AsnIds) > 0 then
-
 
697
    res := res + ListGetElement(oid^.AsnIds, 0) + '('+OidLastArc(oid)+')'
-
 
698
  else
-
 
699
    res := res + OidLastArc(oid);
-
 
700
  if res = '' then
-
 
701
    AsnNotation := ''
-
 
702
  else
-
 
703
    AsnNotation := '{ ' + res + ' }';
-
 
704
end;
-
 
705
 
-
 
706
function IriNotation(oid: POid): string;
-
 
707
var
-
 
708
  prevOid, curOid: POid;
-
 
709
  res: string;
-
 
710
begin
-
 
711
  CreateOidDef(curOid);
-
 
712
  prevOid := oid;
-
 
713
  res := '';
-
 
714
 
-
 
715
  while true do
-
 
716
  begin
-
 
717
    (* Note: BackRef is not checked yet! Infinite loop is possible! (TODO) *)
-
 
718
    ReadOidFile(prevOid^.ParentFileId + '.OID', curOid);
-
 
719
    if curOid^.ParentFileId = '' then break;
-
 
720
    if curOid^.ParentFileId = curOid^.FileId then break;
-
 
721
    if ListCount(curOid^.UnicodeLabels) > 0 then
-
 
722
      res := ListGetElement(curOid^.UnicodeLabels, 0) + '/' + res
-
 
723
    else
-
 
724
      res := OidLastArc(curOid) + '/' + res;
-
 
725
    prevOid := curOid;
-
 
726
  end;
-
 
727
  FreeOidDef(curOid);
-
 
728
  if ListCount(oid^.UnicodeLabels) > 0 then
-
 
729
    res := res + ListGetElement(oid^.UnicodeLabels, 0)
-
 
730
  else
-
 
731
    res := res + OidLastArc(oid);
-
 
732
  IriNotation := '/' + res;
-
 
733
end;
-
 
734
 
-
 
735
function WeidNotation(oid: POid): string;
-
 
736
begin
-
 
737
  WeidNotation := OidToWeid(oid^.DotNotation);
-
 
738
end;
-
 
739
 
508
procedure DisplayOIDFile(filename: string);
740
procedure DisplayOIDFile(filename: string);
509
var
741
var
510
  isRoot: boolean;
742
  isRoot: boolean;
511
  oid, tmpOID: POID;
743
  oid, tmpOID: POID;
512
  i, menuX, menuY: integer;
744
  i: integer;
513
  linesLeft, linesRequired: integer;
-
 
514
  sTmp, subfile: string;
745
  sTmp, subfile: string;
515
  subsel, subfiles: PStringList;
746
  subsel, subfiles: PStringList;
516
  subselres: integer;
747
  subselres: integer;
517
  exitRequest: boolean;
748
  exitRequest: boolean;
518
  menuIdExit, menuIdAsnEdit, menuIdDescEdit, menuIdAdd, menuIdDelete: integer;
749
  menuIdExit, menuIdAsnEdit, menuIdIriEdit, menuIdDescEdit, menuIdAdd, menuIdDelete: integer;
-
 
750
  menuX, menuY: integer;
519
begin
751
begin
520
  exitRequest := false;
752
  exitRequest := false;
521
  repeat
753
  repeat
522
    CreateOidDef(oid);
754
    CreateOidDef(oid);
523
 
755
 
Line 532... Line 764...
532
    ClrScr;
764
    ClrScr;
533
    _DrawOidTitleBar(filename, oid);
765
    _DrawOidTitleBar(filename, oid);
534
    DrawStatusBar(DEFAULT_STATUSBAR);
766
    DrawStatusBar(DEFAULT_STATUSBAR);
535
    GotoXY(1,2);
767
    GotoXY(1,2);
536
 
768
 
537
    if oid^.DotNotation <> '' then
769
    (*if oid^.DotNotation <> '' then*)
538
    begin
770
    begin
539
      WriteLn('Dot-Notation:');
771
      Write('Dot notation:   ');
540
      WriteLn(oid^.DotNotation);
772
      WriteLnKeepX(DotNotation(oid));
-
 
773
      Write('IRI notation:   ');
-
 
774
      WriteLnKeepX(IriNotation(oid));
-
 
775
      Write('ASN.1 notation: ');
-
 
776
      WriteLnKeepX(AsnNotation(oid));
-
 
777
      Write('WEID notation:  ');
-
 
778
      WriteLnKeepX(WeidNotation(oid));
541
      WriteLn('');
779
      WriteLn('');
542
    end;
780
    end;
543
 
781
 
544
    if Trim(oid^.Description) <> '' then
782
    if Trim(oid^.Description) <> '' then
545
    begin
783
    begin
546
      WriteLn('Description:');
784
      (* WriteLn('Description:'); *)
547
      WriteLn(oid^.Description);
785
      WriteLn(oid^.Description);
548
      WriteLn('');
786
      WriteLn('');
549
    end;
-
 
550
 
-
 
551
    menuX := WhereX + 1;
-
 
552
    menuY := ScreenHeight - ACTIONMENU_SIZE - 1;
-
 
553
 
-
 
554
    if ListCount(oid^.ASNIDs) > 0 then
-
 
555
    begin
-
 
556
      linesLeft := menuY - WhereY - 1;
-
 
557
      linesRequired := 1 + ListCount(oid^.ASNIds);
-
 
558
 
-
 
559
      if LinesLeft < LinesRequired then
-
 
560
      begin
-
 
561
        (* Compact display of ASN.1 identifiers *)
-
 
562
        Write('ASN.1-Identifiers: ');
-
 
563
        for i := 0 to ListCount(oid^.ASNIds)-1 do
-
 
564
        begin
-
 
565
          if i > 0 then Write(', ');
-
 
566
          Write(ListGetElement(oid^.ASNIds, i));
-
 
567
        end;
-
 
568
        WriteLn('');
-
 
569
      end
787
    end
570
      else
788
    else
571
      begin
789
    begin
572
        (* Long display of ASN.1 identifiers *)
-
 
573
        WriteLn('ASN.1-Identifiers:');
-
 
574
        for i := 0 to ListCount(oid^.ASNIds)-1 do
-
 
575
        begin
-
 
576
          WriteLn('- '+ListGetElement(oid^.ASNIds, i));
790
      WriteLn('(No description has been added to this OID.)');
577
        end;
-
 
578
        WriteLn('');
791
      WriteLn('');
579
      end;
792
    end;
580
    end;
-
 
581
 
793
 
582
    (* Now prepare the menu entries *)
794
    (* Now prepare the menu entries *)
583
 
795
 
584
    CreateList(subsel);   (* Contains the human-readable OID name *)
796
    CreateList(subsel);   (* Contains the human-readable OID name *)
585
    CreateList(subfiles); (* Contains the file name               *)
797
    CreateList(subfiles); (* Contains the file name               *)
Line 657... Line 869...
657
      end;
869
      end;
658
    end;
870
    end;
659
 
871
 
660
    if oid^.DotNotation <> '' then
872
    if oid^.DotNotation <> '' then
661
    begin
873
    begin
662
      menuIdAsnEdit := ListAppend(subsel, 'Edit ASN.1 identifiers');
874
      menuIdAsnEdit := ListAppend(subsel, 'View/Edit ASN.1 identifiers');
663
      ListAppend(subfiles, '');
875
      ListAppend(subfiles, '');
664
    end
876
    end
665
    else menuIdAsnEdit := -99;
877
    else menuIdAsnEdit := -99;
666
 
878
 
-
 
879
    if oid^.DotNotation <> '' then
-
 
880
    begin
-
 
881
      menuIdIriEdit := ListAppend(subsel, 'View/Edit Unicode Labels');
-
 
882
      ListAppend(subfiles, '');
-
 
883
    end
-
 
884
    else menuIdIriEdit := -99;
-
 
885
 
667
    menuIdDescEdit := ListAppend(subsel, 'Edit description');
886
    menuIdDescEdit := ListAppend(subsel, 'Edit description');
668
    ListAppend(subfiles, '');
887
    ListAppend(subfiles, '');
669
 
888
 
670
    menuIdAdd := ListAppend(subsel, 'Add child');
889
    menuIdAdd := ListAppend(subsel, 'Add child');
671
    ListAppend(subfiles, '');
890
    ListAppend(subfiles, '');
Line 677... Line 896...
677
    end
896
    end
678
    else menuIdDelete := -99;
897
    else menuIdDelete := -99;
679
 
898
 
680
    (* Show menu *)
899
    (* Show menu *)
681
 
900
 
-
 
901
    menuX := WhereX + 1;
-
 
902
    menuY := ScreenHeight - ACTIONMENU_SIZE - 1;
682
    subselres := DrawSelectionList(menuX, menuY,
903
    subselres := DrawSelectionList(menuX, menuY,
683
                                   ScreenWidth-2,
904
                                   ScreenWidth-2,
684
                                   ACTIONMENU_SIZE,
905
                                   ACTIONMENU_SIZE,
685
                                   subsel,
906
                                   subsel,
686
                                   true,
907
                                   true,
Line 696... Line 917...
696
    else if subselres = menuIdAsnEdit then
917
    else if subselres = menuIdAsnEdit then
697
    begin
918
    begin
698
      if AsnEditor(oid) then
919
      if AsnEditor(oid) then
699
        _WriteOidFile(filename, oid, true);
920
        _WriteOidFile(filename, oid, true);
700
    end
921
    end
-
 
922
    else if subselres = menuIdIriEdit then
-
 
923
    begin
-
 
924
      if IriEditor(oid) then
-
 
925
        _WriteOidFile(filename, oid, true);
-
 
926
    end
701
    else if subselres = menuIdDescEdit then
927
    else if subselres = menuIdDescEdit then
702
    begin
928
    begin
703
      if DescEditor(oid) then
929
      if DescEditor(oid) then
704
        _WriteOidFile(filename, oid, true);
930
        _WriteOidFile(filename, oid, true);
705
    end
931
    end
Line 889... Line 1115...
889
 
1115
 
890
procedure TreeViewPreview;
1116
procedure TreeViewPreview;
891
var
1117
var
892
  list: PStringList;
1118
  list: PStringList;
893
begin
1119
begin
-
 
1120
  ClrScr;
-
 
1121
  DrawTitleBar('TreeView Export', TITLEBAR_LEFT_TEXT, TREEVIEW_FILENAME);
-
 
1122
  DrawStatusBar('Press ESC to return to the main menu');
-
 
1123
 
894
  CreateList(list);
1124
  CreateList(list);
895
 
1125
 
896
  DrawStatusBar('Press ESC to return to the main menu');
-
 
897
  ListLoadFromFile(list, TREEVIEW_FILENAME);
1126
  ListLoadFromFile(list, TREEVIEW_FILENAME);
898
  DrawSelectionList(2, 3, ScreenWidth-2, ScreenHeight-4,
1127
  DrawSelectionList(2, 3, ScreenWidth-2, ScreenHeight-4,
899
                    list, true, 'PREVIEW OF '+TREEVIEW_FILENAME, 2);
1128
                    list, true, 'PREVIEW OF '+TREEVIEW_FILENAME, 2);
900
  (* TODO: Jump to selected OID *)
1129
  (* TODO: Jump to selected OID *)
901
 
1130