/* sassoc.c - implement onto mapping strings->strings */

#ifdef	DOCUMENTATION
title	sassoc	crude associative memory
index	compile-time
index	string onto mapping
index 	onto mpping of strings
index	mapping strings
index	associative memory
synopsis

	 char * table[] = {
	 
	 "first key",	"first data",
	 "2nd k",	"2nd d",
	 NULL		};
	 
	 char * p;	/* result or NULL */
	 char * key;
	 
	 strcpy(key,"2nd k");
	 
	 p = sassoc(table,key);
	 
	 /* p -> "2nd d" */
description

	Given a string key, and a table of pairs (keystring, datastring),
	find keystring == key, and return datastring. return NULL if
	there is not an exact match of key.
	The table must end in NULL.
internal

	I know it is horrid, but I just want a standard, ANY standard,
	for table lookup. Please submit any better standards you have.

diagnostics

author

	Dean Elsner.
#endif


#include <algol68.h>


	char *

sassoc	(table, key)		/* relation string -> string		*/
char *	table[];		/* pairs of strings			*/
char *	key;			/* input to mapping			*/
BEGIN
char *	retval;

	FOR	(retval=NULL; !retval && *table; table+=2)
	DO	IF	(streq(*table,key))
		THEN	retval = *++table;
		FI
	OD
	return(retval);
END

#ifdef testing

char *	t[] = {

"",	"empty",
"1",	"one",
"2",	"two",
NULL};

char *	p;
char	answer[100];

main()
BEGIN
	FOR	(;;)
	DO	printf("1,2,empty:   ");
		gets(answer);
		p = sassoc(t,answer);
		printf("result=\"%s\"\n",p);
	OD
END
#endif

/* end: sassoc.c */
