Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 735 → Rev 734

/trunk_dos/OIDPLUS.PAS
20,10 → 20,6
ASNEDIT_LINES = 10;
DESCEDIT_LINES = 10;
DESCEDIT_PADDING = 3;
ACTIONMENU_SIZE = 5;
MAINMENU_WIDTH = 15;
MAINMENU_HEIGHT = 3;
MAINMENU_ALLOW_ESC = false;
 
procedure _WriteOidFile(filename: string; oid: POid);
begin
71,24 → 67,24
 
function _ShowASNIds(subfile: string): string;
var
childOID: POID;
coid: TOID;
j, jmax: integer;
sTmp: string;
begin
sTmp := '';
CreateOidDef(childOID);
_ReadOidFile(subfile, childOID);
jmax := ListCount(childOID^.ASNIds)-1;
InitOidDef(@coid);
_ReadOidFile(subfile, @coid);
jmax := ListCount(coid.ASNIds)-1;
for j := 0 to jmax do
begin
if j = 0 then sTmp := sTmp + ' (';
sTmp := sTmp + ListGetElement(childOID^.ASNIds, j);
sTmp := sTmp + ListGetElement(coid.ASNIds, j);
if j = jmax then
sTmp := sTmp + ')'
else
sTmp := sTmp + ', ';
end;
FreeOidDef(childOID);
FreeOidDef(@coid);
_ShowASNIds := sTmp;
end;
 
116,20 → 112,19
x, y, w, h: integer;
res: integer;
sInput: string;
menuIdNew, menuIdSave, menuIdExit: integer;
begin
AsnEditor := false;
 
repeat
CreateList(asnList);
InitList(asnList);
 
for i := 0 to ListCount(oid^.ASNIds)-1 do
begin
ListAppend(asnList, ListGetElement(oid^.ASNIDs, i));
end;
menuIdNew := ListAppend(asnList, '<NEW>');
menuIdSave := ListAppend(asnList, '<SAVE>');
menuIdExit := ListAppend(asnList, '<CANCEL>');
ListAppend(asnList, '<NEW>');
ListAppend(asnList, '<SAVE>');
ListAppend(asnList, '<CANCEL>');
 
DrawStatusBar(DEFAULT_STATUSBAR);
x := SINGLE_LINE_BOX_PADDING;
140,7 → 135,6
asnList, true,
'EDIT ASN.1 IDENTIFIERS',
2);
FreeList(asnList);
 
(* Change double-border to thin-border *)
DrawThinBorder(x-1, y-1, w+2, h+2);
151,7 → 145,7
begin
exit;
end
else if res = menuIdNew then
else if res = ListCount(oid^.ASNIDs) then
begin
(* "NEW" item was selected *)
sInput := '';
184,13 → 178,13
else break;
until false;
end
else if res = menuIdSave then
else if res = ListCount(oid^.ASNIDs)+1 then
begin
(* "SAVE" item was selected *)
AsnEditor := true;
Exit;
end
else if res = menuIdExit then
else if res = ListCount(oid^.ASNIDs)+2 then
begin
(* "CANCEL" item was selected *)
AsnEditor := false;
267,7 → 261,7
sId: string;
begin
(* Put all found files into a list *)
CreateList(list);
InitList(list);
FindFirst('????????.OID', Archive, DirInfo);
while DosError = 0 do
begin
300,7 → 294,8
for i := 0 to ListCount(parentOID^.SubIds)-1 do
begin
sTmp := ListGetElement(parentOID^.SubIds, i);
if DotNotationPart(sTmp) = searchDotNotation then
Delete(sTmp, 1, 8);
if sTmp = searchDotNotation then
begin
NumIdAlreadyExisting := true;
exit;
366,40 → 361,40
function NewOidEditor(oid: POID): boolean;
var
newfilename: string;
newOID: POID;
newoid: TOID;
begin
NewOidEditor := false;
 
