/*
   <p>A function to range-check a numeric option.</p>

   <kbd>
   <b>environ - C programming support functions</b><br>
   Copyright (C) 2005  Martin C Gregorie
   
   This program is free software; you can redistribute it and/or
   modify it under the terms of the Lesser GNU General Public License.
   
   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 Lesser GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   </kbd>
  
   <p>Contact Martin Gregorie at <i>martin@gregorie.org</i></p>
*/

#include <stdio.h>
#include <environ.h>

/*
   Range_check the value <u>val</u>.
   It it is outside the range <u>low</u> - <u>high</u> the
   program is terminated by calling <i>error()</i> to output
   the error message:

   <b>program: <u>desc</u> must be in range <u>low</u> - <u>high</u></b>

   It is intended for use during run-time parameter checking.
*/
void check_range(int val, int low, int high, char *desc)
{
   char  buff[80];
   
   if (val < low || val > high)
   {
      snprintf(buff,
               sizeof(buff),
               "%s must be in range %d - %d",
               desc,
               low,
               high);
      error(progname(), buff, "");
   }
}

