/*
   <p>Utility to convert a string to an integer, using the 
   second parameter as the default if the string is empty.</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"

/*
    Convert a string to an integer, using the 
    second parameter as the default if the string is empty.
    This is intended to be used in conjunction with <i>getopt()</i>
    to handle options with optional integer values which default to
    zero if the option is omitted or to some known value if the option
    is present in the command line but without a specified value:

    <b>See also:</b> <i>getopt(), getarg()</i>
*/
int argval(char *s, int d)
{
    int temp;

    temp = atoi(s);
    if (temp == 0)
        temp = d;
    return(temp);
}

