Source file: /~heha/hsn/WdxInfoPacker64.zip/LineProcessing.pas

{$D-,L-,O+,Q-,R-,Y-,S-}
unit LineProcessing;
interface
uses Inifiles,Windows,SysUtils,Controls,Classes,somestuff,
{dialogs,}
strutils, RegExpr,
WdxStruc;
type TFileProp=record
   SubPath,SrcPath,pnextname:string;
   currentFile,nbofplug:cardinal;
   strReplace:boolean;
   strReplaceValue:string;
end;
type TOneLine=Class
private
LineValue:array[0..1024] of char;
PlugWanted:boolean;
resultat:array[0..6*1024] of char;
public
ContPLugDefIni:array[0..260]of char;
procedure SetLineValue(NewValue:pchar);
procedure SetResultat(NewValue:pchar);
procedure SetPlugWanted(NewValue:boolean);
function GetLineValue:pchar;
function GetResult:pchar;
function GetLimitedResult(delimiter:string):string;
procedure GetSeparateValue(Value:TstringList);
function GetAllValueForLine(FileInfop:TFileProp;PathToini:pchar;var Error:boolean;MaxRigh:cardinal;AllWdx:Array of TWdxInfo;isDir:boolean):pchar;
function GetSimpleValue(LinePart,SubPath,SrcPath,FileToOpen:pchar;currentNb:cardinal):pchar;
function GetSimpleValueForDir(LinePart,SubPath,SrcPath,FileToOpen:pchar;currentNb:cardinal):pchar;
function GetHeaderOrFooter(SrcPath,DestName:pchar):pchar;
function GetSeparator:pchar;
procedure GetModulePartValue(Plugin,Field,Unite:pchar;fileinfo:TFileprop;MaxRigh:cardinal;var AllWdxInfo:array of TWdxInfo);overload;
procedure GetModulePartValueForDir(Plugin,Field,Unite:pchar;fileinfo:TFileprop;MaxRigh:cardinal;var AllWdxInfo:array of TWdxInfo);overload;
end;
 function isValidInfo(list:tstringlist):boolean;
implementation
function TOneLine.GetLineValue:pchar;
begin
result:=LineValue;
end;

function TOneLine.GetResult:pchar;
begin
result:=Resultat;
end;
function TOneLine.GetLimitedResult(delimiter:string):string;
var
L1:TStringList;
i,j,k,l:cardinal;
begin
 L1:=TStringList.Create;
 Split('-',delimiter,L1);
 l:=L1.Count;
 i:=0;
 j:=0;
 for k:=0 to l-1 do begin
  if ((L1[k]='') and (k=0)) then i:=0;
  if ((L1[k]='') and (k=1)) then j:=strlen(Resultat);
  if ((L1[k]<>'') and (k=0)) then i:=strtoint(L1[k]);
  if ((L1[k]<>'') and (k=1)) then j:=strtoint(L1[k]);
 end;
 if i<>0 then l:=j-i +1
 else l:=j-i;
 L1.Free;
 result:=copy(string(trim(Resultat)),i,l);
end;