CreateOidDef(newOID);
newOID^.FileId := NextPossibleFileID;
newOID^.Parent := oid^.FileId + oid^.DotNotation;
if NumIdEditor(newOID, oid) and
AsnEditor(newOID) and
DescEditor(newOID) then
InitOidDef(@newoid);
newoid.FileId := NextPossibleFileID;
newoid.Parent := oid^.FileId + oid^.DotNotation;
if NumIdEditor(@newoid, oid) and
AsnEditor(@newoid) and
DescEditor(@newoid) then
begin
newfilename := newOID^.FileId + '.OID';
_WriteOidFile(newfilename, newOID);
newfilename := newoid.FileId + '.OID';
_WriteOidFile(newfilename, @newoid);
 
(* Add link to original file and enable the saving of it *)
ListAppend(oid^.SubIds, newOID^.FileId + newOID^.DotNotation);
ListAppend(oid^.SubIds, newoid.FileId + newoid.DotNotation);
NewOidEditor := true; (* request caller to save @oid *)
end;
FreeOidDef(newOID);
FreeOidDef(@newoid);
end;
 
procedure DeleteChildrenRecursive(oid: POID);
var
i: integer;
childOID: POID;
childOID: TOID;
filenameChild: string;
begin
for i := 0 to ListCount(oid^.SubIds)-1 do
begin
filenameChild := FileIdPart(ListGetElement(oid^.SubIds, i)) + '.OID';
CreateOidDef(childOID);
_ReadOidFile(filenameChild, childOID);
DeleteChildrenRecursive(childOID);
FreeOidDef(childOID);
filenameChild := Copy(ListGetElement(oid^.SubIds, i), 1, 8) + '.OID';
InitOidDef(@childOID);
_ReadOidFile(filenameChild, @childOID);
DeleteChildrenRecursive(@childOID);
FreeOidDef(@childOID);
DeleteFile(filenameChild);
end;
ListClear(oid^.SubIds);
408,29 → 403,27
procedure DeleteOidRecursive(selfOID: POID);
var
i: integer;
parentOID: POID;
parentOID: TOID;
filenameSelf, filenameParent: string;
fileIdToDelete: string;
sTmp: string;
begin
(* Remove all children and their files recursively *)
DeleteChildrenRecursive(selfOID);
 
(* Remove forward reference in parent OID *)
filenameParent := FileIdPart(selfOID^.Parent) + '.OID';
CreateOidDef(parentOID);
_ReadOidFile(filenameParent, parentOID);
for i := 0 to ListCount(parentOID^.SubIds)-1 do
filenameParent := Copy(selfOID^.Parent, 1, 8)+'.OID';
InitOidDef(@parentOID);
_ReadOidFile(filenameParent, @parentOID);
for i := 0 to ListCount(parentOID.SubIds)-1 do
begin
sTmp := ListGetElement(parentOID^.SubIds, i);
if FileIdPart(sTmp) = selfOID^.FileId then
if Copy(ListGetElement(parentOID.SubIds, i), 1, 8) = selfOID^.FileId then
begin
ListDeleteElement(parentOID^.SubIds, i);
_WriteOidFile(filenameParent, parentOID);
ListDeleteElement(parentOID.SubIds, i);
_WriteOidFile(filenameParent, @parentOID);
break;
end;
end;
FreeOidDef(parentOID);
FreeOidDef(@parentOID);
 
(* Delete own file *)
fileIdToDelete := selfOID^.FileId;
438,61 → 431,39
DeleteFile(filenameSelf);
end;
 
function _DeleteConfirmation: boolean;
var
sc: Char;
begin
repeat
ShowMessage('Are you sure you want to delete this OID? (Y/N)', 'DELETE OID', true);
DrawStatusBar('Y = Yes; N = No');
 
sc := ReadKey;
if sc = #0 then
begin
(* Extended key. Nothing we care about. *)
ReadKey;
continue;
end;
 
if UpCase(sc) = 'Y' then
begin
_DeleteConfirmation := true;
break;
end;
 
if UpCase(sc) = 'N' then
begin
_DeleteConfirmation := false;
break;
end;
until false;
end;
 
