//-----------------------------------------------------------------------------
// 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/map
// 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 112 columns wide.
//-----------------------------------------------------------------------------

#include "map_ca.h"

__FMACRO_BEGIN__
//-----------------------------------------------------------------------------
// macro	map_str_cmp_spaces
//
// purpose	Set the comparison feature to enable or disable comparing
//		substrings of non-graphical characters as being collapsed
//		to a single binary 0 character.
//
// arguments	1 (MAP) mapping handle
//		2 (int) -1: no change, 0: disable, 1: enable
//
// returns	(int) -1 : error
//		(int)  0 : OK, previously disabled
//		(int)  1 : OK, previously enabled
//
// WARNING	This function will remove all members from the mapping since
//		the collating order is disrupted by this setting.
//-----------------------------------------------------------------------------
#define map_str_cmp_spaces map_ca_cmp_spaces
__FMACRO_END__

__FMACRO_BEGIN__
//-----------------------------------------------------------------------------
// macro	map_cs_cmp_spaces
//
// purpose	Set the comparison feature to enable or disable comparing
//		substrings of non-graphical characters as being collapsed
//		to a single binary 0 character.
//
// arguments	1 (MAP) mapping handle
//		2 (int) -1: no change, 0: disable, 1: enable
//
// returns	(int) -1 : error
//		(int)  0 : OK, previously disabled
//		(int)  1 : OK, previously enabled
//
// WARNING	This function will remove all members from the mapping since
//		the collating order is disrupted by this setting.
//-----------------------------------------------------------------------------
#define map_cs_cmp_spaces map_ca_cmp_spaces
__FMACRO_END__

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	map_ca_cmp_spaces
//
// purpose	Set the comparison feature to enable or disable comparing
//		substrings of non-graphical characters as being collapsed
//		to a single binary 0 character.
//
// arguments	1 (MAP) mapping handle
//		2 (int) -1: no change, 0: disable, 1: enable
//
// returns	(int) -1 : error
//		(int)  0 : OK, previously disabled
//		(int)  1 : OK, previously enabled
//
// WARNING	This function will remove all members from the mapping since
//		the collating order is disrupted by this setting.
//-----------------------------------------------------------------------------
int
map_ca_cmp_spaces (
    MAP		arg_map
    ,
    int		arg_change
   )
__PROTO_END__
{
    int		previous	;

    //-- Make sure the mapping is empty.
    map_empty( arg_map );

    //-- If not currently set for special string compare, change it.
    if ( arg_change >= 0 && arg_map->cmp_func != map_ca_compare_str ) {
	arg_map->cmp_func = map_ca_compare_str;
	arg_map->options = 0;
    }

    //-- Hold on to the previous options.
    previous = arg_map->options;

    //-- Make appropriate changes based on the change flag.
    if ( arg_change >= 0 ) {

	//-- Disable or enable the option.
	if ( arg_change == 0 ) {
	    arg_map->options &= ~(MAP_OPT_SPACES);
	} else if ( arg_change > 0 ) {
	    arg_map->options |= MAP_OPT_SPACES;
	}

	//-- Re-initialize the AVL layer.
	if ( ! avl_init( & (arg_map->avl_tree),
			 struct map_node_ca,
			 link,
			 map_ca_compare_str ) ) return -1;
    }

    return ! ! ( previous & MAP_OPT_SPACES );
}


