Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 742 → Rev 743

/trunk_dos/OIDFILE.PAS
28,8 → 28,8
procedure CreateOidDef(var oid: POid);
procedure FreeOidDef(oid: POid);
procedure ClearOidDef(oid: POid);
procedure WriteOidFile(filename: string; oid: POid);
procedure ReadOidFile(filename: string; oid: POid);
function WriteOidFile(filename: string; oid: POid): boolean;
function ReadOidFile(filename: string; oid: POid): boolean;
 
(* For the fields "SubIds" and "Parent" *)
function FileIdPart(s: string): string;
94,7 → 94,7
end;
end;
 
procedure WriteOidFile(filename: string; oid: POid);
function WriteOidFile(filename: string; oid: POid): boolean;
var
f: Text;
i: integer;
103,7 → 103,16
desc: string;
begin
Assign(f, filename);
 
{$I-}
Rewrite(f);
{$I+}
if IoResult <> 0 then
begin
WriteOidFile := false;
(* Must not call Close(f) if file was never opened *)
Exit;
end;
 
WriteLn(f, 'VERS' + WANT_VERS);
 
140,9 → 149,11
end;
 
Close(f);
 
WriteOidFile := true;
end;
 
procedure ReadOidFile(filename: string; oid: POid);
function ReadOidFile(filename: string; oid: POid): boolean;
var
f: Text;
line, cmd: string;
152,7 → 163,16
version := '';
 
Assign(f, filename);
{$I-}
Reset(f);
{$I+}
if IoResult <> 0 then
begin
ReadOidFile := false;
(* Must not call Close(f) if file was never opened *)
Exit;
end;
 
while not EOF(f) do
begin
ReadLn(f, line);
206,6 → 226,8
end;
 
Close(f);
 
ReadOidFile := true;
end;
 
function FileIdPart(s: string): string;
/trunk_dos/OIDPLUS.EXE
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk_dos/OIDPLUS.PAS
37,11 → 37,24
TREEVIEW_INCLUDE_DESC = true;
TREEVIEW_WIDTH = 80;
 
procedure _WriteOidFile(filename: string; oid: POid);
procedure _Pause;
var
bakX, bakY: integer;
begin
bakX := WhereX;
bakY := WhereY;
DrawStatusBar('Press any key to continue');
GoToXY(bakX, bakY);
ReadKey;
DrawStatusBar(DEFAULT_STATUSBAR);
end;
 
function _WriteOidFile(filename: string; oid: POid; ShowErrorMessage: boolean): boolean;
var
res: boolean;
begin
DrawStatusBar('Write file ' + filename + '...');
WriteOidFile(filename, oid);
 
res := WriteOidFile(filename, oid);
if DISKIO_SOUND_DEBUGGING then
begin
Sound(70);
49,15 → 62,23
NoSound;
Delay(10);
end;
DrawStatusBar(DEFAULT_STATUSBAR);
 
DrawStatusBar(DEFAULT_STATUSBAR);
_WriteOidFile := res;
 
if ShowErrorMessage and not res then
begin
ShowMessage('Cannot write to file ' + filename, 'ERROR', true);
_Pause;
end;
end;
 
procedure _ReadOidFile(filename: string; oid: POid);
function _ReadOidFile(filename: string; oid: POid; ShowErrorMessage: boolean): boolean;
var
res: boolean;
begin
DrawStatusBar('Read file ' + filename + '...');
ReadOidFile(filename, oid);
 
res := ReadOidFile(filename, oid);
if DISKIO_SOUND_DEBUGGING then
begin
Sound(50);
65,21 → 86,16
NoSound;
Delay(10);
end;
 
DrawStatusBar(DEFAULT_STATUSBAR);
end;
 
procedure _Pause;
var
bakX, bakY: integer;
_ReadOidFile := res;
 
if ShowErrorMessage and not res then
begin
bakX := WhereX;
bakY := WhereY;
DrawStatusBar('Press any key to continue');
GoToXY(bakX, bakY);
ReadKey;
DrawStatusBar(DEFAULT_STATUSBAR);
ShowMessage('Cannot read file ' + filename, 'ERROR', true);
_Pause;
end;
end;
 
function _ShowASNIds(childOID: POID): string;
var
374,12 → 390,13
DescEditor(newOID) then
begin
newfilename := newOID^.FileId + '.OID';
_WriteOidFile(newfilename, newOID);
 
