Tomas Hajny 21 éve
szülő
commit
ad2339dc75
1 módosított fájl, 247 hozzáadás és 130 törlés
  1. 247 130
      utils/h2pas/h2pas.pas

+ 247 - 130
utils/h2pas/h2pas.pas

@@ -26,11 +26,7 @@ program h2pas;
  ****************************************************************************)
  ****************************************************************************)
 
 
    uses
    uses
-{$ifdef Delphi}
-     SysUtils,
-{$else Delphi}
-     strings,
-{$endif Delphi}
+     SysUtils,classes,
      options,scan,converu,lexlib,yacclib;
      options,scan,converu,lexlib,yacclib;
 
 
    type
    type
@@ -50,13 +46,14 @@ program h2pas;
 
 
   var
   var
      hp,ph    : presobject;
      hp,ph    : presobject;
-     extfile  : text;  (* file for implementation headers extern procs *)
+     implemfile  : text;  (* file for implementation headers extern procs *)
      IsExtern : boolean;
      IsExtern : boolean;
      NeedEllipsisOverload : boolean;
      NeedEllipsisOverload : boolean;
      must_write_packed_field : boolean;
      must_write_packed_field : boolean;
      tempfile : text;
      tempfile : text;
      No_pop   : boolean;
      No_pop   : boolean;
      s,TN,PN  : String;
      s,TN,PN  : String;
+     pointerprefix: boolean;
 
 
 (* $ define yydebug
 (* $ define yydebug
  compile with -dYYDEBUG to get debugging info *)
  compile with -dYYDEBUG to get debugging info *)
@@ -69,6 +66,10 @@ program h2pas;
 
 
   var space_array : array [0..255] of byte;
   var space_array : array [0..255] of byte;
       space_index : byte;
       space_index : byte;
+      
+      { Used when PPointers is used - pointer type definitions }
+      PTypeList : TStringList;
+      
 
 
         procedure shift(space_number : byte);
         procedure shift(space_number : byte);
           var
           var
@@ -206,9 +207,14 @@ program h2pas;
         if RemoveUnderScore and (length(s)>1) and (s[1]='_') then
         if RemoveUnderScore and (length(s)>1) and (s[1]='_') then
          i:=2;
          i:=2;
         if UsePPointers then
         if UsePPointers then
-         PointerName:='P'+Copy(s,i,255)
+        begin
+         PointerName:='P'+Copy(s,i,255);
+         PTypeList.Add(PointerName);
+        end 
         else
         else
          PointerName:=Copy(s,i,255);
          PointerName:=Copy(s,i,255);
+        if PointerPrefix then
+           PTypeList.Add('P'+s);
       end;
       end;
 
 
 
 
@@ -265,21 +271,21 @@ program h2pas;
                         writeln(outfile,';');
                         writeln(outfile,';');
                         popshift;
                         popshift;
                         { get function in implementation }
                         { get function in implementation }
-                        write(extfile,aktspace,'function ',name);
-                        write(extfile,'(var a : ',ph,') : ');
+                        write(implemfile,aktspace,'function ',name);
+                        write(implemfile,'(var a : ',ph,') : ');
                         if not compactmode then
                         if not compactmode then
                          shift(2);
                          shift(2);
-                        write_p_a_def(extfile,hp3^.p1^.p1,hp2^.p1);
-                        writeln(extfile,';');
-                        writeln(extfile,aktspace,'begin');
+                        write_p_a_def(implemfile,hp3^.p1^.p1,hp2^.p1);
+                        writeln(implemfile,';');
+                        writeln(implemfile,aktspace,'begin');
                         shift(3);
                         shift(3);
-                        write(extfile,aktspace,name,':=(a.flag',flag_index);
-                        writeln(extfile,' and bm_',ph,'_',name,') shr bp_',ph,'_',name,';');
+                        write(implemfile,aktspace,name,':=(a.flag',flag_index);
+                        writeln(implemfile,' and bm_',ph,'_',name,') shr bp_',ph,'_',name,';');
                         popshift;
                         popshift;
-                        writeln(extfile,aktspace,'end;');
+                        writeln(implemfile,aktspace,'end;');
                         if not compactmode then
                         if not compactmode then
                          popshift;
                          popshift;
-                        writeln(extfile,'');
+                        writeln(implemfile,'');
                         { set function in interface }
                         { set function in interface }
                         write(outfile,aktspace,'procedure set_',name);
                         write(outfile,aktspace,'procedure set_',name);
                         write(outfile,'(var a : ',ph,'; __',name,' : ');
                         write(outfile,'(var a : ',ph,'; __',name,' : ');
@@ -288,22 +294,22 @@ program h2pas;
                         writeln(outfile,');');
                         writeln(outfile,');');
                         popshift;
                         popshift;
                         { set function in implementation }
                         { set function in implementation }
