function c_string_generate_from_string(const str:string;pas:boolean=false):c_string;
var i,j,k,m,len:SizeInt;
res:c_string;
bool:boolean;
gstr,gtempstr1,gtempstr2,gtempstr3:string;
begin
gstr:=str; gtempstr1:=''; gtempstr2:=''; gtempstr3:='';
i:=1; len:=length(str); res.count:=0; bool:=false;
SetLength(res.item,0); SetLength(res.status,0);
while(i<=len) do
begin
if(pas) then
begin
if(gstr[i]=#39) or (gstr[i]='#') then
begin
j:=i;
while(j<=len)do
begin
if(Copy(gstr,j,2)='#$') then
begin
k:=j+2;
while(k<=len) and (c_string_is_hex(gstr[k])) and (k-j<=5) do inc(k);
j:=k+1; continue;
end
else if(gstr[j]='#') then
begin
k:=j+1;
while(k<=len) and (gstr[k]>='0') and (gstr[k]<='9') and (k-j<=5) do inc(k);
j:=k+1; continue;
end
else if(gstr[j]=#39) then
begin
k:=j+1;
while(k<=len) and (gstr[k]<>#39) do inc(k);
j:=k+1; continue;
end
else break;
end;
inc(res.count);
SetLength(res.item,res.count);
res.item[res.count-1]:=Copy(gstr,i,j-i+1);
i:=j+1; inc(j); m:=i;
while(j<=len) and (gstr[j]=' ') do inc(j);
if(j<=len) and (gstr[j]=#10) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=2;
end
else if(j<=len) and (j>m) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=1;
end
else if(j>len) or (gstr[j]>' ') then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=0;
end;
bool:=false;
continue;
end;
end
else
begin
if(gstr[i]=#39) or (gstr[i]='"') then
begin
j:=i+1;
while(j<=len) do
begin
if(j>i+3) and (gstr[j-3]<>'\') and (gstr[j-2]='\') and (gstr[j-1]='\')
and (gstr[i]=gstr[j]) then break
else if(j>i+2) and (gstr[j-2]='\') and (gstr[j-1]='\')
and (gstr[i]=gstr[j]) then break
else if(j>i+1) and (gstr[j-1]<>'\') and (gstr[i]=gstr[j]) then break
else if(j=i+1) and (gstr[i]=gstr[j]) then break;
inc(j);
end;
inc(res.count);
SetLength(res.item,res.count);
res.item[res.count-1]:=Copy(gstr,i,j-i+1);
i:=j+1; inc(j); m:=i;
while(j<=len) and (gstr[j]=' ') do inc(j);
if(j<=len) and (gstr[j]=#10) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=2;
end
else if(j<=len) and (j>m) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=1;
end
else if(j>len) or (gstr[j]>' ') then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=0;
end;
bool:=false;
continue;
end;
end;
if(i<=len-2) then gtempstr1:=Copy(gstr,i,3) else gtempstr1:=''; //That is where ERROR occurs.
if(i<=len-1) then gtempstr2:=Copy(gstr,i,2) else gtempstr2:='';
if(i<=len) then gtempstr3:=Copy(gstr,i,1) else gtempstr3:='';
if(pas=false) then
begin
if(i<=len-2) and (c_string_is_operator(gtempstr1)>0) then
begin
inc(res.count);
SetLength(res.item,res.count);
res.item[res.count-1]:=gtempstr1;
j:=i+3;
while(j<=len) and (gstr[j]=' ') do inc(j);
if(j<=len) and (gstr[j]=#10) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=2;
end
else if(j<=len) and (j>i+3) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=1;
end
else if(j>len) or (gstr[j]>' ') then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=0;
end;
inc(i,3); bool:=false; continue;
end
else if(i<=len-1) and (c_string_is_operator(gtempstr2)>0) then
begin
inc(res.count);
SetLength(res.item,res.count);
res.item[res.count-1]:=gtempstr2;
j:=i+2;
while(j<=len) and (gstr[j]=' ') do inc(j);
if(j<=len) and (gstr[j]=#10) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=2;
end
else if(j<=len) and (j>i+2) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=1;
end
else if(j>len) or (gstr[j]>' ') then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=0;
end;
inc(i,2); bool:=false; continue;
end
else if(c_string_is_operator(gtempstr3)>0) or (c_string_is_bracket(gstr[i])) then
begin
if((res.count>0) and (c_string_is_vaild_value(res.item[res.count-1])=false)
and (gstr[i]='-')) or ((gstr[i]='-') and (res.count=0)) then
begin
inc(res.count);
SetLength(res.item,res.count);
res.item[res.count-1]:=gtempstr3;
inc(i); bool:=true; continue;
end
else if(res.count>0) and (c_string_is_vaild_value(res.item[res.count-1])=true)
and (not c_string_is_bracket(gstr[i]))
and (gstr[i]='.') then
begin
res.item[res.count-1]:=res.item[res.count-1]+gtempstr3;
inc(i); bool:=true; continue;
end
else if(res.count>0) and (c_string_is_vaild_value(res.item[res.count-1])=true)
and (length(res.item[res.count-1])>0) and (not c_string_is_bracket(gstr[i]))
and (gstr[i]='+') and ((res.item[res.count-1][length(res.item[res.count-1])]='E')
or (res.item[res.count-1][length(res.item[res.count-1])]='e')) then
begin
res.item[res.count-1]:=res.item[res.count-1]+gtempstr3;
inc(i); bool:=true; continue;
end;
inc(res.count);
SetLength(res.item,res.count);
res.item[res.count-1]:=gtempstr3;
j:=i+1;
while(j<=len) and (gstr[j]=' ') do inc(j);
if(j<=len) and (gstr[j]=#10) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=2;
end
else if(j<=len) and (j>i+1) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=1;
end
else if(j>len) or (gstr[j]>' ') then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=0;
end;
inc(i); bool:=false; continue;
end;
end
else
begin
if(i<=len-2) and (c_string_is_operator(gtempstr1,true)>0) and (bool=false) then
begin
inc(res.count);
SetLength(res.item,res.count);
res.item[res.count-1]:=gtempstr1;
j:=i+3;
while(j<=len) and (gstr[j]=' ') do inc(j);
if(j<=len) and (gstr[j]=#10) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=2;
end
else if(j<=len) and (j>i+3) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=1;
end
else if(j>len) or (gstr[j]>' ') then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=0;
end;
inc(i,3); bool:=false; continue;
end
else if(i<=len-1) and (c_string_is_operator(gtempstr2,true)>0) and (bool=false) then
begin
inc(res.count);
SetLength(res.item,res.count);
res.item[res.count-1]:=gtempstr2;
j:=i+2;
while(j<=len) and (gstr[j]=' ') do inc(j);
if(j<=len) and (gstr[j]=#10) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=2;
end
else if(j<=len) and (j>i+2) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=1;
end
else if(j>len) or (gstr[j]>' ') then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=0;
end;
inc(i,2); bool:=false; continue;
end
else if(c_string_is_operator(gtempstr3,true)>0) or
(c_string_is_bracket(gstr[i])) then
begin
if((res.count>0) and (c_string_is_vaild_value(res.item[res.count-1])=false)
and (gstr[i]='-')) or ((gstr[i]='-') and (res.count=0)) then
begin
inc(res.count);
SetLength(res.item,res.count);
res.item[res.count-1]:=gtempstr3;
inc(i); bool:=true; continue;
end
else if(res.count>0) and (c_string_is_vaild_value(res.item[res.count-1])=true)
and (gstr[i]='.') and (not c_string_is_bracket(gstr[i])) then
begin
res.item[res.count-1]:=res.item[res.count-1]+gtempstr3;
inc(i); bool:=true; continue;
end;
inc(res.count);
SetLength(res.item,res.count);
res.item[res.count-1]:=gtempstr3;
j:=i+1;
while(j<=len) and (gstr[j]=' ') do inc(j);
if(j<=len) and (gstr[j]=#10) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=2;
end
else if(j<=len) and (j>i+1) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=1;
end
else if(j>len) or (gstr[j]>' ') then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=0;
end;
inc(i); bool:=false; continue;
end;
end;
if(i>len) then break;
if(c_string_is_vaild_char(gstr[i])) then
begin
if(bool=false) then
begin
inc(res.count);
SetLength(res.item,res.count);
res.item[res.count-1]:=gtempstr3;
bool:=true;
end
else
begin
res.item[res.count-1]:=res.item[res.count-1]+gtempstr3;
end;
if(i=len) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=0;
end;
inc(i); continue;
end
else if(c_string_is_vaild_char(gstr[i])=false) and (bool=true) then
begin
j:=i;
while(j<=len) and (gstr[j]=' ') do inc(j);
if(j<=len) and (gstr[j]=#10) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=2;
end
else if(j<=len) and (j>i) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=1;
end
else if(j>len) then
begin
SetLength(res.status,res.count);
res.status[res.count-1]:=0;
end;
bool:=false; inc(i); continue;
end;
inc(i);
end;
Result.count:=res.count;
SetLength(Result.item,res.count);
for i:=1 to res.count do Result.item[i-1]:=res.item[i-1];
SetLength(Result.status,res.count);
for i:=1 to res.count do Result.status[i-1]:=res.status[i-1];
SetLength(res.item,0); SetLength(res.status,0); res.count:=0;
end;