if _WriteOidFile(newfilename, newOID, true) then
begin
(* Add link to original file and enable the saving of it *)
ListAppend(oid^.SubIds, newOID^.FileId + newOID^.DotNotation);
NewOidEditor := true; (* request caller to save <oid> *)
end;
end;
FreeOidDef(newOID);
end;
 
395,8 → 412,10
if FileExists(filenameChild) then
begin
CreateOidDef(childOID);
_ReadOidFile(filenameChild, childOID);
if _ReadOidFile(filenameChild, childOID, false) then
begin
DeleteChildrenRecursive(childOID);
end;
FreeOidDef(childOID);
DeleteFile(filenameChild);
end;
414,15 → 433,18
DeleteChildrenRecursive(selfOID);
 
(* Remove forward reference in parent OID *)
(* (this is the most important part) *)
filenameParent := FileIdPart(selfOID^.Parent) + '.OID';
if FileExists(filenameParent) then
begin
CreateOidDef(parentOID);
_ReadOidFile(filenameParent, parentOID);
if _ReadOidFile(filenameParent, parentOID, true) then
begin
if ListDeleteElementByValue(parentOID^.SubIds, selfOID^.FileId + selfOID^.DotNotation) then
begin
_WriteOidFile(filenameParent, parentOID);
_WriteOidFile(filenameParent, parentOID, true);
end;
end;
FreeOidDef(parentOID);
end;
 
485,16 → 507,14
begin
exitRequest := false;
repeat
if not FileExists(filename) then
CreateOidDef(oid);
 
if not _ReadOidFile(filename, oid, true) then
begin
ShowMessage('File ' + filename + ' not found', 'ERROR', true);
_Pause;
FreeOidDef(oid);
exit;
end;
 
CreateOidDef(oid);
_ReadOidFile(filename, oid);
 
(* Print OID information *)
 
ClrScr;
568,8 → 588,10
if FileExists(subfile) then
begin
CreateOidDef(tmpOID);
_ReadOidFile(subfile, tmpOID);
ListAppend(subsel, 'Go to parent ' + DotNotationPart(sTmp) + _ShowASNIds(tmpOID));
if _ReadOidFile(subfile, tmpOID, true) then
ListAppend(subsel, 'Go to parent ' + DotNotationPart(sTmp) + _ShowASNIds(tmpOID))
else
ListAppend(subsel, 'Go to parent ' + DotNotationPart(sTmp) + ' (READ ERROR)');
FreeOidDef(tmpOID);
end
else
593,8 → 615,10
if FileExists(subfile) then
begin
CreateOidDef(tmpOID);
_ReadOidFile(subfile, tmpOID);
ListAppend(subsel, 'Go to child ' + DotNotationPart(sTmp) + _ShowASNIds(tmpOID));
if _ReadOidFile(subfile, tmpOID, true) then
ListAppend(subsel, 'Go to child ' + DotNotationPart(sTmp) + _ShowASNIds(tmpOID))
else
ListAppend(subsel, 'Go to child ' + DotNotationPart(sTmp) + ' (READ ERROR)');
FreeOidDef(tmpOID);
end
else
643,17 → 667,17
else if subselres = menuIdAsnEdit then
begin
if AsnEditor(oid) then
_WriteOidFile(filename, oid);
_WriteOidFile(filename, oid, true);
end
else if subselres = menuIdDescEdit then
begin
if DescEditor(oid) then
_WriteOidFile(filename, oid);
_WriteOidFile(filename, oid, true);
end
else if subselres = menuIdAdd then
begin
if NewOidEditor(oid) then
_WriteOidFile(filename, oid);
_WriteOidFile(filename, oid, true);
end
else if subselres = menuIdDelete then
begin
667,7 → 691,7
end
else
begin
ShowMessage('Parent file ' + filename + ' not found', 'ERROR', true);
ShowMessage('Parent file ' + sTmp + ' not found', 'ERROR', true);
_Pause;
exitRequest := true;
end;
687,7 → 711,7
end
else
begin
ShowMessage('File ' + filename + ' not found', 'ERROR', true);
ShowMessage('File ' + sTmp + ' not found', 'ERROR', true);
_Pause;
end;
end;
698,7 → 722,7
until exitRequest;
end;
 
