//-----------------------------------------------------------------------------
// 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/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	str_yes_no
//
// purpose	Determine if a given string represents a yes/true or no/false
//		boolean value in several forms and languages.
//
// argument	1 (const char *) string to determine value from
//
// returns	(int) -1 : unknown
//		(int)  0 : ei/false/na/nao/ne/nee/nei/nein/nem/nie/no/non/nyet
//		(int)  1 : ano/da/do/igem/ja/jaa/jes/kylla/oui/si/sim/tak/true/yes
//-----------------------------------------------------------------------------
#define str_true_false	str_yes_no
#define str_ano_ne	str_yes_no
#define str_ja_nej	str_yes_no
#define str_ja_nee	str_yes_no
#define str_jaa_ei	str_yes_no
#define str_jes_ne	str_yes_no
#define str_kylla_ei	str_yes_no
#define str_oui_non	str_yes_no
#define str_ja_nein	str_yes_no
#define str_igem_nem	str_yes_no
#define str_si_no	str_yes_no
#define str_ja_nei	str_yes_no
#define str_tak_nie	str_yes_no
#define str_sim_nao	str_yes_no
#define str_da_nyet	str_yes_no
#define str_da_ne	str_yes_no
#define str_do_na	str_yes_no

int
str_yes_no (
    const char *	arg_string
    )
__PROTO_END__
{
    char *	end_string	;
    long	number		;
    int		ch		;

    //-- Make sure we have a valid string pointer.
    if ( ! arg_string ) return -1;

    //-- Check to see if there is a number.
    end_string = NULL;
    number = strtol( arg_string, & end_string, 0 );

    //-- If there is a number, use that and ignore characters that follow.
    if ( end_string == NULL || end_string > arg_string ) {
	if ( number < 0 ) return -1;
	if ( number > 0 ) return 1;
	return 0;
    }

    //-- Else, interpret the word based on first letter.
    ch = tolower( * arg_string );
    if ( ch >= 'o' ) {
	if ( ch == 'o' || ch == 's' || ch == 't' || ch == 'y' ) return 1;
	return -1;
    }
    if ( ch == 'e' || ch == 'f' || ch == 'n' ) return 0;
    if ( ch == 'a' || ch == 'd' || ch == 'j' || ch == 'k' ) return 1;
    return -1;
}

