Browse Source

changes for resourcestrings

michael 26 years ago
parent
commit
d1e6915de3
4 changed files with 101 additions and 20 deletions
  1. 5 3
      compiler/cg386ld.pas
  2. 76 13
      compiler/cresstr.pas
  3. 15 3
      compiler/symsym.inc
  4. 5 1
      compiler/symsymh.inc

+ 5 - 3
compiler/cg386ld.pas

@@ -80,8 +80,7 @@ implementation
                      begin
                      begin
                          pushusedregisters(pushed,$ff);
                          pushusedregisters(pushed,$ff);
                          exprasmlist^.concat(new(pai386,op_const(A_PUSH,S_L,
                          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');
                          emitcall('FPC_GETRESOURCESTRING');
 
 
                          hregister:=getexplicitregister32(R_EAX);
                          hregister:=getexplicitregister32(R_EAX);
@@ -864,7 +863,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $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
     * resourcestring fix
 
 
   Revision 1.64  1999/07/22 09:37:37  florian
   Revision 1.64  1999/07/22 09:37:37  florian

+ 76 - 13
compiler/cresstr.pas

@@ -24,19 +24,20 @@ unit cresstr;
   interface
   interface
 
 
     procedure insertresourcestrings;
     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;
     function calc_resstring_hashvalue(p : pchar;len : longint) : longint;
 
 
   implementation
   implementation
 
 
     uses
     uses
-       aasm,verbose,files;
+       globals,aasm,verbose,files;
 
 
     const
     const
        { we can use a static constant because we compile a program only once }
        { we can use a static constant because we compile a program only once }
        { per compiler call                                                   }
        { per compiler call                                                   }
        resstrcount : longint = 0;
        resstrcount : longint = 0;
-
+       resourcefilename = 'resource.rst';
+       
     { calcs the hash value for a give resourcestring, len is }
     { calcs the hash value for a give resourcestring, len is }
     { necessary because the resourcestring can contain #0    }
     { necessary because the resourcestring can contain #0    }
     function calc_resstring_hashvalue(p : pchar;len : longint) : longint;
     function calc_resstring_hashvalue(p : pchar;len : longint) : longint;
@@ -45,7 +46,7 @@ unit cresstr;
 
 
       begin
       begin
          hash:=len;
          hash:=len;
-         For I:=0 to Len-1 do
+         For I:=0 to Len-2 do // 0 terminated
            begin
            begin
            hash:=hash shl 4;
            hash:=hash shl 4;
            inc(Hash,Ord(p[i]));
            inc(Hash,Ord(p[i]));
@@ -71,25 +72,85 @@ unit cresstr;
          resourcestringlist^.insert(new(pai_symbol,initname_global('RESOURCESTRINGLIST')));
          resourcestringlist^.insert(new(pai_symbol,initname_global('RESOURCESTRINGLIST')));
       end;
       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
       var
          l1 : pasmlabel;
          l1 : pasmlabel;
          s : pchar;
          s : pchar;
 
 
       begin
       begin
-         { shall we generate a po file? }
-         { !!!!!! not yet implemented   }
-
          { we don't need to generate consts in units }
          { we don't need to generate consts in units }
-         if current_module^.is_unit then
+         if (main_module^.is_unit) then
            exit;
            exit;
 
 
          if not(assigned(resourcestringlist)) then
          if not(assigned(resourcestringlist)) then
            resourcestringlist:=new(paasmoutput,init);
            resourcestringlist:=new(paasmoutput,init);
 
 
          inc(resstrcount);
          inc(resstrcount);
-
+         
+         AppendToResourceFile(Name,P,Len,Hash);  
+         
          { an empty ansi string is nil! }
          { an empty ansi string is nil! }
          if (p=nil) or (len=0) then
          if (p=nil) or (len=0) then
            resourcestringlist^.concat(new(pai_const,init_32bit(0)))
            resourcestringlist^.concat(new(pai_const,init_32bit(0)))
@@ -112,14 +173,16 @@ unit cresstr;
               consts^.concat(new(pai_const,init_8bit(0)));
               consts^.concat(new(pai_const,init_8bit(0)));
            end;
            end;
          resourcestringlist^.concat(new(pai_const,init_32bit(0)));
          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;
 
 
 end.
 end.
 {
 {
   $Log$
   $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
   + Added computehashvalue
 
 
   Revision 1.1  1999/07/22 09:34:04  florian
   Revision 1.1  1999/07/22 09:34:04  florian

+ 15 - 3
compiler/symsym.inc

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

+ 5 - 1
compiler/symsymh.inc

@@ -283,6 +283,7 @@
        tconstsym = object(tsym)
        tconstsym = object(tsym)
           definition : pdef;
           definition : pdef;
           consttype  : tconsttype;
           consttype  : tconsttype;
+          reshash,    { needed for resource strings }
           value,
           value,
           len        : longint; { len is needed for string length }
           len        : longint; { len is needed for string length }
           constructor init(const n : string;t : tconsttype;v : longint);
           constructor init(const n : string;t : tconsttype;v : longint);
@@ -332,7 +333,10 @@
 
 
 {
 {
   $Log$
   $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
     + resourcestring implemented
     + start of longstring support
     + start of longstring support