------------------------------------------------------------------------------
--                                                                          --
--                          GNATCHECK COMPONENTS                            --
--                                                                          --
--           G N A T C H E C K . R U L E S . R U L E _ T A B L E            --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
--                     Copyright (C) 2004-2006, AdaCore                     --
--                                                                          --
-- GNATCHECK  is  free  software;  you can redistribute it and/or modify it --
-- under terms of the  GNU  General Public License as published by the Free --
-- Software Foundation;  either version 2, or ( at your option)  any  later --
-- version.  GNATCHECK  is  distributed in the hope that it will be useful, --
-- but  WITHOUT  ANY  WARRANTY;   without  even  the  implied  warranty  of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details.  You should have received a copy of the --
-- GNU  General Public License distributed with GNAT; see file  COPYING. If --
-- not,  write to the  Free Software Foundation,  51 Franklin Street, Fifth --
-- Floor, Boston, MA 02110-1301, USA.                                       --
--                                                                          --
-- GNATCHECK is maintained by AdaCore (http://www.adacore.com).             --
--                                                                          --
------------------------------------------------------------------------------

--  This package defines the table for storing rules to be checked by
--  gnatcheck. For any rule the only means to get into this table is the
--  call to the Register_Rule procedure

with Table;

package Gnatcheck.Rules.Rule_Table is

   type Rule_Id is new Natural;
   No_Rule    : constant Rule_Id := Rule_Id'First;
   First_Rule : constant Rule_Id := No_Rule + 1;

   procedure Process_Rule_Option (Option : String);
   --  Processes the rule option taken from the command line or from rule
   --  configuration file.
   --
   --  The following options are supported:
   --
   --  +ALL                 - turn all the rules ON
   --  +GLOBAL              - turn all the global rules ON (tempporary
   --                         undocumented feature)
   --  -ALL                 - turn all the rules OFF
   --  -GLOBAL              - turn all the global rules OFF (tempporary
   --                         undocumented feature)
   --  +R<rule_id>[:params] - turn ON the given rule [for the given parameters
   --                         values]
   --  -R<rule_id>[:params] - turn OFF the given rule [for the given parameters
   --                         values]. At the moment the rule parameter
   --                         for -R option is not implemented, and -R option
   --                         with parameters is just ignored
   --
   --  params is a list of strings separated by a comma. No space character is
   --  allowed next to ':' or to ','.
   --
   --  <rule_id> should be the name (identifier) of a rule that is currently
   --  implemented in gnatcheck, casing is not important
   --
   --  If the actual does not correspond to any of these formats, or if
   --  <rule_id> does not correspond to any of the rules currently implemented
   --  in gnatcheck, the warning message is generated and nothing is changed in
   --  the state of the currently implemented rules

   procedure Process_Rule_File (RF_Name : String);
   --  Processes a set of rule options stored in the rule configuration file.
   --  RF_Name is the name of this rule file.
   --
   --  If file with this name does not exist, the corresponding warning message
   --  is generated.
   --
   --  The rule file may contain empty lines, Ada-style comment lines and lines
   --  containing the rule options, Rule options written in the rule file have
   --  the same syntax as rule options given in the command line (see the
   --  documentation for Process_Rule_Option, except that +/-GLOBAL rule
   --  option is not allowed in the rule configuration file), but they can be
   --  written in the free format, that is:
   --
   --  - a rule option can be written in several lines, with the spaces between
   --    the component of the rule options
   --
   --  - end-of-line (Ada-style) comments may be used
   --
   --  Each rule option in the rule file should start from a new line.
   --
   --  For any problem detected when parsing the rule file the corresponding
   --  warning message is generated. Any part of the rule file that can not be
   --  interpreted as an empty line, a comment line or a rule option is
   --  ignored. Any rule option that does not satisfy the requirements stated
   --  in the description of the rule options in documentation of
   --  Process_Rule_Option is also ignored.

   procedure Rules_Help;
   --  Outputs into Stderr the help info for all the rules currently
   --  implemented in gnatcheck

   package All_Rules is new Table.Table (
     Table_Component_Type => Rule_Access,
     Table_Index_Type     => Rule_Id,
     Table_Low_Bound      => First_Rule,
     Table_Initial        => 100,
     Table_Increment      => 100,
     Table_Name           => "Rule table");

   function Get_Rule (Rule_Name : String) return Rule_Id;
   --  Returns the Id for the rule registered under the name Rule_Name.
   --  If there is no such rule, returns No_Rule. Rule names are not
   --  case-sensitive.

   function Present (Rule : Rule_Id) return Boolean;
   --  Checks if Rule represents some existing record in the Rule Table

   procedure Turn_All_Rules_On;
   --  Turns ON all the rules currently implemented in gnatcheck

   procedure Turn_All_Global_Rules_On;
   --  Turns ON all the global rules currently implemented in gnatcheck

   procedure Turn_All_Rules_Off;
   --  Turns OFF all the rules currently implemented in gnatcheck

   procedure Turn_All_Global_Rules_Off;
   --  Turns OFF all the global rules currently implemented in gnatcheck

   procedure Set_Rule_State (For_Rule : Rule_Id; To_State : Rule_States);
   --  Sets the state of the argument rule. Requires Present (For_Rule)

end Gnatcheck.Rules.Rule_Table;
