ekg2
|
00001 /* $Id: dynstuff.h 4542 2008-08-28 18:42:26Z darkjames $ */ 00002 00003 /* 00004 * (C) Copyright 2001-2002 Wojtek Kaniewski <wojtekka@irc.pl> 00005 * Dawid Jarosz <dawjar@poczta.onet.pl> 00006 * Adam Wysocki <gophi@ekg.chmurka.net> 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License Version 2 as 00010 * published by the Free Software Foundation. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 */ 00021 00022 #ifndef __EKG_DYNSTUFF_H 00023 #define __EKG_DYNSTUFF_H 00024 00025 struct list { 00026 /* it is important that we keep 'next' first field, 00027 * because C allows us to call first field of any structure 00028 * without knowing its' type 00029 * 00030 * so *3() would work peacefully w/ both list_t and not-list_t lists */ 00031 struct list *next; 00032 00033 void *data; 00034 }; 00035 00036 typedef struct list *list_t; 00037 00038 #define LIST_ADD_COMPARE(x, type) int x(const type data1, const type data2) 00039 #define LIST_ADD_SORTED2(list, data, comp) list_add_sorted3((list_t *) (void *) list, (list_t) data, (void *) comp) 00040 #define LIST_ADD_BEGINNING2(list, data) list_add_beginning3((list_t *) (void *) list, (list_t) data) 00041 #define LIST_ADD2(list, data) list_add3((list_t *) (void *) list, (list_t) data) 00042 00043 #define LIST_COUNT2(list) list_count((list_t) list) 00044 #define LIST_REMOVE2(list, elem, func) list_remove3((list_t *) (void *) list, (list_t) elem, (void *) func) 00045 #define LIST_UNLINK2(list, elem) list_unlink3((list_t *) (void *) list, (list_t) elem) 00046 #define LIST_FREE_ITEM(x, type) void x(type data) 00047 00048 #define LIST_DESTROY2(list, func) list_destroy3((list_t) list, (void *) func) 00049 00050 void *list_add_beginning(list_t *list, void *data); 00051 00052 void *list_add3(list_t *list, list_t new); 00053 void *list_add_sorted3(list_t *list, list_t new, int (*comparision)(void *, void *)); 00054 void list_add_beginning3(list_t *list, list_t new); 00055 00056 void *list_remove3(list_t *list, list_t elem, void (*func)(list_t)); 00057 void *list_remove3i(list_t *list, list_t elem, void (*func)(list_t data)); 00058 void *list_unlink3(list_t *list, list_t elem); 00059 00060 int list_destroy(list_t list); 00061 int list_destroy3(list_t list, void (*func)(void *)); 00062 00063 void list_cleanup(list_t *list); 00064 int list_remove_safe(list_t *list, void *data); 00065 00066 struct string { 00067 char *str; 00068 int len, size; 00069 }; 00070 00071 typedef struct string *string_t; 00072 00073 string_t string_init(const char *str); 00074 int string_append(string_t s, const char *str); 00075 int string_append_n(string_t s, const char *str, int count); 00076 int string_append_c(string_t s, char ch); 00077 int string_append_raw(string_t s, const char *str, int count); 00078 void string_remove(string_t s, int count); 00079 char *string_free(string_t s, int free_string); 00080 00081 /* tablice stringow */ 00082 char **array_make(const char *string, const char *sep, int max, int trim, int quotes); 00083 char *array_join(char **array, const char *sep); 00084 00085 int array_add(char ***array, char *string); 00086 int array_add_check(char ***array, char *string, int casesensitive); 00087 int array_count(char **array); 00088 int array_item_contains(char **array, const char *string, int casesensitive); 00089 void array_free(char **array); 00090 00091 /* rozszerzenia libców */ 00092 00093 const char *itoa(long int i); 00094 00095 /* 00096 * handle private data 00097 */ 00098 typedef struct private_data_s { 00099 struct private_data_s *next; 00100 00101 char *name; 00102 char *value; 00103 } private_data_t; 00104 00105 void private_item_set(private_data_t **data, const char *item_name, const char *value); 00106 int private_item_get_int(private_data_t **data, const char *item_name); 00107 void private_items_destroy(private_data_t **data); 00108 00109 #endif /* __EKG_DYNSTUFF_H */ 00110 00111 /* 00112 * Local Variables: 00113 * mode: c 00114 * c-file-style: "k&r" 00115 * c-basic-offset: 8 00116 * indent-tabs-mode: t 00117 * End: 00118 */