procedure DisplayOIDFile(filename: string);
const
ID_EXIT = '?EXIT';
ID_ASNEDIT = '?ASN1';
ID_DESCEDIT = '?DESC';
ID_ADDCHILD = '?ADDC';
ID_DELETE = '?DELE';
NAVBAR_SIZE = 5;
var
isRoot: boolean;
oid: POID;
f: Text;
line, cmd: string;
oid: TOID;
i, menuX, menuY: integer;
linesLeft, linesRequired: integer;
sTmp, subfile: string;
sAsn: string;
subsel, subfiles: PStringList;
subselres: integer;
exitRequest: boolean;
menuIdExit, menuIdAsnEdit, menuIdDescEdit, menuIdAdd, menuIdDelete: integer;
sTmp1: string;
begin
exitRequest := false;
repeat
CreateOidDef(oid);
_ReadOidFile(filename, oid);
InitOidDef(@oid);
_ReadOidFile(filename, @oid);
 
(* Print OID information *)
 
ClrScr;
 
if oid^.DotNotation = '' then
if oid.DotNotation = '' then
DrawTitleBar('OID ROOT')
else
DrawTitleBar('OID ' + oid^.DotNotation);
DrawTitleBar('OID ' + oid.DotNotation);
GotoXY(ScreenWidth-Length(filename)+1,1);
TextBackground(White);
TextColor(Black);
502,36 → 473,36
DrawStatusBar(DEFAULT_STATUSBAR);
GotoXY(1,2);
 
if oid^.DotNotation <> '' then
if oid.DotNotation <> '' then
begin
WriteLn('Dot-Notation:');
WriteLn(oid^.DotNotation);
WriteLn(oid.DotNotation);
WriteLn('');
end;
 
if Trim(oid^.Description) <> '' then
if Trim(oid.Description) <> '' then
begin
WriteLn('Description:');
WriteLn(oid^.Description);
WriteLn(oid.Description);
WriteLn('');
end;
 
menuX := WhereX + 1;
menuY := ScreenHeight - ACTIONMENU_SIZE - 1;
menuY := ScreenHeight - NAVBAR_SIZE - 1;
 
if ListCount(oid^.ASNIDs) > 0 then
if ListCount(oid.ASNIDs) > 0 then
begin
linesLeft := menuY - WhereY - 1;
linesRequired := 1 + ListCount(oid^.ASNIds);
linesRequired := 1 + ListCount(oid.ASNIds);
 
if LinesLeft < LinesRequired then
begin
(* Compact display of ASN.1 identifiers *)
Write('ASN.1-Identifiers: ');
for i := 0 to ListCount(oid^.ASNIds)-1 do
for i := 0 to ListCount(oid.ASNIds)-1 do
begin
if i > 0 then Write(', ');
Write(ListGetElement(oid^.ASNIds, i));
Write(ListGetElement(oid.ASNIds, i));
end;
WriteLn('');
end
539,9 → 510,9
begin
(* Long display of ASN.1 identifiers *)
WriteLn('ASN.1-Identifiers:');
for i := 0 to ListCount(oid^.ASNIds)-1 do
for i := 0 to ListCount(oid.ASNIds)-1 do
begin
WriteLn('- '+ListGetElement(oid^.ASNIds, i));
WriteLn('- '+ListGetElement(oid.ASNIds, i));
end;
WriteLn('');
end;
549,66 → 520,69
 
(* Now prepare the menu entries *)
 
CreateList(subsel);
CreateList(subfiles);
InitList(subsel);
InitList(subfiles);
 
if oid^.Parent = '' then
sTmp := oid.Parent;
if sTmp = '' then
begin
isRoot := true;
end
else
begin
isRoot := DotNotationPart(oid^.Parent) = oid^.DotNotation;
Delete(sTmp, 1, 8);
isRoot := sTmp = oid.DotNotation;
end;
 
if (oid^.Parent <> '') and not isRoot then
if (oid.Parent <> '') and not isRoot then
begin
sTmp := oid^.Parent;
subfile := FileIdPart(sTmp) + '.OID';
ListAppend(subsel, 'Go to parent ' + DotNotationPart(sTmp) + _ShowASNIds(subfile));
sTmp := oid.Parent;
subfile := Copy(sTmp, 1, 8)+'.OID';
Delete(sTmp, 1, 8);
sTmp := sTmp + _ShowASNIds(subfile);
ListAppend(subsel, 'Go to parent ' + sTmp);
ListAppend(subfiles, subfile);
end;
 
