//-----------------------------------------------------------------------------
// Copyright © 2004 - 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/string
// 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 "string_lib.h"

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	split_cmp_args
//
// purpose	Compare a split string with zero or more argument strings.
//
//		For each function argument string, a part is split from the
//		string associated with the given split object, and the part
//		argument are compared.
//
// note		Only as many split string parts are compared as there are
//		arguments given.  If the split string comes up short, this
//		will result in a mis-match indication at that argument.
//		However, if the split string has more part available, this
//		will not be indicated.  In order to determine if there are
//		more parts available, call split_next() afterwards to see
//		if it indicates a successful split (returns 0).
//
// argument	1 (split_p) pointer to split state
//		2...X-1 (const char *) arguments to compare
//
// note		It is not necessary to supply a NULL after the arguments since
//		split_cmp_args is defined as a macro that provides it.
//
// returns	(int) -1 : error
//		(int)  0 : split string matches arguments
//		(int)  N : mismatch at Nth comparison argument (1..X)
//-----------------------------------------------------------------------------
#define split_cmp_args(s,a...) ((split_cmp_args)((s),a,(const char *)(NULL)))
int
(split_cmp_args) (
    split_p		arg_split
    ,
    ...
    )
__PROTO_END__
{
    va_list		var_arg		;
    const char *	str_arg		;
    int			num_arg		;

    va_start( var_arg, arg_split );
    num_arg = 0;
    while ( ( str_arg = va_arg( var_arg, const char * ) ) ) {
	++ num_arg;
	if ( split_next( arg_split ) != 0 ) break;
	if ( memcmp( str_arg,
		     split_part_ptr( arg_split ),
		     split_part_len( arg_split ) ) != 0 )
	    goto mismatch;
    }
    num_arg = 0;
 mismatch:
    va_end( var_arg );
    return num_arg;
}

