//-----------------------------------------------------------------------------
// Copyright © 2003 - Philip Howard - All rights reserved
//
// 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/option
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	libh at ipal dot org
// homepage	http://phil.ipal.org/
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 120 columns wide.
//-----------------------------------------------------------------------------

#include "option_lib.h"

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	option_flag
//
// purpose	Check if an option matches, and if so return true, else false.
//
// arguments	1 (int *) pointer to number of options
//		2 (char * * *) pointer to argv for options
//		3..N (const char *) pointers to possible options
//
// returns	(int) 0 : option did not match
//		(int) 1 : option did match
//-----------------------------------------------------------------------------
int
option_flag (
    int *		arg_argc_ptr
    ,
    char * * *		arg_argv_ptr
    ,
    ...
    )
__PROTO_END__
{
    va_list		var_args	;
    const char *	opt_ptr		;
    char * *		argv		;
    char *		args		;
    int			argc		;

    if ( ! arg_argc_ptr || ! ( argc = * arg_argc_ptr ) ) return 0;
    if ( ! arg_argv_ptr || ! ( argv = * arg_argv_ptr ) ) return 0;
    if ( ! ( args = * argv ) ) return 0;
    va_start( var_args, arg_argv_ptr );
    while ( ( opt_ptr = va_arg( var_args, const char * ) ) ) {
	if ( strcmp( opt_ptr, args ) == 0 ) {
	    va_end( var_args );
	    return 1;
	}
    }
    va_end( var_args );
    return 0;
}

