summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
be024aa)
Add a new function that adds an object to the end of a linked list.
We make use of this in makewordlist, which means we search for keys
containing words from the start of the email address first, rather than
starting with the words at the end. When you're dealing with TLDs like
com, net, org this makes a big difference, as you don't end up with a
huge list from the first word you try.
+struct ll *lladdend(struct ll *curll, void *object)
+{
+ struct ll *new;
+ struct ll *cur;
+
+ if ((new = malloc(sizeof(struct ll))) == NULL) {
+ logthing(LOGTHING_ERROR,
+ "Couldn't allocate memory in lladdend()");
+ return NULL;
+ }
+
+ new->next = NULL;
+ new->object = object;
+
+ if (curll != NULL) {
+ cur = curll;
+ while (cur->next != NULL) {
+ cur = cur->next;
+ }
+ cur->next = new;
+ } else {
+ curll = new;
+ }
+
+ return curll;
+}
+
struct ll *lldel(struct ll *curll, void *object,
int (*objectcmp) (const void *object1, const void *object2))
{
struct ll *lldel(struct ll *curll, void *object,
int (*objectcmp) (const void *object1, const void *object2))
{
*/
struct ll *lladd(struct ll *curll, void *object);
*/
struct ll *lladd(struct ll *curll, void *object);
+/**
+ * lladdend - Add an item to the end of a linked list.
+ * @curll: The list to add to. Can be NULL to create a new list.
+ * @object: The object to add.
+ *
+ * Returns a pointer to the head of the new list.
+ */
+struct ll *lladdend(struct ll *curll, void *object);
+
/**
* lldel - Remove an item from a linked list.
* @curll: The list to remove the item from.
/**
* lldel - Remove an item from a linked list.
* @curll: The list to remove the item from.
if (llfind(wordlist, start,
(int (*)(const void *, const void *)) strcmp
) == NULL) {
if (llfind(wordlist, start,
(int (*)(const void *, const void *)) strcmp
) == NULL) {
- wordlist = lladd(wordlist, start);
+ wordlist = lladdend(wordlist, start);