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, strcmp) == NULL) {
58 wordlist = lladd(wordlist, start);
66 * makewordlistfromkey - Takes a public key and splits it into a set of
68 * @wordlist: The current word list.
69 * @key: The key to return the words from.
71 * We take words and split it on non alpha numeric characters. These get
72 * added to the word list if they're not already present. If the wordlist
73 * is NULL then we start a new list, otherwise it's search for already
74 * added words. Note that words is modified in the process of scanning.
76 * Returns the new word list.
78 struct ll *makewordlistfromkey(struct ll *wordlist,
79 struct openpgp_publickey *key)
83 struct ll *words = NULL;
86 uids = keyuids(key, NULL);
87 for (i = 0; uids[i] != NULL; ++i) {
88 words = makewordlist(NULL, uids[i]);
89 for (wl = words; wl != NULL; wl = wl->next) {
90 if (llfind(wordlist, wl->object, strcmp) == NULL) {
91 wordlist = lladd(wordlist, strdup(wl->object));