Changeset 75

Show
Ignore:
Timestamp:
03/19/99 09:08:47 (15 years ago)
Author:
ucacoxh
Message:

Added overlapping_words which returns the number of overlapping words
in two strings.

Slightly annoyed at having to write this but M$ mixerGetID and
mixerOpen fn's do not work for wave identifiers so there is no way to
tie the mixer to wave in / wave out devices bar matching manufacturer
id and finding the most overlap in words between the mixer name and
wave name. Grrr! Thwack!

Location:
common/trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • common/trunk/src/util.c

    r74 r75  
    248248        *w = '\0'; 
    249249} 
     250 
     251static int 
     252string_to_words(char *s, char**w, int max_words) 
     253{ 
     254        char *lasts; 
     255        int n; 
     256 
     257        n = 0; 
     258        w[0] = strtok_r(s, " ", &lasts); 
     259        if (w[0] == NULL) { 
     260                return n; 
     261        } 
     262 
     263        while(++n < max_words) { 
     264                w[n] = strtok_r(NULL, " ", &lasts); 
     265                if (w[n] == NULL) break; 
     266        } 
     267        return n; 
     268} 
     269 
     270int 
     271overlapping_words(const char *s1, const char *s2, int max_words) 
     272{ 
     273        char *c1, *c2, **w1, **w2; 
     274        int nw1, nw2, nover, i, j; 
     275 
     276        c1 = xstrdup(s1); 
     277        c2 = xstrdup(s2); 
     278 
     279        w1 = (char**)xmalloc(sizeof(char*)*max_words); 
     280        w2 = (char**)xmalloc(sizeof(char*)*max_words); 
     281 
     282        nw1 = string_to_words(c1, w1, max_words); 
     283        nw2 = string_to_words(c2, w2, max_words); 
     284 
     285        nover = 0; 
     286        for(i = 0; i < nw1; i++) { 
     287                for(j = 0; j < nw2; j++) { 
     288                        if (strcmp(w1[i], w2[j]) == 0) { 
     289                                nover++; 
     290                                continue; 
     291                        } 
     292                } 
     293        } 
     294 
     295        xfree(c1); 
     296        xfree(c2); 
     297         
     298        return nover; 
     299} 
     300 
     301 
  • common/trunk/src/util.h

    r3 r75  
    5050void     block_check(char *p); 
    5151 
    52 void purge_chars(char *src, char *to_go); /* Removes occurances of chars in to_go from src */ 
     52/* purge_chars: removes occurances of chars in to_go from src */ 
     53void purge_chars(char *src, char *to_go);  
     54 
     55/* overlapping_words: returns how many words match in two strings */ 
     56int overlapping_words(const char *s1, const char *s2, int max_words); 
    5357 
    5458#endif