Blame opensm/osm_check_n_fix

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