Subversion Repositories oidplus

Rev

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

Rev 742 Rev 743
Line 35... Line 35...
35
  MAINMENU_ALLOW_ESC     = false;
35
  MAINMENU_ALLOW_ESC     = false;
36
  TREEVIEW_INDENT        = 0;
36
  TREEVIEW_INDENT        = 0;
37
  TREEVIEW_INCLUDE_DESC  = true;
37
  TREEVIEW_INCLUDE_DESC  = true;
38
  TREEVIEW_WIDTH         = 80;
38
  TREEVIEW_WIDTH         = 80;
39
 
39
 
40
procedure _WriteOidFile(filename: string; oid: POid);
40
procedure _Pause;
-
 
41
var
-
 
42
  bakX, bakY: integer;
41
begin
43
begin
-
 
44
  bakX := WhereX;
-
 
45
  bakY := WhereY;
42
  DrawStatusBar('Write file ' + filename + '...');
46
  DrawStatusBar('Press any key to continue');
43
  WriteOidFile(filename, oid);
47
  GoToXY(bakX, bakY);
-
 
48
  ReadKey;
-
 
49
  DrawStatusBar(DEFAULT_STATUSBAR);
-
 
50
end;
44
 
51
 
-
 
52
function _WriteOidFile(filename: string; oid: POid; ShowErrorMessage: boolean): boolean;
-
 
53
var
-
 
54
  res: boolean;
-
 
55
begin
-
 
56
  DrawStatusBar('Write file ' + filename + '...');
-
 
57
  res := WriteOidFile(filename, oid);
45
  if DISKIO_SOUND_DEBUGGING then
58
  if DISKIO_SOUND_DEBUGGING then
46
  begin
59
  begin
47
    Sound(70);
60
    Sound(70);
48
    Delay(DISKIO_SOUND_DELAY - 10);
61
    Delay(DISKIO_SOUND_DELAY - 10);
49
    NoSound;
62
    NoSound;
50
    Delay(10);
63
    Delay(10);
51
  end;
64
  end;
52
 
-
 
53
  DrawStatusBar(DEFAULT_STATUSBAR);
65
  DrawStatusBar(DEFAULT_STATUSBAR);
-
 
66
 
-
 
67
  _WriteOidFile := res;
-
 
68
 
-
 
69
  if ShowErrorMessage and not res then
-
 
70
  begin
-
 
71
    ShowMessage('Cannot write to file ' + filename, 'ERROR', true);
-
 
72
    _Pause;
-
 
73
  end;
54
end;
74
end;
55
 
75
 
56
procedure _ReadOidFile(filename: string; oid: POid);
76
function _ReadOidFile(filename: string; oid: POid; ShowErrorMessage: boolean): boolean;
-
 
77
var
-
 
78
  res: boolean;
57
begin
79
begin
58
  DrawStatusBar('Read file ' + filename + '...');
80
  DrawStatusBar('Read file ' + filename + '...');
59
  ReadOidFile(filename, oid);
81
  res := ReadOidFile(filename, oid);
60
 
-
 
61
  if DISKIO_SOUND_DEBUGGING then
82
  if DISKIO_SOUND_DEBUGGING then
62
  begin
83
  begin
63
    Sound(50);
84
    Sound(50);
64
    Delay(DISKIO_SOUND_DELAY - 10);
85
    Delay(DISKIO_SOUND_DELAY - 10);
65
    NoSound;
86
    NoSound;
66
    Delay(10);
87
    Delay(10);
67
  end;
88
  end;
68
 
-
 
69
  DrawStatusBar(DEFAULT_STATUSBAR);
89
  DrawStatusBar(DEFAULT_STATUSBAR);
70
end;
-
 
71
 
90
 
72
procedure _Pause;
91
  _ReadOidFile := res;
73
var
92
 
74
  bakX, bakY: integer;
93
  if ShowErrorMessage and not res then
75
begin
94
  begin
76
  bakX := WhereX;
-
 
77
  bakY := WhereY;
-
 
78
  DrawStatusBar('Press any key to continue');
95
    ShowMessage('Cannot read file ' + filename, 'ERROR', true);