-                        write(extfile,aktspace,'procedure set_',name);
-                        write(extfile,'(var a : ',ph,'; __',name,' : ');
+                        write(implemfile,aktspace,'procedure set_',name);
+                        write(implemfile,'(var a : ',ph,'; __',name,' : ');
                         if not compactmode then
                         if not compactmode then
                          shift(2);
                          shift(2);
-                        write_p_a_def(extfile,hp3^.p1^.p1,hp2^.p1);
-                        writeln(extfile,');');
-                        writeln(extfile,aktspace,'begin');
+                        write_p_a_def(implemfile,hp3^.p1^.p1,hp2^.p1);
+                        writeln(implemfile,');');
+                        writeln(implemfile,aktspace,'begin');
                         shift(3);
                         shift(3);
-                        write(extfile,aktspace,'a.flag',flag_index,':=');
-                        write(extfile,'a.flag',flag_index,' or ');
-                        writeln(extfile,'((__',name,' shl bp_',ph,'_',name,') and bm_',ph,'_',name,');');
+                        write(implemfile,aktspace,'a.flag',flag_index,':=');
+                        write(implemfile,'a.flag',flag_index,' or ');
+                        writeln(implemfile,'((__',name,' shl bp_',ph,'_',name,') and bm_',ph,'_',name,');');
                         popshift;
                         popshift;
-                        writeln(extfile,aktspace,'end;');
+                        writeln(implemfile,aktspace,'end;');
                         if not compactmode then
                         if not compactmode then
                          popshift;
                          popshift;
-                        writeln(extfile,'');
+                        writeln(implemfile,'');
                      end
                      end
                    else if is_sized then
                    else if is_sized then
                      begin
                      begin
@@ -531,7 +537,7 @@ program h2pas;
        (* if in args *dname is replaced by pdname *)
        (* if in args *dname is replaced by pdname *)
        in_args : boolean = false;
        in_args : boolean = false;
        typedef_level : longint = 0;
        typedef_level : longint = 0;
-
+       
     (* writes an argument list, where p is t_arglist *)
     (* writes an argument list, where p is t_arglist *)
 
 
     procedure write_args(var outfile:text; p : presobject);
     procedure write_args(var outfile:text; p : presobject);
@@ -579,20 +585,26 @@ program h2pas;
               else
               else
                 begin
                 begin
                    (* generate a call by reference parameter ?       *)
                    (* generate a call by reference parameter ?       *)
+
+//                   varpara:=usevarparas and
+//                            assigned(p^.p1^.p2^.p1) and
+//                            (p^.p1^.p2^.p1^.typ in [t_addrdef,t_pointerdef]) and
+//                            assigned(p^.p1^.p2^.p1^.p1) and
+//                            (p^.p1^.p2^.p1^.p1^.typ<>t_procdef);
                    varpara:=usevarparas and
                    varpara:=usevarparas and
-                            assigned(p^.p1^.p2^.p1) and
-                            (p^.p1^.p2^.p1^.typ in [t_addrdef,t_pointerdef]) and
-                            assigned(p^.p1^.p2^.p1^.p1) and
-                            (p^.p1^.p2^.p1^.p1^.typ<>t_procdef);
+                            assigned(p^.p1^.p1) and
+                            (p^.p1^.p1^.typ in [t_addrdef,t_pointerdef]) and
+                            assigned(p^.p1^.p1^.p1) and
+                            (p^.p1^.p1^.p1^.typ<>t_procdef);
                    (* do not do it for char pointer !!               *)
                    (* do not do it for char pointer !!               *)
                    (* para : pchar; and var para : char; are         *)
                    (* para : pchar; and var para : char; are         *)
                    (* completely different in pascal                 *)
                    (* completely different in pascal                 *)
                    (* here we exclude all typename containing char   *)
                    (* here we exclude all typename containing char   *)
                    (* is this a good method ??                       *)
                    (* is this a good method ??                       *)
                    if varpara and
                    if varpara and
-                      (p^.p1^.p2^.p1^.typ=t_pointerdef) and
-                      (p^.p1^.p2^.p1^.p1^.typ=t_id) and
-                      (pos('CHAR',uppercase(p^.p1^.p2^.p1^.p1^.str))<>0) then
+                      (p^.p1^.p1^.typ=t_pointerdef) and
+                      (p^.p1^.p1^.p1^.typ=t_id) and
+                      (pos('CHAR',uppercase(p^.p1^.p1^.p1^.str))<>0) then
                      varpara:=false;
                      varpara:=false;
                    if varpara then
                    if varpara then
                      begin
                      begin
@@ -621,8 +633,10 @@ program h2pas;
                          end;
                          end;
                      end;
                      end;
                    write(outfile,':');
                    write(outfile,':');
