X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fada%2Fg-awk.ads;h=a854489a8e258f91abbbec4afde826f5dd3110e5;hb=169337519eece470dd1e178a4356030a6c845b37;hp=9ac484f6e8242057c1272d2d2b115f8953cdbd6e;hpb=83cce46b47d48de4c71b02a20f5bf36296a48568;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/ada/g-awk.ads b/gcc/ada/g-awk.ads index 9ac484f6e82..a854489a8e2 100644 --- a/gcc/ada/g-awk.ads +++ b/gcc/ada/g-awk.ads @@ -6,9 +6,7 @@ -- -- -- S p e c -- -- -- --- $Revision: 1.10 $ --- -- --- Copyright (C) 2000 Ada Core Technologies, Inc. -- +-- Copyright (C) 2000-2006, AdaCore -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -18,8 +16,8 @@ -- 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, 59 Temple Place - Suite 330, Boston, -- --- MA 02111-1307, USA. -- +-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, -- +-- Boston, MA 02110-1301, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- @@ -28,10 +26,11 @@ -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- --- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). -- +-- GNAT was originally developed by the GNAT team at New York University. -- +-- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ --- + -- This is an AWK-like unit. It provides an easy interface for parsing one -- or more files containing formatted data. The file can be viewed seen as -- a database where each record is a line and a field is a data element in @@ -39,7 +38,7 @@ -- that a record cannot span multiple lines. The operating procedure is to -- read files line by line, with each line being presented to the user of -- the package. The interface provides services to access specific fields --- in the line. Thus it is possible to control actions takn on a line based +-- in the line. Thus it is possible to control actions taken on a line based -- on values of some fields. This can be achieved directly or by registering -- callbacks triggered on programmed conditions. -- @@ -84,8 +83,8 @@ -- -- Examples of these three approaches appear below -- --- There is many ways to use this package. The following discussion shows --- three approaches, using the three iterator forms, to using this package. +-- There are many ways to use this package. The following discussion shows +-- three approaches to using this package, using the three iterator forms. -- All examples will use the following file (computer.db): -- -- Pluton;Windows-NT;Pentium III @@ -188,31 +187,30 @@ with GNAT.Regpat; package GNAT.AWK is Session_Error : exception; - -- Raised when a Session is reused but is not closed. + -- Raised when a Session is reused but is not closed File_Error : exception; - -- Raised when there is a file problem (see below). + -- Raised when there is a file problem (see below) End_Error : exception; -- Raised when an attempt is made to read beyond the end of the last -- file of a session. Field_Error : exception; - -- Raised when accessing a field value which does not exist. + -- Raised when accessing a field value which does not exist Data_Error : exception; - -- Raised when it is not possible to convert a field value to a specific - -- type. + -- Raised when it is impossible to convert a field value to a specific type type Count is new Natural; type Widths_Set is array (Positive range <>) of Positive; - -- Used to store a set of columns widths. + -- Used to store a set of columns widths Default_Separators : constant String := " " & ASCII.HT; Use_Current : constant String := ""; - -- Value used when no separator or filename is specified in iterators. + -- Value used when no separator or filename is specified in iterators type Session_Type is limited private; -- This is the main exported type. A session is used to keep the state of @@ -244,7 +242,9 @@ package GNAT.AWK is procedure Set_Field_Separators (Separators : String := Default_Separators; - Session : Session_Type := Current_Session); + Session : Session_Type); + procedure Set_Field_Separators + (Separators : String := Default_Separators); -- Set the field separators. Each character in the string is a field -- separator. When a line is read it will be split by field using the -- separators set here. Separators can be changed at any point and in this @@ -255,13 +255,18 @@ package GNAT.AWK is procedure Set_FS (Separators : String := Default_Separators; - Session : Session_Type := Current_Session) + Session : Session_Type) renames Set_Field_Separators; - -- FS is the AWK abbreviation for above service. + procedure Set_FS + (Separators : String := Default_Separators) + renames Set_Field_Separators; + -- FS is the AWK abbreviation for above service procedure Set_Field_Widths (Field_Widths : Widths_Set; - Session : Session_Type := Current_Session); + Session : Session_Type); + procedure Set_Field_Widths + (Field_Widths : Widths_Set); -- This is another way to split a line by giving the length (in number of -- characters) of each field in a line. Field widths can be changed at any -- point and in this case the current line is split according to the new @@ -272,7 +277,9 @@ package GNAT.AWK is procedure Add_File (Filename : String; - Session : Session_Type := Current_Session); + Session : Session_Type); + procedure Add_File + (Filename : String); -- Add Filename to the list of file to be processed. There is no limit on -- the number of files that can be added. Files are processed in the order -- they have been added (i.e. the filename list is FIFO). If Filename does @@ -282,7 +289,11 @@ package GNAT.AWK is (Directory : String; Filenames : String; Number_Of_Files_Added : out Natural; - Session : Session_Type := Current_Session); + Session : Session_Type); + procedure Add_Files + (Directory : String; + Filenames : String; + Number_Of_Files_Added : out Natural); -- Add all files matching the regular expression Filenames in the specified -- directory to the list of file to be processed. There is no limit on -- the number of files that can be added. Each file is processed in @@ -295,50 +306,60 @@ package GNAT.AWK is ------------------------------------- function Number_Of_Fields - (Session : Session_Type := Current_Session) - return Count; + (Session : Session_Type) return Count; + function Number_Of_Fields + return Count; + pragma Inline (Number_Of_Fields); -- Returns the number of fields in the current record. It returns 0 when -- no file is being processed. function NF - (Session : Session_Type := Current_Session) - return Count + (Session : Session_Type) return Count + renames Number_Of_Fields; + function NF + return Count renames Number_Of_Fields; - -- AWK abbreviation for above service. + -- AWK abbreviation for above service function Number_Of_File_Lines - (Session : Session_Type := Current_Session) - return Count; + (Session : Session_Type) return Count; + function Number_Of_File_Lines + return Count; + pragma Inline (Number_Of_File_Lines); -- Returns the current line number in the processed file. It returns 0 when -- no file is being processed. - function FNR - (Session : Session_Type := Current_Session) - return Count renames Number_Of_File_Lines; - -- AWK abbreviation for above service. + function FNR (Session : Session_Type) return Count + renames Number_Of_File_Lines; + function FNR return Count + renames Number_Of_File_Lines; + -- AWK abbreviation for above service function Number_Of_Lines - (Session : Session_Type := Current_Session) - return Count; + (Session : Session_Type) return Count; + function Number_Of_Lines + return Count; + pragma Inline (Number_Of_Lines); -- Returns the number of line processed until now. This is equal to number -- of line in each already processed file plus FNR. It returns 0 when -- no file is being processed. - function NR - (Session : Session_Type := Current_Session) - return Count + function NR (Session : Session_Type) return Count renames Number_Of_Lines; - -- AWK abbreviation for above service. + function NR return Count + renames Number_Of_Lines; + -- AWK abbreviation for above service function Number_Of_Files - (Session : Session_Type := Current_Session) - return Natural; + (Session : Session_Type) return Natural; + function Number_Of_Files + return Natural; + pragma Inline (Number_Of_Files); -- Returns the number of files associated with Session. This is the total -- number of files added with Add_File and Add_Files services. - function File - (Session : Session_Type := Current_Session) - return String; + function File (Session : Session_Type) return String; + function File return String; -- Returns the name of the file being processed. It returns the empty -- string when no file is being processed. @@ -348,24 +369,27 @@ package GNAT.AWK is function Field (Rank : Count; - Session : Session_Type := Current_Session) - return String; + Session : Session_Type) return String; + function Field + (Rank : Count) return String; -- Returns field number Rank value of the current record. If Rank = 0 it -- returns the current record (i.e. the line as read in the file). It -- raises Field_Error if Rank > NF or if Session is not open. function Field (Rank : Count; - Session : Session_Type := Current_Session) - return Integer; + Session : Session_Type) return Integer; + function Field + (Rank : Count) return Integer; -- Returns field number Rank value of the current record as an integer. It -- raises Field_Error if Rank > NF or if Session is not open. It -- raises Data_Error if the field value cannot be converted to an integer. function Field (Rank : Count; - Session : Session_Type := Current_Session) - return Float; + Session : Session_Type) return Float; + function Field + (Rank : Count) return Float; -- Returns field number Rank value of the current record as a float. It -- raises Field_Error if Rank > NF or if Session is not open. It -- raises Data_Error if the field value cannot be converted to a float. @@ -374,8 +398,11 @@ package GNAT.AWK is type Discrete is (<>); function Discrete_Field (Rank : Count; - Session : Session_Type := Current_Session) - return Discrete; + Session : Session_Type) return Discrete; + generic + type Discrete is (<>); + function Discrete_Field_Current_Session + (Rank : Count) return Discrete; -- Returns field number Rank value of the current record as a type -- Discrete. It raises Field_Error if Rank > NF. It raises Data_Error if -- the field value cannot be converted to type Discrete. @@ -410,7 +437,11 @@ package GNAT.AWK is (Field : Count; Pattern : String; Action : Action_Callback; - Session : Session_Type := Current_Session); + Session : Session_Type); + procedure Register + (Field : Count; + Pattern : String; + Action : Action_Callback); -- Register an Action associated with a Pattern. The pattern here is a -- simple string that must match exactly the field number specified. @@ -418,7 +449,11 @@ package GNAT.AWK is (Field : Count; Pattern : GNAT.Regpat.Pattern_Matcher; Action : Action_Callback; - Session : Session_Type := Current_Session); + Session : Session_Type); + procedure Register + (Field : Count; + Pattern : GNAT.Regpat.Pattern_Matcher; + Action : Action_Callback); -- Register an Action associated with a Pattern. The pattern here is a -- simple regular expression which must match the field number specified. @@ -426,7 +461,11 @@ package GNAT.AWK is (Field : Count; Pattern : GNAT.Regpat.Pattern_Matcher; Action : Match_Action_Callback; - Session : Session_Type := Current_Session); + Session : Session_Type); + procedure Register + (Field : Count; + Pattern : GNAT.Regpat.Pattern_Matcher; + Action : Match_Action_Callback); -- Same as above but it pass the set of matches to the action -- procedure. This is useful to analyse further why and where a regular -- expression did match. @@ -434,7 +473,10 @@ package GNAT.AWK is procedure Register (Pattern : Pattern_Callback; Action : Action_Callback; - Session : Session_Type := Current_Session); + Session : Session_Type); + procedure Register + (Pattern : Pattern_Callback; + Action : Action_Callback); -- Register an Action associated with a Pattern. The pattern here is a -- function that must return a boolean. Action callback will be called if -- the pattern callback returns True and nothing will happen if it is @@ -443,7 +485,9 @@ package GNAT.AWK is procedure Register (Action : Action_Callback; - Session : Session_Type := Current_Session); + Session : Session_Type); + procedure Register + (Action : Action_Callback); -- Register an Action that will be called for every line. This is -- equivalent to a Pattern_Callback function always returning True. @@ -454,7 +498,10 @@ package GNAT.AWK is procedure Parse (Separators : String := Use_Current; Filename : String := Use_Current; - Session : Session_Type := Current_Session); + Session : Session_Type); + procedure Parse + (Separators : String := Use_Current; + Filename : String := Use_Current); -- Launch the iterator, it will read every line in all specified -- session's files. Registered callbacks are then called if the associated -- pattern match. It is possible to specify a filename and a set of @@ -494,7 +541,10 @@ package GNAT.AWK is procedure Open (Separators : String := Use_Current; Filename : String := Use_Current; - Session : Session_Type := Current_Session); + Session : Session_Type); + procedure Open + (Separators : String := Use_Current; + Filename : String := Use_Current); -- Open the first file and initialize the unit. This must be called once -- before using Get_Line. It is possible to specify a filename and a set of -- separators directly. This offer a quick way to parse a single file. @@ -505,7 +555,9 @@ package GNAT.AWK is procedure Get_Line (Callbacks : Callback_Mode := None; - Session : Session_Type := Current_Session); + Session : Session_Type); + procedure Get_Line + (Callbacks : Callback_Mode := None); -- Read a line from the current input file. If the file index is at the -- end of the current input file (i.e. End_Of_File is True) then the -- following file is opened. If there is no more file to be processed, @@ -523,17 +575,20 @@ package GNAT.AWK is -- This procedure can be used from a subprogram called by procedure Parse -- or by an instantiation of For_Every_Line (see below). - function End_Of_Data - (Session : Session_Type := Current_Session) - return Boolean; + (Session : Session_Type) return Boolean; + function End_Of_Data + return Boolean; + pragma Inline (End_Of_Data); -- Returns True if there is no more data to be processed in Session. It -- means that the latest session's file is being processed and that -- there is no more data to be read in this file (End_Of_File is True). function End_Of_File - (Session : Session_Type := Current_Session) - return Boolean; + (Session : Session_Type) return Boolean; + function End_Of_File + return Boolean; + pragma Inline (End_Of_File); -- Returns True when there is no more data to be processed on the current -- session's file. @@ -555,7 +610,13 @@ package GNAT.AWK is (Separators : String := Use_Current; Filename : String := Use_Current; Callbacks : Callback_Mode := None; - Session : Session_Type := Current_Session); + Session : Session_Type); + generic + with procedure Action (Quit : in out Boolean); + procedure For_Every_Line_Current_Session + (Separators : String := Use_Current; + Filename : String := Use_Current; + Callbacks : Callback_Mode := None); -- This is another iterator. Action will be called for each new -- record. The iterator's termination can be controlled by setting Quit -- to True. It is by default set to False. It is possible to specify a @@ -569,13 +630,6 @@ package GNAT.AWK is -- open. private - pragma Inline (End_Of_File); - pragma Inline (End_Of_Data); - pragma Inline (Number_Of_Fields); - pragma Inline (Number_Of_Lines); - pragma Inline (Number_Of_Files); - pragma Inline (Number_Of_File_Lines); - type Session_Data; type Session_Data_Access is access Session_Data;