LTP GCOV extension - code coverage report
Current view: directory - fcode-utils/toke - nextfcode.c
Test: FCode suite 1.0.2
Date: 2006-10-30 Instrumented lines: 106
Code covered: 100.0 % Executed lines: 106
Legend: not executed executed converted-only

       1                 : /*
       2                 :  *                     OpenBIOS - free your system!
       3                 :  *                         ( FCode tokenizer )
       4                 :  *
       5                 :  *  This program is part of a free implementation of the IEEE 1275-1994
       6                 :  *  Standard for Boot (Initialization Configuration) Firmware.
       7                 :  *
       8                 :  *  Copyright (C) 2001-2005 Stefan Reinauer, <stepan@openbios.org>
       9                 :  *
      10                 :  *  This program is free software; you can redistribute it and/or modify
      11                 :  *  it under the terms of the GNU General Public License as published by
      12                 :  *  the Free Software Foundation; version 2 of the License.
      13                 :  *
      14                 :  *  This program is distributed in the hope that it will be useful,
      15                 :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17                 :  *  GNU General Public License for more details.
      18                 :  *
      19                 :  *  You should have received a copy of the GNU General Public License
      20                 :  *  along with this program; if not, write to the Free Software
      21                 :  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
      22                 :  *
      23                 :  */
      24                 : 
      25                 : /* **************************************************************************
      26                 :  *
      27                 :  *      Functions for Managing FCode Assignment Pointer and for
      28                 :  *          Detection of Overlapping-FCode Error in Tokenizer
      29                 :  *
      30                 :  *      (C) Copyright 2006 IBM Corporation.  All Rights Reserved.
      31                 :  *      Module Author:  David L. Paktor    dlpaktor@us.ibm.com
      32                 :  *
      33                 :  **************************************************************************** */
      34                 : 
      35                 : /* **************************************************************************
      36                 :  *
      37                 :  *      The fact that the user is able to specify, at any time, the
      38                 :  *          next FCode number to be assigned introduces the risk that
      39                 :  *          a symbol might inadvertently be assigned an FCode that is
      40                 :  *          still in use by another symbol, which could lead to bizarre
      41                 :  *          and hard-to-trace failures at run-time.
      42                 :  *
      43                 :  *      This module will support a means whereby to detect and report,
      44                 :  *          as an Error, overlapping FCode assignments.
      45                 :  *
      46                 :  *      The task is further complicated by the fact that, under some
      47                 :  *          circumstances, "recycling" a range of FCodes can be done
      48                 :  *          safely, and the programmer may do so intentionally.
      49                 :  *
      50                 :  *      We will define a way for the programmer to specify that FCode
      51                 :  *          assignments are being intentionally "recycled", and that
      52                 :  *          overlaps with previously-assigned FCodes are not to be
      53                 :  *          treated as Errors.  We will not attempt to analyze whether
      54                 :  *          it is, indeed, safe to do so; the programmer who does this
      55                 :  *          is presumed to be sufficiently responsible.
      56                 :  *
      57                 :  **************************************************************************** */
      58                 : 
      59                 : 
      60                 : /* **************************************************************************
      61                 :  *
      62                 :  *      Functions Exported:
      63                 :  *          reset_fcode_ranges   (Re-)Initialize the range of assignable
      64                 :  *                                   FCode numbers and clear the records
      65                 :  *                                   of prevously-assigned ranges of FCodes
      66                 :  *          list_fcode_ranges    Display a final report of assigned FCode
      67                 :  *                                   ranges at end of tokenization or when
      68                 :  *                                   the  reset_fcodes()  routine is called.
      69                 :  *          set_next_fcode       Set the start of a new Range of FCode
      70                 :  *                                   numbers to be assigned.
      71                 :  *          assigning_fcode      The next FCode number is about to be assigned;
      72                 :  *                                   test for out-of-bounds, overlap, etc.
      73                 :  *                                   errors.
      74                 :  *          bump_fcode           Increment the next FCode number prior to the
      75                 :  *                                    next assignment.
      76                 :  *
      77                 :  **************************************************************************** */
      78                 : 
      79                 : /* **************************************************************************
      80                 :  *
      81                 :  *      Revision History:
      82                 :  *          06 Jun 06  -- Need became apparent after verification test
      83                 :  *                            against existing device-drivers.
      84                 :  *              
      85                 :  *
      86                 :  **************************************************************************** */
      87                 : 
      88                 : 
      89                 : /* **************************************************************************
      90                 :  *
      91                 :  *      Still to be done:
      92                 :  *          Detect and report when the Current Range stops overlapping
      93                 :  *              one particular Range and starts overlapping another.
      94                 :  *
      95                 :  *          Detect and report when the Current Range overlaps more than
      96                 :  *              one Range at a time (e.g., if other Ranges themselves
      97                 :  *              overlap, and the Current Range is stepping through them)
      98                 :  *              but, again, only display one message per overlapped Range.
      99                 :  *
     100                 :  **************************************************************************** */
     101                 : 
     102                 : 
     103                 : 
     104                 : /* **************************************************************************
     105                 :  *
     106                 :  *          Global Variables Imported
     107                 :  *              iname              Name of current input file
     108                 :  *              lineno             Line Number within current input file
     109                 :  *
     110                 :  **************************************************************************** */
     111                 : 
     112                 : #include <string.h>
     113                 : #include <stdio.h>
     114                 : #include <stdlib.h>
     115                 : 
     116                 : #include "toke.h"
     117                 : #include "nextfcode.h"
     118                 : #include "errhandler.h"
     119                 : #include "stream.h"
     120                 : #include "scanner.h"
     121                 : 
     122                 : 
     123                 : /* **************************************************************************
     124                 :  *
     125                 :  *          Global Variables Exported
     126                 :  *              nextfcode          The next FCode-number to be assigned
     127                 :  *
     128                 :  **************************************************************************** */
     129                 : 
     130                 : u16  nextfcode;         /*  The next FCode-number to be assigned              */
     131                 : 
     132                 : /* **************************************************************************
     133                 :  *
     134                 :  *      Internal (Static) Structure:
     135                 :  *          fcode_range_t         The record of a Range of assigned FCodes
     136                 :  *
     137                 :  *   Fields:
     138                 :  *       fcr_start            FCode number at the start of a this Range
     139                 :  *       fcr_end              Last FCode number in this Range that has
     140                 :  *                                actually been assigned.  0 if none made yet.
     141                 :  *       fcr_infile           File name of where this Range was started
     142                 :  *       fcr_linenum          Line number where this Range was started
     143                 :  *       fcr_not_lapped       TRUE if an overlap error has not been reported
     144                 :  *                                against this Range.  Use this to prevent
     145                 :  *                                issuing an Error message every time an
     146                 :  *                                overlapping FCode is assigned; once per
     147                 :  *                                Range is sufficient.
     148                 :  *       fcr_next             Pointer to following entry in linked-list.
     149                 :  *
     150                 :  *   We will keep the list of assigned FCode Ranges as a forward-linked,
     151                 :  *       rather than the more usual backward-linked, list for convenience
     152                 :  *       at listing-time.  Otherwise, it doesn't make much difference.
     153                 :  *
     154                 :  **************************************************************************** */
     155                 : 
     156                 : typedef struct fcode_range
     157                 :     {
     158                 :         u16                 fcr_start;
     159                 :         u16                 fcr_end ;
     160                 :         char               *fcr_infile;
     161                 :         int                 fcr_linenum;
     162                 :         bool                fcr_not_lapped;
     163                 :         struct fcode_range *fcr_next;
     164                 :     }  fcode_range_t ;
     165                 : 
     166                 : 
     167                 : /* **************************************************************************
     168                 :  *
     169                 :  *          Internal Static Variables
     170                 :  *     ranges_exist              TRUE if FCode Ranges have been created;
     171                 :  *                                   Prevents unnecessary overlap checking.
     172                 :  *     changes_listed            TRUE if no changes to any of the Ranges
     173                 :  *                                   have taken place since the last time
     174                 :  *                                   a Listing was displayed.  Prevents
     175                 :  *                                   unnecessary repetions (e.g., if a
     176                 :  *                                    reset_fcode_ranges()  was called
     177                 :  *                                   right after an operation that causes
     178                 :  *                                   a Listing
     179                 :  *
     180                 :  *          These four apply if no FCode Ranges have been created:
     181                 :  *
     182                 :  *     range_start               First FCode in the current first (only) range.
     183                 :  *     range_end                 Last FCode in current first (only) range that
     184                 :  *                                   has actually been assigned.  0 if none yet.
     185                 :  *     first_fcr_infile          File name of where first (only) range started.
     186                 :  *     first_fcr_linenum         Line number where first (only) range started.
     187                 :  *
     188                 :  *          These two apply after FCode Ranges have been created:
     189                 :  *
     190                 :  *     first_fc_range            Pointer to the first entry in the linked
     191                 :  *                                   list of FCode Ranges.
     192                 :  *     current_fc_range          Pointer to the entry in the linked list of
     193                 :  *                                   Ranges that contains the Current Range.
     194                 :  *
     195                 :  **************************************************************************** */
     196                 : 
     197                 : static bool           ranges_exist      = FALSE;
     198                 : static bool           changes_listed    = FALSE;
     199                 : 
     200                 : static u16            range_start       = FCODE_START;
     201                 : static u16            range_end         = 0;
     202                 : static char          *first_fcr_infile  = NULL;
     203                 : static int            first_fcr_linenum = 0;
     204                 : 
     205                 : static fcode_range_t *first_fc_range    = NULL;
     206                 : static fcode_range_t *current_fc_range  = NULL;
     207                 : 
     208                 : /* **************************************************************************
     209                 :  *
     210                 :  *      Function name:  reset_fcode_ranges
     211                 :  *      Synopsis:       (Re-)Initialize the range of assignable FCode numbers
     212                 :  *                          and clear the records of prevously-assigned Ranges
     213                 :  *
     214                 :  *      Inputs:
     215                 :  *         Parameters:                  NONE
     216                 :  *         Global Variables:
     217                 :  *             iname                    Name of current input file
     218                 :  *             lineno                   Line Number within current input file
     219                 :  *         Local Static Variables:
     220                 :  *             ranges_exist             TRUE if FCode Ranges have been created
     221                 :  *             first_fc_range           Pointer to First FCode Range
     222                 :  *             current_fc_range         Pointer to the current Range
     223                 :  *
     224                 :  *      Outputs:
     225                 :  *         Returned Value:              NONE
     226                 :  *         Global Variables:
     227                 :  *             nextfcode                Initialized to Standard start value
     228                 :  *                                          for user-assigned FCodes
     229                 :  *         Local Static Variables:
     230                 :  *             ranges_exist             Cleared to FALSE
     231                 :  *             changes_listed           Reset to FALSE
     232                 :  *             range_start              Reset to Standard start value
     233                 :  *             range_end                Reset to 0
     234                 :  *             first_fcr_infile         Copy of iname
     235                 :  *             first_fcr_linenum        Copy of lineno
     236                 :  *             first_fc_range           Reset to NULL
     237                 :  *             current_fc_range         Reset to NULL
     238                 :  *         Memory Allocated
     239                 :  *             For  first_fcr_infile , which will have a copy of  iname
     240                 :  *         When Freed?
     241                 :  *             The next time this routine is called.
     242                 :  *         Memory Freed
     243                 :  *             Any FCode Ranges that were in effect will be freed, and the
     244                 :  *                 memory for their  fcr_infile  fields will be freed.
     245                 :  *             If  iname  has changed, memory for  first_fcr_infile  will
     246                 :  *                 be freed before the new copy is made.
     247                 :  *
     248                 :  *      Process Explanation:
     249                 :  *          This will be called either as part of normal initialization
     250                 :  *              or in response to a User-issued directive.
     251                 :  *          In the former case, it may be called twice:  once before any
     252                 :  *              Source is examined, and once again in response to the first
     253                 :  *              (and only to the first) invocation of an FCode-Starter, at
     254                 :  *              which time the input file name and line number will be updated.
     255                 :  *          In the latter case, the calling routine will be responsible for
     256                 :  *              displaying any Advisory Messages and listings of previously
     257                 :  *              assigned FCode Ranges.
     258                 :  *
     259                 :  **************************************************************************** */
     260                 : 
     261                 : void reset_fcode_ranges( void)
     262             403 : {
     263             403 :     if ( ranges_exist )
     264                 :     {
     265             248 :         while ( current_fc_range != NULL )
     266                 :         {
     267             212 :             current_fc_range = first_fc_range->fcr_next;
     268             212 :             free( first_fc_range->fcr_infile);
     269             212 :             free( first_fc_range);
     270             212 :             first_fc_range = current_fc_range;
     271                 :         }
     272              36 :         ranges_exist = FALSE;
     273                 :     }else{
     274             367 :         if ( first_fcr_infile != NULL )
     275                 :         {
     276             198 :             if ( strcmp( first_fcr_infile, iname) != 0 )
     277                 :             {
     278              34 :                 free( first_fcr_infile);
     279              34 :                 first_fcr_infile = NULL;
     280                 :             }
     281                 :         }
     282                 :     }
     283                 : 
     284             403 :     changes_listed    = FALSE;
     285             403 :     range_start       = FCODE_START;
     286             403 :     range_end         = 0;
     287                 : 
     288             403 :     if ( first_fcr_infile == NULL )
     289                 :     {
     290             239 :         first_fcr_infile = strdup( iname);
     291                 :     }
     292             403 :     first_fcr_linenum = lineno;
     293             403 :     nextfcode         = FCODE_START;
     294             403 : }
     295                 : 
     296                 : /* **************************************************************************
     297                 :  *
     298                 :  *      Function name:  list_fcode_ranges
     299                 :  *      Synopsis:       Display an Advisory of assigned FCode ranges at
     300                 :  *                          end of tokenization or upon reset_fcodes() 
     301                 :  *
     302                 :  *      Inputs:
     303                 :  *         Parameters:
     304                 :  *             final_tally               TRUE if printing a final tally at
     305                 :  *                                           end of tokenization.  
     306                 :  *         Global Variables:
     307                 :  *             verbose                   Do not print anything if not set.
     308                 :  *             nextfcode                 FCode next after last-assigned
     309                 :  *         Local Static Variables:
     310                 :  *             changes_listed            If TRUE, only print new-line.
     311                 :  *             ranges_exist              TRUE if more than one Range exists.
     312                 :  *             range_start               FCode at start of only range
     313                 :  *             range_end                 Last FCode in only range; 0 if none.
     314                 :  *             first_fc_range            Ptr to start of FCode Ranges list
     315                 :  *
     316                 :  *      Outputs:
     317                 :  *         Returned Value:               NONE
     318                 :  *         Local Static Variables:
     319                 :  *             changes_listed           Set to TRUE. 
     320                 :  *         Printout:
     321                 :  *            Printed to Standard Out on final tally, or to STDERR otherwise.
     322                 :  *            One of three formats:
     323                 :  *            1   No FCodes assigned.
     324                 :  *            2   Last assigned FCode = 0xXXX
     325                 :  *            3   FCodes assigned:
     326                 :  *                    [ No FCodes assigned in the range that started ... ]
     327                 :  *                    [ From 0xXXX to 0xYYY ** in the range that started ... ]
     328                 :  *                        (** = Indicator if the Range has an Overlap Error.)
     329                 :  *
     330                 :  *      Process Explanation:
     331                 :  *          This is called to complete an Advisory or Standard-Out Message
     332                 :  *              that doesn't end in a new-line.
     333                 :  *
     334                 :  *      Extraneous Remarks:
     335                 :  *          If we ever decide not to keep entries for Ranges in which no
     336                 :  *              assignments were made, let's not remove the code that lists
     337                 :  *              them.  It's harmless to keep it around, and we remain ready...
     338                 :  *
     339                 :  **************************************************************************** */
     340                 : 
     341                 : void list_fcode_ranges( bool final_tally)
     342             219 : {
     343             219 :     if ( verbose )
     344                 :     {
     345             219 :         FILE *message_dest = ( final_tally ? stdout : ERRMSG_DESTINATION );
     346             219 :         if ( changes_listed )
     347                 :         {
     348               2 :             fprintf(message_dest, "\n");
     349                 :         }else{
     350             217 :             changes_listed = TRUE;
     351                 : 
     352             217 :             if ( INVERSE(ranges_exist) )
     353                 :             {   /*  List the first and only range  */
     354             163 :                 if ( range_end == 0 )
     355                 :                 {
     356              20 :                     fprintf(message_dest, "No FCodes assigned.\n");
     357                 :                 }else{
     358             143 :                     if ( range_start == FCODE_START )
     359                 :                     {
     360             142 :                         fprintf(message_dest,
     361                 :                             "Last assigned FCode = 0x%x\n", range_end);
     362                 :                     }else{
     363               1 :                         fprintf(message_dest,
     364                 :                             "FCodes assigned:  0x%x to 0x%x\n",
     365                 :                                 range_start, range_end);
     366                 :                     }
     367                 :                 }
     368                 :                 /*  We are done listing the first and only range  */
     369                 :             }else{   /*  List the collection of Ranges  */
     370                 : 
     371                 :                 /*  Pionter to function returning void  */
     372                 :                 typedef void (*vfunct)();
     373                 : 
     374                 :                 /*  Function for the  started_at()  part of the message  */
     375                 :                 vfunct start_at_funct =
     376              54 :                     ( final_tally ? print_started_at : started_at );
     377                 : 
     378                 : 
     379              54 :                 fcode_range_t *next_range = first_fc_range;
     380                 : 
     381              54 :                 fprintf(message_dest, "FCodes assigned:\n");
     382                 : 
     383             452 :                 while ( next_range != NULL )
     384                 :                 {
     385             344 :                     if ( next_range->fcr_end == 0 )
     386                 :                     {
     387             108 :                         fprintf(message_dest, "    None assigned");
     388                 :                     }else{
     389             236 :                         fprintf(message_dest, "    From 0x%x to 0x%x",
     390                 :                             next_range->fcr_start, next_range->fcr_end );
     391             236 :                         if ( INVERSE( next_range->fcr_not_lapped) )
     392                 :                         {
     393             109 :                             fprintf(message_dest, " ***Overlap***" );
     394                 :                         }
     395                 :                     }
     396             344 :                     fprintf(message_dest, " in the range");
     397             344 :                     (*start_at_funct)(
     398                 :                         next_range->fcr_infile, next_range->fcr_linenum );
     399                 : 
     400             344 :                     next_range = next_range->fcr_next;
     401                 :                 }
     402                 :             }
     403                 :         }
     404                 :     }
     405             219 : }
     406                 : 
     407                 : 
     408                 : /* **************************************************************************
     409                 :  *
     410                 :  *      Function name:  set_next_fcode
     411                 :  *      Synopsis:       Set the start of a new Range of FCode numbers
     412                 :  *
     413                 :  *      Inputs:
     414                 :  *         Parameters:
     415                 :  *             new_fcode                 Start of the new range of FCodes
     416                 :  *         Global Variables:
     417                 :  *             nextfcode                 The next FCode-number to be assigned
     418                 :  *             iname                     Name of current input file
     419                 :  *             lineno                    Line Number within current input file
     420                 :  *         Local Static Variables:
     421                 :  *             ranges_exist              TRUE if FCode Ranges have been created
     422                 :  *             range_start               First FCode in the current (first
     423                 :  *                                           and only) range
     424                 :  *             range_end                 Last FCode in only range; 0 if none.
     425                 :  *             current_fc_range          Pointer to the current Range if there
     426                 :  *                                           are more than one.
     427                 :  *
     428                 :  *      Outputs:
     429                 :  *         Returned Value:               NONE
     430                 :  *         Global Variables:
     431                 :  *             nextfcode                 Set to the start of the new range
     432                 :  *         Local Static Variables:
     433                 :  *             ranges_exist              May be set to TRUE
     434                 :  *             first_fc_range            May be initialized
     435                 :  *             current_fc_range          May be initialized or moved
     436                 :  *             first_fcr_infile          May be updated, may be made NULL
     437                 :  *             first_fcr_linenum         May be updated, may be made irrelevant
     438                 :  *             range_start               May be set to start of the new range
     439                 :  *                                           or rendered irrelevant
     440                 :  *             range_end                 Reset to 0 (by  reset_fcode_ranges() )
     441                 :  *             changes_listed            Reset to FALSE
     442                 :  *         Memory Allocated
     443                 :  *             For new Range data structure; for copy of  iname
     444                 :  *         When Freed?
     445                 :  *             By reset_fcode_ranges()
     446                 :  *
     447                 :  *      Error Detection:
     448                 :  *          Not here.
     449                 :  *          The calling routine will detect and report attempts to set an
     450                 :  *             illegal new range. 
     451                 :  *          Overlap with earlier Ranges will be detected and reported when
     452                 :  *              the FCode is actually Assigned.
     453                 :  *
     454                 :  *      Process Explanation:
     455                 :  *          The calling routine will not call this routine with a new starting
     456                 :  *              FCode that is not legal per the Standard.
     457                 :  *          It may call with a new starting FCode that is equal to  nextfcode
     458                 :  *          If no Ranges exist yet, and the new starting FCode is equal to
     459                 :  *              the current value of  nextfcode , this is a continuation of
     460                 :  *              the first and only range; do not change the file name or line
     461                 :  *              number; just go away.
     462                 :  *          If no Ranges exist yet, and no FCode assignments have been made
     463                 :  *              in the current range, then this is a new start for the first
     464                 :  *              and only range; detect the latter condition by range_end == 0
     465                 :  *              Call the  reset_fcode_ranges()  routine to update the file name
     466                 :  *              and line number, then update the remaining variables for the
     467                 :  *              current (first and only) range, and you are done here.
     468                 :  *          If no Ranges exist yet, and if FCode assignments _have_ been made
     469                 :  *              in the current (first and only) range, create a data structure
     470                 :  *              for the first (and now no longer only) Range and point both
     471                 :  *              the  first_fc_range  and  current_fc_range  pointers at it.
     472                 :  *              Set the  ranges_exist  flag to TRUE.
     473                 :  *          If Ranges exist, whether from being newly-created, above, or from
     474                 :  *              earlier, create a data structure for the new Current Range
     475                 :  *              and move the  current_fc_range  pointer to point at it.  If
     476                 :  *              the new starting FCode is equal to  nextfcode  we still want
     477                 :  *              to create a new Range that will be listed separately.
     478                 :  *          If no assignments were made within the Current Range, we will not
     479                 :  *              overwrite or delete it; it will be listed at the appropriate
     480                 :  *              time, and will be harmless in the overlap test.
     481                 :  *
     482                 :  *      Extraneous Remarks:
     483                 :  *          We will trade off the strict rules of structured code here,
     484                 :  *              in exchange for ease of coding.
     485                 :  *
     486                 :  **************************************************************************** */
     487                 : 
     488                 : void set_next_fcode( u16  new_fcode)
     489             211 : {
     490             211 :     if ( INVERSE( ranges_exist) )
     491                 :     {    /*  The current range is the first and only.  */
     492                 : 
     493              66 :         if ( new_fcode == nextfcode )
     494                 :         {
     495                 :             /*  Do nothing here  */
     496              22 :             return;
     497                 :         }
     498                 : 
     499              44 :         if ( range_end == 0 )
     500                 :         {   /*  No FCode assignments have been made in the current range  */
     501                 :             /*  This is still the first and only range.                   */
     502                 : 
     503               3 :             reset_fcode_ranges();   /*  Update file name and line number  */
     504               3 :             range_start = new_fcode;
     505               3 :             nextfcode = new_fcode;
     506                 : 
     507                 :             /*  We are done here  */
     508               3 :             return;
     509                 : 
     510                 :         }else{  /*  Create the data structure for the first Range  */
     511              41 :             first_fc_range = safe_malloc( sizeof( fcode_range_t),
     512                 :                                  "creating first FCode Range" );
     513              41 :             first_fc_range->fcr_start        = range_start;
     514              41 :             first_fc_range->fcr_end          = range_end;
     515              41 :             first_fc_range->fcr_infile       = first_fcr_infile;
     516              41 :             first_fc_range->fcr_linenum      = first_fcr_linenum;
     517              41 :             first_fc_range->fcr_not_lapped   = TRUE;
     518              41 :             first_fc_range->fcr_next         = NULL;
     519                 : 
     520              41 :             first_fcr_infile  = NULL;
     521              41 :             first_fcr_linenum = 0;
     522              41 :             range_start       = FCODE_START;
     523              41 :             range_end         = 0;
     524                 : 
     525              41 :             current_fc_range  = first_fc_range;
     526                 : 
     527              41 :             ranges_exist      = TRUE;
     528                 :         }
     529                 :     }
     530                 : 
     531                 :     /*  Previous Ranges exist now for sure!  */
     532             186 :     current_fc_range->fcr_next  = safe_malloc( sizeof( fcode_range_t),
     533                 :                                       "creating new FCode Range" );
     534             186 :     current_fc_range = current_fc_range->fcr_next;
     535                 : 
     536             186 :     nextfcode                         = new_fcode;
     537             186 :     current_fc_range->fcr_start       = nextfcode;
     538             186 :     current_fc_range->fcr_end         = 0;
     539                 :                                   /*  Will be filled in by first assignment  */
     540             186 :     current_fc_range->fcr_infile      = strdup( iname);
     541             186 :     current_fc_range->fcr_linenum     = lineno;
     542             186 :     current_fc_range->fcr_not_lapped  = TRUE;
     543             186 :     current_fc_range->fcr_next        = NULL;
     544                 : 
     545             186 :     changes_listed                    = FALSE;
     546                 : }
     547                 : 
     548                 : 
     549                 : /* **************************************************************************
     550                 :  *
     551                 :  *      Function name:  find_overlap
     552                 :  *      Synopsis:       Compare the FCode under test against existing
     553                 :  *                          FCode Ranges and return a pointer to the
     554                 :  *                          Range against which it overlaps, if any.
     555                 :  *
     556                 :  *      Inputs:
     557                 :  *         Parameters:
     558                 :  *             test_fcode                 FCode to be tested
     559                 :  *         Local Static Variables:
     560                 :  *             ranges_exist               If not TRUE, no need to test
     561                 :  *             first_fc_range             Start of Ranges to test
     562                 :  *             current_fc_range           Do not test Current Range
     563                 :  *
     564                 :  *      Outputs:
     565                 :  *         Returned Value:                Pointer to FCode Range in which an
     566                 :  *                                            overlap exists, or NULL if none.
     567                 :  *
     568                 :  *      Error Detection:
     569                 :  *          The calling routine will treat any findings as it deems appropriate.
     570                 :  *
     571                 :  *      Process Explanation:
     572                 :  *          A Range within which no assignments were made will never "hit"
     573                 :  *              the overlap test because its  fcr_end  field will be zero
     574                 :  *              and its  fcr_start  field will be non-zero; there's no
     575                 :  *              number that will be "between" them!
     576                 :  *
     577                 :  **************************************************************************** */
     578                 : 
     579                 : static fcode_range_t *find_overlap( u16 test_fcode)
     580            3712 : {
     581            3712 :     fcode_range_t *retval = NULL;
     582            3712 :     if ( ranges_exist )
     583                 :     {
     584            3712 :         fcode_range_t *test_range = first_fc_range;
     585           17185 :         while ( test_range != current_fc_range )
     586                 :         {
     587            9822 :             if ( ( test_fcode <= test_range->fcr_end ) &&
     588                 :                  ( test_fcode >= test_range->fcr_start )  )
     589                 :             {
     590              61 :                 retval = test_range;
     591              61 :                 break;
     592                 :             }
     593            9761 :             test_range = test_range->fcr_next;
     594                 :         }
     595                 :     }
     596                 : 
     597            3712 :     return( retval);
     598                 : }
     599                 : 
     600                 : 
     601                 : /* **************************************************************************
     602                 :  *
     603                 :  *      Function name:  assigning_fcode
     604                 :  *      Synopsis:       Commit the next FCode number to be assigned;
     605                 :  *                          test for out-of-bounds, overlap, etc. errors.
     606                 :  *
     607                 :  *      Inputs:
     608                 :  *         Parameters:
     609                 :  *             
     610                 :  *         Global Variables:
     611                 :  *             nextfcode            The FCode-number to be assigned
     612                 :  *         Local Static Variables:
     613                 :  *             ranges_exist         TRUE if FCode Ranges have been created
     614                 :  *             first_fc_range       First entry in linked list of Ranges.
     615                 :  *             current_fc_range     List entry for Current Range.
     616                 :  *
     617                 :  *      Outputs:
     618                 :  *         Returned Value:                  NONE
     619                 :  *         Local Static Variables:
     620                 :  *             changes_listed               Reset to FALSE
     621                 :  *                    One of these two will be set to  nextfcode 
     622                 :  *             range_end                       ... if  ranges_exist  is FALSE
     623                 :  *             current_fc_range->fcr_end       ... if  ranges_exist  is TRUE
     624                 :  *
     625                 :  *      Error Detection:
     626                 :  *          FATAL if the value of  nextfcode  is larger than the legal
     627                 :  *              maximum for an FCode
     628                 :  *          ERROR if the value of  nextfcode   falls within one of the
     629                 :  *              existing Ranges (other than the current one, of course)
     630                 :  *
     631                 :  **************************************************************************** */
     632                 : 
     633                 : void assigning_fcode( void)
     634           12964 : {
     635           12964 :     if ( nextfcode > FCODE_LIMIT )
     636                 :     {
     637                 :         /*  Let's give a last summarization before we crap out */
     638               2 :         tokenization_error( INFO, "");
     639               2 :         list_fcode_ranges( FALSE);
     640                 : 
     641               2 :         tokenization_error( FATAL,
     642                 :             "Too many definitions.  "
     643                 :             "Assigned FCode exceeds limit "
     644                 :             "specified by IEEE-1275.");
     645                 :         /*
     646                 :          *  No need to  return()  from here.
     647                 :          *  FATAL error exits program.
     648                 :          */
     649                 :     }
     650                 : 
     651           12962 :     changes_listed = FALSE;
     652                 : 
     653           12962 :     if ( INVERSE(ranges_exist) )
     654                 :     {    /*  No Overlap Error checking needed here.  */
     655            6215 :         range_end = nextfcode;
     656                 :     }else{
     657            6747 :         current_fc_range->fcr_end = nextfcode;
     658                 : 
     659                 :         /*   Detect and report Overlap Error only once per Range  */
     660            6747 :         if ( current_fc_range->fcr_not_lapped )
     661                 :         {
     662            3712 :             fcode_range_t *found_lap = find_overlap( nextfcode);
     663            3712 :             if ( found_lap != NULL )
     664                 :             {
     665              61 :                 tokenization_error( TKERROR,
     666                 :                     "Assigning FCode of 0x%x, "
     667                 :                         "which overlaps the range", nextfcode);
     668              61 :                 started_at( found_lap->fcr_infile, found_lap->fcr_linenum);
     669                 : 
     670              61 :                 current_fc_range->fcr_not_lapped = FALSE;
     671                 :             }
     672                 :         }
     673                 :     }
     674                 : 
     675           12962 : }
     676                 : 
     677                 : 
     678                 : /* **************************************************************************
     679                 :  *
     680                 :  *      Function name:  bump_fcode
     681                 :  *      Synopsis:       Increment the next assignable FCode number
     682                 :  *                          prior to the next assignment.
     683                 :  *
     684                 :  *      Inputs:
     685                 :  *         Parameters:                   NONE
     686                 :  *         Global Variables:
     687                 :  *             nextfcode                 The next FCode-number to be assigned
     688                 :  *
     689                 :  *      Outputs:
     690                 :  *         Returned Value:               NONE
     691                 :  *         Global Variables:
     692                 :  *             nextfcode                 Incremented
     693                 :  *
     694                 :  *      Extraneous Remarks:
     695                 :  *          This looks like a no-brainer now, but if we ever need this
     696                 :  *              function to perform any more sophisticated background
     697                 :  *              activity, we can limit the scope of our modifications
     698                 :  *              to this routine.
     699                 :  *
     700                 :  **************************************************************************** */
     701                 : 
     702                 : void bump_fcode( void)
     703           12962 : {
     704           12962 :     nextfcode++;
     705           12962 : }

Generated by: LTP GCOV extension version 1.5