-                   if varpara then
-                     write_p_a_def(outfile,p^.p1^.p2^.p1^.p1,p^.p1^.p1)
+                   if varpara then 
+                   begin
+                     write_p_a_def(outfile,p^.p1^.p2^.p1,p^.p1^.p1^.p1);
+                   end
                    else
                    else
                      write_p_a_def(outfile,p^.p1^.p2^.p1,p^.p1^.p1);
                      write_p_a_def(outfile,p^.p1^.p2^.p1,p^.p1^.p1);
 
 
@@ -646,6 +660,8 @@ program h2pas;
          in_args:=old_in_args;
          in_args:=old_in_args;
          popshift;
          popshift;
       end;
       end;
+       
+
 
 
     procedure write_p_a_def(var outfile:text; p,simple_type : presobject);
     procedure write_p_a_def(var outfile:text; p,simple_type : presobject);
       var
       var
@@ -720,10 +736,14 @@ program h2pas;
                                       if not pointerwritten then
                                       if not pointerwritten then
                                        begin
                                        begin
                                          if in_args then
                                          if in_args then
-                                          write(outfile,'P')
+                                         begin
+                                          write(outfile,'P');
+                                          pointerprefix:=true;
+                                         end 
                                          else
                                          else
                                           write(outfile,'^');
                                           write(outfile,'^');
                                          write_p_a_def(outfile,p^.p1,simple_type);
                                          write_p_a_def(outfile,p^.p1,simple_type);
+                                         pointerprefix:=false;
                                        end;
                                        end;
                                      end;
                                      end;
                                 end;
                                 end;
@@ -780,6 +800,8 @@ program h2pas;
          case p^.typ of
          case p^.typ of
             t_id :
             t_id :
               begin
               begin
+                if pointerprefix then
+                   PTypeList.Add('P'+p^.str);
                 if p^.intname then
                 if p^.intname then
                  write(outfile,p^.p)
                  write(outfile,p^.p)
                 else
                 else
@@ -815,10 +837,14 @@ program h2pas;
                  if not pointerwritten then
                  if not pointerwritten then
                   begin
                   begin
                     if in_args then
                     if in_args then
-                     write(outfile,'P')
+                    begin
+                     write(outfile,'P');
+                     pointerprefix:=true;
+                    end 
                     else
                     else
                      write(outfile,'^');
                      write(outfile,'^');
                     write_type_specifier(outfile,p^.p1);
                     write_type_specifier(outfile,p^.p1);
+                    pointerprefix:=false;
                   end;
                   end;
               end;
               end;
             t_enumdef :
             t_enumdef :
@@ -826,6 +852,8 @@ program h2pas;
                  if (typedef_level>1) and (p^.p1=nil) and
                  if (typedef_level>1) and (p^.p1=nil) and
                     (p^.p2^.typ=t_id) then
                     (p^.p2^.typ=t_id) then
                    begin
                    begin
+                      if pointerprefix then
+                        PTypeList.Add('P'+p^.p2^.str);
                       write(outfile,p^.p2^.p);
                       write(outfile,p^.p2^.p);
                    end
                    end
                  else
                  else
@@ -914,11 +942,16 @@ program h2pas;
                  if ((in_args) or (typedef_level>1)) and
                  if ((in_args) or (typedef_level>1)) and
                     (p^.p1=nil) and (p^.p2^.typ=t_id) then
                     (p^.p1=nil) and (p^.p2^.typ=t_id) then
                    begin
                    begin
+                      if pointerprefix then
+                        PTypeList.Add('P'+p^.p2^.str);
                      write(outfile,TypeName(p^.p2^.p));
                      write(outfile,TypeName(p^.p2^.p));
                    end
                    end
                  else
                  else
                    begin
                    begin
-                      writeln(outfile,'record');
+                      if packrecords then
+                        writeln(outfile,'packed record')
+                      else
+                        writeln(outfile,'record');
                       shift(3);
                       shift(3);
                       hp1:=p^.p1;
                       hp1:=p^.p1;
 
 
@@ -1046,7 +1079,10 @@ program h2pas;
                  else
                  else
                    begin
                    begin
                       inc(typedef_level);
                       inc(typedef_level);
-                      writeln(outfile,'record');
+                      if packrecords then
+                        writeln(outfile,'packed record')
+                      else
+                        writeln(outfile,'record');
                       shift(2);
                       shift(2);
                       writeln(outfile,aktspace,'case longint of');
                       writeln(outfile,aktspace,'case longint of');
                       shift(3);
                       shift(3);
@@ -1286,7 +1322,7 @@ begin
          begin
          begin
          write(outfile,aktspace);
          write(outfile,aktspace);
          if not IsExtern then
          if not IsExtern then
