|
@@ -34,7 +34,7 @@ uses
|
|
SysUtils,
|
|
SysUtils,
|
|
cclasses,widestr,
|
|
cclasses,widestr,
|
|
cutils,globtype,globals,systems,
|
|
cutils,globtype,globals,systems,
|
|
- symbase,symconst,symtype,symdef,symsym,symtable,
|
|
|
|
|
|
+ symbase,symconst,symtype,defutil, symdef,symsym,symtable,
|
|
verbose,fmodule,ppu,
|
|
verbose,fmodule,ppu,
|
|
aasmtai,aasmdata,aasmcnst,
|
|
aasmtai,aasmdata,aasmcnst,
|
|
aasmcpu;
|
|
aasmcpu;
|
|
@@ -44,9 +44,11 @@ uses
|
|
TResourceStringItem = class(TLinkedListItem)
|
|
TResourceStringItem = class(TLinkedListItem)
|
|
Sym : TConstSym;
|
|
Sym : TConstSym;
|
|
Name : String;
|
|
Name : String;
|
|
- Value : Pchar;
|
|
|
|
- Len : Longint;
|
|
|
|
|
|
+ AValue : PAnsiChar;
|
|
|
|
+ WValue : pcompilerwidestring; // just a reference, do not free.
|
|
|
|
+ Len : Longint; // in bytes, not characters
|
|
hash : Cardinal;
|
|
hash : Cardinal;
|
|
|
|
+ isUnicode : Boolean;
|
|
constructor Create(asym:TConstsym);
|
|
constructor Create(asym:TConstsym);
|
|
destructor Destroy;override;
|
|
destructor Destroy;override;
|
|
procedure CalcHash;
|
|
procedure CalcHash;
|
|
@@ -71,33 +73,67 @@ uses
|
|
---------------------------------------------------------------------}
|
|
---------------------------------------------------------------------}
|
|
|
|
|
|
constructor TResourceStringItem.Create(asym:TConstsym);
|
|
constructor TResourceStringItem.Create(asym:TConstsym);
|
|
|
|
+
|
|
|
|
+ var
|
|
|
|
+ pw : pcompilerwidestring;
|
|
|
|
+ t : TDef;
|
|
|
|
+
|
|
begin
|
|
begin
|
|
inherited Create;
|
|
inherited Create;
|
|
Sym:=Asym;
|
|
Sym:=Asym;
|
|
Name:=lower(asym.owner.name^+'.'+asym.Name);
|
|
Name:=lower(asym.owner.name^+'.'+asym.Name);
|
|
- Len:=asym.value.len;
|
|
|
|
- GetMem(Value,Len);
|
|
|
|
- Move(asym.value.valueptr^,Value^,Len);
|
|
|
|
|
|
+ isUnicode:=is_systemunit_unicode;
|
|
|
|
+ if IsUnicode then
|
|
|
|
+ begin
|
|
|
|
+ T:=aSym.constdef;
|
|
|
|
+ WValue:=pcompilerwidestring(asym.value.valueptr);
|
|
|
|
+ Len:=WValue^.len*sizeOf(tcompilerwidechar);
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ Len:=asym.value.len;
|
|
|
|
+ GetMem(AValue,Len);
|
|
|
|
+ Move(asym.value.valueptr^,AValue^,Len);
|
|
|
|
+ end;
|
|
CalcHash;
|
|
CalcHash;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TResourceStringItem.Destroy;
|
|
destructor TResourceStringItem.Destroy;
|
|
begin
|
|
begin
|
|
- FreeMem(Value);
|
|
|
|
|
|
+ if Assigned(AValue) then
|
|
|
|
+ FreeMem(AValue);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TResourceStringItem.CalcHash;
|
|
procedure TResourceStringItem.CalcHash;
|
|
Var
|
|
Var
|
|
g : Cardinal;
|
|
g : Cardinal;
|
|
- I : longint;
|
|
|
|
|
|
+ llen,wlen,I : longint;
|
|
|
|
+ P : PByte;
|
|
|
|
+ pc : PAnsiChar;
|
|
|
|
+
|
|
begin
|
|
begin
|
|
|
|
+ pc:=nil;
|
|
hash:=0;
|
|
hash:=0;
|
|
- For I:=0 to Len-1 do { 0 terminated }
|
|
|
|
|
|
+ if IsUnicode then
|
|
|
|
+ begin
|
|
|
|
+ // Need to calculate hash on UTF8 encoded string, GNU gettext.
|
|
|
|
+ llen:=UnicodeToUtf8(nil,0,PUnicodeChar(wValue^.data),wValue^.len);
|
|
|
|
+ getmem(pc,llen);
|
|
|
|
+ UnicodeToUtf8(PC,llen,PUnicodeChar(wValue^.data),len);
|
|
|
|
+ P:=PByte(pc);
|
|
|
|
+ llen:=llen-1; // Take of terminating #0
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ llen:=Len;
|
|
|
|
+ P:=PByte(AValue);
|
|
|
|
+ end;
|
|
|
|
+ For I:=0 to lLen-1 do { 0 terminated }
|
|
begin
|
|
begin
|
|
hash:=hash shl 4;
|
|
hash:=hash shl 4;
|
|
- inc(Hash,Ord(Value[i]));
|
|
|
|
|
|
+ inc(Hash,P[i]);
|
|
g:=hash and ($f shl 28);
|
|
g:=hash and ($f shl 28);
|
|
if g<>0 then
|
|
if g<>0 then
|
|
begin
|
|
begin
|
|
@@ -105,6 +141,8 @@ uses
|
|
hash:=hash xor g;
|
|
hash:=hash xor g;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
+ if Assigned(Pc) then
|
|
|
|
+ FreeMem(PC);
|
|
If Hash=0 then
|
|
If Hash=0 then
|
|
Hash:=$ffffffff;
|
|
Hash:=$ffffffff;
|
|
end;
|
|
end;
|
|
@@ -133,6 +171,8 @@ uses
|
|
R : TResourceStringItem;
|
|
R : TResourceStringItem;
|
|
resstrdef: tdef;
|
|
resstrdef: tdef;
|
|
tcb : ttai_typedconstbuilder;
|
|
tcb : ttai_typedconstbuilder;
|
|
|
|
+ enc : tstringencoding;
|
|
|
|
+
|
|
begin
|
|
begin
|
|
resstrdef:=search_system_type('TRESOURCESTRINGRECORD').typedef;
|
|
resstrdef:=search_system_type('TRESOURCESTRINGRECORD').typedef;
|
|
|
|
|
|
@@ -157,12 +197,20 @@ uses
|
|
while assigned(R) do
|
|
while assigned(R) do
|
|
begin
|
|
begin
|
|
tcb:=ctai_typedconstbuilder.create([tcalo_vectorized_dead_strip_item,tcalo_data_force_indirect]);
|
|
tcb:=ctai_typedconstbuilder.create([tcalo_vectorized_dead_strip_item,tcalo_data_force_indirect]);
|
|
- if assigned(R.value) and (R.len<>0) then
|
|
|
|
- valuelab:=tcb.emit_ansistring_const(current_asmdata.asmlists[al_const],R.Value,R.Len,getansistringcodepage)
|
|
|
|
- else
|
|
|
|
|
|
+ valuelab.lab:=nil;
|
|
|
|
+ valuelab.ofs:=0;
|
|
|
|
+ if (R.len<>0) then
|
|
begin
|
|
begin
|
|
- valuelab.lab:=nil;
|
|
|
|
- valuelab.ofs:=0;
|
|
|
|
|
|
+ if R.isUnicode and assigned(R.WValue) then
|
|
|
|
+ begin
|
|
|
|
+ enc:=tstringdef(cunicodestringtype).encoding;
|
|
|
|
+ valuelab:=tcb.emit_unicodestring_const(current_asmdata.asmlists[al_const],R.WValue,enc,False);
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ if assigned(R.AValue) then
|
|
|
|
+ valuelab:=tcb.emit_ansistring_const(current_asmdata.asmlists[al_const],R.AValue,R.Len,getansistringcodepage)
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
current_asmdata.asmlists[al_const].concat(cai_align.Create(sizeof(pint)));
|
|
current_asmdata.asmlists[al_const].concat(cai_align.Create(sizeof(pint)));
|
|
namelab:=tcb.emit_ansistring_const(current_asmdata.asmlists[al_const],@R.Name[1],length(R.name),getansistringcodepage);
|
|
namelab:=tcb.emit_ansistring_const(current_asmdata.asmlists[al_const],@R.Name[1],length(R.name),getansistringcodepage);
|
|
@@ -171,7 +219,7 @@ uses
|
|
TResourceStringRecord = Packed Record
|
|
TResourceStringRecord = Packed Record
|
|
Name,
|
|
Name,
|
|
CurrentValue,
|
|
CurrentValue,
|
|
- DefaultValue : AnsiString;
|
|
|
|
|
|
+ DefaultValue : AnsiString/Widestring;
|
|
HashValue : LongWord;
|
|
HashValue : LongWord;
|
|
end;
|
|
end;
|
|
}
|
|
}
|
|
@@ -205,9 +253,11 @@ uses
|
|
F: Text;
|
|
F: Text;
|
|
R: TResourceStringItem;
|
|
R: TResourceStringItem;
|
|
ResFileName: string;
|
|
ResFileName: string;
|
|
- I: Integer;
|
|
|
|
|
|
+ I,Len: Integer;
|
|
C: tcompilerwidechar;
|
|
C: tcompilerwidechar;
|
|
W: pcompilerwidestring;
|
|
W: pcompilerwidestring;
|
|
|
|
+ P : PByte;
|
|
|
|
+
|
|
begin
|
|
begin
|
|
ResFileName:=ChangeFileExt(current_module.ppufilename,'.rsj');
|
|
ResFileName:=ChangeFileExt(current_module.ppufilename,'.rsj');
|
|
message1 (general_i_writingresourcefile,ExtractFileName(ResFileName));
|
|
message1 (general_i_writingresourcefile,ExtractFileName(ResFileName));
|
|
@@ -229,15 +279,26 @@ uses
|
|
while assigned(R) do
|
|
while assigned(R) do
|
|
begin
|
|
begin
|
|
write(f, '{"hash":',R.Hash,',"name":"',R.Name,'","sourcebytes":[');
|
|
write(f, '{"hash":',R.Hash,',"name":"',R.Name,'","sourcebytes":[');
|
|
|
|
+ if R.isUnicode then
|
|
|
|
+ P:=PByte(R.WValue^.data)
|
|
|
|
+ else
|
|
|
|
+ P:=PByte(R.AValue);
|
|
for i:=0 to R.Len-1 do
|
|
for i:=0 to R.Len-1 do
|
|
begin
|
|
begin
|
|
- write(f,ord(R.Value[i]));
|
|
|
|
|
|
+ write(f,P[i]);
|
|
if i<>R.Len-1 then
|
|
if i<>R.Len-1 then
|
|
write(f,',');
|
|
write(f,',');
|
|
end;
|
|
end;
|
|
write(f,'],"value":"');
|
|
write(f,'],"value":"');
|
|
- initwidestring(W);
|
|
|
|
- ascii2unicode(R.Value,R.Len,current_settings.sourcecodepage,W);
|
|
|
|
|
|
+ if Not r.isUnicode then
|
|
|
|
+ begin
|
|
|
|
+ initwidestring(W);
|
|
|
|
+ ascii2unicode(R.AValue,R.Len,current_settings.sourcecodepage,W);
|
|
|
|
+ end
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ W:=R.WValue;
|
|
|
|
+ end;
|
|
for I := 0 to W^.len - 1 do
|
|
for I := 0 to W^.len - 1 do
|
|
begin
|
|
begin
|
|
C := W^.Data[I];
|
|
C := W^.Data[I];
|
|
@@ -261,7 +322,8 @@ uses
|
|
write(f,Chr(C));
|
|
write(f,Chr(C));
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
- donewidestring(W);
|
|
|
|
|
|
+ if W<>R.WValue then
|
|
|
|
+ donewidestring(W);
|
|
write(f,'"}');
|
|
write(f,'"}');
|
|
R:=TResourceStringItem(R.Next);
|
|
R:=TResourceStringItem(R.Next);
|
|
if assigned(R) then
|
|
if assigned(R) then
|