changes for resourcestrings

This commit is contained in:
michael 1999-07-24 15:12:56 +00:00
parent 916859ebd7
commit d1e6915de3
4 changed files with 101 additions and 20 deletions

View File

@ -80,8 +80,7 @@ implementation
begin
pushusedregisters(pushed,$ff);
exprasmlist^.concat(new(pai386,op_const(A_PUSH,S_L,
calc_resstring_hashvalue(pchar(pconstsym(p^.symtableentry)^.value),
pconstsym(p^.symtableentry)^.len))));
pconstsym(p^.symtableentry)^.reshash)));
emitcall('FPC_GETRESOURCESTRING');
hregister:=getexplicitregister32(R_EAX);
@ -864,7 +863,10 @@ implementation
end.
{
$Log$
Revision 1.65 1999-07-23 23:09:06 peter
Revision 1.66 1999-07-24 15:12:56 michael
changes for resourcestrings
Revision 1.65 1999/07/23 23:09:06 peter
* resourcestring fix
Revision 1.64 1999/07/22 09:37:37 florian

View File

@ -24,19 +24,20 @@ unit cresstr;
interface
procedure insertresourcestrings;
procedure registerresourcestring(p : pchar;len : longint);
procedure registerresourcestring(Const name : string;p : pchar;len,hash : longint);
function calc_resstring_hashvalue(p : pchar;len : longint) : longint;
implementation
uses
aasm,verbose,files;
globals,aasm,verbose,files;
const
{ we can use a static constant because we compile a program only once }
{ per compiler call }
resstrcount : longint = 0;
resourcefilename = 'resource.rst';
{ calcs the hash value for a give resourcestring, len is }
{ necessary because the resourcestring can contain #0 }
function calc_resstring_hashvalue(p : pchar;len : longint) : longint;
@ -45,7 +46,7 @@ unit cresstr;
begin
hash:=len;
For I:=0 to Len-1 do
For I:=0 to Len-2 do // 0 terminated
begin
hash:=hash shl 4;
inc(Hash,Ord(p[i]));
@ -71,25 +72,85 @@ unit cresstr;
resourcestringlist^.insert(new(pai_symbol,initname_global('RESOURCESTRINGLIST')));
end;
procedure registerresourcestring(p : pchar;len : longint);
Procedure AppendToResourceFile(const name : string;p : pchar;len,hash : longint);
Type
TMode = (quoted,unquoted);
Var F : Text;
Mode : TMode;
C : char;
Col,i : longint;
Procedure Add(Const S : String);
begin
Write(F,S);
Col:=Col+length(s);
end;
begin
Assign(F,ResourceFileName);
Append(f);
writeln(f);
Writeln (f,'# hash value = ',hash);
Add(Name+'=');
Mode:=unquoted;
col:=0;
For I:=0 to Len do
begin
C:=P[i];
If (ord(C)>31) and (Ord(c)<=128) and (c<>'''') then
begin
If mode=Quoted then
Add(c)
else
begin
Add(''''+c);
mode:=quoted
end
end
else
begin
If Mode=quoted then
begin
Add('''');
mode:=unquoted;
end;
Add('#'+tostr(ord(c)));
end;
If Col>72 then
begin
if mode=quoted then
Write (F,'''');
Writeln(F,'+');
Col:=0;
Mode:=unQuoted;
end;
end;
if mode=quoted then writeln (f,'''');
Writeln(f);
close(f);
end;
procedure registerresourcestring(const name : string;p : pchar;len,hash : longint);
var
l1 : pasmlabel;
s : pchar;
begin
{ shall we generate a po file? }
{ !!!!!! not yet implemented }
{ we don't need to generate consts in units }
if current_module^.is_unit then
if (main_module^.is_unit) then
exit;
if not(assigned(resourcestringlist)) then
resourcestringlist:=new(paasmoutput,init);
inc(resstrcount);
AppendToResourceFile(Name,P,Len,Hash);
{ an empty ansi string is nil! }
if (p=nil) or (len=0) then
resourcestringlist^.concat(new(pai_const,init_32bit(0)))
@ -112,14 +173,16 @@ unit cresstr;
consts^.concat(new(pai_const,init_8bit(0)));
end;
resourcestringlist^.concat(new(pai_const,init_32bit(0)));
resourcestringlist^.concat(new(pai_const,init_32bit(
calc_resstring_hashvalue(p,len))));
resourcestringlist^.concat(new(pai_const,init_32bit(hash)));
end;
end.
{
$Log$
Revision 1.2 1999-07-22 20:04:58 michael
Revision 1.3 1999-07-24 15:12:58 michael
changes for resourcestrings
Revision 1.2 1999/07/22 20:04:58 michael
+ Added computehashvalue
Revision 1.1 1999/07/22 09:34:04 florian

View File

@ -1487,6 +1487,7 @@
typ:=constsym;
consttype:=t;
value:=v;
reshash:=0;
definition:=nil;
len:=0;
end;
@ -1512,7 +1513,10 @@
definition:=nil;
len:=l;
if t=constresourcestring then
registerresourcestring(pchar(value),len);
begin
reshash:=calc_resstring_hashvalue(pchar(value),len);
registerresourcestring(name,pchar(value),len,reshash);
end;
end;
constructor tconstsym.load;
@ -1538,7 +1542,10 @@
getmem(pchar(value),len+1);
current_ppu^.getdata(pchar(value)^,len);
if consttype=constresourcestring then
registerresourcestring(pchar(value),len);
begin
reshash:=readlong;
registerresourcestring(name,pchar(value),len,reshash);
end;
end;
constreal :
begin
@ -1606,6 +1613,8 @@
begin
writelong(len);
current_ppu^.putdata(pchar(value)^,len);
If consttype = constresourcestring then
writelong(reshash);
end;
constreal :
writereal(pbestreal(value)^);
@ -2002,7 +2011,10 @@
{
$Log$
Revision 1.102 1999-07-24 13:36:23 michael
Revision 1.103 1999-07-24 15:12:59 michael
changes for resourcestrings
Revision 1.102 1999/07/24 13:36:23 michael
* Fixed resourcestring writing to units
Revision 1.101 1999/07/23 20:59:23 peter

View File

@ -283,6 +283,7 @@
tconstsym = object(tsym)
definition : pdef;
consttype : tconsttype;
reshash, { needed for resource strings }
value,
len : longint; { len is needed for string length }
constructor init(const n : string;t : tconsttype;v : longint);
@ -332,7 +333,10 @@
{
$Log$
Revision 1.27 1999-07-22 09:37:57 florian
Revision 1.28 1999-07-24 15:13:01 michael
changes for resourcestrings
Revision 1.27 1999/07/22 09:37:57 florian
+ resourcestring implemented
+ start of longstring support