-         write(extfile,aktspace);
+         write(implemfile,aktspace);
          end;
          end;
          (* distinguish between procedure and function *)
          (* distinguish between procedure and function *)
          if assigned(yyv[yysp-4]) then
          if assigned(yyv[yysp-4]) then
@@ -1298,9 +1334,9 @@ begin
          write_args(outfile,yyv[yysp-2]^.p1^.p1^.p2);
          write_args(outfile,yyv[yysp-2]^.p1^.p1^.p2);
          if not IsExtern then
          if not IsExtern then
          begin
          begin
-         write(extfile,'procedure ',yyv[yysp-2]^.p1^.p2^.p);
+         write(implemfile,'procedure ',yyv[yysp-2]^.p1^.p2^.p);
          if assigned(yyv[yysp-2]^.p1^.p1^.p2) then
          if assigned(yyv[yysp-2]^.p1^.p1^.p2) then
-         write_args(extfile,yyv[yysp-2]^.p1^.p1^.p2);
+         write_args(implemfile,yyv[yysp-2]^.p1^.p1^.p2);
          end;
          end;
          end
          end
          else
          else
@@ -1313,11 +1349,11 @@ begin
          write_p_a_def(outfile,yyv[yysp-2]^.p1^.p1^.p1,yyv[yysp-4]);
          write_p_a_def(outfile,yyv[yysp-2]^.p1^.p1^.p1,yyv[yysp-4]);
          if not IsExtern then
          if not IsExtern then
          begin
          begin
-         write(extfile,'function ',yyv[yysp-2]^.p1^.p2^.p);
+         write(implemfile,'function ',yyv[yysp-2]^.p1^.p2^.p);
          if assigned(yyv[yysp-2]^.p1^.p1^.p2) then
          if assigned(yyv[yysp-2]^.p1^.p1^.p2) then
-         write_args(extfile,yyv[yysp-2]^.p1^.p1^.p2);
-         write(extfile,':');
-         write_p_a_def(extfile,yyv[yysp-2]^.p1^.p1^.p1,yyv[yysp-4]);
+         write_args(implemfile,yyv[yysp-2]^.p1^.p1^.p2);
+         write(implemfile,':');
+         write_p_a_def(implemfile,yyv[yysp-2]^.p1^.p1^.p1,yyv[yysp-4]);
          end;
          end;
          end;
          end;
          if assigned(yyv[yysp-1]) then
          if assigned(yyv[yysp-1]) then
@@ -1341,10 +1377,10 @@ begin
          writeln(outfile,';');
          writeln(outfile,';');
          if not IsExtern then
          if not IsExtern then
          begin
          begin
-         writeln(extfile,';');
-         writeln(extfile,aktspace,'begin');
-         writeln(extfile,aktspace,'  { You must implemented this function }');
-         writeln(extfile,aktspace,'end;');
+         writeln(implemfile,';');
+         writeln(implemfile,aktspace,'begin');
+         writeln(implemfile,aktspace,'  { You must implement this function }');
+         writeln(implemfile,aktspace,'end;');
          end;
          end;
          end;
          end;
          IsExtern:=false;
          IsExtern:=false;
@@ -1437,6 +1473,9 @@ begin
          TN:=TypeName(yyv[yysp-1]^.str);
          TN:=TypeName(yyv[yysp-1]^.str);
          PN:=PointerName(yyv[yysp-1]^.str);
          PN:=PointerName(yyv[yysp-1]^.str);
          if UsePPointers then writeln(outfile,aktspace,PN,' = ^',TN,';');
          if UsePPointers then writeln(outfile,aktspace,PN,' = ^',TN,';');
+         if PackRecords then
+         writeln(outfile, aktspace, TN, ' = packed record')
+         else
          writeln(outfile, aktspace, TN, ' = record');
          writeln(outfile, aktspace, TN, ' = record');
          writeln(outfile, aktspace, '    {undefined structure}');
          writeln(outfile, aktspace, '    {undefined structure}');
          writeln(outfile, aktspace, '  end;');
          writeln(outfile, aktspace, '  end;');
@@ -1630,39 +1669,39 @@ begin
          if not stripinfo then
          if not stripinfo then
          begin
          begin
          writeln (outfile,aktspace,'{ was #define dname(params) para_def_expr }');
          writeln (outfile,aktspace,'{ was #define dname(params) para_def_expr }');
-         writeln (extfile,aktspace,'{ was #define dname(params) para_def_expr }');
+         writeln (implemfile,aktspace,'{ was #define dname(params) para_def_expr }');
          if assigned(yyv[yysp-3]) then
          if assigned(yyv[yysp-3]) then
          begin
          begin
          writeln (outfile,aktspace,'{ argument types are unknown }');
          writeln (outfile,aktspace,'{ argument types are unknown }');
