suffix_list.c

Thu, 15 Sep 2011 13:29:06 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 15 Sep 2011 13:29:06 +0200
changeset 10
ecf787666f44
child 11
06cbd0ec003d
permissions
-rw-r--r--

refactored sources

10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * suffix_list.c
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Created on: 15.09.2011
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 * Author: beckermi
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 */
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 #include "suffix_list.h"
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 suffix_list_t* new_suffix_list_t() {
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 suffix_list_t* suffixList = malloc(sizeof(suffix_list_t*));
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 suffixList->count = 0;
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 suffixList->items = NULL;
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 return suffixList;
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 }
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 void destroy_suffix_list_t(suffix_list_t* list) {
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 while (--list->count >= 0) {
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 free(list->items[list->count]);
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 }
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 free(list);
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 }
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 void add_suffix(suffix_list_t* list, char* item) {
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 char** reallocated_list =
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 realloc(list->items, sizeof(char**) * list->count + 1);
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 if (reallocated_list != NULL) {
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 list->items = reallocated_list;
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 list->items[list->count] = item;
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 list->count++;
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 }
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 }
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34

mercurial