Subversion Repositories oidplus

Rev

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

Rev 748 Rev 749
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-19                         *)
6
(* Revision: 2022-02-20                         *)
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 20... Line 20...
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
  Weid;
23
 
23
 
24
const
24
const
25
  VERSIONINFO            = 'Revision: 2022-02-19';
25
  VERSIONINFO            = 'Revision: 2022-02-20';
26
  DEFAULT_STATUSBAR      = '(C)2020-2022 ViaThinkSoft. Licensed under the terms of the Apache 2.0 license.';
-
 
27
  TITLEBAR_LEFT_TEXT     = 'OIDplus';
26
  TITLEBAR_LEFT_TEXT     = 'OIDplus';
28
  DISKIO_SOUND_DEBUGGING = false;
27
  DISKIO_SOUND_DEBUGGING = false;
29
  DISKIO_SOUND_DELAY     = 500;
28
  DISKIO_SOUND_DELAY     = 500;
30
  ASNEDIT_LINES          = 10;
29
  ASNEDIT_LINES          = 10;
31
  DESCEDIT_LINES         = 10;
30
  DESCEDIT_LINES         = 10;
Line 44... Line 43...
44
begin
43
begin
45
  DrawStatusBar('Press any key to continue');
44
  DrawStatusBar('Press any key to continue');
46
  CursorOn;
45
  CursorOn;
47
  ReadKey;
46
  ReadKey;
48
  CursorOff;
47
  CursorOff;
49
  DrawStatusBar(DEFAULT_STATUSBAR);
48
  DrawStatusBar('');
50
end;
49
end;
51
 
50
 
52
function _WriteOidFile(filename: string; oid: POid; ShowErrorMessage: boolean): boolean;
51
function _WriteOidFile(filename: string; oid: POid; ShowErrorMessage: boolean): boolean;
53
var
52
var
54
  res: boolean;
53
  res: boolean;
Line 60... Line 59...
60
    Sound(70);
59
    Sound(70);
61
    Delay(DISKIO_SOUND_DELAY - 10);
60
    Delay(DISKIO_SOUND_DELAY - 10);
62
    NoSound;
61
    NoSound;
63
    Delay(10);
62
    Delay(10);
64
  end;
63
  end;
65
  DrawStatusBar(DEFAULT_STATUSBAR);
64
  DrawStatusBar('');
66
 
65
 
67
  _WriteOidFile := res;
66
  _WriteOidFile := res;
68
 
67
 
69
  if ShowErrorMessage and not res then
68
  if ShowErrorMessage and not res then
70
  begin
69
  begin
Line 84... Line 83...
84
    Sound(50);
83
    Sound(50);
85
    Delay(DISKIO_SOUND_DELAY - 10);
84
    Delay(DISKIO_SOUND_DELAY - 10);
86
    NoSound;
85
    NoSound;
87
    Delay(10);
86
    Delay(10);
88
  end;
87
  end;
89
  DrawStatusBar(DEFAULT_STATUSBAR);
88
  DrawStatusBar('');
90
 
89
 
91
  _ReadOidFile := res;
90
  _ReadOidFile := res;
92
 
91
 
93
  if ShowErrorMessage and not res then
92
  if ShowErrorMessage and not res then
94
  begin
93
  begin
Line 141... Line 140...
141
    end;
140
    end;
142
    menuIdNew  := ListAppend(asnList, '<NEW>');
141
    menuIdNew  := ListAppend(asnList, '<NEW>');
143
    menuIdSave := ListAppend(asnList, '<SAVE>');
142
    menuIdSave := ListAppend(asnList, '<SAVE>');
144
    menuIdExit := ListAppend(asnList, '<CANCEL>');
143
    menuIdExit := ListAppend(asnList, '<CANCEL>');
145
 
144
 
146
    DrawStatusBar(DEFAULT_STATUSBAR);
145
    DrawStatusBar('');
147
    x := SINGLE_LINE_BOX_PADDING;
146
    x := SINGLE_LINE_BOX_PADDING;
148
    y := ScreenHeight div 2 - ASNEDIT_LINES div 2;