-         writeln (extfile,aktspace,'{ argument types are unknown }');
+         writeln (implemfile,aktspace,'{ argument types are unknown }');
          end;
          end;
          if not assigned(yyv[yysp-1]^.p3) then
          if not assigned(yyv[yysp-1]^.p3) then
          begin
          begin
          writeln(outfile,aktspace,'{ return type might be wrong }   ');
          writeln(outfile,aktspace,'{ return type might be wrong }   ');
-         writeln(extfile,aktspace,'{ return type might be wrong }   ');
+         writeln(implemfile,aktspace,'{ return type might be wrong }   ');
          end;
          end;
          end;
          end;
          block_type:=bt_func;
          block_type:=bt_func;
          write(outfile,aktspace,'function ',yyv[yysp-5]^.p);
          write(outfile,aktspace,'function ',yyv[yysp-5]^.p);
-         write(extfile,aktspace,'function ',yyv[yysp-5]^.p);
+         write(implemfile,aktspace,'function ',yyv[yysp-5]^.p);
          
          
          if assigned(yyv[yysp-3]) then
          if assigned(yyv[yysp-3]) then
          begin
          begin
          write(outfile,'(');
          write(outfile,'(');
-         write(extfile,'(');
+         write(implemfile,'(');
          ph:=new(presobject,init_one(t_enumdef,yyv[yysp-3]));
          ph:=new(presobject,init_one(t_enumdef,yyv[yysp-3]));
          write_def_params(outfile,ph);
          write_def_params(outfile,ph);
-         write_def_params(extfile,ph);
+         write_def_params(implemfile,ph);
          if assigned(ph) then dispose(ph,done);
          if assigned(ph) then dispose(ph,done);
          ph:=nil;
          ph:=nil;
          (* types are unknown *)
          (* types are unknown *)
          write(outfile,' : longint)');
          write(outfile,' : longint)');
-         write(extfile,' : longint)');
+         write(implemfile,' : longint)');
          end;
          end;
          if not assigned(yyv[yysp-1]^.p3) then
          if not assigned(yyv[yysp-1]^.p3) then
          begin
          begin
          writeln(outfile,' : longint;',aktspace,commentstr);
          writeln(outfile,' : longint;',aktspace,commentstr);
-         writeln(extfile,' : longint;');
+         writeln(implemfile,' : longint;');
          flush(outfile);
          flush(outfile);
          end
          end
          else
          else
@@ -1671,16 +1710,16 @@ begin
          write_type_specifier(outfile,yyv[yysp-1]^.p3);
          write_type_specifier(outfile,yyv[yysp-1]^.p3);
          writeln(outfile,';',aktspace,commentstr);
          writeln(outfile,';',aktspace,commentstr);
          flush(outfile);
          flush(outfile);
-         write(extfile,' : ');
-         write_type_specifier(extfile,yyv[yysp-1]^.p3);
-         writeln(extfile,';');
+         write(implemfile,' : ');
+         write_type_specifier(implemfile,yyv[yysp-1]^.p3);
+         writeln(implemfile,';');
          end;
          end;
          writeln(outfile);
          writeln(outfile);
          flush(outfile);
          flush(outfile);
          hp:=new(presobject,init_two(t_funcname,yyv[yysp-5],yyv[yysp-1]));
          hp:=new(presobject,init_two(t_funcname,yyv[yysp-5],yyv[yysp-1]));
-         write_funexpr(extfile,hp);
-         writeln(extfile);
-         flush(extfile);
+         write_funexpr(implemfile,hp);
+         writeln(implemfile);
+         flush(implemfile);
          if assigned(hp)then dispose(hp,done);
          if assigned(hp)then dispose(hp,done);
          
          
        end;
        end;
@@ -1731,19 +1770,19 @@ begin
          if not stripinfo then
          if not stripinfo then
          begin
          begin
          writeln (outfile,aktspace,'{ was #define dname def_expr }');
          writeln (outfile,aktspace,'{ was #define dname def_expr }');
-         writeln (extfile,aktspace,'{ was #define dname def_expr }');
+         writeln (implemfile,aktspace,'{ was #define dname def_expr }');
          end;
          end;
          block_type:=bt_func;
          block_type:=bt_func;
          write(outfile,aktspace,'function ',yyv[yysp-3]^.p);
          write(outfile,aktspace,'function ',yyv[yysp-3]^.p);
-         write(extfile,aktspace,'function ',yyv[yysp-3]^.p);
+         write(implemfile,aktspace,'function ',yyv[yysp-3]^.p);
          shift(2);
          shift(2);
          if not assigned(yyv[yysp-1]^.p3) then
          if not assigned(yyv[yysp-1]^.p3) then
          begin
          begin
          writeln(outfile,' : longint;');
          writeln(outfile,' : longint;');
          writeln(outfile,aktspace,'  { return type might be wrong }');
          writeln(outfile,aktspace,'  { return type might be wrong }');
          flush(outfile);
          flush(outfile);
