Subversion Repositories oidplus

Rev

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

Rev 744 Rev 745
Line 1... Line 1...
1
unit OIDFILE;
1
unit OIDFILE;
2
 
2
 
3
(************************************************)
3
(************************************************)
4
(* OIDFILE.PAS                                  *)
4
(* OIDFILE.PAS                                  *)
5
(* Author:   Daniel Marschall                   *)
5
(* Author:   Daniel Marschall                   *)
6
(* Revision: 2022-02-14                         *)
6
(* Revision: 2022-02-15                         *)
7
(* License:  Apache 2.0                         *)
7
(* License:  Apache 2.0                         *)
8
(* This file contains:                          *)
8
(* This file contains:                          *)
9
(* - Functions to handle an OID ASCII format    *)
9
(* - Functions to handle an OID ASCII format    *)
10
(************************************************)
10
(************************************************)
11
 
11
 
Line 19... Line 19...
19
  TOID = record
19
  TOID = record
20
    FileId: string;
20
    FileId: string;
21
    DotNotation: string;
21
    DotNotation: string;
22
    ASNIds: PStringList;
22
    ASNIds: PStringList;
23
    Description: string;
23
    Description: string;
24
    SubIds: PStringList; (* first 8 chars are FileId, followed by Dot-Notation *)
24
    SubIds: PStringList; (* first 8 chars are FileId, followed by DotNotation *)
-
 
25
    ParentFileId: string;
25
    Parent: string; (* First 8 chars are FileId, followed by Dot-Notation *)
26
    ParentDotNotation: string;
26
  end;
27
  end;
27
 
28
 
28
procedure CreateOidDef(var oid: POid);
29
procedure CreateOidDef(var oid: POid);
29
procedure FreeOidDef(oid: POid);
30
procedure FreeOidDef(oid: POid);
30
procedure ClearOidDef(oid: POid);
31
procedure ClearOidDef(oid: POid);
31
function WriteOidFile(filename: string; oid: POid): boolean;
32
function WriteOidFile(filename: string; oid: POid): boolean;
32
function ReadOidFile(filename: string; oid: POid): boolean;
33
function ReadOidFile(filename: string; oid: POid): boolean;
33
 
34
 
34
(* For the fields "SubIds" and "Parent" *)
35
(* For the strings in the list "SubIds": *)
35
function FileIdPart(s: string): string;
36
function FileIdPart(s: string): string;
36
function DotNotationPart(s: string): string;
37
function DotNotationPart(s: string): string;
37
 
38
 
38
implementation
39
implementation
39
 
40
 
Line 47... Line 48...
47
begin
48
begin
48
  GetMem(oid, SizeOf(TOID));
49
  GetMem(oid, SizeOf(TOID));
49
  oid^.FileId := '';
50
  oid^.FileId := '';
50
  oid^.DotNotation := '';
51
  oid^.DotNotation := '';
51
  oid^.Description := '';
52
  oid^.Description := '';
52
  oid^.Parent := '';
53
  oid^.ParentFileId := '';
-
 
54
  oid^.ParentDotNotation := '';
53
  CreateList(oid^.ASNIds);
55
  CreateList(oid^.ASNIds);
54
  CreateList(oid^.SubIds);
56
  CreateList(oid^.SubIds);
55
end;
57
end;
56
 
58
 
57
procedure FreeOidDef(oid: POid);
59
procedure FreeOidDef(oid: POid);
Line 61... Line 63...
61
  FreeMem(oid, SizeOf(TOID));
63
  FreeMem(oid, SizeOf(TOID));
62
end;
64
end;
63
 
65
 
64
procedure ClearOidDef(oid: POid);
66
procedure ClearOidDef(oid: POid);
65
begin
67
begin
-
 
68
  oid^.FileId := '';
-
 
69
  oid^.DotNotation := '';
-
 
70
  oid^.Description := '';
-
 
71
  oid^.ParentFileId := '';
-
 
72
  oid^.ParentDotNotation := '';
66
  FreeOidDef(oid);
73
  ListClear(oid^.ASNIds);
67
  CreateOidDef(oid);
74
  ListClear(oid^.SubIds);
68
end;
75
end;
69
 
76
 
70
procedure ListBubbleSortSubIds(oid: POid);
77
procedure ListBubbleSortSubIds(oid: POid);
71
var
78
var
72
  n, i: integer;
79
  n, i: integer;
Line 116... Line 123...
116
 
123
 
117
  WriteLn(f, 'VERS' + WANT_VERS);
124
  WriteLn(f, 'VERS' + WANT_VERS);
118
 
125
 
119
  WriteLn(f, 'SELF' + oid^.FileId + oid^.DotNotation);
126
  WriteLn(f, 'SELF' + oid^.FileId + oid^.DotNotation);
120
 
127
 
121
  WriteLn(f, 'SUPR' + oid^.Parent);
128
  WriteLn(f, 'SUPR' + oid^.ParentFileId + oid^.ParentDotNotation);
122
 
129
 
123
  (* Sort sub IDs *)
130
  (* Sort sub IDs *)
124
  ListBubbleSortSubIds(oid);
131
  ListBubbleSortSubIds(oid);
125
 
132
 
126
  for i := 0 to ListCount(oid^.SubIds)-1 do
133
  for i := 0 to ListCount(oid^.SubIds)-1 do
Line 191... Line 198...
191
      oid^.DotNotation := line;
198
      oid^.DotNotation := line;
192
    end;
199
    end;
193
 
200
 
194
    if cmd = 'SUPR' then
201
    if cmd = 'SUPR' then
195
    begin
202
    begin
196
      oid^.Parent := line;
203
      oid^.ParentFileId := FileIdPart(line);
-
 
204
      oid^.ParentDotNotation := DotNotationPart(line);
197
    end;
205
    end;
198
 
206
 
199
    if cmd = 'CHLD' then
207
    if cmd = 'CHLD' then
200
    begin
208
    begin
201
      ListAppend(oid^.SubIds, line);
209
      ListAppend(oid^.SubIds, line);