string_list.c

Thu, 01 Dec 2011 17:06:27 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 01 Dec 2011 17:06:27 +0100
changeset 26
853a1181884b
parent 20
43725438ac50
permissions
-rw-r--r--

Merge with 3963e8800a1268be93d938c709e2d4be4d0b2d39

10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
19
8bac9fd0629d generalized suffix_list to string_list
Mike Becker <universe@uap-core.de>
parents: 17
diff changeset
2 * string_list.c
10
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
20
43725438ac50 Changed author comments + added signatures for upcomming bfile heuristics
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
5 * Author: Mike
10
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
19
8bac9fd0629d generalized suffix_list to string_list
Mike Becker <universe@uap-core.de>
parents: 17
diff changeset
8 #include "string_list.h"
10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9
19
8bac9fd0629d generalized suffix_list to string_list
Mike Becker <universe@uap-core.de>
parents: 17
diff changeset
10 string_list_t* new_string_list_t() {
8bac9fd0629d generalized suffix_list to string_list
Mike Becker <universe@uap-core.de>
parents: 17
diff changeset
11 string_list_t* stringList = malloc(sizeof(string_list_t));
8bac9fd0629d generalized suffix_list to string_list
Mike Becker <universe@uap-core.de>
parents: 17
diff changeset
12 stringList->count = 0;
8bac9fd0629d generalized suffix_list to string_list
Mike Becker <universe@uap-core.de>
parents: 17
diff changeset
13 stringList->items = NULL;
10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14
19
8bac9fd0629d generalized suffix_list to string_list
Mike Becker <universe@uap-core.de>
parents: 17
diff changeset
15 return stringList;
10
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
19
8bac9fd0629d generalized suffix_list to string_list
Mike Becker <universe@uap-core.de>
parents: 17
diff changeset
18 void destroy_string_list_t(string_list_t* list) {
17
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
19 if (list->items != NULL) {
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
20 free(list->items);
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
21 }
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
22 free(list);
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
23 }
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
24
19
8bac9fd0629d generalized suffix_list to string_list
Mike Becker <universe@uap-core.de>
parents: 17
diff changeset
25 void add_string(string_list_t* list, char* item) {
10
ecf787666f44 refactored sources
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 char** reallocated_list =
17
5f43f733cc12 fixed suffixList realloc bug + added destroy_suffix_list_t
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
27 realloc(list->items, sizeof(char*) * (list->count + 1));
10
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