#!/bin/bash
#<pre><b>
# Script     : mybadinc
# Version    : 1.0
# Author     : Roland Rashleigh-Berry
# Date       : 07-Jun-2005
# Purpose    : To list which of your own SAS programs do not have a correct 
#              increment in the standard header.
# SubScripts : none
# Notes      : none
# Usage      : mybadinc 
#              mybadinc -f
#================================================================================
# OPTIONS:
#-opt- -------------------------------description--------------------------------
#  f   (switch) fixes your increment in the standard headers
#===============================================================================
# PARAMETERS:
#-pos- -------------------------------description-------------------------------
# N/A  Do not supply any parameters
#===============================================================================
# AMENDMENT HISTORY:
# init --date-- mod-id ----------------------description------------------------
# 
#===============================================================================
# This is public domain software. No guarantee as to suitability or accuracy is
# given or implied. User uses this code entirely at their own risk.
#===============================================================================

# Usage message then exit
usage () {
  echo "Usage: mybadinc -f" 1>&2
  exit 1
}

# options defaults
switchf=0                           # Default switch=off for fixes your program
name


# "case" statement for action to take on selected options
while getopts "f" param ; do
  case $param in
   "?") # bad option supplied
        usage
        ;;
   "f") # (switch) fixes your program name
        switchf=1
        ;;
  esac
done


# shift to bring first parameter to position 1
shift $(($OPTIND - 1))


# No parameters required
if [ $# -gt 0 ] ; then
  echo "Do not supply any parameters" 1>&2
  usage
fi

inc=$(pwd | awk -F/ '{print $8}')


if [ $switchf -eq 0 ] ; then

  grep "^/ Increment  *: .* *" $(myfiles *.sas) | gawk -F: 'index($3,inc)==0'
inc="$inc"

else

  echo "The following files will be fixed:" 1>&2
  for file in $(grep "^/ Increment  *: .* *" $(myfiles *.sas) | gawk -F:
'index($3,inc)==0 {print $1}' inc="$inc")
  do
    echo "$file" 1>&2
    perl -i -pe "s%^/ Increment  *: .* *%/ Increment    : $inc%" ${file}
  done

fi