147
    y := ScreenHeight div 2 - ASNEDIT_LINES div 2;
149
    w := ScreenWidth - (SINGLE_LINE_BOX_PADDING-1)*2;
148
    w := ScreenWidth - (SINGLE_LINE_BOX_PADDING-1)*2;
150
    h := ASNEDIT_LINES;
149
    h := ASNEDIT_LINES;
151
    res := DrawSelectionList(x, y, w, h,
150
    res := DrawSelectionList(x, y, w, h,
Line 279... Line 278...
279
    end;
278
    end;
280
    menuIdNew  := ListAppend(iriList, '<NEW>');
279
    menuIdNew  := ListAppend(iriList, '<NEW>');
281
    menuIdSave := ListAppend(iriList, '<SAVE>');
280
    menuIdSave := ListAppend(iriList, '<SAVE>');
282
    menuIdExit := ListAppend(iriList, '<CANCEL>');
281
    menuIdExit := ListAppend(iriList, '<CANCEL>');
283
 
282
 
284
    DrawStatusBar(DEFAULT_STATUSBAR);
283
    DrawStatusBar('');
285
    x := SINGLE_LINE_BOX_PADDING;
284
    x := SINGLE_LINE_BOX_PADDING;
286
    y := ScreenHeight div 2 - ASNEDIT_LINES div 2;
285
    y := ScreenHeight div 2 - ASNEDIT_LINES div 2;
287
    w := ScreenWidth - (SINGLE_LINE_BOX_PADDING-1)*2;
286
    w := ScreenWidth - (SINGLE_LINE_BOX_PADDING-1)*2;
288
    h := ASNEDIT_LINES;
287
    h := ASNEDIT_LINES;
289
    res := DrawSelectionList(x, y, w, h,
288
    res := DrawSelectionList(x, y, w, h,
Line 441... Line 440...
441
  end;
440
  end;
442
  NextPossibleFileId := sId;
441
  NextPossibleFileId := sId;
443
  FreeList(list);
442
  FreeList(list);
444
end;
443
end;
445
 
444
 
446
function NumIdAlreadyExisting(parentOID: POID; sInput: string): boolean;
445
function NumIdAlreadyExisting(parentOID: POID; arcval: string): boolean;
447
var
446
var
448
  searchDotNotation: string;
447
  searchDotNotation: string;
449
  sTmp: string;
448
  sTmp: string;
450
  i: integer;
449
  i: integer;
451
begin
450
begin
452
  if parentOID^.DotNotation = '' then
451
  if parentOID^.DotNotation = '' then
453
    searchDotNotation := sInput
452
    searchDotNotation := arcval
454
  else
453
  else
455
    searchDotNotation := parentOID^.DotNotation + '.' + sInput;
454
    searchDotNotation := parentOID^.DotNotation + '.' + arcval;
456
  for i := 0 to ListCount(parentOID^.SubIds)-1 do
455
  for i := 0 to ListCount(parentOID^.SubIds)-1 do
457
  begin
456
  begin
458
    sTmp := ListGetElement(parentOID^.SubIds, i);
457
    sTmp := ListGetElement(parentOID^.SubIds, i);
459
    if DotNotationPart(sTmp) = searchDotNotation then
458
    if DotNotationPart(sTmp) = searchDotNotation then
460
    begin
459
    begin
Line 466... Line 465...
466
end;
465
end;
467
 
466
 
468
function NumIdEditor(oid: POID; parentOID: POID): boolean;
467
function NumIdEditor(oid: POID; parentOID: POID): boolean;
469
var
468
var
470
  sInput: string;
469
  sInput: string;
-
 
470
  title: string;
-
 
471
  base36mode: boolean;
-
 
472
  arcval: string;
471
begin
473
begin
472
  NumIdEditor := false;
474
  NumIdEditor := false;
473
  sInput := '';
475
  sInput := '';
474
 
476
 
-
 
477
  base36mode := false;
475
  CursorOn;
478
  CursorOn;
476
  repeat
479
  repeat
-
 
480
    if base36mode then
-
 
481
    begin
-
 
482
      DrawStatusBar('Press ESC to cancel');
-
 
483
      title := 'ENTER BASE36 ID'
-
 
484
    end
-
 
485
    else
-
 
486
    begin
-
 
487
      DrawStatusBar('Enter "WEID" to enter a Base36 instead of Base10; press ESC to cancel');
-
 
488
      title := 'ENTER NUMERIC ID';
-
 
489
    end;
477
    if QueryVal(sInput,
490
    if QueryVal(sInput,
478
                SINGLE_LINE_BOX_PADDING_INNER,
491
                SINGLE_LINE_BOX_PADDING_INNER,
479
                ScreenHeight div 2,
492
                ScreenHeight div 2,
480
                ScreenWidth - (SINGLE_LINE_BOX_PADDING_INNER-1)*2,
493
                ScreenWidth - (SINGLE_LINE_BOX_PADDING_INNER-1)*2,
481
                1,
494
                1,
482
                'ENTER NUMERIC ID',
495
                title,
483
                2) then
496
                2) then
484
    begin
497
    begin
485
      if sInput = '' then continue;
498
      if sInput = '' then continue;
-
 
499
      if not base36mode and (sInput = 'WEID') then
-
 
500
      begin
-
 
501
        sInput := '';
-
 
502
        base36mode := true;
-
 
503
      end
486
      if not IsPositiveIntegerOrZero(sInput) then
504
      else if not base36mode and not IsPositiveIntegerOrZero(sInput) then
487
      begin
505
      begin
488
        ShowMessage('Invalid numeric ID (must be a positive integer)', 'ERROR', true);
506
        ShowMessage('Invalid numeric ID (must be a positive integer)', 'ERROR', true);
489
        _Pause;
507
        _Pause;
490
      end
508
      end
491
      else if (parentOID^.DotNotation='') and (StrToInt(sInput) > 2) then
509
      else if base36mode and not IsBase36String(sInput) then
-
 
510
      begin
-
 
511
        ShowMessage('Invalid base36 ID (must be 0..9, A..Z)', 'ERROR', true);
-
 
512
        _Pause;
-
 
513
      end
-
 
514
      else
-
 
515
      begin
-
 
516
        if base36mode then
-
 
517
          arcval := base_convert_bigint(sInput, 36, 10)
-
 
518
        else
-
 
519
          arcval := sInput;
-
 
520
        arcval := StripLeadingZeros(arcval);
-
 
521
 
-
 
522
        if (parentOID^.DotNotation='') and (arcval <> '0') and (arcval <> '1') and (arcval <> '2') then
492
      begin
523
        begin
493
        ShowMessage('Invalid numeric ID (root arc can only be 0, 1, or 2)', 'ERROR', true);
524
          ShowMessage('Invalid numeric ID (root arc can only be 0, 1, or 2)', 'ERROR', true);
494
        _Pause;
525
          _Pause;
495
      end
526
        end
496
      else if ((parentOID^.DotNotation='0') or (parentOID^.DotNotation='1')) and (StrToInt(sInput) > 39) then
527
        else if ((parentOID^.DotNotation='0') or (parentOID^.DotNotation='1')) and
-
 
528
                ((Length(arcval)>2) or (StrToInt(arcval) > 39)) then
497
      begin
529
        begin
498
        ShowMessage('Invalid numeric ID (root 0 and 1 must have sub-arc of 0..39)', 'ERROR', true);
530
          ShowMessage('Invalid numeric ID (root 0 and 1 must have sub-arc of 0..39)', 'ERROR', true);
499
        _Pause;
531
          _Pause;
500
      end
532
        end
501
      else if NumIdAlreadyExisting(parentOID, sInput) then
533
        else if NumIdAlreadyExisting(parentOID, arcval) then
502
      begin
534
        begin
503
        ShowMessage('This numeric ID is already used in this arc', 'ERROR', true);
535
          ShowMessage('This numeric ID is already used in this arc', 'ERROR', true);
504
        _Pause;
536
          _Pause;
505
      end
537
        end
506
      else
538
        else
507
      begin
539
        begin
508
        if parentOID^.DotNotation = '' then
540
          if parentOID^.DotNotation = '' then
509
          oid^.DotNotation := sInput
541
            oid^.DotNotation := arcval
510
        else
542
          else
511
          oid^.DotNotation := parentOID^.DotNotation + '.' + sInput;
543
            oid^.DotNotation := parentOID^.DotNotation + '.' + arcval;
512
        NumIdEditor := true; (* request caller to save <oid> *)
544
          NumIdEditor := true; (* request caller to save <oid> *)
513
        Break;
545
          Break;
514
      end;
546
        end;
-
 
547
      end;
515
    end
548
    end
516
    else
549
    else
517
    begin
550
    begin
-
 
551
      (* User pressed ESC *)
518
      Break;
552
      Break;
519
    end;
553
    end;
520
  until false;
554
  until false;
521
  CursorOff;
555
  CursorOff;
522
end;
556
end;
Line 761... Line 795...
761
 
795
 
762
    (* Print OID information *)
796
    (* Print OID information *)
763
 
797
 
764
    ClrScr;
798
    ClrScr;
765
    _DrawOidTitleBar(filename, oid);
799
    _DrawOidTitleBar(filename, oid);
766
    DrawStatusBar(DEFAULT_STATUSBAR);
800
    DrawStatusBar('');
767
    GotoXY(1,2);
801
    GotoXY(1,2);
768
 
802
 
769
    (*if oid^.DotNotation <> '' then*)
-
 
770
    begin
-
 
771
      Write('Dot notation:   ');
803
    Write('Dot notation:   ');
772
      WriteLnKeepX(DotNotation(oid));
804
    WriteLnKeepX(DotNotation(oid));
773
      Write('IRI notation:   ');
-
 
774
      WriteLnKeepX(IriNotation(oid));
-
 
775
      Write('ASN.1 notation: ');
805
    Write('ASN.1 notation: ');
776
      WriteLnKeepX(AsnNotation(oid));
806
    WriteLnKeepX(AsnNotation(oid));
-
 
807
    Write('OID-IRI:        ');
-
 
808
    WriteLnKeepX(IriNotation(oid));
777
      Write('WEID notation:  ');
809
    Write('WEID notation:  ');
778
      WriteLnKeepX(WeidNotation(oid));
810
    WriteLnKeepX(WeidNotation(oid));
779
      WriteLn('');
811
    WriteLn('');
780
    end;
-
 
781
 
812
 
782
    if Trim(oid^.Description) <> '' then
813
    if Trim(oid^.Description) <> '' then
783
    begin
814
    begin
784
      (* WriteLn('Description:'); *)
815
      (* WriteLn('Description:'); *)
785
      WriteLn(oid^.Description);
816
      WriteLn(oid^.Description);
Line 876... Line 907...
876
    end
907
    end
877
    else menuIdAsnEdit := -99;
908
    else menuIdAsnEdit := -99;
878
 
909
 
879
    if oid^.DotNotation <> '' then
910
    if oid^.DotNotation <> '' then
880
    begin
911
    begin
881
      menuIdIriEdit := ListAppend(subsel, 'View/Edit Unicode Labels');
912
      menuIdIriEdit := ListAppend(subsel, 'View/Edit Unicode Labels (OID-IRI)');
882
      ListAppend(subfiles, '');
913
      ListAppend(subfiles, '');
883
    end
914
    end
884
    else menuIdIriEdit := -99;
915
    else menuIdIriEdit := -99;
885
 
916
 
886
    menuIdDescEdit := ListAppend(subsel, 'Edit description');
917
    menuIdDescEdit := ListAppend(subsel, 'Edit description');
Line 1126... Line 1157...
1126
  ListLoadFromFile(list, TREEVIEW_FILENAME);
1157
  ListLoadFromFile(list, TREEVIEW_FILENAME);
1127
  DrawSelectionList(2, 3, ScreenWidth-2, ScreenHeight-4,
1158
  DrawSelectionList(2, 3, ScreenWidth-2, ScreenHeight-4,
1128
                    list, true, 'PREVIEW OF '+TREEVIEW_FILENAME, 2);
1159
                    list, true, 'PREVIEW OF '+TREEVIEW_FILENAME, 2);
1129
  (* TODO: Jump to selected OID *)
1160
  (* TODO: Jump to selected OID *)
1130
 
1161
 
1131
  DrawStatusBar(DEFAULT_STATUSBAR);
1162
  DrawStatusBar('');
1132
 
1163
 
1133
  FreeList(list);
1164
  FreeList(list);
1134
end;
1165
end;
1135
 
1166
 
1136
procedure OP_TreeView;
1167
procedure OP_TreeView;
Line 1146... Line 1177...
1146
 
1177
 
1147
  (* This will try creating a new root file if it does not exist *)
1178
  (* This will try creating a new root file if it does not exist *)
1148
  rootfile := _GetRootFile(true);
1179
  rootfile := _GetRootFile(true);
1149
  if rootfile = '' then
1180
  if rootfile = '' then
1150
  begin
1181
  begin
1151
    DrawStatusBar(DEFAULT_STATUSBAR);
1182
    DrawStatusBar('');
1152
    Exit;
1183
    Exit;
1153
  end;
1184
  end;
1154
 
1185
 
1155
  Assign(F, TREEVIEW_FILENAME);
1186
  Assign(F, TREEVIEW_FILENAME);
1156
  {$I-}
1187
  {$I-}
Line 1159... Line 1190...
1159
  if IoResult <> 0 then
1190
  if IoResult <> 0 then
1160
  begin
1191
  begin
1161
    (* Can happen if disk is read-only (Runtime Error 150) *)
1192
    (* Can happen if disk is read-only (Runtime Error 150) *)
1162
    ShowMessage('Cannot open '+TREEVIEW_FILENAME+' for writing.', 'ERROR', true);
1193
    ShowMessage('Cannot open '+TREEVIEW_FILENAME+' for writing.', 'ERROR', true);
1163
    _Pause;
1194
    _Pause;
1164
    DrawStatusBar(DEFAULT_STATUSBAR);
1195
    DrawStatusBar('');
1165
    Exit;
1196
    Exit;
1166
  end;
1197
  end;
1167
 
1198
 
1168
  res := false;
1199
  res := false;
1169
  CreateOidDef(rootoid);
1200
  CreateOidDef(rootoid);
Line 1174... Line 1205...
1174
  end;
1205
  end;
1175
  FreeOidDef(rootoid);
1206
  FreeOidDef(rootoid);
1176
 
1207
 
1177
  Close(F);
1208
  Close(F);
1178
 
1209
 
1179
  DrawStatusBar(DEFAULT_STATUSBAR);
1210
  DrawStatusBar('');
1180
  if res then
1211
  if res then
1181
  begin
1212
  begin
1182
    ShowMessage('TreeView successfully exported as '+TREEVIEW_FILENAME, 'TREEVIEW EXPORT', true);
1213
    ShowMessage('TreeView successfully exported as '+TREEVIEW_FILENAME, 'TREEVIEW EXPORT', true);
1183
    _Pause;
1214
    _Pause;
1184
  end;
1215
  end;
Line 1194... Line 1225...
1194
begin
1225
begin
1195
  repeat
1226
  repeat
1196
    ClrScr;
1227
    ClrScr;
1197
 
1228
 
1198
    DrawTitleBar('Welcome to OIDplus for DOS', '', '');
1229
    DrawTitleBar('Welcome to OIDplus for DOS', '', '');
1199
    DrawStatusBar(DEFAULT_STATUSBAR);
1230
    DrawStatusBar('(C)2020-2022 ViaThinkSoft. Licensed under the terms of the Apache 2.0 license.');
1200
    GoToXY(ScreenWidth-Length(VERSIONINFO), ScreenHeight-1);
1231
    GoToXY(ScreenWidth-Length(VERSIONINFO), ScreenHeight-1);
1201
    Write(VERSIONINFO);
1232
    Write(VERSIONINFO);
1202
 
1233
 
1203
    CreateList(menu);
1234
    CreateList(menu);
1204
 
1235