79
  GoToXY(bakX, bakY);
96
    _Pause;
80
  ReadKey;
97
  end;
81
  DrawStatusBar(DEFAULT_STATUSBAR);
-
 
82
end;
98
end;
83
 
99
 
84
function _ShowASNIds(childOID: POID): string;
100
function _ShowASNIds(childOID: POID): string;
85
var
101
var
86
  j, jmax: integer;
102
  j, jmax: integer;
Line 372... Line 388...
372
  if NumIdEditor(newOID, oid) and
388
  if NumIdEditor(newOID, oid) and
373
     AsnEditor(newOID) and
389
     AsnEditor(newOID) and
374
     DescEditor(newOID) then
390
     DescEditor(newOID) then
375
  begin
391
  begin
376
    newfilename := newOID^.FileId + '.OID';
392
    newfilename := newOID^.FileId + '.OID';
377
    _WriteOidFile(newfilename, newOID);
393
    if _WriteOidFile(newfilename, newOID, true) then
378
 
394
    begin
379
    (* Add link to original file and enable the saving of it *)
395
      (* Add link to original file and enable the saving of it *)
380
    ListAppend(oid^.SubIds, newOID^.FileId + newOID^.DotNotation);
396
      ListAppend(oid^.SubIds, newOID^.FileId + newOID^.DotNotation);
381
    NewOidEditor := true; (* request caller to save <oid> *)
397
      NewOidEditor := true; (* request caller to save <oid> *)
382
  end;
398
    end;
-
 
399
  end;
383
  FreeOidDef(newOID);
400
  FreeOidDef(newOID);
384
end;
401
end;
385
 
402
 
386
procedure DeleteChildrenRecursive(oid: POID);
403
procedure DeleteChildrenRecursive(oid: POID);
387
var
404
var
Line 393... Line 410...
393
  begin
410
  begin
394
    filenameChild := FileIdPart(ListGetElement(oid^.SubIds, i)) + '.OID';
411
    filenameChild := FileIdPart(ListGetElement(oid^.SubIds, i)) + '.OID';
395
    if FileExists(filenameChild) then
412
    if FileExists(filenameChild) then
396
    begin
413
    begin
397
      CreateOidDef(childOID);
414
      CreateOidDef(childOID);
398
      _ReadOidFile(filenameChild, childOID);
415
      if _ReadOidFile(filenameChild, childOID, false) then
-
 
416
      begin
399
      DeleteChildrenRecursive(childOID);
417
        DeleteChildrenRecursive(childOID);
-
 
418
      end;
400
      FreeOidDef(childOID);
419
      FreeOidDef(childOID);
401
      DeleteFile(filenameChild);
420
      DeleteFile(filenameChild);
402
    end;
421
    end;
403
  end;
422
  end;
404
  ListClear(oid^.SubIds);
423
  ListClear(oid^.SubIds);
Line 412... Line 431...
412
begin
431
begin
413
  (* Remove all children and their files recursively *)
432
  (* Remove all children and their files recursively *)
414
  DeleteChildrenRecursive(selfOID);
433
  DeleteChildrenRecursive(selfOID);
415
 
434
 
416
  (* Remove forward reference in parent OID *)
435
  (* Remove forward reference in parent OID *)
-
 
436
  (* (this is the most important part)      *)
417
  filenameParent := FileIdPart(selfOID^.Parent) + '.OID';
437
  filenameParent := FileIdPart(selfOID^.Parent) + '.OID';
418
  if FileExists(filenameParent) then
438
  if FileExists(filenameParent) then
419
  begin
439
  begin
420
    CreateOidDef(parentOID);
440
    CreateOidDef(parentOID);
421
    _ReadOidFile(filenameParent, parentOID);
441
    if _ReadOidFile(filenameParent, parentOID, true) then
-
 
442
    begin
422
    if ListDeleteElementByValue(parentOID^.SubIds, selfOID^.FileId + selfOID^.DotNotation) then
443
      if ListDeleteElementByValue(parentOID^.SubIds, selfOID^.FileId + selfOID^.DotNotation) then
423
    begin
444
      begin
