2 * wordlist.c - Routines for manipulating word lists
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2004 Project Purple
14 #include "decodekey.h"
19 * makewordlist - Takes a string and splits it into a set of unique words.
20 * @wordlist: The current word list.
21 * @words: The string to split and add.
23 * We take words and split it on non alpha numeric characters. These get
24 * added to the word list if they're not already present. If the wordlist
25 * is NULL then we start a new list, otherwise it's search for already
26 * added words. Note that words is modified in the process of scanning.
28 * Returns the new word list.
30 struct ll *makewordlist(struct ll *wordlist, char *word)
36 * Walk through the words string, spliting on non alphanumerics and
37 * then checking if the word already exists in the list. If not then
41 while (end != NULL && *end != 0) {
43 while (*start != 0 && !isalnum(*start)) {
47 while (*end != 0 && isalnum(*end)) {
51 if (end - start > 1) {
57 if (llfind(wordlist, start,
58 (int (*)(const void *, const void *)) strcmp
60 wordlist = lladdend(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,
93 (int (*)(const void *, const void *)) strcmp
95 wordlist = lladd(wordlist, strdup(wl->object));