LTP GCOV extension - code coverage report
Current view: directory - fcode-utils/toke - nextfcode.c
Test: toke.info
Date: 2006-08-18 Instrumented lines: 106
Code covered: 100.0 % Executed lines: 106

       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             364 : {
     263             364 :     if ( ranges_exist )
     264                 :     {
     265             112 :         while ( current_fc_range != NULL )
     266                 :         {
     267              94 :             current_fc_range = first_fc_range->fcr_next;
     268              94 :             free( first_fc_range->fcr_infile);
     269              94 :             free( first_fc_range);
     270              94 :             first_fc_range = current_fc_range;
     271                 :         }
     272              18 :         ranges_exist = FALSE;
     273                 :     }else{
     274             346 :         if ( first_fcr_infile != NULL )
     275                 :         {
     276             192 :             if ( strcmp( first_fcr_infile, iname) != 0 )
     277                 :             {
     278              37 :                 free( first_fcr_infile);
     279              37 :                 first_fcr_infile = NULL;
     280                 :             }
     281                 :         }
     282                 :     }
     283                 : 
     284             364 :     changes_listed    = FALSE;
     285             364 :     range_start       = FCODE_START;
     286             364 :     range_end         = 0;
     287                 : 
     288             364 :     if ( first_fcr_infile == NULL )
     289                 :     {
     290             209 :         first_fcr_infile = strdup( iname);
     291                 :     }
     292             364 :     first_fcr_linenum = lineno;
     293             364 :     nextfcode         = FCODE_START;
     294             364 : }
     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             195 : {
     343             195 :     if ( verbose )
     344                 :     {
     345             195 :         FILE *message_dest = ( final_tally ? stdout : ERRMSG_DESTINATION );
     346             195 :         if ( changes_listed )
     347                 :         {
     348               2 :             fprintf(message_dest, "\n");
     349                 :         }else{
     350             193 :             changes_listed = TRUE;
     351                 : 
     352             193 :             if ( INVERSE(ranges_exist) )
     353                 :             {   /*  List the first and only range  */
     354             161 :                 if ( range_end == 0 )
     355                 :                 {
     356              18 :                     fprintf(message_dest, "No FCodes assigned.\n");
     357                 :                 }else{
     358             143 :                     if ( range_start == FCODE_START )
     359                 :                     {
     360             140 :                         fprintf(message_dest,
     361                 :                             "Last assigned FCode = 0x%x\n", range_end);
     362                 :                     }else{
     363               3 :                         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              32 :                     ( final_tally ? print_started_at : started_at );
     377                 : 
     378                 : 
     379              32 :                 fcode_range_t *next_range = first_fc_range;
     380                 : 
     381              32 :                 fprintf(message_dest, "FCodes assigned:\n");
     382                 : 
     383             220 :                 while ( next_range != NULL )
     384                 :                 {
     385             156 :                     if ( next_range->fcr_end == 0 )
     386                 :                     {
     387              14 :                         fprintf(message_dest, "    None assigned");
     388                 :                     }else{
     389             142 :                         fprintf(message_dest, "    From 0x%x to 0x%x",
     390                 :                             next_range->fcr_start, next_range->fcr_end );
     391             142 :                         if ( INVERSE( next_range->fcr_not_lapped) )
     392                 :                         {
     393              66 :                             fprintf(message_dest, " ***Overlap***" );
     394                 :                         }
     395                 :                     }
     396             156 :                     fprintf(message_dest, " in the range");
     397             156 :                     (*start_at_funct)(
     398                 :                         next_range->fcr_infile, next_range->fcr_linenum );
     399                 : 
     400             156 :                     next_range = next_range->fcr_next;
     401                 :                 }
     402                 :             }
     403                 :         }
     404                 :     }
     405             195 : }
     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             106 : {
     490             106 :     if ( INVERSE( ranges_exist) )
     491                 :     {    /*  The current range is the first and only.  */
     492                 : 
     493              44 :         if ( new_fcode == nextfcode )
     494                 :         {
     495                 :             /*  Do nothing here  */
     496              19 :             return;
     497                 :         }
     498                 : 
     499              25 :         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              22 :             first_fc_range = safe_malloc( sizeof( fcode_range_t),
     512                 :                                  "creating first FCode Range" );
     513              22 :             first_fc_range->fcr_start        = range_start;
     514              22 :             first_fc_range->fcr_end          = range_end;
     515              22 :             first_fc_range->fcr_infile       = first_fcr_infile;
     516              22 :             first_fc_range->fcr_linenum      = first_fcr_linenum;
     517              22 :             first_fc_range->fcr_not_lapped   = TRUE;
     518              22 :             first_fc_range->fcr_next         = NULL;
     519                 : 
     520              22 :             first_fcr_infile  = NULL;
     521              22 :             first_fcr_linenum = 0;
     522              22 :             range_start       = FCODE_START;
     523              22 :             range_end         = 0;
     524                 : 
     525              22 :             current_fc_range  = first_fc_range;
     526                 : 
     527              22 :             ranges_exist      = TRUE;
     528                 :         }
     529                 :     }
     530                 : 
     531                 :     /*  Previous Ranges exist now for sure!  */
     532              84 :     current_fc_range->fcr_next  = safe_malloc( sizeof( fcode_range_t),
     533                 :                                       "creating new FCode Range" );
     534              84 :     current_fc_range = current_fc_range->fcr_next;
     535                 : 
     536              84 :     nextfcode                         = new_fcode;
     537              84 :     current_fc_range->fcr_start       = nextfcode;
     538              84 :     current_fc_range->fcr_end         = 0;
     539                 :                                   /*  Will be filled in by first assignment  */
     540              84 :     current_fc_range->fcr_infile      = strdup( iname);
     541              84 :     current_fc_range->fcr_linenum     = lineno;
     542              84 :     current_fc_range->fcr_not_lapped  = TRUE;
     543              84 :     current_fc_range->fcr_next        = NULL;
     544                 : 
     545              84 :     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                 :  *         Global Variables:
     560                 :  *             
     561                 :  *         Local Static Variables:
     562                 :  *             ranges_exist               If not TRUE, no need to test
     563                 :  *             first_fc_range             Start of Ranges to test
     564                 :  *             current_fc_range           Do not test Current Range
     565                 :  *
     566                 :  *      Outputs:
     567                 :  *         Returned Value:                Pointer to FCode Range in which an
     568                 :  *                                            overlap exists, or NULL if none.
     569                 :  *
     570                 :  *      Error Detection:
     571                 :  *          The calling routine will treat any findings as it deems appropriate.
     572                 :  *
     573                 :  *      Process Explanation:
     574                 :  *          A Range within which no assignments were made will never "hit"
     575                 :  *              the overlap test because its  fcr_end  field will be zero
     576                 :  *              and its  fcr_start  field will be non-zero; there's no
     577                 :  *              number that will be "between" them!
     578                 :  *
     579                 :  **************************************************************************** */
     580                 : 
     581                 : static fcode_range_t *find_overlap( u16 test_fcode)
     582            2876 : {
     583            2876 :     fcode_range_t *retval = NULL;
     584            2876 :     if ( ranges_exist )
     585                 :     {
     586            2876 :         fcode_range_t *test_range = first_fc_range;
     587           10208 :         while ( test_range != current_fc_range )
     588                 :         {
     589            4494 :             if ( ( test_fcode <= test_range->fcr_end ) &&
     590                 :                  ( test_fcode >= test_range->fcr_start )  )
     591                 :             {
     592              38 :                 retval = test_range;
     593              38 :                 break;
     594                 :             }
     595            4456 :             test_range = test_range->fcr_next;
     596                 :         }
     597                 :     }
     598                 : 
     599            2876 :     return( retval);
     600                 : }
     601                 : 
     602                 : 
     603                 : /* **************************************************************************
     604                 :  *
     605                 :  *      Function name:  assigning_fcode
     606                 :  *      Synopsis:       Commit the next FCode number to be assigned;
     607                 :  *                          test for out-of-bounds, overlap, etc. errors.
     608                 :  *
     609                 :  *      Inputs:
     610                 :  *         Parameters:
     611                 :  *             
     612                 :  *         Global Variables:
     613                 :  *             nextfcode
     614                 :  *         Local Static Variables:
     615                 :  *             ranges_exist         TRUE if FCode Ranges have been created
     616                 :  *             first_fc_range       First entry in linked list of Ranges.
     617                 :  *             current_fc_range     List entry for Current Range.
     618                 :  *
     619                 :  *      Outputs:
     620                 :  *         Returned Value:                  NONE
     621                 :  *         Global Variables:
     622                 :  *         Local Static Variables:
     623                 :  *             changes_listed               Reset to FALSE
     624                 :  *                    One of these two will be set to  nextfcode 
     625                 :  *             range_end                       ... if  ranges_exist  is FALSE
     626                 :  *             current_fc_range->fcr_end       ... if  ranges_exist  is TRUE
     627                 :  *
     628                 :  *      Error Detection:
     629                 :  *          FATAL if the value of  nextfcode  is larger than the legal
     630                 :  *              maximum for an FCode
     631                 :  *          ERROR if the value of  nextfcode   falls within one of the
     632                 :  *              existing Ranges (other than the current one, of course)
     633                 :  *
     634                 :  **************************************************************************** */
     635                 : 
     636                 : void assigning_fcode( void)
     637            9979 : {
     638            9979 :     if ( nextfcode > FCODE_LIMIT )
     639                 :     {
     640                 :         /*  Let's give a last summarization before we crap out */
     641               1 :         tokenization_error( INFO, "");
     642               1 :         list_fcode_ranges( FALSE);
     643                 : 
     644               1 :         tokenization_error( FATAL,
     645                 :             "Too many definitions.  "
     646                 :             "Assigned FCode exceeds limit "
     647                 :             "specified by IEEE-1275.");
     648                 :         /*
     649                 :          *  No need to  return()  from here.
     650                 :          *  FATAL error exits program.
     651                 :          */
     652                 :     }
     653                 : 
     654            9978 :     changes_listed = FALSE;
     655                 : 
     656            9978 :     if ( INVERSE(ranges_exist) )
     657                 :     {    /*  No Overlap Error checking needed here.  */
     658            4818 :         range_end = nextfcode;
     659                 :     }else{
     660            5160 :         current_fc_range->fcr_end = nextfcode;
     661                 : 
     662                 :         /*   Detect and report Overlap Error only once per Range  */
     663            5160 :         if ( current_fc_range->fcr_not_lapped )
     664                 :         {
     665            2876 :             fcode_range_t *found_lap = find_overlap( nextfcode);
     666            2876 :             if ( found_lap != NULL )
     667                 :             {
     668              38 :                 tokenization_error( TKERROR,
     669                 :                     "Assigning FCode of 0x%x, "
     670                 :                         "which overlaps the range", nextfcode);
     671              38 :                 started_at( found_lap->fcr_infile, found_lap->fcr_linenum);
     672                 : 
     673              38 :                 current_fc_range->fcr_not_lapped = FALSE;
     674                 :             }
     675                 :         }
     676                 :     }
     677                 : 
     678            9978 : }
     679                 : 
     680                 : 
     681                 : /* **************************************************************************
     682                 :  *
     683                 :  *      Function name:  bump_fcode
     684                 :  *      Synopsis:       Increment the next assignable FCode number
     685                 :  *                          prior to the next assignment.
     686                 :  *
     687                 :  *      Inputs:
     688                 :  *         Parameters:                   NONE
     689                 :  *         Global Variables:
     690                 :  *             nextfcode                 The next FCode-number to be assigned
     691                 :  *
     692                 :  *      Outputs:
     693                 :  *         Returned Value:               NONE
     694                 :  *         Global Variables:
     695                 :  *             nextfcode                 Incremented
     696                 :  *
     697                 :  *      Extraneous Remarks:
     698                 :  *          This looks like a no-brainer now, but if we ever need this
     699                 :  *              function to perform any more sophisticated background
     700                 :  *              activity, we can limit the scope of our modifications
     701                 :  *              to this routine.
     702                 :  *
     703                 :  **************************************************************************** */
     704                 : 
     705                 : void bump_fcode( void)
     706            9978 : {
     707            9978 :     nextfcode++;
     708            9978 : }

Generated by: LTP GCOV extension version 1.5