procedure CreateRootOIDFile(filename: string);
function CreateRootOIDFile(filename: string; ShowErrorMessage: boolean): boolean;
var
oid: POID;
begin
712,7 → 736,7
oid^.FileId := ZeroPad(0, 8);
oid^.DotNotation := '';
oid^.Parent := ZeroPad(0, 8);
_WriteOidFile(filename, oid);
CreateRootOIDFile := _WriteOidFile(filename, oid, ShowErrorMessage);
FreeOidDef(oid);
end;
 
721,24 → 745,13
rootFile: string;
begin
rootFile := ZeroPad(0, 8) + '.OID';
_GetRootFile := rootFile;
if not FileExists(rootFile) then
begin
{$I-}
CreateRootOIDFile(rootFile);
{$I+}
end;
if not FileExists(rootFile) then
if not CreateRootOIDFile(rootFile, ShowErrorMessage) then
begin
_GetRootFile := '';
if ShowErrorMessage then
begin
ShowMessage('Cannot create ' + rootfile + '! Is disk read-only?', 'ERROR', true);
_Pause;
end;
end
else
begin
_GetRootFile := rootFile;
end;
end;
 
769,8 → 782,10
procedure OP_ReturnToMSDOS;
begin
ClrScr;
TextBackground(Black);
TextColor(LightGray);
WriteLn('Thank you for using OIDplus for DOS.');
WRiteLn('');
WriteLn('');
end;
 
function _GetTreeViewLine(oid: POID; indent: integer): string;
820,20 → 835,25
sTmp := ListGetElement(oid^.SubIds, i);
CreateOidDef(suboid);
childFilename := FileIdPart(sTmp) + '.OID';
if FileExists(childFilename) then
if not FileExists(childFilename) then
begin
_ReadOidFile(childFilename, suboid);
_RecTreeExport(suboid, F, indent+1);
FreeOidDef(suboid);
sTmp := 'ERROR: ' + childFilename + ' FILE MISSING (CONTAINS ' + DotNotationPart(sTmp) + ')!';
sTmp := TrimLineToWidth(sTmp, TREEVIEW_WIDTH);
WriteLn(F, sTmp);
end
else
else if not _ReadOidFile(childFilename, suboid, false) then
begin
sTmp := 'ERROR: FILE ' + childFilename + ' CONTAINING CHILD OID ' + DotNotationPart(sTmp) + ' WAS NOT FOUND!';
sTmp := 'ERROR: ' + childFilename + ' READ ERROR (CONTAINS ' + DotNotationPart(sTmp) + ')!';
sTmp := TrimLineToWidth(sTmp, TREEVIEW_WIDTH);
WriteLn(F, sTmp);
end
else
begin
_RecTreeExport(suboid, F, indent+1);
FreeOidDef(suboid);
end
end;
end;
end;
 
procedure OP_TreeView;
var
840,6 → 860,7
F: Text;
rootoid: POID;
rootfile: string;
res: boolean;
begin
ClrScr;
DrawTitleBar('TreeView Export', TITLEBAR_LEFT_TEXT, '');
846,23 → 867,44
DrawStatusBar('Exporting data... please wait...');
 
(* This will try creating a new root file if it does not exist *)
rootfile := _GetRootFile(true);;
if rootfile = '' then Exit;
rootfile := _GetRootFile(true);
if rootfile = '' then
begin
DrawStatusBar(DEFAULT_STATUSBAR);
Exit;
end;
 
Assign(F, 'OIDTREE.TXT');
{$I-}
Rewrite(F);
{$I+}
if IoResult <> 0 then
begin
(* Can happen if disk is read-only (Runtime Error 150) *)
ShowMessage('Cannot open OIDTREE.TXT for writing.', 'ERROR', true);
_Pause;
DrawStatusBar(DEFAULT_STATUSBAR);
Exit;
end;
 
res := false;
CreateOidDef(rootoid);
_ReadOidFile(rootfile, rootoid);
if _ReadOidFile(rootfile, rootoid, true) then
begin
_RecTreeExport(rootoid, F, 0);
res := true;
end;
FreeOidDef(rootoid);
 
Close(F);
 
DrawStatusBar(DEFAULT_STATUSBAR);
if res then
begin
ShowMessage('TreeView successfully exported as OIDTREE.TXT', 'TREEVIEW EXPORT', true);
_Pause;
 
Close(F);
end;
end;
 
procedure OP_MainMenu;
var