424
      _WriteOidFile(filenameParent, parentOID);
445
        _WriteOidFile(filenameParent, parentOID, true);
-
 
446
      end;
425
    end;
447
    end;
426
    FreeOidDef(parentOID);
448
    FreeOidDef(parentOID);
427
  end;
449
  end;
428
 
450
 
429
  (* Delete own file *)
451
  (* Delete own file *)
Line 483... Line 505...
483
  exitRequest: boolean;
505
  exitRequest: boolean;
484
  menuIdExit, menuIdAsnEdit, menuIdDescEdit, menuIdAdd, menuIdDelete: integer;
506
  menuIdExit, menuIdAsnEdit, menuIdDescEdit, menuIdAdd, menuIdDelete: integer;
485
begin
507
begin
486
  exitRequest := false;
508
  exitRequest := false;
487
  repeat
509
  repeat
-
 
510
    CreateOidDef(oid);
-
 
511
 
488
    if not FileExists(filename) then
512
    if not _ReadOidFile(filename, oid, true) then
489
    begin
513
    begin
490
      ShowMessage('File ' + filename + ' not found', 'ERROR', true);
-
 
491
      _Pause;
514
      FreeOidDef(oid);
492
      exit;
515
      exit;
493
    end;
516
    end;
494
 
517
 
495
    CreateOidDef(oid);
-
 
496
    _ReadOidFile(filename, oid);
-
 
497
 
-
 
498
    (* Print OID information *)
518
    (* Print OID information *)
499
 
519
 
500
    ClrScr;
520
    ClrScr;
501
    _DrawOidTitleBar(filename, oid);
521
    _DrawOidTitleBar(filename, oid);
502
    DrawStatusBar(DEFAULT_STATUSBAR);
522
    DrawStatusBar(DEFAULT_STATUSBAR);
Line 566... Line 586...
566
      sTmp := oid^.Parent;
586
      sTmp := oid^.Parent;
567
      subfile := FileIdPart(sTmp) + '.OID';
587
      subfile := FileIdPart(sTmp) + '.OID';
568
      if FileExists(subfile) then
588
      if FileExists(subfile) then
569
      begin
589
      begin
570
        CreateOidDef(tmpOID);
590
        CreateOidDef(tmpOID);
571
        _ReadOidFile(subfile, tmpOID);
591
        if _ReadOidFile(subfile, tmpOID, true) then
572
        ListAppend(subsel, 'Go to parent ' + DotNotationPart(sTmp) + _ShowASNIds(tmpOID));
592
          ListAppend(subsel, 'Go to parent ' + DotNotationPart(sTmp) + _ShowASNIds(tmpOID))
-
 
593
        else
-
 
594
          ListAppend(subsel, 'Go to parent ' + DotNotationPart(sTmp) + ' (READ ERROR)');
573
        FreeOidDef(tmpOID);
595
        FreeOidDef(tmpOID);
574
      end
596
      end
575
      else
597
      else
576
      begin
598
      begin
577
        ListAppend(subsel, 'Go to parent ' + DotNotationPart(sTmp) + ' (FILE NOT FOUND)');
599
        ListAppend(subsel, 'Go to parent ' + DotNotationPart(sTmp) + ' (FILE NOT FOUND)');
Line 591... Line 613...
591
      sTmp := ListGetElement(oid^.SubIds, i);
613
      sTmp := ListGetElement(oid^.SubIds, i);
592
      subfile := FileIdPart(sTmp) + '.OID';
614
      subfile := FileIdPart(sTmp) + '.OID';
593
      if FileExists(subfile) then
615
      if FileExists(subfile) then
594
      begin
616
      begin
595
        CreateOidDef(tmpOID);
617
        CreateOidDef(tmpOID);
596
        _ReadOidFile(subfile, tmpOID);
618
        if _ReadOidFile(subfile, tmpOID, true) then
597
        ListAppend(subsel, 'Go to child  ' + DotNotationPart(sTmp) + _ShowASNIds(tmpOID));
619
          ListAppend(subsel, 'Go to child  ' + DotNotationPart(sTmp) + _ShowASNIds(tmpOID))