if isRoot then
begin
menuIdExit := ListAppend(subsel, 'Back to main menu');
ListAppend(subfiles, '');
end
else menuIdExit := -99;
ListAppend(subsel, 'Back to main menu');
ListAppend(subfiles, ID_EXIT);
end;
 
for i := 0 to ListCount(oid^.SubIds)-1 do
for i := 0 to ListCount(oid.SubIds)-1 do
begin
sTmp := ListGetElement(oid^.SubIds, i);
subfile := FileIdPart(sTmp) + '.OID';
ListAppend(subsel, 'Go to child ' + DotNotationPart(sTmp) + _ShowASNIds(subfile));
sTmp := ListGetElement(oid.SubIds, i);
subfile := Copy(sTmp, 1, 8)+'.OID';
Delete(sTmp, 1, 8);
sTmp := sTmp + _ShowASNIds(subfile);
ListAppend(subsel, 'Go to child ' + sTmp);
ListAppend(subfiles, subfile);
end;
 
if oid^.DotNotation <> '' then
if oid.DotNotation <> '' then
begin
menuIdAsnEdit := ListAppend(subsel, 'Edit ASN.1 identifiers');
ListAppend(subfiles, '');
end
else menuIdAsnEdit := -99;
ListAppend(subsel, 'Edit ASN.1 identifiers');
ListAppend(subfiles, ID_ASNEDIT);
end;
 
menuIdDescEdit := ListAppend(subsel, 'Edit description');
ListAppend(subfiles, '');
ListAppend(subsel, 'Edit description');
ListAppend(subfiles, ID_DESCEDIT);
 
menuIdAdd := ListAppend(subsel, 'Add child');
ListAppend(subfiles, '');
ListAppend(subsel, 'Add child');
ListAppend(subfiles, ID_ADDCHILD);
 
if not isRoot then
begin
menuIdDelete := ListAppend(subsel, 'Delete OID');
ListAppend(subfiles, '');
end
else menuIdDelete := -99;
ListAppend(subsel, 'Delete OID');
ListAppend(subfiles, ID_DELETE);
end;
 
(* Show menu *)
 