procedure TOneLine.SetResultat(NewValue:pchar);
begin
fillchar(Resultat,sizeof(Resultat),#0);
strlcopy(Resultat,NewValue,sizeof(Resultat)-1);
end;

procedure TOneLine.SetLineValue(NewValue:pchar);
begin
fillchar(LineValue,sizeof(LineValue),#0);
strlcopy(LineValue,NewValue,sizeof(LineValue)-1);
end;

procedure TOneLine.SetPlugWanted(NewValue:boolean);
begin
PlugWanted:=NewValue;
end;

procedure TOneLine.GetSeparateValue(Value:TstringList);
var Linein:string;
begin
Linein:=StringReplace(LineValue,' ', '_',[rfReplaceAll, rfIgnoreCase]);
Split(';',Linein,Value);
end;

function TOneLine.GetAllValueForLine(FileInfop:TFileProp;PathToini:pchar;var Error:boolean;MaxRigh:cardinal;AllWdx:Array of TWdxInfo;isDir:boolean):pchar;
var outbuf,outTest:array[0..1024] of char;
Linein:string;
Part,Moddetail,Fieldetail,truePos:TstringList;
PluginToFind,FieldToFind,UnitToFind:string;
strToGet:string;
i,n:cardinal;
s,s1:string;
//test:boolean;
tmp,getLimitedRange,isInField:boolean;
begin
 Error:=false;
 tmp:=false;
 getLimitedRange:=false;
 isInField:=false;
 fillchar(outbuf,sizeof(outbuf),#0);
 fillchar(outTest,sizeof(outTest),#0);
 if (pos('@Mod=',LineValue)<>0) then begin //IF Users wants a wdx information
 //Split different part with/without wanted wdx information
 Part:=TStringList.Create;
 Linein:=StringReplace(LineValue,'@Mod=', '',[rfReplaceAll, rfIgnoreCase]);
 Linein:=StringReplace(Linein,'/IFE/', '',[rfReplaceAll, rfIgnoreCase]);
 Linein:=StringReplace(Linein,'_', '1_1',[rfReplaceAll, rfIgnoreCase]);
 SetLineValue(pchar(Linein));
 GetSeparateValue(Part);
 //for every part
 n:=Part.Count-1;
 for i:=0 to n do begin
  if Part[i]<>'' then begin
   if pos('@',Part[i])<>0 then begin //Split element (field, unit, plugin name)
    Moddetail:=TStringList.Create;
    Split('@',Part[i],Moddetail);
    PluginToFind:=Moddetail[1];
    if pos('.',Moddetail[0])<>0 then begin
     Fieldetail:=TStringList.Create;
     Split('.',Moddetail[0],Fieldetail);
     Fieldetail[0]:=StringReplace(Fieldetail[0],'_', ' ',[rfReplaceAll, rfIgnoreCase]);
     FieldToFind:=Fieldetail[0];
     Fieldetail[1]:=StringReplace(Fieldetail[1],'_', ' ',[rfReplaceAll, rfIgnoreCase]);
     UnitToFind:=Fieldetail[1];
    end else begin
     Moddetail[0]:=StringReplace(Moddetail[0],'_', ' ',[rfReplaceAll, rfIgnoreCase]);
     FieldToFind:=Moddetail[0];
     UnitToFind:=inttostr(0);
    end;
    if (((UnitToFind<>'0') and(pos(':',UnitToFind)<>0) and ExecRegExpr ('\d+[^\.]', UnitToFind)) or ((FieldToFind<>'0') and(pos(':',FieldToFind)<>0) and ExecRegExpr ('\d+[^\.]', FieldToFind))) then begin
     if UnitToFind ='0' then isInField:=true;
     getLimitedRange:=true;
     truePos:=TStringList.create;
     if isInField then begin
      Split(':',FieldToFind,truePos);
      FieldToFind:=truePos[0];
     end else begin
      Split(':',UnitToFind,truePos);
      UnitToFind:=truePos[0];
     end;
     strToGet:=truePos[1];
     truePos.Free;
    end;
    //Call the function to retrieve wdx info
    if isDir =false then GetModulePartValue(pchar(PluginToFind),pchar(FieldToFind),pchar(UnitToFind),fileInfop,MaxRigh,AllWdx)
    else  GetModulePartValueForDir(pchar(PluginToFind),pchar(FieldToFind),pchar(UnitToFind),fileInfop,MaxRigh,AllWdx);
    //To Test current and global wdx result
    if (getLimitedRange=true) then begin
     strlcat(outbuf,pchar(GetLimitedResult(strToGet)),sizeof(outbuf)-1);
     strlcat(outTest,pchar(GetLimitedResult(strToGet)),sizeof(outTest)-1);
    end else begin
     strlcat(outbuf,GetResult,sizeof(outbuf)-1);
     strlcat(outTest,GetResult,sizeof(outTest)-1);
    end;
    tmp:=true; //there was at least a wdx info wanted
    end else begin
     if ((Pos('[',Part[i])=1) and (Pos(']:',Part[i])<>0)) then begin
      getLimitedRange:=true;
      strToGet:=MidStr(Part[i],Pos(']:',string(Part[i]))+2,strlen(pchar(Part[i]))-Pos(']:',string(Part[i]))-1);
      Part[i]:=MidStr(Part[i],2,strlen(pchar(Part[i]))-Pos(']:',string(Part[i]))-strlen(pchar(strToGet))+1);
     end;
     Part[i]:=StringReplace(Part[i],'1_1', 'a@a',[rfReplaceAll, rfIgnoreCase]);
     Part[i]:=StringReplace(Part[i],'_', ' ',[rfReplaceAll, rfIgnoreCase]);
     Part[i]:=StringReplace(Part[i],'a@a', '_',[rfReplaceAll, rfIgnoreCase]);
     //Get simple value (no wdx info)
     if (getLimitedRange = true) then begin
     if (isDir=false) then begin
      s1:=GetSimpleValue(pchar(Part[i]),pchar(FileInfop.Subpath),pchar(FileInfop.SrcPath),pchar(FileInfop.pnextname),FileInfop.currentFile);
      SetResultat(pchar(s1));
      strlcat(outbuf,pchar(GetLimitedResult(strToGet)),sizeof(outbuf)-1);
      getLimitedRange:=false;
     end else begin
      s1:=GetSimpleValueForDir(pchar(Part[i]),pchar(FileInfop.Subpath),pchar(FileInfop.SrcPath),pchar(  FileInfop.pnextname),FileInfop.currentFile);
      SetResultat(pchar(s1));
      strlcat(outbuf,pchar(GetLimitedResult(strToGet)),sizeof(outbuf)-1);
      getLimitedRange:=false;
     end;
     end else begin
      if (isDir=false) then strlcat(outbuf,GetSimpleValue(pchar(Part[i]),pchar(FileInfop.Subpath),pchar(FileInfop.SrcPath),pchar(  FileInfop.pnextname),FileInfop.currentFile),sizeof(outbuf)-1)
      else strlcat(outbuf,GetSimpleValueForDir(pchar(Part[i]),pchar(FileInfop.Subpath),pchar(FileInfop.SrcPath),pchar(  FileInfop.pnextname),FileInfop.currentFile),sizeof(outbuf)-1);
     end;
     end;
    end;
   end;
  end else begin
  if ((Pos('[',LineValue)=1) and (Pos(']:',LineValue)<>0)) then begin
   getLimitedRange:=true;
   strToGet:=MidStr(LineValue,Pos(']:',string(LineValue))+2,strlen(LineValue)-Pos(']:',string(LineValue))-1);
   s1:=MidStr(LineValue,2,strlen(LineValue)-Pos(']:',string(LineValue))-strlen(pchar(strToGet))+1);
   SetLineValue(pchar(s1));
  end;
  //Get simple value (no wdx info)
  if (getLimitedRange = true) then begin
   if (isDir=false)then begin
    s1:=GetSimpleValue(LineValue,pchar(FileInfop.Subpath),pchar(FileInfop.SrcPath),pchar(FileInfop.pnextname),FileInfop.currentFile);
    SetResultat(pchar(s1));
    strlcat(outbuf,pchar(GetLimitedResult(strToGet)),sizeof(outbuf)-1);
//    getLimitedRange:=false;
   end else  begin
    s1:=GetSimpleValueForDir(LineValue,pchar(FileInfop.Subpath),pchar(FileInfop.SrcPath),pchar(FileInfop.pnextname),FileInfop.currentFile);
    SetResultat(pchar(s1));
    strlcat(outbuf,pchar(GetLimitedResult(strToGet)),sizeof(outbuf)-1);
  //  getLimitedRange:=false;
   end;
  end else begin
   if (isDir=false)then strlcat(outbuf,GetSimpleValue(LineValue,pchar(FileInfop.Subpath),pchar(FileInfop.SrcPath),pchar(FileInfop.pnextname),FileInfop.currentFile),sizeof(outbuf)-1)
   else  strlcat(outbuf,GetSimpleValueForDir(LineValue,pchar(FileInfop.Subpath),pchar(FileInfop.SrcPath),pchar(FileInfop.pnextname),FileInfop.currentFile),sizeof(outbuf)-1);
  end;
  end;
  if tmp=true then begin
   s:=outTest;
   if length(s)=0 then Error:=true;
  end;

  result:=outbuf;
end;
procedure TOneLine.GetModulePartValue(Plugin,Field,Unite:pchar;fileinfo:TFileprop;MaxRigh:cardinal;var AllWdxInfo:array of TWdxInfo);
var i,plug2use:cardinal;
right,RemoveCR,forcestrReplace:boolean;
fullname:array[0..259] of char;
outbuf:array[0..1024] of char;
outright:array[0..50]of char;
s,s1:string;
s2:array[0..1024] of char;
List:tstringlist;
char1,char2:string;
begin
 plug2use:=0;
 fillchar(outbuf,sizeof(outbuf),#0);
 fillchar(outright,sizeof(outright),#0);
 strlcopy(fullname,pchar(fileinfo.SrcPath),sizeof(fullname)-1);
 strlcat(fullname,pchar(fileinfo.pnextname),sizeof(fullname)-1);
 right:=false;
 RemoveCR:=false;
 forcestrReplace:=false;
 s:=Plugin;
 if pos('->R',Plugin)<>0 then begin//Do we have a wanted right align wdx info
  s:=StringReplace(Plugin,'->R', '',[rfReplaceAll, rfIgnoreCase]);
  right:=true;
 end;
 if pos('->B',Plugin)<>0 then begin//Do we have a wanted right align wdx info
  if right then s:=StringReplace(s,'->B', '',[rfReplaceAll, rfIgnoreCase])
  else s:=StringReplace(Plugin,'->B', '',[rfReplaceAll, rfIgnoreCase]);
  RemoveCR:=true;
 end;
 if pos('->F',Plugin)<>0 then begin//Do we have a wanted right align wdx info
  forcestrReplace:=true;
  s:=StringReplace(Plugin,'->F', '',[rfReplaceAll, rfIgnoreCase])
 end;
 if fileinfo.nbofplug>0 then begin
  for i:=0 to fileinfo.nbofplug-1 do begin
   if (UpperCase(AllWdxInfo[i].Name)=UpperCase(s)) then begin
    plug2use:=i;
   end;
  end;
 end;
 if (AllWdxInfo[plug2use].CanBeUsed=true) then begin
  if ( AllWdxInfo[plug2use].isInit = false ) then AllWdxInfo[plug2use].init;
   FillChar(s2,sizeof(s2),#0);
   s1:=string(AllWdxInfo[plug2use].Get(fullname,Field,unite,false));
   StrLCopy(s2,pchar(s1),sizeof(s2)-1);
   s1:=s2;
   if RemoveCR then  s1:=StringReplace(s1,#13#10,#32,[rfReplaceAll, rfIgnoreCase]);
   if right then begin
    if MaxRigh=0 then MaxRigh:=12;
    if MaxRigh>50 then MaxRigh:=50;
    if length(s1)<MaxRigh then begin
     for i:=0 to MaxRigh-length(s1)-2 do begin
      strlcat(outright,chr(32),sizeof(outright)-1);
     end;
     strlcat(outright,pchar(s1),sizeof(outright)-1);
    end else strlcat(outright,pchar('max length limit reached'),sizeof(outright)-1);
    if length(s1)=0 then outright[0]:=#0;
    SetResultat(outright);
   end else begin
    if ((fileinfo.strReplace) or (forcestrReplace)) then begin
     list:=tstringlist.create;
     Split('|',fileinfo.strReplaceValue,list);
     if (list.Count=2) then begin
      if (isValidInfo(list)) then begin
       char1:=chr(StrToInt(list[0]));
       char2:=chr(StrToInt(list[1]));
       s1:=StringReplace(s1,char1,char2,[rfReplaceAll, rfIgnoreCase]);
      end else s1:='Error in the ascii values';
      strlcopy(outbuf,pchar(s1),sizeof(outbuf)-1);
     end else StrLCopy(outbuf,s2,sizeof(outbuf)-1);
     list.free;
    end else StrLCopy(outbuf,s2,sizeof(outbuf)-1);
    SetResultat(outbuf);
   end;
  end else begin
   SetResultat(pchar('the wanted plugin is missing'));
  end;
end;

procedure TOneLine.GetModulePartValueForDir(Plugin,Field,Unite:pchar;fileinfo:TFileprop;MaxRigh:cardinal;var AllWdxInfo:array of TWdxInfo);
var i,plug2use:cardinal;
right,RemoveCR,forcestrReplace:boolean;
fullname:array[0..259] of char;
outbuf:array[0..1024] of char;
outright:array[0..50]of char;
s,s1:string;
s2:array[0..1024] of char;
List:tstringlist;
char1,char2:string;
begin
fillchar(outbuf,sizeof(outbuf),#0);
fillchar(outright,sizeof(outright),#0);
strlcopy(fullname,pchar(fileinfo.SrcPath),sizeof(fullname)-1);
strlcat(fullname,pchar(fileinfo.pnextname),sizeof(fullname)-1);
right:=false;
RemoveCR:=false;
forcestrReplace:=false;
s:=Plugin;
plug2use:=0;
if pos('->R',Plugin)<>0 then begin//Do we have a wanted right align wdx info
s:=StringReplace(Plugin,'->R', '',[rfReplaceAll, rfIgnoreCase]);
right:=true;
end;
if pos('->B',Plugin)<>0 then begin//Do we have a wanted right align wdx info
if right then s:=StringReplace(s,'->B', '',[rfReplaceAll, rfIgnoreCase])
else s:=StringReplace(Plugin,'->B', '',[rfReplaceAll, rfIgnoreCase]);
RemoveCR:=true;
end;
if pos('->F',Plugin)<>0 then begin//Do we have a wanted right align wdx info
forcestrReplace:=true;
s:=StringReplace(Plugin,'->F', '',[rfReplaceAll, rfIgnoreCase])
end;
	for i:=0 to fileinfo.nbofplug-1 do begin
		if (UpperCase(AllWdxInfo[i].Name)=UpperCase(s)) then begin
			plug2use:=i;
		end;
	end;
	if (AllWdxInfo[plug2use].CanBeUsed=true) then begin
		if ( AllWdxInfo[plug2use].isInit = false ) then AllWdxInfo[plug2use].init;
		FillChar(s2,sizeof(s2),#0);
		s1:=string(AllWdxInfo[plug2use].Get(fullname,Field,unite,true));
		StrLCopy(s2,pchar(s1),sizeof(s2)-1);
		s1:=s2;
		if RemoveCR then  s1:=StringReplace(s1,#13#10,#32,[rfReplaceAll, rfIgnoreCase]);
		if right then begin
			if MaxRigh=0 then MaxRigh:=12;
			if MaxRigh>50 then MaxRigh:=50;
			if length(s1)<MaxRigh then begin
				for i:=0 to MaxRigh-length(s1)-2 do begin
					strlcat(outright,chr(32),sizeof(outright)-1);
				end;
				strlcat(outright,pchar(s1),sizeof(outright)-1);
      end else strlcat(outright,pchar('max length limit reached'),sizeof(outright)-1);
			if length(s1)=0 then outright[0]:=#0;
			SetResultat(outright);
		end
		else begin
			if ((fileinfo.strReplace) or (forcestrReplace)) then begin
			  list:=tstringlist.create;
			  Split('|',fileinfo.strReplaceValue,list);
			  if (list.Count=2) then begin
				if (isValidInfo(list)) then begin
					char1:=chr(StrToInt(list[0]));
					char2:=chr(StrToInt(list[1]));
					s1:=StringReplace(s1,char1,char2,[rfReplaceAll, rfIgnoreCase]);
				end else s1:='Error in the ascii values';
				strlcopy(outbuf,pchar(s1),sizeof(outbuf)-1);
			  end else StrLCopy(outbuf,s2,sizeof(outbuf)-1);
			  list.free;
			end else StrLCopy(outbuf,s2,sizeof(outbuf)-1);
			SetResultat(outbuf);
		end;
	end else begin
		SetResultat(pchar('the wanted plugin is missing'));
	end;
end;

function TOneLine.GetSimpleValue(LinePart,SubPath,SrcPath,FileToOpen:pchar;currentNb:cardinal):pchar;
var s:tsearchrec;
 p,p2:pchar;
 fullname,shortpathname:array[0..259] of char;
 outbuf:array[0..1024] of char;
 j:cardinal;
 ch:char;
begin
  outbuf[0]:=#0;
  if GetShortPathName(SrcPath,shortpathname,sizeof(shortpathname)-1)=0 then
   strlcopy(shortpathname,SrcPath,sizeof(shortpathname)-1);
   j:=0;
   while j<length(LinePart) do begin
  if LinePart[j]='%' then begin
    case LinePart[j+1] of
   'O':begin  {Name without extension and relative path}
     p:=strrscan(FileToOpen,'\');
     if p<>nil then inc(p)
         else p:=FileToOpen;
     p2:=strrscan(p,'.'); {Only dots in name, not path!}
     if p2<>nil then p2[0]:=#0;
     strlcat(outbuf,p,sizeof(outbuf)-1);
     if p2<>nil then p2[0]:='.';
      end;
   'T':strlcat(outbuf,#9,sizeof(outbuf)-1);
   'n':begin
      strlcopy(fullname,SrcPath,sizeof(outbuf)-1);
      strlcat(fullname,FileToOpen,sizeof(outbuf)-1);
      if FindFirst(fullname,faAnyFile,s)=0 then begin
       if s.finddata.cAlternateFileName[0]<>#0 then strlcat(outbuf,s.finddata.cAlternateFileName,sizeof(outbuf)-1)
       end else begin strlcat(outbuf,FileToOpen,sizeof(outbuf)-1);
       sysutils.FindClose(s);
      end;
      end;
     'N':strlcat(outbuf,FileToOpen,sizeof(outbuf)-1); {Aktuelle Datei (langer Name)}
     'E':begin  {Extension}
      p:=strrscan(FileToOpen,'\');
      if p<>nil then inc(p)
      else p:=FileToOpen;
      p:=strrscan(p,'.'); {Only dots in name, not path!}
      if p<>nil then strlcat(outbuf,p+1,sizeof(outbuf)-1);
    end;
   'M':begin   {Aktuelle Datei ohne rel. Pfad (langer Name)}
      p:=strrscan(FileToOpen,'\');
      if p<>nil then inc(p)
      else p:=FileToOpen;
      strlcat(outbuf,p,sizeof(outbuf)-1);
    end;
   'p':strlcat(outbuf,shortpathname,sizeof(outbuf)-1);
   'P':strlcat(outbuf,SrcPath,sizeof(outbuf)-1);
   'D':begin  {Relative path of file}
      p:=strrscan(FileToOpen,'\');
      if p<>nil then begin
       ch:=p[1];
       p[1]:=#0;
       strlcat(outbuf,FileToOpen,sizeof(outbuf)-1); {Aktuelle Datei (langer Name)}
       p[1]:=ch;
     end;
    end;
   '%':strlcat(outbuf,'%',sizeof(outbuf)-1);
   'L':strlcat(outbuf,#13#10,sizeof(outbuf)-1);
   '#':strlcat(outbuf,';',sizeof(outbuf)-1);
	 ' ':strlcat(outbuf,' ',sizeof(outbuf)-1);
	 'I':strlcat(outbuf,pchar(inttostr(currentNb)),sizeof(outbuf)-1);
    end;
    inc(j);
  end
  else if strlen(outbuf)<sizeof(outbuf)-1 then begin
   p:=strend(outbuf);
   p[0]:=LinePart[j];
   p[1]:=#0;
    end;
  inc(j);
   end;
 result:=outbuf;
 end;


function TOneLine.GetSimpleValueForDir(LinePart,SubPath,SrcPath,FileToOpen:pchar;currentNb:cardinal):pchar;
var s:tsearchrec;
 p,p2:pchar;
 fullname,shortpathname:array[0..259] of char;
 outbuf:array[0..1024] of char;
 j:cardinal;
 ch:char;
begin
  outbuf[0]:=#0;
  if GetShortPathName(SrcPath,shortpathname,sizeof(shortpathname)-1)=0 then
   strlcopy(shortpathname,SrcPath,sizeof(shortpathname)-1);
   j:=0;
   while j<length(LinePart) do begin
  if LinePart[j]='%' then begin
    case LinePart[j+1] of
   'O':begin  {Name without extension and relative path}
     p:=strrscan(FileToOpen,'\');
     if p<>nil then inc(p)
         else p:=FileToOpen;
     p2:=strrscan(p,'.'); {Only dots in name, not path!}
     if p2<>nil then p2[0]:=#0;
     strlcat(outbuf,p,sizeof(outbuf)-1);
     if p2<>nil then p2[0]:='.';
      end;
   'T':strlcat(outbuf,#9,sizeof(outbuf)-1);
   'n':begin
      strlcopy(fullname,SrcPath,sizeof(outbuf)-1);
      strlcat(fullname,FileToOpen,sizeof(outbuf)-1);
      if FindFirst(fullname,faAnyFile,s)=0 then begin
       if s.finddata.cAlternateFileName[0]<>#0 then strlcat(outbuf,s.finddata.cAlternateFileName,sizeof(outbuf)-1)
       end else begin strlcat(outbuf,FileToOpen,sizeof(outbuf)-1);
       sysutils.FindClose(s);
      end;
      end;
     'N':strlcat(outbuf,FileToOpen,sizeof(outbuf)-1); {Aktuelle Datei (langer Name)}
     'E':begin  {Extension}
      p:=strrscan(FileToOpen,'\');
      if p<>nil then inc(p)
      else p:=FileToOpen;
      p:=strrscan(p,'.'); {Only dots in name, not path!}
      if p<>nil then strlcat(outbuf,p+1,sizeof(outbuf)-1);
    end;
   'M':begin   {Aktuelle Datei ohne rel. Pfad (langer Name)}
      p:=strrscan(FileToOpen,'\');
      if p<>nil then inc(p)
      else p:=FileToOpen;
      strlcat(outbuf,p,sizeof(outbuf)-1);
    end;
   'p':strlcat(outbuf,shortpathname,sizeof(outbuf)-1);
   'P':strlcat(outbuf,SrcPath,sizeof(outbuf)-1);
   'D':begin  {Relative path of file}
      p:=strrscan(FileToOpen,'\');
      if p<>nil then begin
       ch:=p[1];
       p[1]:=#0;
       strlcat(outbuf,FileToOpen,sizeof(outbuf)-1); {Aktuelle Datei (langer Name)}
       p[1]:=ch;
     end;
    end;
   '%':strlcat(outbuf,'%',sizeof(outbuf)-1);
   'L':strlcat(outbuf,#13#10,sizeof(outbuf)-1);
   '#':strlcat(outbuf,';',sizeof(outbuf)-1);
	 ' ':strlcat(outbuf,' ',sizeof(outbuf)-1);
	 'I':strlcat(outbuf,pchar(inttostr(currentNb)),sizeof(outbuf)-1);
    end;
    inc(j);
  end
  else if strlen(outbuf)<sizeof(outbuf)-1 then begin
   p:=strend(outbuf);
   p[0]:=LinePart[j];
   p[1]:=#0;
    end;
  inc(j);
   end;
 result:=outbuf;
 end;

function TOneLine.GetHeaderOrFooter(SrcPath,DestName:pchar):pchar;
var p,p2:pchar;
 outbuf:array[0..1024] of char;
 j:cardinal;
begin
  outbuf[0]:=#0;
  j:=0;
   while j<length(LineValue) do begin
  if LineValue[j]='%' then begin
    case LineValue[j+1] of
   '%':strlcat(outbuf,'%',sizeof(outbuf)-1);
   'L':strlcat(outbuf,#13#10,sizeof(outbuf)-1);
   'P':strlcat(outbuf,SrcPath,sizeof(outbuf)-1);
   'D':strlcat(outbuf,DestName,sizeof(outbuf)-1);
   'O':begin  {Name without extension and relative path}
     p:=strrscan(DestName,'\');
     if p<>nil then inc(p)
     else p:=DestName;
     p2:=strrscan(p,'.'); {Only dots in name, not path!}
     if p2<>nil then p2[0]:=#0;
     strlcat(outbuf,p,sizeof(outbuf)-1);
     if p2<>nil then p2[0]:='.';
      end;
   'T':strlcat(outbuf,#9,sizeof(outbuf)-1);
   ' ':strlcat(outbuf,' ',sizeof(outbuf)-1);
    end;
    inc(j);
  end
  else if strlen(outbuf)<sizeof(outbuf)-1 then begin
   p:=strend(outbuf);
   p[0]:=LineValue[j];
   p[1]:=#0;
    end;
  inc(j);
   end;
 result:=outbuf;
 end;

function TOneLine.GetSeparator:pchar;
var p:pchar;
 outbuf:array[0..1024] of char;
 j:cardinal;
begin
  outbuf[0]:=#0;
  j:=0;
   while j<length(LineValue) do begin
  if LineValue[j]='%' then begin
    case LineValue[j+1] of
   '%':strlcat(outbuf,'%',sizeof(outbuf)-1);
   ' ':strlcat(outbuf,' ',sizeof(outbuf)-1);
   'T':strlcat(outbuf,#9,sizeof(outbuf)-1);
   'L':strlcat(outbuf,#13#10,sizeof(outbuf)-1);
    end;
    inc(j);
  end
  else if strlen(outbuf)<sizeof(outbuf)-1 then begin
   p:=strend(outbuf);
   p[0]:=LineValue[j];
   p[1]:=#0;
    end;
  inc(j);
   end;
 result:=outbuf;
 end;

function isValidInfo(list:tstringlist):boolean;
var
	i:cardinal;
	charArray:array[0..50]of char;
begin
	i:=0;
	StrLCopy(charArray,pchar(List[0]),sizeof(charArray)-1);
	if IsCharAlpha(charArray[0]) then i:=i+1;
	fillchar(charArray,sizeof(charArray),#0);
	StrLCopy(charArray,pchar(List[1]),sizeof(charArray)-1);
	if IsCharAlpha(charArray[0]) then i:=i+1;

	if i=0 then result:=true
	else result := false;
end;

end.
Detected encoding: ASCII (7 bit)2