Blame opensm/osm_check_n_fix

Packit Service 54dbc3
eval '(exit $?0)' &&
Packit Service 54dbc3
  eval 'exec perl -S $0 ${1+"$@"}' &&
Packit Service 54dbc3
  eval 'exec perl -S $0 $argv:q'
Packit Service 54dbc3
  if 0;
Packit Service 54dbc3
Packit Service 54dbc3
#!/usr/bin/perl -W
Packit Service 54dbc3
#
Packit Service 54dbc3
# Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
Packit Service 54dbc3
# Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
Packit Service 54dbc3
# Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
Packit Service 54dbc3
#
Packit Service 54dbc3
# This software is available to you under a choice of one of two
Packit Service 54dbc3
# licenses.  You may choose to be licensed under the terms of the GNU
Packit Service 54dbc3
# General Public License (GPL) Version 2, available from the file
Packit Service 54dbc3
# COPYING in the main directory of this source tree, or the
Packit Service 54dbc3
# OpenIB.org BSD license below:
Packit Service 54dbc3
#
Packit Service 54dbc3
#     Redistribution and use in source and binary forms, with or
Packit Service 54dbc3
#     without modification, are permitted provided that the following
Packit Service 54dbc3
#     conditions are met:
Packit Service 54dbc3
#
Packit Service 54dbc3
#      - Redistributions of source code must retain the above
Packit Service 54dbc3
#        copyright notice, this list of conditions and the following
Packit Service 54dbc3
#        disclaimer.
Packit Service 54dbc3
#
Packit Service 54dbc3
#      - Redistributions in binary form must reproduce the above
Packit Service 54dbc3
#        copyright notice, this list of conditions and the following
Packit Service 54dbc3
#        disclaimer in the documentation and/or other materials
Packit Service 54dbc3
#        provided with the distribution.
Packit Service 54dbc3
#
Packit Service 54dbc3
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit Service 54dbc3
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit Service 54dbc3
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit Service 54dbc3
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit Service 54dbc3
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit Service 54dbc3
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit Service 54dbc3
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit Service 54dbc3
# SOFTWARE.
Packit Service 54dbc3
#
Packit Service 54dbc3
#########################################################################
Packit Service 54dbc3
#
Packit Service 54dbc3
#  Abstract:
Packit Service 54dbc3
#     Perl script for simple source code error checking and fixing
Packit Service 54dbc3
#
Packit Service 54dbc3
#  Environment:
Packit Service 54dbc3
#     Linux User Mode
Packit Service 54dbc3
#
Packit Service 54dbc3
#  Author:
Packit Service 54dbc3
#     Eitan Zahavi, Mellanox Technologies LTD Yokneam Israel.
Packit Service 54dbc3
#
Packit Service 54dbc3
#  $Revision: 1.4 $
Packit Service 54dbc3
#
Packit Service 54dbc3
#
Packit Service 54dbc3
#
Packit Service 54dbc3
# DESCRIPTION:
Packit Service 54dbc3
#
Packit Service 54dbc3
# This script performs some simple conformance checks on the
Packit Service 54dbc3
# OpenSM source code.  It does NOT attempt to act like a full
Packit Service 54dbc3
# blown 'C' language parser, so it can be fooled.  Something
Packit Service 54dbc3
# is better than nothing.
Packit Service 54dbc3
#
Packit Service 54dbc3
# The script starts by running the 'osm_indent' script on teh given files.
Packit Service 54dbc3
#
Packit Service 54dbc3
# We use an extra file for tracking error codes used by each file.
Packit Service 54dbc3
# The name is osm_errors_codes.
Packit Service 54dbc3
#
Packit Service 54dbc3
# The following checks are performed:
Packit Service 54dbc3
# 1) Verify that the function name provided in a log statement
Packit Service 54dbc3
#    matches the name of the current function.
Packit Service 54dbc3
#
Packit Service 54dbc3
# 2) Verify that log statements are in the form that this script
Packit Service 54dbc3
#    can readily parse.  Improvements to the regular expressions
Packit Service 54dbc3
#    might make this unnecessary.
Packit Service 54dbc3
#
Packit Service 54dbc3
# 3) Verify that lower two digits of the error codes used in log
Packit Service 54dbc3
#    statements are unique within that file.
Packit Service 54dbc3
#
Packit Service 54dbc3
# 4) Verify that upper two digits of the error codes used in log
Packit Service 54dbc3
#    statements are not used by any other module.
Packit Service 54dbc3
#
Packit Service 54dbc3
# 5) Verify the lines do not have extra spaces.
Packit Service 54dbc3
#
Packit Service 54dbc3
# USAGE:
Packit Service 54dbc3
#
Packit Service 54dbc3
# In the OpenSM source directory, type:
Packit Service 54dbc3
# osm_check_n_fix -f *.c
Packit Service 54dbc3
#
Packit Service 54dbc3
#########################################################################
Packit Service 54dbc3
Packit Service 54dbc3
# Do necessary upfront initialization
Packit Service 54dbc3
$verbose = 0;
Packit Service 54dbc3
$in_c_comment = 0;
Packit Service 54dbc3
$fix_mode = 0;
Packit Service 54dbc3
$confirm_mode = 0;
Packit Service 54dbc3
$re_assign_err_prefix = 0;
Packit Service 54dbc3
Packit Service 54dbc3
if( !scalar(@ARGV) )
Packit Service 54dbc3
{
Packit Service 54dbc3
    print "ERROR: You must specify the files on which to operate, such as '*.c'\n";
Packit Service 54dbc3
    osm_check_usage();
Packit Service 54dbc3
    exit;
Packit Service 54dbc3
}
Packit Service 54dbc3
Packit Service 54dbc3
# loop through all the command line options
Packit Service 54dbc3
do
Packit Service 54dbc3
{
Packit Service 54dbc3
    $doing_params = 0;
Packit Service 54dbc3
Packit Service 54dbc3
    # First, look for command line options.
Packit Service 54dbc3
    if( $ARGV[0] =~ /-[v|V]/ )
Packit Service 54dbc3
    {
Packit Service 54dbc3
        $verbose += 1;
Packit Service 54dbc3
        shift;
Packit Service 54dbc3
        print "Verbose mode on, level = $verbose.\n";
Packit Service 54dbc3
        $doing_params = 1;
Packit Service 54dbc3
    }
Packit Service 54dbc3
Packit Service 54dbc3
    if( $ARGV[0] =~ /(-f|--fix)/ )
Packit Service 54dbc3
    {
Packit Service 54dbc3
        $fix_mode += 1;
Packit Service 54dbc3
        shift;
Packit Service 54dbc3
        print "Fix mode on.\n";
Packit Service 54dbc3
        $doing_params = 1;
Packit Service 54dbc3
    }
Packit Service 54dbc3
Packit Service 54dbc3
    if( $ARGV[0] =~ /(-c|--confirm)/ )
Packit Service 54dbc3
    {
Packit Service 54dbc3
        $confirm_mode += 1;
Packit Service 54dbc3
        shift;
Packit Service 54dbc3
        print "Confirm mode on.\n";
Packit Service 54dbc3
        $doing_params = 1;
Packit Service 54dbc3
    }
Packit Service 54dbc3
Packit Service 54dbc3
    if( $ARGV[0] =~ /(-r|--re-assign-mod-err-prefix)/ )
Packit Service 54dbc3
    {
Packit Service 54dbc3
        $re_assign_err_prefix += 1;
Packit Service 54dbc3
        shift;
Packit Service 54dbc3
        print "Allow Re-Assignment of Module Err Prefixes.\n";
Packit Service 54dbc3
        $doing_params = 1;
Packit Service 54dbc3
    }
Packit Service 54dbc3
Packit Service 54dbc3
    if( !scalar(@ARGV))
Packit Service 54dbc3
    {
Packit Service 54dbc3
        print "ERROR: You must specify the files on which to operate, such as '*.c'\n";
Packit Service 54dbc3
        osm_check_usage();
Packit Service 54dbc3
        exit;
Packit Service 54dbc3
    }
Packit Service 54dbc3
} while( $doing_params == 1 );
Packit Service 54dbc3
Packit Service 54dbc3
# parse the osm_error_codes file and define:
Packit Service 54dbc3
# module_by_prefix
Packit Service 54dbc3
# module_err_prefixes
Packit Service 54dbc3
# module_last_err_used
Packit Service 54dbc3
if (open(ERRS, "
Packit Service 54dbc3
  @ERR_DEFS = <ERRS>;
Packit Service 54dbc3
  close(ERRS);
Packit Service 54dbc3
  foreach $errDef (@ERR_DEFS) {
Packit Service 54dbc3
    # the format should be <file name> <err prefix> <last err>
Packit Service 54dbc3
    if ($errDef =~ m/^(\S+)\s+(\S+)\s+([0-9]+)$/) {
Packit Service 54dbc3
      ($file_name,$mod_prefix,$last_err) = ($1,$2,$3);
Packit Service 54dbc3
      if (defined($module_by_prefix{$mod_prefix})) {
Packit Service 54dbc3
        print "ERROR: Double module prefix:$mod_prefix on:$module_by_prefix($mod_prefix) and $file_name\n";
Packit Service 54dbc3
        exit 3;
Packit Service 54dbc3
      }
Packit Service 54dbc3
      $module_by_prefix{$mod_prefix} = $file_name;
Packit Service 54dbc3
      $module_err_prefixes{$file_name} = $mod_prefix;
Packit Service 54dbc3
      $module_last_err_used{$file_name} = $last_err;
Packit Service 54dbc3
    } else {
Packit Service 54dbc3
      print "ERROR: Fail to parse sm_error_codes: $errDef\n";
Packit Service 54dbc3
      exit 3;
Packit Service 54dbc3
    }
Packit Service 54dbc3
  }
Packit Service 54dbc3
}
Packit Service 54dbc3
Packit Service 54dbc3
# do a file by file read into memory so we can tweek it:
Packit Service 54dbc3
foreach $file_name (@ARGV) {
Packit Service 54dbc3
	print "- $file_name ----------------------------------------------------\n";
Packit Service 54dbc3
   # first step is to run indent
Packit Service 54dbc3
	 $res=`osm_indent $file_name`;
Packit Service 54dbc3
Packit Service 54dbc3
    open(INFILE, "<$file_name") || die("Fail to open $file_name");
Packit Service 54dbc3
    @LINES = <INFILE>;
Packit Service 54dbc3
    close(INFILE);
Packit Service 54dbc3
    $any_fix = 0;
Packit Service 54dbc3
    $needed_fixing = 0;
Packit Service 54dbc3
    $need_indentation = 0;
Packit Service 54dbc3
Packit Service 54dbc3
  LINE: for ($line_num = 0; $line_num 
Packit Service 54dbc3
      $line = $LINES[$line_num];
Packit Service 54dbc3
      $_ = $line;
Packit Service 54dbc3
Packit Service 54dbc3
      # Skip C single line C style comments
Packit Service 54dbc3
      # This line must come before the multi-line C comment check!
Packit Service 54dbc3
      if( /\/\*.*\*\// )
Packit Service 54dbc3
      {
Packit Service 54dbc3
          $in_c_comment = 0;
Packit Service 54dbc3
          next LINE;
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
      # skip multi-line C style comments
Packit Service 54dbc3
      if( /\/\*/ )
Packit Service 54dbc3
      {
Packit Service 54dbc3
          $in_c_comment = 1;
Packit Service 54dbc3
          next LINE;
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
      # end skipping of multi-line C style comments
Packit Service 54dbc3
      if( /\*\// )
Packit Service 54dbc3
      {
Packit Service 54dbc3
          $in_c_comment = 0;
Packit Service 54dbc3
          next LINE;
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
      # We're still in a C comment, so ignore input
Packit Service 54dbc3
      if( $in_c_comment == 1 )
Packit Service 54dbc3
      {
Packit Service 54dbc3
        next LINE;
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
Packit Service 54dbc3
      # Error on C++ style comment lines
Packit Service 54dbc3
      if( /\/\// )
Packit Service 54dbc3
      {
Packit Service 54dbc3
        print "C++ style comment on $file_name $line_num\n";
Packit Service 54dbc3
        $needed_fixing++;
Packit Service 54dbc3
        if ($fix_mode) {
Packit Service 54dbc3
          $line =~ s=\/\/(.*)$=/* \1 */=;
Packit Service 54dbc3
          if (confirm_change($line, $LINES[$line_num])) {
Packit Service 54dbc3
            $LINES[$line_num] = $line;
Packit Service 54dbc3
            $any_fix++;
Packit Service 54dbc3
          }
Packit Service 54dbc3
          $any_fix++;
Packit Service 54dbc3
        }
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
      # check for lines with trailing spaces:
Packit Service 54dbc3
      if (/[ \t]+$/) {
Packit Service 54dbc3
        $needed_fixing++;
Packit Service 54dbc3
        if ($fix_mode) {
Packit Service 54dbc3
          $line =~ s/\s+$/\n/;
Packit Service 54dbc3
          if (confirm_change($line, $LINES[$line_num])) {
Packit Service 54dbc3
            $LINES[$line_num] = $line;
Packit Service 54dbc3
            $any_fix++;
Packit Service 54dbc3
          }
Packit Service 54dbc3
          $any_fix++;
Packit Service 54dbc3
        }
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
      # check for bad PRIx64 usage
Packit Service 54dbc3
      # It's a common mistake to forget the % before the PRIx64
Packit Service 54dbc3
      if (/[^%0-9][0-9]*\"\s*PRIx64/ ) {
Packit Service 54dbc3
        $needed_fixing++;
Packit Service 54dbc3
        print "No % sign before PRx64!!: $file_name $line_num\n";
Packit Service 54dbc3
        if ($fix_mode) {
Packit Service 54dbc3
          $line =~ s/([0-9]*)\"\s*PRIx64/%$1\" PRIx64/;
Packit Service 54dbc3
          if (confirm_change($line, $LINES[$line_num])) {
Packit Service 54dbc3
            $LINES[$line_num] = $line;
Packit Service 54dbc3
            $any_fix++;
Packit Service 54dbc3
          }
Packit Service 54dbc3
        }
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
      # This simple script doesn't handle checking PRIx64 usage
Packit Service 54dbc3
      # when PRIx64 starts the line.  Just give a warning.
Packit Service 54dbc3
      if( /^\s*PRIx64/ )
Packit Service 54dbc3
      {
Packit Service 54dbc3
        $needed_fixing++;
Packit Service 54dbc3
        print "Warning: PRIx64 at start of line.  $file_name $line_num\n";
Packit Service 54dbc3
#        if ($fix_mode) {
Packit Service 54dbc3
#          print "Fatal: can not auto fix\n";
Packit Service 54dbc3
#          exit 1;
Packit Service 54dbc3
#        }
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
      # Attempt to locate function names.
Packit Service 54dbc3
      # Function names must start on the beginning of the line.
Packit Service 54dbc3
      if( /^(\w+)\s*\(/ )
Packit Service 54dbc3
      {
Packit Service 54dbc3
        $current_func = $1;
Packit Service 54dbc3
        if( $verbose == 1 )
Packit Service 54dbc3
          {
Packit Service 54dbc3
            print "Processing $file_name: $current_func\n";
Packit Service 54dbc3
          }
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
      # Attempt to find OSM_LOG_ENTER entries.
Packit Service 54dbc3
      # When found, verify that the function name provided matches
Packit Service 54dbc3
      # the actual function.
Packit Service 54dbc3
      if( /OSM_LOG_ENTER\s*\(\s*([\-\.\>\w]+)\s*,\s*(\w+)\s*\)/ ) {
Packit Service 54dbc3
        $log_func = $2;
Packit Service 54dbc3
        if( $current_func ne $log_func ) {
Packit Service 54dbc3
          printf "MISMATCH!! $file_name $line_num: $current_func != $log_func\n";
Packit Service 54dbc3
          $needed_fixing++;
Packit Service 54dbc3
          if ($fix_mode) {
Packit Service 54dbc3
            $line =~
Packit Service 54dbc3
              s/OSM_LOG_ENTER\s*\(\s*([\-\.\>\w]+)\s*,\s*(\w+)\s*\)/OSM_LOG_ENTER( $1, $current_func )/;
Packit Service 54dbc3
            if (confirm_change($line, $LINES[$line_num])) {
Packit Service 54dbc3
              $LINES[$line_num] = $line;
Packit Service 54dbc3
              $any_fix++;
Packit Service 54dbc3
            }
Packit Service 54dbc3
          }
Packit Service 54dbc3
        }
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
      # Check for non-conforming log statements.
Packit Service 54dbc3
      # Log statements must not start the log string on the same line
Packit Service 54dbc3
      # as the osm_log function itself.
Packit Service 54dbc3
      # Watch out for the #include "osm_log.h" statement as a false positive.
Packit Service 54dbc3
      if (/osm_log\s*\(.*OSM_.*\"/ ) {
Packit Service 54dbc3
        if (/Format Waved/) {
Packit Service 54dbc3
          print "Skipping log format waiver at $file_name $line_num\n";
Packit Service 54dbc3
        } else {
Packit Service 54dbc3
          print "NON-CONFORMING LOG STATEMENT!! $file_name $line_num\n";
Packit Service 54dbc3
          $needed_fixing++;
Packit Service 54dbc3
          if ($fix_mode) {
Packit Service 54dbc3
            print "Fatal: can not auto fix\n";
Packit Service 54dbc3
            exit 1;
Packit Service 54dbc3
          }
Packit Service 54dbc3
        }
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
      # Attempt to find osm_log entries.
Packit Service 54dbc3
      if( /^\s*\"(\w+):/ )
Packit Service 54dbc3
      {
Packit Service 54dbc3
          $log_func = $1;
Packit Service 54dbc3
          if( $current_func ne $log_func )
Packit Service 54dbc3
          {
Packit Service 54dbc3
              print "MISMATCHED LOG FUNCTION!! $file_name $line_num: $current_func != $log_func\n";
Packit Service 54dbc3
              $needed_fixing++;
Packit Service 54dbc3
              if ($fix_mode) {
Packit Service 54dbc3
                  $line =~
Packit Service 54dbc3
                      s/^(\s*)\"(\w+):/$1\"$current_func:/;
Packit Service 54dbc3
                  if (confirm_change($line, $LINES[$line_num])) {
Packit Service 54dbc3
                      $LINES[$line_num] = $line;
Packit Service 54dbc3
                      $any_fix++;
Packit Service 54dbc3
                  }
Packit Service 54dbc3
              }
Packit Service 54dbc3
          }
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
      # Error logging must look like 'ERR 1234:'
Packit Service 54dbc3
      # The upper two digits are error range assigned to that module.
Packit Service 54dbc3
      # The lower two digits are the error code itself.
Packit Service 54dbc3
      # Error codes are in hexadecimal.
Packit Service 54dbc3
      if( /ERR(\s+)([0-9a-fA-F]{2})([0-9a-fA-F]{2})(..)/ )
Packit Service 54dbc3
      {
Packit Service 54dbc3
          # track any error for this exp:
Packit Service 54dbc3
          $exp_err = 0;
Packit Service 54dbc3
Packit Service 54dbc3
          # the parsed prefix and err code:
Packit Service 54dbc3
          ($found_prefix,$found_code) = ($2,$3);
Packit Service 54dbc3
Packit Service 54dbc3
          # Check if we already established the error prefix for this module
Packit Service 54dbc3
          $err_prefix = $module_err_prefixes{$file_name};
Packit Service 54dbc3
Packit Service 54dbc3
          # err prefix is not available for this file
Packit Service 54dbc3
          if ( ! $err_prefix ) {
Packit Service 54dbc3
            # make sure no other file uses this prefix:
Packit Service 54dbc3
            if ($module_by_prefix{$found_prefix}) {
Packit Service 54dbc3
              # some other file uses that prefix:
Packit Service 54dbc3
Packit Service 54dbc3
              # two modes: either use a new one or abort
Packit Service 54dbc3
              if ($re_assign_err_prefix) {
Packit Service 54dbc3
                # scan the available module prefixes for an empty one:
Packit Service 54dbc3
                $found = 0;
Packit Service 54dbc3
                for ($new_prefix_idx = 1; $found == 0; $new_prefix_idx++) {
Packit Service 54dbc3
                  $prefix = sprintf("%02X", $new_prefix_idx);
Packit Service 54dbc3
                  if (!defined($module_by_prefix{$prefix})) {
Packit Service 54dbc3
                    $module_err_prefixes{$file_name} = $prefix;
Packit Service 54dbc3
                    $module_by_prefix{$prefix} = $file_name;
Packit Service 54dbc3
                    $found = 1;
Packit Service 54dbc3
                  }
Packit Service 54dbc3
                  $exp_err = 1;
Packit Service 54dbc3
                }
Packit Service 54dbc3
              } else {
Packit Service 54dbc3
                print "Fatal: File $module_by_prefix{$2} already uses same prefix:$2 used by: $file_name (line=$line_num)\n";
Packit Service 54dbc3
                exit 1;
Packit Service 54dbc3
              }
Packit Service 54dbc3
            } else {
Packit Service 54dbc3
              # the prefix found is unused:
Packit Service 54dbc3
Packit Service 54dbc3
              # Create a new prefix for this module.
Packit Service 54dbc3
              $module_err_prefixes{$file_name} = $found_prefix;
Packit Service 54dbc3
              $module_by_prefix{$found_prefix} = $file_name;
Packit Service 54dbc3
              $err_prefix = $found_prefix;
Packit Service 54dbc3
            }
Packit Service 54dbc3
          } else {
Packit Service 54dbc3
            # we already have a prefix for this file
Packit Service 54dbc3
Packit Service 54dbc3
            if( $err_prefix ne $found_prefix )
Packit Service 54dbc3
            {
Packit Service 54dbc3
              $needed_fixing++;
Packit Service 54dbc3
              print "BAD ERR RANGE IN LOG ENTRY!! $file_name $line_num: $current_func\n";
Packit Service 54dbc3
              print "\tExpected $err_prefix but found $found_prefix\n";
Packit Service 54dbc3
              $exp_err = 1;
Packit Service 54dbc3
            }
Packit Service 54dbc3
          }
Packit Service 54dbc3
Packit Service 54dbc3
          # now check for code duplicates
Packit Service 54dbc3
          $err_base = $module_err_bases{$found_code};
Packit Service 54dbc3
          if( $err_base ) {
Packit Service 54dbc3
            $needed_fixing++;
Packit Service 54dbc3
            print "DUPLICATE ERR NUMBER IN LOG ENTRY!! $file_name $line_num: $current_func: $3\n";
Packit Service 54dbc3
            print "\tPrevious use on line $err_base.\n";
Packit Service 54dbc3
Packit Service 54dbc3
            # use the last error code for this module:
Packit Service 54dbc3
            $module_last_err_used{$file_name}++;
Packit Service 54dbc3
            $err_code = sprintf("%02X", $module_last_err_used{$file_name});
Packit Service 54dbc3
            print "\tUsing new err code:0x$err_code ($module_last_err_used{$file_name})\n";
Packit Service 54dbc3
            $module_err_bases{$err_code} = $line_num;
Packit Service 54dbc3
            $exp_err = 1;
Packit Service 54dbc3
          } else {
Packit Service 54dbc3
            # Add this error code to the list used by this module
Packit Service 54dbc3
            # The data stored in the line number on which it is used.
Packit Service 54dbc3
            $module_err_bases{$found_code} = $line_num;
Packit Service 54dbc3
            # track the last code used
Packit Service 54dbc3
            $err_code_num = eval("0x$found_code");
Packit Service 54dbc3
            if ($module_last_err_used{$file_name} < $err_code_num) {
Packit Service 54dbc3
              $module_last_err_used{$file_name} = $err_code_num;
Packit Service 54dbc3
            }
Packit Service 54dbc3
            $err_code = $found_code;
Packit Service 54dbc3
Packit Service 54dbc3
            if( $verbose > 1 ) {
Packit Service 54dbc3
              print "Adding new error: $err_prefix$found_code in $file_name.\n";
Packit Service 54dbc3
            }
Packit Service 54dbc3
          }
Packit Service 54dbc3
Packit Service 54dbc3
          if( $4 ne ": " ) {
Packit Service 54dbc3
            $needed_fixing++;
Packit Service 54dbc3
            print "MALFORMED LOG STATEMENT!!  NEEDS ': ' $file_name $line_num\n";
Packit Service 54dbc3
            $exp_err = 1;
Packit Service 54dbc3
          }
Packit Service 54dbc3
Packit Service 54dbc3
          if( $1 ne " " )
Packit Service 54dbc3
          {
Packit Service 54dbc3
            $needed_fixing++;
Packit Service 54dbc3
            print "USE ONLY 1 SPACE AFTER ERR!! $file_name $line_num\n";
Packit Service 54dbc3
            $exp_err = 1;
Packit Service 54dbc3
          }
Packit Service 54dbc3
Packit Service 54dbc3
          if ($exp_err && $fix_mode) {
Packit Service 54dbc3
              $line =~
Packit Service 54dbc3
                  s/ERR(\s+)([0-9a-fA-F]{2})([0-9a-fA-F]{2})([^\"]*\")/ERR ${err_prefix}$err_code: \" /;
Packit Service 54dbc3
              if (confirm_change($line, $LINES[$line_num])) {
Packit Service 54dbc3
                  $LINES[$line_num] = $line;
Packit Service 54dbc3
                  $any_fix++;
Packit Service 54dbc3
              }
Packit Service 54dbc3
          }
Packit Service 54dbc3
      }
Packit Service 54dbc3
Packit Service 54dbc3
      # verify expected use of sizeof() with pointers
Packit Service 54dbc3
      if( /sizeof\s*\(\s*[h|p]_[^-]+\)/ )
Packit Service 54dbc3
      {
Packit Service 54dbc3
          print "SUSPICIOUS USE OF SIZEOF(), DO YOU NEED AN '*' $file_name $line_num\n";
Packit Service 54dbc3
          $needed_fixing++;
Packit Service 54dbc3
          if ($fix_mode) {
Packit Service 54dbc3
              $line =~
Packit Service 54dbc3
                  s/sizeof\s*\(\s*([h|p])_/sizeof \(*$1_/;
Packit Service 54dbc3
              if (confirm_change($line, $LINES[$line_num])) {
Packit Service 54dbc3
                  $LINES[$line_num] = $line;
Packit Service 54dbc3
                  $any_fix++;
Packit Service 54dbc3
              }
Packit Service 54dbc3
          }
Packit Service 54dbc3
      }
Packit Service 54dbc3
   }
Packit Service 54dbc3
Packit Service 54dbc3
    # reset the base error value, since each module can
Packit Service 54dbc3
    # repeat this range.
Packit Service 54dbc3
    %module_err_bases = ();
Packit Service 54dbc3
Packit Service 54dbc3
    # if any fix write out the fixed file:
Packit Service 54dbc3
    if ($any_fix) {
Packit Service 54dbc3
      open(OF,">$file_name.fix");
Packit Service 54dbc3
      print OF @LINES;
Packit Service 54dbc3
      close(OF);
Packit Service 54dbc3
    } elsif ($needed_fixing) {
Packit Service 54dbc3
      print "Found $needed_fixing Errors on file: $file_name\n";
Packit Service 54dbc3
    }
Packit Service 54dbc3
}
Packit Service 54dbc3
Packit Service 54dbc3
# write out the error codes.
Packit Service 54dbc3
# module_by_prefix
Packit Service 54dbc3
# module_err_prefixes
Packit Service 54dbc3
# module_last_err_used
Packit Service 54dbc3
open(ERRS,">osm_error_codes");
Packit Service 54dbc3
foreach $fn (sort(keys(%module_err_prefixes))) {
Packit Service 54dbc3
  print ERRS "$fn $module_err_prefixes{$fn} $module_last_err_used{$fn}\n";
Packit Service 54dbc3
}
Packit Service 54dbc3
close(ERRS);
Packit Service 54dbc3
Packit Service 54dbc3
sub osm_check_usage
Packit Service 54dbc3
{
Packit Service 54dbc3
    print "Usage:\n";
Packit Service 54dbc3
    print "osm_check.pl [-v|V] [-f|--fix] [-c|--confirm] [-r|--re-assign-mod-err-prefix] <file list>\n";
Packit Service 54dbc3
    print "[-v|V] - enable verbose mode.\n";
Packit Service 54dbc3
    print "[-f|--fix] - enable auto fix mode.\n";
Packit Service 54dbc3
    print "[-c|--confirm] - enable manual confirmation mode.\n";
Packit Service 54dbc3
    print "[-r|--re-assign-mod-err-prefix] - enables re-assign error prefixes if the file does not have one.\n";
Packit Service 54dbc3
}
Packit Service 54dbc3
Packit Service 54dbc3
sub confirm_change {
Packit Service 54dbc3
    local ($line, $orig_line) = @_;
Packit Service 54dbc3
    if ($confirm_mode) {
Packit Service 54dbc3
	print "In Line:".($line_num + 1)."\n";
Packit Service 54dbc3
        print "From: ${orig_line}To:   ${line}Ok [y] ?";
Packit Service 54dbc3
        $| = 1;
Packit Service 54dbc3
        $ans = <STDIN>;
Packit Service 54dbc3
        chomp $ans;
Packit Service 54dbc3
Packit Service 54dbc3
        if ($ans && $ans ne "y") {
Packit Service 54dbc3
            return 0;
Packit Service 54dbc3
        }
Packit Service 54dbc3
    } else {
Packit Service 54dbc3
        print "From: ${orig_line}To:   ${line}";
Packit Service 54dbc3
    }
Packit Service 54dbc3
    return 1;
Packit Service 54dbc3
}