AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages
Ada FAQ


Join >
Home >
Articles >
Getting Started >
Ada FAQ >
Source Treasury >
Books & Tutorials >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Back
Ada Libraries - Debug
Libraries of Ada Code

This is a very simple package, but I think it is pretty cool. The package supplies the basic put routines (for char & string), but output is printed only if a debug flag is on.

So far this is all commonplace.

The nice feature is that when the program starts (actually, when the package is elaborated) the package checks all the command line arguments, and if it finds -d or -D among them, it automagically sets on the debug printing.

It is nice for quick and dirty work, and may be useful for students who are not familiar with Ada.Command_Line.




-- Purpose:   Implements debug print routines. If a program that with's this package, has a "-d"/"-D" command line arg,
--            debug printing will be active. otherwise debug output is suppressed. User code can switch between modes.
--  Exported Routines:
--       * Put(Char/String)       - Output debug info
--       * Quite/Verobse          - Switch mode
----------------------------------------------------------------------------------------------------------------------------
-- Log: 
--        10/7/2000 - First hack at it
----------------------------------------------------------------------------------------------------------------------------


package Debug is

   
   procedure Put(c:character);
   procedure Put(s:string);
   procedure Quiet;
   procedure Verbose;

end;


with Ada.Text_Io;
with Ada.Command_Line;
use  Ada.Command_Line;

package body Debug is


   Active:Boolean:=FALSE;

   ---------
   -- Put --
   ---------

   procedure Put (c:character) is
   begin
      if Active then
         Ada.Text_Io.Put(c);
      end if;
   end Put;
   pragma Inline(put);

   ---------
   -- Put --
   ---------

   procedure Put (s:string) is
   begin
      if Active then
         Ada.Text_Io.Put(s);
      end if;
   end Put;
   pragma Inline(Put);

   -----------
   -- Quiet --
   -----------

   procedure Quiet is
   begin
      Active:=FALSE;
   end Quiet;

   -------------
   -- Verbose --
   -------------

   procedure Verbose is
   begin
      Active:=TRUE;
   end Verbose;

begin
   for i in 1..Argument_Count loop
      declare
         Arg:String:=Argument(i);
      begin
         if Arg'length=2 then
            if (Arg="-d") or (Arg="-D") then
               Verbose;
            end if;
         end if;
      end;
   end loop;
end Debug;


(c) 1998-2004 All Rights Reserved David Botton