-
 
620
        else
-
 
621
          ListAppend(subsel, 'Go to child  ' + DotNotationPart(sTmp) + ' (READ ERROR)');
598
        FreeOidDef(tmpOID);
622
        FreeOidDef(tmpOID);
599
      end
623
      end
600
      else
624
      else
601
      begin
625
      begin
602
        ListAppend(subsel, 'Go to child  ' + DotNotationPart(sTmp) + ' (FILE NOT FOUND)');
626
        ListAppend(subsel, 'Go to child  ' + DotNotationPart(sTmp) + ' (FILE NOT FOUND)');
Line 641... Line 665...
641
      exitRequest := true;
665
      exitRequest := true;
642
    end
666
    end
643
    else if subselres = menuIdAsnEdit then
667
    else if subselres = menuIdAsnEdit then
644
    begin
668
    begin
645
      if AsnEditor(oid) then
669
      if AsnEditor(oid) then
646
        _WriteOidFile(filename, oid);
670
        _WriteOidFile(filename, oid, true);
647
    end
671
    end
648
    else if subselres = menuIdDescEdit then
672
    else if subselres = menuIdDescEdit then
649
    begin
673
    begin
650
      if DescEditor(oid) then
674
      if DescEditor(oid) then
651
        _WriteOidFile(filename, oid);
675
        _WriteOidFile(filename, oid, true);
652
    end
676
    end
653
    else if subselres = menuIdAdd then
677
    else if subselres = menuIdAdd then
654
    begin
678
    begin
655
      if NewOidEditor(oid) then
679
      if NewOidEditor(oid) then
656
        _WriteOidFile(filename, oid);
680
        _WriteOidFile(filename, oid, true);
657
    end
681
    end
658
    else if subselres = menuIdDelete then
682
    else if subselres = menuIdDelete then
659
    begin
683
    begin
660
      if _DeleteConfirmation then
684
      if _DeleteConfirmation then
661
      begin
685
      begin
Line 665... Line 689...
665
        begin
689
        begin
666
          filename := sTmp;
690
          filename := sTmp;
667
        end
691
        end
668
        else
692
        else
669
        begin
693
        begin
670
          ShowMessage('Parent file ' + filename + ' not found', 'ERROR', true);
694
          ShowMessage('Parent file ' + sTmp + ' not found', 'ERROR', true);
671
          _Pause;
695
          _Pause;
672
          exitRequest := true;
696
          exitRequest := true;
673
        end;
697
        end;
674
      end;
698
      end;
675
    end
699
    end
Line 685... Line 709...
685
      begin
709
      begin
686
        filename := sTmp;
710
        filename := sTmp;
687
      end
711
      end
688
      else
712
      else
689
      begin
713
      begin
690
        ShowMessage('File ' + filename + ' not found', 'ERROR', true);
714
        ShowMessage('File ' + sTmp + ' not found', 'ERROR', true);
691
        _Pause;
715
        _Pause;
692
      end;
716
      end;
693
    end;
717
    end;
694
    FreeList(subsel);
718
    FreeList(subsel);
695
    FreeList(subfiles);
719
    FreeList(subfiles);
696
 
720
 
697
    FreeOidDef(oid);
721
    FreeOidDef(oid);
698
  until exitRequest;
722
  until exitRequest;
699
end;
723
end;
700
 
724
 
701
procedure CreateRootOIDFile(filename: string);
725
function CreateRootOIDFile(filename: string; ShowErrorMessage: boolean): boolean;
702
var
726
var
703
  oid: POID;
727
  oid: POID;
704
begin
728
begin
705
  CreateOidDef(oid);
729
  CreateOidDef(oid);
706
  oid^.Description := 'This is the root of the OID tree.' +#13#10 +
730
  oid^.Description := 'This is the root of the OID tree.' +#13#10 +
Line 710... Line 734...
710
                      '- 1 (iso)' + #13#10 +
734
                      '- 1 (iso)' + #13#10 +
711
                      '- 2 (joint-iso-itu-t)';
735
                      '- 2 (joint-iso-itu-t)';
712
  oid^.FileId      := ZeroPad(0, 8);
