home *** CD-ROM | disk | FTP | other *** search
/ Hacker / Hacker.iso / HACKER / DECOMP / DECAF / decaf.adb < prev    next >
Encoding:
Text File  |  1996-09-19  |  4.8 KB  |  160 lines

  1. --
  2. -- Copyright (C) 1996 Ada Resource Association (ARA), Columbus, Ohio.
  3. -- Author: Gilles Demailly
  4. --
  5. --
  6. -- Permission to use, copy, modify, and distribute this software and its
  7. -- documentation for any purpose and without fee is hereby granted,
  8. -- provided that the above copyright and authorship notice appear in all
  9. -- copies and that both that copyright notice and this permission notice
  10. -- appear in supporting documentation.
  11. -- 
  12. -- The ARA makes no representations about the suitability of this software
  13. -- for any purpose.  It is provided "as is" without express
  14. -- or implied warranty.
  15. -- 
  16.  
  17. --
  18. -- This is the main program Decaf
  19. -- to generate an executable, use gnatmake decaf (with Gnat)
  20. --
  21. -- this main program just get and check the different online parameters
  22. -- and gives hand to the Class_File package.
  23. --
  24.  
  25. with Ada.Command_Line;
  26. with Ada.Text_Io;
  27.  
  28. with Ada.Strings.Unbounded;
  29. use  Ada.Strings.Unbounded;
  30.  
  31. with Byte_Utilities;
  32. use Byte_Utilities;
  33.  
  34. with Class_File;
  35.  
  36. procedure decaf is
  37.  
  38.    The_File  : Byte_Utilities.File_Type;
  39.    The_Class : Class_File.Class_File;
  40.    Arguments : Natural;
  41.    File_Name : Unbounded_String := Null_Unbounded_String;
  42.    Body_Gen  : Boolean          := False;
  43.    Stk_Gen   : Boolean          := False;
  44.    Ada_Gen   : Boolean          := False;
  45.    
  46.    -- Display Decaf Help message
  47.    -----------------------------
  48.    procedure Decaf_Help is 
  49.    begin
  50.       Ada.Text_Io.Put_Line
  51.          ("Usage : decaf [-b] [-ada] [-stk] name(s)");
  52.       Ada.Text_Io.New_Line;
  53.       Ada.Text_Io.Put_Line
  54.          ("where options include:");
  55.       Ada.Text_Io.Put_Line
  56.          ("   -b    : Provides a body (this current version provides only");
  57.       Ada.Text_Io.Put_Line
  58.          ("           the methods instructions like javap)");
  59.       Ada.Text_Io.Put_Line
  60.          ("   -ada  : Ouputs Ada code (not yet available)");
  61.       Ada.Text_Io.Put_Line
  62.          ("   -stk  : Ouputs Smalltalk code (not yet available)");
  63.       Ada.Text_Io.Put_Line
  64.          (" name(s) : Java Class file name, including extension and");
  65.       Ada.Text_Io.Put_Line
  66.          ("           full path if necessary. On Unix, *.class may");
  67.       Ada.Text_Io.Put_Line
  68.          ("           be used.");
  69.    end Decaf_Help;
  70.    
  71. begin
  72.  
  73.    -- get the argument number
  74.    --------------------------
  75.    Arguments := Ada.Command_Line.Argument_Count;
  76.    
  77.    if Arguments < 1 then
  78.    
  79.       -- Decaf needs at least one argument,
  80.       -- give the user some informations
  81.       -------------------------------------
  82.       Decaf_Help;
  83.  
  84.    else
  85.    
  86.       for I in 1..Arguments loop
  87.          if Ada.Command_Line.Argument (I) = "-b" then
  88.             Body_Gen := True;
  89.          elsif Ada.Command_Line.Argument (I) = "-ada" then
  90.             Ada_Gen  := True;
  91.          elsif Ada.Command_Line.Argument (I) = "-stk" then
  92.             Stk_Gen  := True;
  93.          else
  94.             begin
  95.             
  96.                -- Open the Java Class file
  97.                ---------------------------
  98.                Byte_Utilities.Open
  99.                   (The_File,
  100.                    In_File, 
  101.                    Big_Endian, 
  102.                    Ada.Command_Line.Argument (I));
  103.    
  104.                -- Read the class from the file
  105.                -------------------------------
  106.                The_Class := Class_File.Read_Class (The_File);
  107.    
  108.                -- Close the file
  109.                -----------------
  110.                Byte_Utilities.Close (The_File);
  111.  
  112.                if Ada_Gen then
  113.                   if Body_Gen then
  114.                      Class_File.Display_Ada_Body (The_Class);
  115.                   else
  116.                      Class_File.Display_Ada_Spec (The_Class);
  117.                   end if;
  118.                end if;
  119.                
  120.                if Stk_Gen then
  121.                   if Body_Gen then
  122.                      Class_File.Display_Stk_Body (The_Class);
  123.                   else
  124.                      Class_File.Display_Stk_Spec (The_Class);
  125.                   end if;
  126.                end if;
  127.                
  128.                if not (Ada_Gen or Stk_Gen) then
  129.                   Class_File.Display_Java_Spec (The_Class, Body_Gen);
  130.                end if;
  131.             
  132.             exception
  133.  
  134.                when others => 
  135.                   Ada.Text_Io.Put_Line 
  136.                      ("the file " & Ada.Command_Line.Argument (I) &
  137.                       " is not a correct Java class file.");
  138.             end;
  139.          end if;
  140.       end loop;
  141.       
  142.    end if;
  143.  
  144. exception
  145.  
  146.    -- How did you managed to get there ?
  147.    -- Is there a bug in Decaf ?
  148.    -- ... anyway I will solve the problem :-)
  149.    ------------------------------------------
  150.    when others =>
  151.       Ada.Text_Io.Put_Line
  152.          (" Unexpected Exception raised in Decaf");
  153.       Ada.Text_Io.Put_Line
  154.          (" Please contact G. Demailly at 100704.2016@compuserve.com,");
  155.       Ada.Text_Io.Put_Line
  156.          (" mention in your subject header <Decaf Problem> - Thanks.");
  157.       Ada.Text_Io.New_Line;
  158.  
  159. end decaf;
  160.