ekg2  GIT master
dynstuff.h
Idź do dokumentacji tego pliku.
1 /* $Id: dynstuff.h 4542 2008-08-28 18:42:26Z darkjames $ */
2 
3 /*
4  * (C) Copyright 2001-2002 Wojtek Kaniewski <wojtekka@irc.pl>
5  * Dawid Jarosz <dawjar@poczta.onet.pl>
6  * Adam Wysocki <gophi@ekg.chmurka.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License Version 2 as
10  * published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 
22 #ifndef __EKG_DYNSTUFF_H
23 #define __EKG_DYNSTUFF_H
24 
25 struct list {
26  /* it is important that we keep 'next' first field,
27  * because C allows us to call first field of any structure
28  * without knowing its' type
29  *
30  * so *3() would work peacefully w/ both list_t and not-list_t lists */
31  struct list *next;
32 
33  void *data;
34 };
35 
36 typedef struct list *list_t;
37 
38 #define LIST_ADD_COMPARE(x, type) int x(const type data1, const type data2)
39 #define LIST_ADD_SORTED2(list, data, comp) list_add_sorted3((list_t *) (void *) list, (list_t) data, (void *) comp)
40 #define LIST_ADD_BEGINNING2(list, data) list_add_beginning3((list_t *) (void *) list, (list_t) data)
41 #define LIST_ADD2(list, data) list_add3((list_t *) (void *) list, (list_t) data)
42 
43 #define LIST_COUNT2(list) list_count((list_t) list)
44 #define LIST_REMOVE2(list, elem, func) list_remove3((list_t *) (void *) list, (list_t) elem, (void *) func)
45 #define LIST_UNLINK2(list, elem) list_unlink3((list_t *) (void *) list, (list_t) elem)
46 #define LIST_FREE_ITEM(x, type) void x(type data)
47 
48 #define LIST_DESTROY2(list, func) list_destroy3((list_t) list, (void *) func)
49 
50 void *list_add_beginning(list_t *list, void *data);
51 
52 void *list_add3(list_t *list, list_t new);
53 void *list_add_sorted3(list_t *list, list_t new, int (*comparision)(void *, void *));
54 void list_add_beginning3(list_t *list, list_t new);
55 
56 void *list_remove3(list_t *list, list_t elem, void (*func)(list_t));
57 void *list_remove3i(list_t *list, list_t elem, void (*func)(list_t data));
58 void *list_unlink3(list_t *list, list_t elem);
59 
60 int list_destroy(list_t list);
61 int list_destroy3(list_t list, void (*func)(void *));
62 
63 void list_cleanup(list_t *list);
64 int list_remove_safe(list_t *list, void *data);
65 
66 struct string {
67  char *str;
68  int len, size;
69 };
70 
71 typedef struct string *string_t;
72 
73 string_t string_init(const char *str);
74 int string_append(string_t s, const char *str);
75 int string_append_n(string_t s, const char *str, int count);
76 int string_append_c(string_t s, char ch);
77 int string_append_raw(string_t s, const char *str, int count);
78 void string_remove(string_t s, int count);
79 char *string_free(string_t s, int free_string);
80 
81 /* tablice stringow */
82 char **array_make(const char *string, const char *sep, int max, int trim, int quotes);
83 char *array_join(char **array, const char *sep);
84 
85 int array_add(char ***array, char *string);
86 int array_add_check(char ***array, char *string, int casesensitive);
87 int array_count(char **array);
88 int array_item_contains(char **array, const char *string, int casesensitive);
89 void array_free(char **array);
90 
91 /* rozszerzenia libców */
92 
93 const char *ekg_itoa(long int i);
94 
95 /*
96  * handle private data
97  */
98 typedef struct private_data_s {
99  struct private_data_s *next;
100 
101  char *name;
102  char *value;
104 
105 void private_item_set(private_data_t **data, const char *item_name, const char *value);
106 int private_item_get_int(private_data_t **data, const char *item_name);
108 
109 #endif /* __EKG_DYNSTUFF_H */
110 
111 /*
112  * Local Variables:
113  * mode: c
114  * c-file-style: "k&r"
115  * c-basic-offset: 8
116  * indent-tabs-mode: t
117  * End:
118  */
int private_item_get_int(private_data_t **data, const char *item_name)
Definition: dynstuff.c:1283
char * array_join(char **array, const char *sep)
Definition: dynstuff.c:499
void * list_remove3(list_t *list, list_t elem, void(*func)(list_t))
void string_remove(string_t s, int count)
Definition: dynstuff.c:723
GString * string_t
Definition: dynstuff.h:147
void list_cleanup(list_t *list)
Definition: dynstuff.c:236
int array_item_contains(char **array, const char *string, int casesensitive)
Definition: dynstuff.c:997
int string_append_n(string_t s, const char *str, int count)
Definition: dynstuff.c:575
void * data
Definition: ekg_hash_benchmark.c:15
char * string_free(string_t s, int free_string)
Definition: dynstuff.c:758
string_t string_init(const char *str)
Definition: dynstuff.c:697
struct list * list_t
Definition: dynstuff.h:79
void * list_add_sorted3(list_t *list, list_t new_, int(*comparision)(void *, void *))
Definition: dynstuff.c:134
void * list_remove3i(list_t *list, list_t elem, void(*func)(list_t data))
Definition: testcase_for_remove_iter.c:55
int string_append_c(string_t s, char ch)
Definition: dynstuff.c:551
void * list_add_beginning(list_t *list, void *data)
Definition: ekg_hash_benchmark.c:31
int list_destroy(list_t list, int free_data)
Definition: dynstuff.c:535
char ch
Definition: completion.c:638
int i
Definition: ekg_hash_benchmark.c:110
char * value
Definition: dynstuff.h:187
int list_destroy3(list_t list, void(*func)(void *))
Definition: dynstuff.c:498
struct list * next
Definition: ekg_hash_benchmark.c:17
void * list_add_beginning3(list_t *list, list_t new_)
Definition: testcase_for_remove_iter.c:43
char * str
Definition: dynstuff.h:67
char ** array_make(const char *string, const char *sep, int max, int trim, int quotes)
Definition: dynstuff.c:806
Definition: dynstuff.h:66
const char * name
Definition: remote.c:88
int array_add_check(char ***array, char *string, int casesensitive)
Definition: dynstuff.c:931
int string_append_raw(string_t s, const char *str, int count)
Definition: dynstuff.c:627
Definition: ekg_hash_benchmark.c:14
void private_item_set(private_data_t **data, const char *item_name, const char *value)
Definition: dynstuff.c:1289
void * list_unlink3(list_t *list, list_t elem)
Definition: dynstuff.c:350
Definition: dynstuff.h:183
int array_count(char **array)
Definition: dynstuff.c:464
void private_items_destroy(private_data_t **data)
Definition: dynstuff.c:1237
const char * ekg_itoa(long int i)
Definition: dynstuff.c:775
int list_remove_safe(list_t *list, void *data, int free_data)
Definition: dynstuff.c:208
void array_free(char **array)
Definition: dynstuff.c:534
struct private_data_s private_data_t
#define s
int size
Definition: dynstuff.h:68
int string_append(string_t s, const char *str)
Definition: dynstuff.c:642
void * list_add3(list_t *list, list_t new_)
Definition: dynstuff.c:188
int array_add(char ***array, char *string)
Definition: dynstuff.c:907