-         writeln(extfile,' : longint;');
-         writeln(extfile,aktspace,'  { return type might be wrong }');
+         writeln(implemfile,' : longint;');
+         writeln(implemfile,aktspace,'  { return type might be wrong }');
          end
          end
          else
          else
          begin
          begin
@@ -1751,18 +1790,18 @@ begin
          write_type_specifier(outfile,yyv[yysp-1]^.p3);
          write_type_specifier(outfile,yyv[yysp-1]^.p3);
          writeln(outfile,';',aktspace,commentstr);
          writeln(outfile,';',aktspace,commentstr);
          flush(outfile);
          flush(outfile);
-         write(extfile,' : ');
-         write_type_specifier(extfile,yyv[yysp-1]^.p3);
-         writeln(extfile,';');
+         write(implemfile,' : ');
+         write_type_specifier(implemfile,yyv[yysp-1]^.p3);
+         writeln(implemfile,';');
          end;
          end;
          writeln(outfile);
          writeln(outfile);
          flush(outfile);
          flush(outfile);
          hp:=new(presobject,init_two(t_funcname,yyv[yysp-3],yyv[yysp-1]));
          hp:=new(presobject,init_two(t_funcname,yyv[yysp-3],yyv[yysp-1]));
-         write_funexpr(extfile,hp);
+         write_funexpr(implemfile,hp);
          popshift;
          popshift;
          dispose(hp,done);
          dispose(hp,done);
-         writeln(extfile);
-         flush(extfile);
+         writeln(implemfile);
+         flush(implemfile);
          end;
          end;
          
          
        end;
        end;
@@ -1798,7 +1837,7 @@ begin
        end;
        end;
   37 : begin
   37 : begin
          
          
-         if not is_packed then
+         if (not is_packed) and (not packrecords) then
          writeln(outfile,'{$PACKRECORDS 1}');
          writeln(outfile,'{$PACKRECORDS 1}');
          is_packed:=true;
          is_packed:=true;
          yyval:=new(presobject,init_two(t_structdef,yyv[yysp-1],yyv[yysp-2]));
          yyval:=new(presobject,init_two(t_structdef,yyv[yysp-1],yyv[yysp-2]));
@@ -1806,7 +1845,7 @@ begin
        end;
        end;
   38 : begin
   38 : begin
          
          
-         if is_packed then
+         if (is_packed) and (not packrecords) then
          writeln(outfile,'{$PACKRECORDS 4}');
          writeln(outfile,'{$PACKRECORDS 4}');
          is_packed:=false;
          is_packed:=false;
          yyval:=new(presobject,init_two(t_structdef,yyv[yysp-0],yyv[yysp-1]));
          yyval:=new(presobject,init_two(t_structdef,yyv[yysp-0],yyv[yysp-1]));
@@ -1814,7 +1853,7 @@ begin
        end;
        end;
   39 : begin
   39 : begin
          
          
-         if not is_packed then
+         if (not is_packed) and (not packrecords) then
          writeln(outfile,'{$PACKRECORDS 1}');
          writeln(outfile,'{$PACKRECORDS 1}');
          is_packed:=true;
          is_packed:=true;
          yyval:=new(presobject,init_two(t_uniondef,yyv[yysp-1],yyv[yysp-2]));
          yyval:=new(presobject,init_two(t_uniondef,yyv[yysp-1],yyv[yysp-2]));
@@ -1854,7 +1893,7 @@ begin
        end;
        end;
   46 : begin
   46 : begin
          
          
-         if not is_packed then
+         if (not is_packed) and (not packrecords)then
          writeln(outfile,'{$PACKRECORDS 1}');
          writeln(outfile,'{$PACKRECORDS 1}');
          is_packed:=true;
          is_packed:=true;
          yyval:=new(presobject,init_one(t_uniondef,yyv[yysp-1]));
          yyval:=new(presobject,init_one(t_uniondef,yyv[yysp-1]));
@@ -1867,7 +1906,7 @@ begin
        end;
        end;
   48 : begin
   48 : begin
          
          
-         if not is_packed then
+         if (not is_packed) and (not packrecords) then
          writeln(outfile,'{$PACKRECORDS 1}');
          writeln(outfile,'{$PACKRECORDS 1}');
          is_packed:=true;
          is_packed:=true;
          yyval:=new(presobject,init_one(t_structdef,yyv[yysp-1]));
          yyval:=new(presobject,init_one(t_structdef,yyv[yysp-1]));
@@ -1875,7 +1914,7 @@ begin
        end;
        end;
   49 : begin
   49 : begin
          
          