736
  oid^.FileId      := ZeroPad(0, 8);
713
  oid^.DotNotation := '';
737
  oid^.DotNotation := '';
714
  oid^.Parent      := ZeroPad(0, 8);
738
  oid^.Parent      := ZeroPad(0, 8);
715
  _WriteOidFile(filename, oid);
739
  CreateRootOIDFile := _WriteOidFile(filename, oid, ShowErrorMessage);
716
  FreeOidDef(oid);
740
  FreeOidDef(oid);
717
end;
741
end;
718
 
742
 
719
function _GetRootFile(ShowErrorMessage: boolean): string;
743
function _GetRootFile(ShowErrorMessage: boolean): string;
720
var
744
var
721
  rootFile: string;
745
  rootFile: string;
722
begin
746
begin
723
  rootFile := ZeroPad(0, 8) + '.OID';
747
  rootFile := ZeroPad(0, 8) + '.OID';
-
 
748
  _GetRootFile := rootFile;
724
  if not FileExists(rootFile) then
749
  if not FileExists(rootFile) then
725
  begin
750
  begin
726
    {$I-}
-
 
727
    CreateRootOIDFile(rootFile);
751
    if not CreateRootOIDFile(rootFile, ShowErrorMessage) then
728
    {$I+}
-
 
729
  end;
-
 
730
  if not FileExists(rootFile) then
-
 
731
  begin
752
    begin
732
    _GetRootFile := '';
753
      _GetRootFile := '';
733
    if ShowErrorMessage then
-
 
734
    begin
-
 
735
      ShowMessage('Cannot create ' + rootfile + '! Is disk read-only?', 'ERROR', true);
-
 
736
      _Pause;
-
 
737
    end;
754
    end;
738
  end
-
 
739
  else
-
 
740
  begin
-
 
741
    _GetRootFile := rootFile;
-
 
742
  end;
755
  end;
743
end;
756
end;
744
 
757
 
745
procedure OP_ManageOIDs;
758
procedure OP_ManageOIDs;
746
var
759
var
Line 767... Line 780...
767
end;
780
end;
768
 
781
 
769
procedure OP_ReturnToMSDOS;
782
procedure OP_ReturnToMSDOS;
770
begin
783
begin
771
  ClrScr;
784
  ClrScr;
-
 
785
  TextBackground(Black);
-
 
786
  TextColor(LightGray);
772
  WriteLn('Thank you for using OIDplus for DOS.');
787
  WriteLn('Thank you for using OIDplus for DOS.');
773
  WRiteLn('');
788
  WriteLn('');
774
end;
789
end;
775
 
790
 
776
function _GetTreeViewLine(oid: POID; indent: integer): string;
791
function _GetTreeViewLine(oid: POID; indent: integer): string;
777
var
792
var
778
  i: integer;
793
  i: integer;
Line 818... Line 833...
818
  for i := 0 to ListCount(oid^.SubIds)-1 do
833
  for i := 0 to ListCount(oid^.SubIds)-1 do
819
  begin
834
  begin
820
    sTmp := ListGetElement(oid^.SubIds, i);
835
    sTmp := ListGetElement(oid^.SubIds, i);
821
    CreateOidDef(suboid);
836
    CreateOidDef(suboid);
822
    childFilename := FileIdPart(sTmp) + '.OID';
837
    childFilename := FileIdPart(sTmp) + '.OID';
823
    if FileExists(childFilename) then
838
    if not FileExists(childFilename) then
824
    begin
839
    begin
825
      _ReadOidFile(childFilename, suboid);
840
      sTmp := 'ERROR: ' + childFilename + ' FILE MISSING (CONTAINS ' + DotNotationPart(sTmp) + ')!';
826
      _RecTreeExport(suboid, F, indent+1);
841
      sTmp := TrimLineToWidth(sTmp, TREEVIEW_WIDTH);
827
      FreeOidDef(suboid);
842
      WriteLn(F, sTmp);
828
    end
843
    end
829
    else
844
    else if not _ReadOidFile(childFilename, suboid, false) then
830
    begin
845
    begin
