home *** CD-ROM | disk | FTP | other *** search
- {$I-,O+}
- Unit LibFile;
-
- Interface
-
- Uses Dos,StrTool,GEDDEFS,LIBACCES;
-
- Function Insert_in_Dir(Var Eintrag:Dir_Entry;Var Verz:Dir_Table):Word;
- { 0 , wenn DIR voll, sonst INDEX des Eintrags }
-
- Function Remove_From_Dir(Var Eintrag:Dir_Entry;Var Verz:Dir_Table):Word;
- { 0 , wenn nicht gefunden , sonst Index des entfernten Eintrags }
-
- Function Init_Lib(Libfile:PathStr):Boolean;
- { True, wenn Ok, schließ Datei wieder }
-
- Function Packen_Empfohlen(Var DIR:Dir_Table):Boolean;
-
- Function Packe_LIB(Var LibFile :PathStr;Var Verz:Dir_Buffer):Boolean;
-
- Function Append_Macro(LibFile,Macro:PathStr;SymName:NameStr):Word;
- { 0 :Ok, Sonst Fehler
- 1 : Fehler bei Directory-Zugriff oder LIBFile nicht gefunden or Wrong File-Version
- 2 : Fehler bei Schreiben
- 4 : Fehler beim lesen des Macros
- 6 : Fehler beim lesen wie beim Schreiben
- 8 : Fehler beim Packen}
-
- Function Append_Macro_uni(Source,Dest:PathStr;SymName:NameStr;
- FileDate,Offset:Longint;Count:Word):Word;
-
- implementation
-
-
- Function Insert_in_Dir(Var Eintrag:Dir_Entry;Var Verz:Dir_Table):Word;
- Var Ins_Idx:Word;
- begin
- Insert_In_Dir:=0;
- UpStr(Eintrag.MacroName);
- Ins_Idx:=Find_In_Dir(Eintrag.MacroName,Verz);
- If Ins_Idx >0 then
- begin
- With Verz[0] do
- begin
- Inc(UsedBLDRecs,Eintrag.NrofRecs);
- Dec(UsedBLDRecs,Verz[Ins_Idx].NrofRecs);
- Inc(TotalSize,Eintrag.NrofRecs);
- end;
- Verz[Ins_idx]:=Eintrag;
- end
- else
- begin
- If Verz[0].NrofDirEntries>=Max_Lib_Size then Exit;
- Ins_Idx:=1;
- While (Ins_Idx<=Verz[0].NrofDirEntries) and
- (Eintrag.MacroName>Verz[Ins_Idx].Macroname) Do Inc(Ins_idx);
- Inc(Verz[0].NrOfDirEntries);
- Move(Verz[Ins_Idx],Verz[Ins_Idx+1],(Verz[0].NrofDirEntries-Ins_Idx) *Sizeof(Dir_Entry));
- Verz[Ins_Idx]:=Eintrag;
- With Verz[0] do
- begin
- Inc(UsedBLDRecs,Eintrag.NrofRecs);
- Inc(TotalSize,Eintrag.NrofRecs);
- end;
- end;
- Insert_In_Dir:=Ins_Idx;
- end;
-
- Function Remove_From_Dir(Var Eintrag:Dir_Entry;Var Verz:Dir_Table):Word;
- Var Ins_Idx:Word;
- begin
- Remove_From_Dir:=0;
- UpStr(Eintrag.MacroName);
- Ins_Idx:=Find_In_Dir(Eintrag.MacroName,Verz);
- If Ins_Idx >0 then
- begin
- Dec(Verz[0].UsedBLDRecs,Verz[Ins_Idx].NrOfRecs);
- Move(Verz[Ins_Idx+1],Verz[Ins_Idx],(Verz[0].NrofDirEntries-Ins_Idx) *Sizeof(Dir_Entry));
- FillChar(Verz[Verz[0].NrofDirEntries],Sizeof(Dir_Entry),0);
- Dec(Verz[0].NrofDirEntries);
- Remove_From_Dir:=Ins_Idx;
- end;
- end;
-
- Function Init_Lib(Libfile:PathStr):Boolean;
- Var LibF :File;
- Verz :Dir_Buffer;
- begin
- Init_Lib:=false;
- Inc(No_Blink);
- Assign(LibF,LibFile);
- Rewrite(LibF,Sizeof(Bildelement));
- Dec(No_Blink);
- If Ioresult<>0 then begin CloseF(LibF);Exit; end;
- Fillchar(Verz,Sizeof(Verz),0);
- With Verz.DIR[0] Do FILEID:=LIB_FILEID;
- If NOT PUT_DIR_BUFF(LIBF,Verz) then Exit;
- CloseF(LibF);
- Init_Lib:=True;
- end;
-
- Function Packen_Empfohlen(Var DIR:Dir_Table):Boolean;
- Const Slack = 1.5;
- begin
- With DIR[0] do
- Packen_Empfohlen:=(TotalSize>1000) and (Round(UsedBLDRecs*Slack)<TotalSize);
- end;
-
- Function _Packe_LIB(Var LibFile :PathStr;Var Verz:Dir_Buffer):Boolean;
- Var Infile,TempFile:File;
- TempName:PathStr;
- P_Orig :PathStr;
- N_Orig :NameStr;
- E_Orig :ExtStr;
- BLD :Bildelement;
- Dummy,
- I,J :Word;
-
- Procedure Quit;
- begin
- CloseF(Infile);
- CloseF(TempFile);
- Erase(Tempfile);
- If Ioresult=0 then Exit;
- end;
-
- Function Error:Boolean;
- begin
- Error:=False;
- If Ioresult=0 then Exit;
- Error:=True;
- Quit;
- end;
-
- begin
- _Packe_Lib:=false;
- Fsplit(LibFile,P_Orig,N_Orig,E_Orig);
- TempName:=RandomFileName(P_Orig,'.LIB');
- Assign(Infile,LibFile);
- If Not(Get_Dir_Buff(InFile,Verz)) then Exit;
- If Not Init_Lib(TempName) then Exit;
- Assign(TempFile,TempName);
- Reset(TempFile,Sizeof(Bildelement));
- If Error then Exit;
- Seek(TempFile,FileSize(TempFile));
- If Error then Exit;
- Verz.Dir[0].UsedBLDRecs:=0;
- For I:= 1 to Verz.DIR[0].NrOfDirEntries Do
- With Verz.DIR[I] do
- begin
- Seek(Infile,FileOffset);
- If Error then Exit;
- FileOffset:=FileSize(TempFile);
- If Error then Exit;
- Inc(Verz.Dir[0].UsedBLDRecs,NrofRecs);
- For J:= 1 to NrOfRecs Do
- begin
- BlockRead(Infile,Bld,1);
- If Error then Exit;
- BlockWrite(TempFile,Bld,1);
- If Error then Exit;
- end;
- end;
- Verz.Dir[0].TotalSize:=Verz.Dir[0].UsedBLDRecs;
- If Not Put_Dir_Buff(TempFile,Verz) then begin Quit; Exit end;
- CloseF(InFile);
- Rename(Infile,RandomFilename(P_Orig,'.LI$'));
- Dummy:=IoResult;
- CloseF(TempFile);
- Rename(TempFile,P_Orig+N_Orig+E_Orig);
- If Ioresult=0 then
- begin
- Erase(Infile);
- Dummy:=IOresult;
- end
- else
- begin
- Rename(Infile,P_Orig+N_Orig+E_Orig);
- Dummy:=Ioresult;
- Erase(TempFile);
- Dummy:=Ioresult;
- Exit;
- end;
- _Packe_Lib:=True;
- end;
-
- Function Packe_LIB(Var LibFile :PathStr;Var Verz:Dir_Buffer):Boolean;
- begin
- Inc(No_blink);
- Packe_LIB:=_Packe_LIB(LibFile,Verz);
- Dec(No_Blink);
- end;
-
- Function Append_Macro_LIB(Var LibFile,Macro:PathStr;Var SymName:NameStr;
- Date,Offset:Longint;Count:Word):Word;
- Var LibF,MacFile :File;
- Verz :Dir_Buffer;
- P :PathStr;
- N :NameStr;
- E :ExtStr;
- WritePos:Longint;
- Eintrag :Dir_Entry;
- Ok_In:Boolean;
- Ok_out:Boolean;
- Dummy :Word;
- BLD :Bildelement;
- Nr :Word;
- SrcVers:Word;
-
- begin
- Append_Macro_LIB:=1;
- Assign(LibF,LibFile);
- If Not(Get_Dir_Buff(LibF,Verz)) then Exit;
- WritePos:=Filesize(LibF);
- Fillchar(Eintrag,Sizeof(Eintrag),0);
- Eintrag.FileOffset:=WritePos;
- Seek(LibF,WritePos);
- Ok_Out:=Ioresult=0;
- If Ok_Out then
- begin
- Assign(MacFile,Macro);
- Reset(MacFile,Sizeof(Bildelement));
- Ok_In:=Ioresult=0;
- Seek(Macfile,Offset);
- Ok_In:=Ok_In and (Ioresult=0);
- Eintrag.NrOfRecs:=0;
- While Ok_In and Ok_Out
- and Not(Eof(Macfile))
- and (Eintrag.NrofRecs<Count) do
- begin
- BlockRead(MacFile,BLD,1);
- Ok_In:=Ioresult=0;
- If Eintrag.NrOfRecs=0 then
- begin
- SrcVers:=Defaults(BLD).GEDVersion;
- FitVersionCode(SrcVers);
- Defaults(BLD).GEDVersion:=VersionCode;
- end else Update_Obj(BLD,SrcVers);
- If Ok_In then
- begin
- BlockWrite(LibF,BLD,1);
- Ok_Out:=Ioresult=0;
- Inc(Eintrag.NrOfRecs);
- end;
- end;
- If Date<>0 then
- Eintrag.Date:=Date
- else
- GetFTime(MacFile,Eintrag.Date);
- Close(MacFile);
- Dummy:=Ioresult;
- If SymName='' then
- Fsplit(Macro,P,Eintrag.MacroName,E)
- else
- Eintrag.MacroName:=SymName;
- If Ok_In and Ok_Out then
- If Insert_In_Dir(Eintrag,Verz.DIR)>0 then
- Ok_Out:=Put_Dir_Buff(LibF,Verz);
- end;
- Close(LibF);
- Ok_Out:=Ok_Out and (Ioresult=0);
- Append_Macro_LIB:=0;
- If Not(Ok_Out) then Append_Macro_LIB:=2;
- If Not(Ok_In) then Append_Macro_LIB:=4;
- If Not(Ok_In or Ok_Out) then Append_Macro_LIB:=6;
- If Ok_In and Ok_Out and Packen_Empfohlen(Verz.DIR) then
- If Not Packe_LIB(Libfile,Verz) then Append_Macro_LIB:=8;
- end;
-
- Function Append_Macro(LibFile,Macro:PathStr;SymName:NameStr):Word;
- begin
- Inc(No_blink);
- Append_Macro:=Append_Macro_LIB(LibFile,Macro,SymName,0,0,$FFFF);
- Dec(No_blink);
- end;
-
- Function Append_Macro_uni(Source,Dest:PathStr;SymName:NameStr;
- FileDate,Offset:Longint;Count:Word):Word;
- begin
- Inc(No_blink);
- Append_Macro_uni:=Append_Macro_LIB(Dest,Source,SymName,FileDate,Offset,Count);
- Dec(No_blink);
- end;
-
-
- end.
-