cline.c

changeset 9
1dd63a32ffc4
parent 8
28319b20968c
child 11
06cbd0ec003d
equal deleted inserted replaced
8:28319b20968c 9:1dd63a32ffc4
1 #include "cline.h" 1 #include "cline.h"
2 #include "functions.h" 2 #include "functions.h"
3 3
4 suffix_list_t* new_suffix_list_t() { 4 suffix_list_t* new_suffix_list_t() {
5 suffix_list_t* suffixList = malloc(sizeof(suffix_list_t*)); 5 suffix_list_t* suffixList = malloc(sizeof(suffix_list_t));
6 suffixList->count = 0; 6 suffixList->count = 0;
7 suffixList->items = NULL; 7 suffixList->items = NULL;
8 } 8
9 9 return suffixList;
10 void destroy_suffix_list_t(suffix_list_t* list) {
11 while (--list->count >= 0) {
12 free(list->items[list->count]);
13 }
14 free(list);
15 } 10 }
16 11
17 void add_suffix(suffix_list_t* list, char* item) { 12 void add_suffix(suffix_list_t* list, char* item) {
18 char** reallocated_list = 13 char** reallocated_list =
19 realloc(list->items, sizeof(char**) * list->count + 1); 14 realloc(list->items, sizeof(char*) * list->count + 1);
20 if (reallocated_list != NULL) { 15 if (reallocated_list != NULL) {
21 list->items = reallocated_list; 16 list->items = reallocated_list;
22 list->items[list->count] = item; 17 list->items[list->count] = item;
23 list->count++; 18 list->count++;
24 } 19 }
25 } 20 }
26 21
27 settings_t* new_settings_t() { 22 settings_t* new_settings_t() {
28 settings_t *settings = malloc(sizeof(settings_t*)); 23 settings_t *settings = malloc(sizeof(settings_t));
29 if (settings != NULL) { 24 if (settings != NULL) {
30 #ifdef _WIN32 25 #ifdef _WIN32
31 settings->fileSeparator = '\\'; 26 settings->fileSeparator = '\\';
32 #else 27 #else
33 settings->fileSeparator = '/'; 28 settings->fileSeparator = '/';
40 35
41 return settings; 36 return settings;
42 } 37 }
43 38
44 void destroy_settings_t(settings_t* settings) { 39 void destroy_settings_t(settings_t* settings) {
45 destroy_suffix_list_t(settings->suffixList); 40 free(settings->suffixList);
46 free(settings); 41 free(settings);
47 } 42 }
48 43
49 void printHelpText(const char* prgName) { 44 void printHelpText(const char* prgName) {
50 // Help text 45 // Help text

mercurial