-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.c
82 lines (65 loc) · 1.62 KB
/
list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* This file is part of John the Ripper password cracker,
* Copyright (c) 1996-98,2013 by Solar Designer
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*/
#include <stdio.h>
#include <string.h>
#include "memory.h"
#include "list.h"
void list_init(struct list_main **list)
{
*list = mem_alloc_tiny(sizeof(struct list_main), MEM_ALIGN_WORD);
(*list)->tail = (*list)->head = NULL;
(*list)->count = 0;
}
void list_add(struct list_main *list, char *data)
{
struct list_entry *entry;
entry = mem_alloc_tiny(sizeof(struct list_entry) + strlen(data),
MEM_ALIGN_WORD);
strcpy(entry->data, data);
list_add_link(list, entry);
}
void list_add_link(struct list_main *list, struct list_entry *entry)
{
entry->next = NULL;
if (list->tail)
list->tail = list->tail->next = entry;
else
list->tail = list->head = entry;
list->count++;
}
void list_add_multi(struct list_main *list, char *data)
{
char *comma;
do {
if ((comma = strchr(data, ','))) *comma = 0;
list_add(list, data);
data = comma + 1;
if (comma) *comma = ',';
} while (comma);
}
void list_add_unique(struct list_main *list, char *data)
{
struct list_entry *current;
if ((current = list->head))
do {
if (!strcmp(current->data, data)) return;
} while ((current = current->next));
list_add(list, data);
}
#if 0
void list_del_next(struct list_main *list, struct list_entry *prev)
{
if (prev) {
if (!(prev->next = prev->next->next)) list->tail = prev;
} else
if (!(list->head = list->head->next)) list->tail = NULL;
list->count--;
}
#endif