DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T s

⟦18efb2c21⟧ TextFile

    Length: 4218 (0x107a)
    Types: TextFile
    Names: »soundex.c«

Derivation

└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
    └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« 
        └─⟦d3ac74d73⟧ 
            └─⟦this⟧ »isode-5.0/quipu/soundex.c« 

TextFile

/* make_keys.c - */

#ifndef lint
static char *rcsid = "$Header: /f/osi/quipu/RCS/soundex.c,v 6.0 89/03/18 23:41:55 mrose Rel $";
#endif

/*
 * $Header: /f/osi/quipu/RCS/soundex.c,v 6.0 89/03/18 23:41:55 mrose Rel $
 *
 *
 * $Log:	soundex.c,v $
 * Revision 6.0  89/03/18  23:41:55  mrose
 * Release 5.0
 * 
 */

/*
 *                                NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */


/* Some routines copied from Thorn - then modified */

#include <ctype.h>
#include "quipu/util.h"
#include "quipu/attrvalue.h"
#include "quipu/ds_search.h"

static void make_keys();
static void make_long_keys();
static void make_single_key();

avs_soundex_key (a)
AV_Sequence a;
{
	if ( (a->avseq_av->av_syntax != AV_CASEIGNORESTRING) || (a->avseq_av->av_syntax != AV_CASEIGNORESTRING) )
		return;

	for (; a != NULLAV; a = a -> avseq_next)
		make_keys (a->avseq_soundex,a->avseq_av->av_un.av_str);
}

fitem_soundex_key (a)
struct filter_item *a;
{
	if ( (a->UNAVA.ava_value->av_syntax != AV_CASEIGNORESTRING) || (a->UNAVA.ava_value->av_syntax != AV_CASEIGNORESTRING) )
		a->fi_soundex[0][0] = 0;

	make_keys (a->fi_soundex,a->UNAVA.ava_value->av_un.av_str);
}


soundex_cmp (a,b)
Soundex a [MAXSOUNDEXKEYS][SOUNDEXKEYSIZE];
Soundex b [MAXSOUNDEXKEYS][SOUNDEXKEYSIZE];
{
register int j,k,i;
int len;
int result = NOTOK;

	for (i=0, k=0; i < MAXSOUNDEXKEYS ; i++) {
		if (b[i][0] == 0)
			return (result);
		if (a[k][0] == 0)
			return (NOTOK);

		for (j=k; j < MAXSOUNDEXKEYS; j++) {
			if (a[j][0] == 0)
				return (NOTOK);
			for (len=0; len < SOUNDEXKEYSIZE; len++)
				if (b[i][len] == 0)
					break;
			if (strncmp (a[j],b[i],len) == 0) {
				k = j + 1;
				result = OK;
				break;
			}
		if ( j >= MAXSOUNDEXKEYS )
			return (NOTOK);
		}

	}
	return (NOTOK);
}


static void make_keys (buf,str)
Soundex buf [MAXSOUNDEXKEYS][SOUNDEXKEYSIZE];
char *str;
{
register int i = 0;
register char * ptr, sep;
register char * name;

	name = str;
	ptr = name;
	while (*name && (i < MAXSOUNDEXKEYS) ) {
		while ( (*ptr != '.') && (*ptr != ' ') && (*ptr != '-') && (*ptr != 0) )
			ptr++;
		sep = *ptr;
		*ptr = 0;
		make_single_key (buf [i++],name);
		if ((*ptr = sep) == 0)
			break;
		name = ++ptr;
	}

	if (i < MAXSOUNDEXKEYS)
		buf [i][0] = 0;

	if ((i >= MAXSOUNDEXKEYS) && ( *--ptr != 0))
		make_long_keys (buf,str);
}

static void make_single_key (buf,name)
Soundex buf [SOUNDEXKEYSIZE];
char  *name;
{
register char c, lc, prev ='0';
register int i;
extern char chrcnv[];

	for (i=0; (*name) && (i<SOUNDEXKEYSIZE); name++) {
		lc = chrcnv[*name];
		if (isupper (lc)) {
			/*   ABCDEFGHIJKLMNOPQRSTUVWXYZ   */
			c = "abcdabcaacclmmabcrcdabacac" [lc-'A'];
			if (i == 0)
				buf[i++] = lc;
			else if ((c != 'a') && (c != prev))
				buf[i++] = c;
			prev = c;
		} else if (isdigit (lc)) {
			buf[i++] = lc;
			prev = lc;
		}
	}
	if (i<SOUNDEXKEYSIZE)
		buf [i] = 0;
}


/* This is experimental and may/may not be included in the final system
 *
 * The idea is that if the string contains more than MAXSOUNDEKKEY
 * words, we will ignore certain 'gramatical' words,
 * so the key is made of only 'important' words.
 * This is of course language dependant
 */

#include "cmd_srch.h"

static void make_long_keys (buf,name)
Soundex buf [MAXSOUNDEXKEYS][SOUNDEXKEYSIZE];
register char *name;
{
register int i = 0;
register char * ptr, sep;
static CMD_TABLE cmd_words [] = {
	"a",            0,
	"i",            0,
	"as",           0,
	"an",           0,
	"is",           0,
	"in",           0,
	"on",           0,
	"of",           0,
	"it",           0,
	"to",           0,
	"the",          0,
	"was",          0,
	"this",         0,
	"that",         0,
	0,              -1
};

	ptr = name;
	while (*name && (i < MAXSOUNDEXKEYS) ) {
		while ( (*ptr != '.') && (*ptr != ' ') && (*ptr != '-') && (*ptr != 0) )
			ptr++;
		sep = *ptr;
		*ptr = 0;

		if (cmd_srch (name,cmd_words) == -1)
			make_single_key (buf [i++],name);

		if ((*ptr = sep) == 0)
			break;
		name = ++ptr;
	}

	if (i < MAXSOUNDEXKEYS)
		buf [i][0] = 0;

}