2 * wordlist.c - Routines for manipulating word lists
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2004 Project Purple
8 * $Id: wordlist.c,v 1.3 2004/05/28 03:23:04 noodles Exp $
16 #include "decodekey.h"
21 * makewordlist - Takes a string and splits it into a set of unique words.
22 * @wordlist: The current word list.
23 * @words: The string to split and add.
25 * We take words and split it on non alpha numeric characters. These get
26 * added to the word list if they're not already present. If the wordlist
27 * is NULL then we start a new list, otherwise it's search for already
28 * added words. Note that words is modified in the process of scanning.
30 * Returns the new word list.
32 struct ll *makewordlist(struct ll *wordlist, char *word)
38 * Walk through the words string, spliting on non alphanumerics and
39 * then checking if the word already exists in the list. If not then
43 while (end != NULL && *end != 0) {
45 while (*start != 0 && !isalnum(*start)) {
49 while (*end != 0 && isalnum(*end)) {
53 if (end - start > 1) {
59 if (llfind(wordlist, start, strcmp) == NULL) {
60 wordlist = lladd(wordlist, start);
68 * makewordlistfromkey - Takes a public key and splits it into a set of
70 * @wordlist: The current word list.
71 * @key: The key to return the words from.
73 * We take words and split it on non alpha numeric characters. These get
74 * added to the word list if they're not already present. If the wordlist
75 * is NULL then we start a new list, otherwise it's search for already
76 * added words. Note that words is modified in the process of scanning.
78 * Returns the new word list.
80 struct ll *makewordlistfromkey(struct ll *wordlist,
81 struct openpgp_publickey *key)
85 struct ll *words = NULL;
88 uids = keyuids(key, NULL);
89 for (i = 0; uids[i] != NULL; ++i) {
90 words = makewordlist(NULL, uids[i]);
91 for (wl = words; wl != NULL; wl = wl->next) {
92 if (llfind(wordlist, wl->object, strcmp) == NULL) {
93 wordlist = lladd(wordlist, strdup(wl->object));