subselres := DrawSelectionList(menuX, menuY,
ScreenWidth-2,
ACTIONMENU_SIZE,
NAVBAR_SIZE,
subsel,
true,
'SELECT ACTION',
618,79 → 592,83
 
if subselres = -1 then
begin
exitRequest := true;
exit;
end
else if subselres = menuIdAsnEdit then
else
begin
if AsnEditor(oid) then
_WriteOidFile(filename, oid);
sTmp1 := ListGetElement(subfiles, subselres);
if sTmp1 = ID_ASNEDIT then
begin
if AsnEditor(@oid) then
_WriteOidFile(filename, @oid);
end
else if subselres = menuIdDescEdit then
else if sTmp1 = ID_DESCEDIT then
begin
if DescEditor(oid) then
_WriteOidFile(filename, oid);
if DescEditor(@oid) then
_WriteOidFile(filename, @oid);
end
else if subselres = menuIdAdd then
else if sTmp1 = ID_ADDCHILD then
begin
if NewOidEditor(oid) then
_WriteOidFile(filename, oid);
if NewOidEditor(@oid) then
begin
_WriteOidFile(filename, @oid);
end;
end
else if subselres = menuIdDelete then
else if sTmp1 = ID_DELETE then
begin
if _DeleteConfirmation then
ShowMessage('Are you sure you want to delete this OID?', 'DELETE OID', true);
DrawStatusBar('Y = Yes; any other key = No');
if UpCase(ReadKey) = 'Y' then
begin
filename := FileIdPart(oid^.Parent) + '.OID';
DeleteOidRecursive(oid);
filename := Copy(oid.Parent,1,8)+'.OID';
DeleteOidRecursive(@oid);
end;
end
else if subselres = menuIdExit then
else if sTmp1 = ID_EXIT then
begin
exitRequest := true;
exit;
end
else
begin
(* Normal OID *)
filename := ListGetElement(subfiles, subselres);
filename := sTmp1;
end;
end;
FreeList(subsel);
FreeList(subfiles);
 
FreeOidDef(oid);
until exitRequest;
FreeOidDef(@oid);
until false;
end;
 
procedure CreateInitOIDFile(filename: string);
var
oid: POID;
oid: TOID;
begin
CreateOidDef(oid);
oid^.Description := 'This is the root of the OID tree.' +#13#10 +
InitOidDef(@oid);
oid.Description := 'This is the root of the OID tree.' +#13#10 +
#13#10 +
'Valid subsequent arcs are per definition:' + #13#10 +
'- 0 (itu-t)' + #13#10 +
'- 1 (iso)' + #13#10 +
'- 2 (joint-iso-itu-t)';
oid^.FileId := '00000000';
oid^.DotNotation := '';
oid^.Parent := '00000000';
_WriteOidFile(filename, oid);
FreeOidDef(oid);
oid.FileId := '00000000';
oid.DotNotation := '';
oid.Parent := '00000000';
_WriteOidFile(filename, @oid);
FreeOidDef(@oid);
end;
 
procedure OP_ManageOIDs;
var
initFile: string;
begin
ClrScr;
DrawTitleBar('Manage Object Identifiers');
DrawStatusBar('');
 
initFile := ZeroPad(0, 8) + '.OID';
if not FileExists(initFile) then
if not FileExists('00000000.OID') then
begin
CreateInitOIDFile(initFile);
CreateInitOIDFile('00000000.OID');
end;
DisplayOIDFile(initFile);
DisplayOIDFile('00000000.OID');
end;
 
procedure OP_ManageRAs;
700,6 → 678,8
DrawStatusBar('');
 
(* TODO: Implement "Manage RAs" feature *)
ShowMessage('This feature has not yet been implemented!', 'NOTICE', true);
_Pause;
end;
 
procedure OP_ReturnToMSDOS;
708,10 → 688,12
end;
 
procedure OP_MainMenu;
const
MenuWidth = 15;
MenuHeight = 3;
var
menu: PStringList;
menuRes, menuLeft, menuTop: integer;
menuIdOID, menuIdRA, menuIdExit: integer;
begin
repeat
ClrScr;
721,28 → 703,25
GoToXY(ScreenWidth-Length(VERSIONINFO), ScreenHeight-1);
Write(VERSIONINFO);
 
CreateList(menu);
 
menuIdOID := ListAppend(menu, 'Manage OIDs');
menuIdRA := -99; (*ListAppend(menu, 'Manage RAs');*)
menuIdExit := ListAppend(menu, 'Return to DOS');
 
menuLeft := round(ScreenWidth/2 -MAINMENU_WIDTH/2);
menuTop := round(ScreenHeight/2-MAINMENU_HEIGHT/2);
menuRes := DrawSelectionList(menuLeft, menuTop,
MAINMENU_WIDTH, MAINMENU_HEIGHT,
menu, true, 'MAIN MENU', 2);
InitList(menu);
ListAppend(menu, 'Manage OIDs');
ListAppend(menu, 'Manage RAs');
ListAppend(menu, 'Return to DOS');
menuLeft := round(ScreenWidth/2 -MenuWidth/2);
menuTop := round(ScreenHeight/2-MenuHeight/2);
menuRes := DrawSelectionList(menuLeft, menuTop, MenuWidth, MenuHeight, menu, true, 'MAIN MENU', 2);
FreeList(menu);
 
if menuRes = menuIdOID then
if menuRes = 0 then
begin
OP_ManageOIDs;
end
else if menuRes = menuIdRA then
end;
 
if menuRes = 1 then
begin
OP_ManageRAs;
end;
until (menuRes = menuIdExit) or (MAINMENU_ALLOW_ESC and (menuRes = -1));
until (menuRes = 2) or (menuRes = -1);
 
OP_ReturnToMSDOS;
end;