Subversion Repositories oidplus

Rev

Rev 734 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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