#!/bin/bash
######################################################################
# Simple archive search
# Description:
#   Search the archives for a word or phrase.  Allow limiting to a specific
# range of archives.
######################################################################
# Command line:
# search "word or phrase" vstart vend istart iend
#  where:
#   - vstart - is the volume to start searching from
#   - vend   - is the end volume to search to
#   - istart - is the issue to start searching
#   - iend   - is the issue to end searching
#   - default values for start and end are the whole archive
######################################################################
# History:
#  081019 - Created.
######################################################################

# Define starting point

if [ $# -eq 0 ]; then
  echo "No search string"
  exit 1
else
  if [ $# -eq 1 ]; then
    vol_start=01
    vol_end=12
  fi
  if [ $# -ge 3 ]; then
      vol_start=$2
      vol_end=$3
      is_start=0
      is_end=999
  fi
  if [ $# -ge 5 ]; then
    is_start=$4
    is_end=$5
  fi
fi

# Debug statement

echo "Parameter count = $#"
echo "String to search for = $1"
echo "Start volume = $vol_start"
echo "End volume = $vol_end"
echo "Start issue = $is_start"
echo "End issue = $is_end"

# End Debug

AmIDone="Not"

while [ $AmIDone = "Not" ]
do
  DirToDo=""
  VolNow=""
  IssueNow=""

  if [ $vol_start -lt 10 ]; then
    VolNow="v0$vol_start"
  else
    VolNow="v$vol_start"
  fi

  iss_dir=0
  while [ $iss_dir -lt 10 ]
  do
    DirToDo="$VolNow`n`$iss_dir`00-`$iss_dir`99`"
    echo $DirToDo
    iss_dir=$iss_dir+1
  done

  # Debug Statement

  echo $VolNow

  # End Debug

  AmIDone="Yes"

done