831
      sTmp := 'ERROR: FILE ' + childFilename + ' CONTAINING CHILD OID ' + DotNotationPart(sTmp) + ' WAS NOT FOUND!';
846
      sTmp := 'ERROR: ' + childFilename + ' READ ERROR (CONTAINS ' + DotNotationPart(sTmp) + ')!';
832
      sTmp := TrimLineToWidth(sTmp, TREEVIEW_WIDTH);
847
      sTmp := TrimLineToWidth(sTmp, TREEVIEW_WIDTH);
833
      WriteLn(F, sTmp);
848
      WriteLn(F, sTmp);
834
    end;
849
    end
-
 
850
    else
-
 
851
    begin
-
 
852
      _RecTreeExport(suboid, F, indent+1);
-
 
853
      FreeOidDef(suboid);
-
 
854
    end
835
  end;
855
  end;
836
end;
856
end;
837
 
857
 
838
procedure OP_TreeView;
858
procedure OP_TreeView;
839
var
859
var
840
  F: Text;
860
  F: Text;
841
  rootoid: POID;
861
  rootoid: POID;
842
  rootfile: string;
862
  rootfile: string;
-
 
863
  res: boolean;
843
begin
864
begin
844
  ClrScr;
865
  ClrScr;
845
  DrawTitleBar('TreeView Export', TITLEBAR_LEFT_TEXT, '');
866
  DrawTitleBar('TreeView Export', TITLEBAR_LEFT_TEXT, '');
846
  DrawStatusBar('Exporting data... please wait...');
867
  DrawStatusBar('Exporting data... please wait...');
847
 
868
 
848
  (* This will try creating a new root file if it does not exist *)
869
  (* This will try creating a new root file if it does not exist *)
849
  rootfile := _GetRootFile(true);;
870
  rootfile := _GetRootFile(true);
850
  if rootfile = '' then Exit;
871
  if rootfile = '' then
-
 
872
  begin
-
 
873
    DrawStatusBar(DEFAULT_STATUSBAR);
-
 
874
    Exit;
-
 
875
  end;
851
 
876
 
852
  Assign(F, 'OIDTREE.TXT');
877
  Assign(F, 'OIDTREE.TXT');
-
 
878
  {$I-}
853
  Rewrite(F);
879
  Rewrite(F);
-
 
880
  {$I+}
-
 
881
  if IoResult <> 0 then
-
 
882
  begin
-
 
883
    (* Can happen if disk is read-only (Runtime Error 150) *)
-
 
884
    ShowMessage('Cannot open OIDTREE.TXT for writing.', 'ERROR', true);
-
 
885
    _Pause;
-
 
886
    DrawStatusBar(DEFAULT_STATUSBAR);
-
 
887
    Exit;
-
 
888
  end;
854
 
889
 
-
 
890
  res := false;
855
  CreateOidDef(rootoid);
891
  CreateOidDef(rootoid);
856
  _ReadOidFile(rootfile, rootoid);
892
  if _ReadOidFile(rootfile, rootoid, true) then
-
 
893
  begin
857
  _RecTreeExport(rootoid, F, 0);
894
    _RecTreeExport(rootoid, F, 0);
-
 
895
    res := true;
-
 
896
  end;
858
  FreeOidDef(rootoid);
897
  FreeOidDef(rootoid);
859
 
898
 
-
 
899
  Close(F);
-
 
900
 
860
  DrawStatusBar(DEFAULT_STATUSBAR);
901
  DrawStatusBar(DEFAULT_STATUSBAR);
-
 
902
  if res then
-
 
903
  begin
861
  ShowMessage('TreeView successfully exported as OIDTREE.TXT', 'TREEVIEW EXPORT', true);
904
    ShowMessage('TreeView successfully exported as OIDTREE.TXT', 'TREEVIEW EXPORT', true);
862
  _Pause;
905
    _Pause;
863
 
-
 
864
  Close(F);
906
  end;
865
end;
907
end;
866
 
908
 
867
procedure OP_MainMenu;
909
procedure OP_MainMenu;
868
var
910
var
869
  menu: PStringList;
911
  menu: PStringList;