Subversion Repositories oidplus

Rev

Rev 733 | Rev 735 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
733 daniel-mar 1
unit OIDFILE;
2
 
3
(************************************************)
4
(* OIDFILE.PAS                                  *)
5
(* Author:   Daniel Marschall                   *)
734 daniel-mar 6
(* Revision: 2022-02-14                         *)
733 daniel-mar 7
(* License:  Apache 2.0                         *)
8
(* This file contains:                          *)
9
(* - Functions to handle an OID ASCII format    *)
10
(************************************************)
11
 
12
interface
13
 
14
uses
15
  StrList;
16
 
17
type
18
  POID = ^TOID;
19
  TOID = record
20
    FileId: string;
21
    DotNotation: string;
22
    ASNIds: PStringList;
23
    Description: string;
734 daniel-mar 24
    SubIds: PStringList; (* first 8 chars are FileId, followed by Dot-Notation *)
25
    Parent: string; (* First 8 chars are FileId, followed by Dot-Notation *)
733 daniel-mar 26
  end;
27
 
734 daniel-mar 28
procedure InitOidDef(oid: POid);
733 daniel-mar 29
procedure FreeOidDef(oid: POid);
734 daniel-mar 30
procedure ClearOidDef(oid: POid);
733 daniel-mar 31
procedure WriteOidFile(filename: string; oid: POid);
32
procedure ReadOidFile(filename: string; oid: POid);
33
 
34
implementation
35
 
36
uses
37
  VtsFuncs;
38
 
39
const
40
  WANT_VERS = '2022';
41
 
734 daniel-mar 42
procedure InitOidDef(oid: POid);
43
begin
44
  oid^.FileId := '';
45
  oid^.DotNotation := '';
46
  oid^.Description := '';
47
  oid^.Parent := '';
48
  InitList(oid^.ASNIds);
49
  InitList(oid^.SubIds);
50
end;
51
 
733 daniel-mar 52
procedure FreeOidDef(oid: POid);
53
begin
54
  FreeList(oid^.ASNIds);
55
  FreeList(oid^.SubIds);
56
end;
57
 
734 daniel-mar 58
procedure ClearOidDef(oid: POid);
59
begin
60
  FreeOidDef(oid);
61
  InitOidDef(oid);
62
end;
63
 
733 daniel-mar 64
procedure WriteOidFile(filename: string; oid: POid);
65
var
66
  f: Text;
67
  i: integer;
68
  lines: PStringList;
69
  sTmp: string;
70
  desc: string;
71
begin
72
  Assign(f, filename);
73
  Rewrite(f);
74
 
75
  WriteLn(f,'VERS' + WANT_VERS);
76
 
77
  WriteLn(f,'SELF' + oid^.FileId + oid^.DotNotation);
78
 
79
  WriteLn(f,'SUPR' + oid^.Parent);
80
 
81
  for i := 0 to ListCount(oid^.SubIds)-1 do
82
  begin
83
    sTmp := ListGetElement(oid^.SubIds, i);
84
    WriteLn(f, 'CHLD' + sTmp);
85
  end;
86
 
87
  for i := 0 to ListCount(oid^.AsnIds)-1 do
88
  begin
89
    sTmp := ListGetElement(oid^.AsnIds, i);
90
    WriteLn(f, 'ASN1' + sTmp);
91
  end;
92
 
93
  desc := Trim(oid^.Description);
94
  if desc <> '' then
95
  begin
96
    InitList(lines);
97
    SplitStrToList(desc, lines, #13#10);
98
    for i := 0 to ListCount(lines)-1 do
99
    begin
100
      sTmp := ListGetElement(lines, i);
101
      WriteLn(f, 'DESC' + sTmp);
102
    end;
103
    FreeList(lines);
104
  end;
105
 
106
  Close(f);
107
end;
108
 
109
procedure ReadOidFile(filename: string; oid: POid);
110
var
111
  f: Text;
112
  line, cmd: string;
113
  version: string;
114
begin
734 daniel-mar 115
  ClearOidDef(oid);
733 daniel-mar 116
  version := '';
117
 
118
  Assign(f, filename);
119
  Reset(f);
120
  while not EOF(f) do
121
  begin
122
    ReadLn(f, line);
123
    cmd := Copy(line,1,4);
124
    Delete(line,1,4);
125
 
126
    if cmd = 'VERS' then
127
    begin
128
      version := line;
129
    end;
130
 
131
    if cmd = 'SELF' then
132
    begin
133
      oid^.FileId := Copy(line,1,8);
134
      Delete(line,1,8);
135
      oid^.DotNotation := line;
136
    end;
137
 
138
    if cmd = 'SUPR' then
139
    begin
140
      oid^.Parent := line;
141
    end;
142
 
143
    if cmd = 'CHLD' then
144
    begin
145
      ListAppend(oid^.SubIds, line);
146
    end;
147
 
148
    if cmd = 'ASN1' then
149
    begin
150
      ListAppend(oid^.ASNIds, line);
151
    end;
152
 
153
    if cmd = 'DESC' then
154
    begin
155
      oid^.Description := oid^.Description + line + #13#10;
156
    end;
157
  end;
158
 
159
  (* Remove last CRLF *)
160
  oid^.Description := Copy(oid^.Description, 1, Length(oid^.Description)-Length(#13#10));
161
 
162
  (* Check if something is not correct *)
163
  if (version <> WANT_VERS) or (oid^.FileId = '') then
164
  begin
165
    (* Invalidate everything *)
734 daniel-mar 166
    ClearOidDef(oid);
733 daniel-mar 167
  end;
168
 
169
  Close(f);
170
end;
171
 
172
end.