-         if is_packed then
+         if (is_packed) and (not packrecords) then
          writeln(outfile,'{$PACKRECORDS 4}');
          writeln(outfile,'{$PACKRECORDS 4}');
          is_packed:=false;
          is_packed:=false;
          yyval:=new(presobject,init_one(t_structdef,yyv[yysp-0]));
          yyval:=new(presobject,init_one(t_structdef,yyv[yysp-0]));
@@ -2062,6 +2101,7 @@ begin
        end;
        end;
   77 : begin
   77 : begin
          
          
+         (* type_specifier STAR declarator *)
          hp:=new(presobject,init_one(t_pointerdef,yyv[yysp-2]));
          hp:=new(presobject,init_one(t_pointerdef,yyv[yysp-2]));
          yyval:=new(presobject,init_two(t_arg,hp,yyv[yysp-0]));
          yyval:=new(presobject,init_two(t_arg,hp,yyv[yysp-0]));
          
          
@@ -7800,12 +7840,71 @@ begin
   line_no:=yylineno;
   line_no:=yylineno;
 end;
 end;
 
 
+procedure WriteFileHeader(var headerfile: Text);
+var
+ i: integer;
+ originalstr: string;
+begin
+{ write unit header }
+  if not includefile then
+   begin
+     writeln(headerfile,'unit ',unitname,';');
+     writeln(headerfile,'interface');
+     writeln(headerfile);
+     writeln(headerfile,'{');
+     writeln(headerfile,'  Automatically converted by H2Pas ',version,' from ',inputfilename);
+     writeln(headerfile,'  The following command line parameters were used:');
+     for i:=1 to paramcount do
+       writeln(headerfile,'    ',paramstr(i));
+     writeln(headerfile,'}');
+     writeln(headerfile);
+   end;
+  if UseName then
+   begin
+     writeln(headerfile,aktspace,'const');
+     writeln(headerfile,aktspace,'  External_library=''',libfilename,'''; {Setup as you need}');
+     writeln(headerfile);
+   end;
+  if UsePPointers then
+   begin
+     Writeln(headerfile,aktspace,'{ Pointers to basic pascal types, inserted by h2pas conversion program.}');
+     Writeln(headerfile,aktspace,'Type');
+     Writeln(headerfile,aktspace,'  PLongint  = ^Longint;');
+     Writeln(headerfile,aktspace,'  PSmallInt = ^SmallInt;');
+     Writeln(headerfile,aktspace,'  PByte     = ^Byte;');
+     Writeln(headerfile,aktspace,'  PWord     = ^Word;');
+     Writeln(headerfile,aktspace,'  PDWord    = ^DWord;');
+     Writeln(headerfile,aktspace,'  PDouble   = ^Double;');
+     Writeln(headerfile);
+   end;
+  if PTypeList.count <> 0 then 
+   Writeln(headerfile,aktspace,'Type');
+  for i:=0 to (PTypeList.Count-1) do
+   begin
+     originalstr:=copy(PTypelist[i],2,length(PTypeList[i]));
+     Writeln(headerfile,aktspace,PTypeList[i],'  = ^',originalstr,';');
+   end;
+  if not packrecords then
+   begin
+      writeln(headerfile,'{$IFDEF FPC}');
+      writeln(headerfile,'{$PACKRECORDS C}');
+      writeln(headerfile,'{$ENDIF}');
+   end;   
+  writeln(headerfile);
+end;
+
 
 
 var
 var
   SS : string;
   SS : string;
   i : longint;
   i : longint;
+  headerfile: Text;
+  finaloutfile: Text;
 begin
 begin
+  pointerprefix:=false;
 { Initialize }
 { Initialize }
+  PTypeList:=TStringList.Create;
+  PTypeList.Sorted := true;
+  PTypeList.Duplicates := dupIgnore;
   yydebug:=true;
   yydebug:=true;
   aktspace:='';
   aktspace:='';
   block_type:=bt_no;
   block_type:=bt_no;
@@ -7824,54 +7923,21 @@ begin
      writeln('file ',inputfilename,' not found!');
      writeln('file ',inputfilename,' not found!');
      halt(1);
      halt(1);
    end;
    end;
-  assign(outfile, outputfilename);
+  { This is the intermediate output file } 
+  assign(outfile, 'ext3.tmp');
   {$I-}
   {$I-}
   rewrite(outfile);
   rewrite(outfile);
   {$I+}
   {$I+}
   if ioresult<>0 then
   if ioresult<>0 then
    begin
    begin
-     writeln('file ',outputfilename,' could not be created!');
+     writeln('file ext3.tmp could not be created!');
      halt(1);
      halt(1);
    end;
    end;
-{ write unit header }
-  if not includefile then
-   begin
-     writeln(outfile,'unit ',unitname,';');
-     writeln(outfile,'interface');
-     writeln(outfile);
-     writeln(outfile,'{');
-     writeln(outfile,'  Automatically converted by H2Pas ',version,' from ',inputfilename);
-     writeln(outfile,'  The following command line parameters were used:');
-     for i:=1 to paramcount do
-       writeln(outfile,'    ',paramstr(i));
-     writeln(outfile,'}');
-     writeln(outfile);
-   end;
-  if UseName then
-   begin
-     writeln(outfile,aktspace,'const');
-     writeln(outfile,aktspace,'  External_library=''',libfilename,'''; {Setup as you need}');
-     writeln(outfile);
-   end;
-  if UsePPointers then
-   begin
-     Writeln(outfile,aktspace,'{ Pointers to basic pascal types, inserted by h2pas conversion program.}');
-     Writeln(outfile,aktspace,'Type');
-     Writeln(outfile,aktspace,'  PLongint  = ^Longint;');
-     Writeln(outfile,aktspace,'  PSmallInt = ^SmallInt;');
-     Writeln(outfile,aktspace,'  PByte     = ^Byte;');
-     Writeln(outfile,aktspace,'  PWord     = ^Word;');
-     Writeln(outfile,aktspace,'  PDWord    = ^DWord;');
-     Writeln(outfile,aktspace,'  PDouble   = ^Double;');
-     Writeln(outfile);
-   end;
-  writeln(outfile,'{$IFDEF FPC}');
-  writeln(outfile,'{$PACKRECORDS C}');
-  writeln(outfile,'{$ENDIF}');
   writeln(outfile);
   writeln(outfile);
 { Open tempfiles }
 { Open tempfiles }
-  Assign(extfile,'ext.tmp');
-  rewrite(extfile);
+  { This is where the implementation section of the unit shall be stored }
+  Assign(implemfile,'ext.tmp');
+  rewrite(implemfile);
   Assign(tempfile,'ext2.tmp');
   Assign(tempfile,'ext2.tmp');
   rewrite(tempfile);
   rewrite(tempfile);
 { Parse! }
 { Parse! }
@@ -7884,10 +7950,10 @@ begin
       writeln(outfile);
       writeln(outfile);
     end;
     end;
    { here we have a problem if a line is longer than 255 chars !! }
    { here we have a problem if a line is longer than 255 chars !! }
-   reset(extfile);
-   while not eof(extfile) do
+   reset(implemfile);
+   while not eof(implemfile) do
     begin
     begin
-      readln(extfile,SS);
+      readln(implemfile,SS);
       writeln(outfile,SS);
       writeln(outfile,SS);
     end;
     end;
    { write end of file }
    { write end of file }
@@ -7895,17 +7961,68 @@ begin
    if not(includefile) then
    if not(includefile) then
      writeln(outfile,'end.');
      writeln(outfile,'end.');
    { close and erase tempfiles }
    { close and erase tempfiles }
-   close(extfile);
-   erase(extfile);
-   close(outfile);
-   close(tempfile);
-   erase(tempfile);
+  close(implemfile);
+  erase(implemfile);
+  close(tempfile);
+  erase(tempfile);
+  flush(outfile);
+   
+  {**** generate full file ****}
+  assign(headerfile, 'ext4.tmp');
+  {$I-}
+  rewrite(headerfile);
+  {$I+}
+  if ioresult<>0 then
+    begin
+      writeln('file ext4.tmp could not be created!');
+      halt(1);
+  end;
+  WriteFileHeader(HeaderFile);
+   
+  { Final output filename } 
+  assign(finaloutfile, outputfilename);
+  {$I-}
+  rewrite(finaloutfile);
+  {$I+}
+  if ioresult<>0 then
+  begin
+     writeln('file ',outputfilename,' could not be created!');
+     halt(1);
+  end;
+  writeln(finaloutfile);
+  
+  { Read unit header file }
+  reset(headerfile);
+  while not eof(headerfile) do
+    begin
+      readln(headerfile,SS);
+      writeln(finaloutfile,SS);
+    end;
+  { Read interface and implementation file }
+  reset(outfile);
+  while not eof(outfile) do
+    begin
+      readln(outfile,SS);
+      writeln(finaloutfile,SS);
+    end;
+   
+  close(HeaderFile);
+  close(outfile);
+  close(finaloutfile);
+  erase(outfile);
+  erase(headerfile);
+   
+  PTypeList.Free;
 end.
 end.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.12  2004-08-18 19:18:18  peter
-    * recommit to get newer timestamp
+  Revision 1.13  2004-09-15 19:16:38  hajny
+    * regenerated
+
+  Revision 1.9  2004/09/08 22:21:41  carl
+    + support for creating packed records
+    * var parameter bugfixes
 
 
   Revision 1.8  2004/08/13 02:35:29  carl
   Revision 1.8  2004/08/13 02:35:29  carl
     + bugfixes with C++ comments, they are now placed above the definition
     + bugfixes with C++ comments, they are now placed above the definition