Annotation of 43BSDReno/contrib/isode-beta/dsap/common/soundex.c, revision 1.1.1.1

1.1       root        1: /* soundex.c - compare a filter and attribute value */
                      2: 
                      3: #ifndef lint
                      4: static char *rcsid = "$Header: /f/osi/dsap/common/RCS/soundex.c,v 7.0 89/11/23 21:47:46 mrose Rel $";
                      5: #endif
                      6: 
                      7: /*
                      8:  * $Header: /f/osi/dsap/common/RCS/soundex.c,v 7.0 89/11/23 21:47:46 mrose Rel $
                      9:  *
                     10:  *
                     11:  * $Log:       soundex.c,v $
                     12:  * Revision 7.0  89/11/23  21:47:46  mrose
                     13:  * Release 6.0
                     14:  * 
                     15:  */
                     16: 
                     17: /*
                     18:  *                                NOTICE
                     19:  *
                     20:  *    Acquisition, use, and distribution of this module and related
                     21:  *    materials are subject to the restrictions of a license agreement.
                     22:  *    Consult the Preface in the User's Manual for the full terms of
                     23:  *    this agreement.
                     24:  *
                     25:  */
                     26: 
                     27: #include <ctype.h>
                     28: #include "quipu/util.h"
                     29: #include "quipu/attrvalue.h"
                     30: #include "quipu/ds_search.h"
                     31: 
                     32: static char * next_word (ptr)
                     33: register char *ptr;
                     34: {
                     35:        while ( (*ptr != '.') && (*ptr != ' ') && (*ptr != '-') && (*ptr != 0) )
                     36:                ptr++;
                     37: 
                     38:        if (*ptr)
                     39:                return (++ptr);
                     40: 
                     41:        return (NULLCP);
                     42: }
                     43: 
                     44: static char next_char (a,last)
                     45: register char ** a;
                     46: char last;
                     47: {
                     48: extern char chrcnv[];
                     49: register char lc, c;
                     50: 
                     51:        if (**a == 0)
                     52:                return (0);
                     53: 
                     54:        for (;*++*a;) {
                     55:                if ( (**a == '.') || (**a ==' ') || (**a == '-') )
                     56:                        return (0);
                     57:                lc = chrcnv[**a];
                     58:                if (isupper (lc)) {
                     59:                        /*   ABCDEFGHIJKLMNOPQRSTUVWXYZ   */
                     60:                        c = "abcdabcaacclmmabcrcdabacac" [lc-'A'];
                     61:                        if ((c != 'a') && (c != last))
                     62:                                return (c);
                     63:                } else if (isdigit (lc)) 
                     64:                        return (lc);
                     65:        }
                     66:        return (0);
                     67: }
                     68: 
                     69: 
                     70: static match_word (a,b)
                     71: char *a;
                     72: char *b;
                     73: {
                     74: register char lasta, lastb;
                     75: 
                     76:        if ( (lasta = chrcnv[*a]) != (lastb = chrcnv[*b]) )
                     77:                return FALSE;
                     78: 
                     79:        for (;;) {
                     80:                lasta = next_char (&a,lasta);
                     81:                lastb = next_char (&b,lastb);
                     82: 
                     83:                if (lastb == 0)
                     84:                        return TRUE;
                     85: 
                     86:                if (lasta != lastb)
                     87:                        return FALSE;
                     88: 
                     89:        }
                     90:        /* NOTREACHED */
                     91: }
                     92: 
                     93: 
                     94: soundex_cmp (a,b)
                     95: register char *a;
                     96: register char *b;
                     97: {
                     98: char result = FALSE;
                     99: register char * ptr;
                    100: 
                    101:        for( ; a && b ; b = next_word (b) ) {
                    102:                for (ptr=a; ptr; ptr=next_word(ptr) )  {
                    103:                        if (match_word (ptr,b)) {
                    104:                                a = next_word (ptr);
                    105:                                result = TRUE;
                    106:                                break;
                    107:                        }
                    108:                }
                    109:                if (ptr == NULLCP)
                    110:                        return FALSE;
                    111:        }
                    112:        if ((a == NULL) && (b != NULL))
                    113:                return FALSE;
                    114: 
                    115:        return (result);
                    116: }
                    117: 
                    118: 
                    119: soundex_match (fitem,avs)
                    120:     register struct filter_item *fitem;
                    121:     register AV_Sequence avs;
                    122: {
                    123:        for (; avs != NULLAV; avs=avs->avseq_next)
                    124:                if (soundex_cmp ((char *)avs->avseq_av.av_struct, (char *)fitem->UNAVA.ava_value->av_struct))
                    125:                        return (OK);
                    126: 
                    127:        return (NOTOK);
                    128: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.