#!/bin/sh
#
# This file is part of TCOS
#
#  (emulate /bin/seq with a shell script)
#
# Copyright (C) 2006-2011  mariodebian at gmail
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#


MAX=$1
NUM=1
INC=1

if [ "$MAX" = "" ]; then
  echo "TCOS seq number generator"
  echo ""
  echo "Print numbers from FIRST to LAST, in steps of INCREMENT."
  echo "Usage: seq LAST"
  echo "  or:  seq FIRST LAST"
  echo "  or:  seq FIRST INCREMENT LAST"
  exit 1
fi

if [ $# = 1 ]; then
  MAX=$1
elif [ $# = 2 ]; then
  NUM=$1
  MAX=$2
elif [ $# = 3 ]; then
  NUM=$1
  INC=$2
  MAX=$3
fi

if [ $MAX -gt 100 ] || [ $MAX -lt 1 ]; then
  echo "ERROR: Max number must be in 1-100"
  exit 1
fi

if [ $INC -lt 1 ] ; then
  echo "ERROR: Increment must be big than 1"
  exit 1
fi

while [ $NUM -le $MAX ]; do
  echo $NUM
  NUM=$((NUM +INC))
done
