home *** CD-ROM | disk | FTP | other *** search
- --
- -- Copyright (C) 1996 Ada Resource Association (ARA), Columbus, Ohio.
- -- Author: Gilles Demailly
- --
- --
- -- Permission to use, copy, modify, and distribute this software and its
- -- documentation for any purpose and without fee is hereby granted,
- -- provided that the above copyright and authorship notice appear in all
- -- copies and that both that copyright notice and this permission notice
- -- appear in supporting documentation.
- --
- -- The ARA makes no representations about the suitability of this software
- -- for any purpose. It is provided "as is" without express
- -- or implied warranty.
- --
-
- --
- -- This is the main program Decaf
- -- to generate an executable, use gnatmake decaf (with Gnat)
- --
- -- this main program just get and check the different online parameters
- -- and gives hand to the Class_File package.
- --
-
- with Ada.Command_Line;
- with Ada.Text_Io;
-
- with Ada.Strings.Unbounded;
- use Ada.Strings.Unbounded;
-
- with Byte_Utilities;
- use Byte_Utilities;
-
- with Class_File;
-
- procedure decaf is
-
- The_File : Byte_Utilities.File_Type;
- The_Class : Class_File.Class_File;
- Arguments : Natural;
- File_Name : Unbounded_String := Null_Unbounded_String;
- Body_Gen : Boolean := False;
- Stk_Gen : Boolean := False;
- Ada_Gen : Boolean := False;
-
- -- Display Decaf Help message
- -----------------------------
- procedure Decaf_Help is
- begin
- Ada.Text_Io.Put_Line
- ("Usage : decaf [-b] [-ada] [-stk] name(s)");
- Ada.Text_Io.New_Line;
- Ada.Text_Io.Put_Line
- ("where options include:");
- Ada.Text_Io.Put_Line
- (" -b : Provides a body (this current version provides only");
- Ada.Text_Io.Put_Line
- (" the methods instructions like javap)");
- Ada.Text_Io.Put_Line
- (" -ada : Ouputs Ada code (not yet available)");
- Ada.Text_Io.Put_Line
- (" -stk : Ouputs Smalltalk code (not yet available)");
- Ada.Text_Io.Put_Line
- (" name(s) : Java Class file name, including extension and");
- Ada.Text_Io.Put_Line
- (" full path if necessary. On Unix, *.class may");
- Ada.Text_Io.Put_Line
- (" be used.");
- end Decaf_Help;
-
- begin
-
- -- get the argument number
- --------------------------
- Arguments := Ada.Command_Line.Argument_Count;
-
- if Arguments < 1 then
-
- -- Decaf needs at least one argument,
- -- give the user some informations
- -------------------------------------
- Decaf_Help;
-
- else
-
- for I in 1..Arguments loop
- if Ada.Command_Line.Argument (I) = "-b" then
- Body_Gen := True;
- elsif Ada.Command_Line.Argument (I) = "-ada" then
- Ada_Gen := True;
- elsif Ada.Command_Line.Argument (I) = "-stk" then
- Stk_Gen := True;
- else
- begin
-
- -- Open the Java Class file
- ---------------------------
- Byte_Utilities.Open
- (The_File,
- In_File,
- Big_Endian,
- Ada.Command_Line.Argument (I));
-
- -- Read the class from the file
- -------------------------------
- The_Class := Class_File.Read_Class (The_File);
-
- -- Close the file
- -----------------
- Byte_Utilities.Close (The_File);
-
- if Ada_Gen then
- if Body_Gen then
- Class_File.Display_Ada_Body (The_Class);
- else
- Class_File.Display_Ada_Spec (The_Class);
- end if;
- end if;
-
- if Stk_Gen then
- if Body_Gen then
- Class_File.Display_Stk_Body (The_Class);
- else
- Class_File.Display_Stk_Spec (The_Class);
- end if;
- end if;
-
- if not (Ada_Gen or Stk_Gen) then
- Class_File.Display_Java_Spec (The_Class, Body_Gen);
- end if;
-
- exception
-
- when others =>
- Ada.Text_Io.Put_Line
- ("the file " & Ada.Command_Line.Argument (I) &
- " is not a correct Java class file.");
- end;
- end if;
- end loop;
-
- end if;
-
- exception
-
- -- How did you managed to get there ?
- -- Is there a bug in Decaf ?
- -- ... anyway I will solve the problem :-)
- ------------------------------------------
- when others =>
- Ada.Text_Io.Put_Line
- (" Unexpected Exception raised in Decaf");
- Ada.Text_Io.Put_Line
- (" Please contact G. Demailly at 100704.2016@compuserve.com,");
- Ada.Text_Io.Put_Line
- (" mention in your subject header <Decaf Problem> - Thanks.");
- Ada.Text_Io.New_Line;
-
- end decaf;
-